[JeeSite] role and permission modification (secondary development code analysis)

Keywords: SQL Database Java xml

@RequiresPermissions("sys:role:edit")
    @RequestMapping(value = "save")
    public String save(Role role, Model model, RedirectAttributes redirectAttributes) {
        if(!UserUtils.getUser().isAdmin()&&role.getSysData().equals(Global.YES)){
            addMessage(redirectAttributes, "Unauthorized operation, only super administrator can modify this data!");
            return "redirect:" + adminPath + "/sys/role/?repage";
        }
        if(Global.isDemoMode()){
            addMessage(redirectAttributes, "Demo mode, operation not allowed!");
            return "redirect:" + adminPath + "/sys/role/?repage";
        }
        if (!beanValidator(model, role)){
            return form(role, model);
        }
        if (!"true".equals(checkName(role.getOldName(), role.getName()))){
            addMessage(model, "Save roles'" + role.getName() + "'fail, Role name already exists");
            return form(role, model);
        }
        if (!"true".equals(checkEnname(role.getOldEnname(), role.getEnname()))){
            addMessage(model, "Save roles'" + role.getName() + "'fail, English name already exists");
            return form(role, model);
        }
        systemService.saveRole(role);
        addMessage(redirectAttributes, "Save roles'" + role.getName() + "'Success");
        return "redirect:" + adminPath + "/sys/role/?repage";
    }


========================================


@Transactional(readOnly = false)
    public void saveRole(Role role) {
        if (StringUtils.isBlank(role.getId())){
            role.preInsert();
            roleDao.insert(role);
            // Sync to Activiti
            saveActivitiGroup(role);
        }else{
            role.preUpdate();
            roleDao.update(role);
        }
        // Update role and menu context
        roleDao.deleteRoleMenu(role);
        if (role.getMenuList().size() > 0){
            roleDao.insertRoleMenu(role);
        }
        // Update role and Department Association
        roleDao.deleteRoleOffice(role);
        if (role.getOfficeList().size() > 0){
            roleDao.insertRoleOffice(role);
        }
        // Sync to Activiti
        saveActivitiGroup(role);
        // Clear user role cache
        UserUtils.removeCache(UserUtils.CACHE_ROLE_LIST);
//        //Clear rights cache
//        systemRealm.clearAllCachedAuthorizationInfo();
    }

========================================

The page passes the parameter menuIds. The parameter used for database storage is menuList. In the middle, setmenuids - > setmenuidlist - > menuList

public List<String> getMenuIdList() {
        List<String> menuIdList = Lists.newArrayList();
        for (Menu menu : menuList) {
            menuIdList.add(menu.getId());
        }
        return menuIdList;
    }

    public void setMenuIdList(List<String> menuIdList) {
        menuList = Lists.newArrayList();
        for (String menuId : menuIdList) {
            Menu menu = new Menu();
            menu.setId(menuId);
            menuList.add(menu);
        }
    }

    public String getMenuIds() {
        return StringUtils.join(getMenuIdList(), ",");
    }
    
    public void setMenuIds(String menuIds) {
        menuList = Lists.newArrayList();
        if (menuIds != null){
            String[] ids = StringUtils.split(menuIds, ",");
            setMenuIdList(Lists.newArrayList(ids));
        }
    }

role.java

 

Only paste the saved permission, omit the role, and the sql statement is a little abnormal. It's very long. Here is just the part of the generated sql statement intercepted

INSERT INTO sys_role_menu(role_id, menu_id) SELECT #{id}, #{menu.id} FROM dual

==========================================

INSERT INTO sys_role_menu(role_id, menu_id) SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual union all SELECT ?, ? FROM dual

The value of the node exists here when saving the submission,


submitHandler: function(form){ var ids = [], nodes = tree.getCheckedNodes(true); for(var i=0; i<nodes.length; i++) { ids.push(nodes[i].id); } $("#menuIds").val(ids); var ids2 = [], nodes2 = tree2.getCheckedNodes(true); for(var i=0; i<nodes2.length; i++) { ids2.push(nodes2[i].id); } $("#officeIds").val(ids2); loading('submitting, please wait '); form.submit(); },

One thing to note is that in the get method of roleDao.xml, column="officeList.id" is named after ro.office "ID as" officelist. ID ":

Form: the select tag is very useful. It also has the function of search and filter

form:select path="roleType" class="input-medium">
                    < form: option value = "assignment" > task assignment < / form: option >
                    < form: option value = "security role" > management role < / form: option >
                    < form: option value = "user" > normal role < / form: option >
                </form:select>

Task assignment management role general role

The repeated verification of user name is simple and easy to use. You can also use ajax to request asynchronously, but you will write more code.

Name already exists "}, enname: {remote:" English name already exists "}},

Posted by alan007 on Mon, 30 Dec 2019 23:56:53 -0800