Search in sources :

Example 1 with UserNotFoundException

use of com.ganster.cms.core.exception.UserNotFoundException in project Ganster-CMS by Gangster-trio.

the class AllotGroupController method addGroup.

@RequestMapping("/add")
public void addGroup(@RequestParam(value = "UserId") Integer userId, @RequestParam(value = "GroupName") String groupName) {
    this.index();
    GroupExample groupExample = new GroupExample();
    groupExample.createCriteria().andGroupNameEqualTo(groupName);
    List<Group> groupList = groupService.selectByExample(groupExample);
    if (userId != null) {
        try {
            if (groupList == null) {
                RInformationUtil rInformationUtil = new RInformationUtil();
                rInformationUtil.dealInfromation(groupName);
                Group group = new Group();
                group.setGroupName(groupName);
                groupService.insert(group);
                groupService.addUserToGroup(userId, groupName);
            // groupService.addCategoryPermissionToGroup(groupName,"update:"+group.getGroupId());
            // groupService.addCategoryPermissionToGroup(groupName, "delete:" + group.getGroupId());
            // groupService.addCategoryPermissionToGroup(groupName,"find:"+group.getGroupId());
            } else {
                for (Group i : groupList) {
                    groupService.addUserToGroup(userId, i.getGroupName());
                }
            }
        } catch (UserNotFoundException e) {
            logger.info("用户未找到");
        } catch (GroupNotFountException e) {
            logger.info("用户组未找到");
        } catch (InformationException e) {
            logger.info("用户组信息不正确");
        } catch (PermissionNotFoundException e) {
            logger.info("用户组未找到");
        } catch (Exception e) {
            logger.info("信息错误");
        }
    }
}
Also used : UserNotFoundException(com.ganster.cms.core.exception.UserNotFoundException) InformationException(com.ganster.cms.auth.Exception.InformationException) Group(com.ganster.cms.core.pojo.Group) GroupNotFountException(com.ganster.cms.core.exception.GroupNotFountException) GroupExample(com.ganster.cms.core.pojo.GroupExample) RInformationUtil(com.ganster.cms.auth.util.RInformationUtil) PermissionNotFoundException(com.ganster.cms.core.exception.PermissionNotFoundException) GroupNotFountException(com.ganster.cms.core.exception.GroupNotFountException) PermissionNotFoundException(com.ganster.cms.core.exception.PermissionNotFoundException) UserNotFoundException(com.ganster.cms.core.exception.UserNotFoundException) InformationException(com.ganster.cms.auth.Exception.InformationException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with UserNotFoundException

use of com.ganster.cms.core.exception.UserNotFoundException in project Ganster-CMS by Gangster-trio.

the class PermissionServiceImplTest method interTest.

@Test
public void interTest() {
    final String userName = "@#$%^&";
    final String siteName = "$%^&&";
    User user = new User();
    user.setUserName(userName);
    userService.insert(user);
    Site site = new Site();
    site.setSiteName(siteName);
    siteService.insert(site);
    Group group = new Group();
    group.setGroupName(userName);
    groupService.insert(group);
    System.out.println(group.getGroupId());
    try {
        groupService.addUserToGroup(user.getUserId(), group.getGroupId());
    } catch (UserNotFoundException | GroupNotFountException e) {
        e.printStackTrace();
    }
    try {
        permissionService.addUserToSite(user.getUserId(), site.getSiteId());
    } catch (UserNotFoundException e) {
        e.printStackTrace();
    }
    List<Site> siteList = permissionService.findAllUserSite(user.getUserId());
    System.out.println(siteList);
    try {
        permissionService.addCategoryPermissionToUser(user.getUserId(), site.getSiteId(), 3, CmsConst.PERMISSION_READ);
    } catch (UserNotFoundException e) {
        e.printStackTrace();
    }
    boolean hasP = permissionService.hasCategoryPermission(user.getUserId(), site.getSiteId(), 3, CmsConst.PERMISSION_READ);
    Assert.assertTrue(hasP);
}
Also used : Site(com.ganster.cms.core.pojo.Site) UserNotFoundException(com.ganster.cms.core.exception.UserNotFoundException) Group(com.ganster.cms.core.pojo.Group) User(com.ganster.cms.core.pojo.User) GroupNotFountException(com.ganster.cms.core.exception.GroupNotFountException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with UserNotFoundException

use of com.ganster.cms.core.exception.UserNotFoundException in project Ganster-CMS by Gangster-trio.

the class SiteController method add.

@PostMapping("/add")
public Message add(@RequestBody Site site) {
    Integer userId = (Integer) SecurityUtils.getSubject().getSession().getAttribute("id");
    User user = userService.selectByPrimaryKey(userId);
    if (site == null) {
        return super.buildMessage(1, "no data", null);
    }
    site.setSiteCreateTime(new Date());
    site.setSiteStatus(0);
    int count = siteService.insert(site);
    if (count == 0) {
        return super.buildMessage(1, "add site failed", null);
    }
    try {
        if (!user.getUserName().equals("admin")) {
            permissionService.addUserToSite(1, site.getSiteId());
        }
        permissionService.addUserToSite(userId, site.getSiteId());
    } catch (UserNotFoundException e) {
        e.printStackTrace();
        return super.buildMessage(1, "用户未找到", null);
    }
    PermissionUtil.flush(userId);
    return super.buildMessage(0, "success", count);
}
Also used : UserNotFoundException(com.ganster.cms.core.exception.UserNotFoundException) User(com.ganster.cms.core.pojo.User) Date(java.util.Date)

Example 4 with UserNotFoundException

use of com.ganster.cms.core.exception.UserNotFoundException in project Ganster-CMS by Gangster-trio.

the class CategoryController method add.

@PostMapping("/add")
public Message add(@RequestBody Category category) {
    Integer userId = (Integer) SecurityUtils.getSubject().getSession().getAttribute("id");
    // 判断栏目内容是否为空
    if (category == null) {
        return super.buildMessage(1, "false", null);
    }
    // 判断登陆用户是否具有对栏目具有写的操作
    // 查询栏目对应的modelId
    ModuleExample moduleExample = new ModuleExample();
    moduleExample.or().andModuleNameEqualTo("栏目管理");
    Module module = moduleService.selectByExample(moduleExample).get(0);
    if (!permissionService.hasModulePermission(userId, category.getCategorySiteId(), module.getModuleId(), CmsConst.PERMISSION_WRITE)) {
        return super.buildMessage(2, "Null Permission", null);
    }
    // 插入栏目数据表的操作
    category.setCategoryCreateTime(new Date());
    category.setCategorySkin("default");
    Category parentCategory = categoryService.selectByPrimaryKey(category.getCategoryParentId());
    Integer level = parentCategory.getCategoryLevel();
    if (level == -1) {
        category.setCategoryLevel(0);
    } else {
        category.setCategoryLevel(level + 1);
    }
    int count = categoryService.insert(category);
    // 插入权限表的操作
    try {
        User user = userService.selectByPrimaryKey(userId);
        permissionService.addCategoryPermissionToUser(userId, category.getCategorySiteId(), category.getCategoryId(), CmsConst.PERMISSION_READ);
        permissionService.addCategoryPermissionToUser(userId, category.getCategorySiteId(), category.getCategoryId(), CmsConst.PERMISSION_WRITE);
        ArticleController.addPermission(category, user, userService, permissionService);
        PermissionUtil.flush(userId);
    } catch (UserNotFoundException e) {
        e.printStackTrace();
        return new Message(1, "false", "没有找到该用户");
    }
    if (count == 1) {
        return new Message(0, "success", count);
    } else {
        return new Message(1, "false", count);
    }
}
Also used : UserNotFoundException(com.ganster.cms.core.exception.UserNotFoundException) Message(com.ganster.cms.admin.dto.Message) Date(java.util.Date)

Aggregations

UserNotFoundException (com.ganster.cms.core.exception.UserNotFoundException)4 GroupNotFountException (com.ganster.cms.core.exception.GroupNotFountException)2 Group (com.ganster.cms.core.pojo.Group)2 User (com.ganster.cms.core.pojo.User)2 Date (java.util.Date)2 Message (com.ganster.cms.admin.dto.Message)1 InformationException (com.ganster.cms.auth.Exception.InformationException)1 RInformationUtil (com.ganster.cms.auth.util.RInformationUtil)1 PermissionNotFoundException (com.ganster.cms.core.exception.PermissionNotFoundException)1 GroupExample (com.ganster.cms.core.pojo.GroupExample)1 Site (com.ganster.cms.core.pojo.Site)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1