use of com.publiccms.entities.sys.SysRoleModule in project PublicCMS-preview by sanluan.
the class SysRoleAdminController method save.
/**
* @param entity
* @param moduleIds
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("save")
public String save(SysRole entity, Integer[] moduleIds, HttpServletRequest request, HttpSession session, ModelMap model) {
SysSite site = getSite(request);
if (entity.isOwnsAllRight()) {
moduleIds = null;
entity.setShowAllModule(false);
}
if (null != entity.getId()) {
SysRole oldEntity = service.getEntity(entity.getId());
if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
return TEMPLATE_ERROR;
}
entity = service.update(entity.getId(), entity, ignoreProperties);
roleModuleService.updateRoleModules(entity.getId(), moduleIds);
if (null != entity) {
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.role", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
} else {
entity.setSiteId(site.getId());
service.save(entity);
if (CommonUtils.notEmpty(moduleIds)) {
List<SysRoleModule> list = new ArrayList<>();
for (int moduleId : moduleIds) {
list.add(new SysRoleModule(new SysRoleModuleId(entity.getId(), moduleId)));
}
roleModuleService.save(list);
}
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.role", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
roleAuthorizedService.dealRoleModules(entity.getId(), entity.isShowAllModule(), moduleService.getEntitys(moduleIds), moduleService.getPageUrl(null));
return TEMPLATE_DONE;
}
use of com.publiccms.entities.sys.SysRoleModule in project PublicCMS-preview by sanluan.
the class SysRoleModuleDirective method execute.
@Override
public void execute(RenderHandler handler) throws IOException, Exception {
Integer[] roleIds = handler.getIntegerArray("roleIds");
Integer moduleId = handler.getInteger("moduleId");
if (CommonUtils.notEmpty(roleIds)) {
if (CommonUtils.notEmpty(moduleId)) {
SysRoleModule entity = service.getEntity(roleIds, moduleId);
handler.put("object", entity).render();
} else {
Integer[] moduleIds = handler.getIntegerArray("moduleIds");
if (CommonUtils.notEmpty(moduleIds)) {
Map<String, Boolean> map = new LinkedHashMap<>();
if (sysRoleService.showAllModule(roleIds)) {
for (Integer id : moduleIds) {
map.put(String.valueOf(id), true);
}
} else {
for (SysRoleModule entity : service.getEntitys(roleIds, moduleIds)) {
map.put(String.valueOf(entity.getId().getModuleId()), true);
}
}
handler.put("map", map).render();
}
}
}
}
use of com.publiccms.entities.sys.SysRoleModule in project PublicCMS-preview by sanluan.
the class SysModuleAdminController method delete.
/**
* @param id
* @param request
* @param session
* @param model
* @return view name
*/
@SuppressWarnings("unchecked")
@RequestMapping("delete")
public String delete(Integer id, HttpServletRequest request, HttpSession session, ModelMap model) {
SysSite site = getSite(request);
if (ControllerUtils.verifyCustom("noright", !siteComponent.isMaster(site.getId()), model)) {
return TEMPLATE_ERROR;
}
SysModule entity = service.getEntity(id);
if (null != entity) {
service.delete(id);
List<SysRoleModule> roleModuleList = (List<SysRoleModule>) roleModuleService.getPage(null, id, null, null).getList();
roleModuleService.deleteByModuleId(id);
dealRoleAuthorized(roleModuleList);
logOperateService.save(new LogOperate(getSite(request).getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "delete.module", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
return TEMPLATE_DONE;
}
use of com.publiccms.entities.sys.SysRoleModule in project PublicCMS-preview by sanluan.
the class SysModuleAdminController method save.
/**
* @param entity
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("save")
public String save(SysModule entity, HttpServletRequest request, HttpSession session, ModelMap model) {
SysSite site = getSite(request);
if (ControllerUtils.verifyCustom("noright", !siteComponent.isMaster(site.getId()), model)) {
return TEMPLATE_ERROR;
}
if (null != entity.getId()) {
entity = service.update(entity.getId(), entity, ignoreProperties);
if (null != entity) {
@SuppressWarnings("unchecked") List<SysRoleModule> roleModuleList = (List<SysRoleModule>) roleModuleService.getPage(null, entity.getId(), null, null).getList();
dealRoleAuthorized(roleModuleList);
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.module", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
} else {
service.save(entity);
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.module", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
return TEMPLATE_DONE;
}
use of com.publiccms.entities.sys.SysRoleModule in project PublicCMS-preview by sanluan.
the class SysModuleAdminController method dealRoleAuthorized.
@SuppressWarnings("unchecked")
private void dealRoleAuthorized(List<SysRoleModule> roleModuleList) {
Set<String> pageUrls = moduleService.getPageUrl(null);
for (SysRoleModule roleModule : roleModuleList) {
Set<Integer> moduleIds = new HashSet<Integer>();
for (SysRoleModule roleModule2 : (List<SysRoleModule>) roleModuleService.getPage(roleModule.getId().getRoleId(), null, null, null).getList()) {
moduleIds.add(roleModule2.getId().getModuleId());
}
SysRole role = roleService.getEntity(roleModule.getId().getRoleId());
if (!moduleIds.isEmpty() && null != role && !role.isOwnsAllRight()) {
roleAuthorizedService.dealRoleModules(roleModule.getId().getRoleId(), role.isShowAllModule(), service.getEntitys(moduleIds.toArray(new Integer[moduleIds.size()])), pageUrls);
}
}
}
Aggregations