use of com.ganster.cms.core.pojo.Site 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.pojo.Site in project Ganster-CMS by Gangster-trio.
the class SiteController method show.
@RequestMapping("/{siteUrl}")
public String show(@PathVariable("siteUrl") String siteUrl, Model model) {
ModelResult result = webService.getSiteModel(siteUrl);
if (result == null) {
return "404";
}
// Add result to module
model.addAttribute("result", result);
Site site = (Site) result.get("site");
// If skin = null, set default skin
if (site.getSiteSkin() == null) {
site.setSiteSkin(CmsConst.DEFAULT_SKIN);
}
// Return to the site's skin view, for example : default-site
return site.getSiteSkin() + CmsConst.SITE_SKIN_SUFFIX;
}
use of com.ganster.cms.core.pojo.Site in project Ganster-CMS by Gangster-trio.
the class SiteController method list.
@GetMapping("/list")
public AjaxData list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) {
Integer userId = (Integer) SecurityUtils.getSubject().getSession().getAttribute("id");
SiteExample siteExample = new SiteExample();
List<Integer> siteIdList = PermissionUtil.getAllPermissionSite(userId);
if (siteIdList == null || siteIdList.isEmpty()) {
return super.buildAjaxData(2, "no privilege", 0, null);
}
siteExample.or().andSiteIdIn(siteIdList);
PageInfo<Site> pageInfo = PageHelper.startPage(page, limit).doSelectPageInfo(() -> siteService.selectByExample(siteExample));
List<Site> siteList = pageInfo.getList();
if (siteList == null || siteList.isEmpty()) {
return super.buildAjaxData(0, "success", 0, null);
} else {
return super.buildAjaxData(0, "success", pageInfo.getTotal(), siteList);
}
}
use of com.ganster.cms.core.pojo.Site in project Ganster-CMS by Gangster-trio.
the class TypeDirective method execute.
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
String cateType = DirectiveUtil.getString(PARAM_CATEGORY_TYPE, params);
String articleType = DirectiveUtil.getString(PARAM_ARTICLE_TYPE, params);
String sort = DirectiveUtil.getString(PARAM_SORT, params);
Integer size = DirectiveUtil.getInteger(PARAM_SIZE, params);
Integer page = DirectiveUtil.getInteger(PARAM_PAGE, params);
Site site = DirectiveUtil.getSite(env);
if (site == null) {
throw new TemplateException("site can't found", env);
}
// 异或非运算 有且仅有一个不为null
if ((cateType == null) == (articleType == null)) {
throw new TemplateException(PARAM_ARTICLE_TYPE + " and " + PARAM_CATEGORY_TYPE + " only one must be specified.", env);
}
if (size == null) {
size = 0;
}
if (page == null) {
page = 0;
}
if (sort == null) {
if (cateType != null)
sort = DEFAULT_CATE_SORT;
if (articleType != null)
sort = DEFAULT_ARTICLE_SORT;
}
List retList;
if (cateType != null) {
CategoryExample categoryExample = new CategoryExample();
categoryExample.or().andCategoryTypeEqualTo(cateType).andCategorySiteIdEqualTo(site.getSiteId());
categoryExample.setOrderByClause(sort);
retList = PageHelper.startPage(page, size).doSelectPage(() -> categoryService.selectByExample(categoryExample));
} else {
ArticleExample articleExample = new ArticleExample();
articleExample.or().andArticleTypeEqualTo(articleType).andArticleSiteIdEqualTo(site.getSiteId());
articleExample.setOrderByClause(sort);
retList = PageHelper.startPage(page, size).doSelectPage(() -> articleService.selectByExample(articleExample));
}
DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.getVersion());
env.setVariable(DirectiveUtil.getRetName(PARAM_RET, params), builder.build().wrap(retList));
body.render(env.getOut());
}
Aggregations