|
|
@@ -7,10 +7,12 @@ import com.github.microservice.auth.client.model.RoleGroupModel;
|
|
|
import com.github.microservice.auth.client.service.AuthResourcesNameService;
|
|
|
import com.github.microservice.auth.security.type.AuthType;
|
|
|
import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
-import com.zhongshu.card.client.model.org.*;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
import com.github.microservice.net.ResultMessage;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.zhongshu.card.client.model.org.AuthModel;
|
|
|
+import com.zhongshu.card.client.model.org.EditAuthParam;
|
|
|
+import com.zhongshu.card.client.model.org.ModularModel;
|
|
|
import com.zhongshu.card.client.model.org.role.RoleAddParam;
|
|
|
import com.zhongshu.card.client.model.org.role.RoleModel;
|
|
|
import com.zhongshu.card.client.model.org.role.RoleQueryParam;
|
|
|
@@ -23,11 +25,13 @@ import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.OrganizationUserDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.RoleDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.UserCountDao;
|
|
|
+import com.zhongshu.card.server.core.dataConfig.CardSystemDefault;
|
|
|
import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
import com.zhongshu.card.server.core.domain.org.OrganizationUser;
|
|
|
import com.zhongshu.card.server.core.domain.org.Role;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
+import com.zhongshu.card.server.core.util.AesUtils;
|
|
|
import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -35,9 +39,7 @@ import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
-import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Assert;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
@@ -420,9 +422,10 @@ public class RoleServiceImpl extends SuperService {
|
|
|
} else {
|
|
|
auth.removeAll(param.getAuths());
|
|
|
}
|
|
|
- Organization organization = organizationDao.findTopByOid(role.getOid());
|
|
|
+
|
|
|
// 管理员角色默认有 管理员的权限
|
|
|
if (role.getIsAdmin() != null && role.getIsAdmin()) {
|
|
|
+ Organization organization = organizationDao.findTopByOid(role.getOid());
|
|
|
if (organization != null && organization.getAuthType() == AuthType.Platform) {
|
|
|
auth.add(AuthConstant.SuperAdmin);
|
|
|
} else {
|
|
|
@@ -469,10 +472,50 @@ public class RoleServiceImpl extends SuperService {
|
|
|
return auth;
|
|
|
}
|
|
|
for (OrganizationUser organizationUser : organizationUsers) {
|
|
|
- Organization organization = organizationUser.getOrganization();
|
|
|
- String oid = organization.getOid();
|
|
|
+ auth.addAll(getOrganizationUserAuths(organizationUser));
|
|
|
+ }
|
|
|
+ return auth;
|
|
|
+ }
|
|
|
|
|
|
- List<Role> roles = organizationUser.getRoles();
|
|
|
+ /**
|
|
|
+ * 得到当前用户在 指定的项目权限(加密后)
|
|
|
+ *
|
|
|
+ * @param projectOid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent getCurrentUserProjectAuth(String projectOid) {
|
|
|
+ Set<String> auths = getUserProjectAllAuths(projectOid, getCurrentUserId());
|
|
|
+ return ResultContent.buildSuccess(AesUtils.encryptAuth(auths));
|
|
|
+ }
|
|
|
+
|
|
|
+ public Set<String> getUserProjectAllAuths(String projectOid, String userId) {
|
|
|
+ Set<String> auth = new HashSet<>();
|
|
|
+ if (StringUtils.isEmpty(userId)) {
|
|
|
+ return auth;
|
|
|
+ }
|
|
|
+ UserAccount userAccount = userCountDao.findTopByUserId(userId);
|
|
|
+ if (ObjectUtils.isEmpty(userAccount)) {
|
|
|
+ return auth;
|
|
|
+ }
|
|
|
+ List<OrganizationUser> organizationUsers = organizationUserDao.findByUserIdAndProjectOid(userAccount.getUserId(), projectOid);
|
|
|
+ if (ObjectUtils.isEmpty(organizationUsers)) {
|
|
|
+ return auth;
|
|
|
+ }
|
|
|
+ for (OrganizationUser organizationUser : organizationUsers) {
|
|
|
+ auth.addAll(getOrganizationUserAuths(organizationUser));
|
|
|
+ }
|
|
|
+ return auth;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 得到机构用户数据权限
|
|
|
+ *
|
|
|
+ * @param organizationUser
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Set<String> getOrganizationUserAuths(OrganizationUser organizationUser) {
|
|
|
+ Set<String> auth = new HashSet<>();
|
|
|
+ if (ObjectUtils.isNotEmpty(organizationUser)) {
|
|
|
|
|
|
// var roleGroupModels = roleService.listRoleGroupFromOrganizationUser(oid, userId).getContent();
|
|
|
// if (!CollectionUtils.isEmpty(roleGroupModels)) {
|
|
|
@@ -488,7 +531,7 @@ public class RoleServiceImpl extends SuperService {
|
|
|
// });
|
|
|
// }
|
|
|
|
|
|
-
|
|
|
+ List<Role> roles = organizationUser.getRoles();
|
|
|
if (ObjectUtils.isNotEmpty(roles)) {
|
|
|
roles.stream().forEach(tempRole -> {
|
|
|
var role = roleService.getRole(tempRole.getRoleId()).getContent();
|
|
|
@@ -496,7 +539,6 @@ public class RoleServiceImpl extends SuperService {
|
|
|
auth.addAll(role.getAuth());
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
List<Role> _list = roles.stream().filter(it -> {
|
|
|
return it.getIsAdmin();
|
|
|
}).collect(Collectors.toList());
|
|
|
@@ -614,6 +656,70 @@ public class RoleServiceImpl extends SuperService {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始机构的管理员角色
|
|
|
+ *
|
|
|
+ * @param organization
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent initOrgManagerRole(Organization organization) {
|
|
|
+ if (ObjectUtils.isNotEmpty(organization)) {
|
|
|
+ Role adminRole = roleDao.findTopByNameAndOid(CardSystemDefault.DEFAULT_ROLE_NAME, organization.getOid());
|
|
|
+ if (ObjectUtils.isEmpty(adminRole)) {
|
|
|
+ Set<String> auth = Set.of(AuthConstant.Admin);
|
|
|
+ if (organization.getAuthType().equals(AuthType.Platform)) {
|
|
|
+ auth = Set.of(AuthConstant.SuperAdmin);
|
|
|
+ }
|
|
|
+
|
|
|
+ String defaultName = CardSystemDefault.DEFAULT_ROLE_NAME;
|
|
|
+ String defaultReMark = CardSystemDefault.DEFAULT_ROLE_NAME;
|
|
|
+ String oid = organization.getOid();
|
|
|
+ // 权限中心: 角色组
|
|
|
+ RoleGroupModel admin = new RoleGroupModel();
|
|
|
+ admin.setName(defaultName);
|
|
|
+ admin.setRemark(defaultReMark);
|
|
|
+ admin.setOrganizationId(oid);
|
|
|
+ admin.setIdentity(auth);
|
|
|
+ com.github.microservice.auth.client.content.ResultContent<String> updateRoleGroupAdmin = roleService.updateRoleGroup(admin);
|
|
|
+ String groupId = updateRoleGroupAdmin.getContent();
|
|
|
+ log.info("初始权限中心角色组成功:{}", groupId);
|
|
|
+
|
|
|
+ if (!StringUtils.isEmpty(groupId)) {
|
|
|
+ // 权限中心: 角色信息
|
|
|
+ com.github.microservice.auth.client.model.RoleModel roleModel = new com.github.microservice.auth.client.model.RoleModel();
|
|
|
+ roleModel.setOrganizationId(oid);
|
|
|
+ roleModel.setName(defaultName);
|
|
|
+ roleModel.setRemark(defaultReMark);
|
|
|
+ roleModel.setAuth(auth);
|
|
|
+ com.github.microservice.auth.client.content.ResultContent<String> updateRole = roleService.updateRole(roleModel);
|
|
|
+
|
|
|
+ log.info("权限中心:初始角色和角色组关系成功");
|
|
|
+ String roleId = updateRole.getContent();
|
|
|
+ roleService.addRoleToRoleGroup(groupId, new String[]{roleId});
|
|
|
+
|
|
|
+ // 添加本地机构角色信息
|
|
|
+ adminRole = new Role();
|
|
|
+ if (organization.getAuthType().equals(AuthType.Platform)) {
|
|
|
+ adminRole.setCode(AuthConstant.SuperAdmin);
|
|
|
+ } else {
|
|
|
+ adminRole.setCode(AuthConstant.Admin);
|
|
|
+ }
|
|
|
+ adminRole.setAuth(auth);
|
|
|
+ adminRole.setOid(oid);
|
|
|
+ adminRole.setRoleGroupId(groupId);
|
|
|
+ adminRole.setName(defaultName);
|
|
|
+ adminRole.setRemark(defaultReMark);
|
|
|
+ adminRole.setRoleType(RoleType.BuildIn);
|
|
|
+ adminRole.setIsAdmin(Boolean.TRUE);
|
|
|
+ adminRole.setRoleId(roleId);
|
|
|
+ adminRole.setAuthType(organization.getAuthType());
|
|
|
+ roleDao.save(adminRole);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
public List<RoleModel> toModels(List<Role> roles) {
|
|
|
if (ObjectUtils.isNotEmpty(roles)) {
|
|
|
return roles.stream().map(this::toModel).collect(Collectors.toList());
|