Package org.jtalks.jcommune.model.dto

Examples of org.jtalks.jcommune.model.dto.GroupsPermissions


    public void showBranchPermissionsShouldReturnModelAndViewWithBranchAndPermissionsInformation()
            throws Exception {
        long branchId = 42;
        Component component = setupComponentMock();

        GroupsPermissions expectedPermissions = new GroupsPermissions();
        Branch expectedBranch = new Branch("name", "description");
        when(branchService.get(branchId)).thenReturn(expectedBranch);
        doReturn(expectedPermissions).when(branchService).getPermissionsFor(component.getId(), branchId);

        mockMvc = MockMvcBuilders.standaloneSetup(administrationController).build();
View Full Code Here


    @Test
    public void testGetPermissionsMapForBranch() throws Exception {
        Branch branch = PersistedObjectsFactory.getDefaultBranch();
        givenPermissions(branch, BranchPermission.values());

        GroupsPermissions groupsPermissions = manager.getPermissionsMapFor(branch);
        verify(pluginPermissionManager).getPluginsBranchPermissions();
        verify(aclManager).getGroupPermissionsOn(branch);
        verify(aclUtil, times(BranchPermission.values().length)).getAclFor(branch);
        assertTrue(groupsPermissions.getPermissions().containsAll(permissions));
        for (GroupAce groupAce : groupAces) {
            List<Group> groups = groupsPermissions.get(groupAce.getPermission(), groupAce.isGranting());
            assertNotNull(getGroupWithId(groups, groupAce.getGroupId()));
            assertTrue(groups.contains(AnonymousGroup.ANONYMOUS_GROUP));
        }
    }
View Full Code Here

     *
     */
    @RequestMapping(value = "/branch/permissions/{branchId}", method = RequestMethod.GET)
    public ModelAndView showBranchPermissions(@PathVariable("branchId") long branchId) throws NotFoundException {
        long forumId = componentService.getComponentOfForum().getId();
        GroupsPermissions permissions = branchService.getPermissionsFor(forumId, branchId);
        Branch branch = branchService.get(branchId);
        return new ModelAndView("branchPermissions")
                .addObject("branch", branch)
                .addObject("permissions", permissions);
    }
View Full Code Here

     */
    @Override
    @PreAuthorize("hasPermission(#componentId, 'COMPONENT', 'GeneralPermission.ADMIN')")
    public <T extends JtalksPermission> List<Group> getPermissionGroupsFor(long componentId, long branchId, boolean allowed, T permission)
            throws NotFoundException {
        GroupsPermissions allPermissions = permissionService.getPermissionsFor(get(branchId));
        if (allowed) {
            return allPermissions.getAllowed(permission);
        }

        return allPermissions.getRestricted(permission);
    }
View Full Code Here

    }

    @Test
    public void getPermissionsShouldReturnPermissionsWhenBranchExist() throws Exception {
        long branchId = 42;
        GroupsPermissions expectedPermissions = new GroupsPermissions();

        Branch expectedBranch = new Branch("name", "description");
        when(branchDao.isExist(branchId)).thenReturn(true);
        when(branchDao.get(branchId)).thenReturn(expectedBranch);
        doReturn(expectedPermissions).when(permissionService).getPermissionsFor(expectedBranch);

        GroupsPermissions permissions = branchService.getPermissionsFor(0, branchId);
        assertEquals(permissions, expectedPermissions);
    }
View Full Code Here

    @Test
    public void getPermissionGroupsShouldReturnAllowedPermissionGroupsWhenBranchExist() throws Exception {
        long branchId = 42;
        BranchPermission permission = BranchPermission.CLOSE_TOPICS;
        GroupsPermissions expectedPermissions = new GroupsPermissions();
        expectedPermissions.addAllowed(permission, new Group("1"));

        Branch expectedBranch = new Branch("name", "description");
        when(branchDao.isExist(branchId)).thenReturn(true);
        when(branchDao.get(branchId)).thenReturn(expectedBranch);
        doReturn(expectedPermissions).when(permissionService).getPermissionsFor(expectedBranch);

        List<Group> result = branchService.getPermissionGroupsFor(0, branchId, true, permission);
        assertEquals(result, expectedPermissions.getAllowed(permission));
    }
View Full Code Here

    @Test
    public void getPermissionGroupsShouldReturnRestrictedPermissionGroupsWhenBranchExist() throws Exception {
        long branchId = 42;
        BranchPermission permission = BranchPermission.CLOSE_TOPICS;
        GroupsPermissions expectedPermissions = new GroupsPermissions();
        expectedPermissions.addRestricted(permission, new Group("1"));

        Branch expectedBranch = new Branch("name", "description");
        when(branchDao.isExist(branchId)).thenReturn(true);
        when(branchDao.get(branchId)).thenReturn(expectedBranch);
        doReturn(expectedPermissions).when(permissionService).getPermissionsFor(expectedBranch);

        List<Group> result = branchService.getPermissionGroupsFor(0, branchId, false, permission);
        assertEquals(result, expectedPermissions.getRestricted(permission));
    }
View Full Code Here

     */
    public GroupsPermissions getPermissionsMapFor(List<Group> groups) {
        List<JtalksPermission> profilePermissions = new ArrayList<>();
        profilePermissions.addAll(ProfilePermission.getAllAsList());

        GroupsPermissions permissions = new GroupsPermissions(profilePermissions);
        for (Group group : groups) {
            GroupsPermissions pmGroup = getPermissionsMapFor(profilePermissions, group);
            for (JtalksPermission permission : pmGroup.getPermissions()) {
                for (Group groupInsert : pmGroup.getAllowed(permission)) {
                    permissions.addAllowed(permission, groupInsert);
                }
                for (Group groupInsert : pmGroup.getRestricted(permission)) {
                    permissions.addRestricted(permission, groupInsert);
                }
            }
        }
        return permissions;
View Full Code Here

     * @param permissions the list of permissions to get
     * @param entity      the entity to get for
     * @return {@link org.jtalks.jcommune.model.dto.GroupsPermissions} for provided {@link org.jtalks.common.model.entity.Entity}
     */
    public GroupsPermissions getPermissionsMapFor(List<JtalksPermission> permissions, Entity entity) {
        GroupsPermissions groupsPermissions = new GroupsPermissions(permissions);
        List<GroupAce> groupAces = aclManager.getGroupPermissionsOn(entity);
        for (JtalksPermission permission : permissions) {
            for (GroupAce groupAce : groupAces) {
                if (groupAce.getPermissionMask() == permission.getMask()) {
                    groupsPermissions.add(permission, getGroup(groupAce), groupAce.isGranting());
                }
            }
            for (AccessControlEntry controlEntry : aclUtil.getAclFor(entity).getEntries()) {
                if (controlEntry.getPermission().equals(permission)
                        && ((UniversalSid)controlEntry.getSid()).getSidId().equals(UserSid.createAnonymous().getSidId())) {
                    groupsPermissions.add(permission, AnonymousGroup.ANONYMOUS_GROUP, controlEntry.isGranting());
                }
            }
        }
        return groupsPermissions;
    }
View Full Code Here

    }

    @Test
    public void testGetPermissionsFor() {
        Branch branch = mock(Branch.class);
        doReturn(new GroupsPermissions()).when(permissionManager).getPermissionsMapFor(branch);
        assertNotNull(permissionService.getPermissionsFor(branch));
    }
View Full Code Here

TOP

Related Classes of org.jtalks.jcommune.model.dto.GroupsPermissions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.