Search in sources :

Example 1 with SysRoleModuleId

use of com.publiccms.entities.sys.SysRoleModuleId 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;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysRole(com.publiccms.entities.sys.SysRole) ArrayList(java.util.ArrayList) SysRoleModule(com.publiccms.entities.sys.SysRoleModule) SysSite(com.publiccms.entities.sys.SysSite) SysRoleModuleId(com.publiccms.entities.sys.SysRoleModuleId) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

LogOperate (com.publiccms.entities.log.LogOperate)1 SysRole (com.publiccms.entities.sys.SysRole)1 SysRoleModule (com.publiccms.entities.sys.SysRoleModule)1 SysRoleModuleId (com.publiccms.entities.sys.SysRoleModuleId)1 SysSite (com.publiccms.entities.sys.SysSite)1 ArrayList (java.util.ArrayList)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1