Browse Source

KERNEL-4414 权限导出finekit适配

pull/1/head
lidongy 4 years ago
parent
commit
30f57b7bc8
  1. 28
      src/main/java/com/fanruan/api/decision/AuthorityKit.java
  2. 10
      src/main/java/com/fanruan/api/decision/user/UserKit.java
  3. 11
      src/main/java/com/fanruan/api/util/DateKit.java
  4. 30
      src/test/java/com/fanruan/api/decision/AuthorityKitTest.java
  5. 27
      src/test/java/com/fanruan/api/decision/user/UserKitTest.java
  6. 7
      src/test/java/com/fanruan/api/util/DateKitTest.java

28
src/main/java/com/fanruan/api/decision/AuthorityKit.java

@ -6,6 +6,7 @@ import com.fr.decision.authority.base.constant.AuthorityValue;
import com.fr.decision.authority.base.constant.type.authority.AuthorityType;
import com.fr.decision.authority.controller.GradeAuthorityController;
import com.fr.decision.authority.data.personnel.DepRole;
import com.fr.decision.config.FSConfig;
import com.fr.decision.webservice.utils.WebServiceUtils;
/**
@ -104,4 +105,31 @@ public class AuthorityKit {
authId,
AuthorityType.fromInteger(authType));
}
/**
* 是否开启了分级权限
*
* @return 开启返回true关闭返回false
*/
public static boolean isGradeAuthority() {
return FSConfig.getInstance().getAuthorizeAttr().isGradeAuthority();
}
/**
* 是否开启了数据连接权限控制
*
* @return 开启返回true关闭返回false
*/
public static boolean isDataConnectionAuthority() {
return FSConfig.getInstance().getAuthorizeAttr().isDataConnectionAuthority();
}
/**
* 是否开启了目录编辑权限
*
* @return 开启返回true关闭返回false
*/
public static boolean isEditReportAuthority() {
return FSConfig.getInstance().getAuthorizeAttr().isEditReportAuthority();
}
}

10
src/main/java/com/fanruan/api/decision/user/UserKit.java

@ -86,4 +86,14 @@ public class UserKit {
public static String getCurrentUserId(HttpServletRequest request) throws Exception {
return UserService.getInstance().getCurrentUserId(request);
}
/**
* 获取超级管理角色下的用户ID列表
*
* @return 用户ID列表
* @throws Exception 异常
*/
public static List<String> getAdminUserIdList() throws Exception {
return UserService.getInstance().getAdminUserIdList();
}
}

11
src/main/java/com/fanruan/api/util/DateKit.java

@ -15,4 +15,15 @@ public class DateKit {
public static Date string2Date(String str, boolean returnNull) {
return DateUtils.string2Date(str, returnNull);
}
/**
* 取得某日期时间的特定表示格式的字符串
*
* @param format 时间格式
* @param date 某日期Date
* @return 某日期的字符串
*/
public static String getDate2Str(String format, Date date) {
return DateUtils.getDate2Str(format, date);
}
}

30
src/test/java/com/fanruan/api/decision/AuthorityKitTest.java

@ -1,7 +1,14 @@
package com.fanruan.api.decision;
import com.fr.decision.authorize.AuthorizeAttr;
import com.fr.decision.config.FSConfig;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.lang.reflect.Method;
@ -10,6 +17,8 @@ import java.lang.reflect.Method;
* @version 10.0
* Created by Zed on 2020/4/30
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({FSConfig.class})
public class AuthorityKitTest {
@Test
@ -27,4 +36,25 @@ public class AuthorityKitTest {
Method method3 = classBook.getDeclaredMethod("setDepAuth", String.class, int.class, String.class, int.class);
Assert.assertNotNull(method3);
}
@Test
public void testIsAuthorizeAttrOpen() {
AuthorizeAttr authorizeAttr = EasyMock.createMock(AuthorizeAttr.class);
EasyMock.expect(authorizeAttr.isGradeAuthority()).andReturn(true).anyTimes();
EasyMock.expect(authorizeAttr.isDataConnectionAuthority()).andReturn(true).anyTimes();
EasyMock.expect(authorizeAttr.isEditReportAuthority()).andReturn(true).anyTimes();
EasyMock.replay(authorizeAttr);
FSConfig fsConfig = EasyMock.createMock(FSConfig.class);
EasyMock.expect(fsConfig.getAuthorizeAttr()).andReturn(authorizeAttr).anyTimes();
EasyMock.replay(fsConfig);
PowerMock.mockStatic(FSConfig.class);
EasyMock.expect(FSConfig.getInstance()).andReturn(fsConfig).anyTimes();
PowerMock.replay(FSConfig.class);
Assert.assertEquals(AuthorityKit.isGradeAuthority(), FSConfig.getInstance().getAuthorizeAttr().isGradeAuthority());
Assert.assertEquals(AuthorityKit.isDataConnectionAuthority(), FSConfig.getInstance().getAuthorizeAttr().isDataConnectionAuthority());
Assert.assertEquals(AuthorityKit.isEditReportAuthority(), FSConfig.getInstance().getAuthorizeAttr().isEditReportAuthority());
}
}

27
src/test/java/com/fanruan/api/decision/user/UserKitTest.java

@ -1,16 +1,26 @@
package com.fanruan.api.decision.user;
import com.fr.decision.webservice.v10.user.UserService;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
/**
* @author Zed
* @version 10.0
* Created by Zed on 2020/4/30
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({UserService.class})
public class UserKitTest {
@Test
@ -22,4 +32,21 @@ public class UserKitTest {
Method method1 = classBook.getDeclaredMethod("getCurrentUserId", HttpServletRequest.class);
Assert.assertNotNull(method1);
}
@Test
public void testGetAdminUserIdList() throws Exception {
List<String> adminUserIdList = new ArrayList<>();
adminUserIdList.add("1");
UserService userService = EasyMock.createMock(UserService.class);
EasyMock.expect(userService.getAdminUserIdList()).andReturn(adminUserIdList);
EasyMock.replay(userService);
PowerMock.mockStatic(UserService.class);
EasyMock.expect(UserService.getInstance()).andReturn(userService);
PowerMock.replay(UserService.class);
Assert.assertEquals(UserKit.getAdminUserIdList(), adminUserIdList);
}
}

7
src/test/java/com/fanruan/api/util/DateKitTest.java

@ -15,4 +15,11 @@ public class DateKitTest {
Assert.assertEquals(DateKit.string2Date("abcd", false), new Date());
Assert.assertEquals(DateKit.string2Date("abcd", true), null);
}
@Test
public void testGetDate2Str() throws Exception {
String date = DateKit.getDate2Str("yyyy-MM-dd", new Date(0));
Assert.assertEquals(date, "1970-01-01");
}
}

Loading…
Cancel
Save