Пример #1
0
  /** Save the permissions for this group */
  public void savePermissions(int groupId, PermissionOptions permissions) {
    Group group = this.repository.get(groupId);

    RoleManager currentRoles = new RoleManager();
    currentRoles.setGroups(Arrays.asList(group));

    group.getRoles().clear();

    boolean isAdministrator = currentRoles.isAdministrator();
    boolean canManageForums = currentRoles.roleExists(SecurityConstants.CAN_MANAGE_FORUMS);
    boolean isCoAdministrator = currentRoles.isCoAdministrator();

    List<Integer> groups = new ArrayList<Integer>();
    for (int gid : currentRoles.getRoleValues(SecurityConstants.GROUPS)) {
      groups.add(gid);
    }

    boolean canInteractwithOtherGroups =
        currentRoles.roleExists(SecurityConstants.INTERACT_OTHER_GROUPS);
    boolean isSuperAdministrator =
        this.sessionManager.getUserSession().getRoleManager().isAdministrator();

    this.registerRole(
        group,
        SecurityConstants.ADMINISTRATOR,
        isSuperAdministrator ? permissions.isAdministrator() : isAdministrator);
    this.registerRole(
        group,
        SecurityConstants.CAN_MANAGE_FORUMS,
        isSuperAdministrator ? permissions.getCanManageForums() : canManageForums);
    this.registerRole(
        group,
        SecurityConstants.CO_ADMINISTRATOR,
        isSuperAdministrator ? permissions.isCoAdministrator() : isCoAdministrator);
    this.registerRole(
        group,
        SecurityConstants.GROUPS,
        isSuperAdministrator ? permissions.getAllowedGroups() : groups);
    this.registerRole(
        group,
        SecurityConstants.INTERACT_OTHER_GROUPS,
        isSuperAdministrator
            ? permissions.getCanInteractOtherGroups()
            : canInteractwithOtherGroups);

    this.registerRole(
        group, SecurityConstants.ATTACHMENTS_DOWNLOAD, permissions.getDownloadAttachments());
    this.registerRole(group, SecurityConstants.ATTACHMENTS_ENABLED, permissions.getAttachments());
    this.registerRole(group, SecurityConstants.CATEGORY, permissions.getAllowedCategories());
    this.registerRole(group, SecurityConstants.POLL_CREATE, permissions.getCanCreatePoll());
    this.registerRole(
        group,
        SecurityConstants.CREATE_STICKY_ANNOUNCEMENT_TOPICS,
        permissions.getCanCreateStickyAnnouncement());
    this.registerRole(group, SecurityConstants.FORUM, permissions.getAllowedForums());
    this.registerRole(group, SecurityConstants.HTML_ALLOWED, permissions.getHtml());
    this.registerRole(group, SecurityConstants.MODERATOR, permissions.isModerator());
    this.registerRole(
        group, SecurityConstants.APPROVE_MESSAGES, permissions.getCanApproveMessages());
    this.registerRole(group, SecurityConstants.MODERATE_FORUM, permissions.getModerateForums());
    this.registerRole(group, SecurityConstants.POST_EDIT, permissions.getCanEditPosts());
    this.registerRole(group, SecurityConstants.POST_DELETE, permissions.getCanRemovePosts());
    this.registerRole(group, SecurityConstants.TOPIC_LOCK_UNLOCK, permissions.getCanLockUnlock());
    this.registerRole(group, SecurityConstants.TOPIC_MOVE, permissions.getCanMoveTopics());
    this.registerRole(group, SecurityConstants.MODERATE_REPLIES, permissions.getModeratedReplies());

    this.registerRole(group, SecurityConstants.FORUM_REPLY_ONLY, permissions.getReplyOnly());
    this.registerRole(group, SecurityConstants.FORUM_READ_ONLY, permissions.getReadOnlyForums());

    this.registerRole(group, SecurityConstants.POLL_VOTE, permissions.getAllowPollVote());
    this.registerRole(
        group, SecurityConstants.PRIVATE_MESSAGE, permissions.isPrivateMessageAllowed());
    this.registerRole(group, SecurityConstants.USER_LISTING, permissions.isUserListingAllowed());
    this.registerRole(group, SecurityConstants.VIEW_PROFILE, permissions.getCanViewProfile());
    this.registerRole(
        group, SecurityConstants.PROFILE_PICTURE, permissions.getCanHaveProfilePicture());
    this.registerRole(
        group,
        SecurityConstants.POST_ONLY_WITH_MODERATOR_ONLINE,
        permissions.getPostOnlyWithModeratorOnline());
    this.registerRole(
        group, SecurityConstants.PM_ONLY_TO_MODERATORS, permissions.isPmOnlyToModerators());
    this.registerRole(
        group, SecurityConstants.VIEW_MODERATION_LOG, permissions.getCanViewActivityLog());
    this.registerRole(
        group, SecurityConstants.VIEW_FULL_MODERATION_LOG, permissions.getCanViewFullActivityLog());

    this.repository.update(group);

    this.sessionManager.computeAllOnlineModerators();
    this.userRepository.changeAllowAvatarState(permissions.getCanHaveProfilePicture(), group);
  }