Search in sources :

Example 1 with SysRoleModule

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;
}
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)

Example 2 with SysRoleModule

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();
            }
        }
    }
}
Also used : SysRoleModule(com.publiccms.entities.sys.SysRoleModule) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with SysRoleModule

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

Example 4 with SysRoleModule

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

Example 5 with SysRoleModule

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);
        }
    }
}
Also used : SysRole(com.publiccms.entities.sys.SysRole) SysRoleModule(com.publiccms.entities.sys.SysRoleModule) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

SysRoleModule (com.publiccms.entities.sys.SysRoleModule)5 LogOperate (com.publiccms.entities.log.LogOperate)3 SysSite (com.publiccms.entities.sys.SysSite)3 List (java.util.List)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 SysRole (com.publiccms.entities.sys.SysRole)2 SysModule (com.publiccms.entities.sys.SysModule)1 SysRoleModuleId (com.publiccms.entities.sys.SysRoleModuleId)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1