Search in sources :

Example 1 with Site

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);
}
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 2 with Site

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;
}
Also used : Site(com.ganster.cms.core.pojo.Site) ModelResult(com.ganster.cms.web.dto.ModelResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Site

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);
    }
}
Also used : Site(com.ganster.cms.core.pojo.Site) SiteExample(com.ganster.cms.core.pojo.SiteExample)

Example 4 with Site

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());
}
Also used : Site(com.ganster.cms.core.pojo.Site) CategoryExample(com.ganster.cms.core.pojo.CategoryExample) List(java.util.List) ArticleExample(com.ganster.cms.core.pojo.ArticleExample)

Aggregations

Site (com.ganster.cms.core.pojo.Site)4 GroupNotFountException (com.ganster.cms.core.exception.GroupNotFountException)1 UserNotFoundException (com.ganster.cms.core.exception.UserNotFoundException)1 ArticleExample (com.ganster.cms.core.pojo.ArticleExample)1 CategoryExample (com.ganster.cms.core.pojo.CategoryExample)1 Group (com.ganster.cms.core.pojo.Group)1 SiteExample (com.ganster.cms.core.pojo.SiteExample)1 User (com.ganster.cms.core.pojo.User)1 ModelResult (com.ganster.cms.web.dto.ModelResult)1 List (java.util.List)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1