Search in sources :

Example 1 with SysRole

use of com.publiccms.entities.sys.SysRole 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 SysRole

use of com.publiccms.entities.sys.SysRole in project PublicCMS-preview by sanluan.

the class SysRoleAdminController method delete.

/**
 * @param id
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("delete")
public String delete(Integer id, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysRole entity = service.getEntity(id);
    SysSite site = getSite(request);
    if (null != entity) {
        if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        service.delete(id);
        @SuppressWarnings("unchecked") List<SysRoleUser> roleUserList = (List<SysRoleUser>) roleUserService.getPage(id, null, null, null).getList();
        for (SysRoleUser roleUser : roleUserList) {
            userService.deleteRoleIds(roleUser.getId().getUserId(), id);
        }
        roleUserService.deleteByRoleId(id);
        roleModuleService.deleteByRoleId(id);
        roleAuthorizedService.deleteByRoleId(id);
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "delete.role", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysRole(com.publiccms.entities.sys.SysRole) ArrayList(java.util.ArrayList) List(java.util.List) SysSite(com.publiccms.entities.sys.SysSite) SysRoleUser(com.publiccms.entities.sys.SysRoleUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with SysRole

use of com.publiccms.entities.sys.SysRole in project PublicCMS-preview by sanluan.

the class SysSiteAdminController method save.

/**
 * @param entity
 * @param domainName
 * @param roleName
 * @param deptName
 * @param userName
 * @param password
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("save")
public String save(SysSite entity, String domainName, String roleName, String deptName, String userName, String password, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    if (ControllerUtils.verifyCustom("noright", !siteComponent.isMaster(site.getId()), model)) {
        return TEMPLATE_ERROR;
    }
    if (!entity.isUseStatic()) {
        entity.setUseSsi(false);
    }
    if (null != entity.getId()) {
        entity = service.update(entity.getId(), entity, ignoreProperties);
        if (null != entity) {
            logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.site", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
        }
    } else {
        if (ControllerUtils.verifyCustom("needAuthorizationEdition", !CmsVersion.isAuthorizationEdition(), model) || ControllerUtils.verifyCustom("unauthorizedDomain", !CmsVersion.verifyDomain(domainName), model) || ControllerUtils.verifyNotEmpty("userName", userName, model) || ControllerUtils.verifyNotEmpty("password", password, model) || ControllerUtils.verifyHasExist("domain", service.getEntity(domainName), model)) {
            return TEMPLATE_ERROR;
        }
        service.save(entity);
        SysDomain domain = new SysDomain(domainName, entity.getId(), false);
        domainService.save(domain);
        SysDept dept = new SysDept(entity.getId(), deptName, 0, true, true);
        // 初始化部门
        deptService.save(dept);
        SysRole role = new SysRole(entity.getId(), roleName, true, true);
        // 初始化角色
        roleService.save(role);
        SysUser user = new SysUser(entity.getId(), userName, VerificationUtils.md5Encode(password), userName, dept.getId(), role.getId().toString(), null, false, true, false, null, null, 0, CommonUtils.getDate());
        // 初始化用户
        userService.save(user);
        // 初始化角色用户映射
        roleUserService.save(new SysRoleUser(new SysRoleUserId(role.getId(), user.getId())));
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.site", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    siteComponent.clear();
    return TEMPLATE_DONEANDREFRESH;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysDomain(com.publiccms.entities.sys.SysDomain) SysUser(com.publiccms.entities.sys.SysUser) SysDept(com.publiccms.entities.sys.SysDept) SysRole(com.publiccms.entities.sys.SysRole) SysRoleUserId(com.publiccms.entities.sys.SysRoleUserId) SysSite(com.publiccms.entities.sys.SysSite) SysRoleUser(com.publiccms.entities.sys.SysRoleUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with SysRole

use of com.publiccms.entities.sys.SysRole in project PublicCMS-preview by sanluan.

the class SysRoleDirective method execute.

@Override
public void execute(RenderHandler handler) throws IOException, Exception {
    Integer id = handler.getInteger("id");
    SysSite site = getSite(handler);
    if (CommonUtils.notEmpty(id)) {
        SysRole entity = service.getEntity(id);
        if (null != entity && site.getId() == entity.getSiteId()) {
            handler.put("object", entity).render();
        }
    } else {
        Integer[] ids = handler.getIntegerArray("ids");
        if (CommonUtils.notEmpty(ids)) {
            List<SysRole> entityList = service.getEntitys(ids);
            Map<String, SysRole> map = new LinkedHashMap<>();
            for (SysRole entity : entityList) {
                if (site.getId() == entity.getSiteId()) {
                    map.put(String.valueOf(entity.getId()), entity);
                }
            }
            handler.put("map", map).render();
        }
    }
}
Also used : SysRole(com.publiccms.entities.sys.SysRole) SysSite(com.publiccms.entities.sys.SysSite) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with SysRole

use of com.publiccms.entities.sys.SysRole 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

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