Package org.jtalks.common.model.permissions

Examples of org.jtalks.common.model.permissions.JtalksPermission


    public JtalksPermission findPluginsBranchPermissionByMask(int mask) {
        PluginFilter filter = new TypeFilter(PluginWithBranchPermissions.class);
        List<Plugin> plugins = pluginLoader.getPlugins(filter);
        for (Plugin plugin : plugins) {
            if (plugin.isEnabled()) {
                JtalksPermission permission = ((PluginWithBranchPermissions) plugin).getBranchPermissionByMask(mask);
                if (permission != null) {
                    return permission;
                }
            }
        }
View Full Code Here


    public JtalksPermission findPluginsBranchPermissionByName(String name) {
        PluginFilter filter = new TypeFilter(PluginWithBranchPermissions.class);
        List<Plugin> plugins = pluginLoader.getPlugins(filter);
        for (Plugin plugin : plugins) {
            if (plugin.isEnabled()) {
                JtalksPermission permission = ((PluginWithBranchPermissions)plugin).getBranchPermissionByName(name);
                if (permission != null) {
                    return permission;
                }
            }
        }
View Full Code Here

        verify(jtalksPermissionFactory).buildFromName(targetPermission.getName());
    }

    @Test
    public void buildFromNameShouldReturnAnyNotNullDefaultValueWhenNoPermissionFound() {
        JtalksPermission targetPermission = BranchPermission.VIEW_TOPICS;
        when(jtalksPermissionFactory.buildFromName(anyString())).thenReturn(null);
        when(pluginsPermissionFactory.buildFromName(anyString())).thenReturn(null);

        JCPermissionFactory permissionFactory = new JCPermissionFactory(jtalksPermissionFactory,pluginsPermissionFactory);
        Permission result = permissionFactory.buildFromName(targetPermission.getName());

        assertNotNull(result);
        verify(jtalksPermissionFactory).buildFromName(targetPermission.getName());
        verify(pluginsPermissionFactory).buildFromName(targetPermission.getName());
    }
View Full Code Here

        verify(pluginsPermissionFactory).buildFromName(targetPermission.getName());
    }

    @Test
    public void buildFromNamesShouldReturnBothOfCommonAndPluginPermissions() {
        JtalksPermission commonPermission = BranchPermission.VIEW_TOPICS;
        JtalksPermission pluginPermission = BranchPermission.CLOSE_TOPICS;
        List<String> names = Arrays.asList(commonPermission.getName(), pluginPermission.getName());
        List<Permission> expected = Arrays.asList((Permission)commonPermission, (Permission)pluginPermission);
        when(jtalksPermissionFactory.buildFromNames(names)).thenReturn(Arrays.asList((Permission)commonPermission));
        when(pluginsPermissionFactory.buildFromNames(names)).thenReturn(Arrays.asList((Permission)pluginPermission));

        JCPermissionFactory permissionFactory = new JCPermissionFactory(jtalksPermissionFactory,pluginsPermissionFactory);
View Full Code Here

    }

    @Test
    public void findPermissionByMaskShouldReturnPluginBranchPermissionIfNoCommonBranchPermissionFound() {
        int mask = -1;
        JtalksPermission targetPermission = BranchPermission.CLOSE_TOPICS;
        when(pluginPermissionManager.findPluginsBranchPermissionByMask(mask)).thenReturn(targetPermission);

        JtalksPermission result = manager.findBranchPermissionByMask(mask);

        assertEquals(result, targetPermission);
    }
View Full Code Here

    @ResponseBody
    public JsonResponse getGroupsForBranchPermission(@RequestBody BranchPermissionDto permissionInfo) {
        long forumId = componentService.getComponentOfForum().getId();
        PermissionGroupsDto permission = new PermissionGroupsDto();

        JtalksPermission branchPermission = permissionManager.findBranchPermissionByMask(permissionInfo.getPermissionMask());
        List<Group> selectedGroups;
        try {
            selectedGroups = branchService.getPermissionGroupsFor(forumId, permissionInfo.getBranchId(),
                    permissionInfo.isAllowed(), branchPermission);
        } catch (NotFoundException e) {
View Full Code Here

     */
    @RequestMapping(value = "/branch/permissions/edit", method = RequestMethod.POST)
    @ResponseBody
    public JsonResponse editBranchPermissions(@RequestBody BranchPermissionDto permissionInfo) {
        long forumId = componentService.getComponentOfForum().getId();
        JtalksPermission branchPermission =  permissionManager.findBranchPermissionByMask(permissionInfo.getPermissionMask());

        List<Group> newlyAddedGroups = permissionManager.getGroupsByIds(permissionInfo.getNewlyAddedGroupIds());
        List<Group> removedGroups = permissionManager.getGroupsByIds(permissionInfo.getRemovedGroupIds());

        PermissionChanges changes = new PermissionChanges(branchPermission, newlyAddedGroups, removedGroups);
View Full Code Here

        assertEquals(actual, Collections.EMPTY_LIST);
    }

    @Test
    public void findPluginBranchPermissionByMaskShouldReturnPermissionIfPluginEnabled() {
        JtalksPermission targetPermission = BranchPermission.VIEW_TOPICS;
        when(pluginWithBranchPermissions.getBranchPermissionByMask(targetPermission.getMask())).thenReturn(targetPermission);
        when(pluginWithBranchPermissions.isEnabled()).thenReturn(true);

        PluginPermissionManager pluginPermissionManager = new PluginPermissionManager(pluginLoader);
        JtalksPermission actual = pluginPermissionManager.findPluginsBranchPermissionByMask(targetPermission.getMask());

        assertEquals(actual, targetPermission);
    }
View Full Code Here

        assertEquals(actual, targetPermission);
    }

    @Test
    public void findPluginBranchPermissionByMaskShouldReturnNullIfPluginDisabled() {
        JtalksPermission targetPermission = BranchPermission.VIEW_TOPICS;
        when(pluginWithBranchPermissions.getBranchPermissionByMask(targetPermission.getMask())).thenReturn(targetPermission);
        when(pluginWithBranchPermissions.isEnabled()).thenReturn(false);

        PluginPermissionManager pluginPermissionManager = new PluginPermissionManager(pluginLoader);
        JtalksPermission result = pluginPermissionManager.findPluginsBranchPermissionByMask(targetPermission.getMask());

        assertNull(result);
    }
View Full Code Here

    public void findPluginBranchPermissionByMaskShouldReturnNullIfNoPermissionFound() {
        when(pluginWithBranchPermissions.getBranchPermissionByMask(anyInt())).thenReturn(null);
        when(pluginWithBranchPermissions.isEnabled()).thenReturn(true);

        PluginPermissionManager pluginPermissionManager = new PluginPermissionManager(pluginLoader);
        JtalksPermission actual = pluginPermissionManager.findPluginsBranchPermissionByMask(1);

        assertNull(actual);
    }
View Full Code Here

TOP

Related Classes of org.jtalks.common.model.permissions.JtalksPermission

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.