Commit 325116da by gdj

增加项目管理员枚举类。

parent 40dd3182
......@@ -118,6 +118,24 @@ public class SecurityUtils {
public static boolean isNotAdminRole() {
return !isAdminRole();
}
public static boolean isProjectAdminRole(Integer roleType) {
return roleType == RoleTypeEnum.PROJECT_ADMIN.getVal();
}
public static boolean isNotProjectAdminRole(Integer roleType) {
return !isProjectAdminRole(roleType);
}
public static boolean isProjectAdminRole() {
Integer roleType = getRoleType();
return isProjectAdminRole(roleType);
}
public static boolean isNotProjectAdminRole() {
return !isProjectAdminRole();
}
public static boolean isAdminRole(Integer roleType) {
return roleType == RoleTypeEnum.ADMIN.getVal();
}
......@@ -171,7 +189,7 @@ public class SecurityUtils {
return aboveMemberRole(roleType);
}
public static boolean aboveMemberRole(Integer roleType) {
int[] roleArr = {RoleTypeEnum.MEMBER.getVal(), RoleTypeEnum.PILOT.getVal(), RoleTypeEnum.ADMIN.getVal(), RoleTypeEnum.SYS_ADMIN.getVal()};
int[] roleArr = {RoleTypeEnum.MEMBER.getVal(), RoleTypeEnum.PILOT.getVal(), RoleTypeEnum.ADMIN.getVal(), RoleTypeEnum.PROJECT_ADMIN.getVal(), RoleTypeEnum.SYS_ADMIN.getVal()};
for(int role : roleArr){
if(roleType == role) {
......@@ -195,7 +213,7 @@ public class SecurityUtils {
}
public static boolean abovePilotRole(Integer roleType) {
int[] roleArr = {RoleTypeEnum.PILOT.getVal(), RoleTypeEnum.ADMIN.getVal(), RoleTypeEnum.SYS_ADMIN.getVal()};
int[] roleArr = {RoleTypeEnum.PILOT.getVal(), RoleTypeEnum.ADMIN.getVal(), RoleTypeEnum.PROJECT_ADMIN.getVal(), RoleTypeEnum.SYS_ADMIN.getVal()};
for(int role : roleArr){
if(roleType == role) {
......@@ -219,7 +237,7 @@ public class SecurityUtils {
}
public static boolean aboveAdminRole(Integer roleType) {
int[] roleArr = {RoleTypeEnum.ADMIN.getVal(), RoleTypeEnum.SYS_ADMIN.getVal()};
int[] roleArr = {RoleTypeEnum.ADMIN.getVal(), RoleTypeEnum.PROJECT_ADMIN.getVal(), RoleTypeEnum.SYS_ADMIN.getVal()};
for(int role : roleArr){
if(roleType == role) {
......@@ -229,6 +247,30 @@ public class SecurityUtils {
return false;
}
public static boolean aboveProjectAdminRoleAndThrowError() {
boolean result = aboveProjectAdminRole();
if (!result) {
throw new RuntimeException("The current role has no permissions");
}
return true;
}
public static boolean aboveProjectAdminRole() {
Integer roleType = getRoleType();
return aboveSysAdminRole(roleType);
}
public static boolean aboveProjectAdminRole(Integer roleType) {
int[] roleArr = {RoleTypeEnum.PROJECT_ADMIN.getVal(), RoleTypeEnum.SYS_ADMIN.getVal()};
for(int role : roleArr) {
if(roleType == role) {
return true;
}
}
return false;
}
public static boolean aboveSysAdminRoleAndThrowError() {
boolean result = aboveSysAdminRole();
if (!result) {
......
......@@ -12,6 +12,8 @@ public enum RoleTypeEnum {
PILOT(2, "飞手"),
PROJECT_ADMIN(50, "项目管理员"),
SYS_ADMIN(100, "系统管理员"),
UNKNOWN(-1, "Unknown");
......@@ -37,6 +39,9 @@ public enum RoleTypeEnum {
if (val == SYS_ADMIN.val) {
return SYS_ADMIN;
}
if (val == PROJECT_ADMIN.val) {
return PROJECT_ADMIN;
}
if (val == ADMIN.val) {
return ADMIN;
}
......
......@@ -202,6 +202,9 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, UserEntity> implem
// throw new RuntimeException("Failed to delete admin");
// }
// 然后 假如是删除管理员 不能删除 项目管理员
if (userEntity.getRoleType() == RoleTypeEnum.PROJECT_ADMIN.getVal()) {
throw new RuntimeException("can't delete workspace project admin");
}
if (userEntity.getRoleType() == RoleTypeEnum.ADMIN.getVal()) {
LambdaQueryWrapper<WorkspaceEntity> workspaceWrapper = new LambdaQueryWrapper<>();
workspaceWrapper.eq(WorkspaceEntity::getAdminUserId, userEntity.getUserId());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment