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("信息错误");
}
}
}
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);
}
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);
}
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);
}
}
Aggregations