|
@@ -10,7 +10,6 @@ import com.boman.domain.SysRoleData;
|
|
|
import com.boman.domain.exception.UnSuchFunctionException;
|
|
|
import com.boman.system.api.RemoteMenuService;
|
|
|
import com.boman.system.api.RemoteRoleDataService;
|
|
|
-import com.boman.system.api.domain.SysMenu;
|
|
|
import com.boman.system.api.domain.SysUser;
|
|
|
import com.boman.system.api.model.LoginUser;
|
|
|
import com.boman.web.core.service.TableServiceCmdService;
|
|
@@ -52,6 +51,7 @@ public class TableContext {
|
|
|
private GenTable table;
|
|
|
private ActionType actionType;
|
|
|
private String tableName;
|
|
|
+ private String functionName;
|
|
|
private JSONObject fixedData;
|
|
|
private JSONObject commitData;
|
|
|
private List<GenTableColumn> columns;
|
|
@@ -62,6 +62,7 @@ public class TableContext {
|
|
|
context.setActionType(ltZero(dto.getObjId()) ? ActionType.INSERT : ActionType.UPDATE);
|
|
|
|
|
|
context.setId(dto.getObjId());
|
|
|
+ context.setFunctionName(table.getFunctionName());
|
|
|
String tableName = requireNonNull(dto.getTable(), "tableName is empty");
|
|
|
context.setTableName(tableName);
|
|
|
|
|
@@ -79,7 +80,7 @@ public class TableContext {
|
|
|
context.setPkName(pkName);
|
|
|
|
|
|
// 检查权限
|
|
|
- checkObjectSaveAuth(context);
|
|
|
+ checkAuthObjectSave(context);
|
|
|
|
|
|
JSONObject commitData = new JSONObject();
|
|
|
packCommitData(context, columns, fixedData, commitData);
|
|
@@ -89,42 +90,24 @@ public class TableContext {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void checkObjectSaveAuth(TableContext context) {
|
|
|
+ private void checkAuthObjectSave(TableContext context) {
|
|
|
GenTable genTable = context.getTable();
|
|
|
String tableName = genTable.getTableName();
|
|
|
- boolean isInsert = ActionType.INSERT.equals(context.getActionType());
|
|
|
- String fun = isInsert ? "新增功能" : "修改功能";
|
|
|
- containsFunction(genTable.getMenuRole(), GenTable.A, "此模块:[" + tableName + "], 没有" + fun);
|
|
|
+ String functionName = genTable.getFunctionName();
|
|
|
+
|
|
|
// 当前登陆人对应的menu,看看是否包含保存功能
|
|
|
LoginUser loginUser = getLoginUser();
|
|
|
- List<SysMenu> menus = remoteMenuService.listMenusByUserId(loginUser.getUserid());
|
|
|
if (SysUser.isAdmin(loginUser.getUserid())) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- List<String> permsList = map(menus, SysMenu::getPerms);
|
|
|
- if (isInsert) {
|
|
|
- String perms = packPermsKey(tableName, GenTable.A);
|
|
|
- if (!permsList.contains(perms)) {
|
|
|
- throw new UnSuchFunctionException("不好意思,您无权限操作");
|
|
|
- }
|
|
|
+ if (ActionType.INSERT.equals(context.getActionType())) {
|
|
|
+ containsFunction(genTable.getMenuRole(), GenTable.A, "模块:[" + functionName + "], 没有新增功能");
|
|
|
+ checkPermsAuth(tableName, GenTable.A);
|
|
|
} else {
|
|
|
- String perms = packPermsKey(tableName, GenTable.M);
|
|
|
- if (!permsList.contains(perms)) {
|
|
|
- throw new UnSuchFunctionException("不好意思,您无权限操作");
|
|
|
- }
|
|
|
-
|
|
|
- List<Long> roleIdList = getLoginUserRoleIdList();
|
|
|
- List<SysRoleData> roleDataList = remoteRoleDataService.listByRoleIdListTableName(joinList(roleIdList), tableName);
|
|
|
- if (isEmpty(roleDataList)) {
|
|
|
- //没有配,证明有此表的全部权限
|
|
|
- return;
|
|
|
- }
|
|
|
- String dataScope = roleDataList.get(0).getDataScope();
|
|
|
- // 不可以修改
|
|
|
- if (!countByCreteBy(dataScope, loginUser, context)) {
|
|
|
- throw new UnSuchFunctionException("不好意思,您无权限操作");
|
|
|
- }
|
|
|
+ containsFunction(genTable.getMenuRole(), GenTable.M, "模块:[" + functionName + "], 没有修改功能");
|
|
|
+ checkPermsAuth(tableName, GenTable.M);
|
|
|
+ checkRoleDataAuth(tableName, context.getPkName(), context.getId());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -162,27 +145,6 @@ public class TableContext {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 功能描述: 根据crete_by到数据库 count, 如果 >0 可以修改
|
|
|
- *
|
|
|
- * @param dataScope dataScope
|
|
|
- * @param loginUser loginUser
|
|
|
- * @param context context.getPkName() context.getId()
|
|
|
- * @return boolean
|
|
|
- */
|
|
|
- public boolean countByCreteBy(String dataScope, LoginUser loginUser, TableContext context) {
|
|
|
- JSONObject condition = new JSONObject();
|
|
|
- condition.put(context.getPkName(), context.getId());
|
|
|
- // 封装crete_by
|
|
|
- cmdService.packAuthCondition(dataScope, condition, loginUser);
|
|
|
- FormDataDto dto = new FormDataDto();
|
|
|
- dto.setTable(context.getTableName());
|
|
|
- dto.setFixedData(condition);
|
|
|
- int count = commonService.count(dto);
|
|
|
- return count > 0;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
/** get and set **/
|
|
|
|
|
|
public Long getId() {
|
|
@@ -248,4 +210,12 @@ public class TableContext {
|
|
|
public void setActionType(ActionType actionType) {
|
|
|
this.actionType = actionType;
|
|
|
}
|
|
|
+
|
|
|
+ public String getFunctionName() {
|
|
|
+ return functionName;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setFunctionName(String functionName) {
|
|
|
+ this.functionName = functionName;
|
|
|
+ }
|
|
|
}
|