@Test
  public void askMoveDestinationDoesNotHaveRoleShouldIgnore() {
    when(roleManager.getCanMoveTopics()).thenReturn(false);

    controller.askMoveDestination("return path", 1, 2, 3);

    verify(mockResult).redirectTo("return path");
  }
  @Test
  public void moveTopicsDoesNotHaveRoleShouldIgnore() {
    when(roleManager.getCanMoveTopics()).thenReturn(false);

    controller.moveTopics(1, "return path", moderationLog, 1, 2);

    verify(mockResult).redirectTo("return path");
  }
  @Test
  public void approveDoesNotHaveRequiredRoleShouldIgnore() {
    when(roleManager.getCanApproveMessages()).thenReturn(false);
    when(mockResult.redirectTo(ForumController.class)).thenReturn(mockForumController);

    controller.approve(1, Arrays.asList(new ApproveInfo[0]));

    verify(mockForumController).show(1, 0);
  }
  @Test
  public void lockUnlockDoesNotHaveRoleShouldIgnore() {
    when(roleManager.getCanLockUnlockTopics()).thenReturn(false);
    when(mockResult.redirectTo(ForumController.class)).thenReturn(mockForumController);

    controller.lockUnlock(1, null, moderationLog, new int[] {1});

    verify(mockForumController).show(1, 0);
  }
  @Test
  public void moveTopics() {
    when(userSession.getUser()).thenReturn(user);
    when(roleManager.getCanMoveTopics()).thenReturn(true);

    controller.moveTopics(1, "return path", moderationLog, 2, 3, 4);

    verify(service).moveTopics(1, moderationLog, 2, 3, 4);
    verify(mockResult).redirectTo("return path");
  }
  @Test
  public void deleteTopicsDoesNotHaveRoleShouldIgnore() {
    when(roleManager.getCanDeletePosts()).thenReturn(false);
    // TODO pass zero?
    when(mockResult.redirectTo(ForumController.class)).thenReturn(mockForumController);

    controller.deleteTopics(1, null, new int[] {4}, moderationLog);

    verify(mockForumController).show(1, 0);
  }
  @Test
  public void lockUnlock() {
    when(userSession.getUser()).thenReturn(user);
    when(roleManager.getCanLockUnlockTopics()).thenReturn(true);
    when(mockResult.redirectTo(ForumController.class)).thenReturn(mockForumController);

    controller.lockUnlock(1, null, moderationLog, new int[] {1, 2, 3});

    verify(service).lockUnlock(new int[] {1, 2, 3}, moderationLog);
    verify(mockForumController).show(1, 0);
  }
  @Test
  public void approveExpectSuccess() {
    when(roleManager.getCanApproveMessages()).thenReturn(true);
    when(mockResult.redirectTo(ForumController.class)).thenReturn(mockForumController);

    controller.approve(1, Arrays.asList(new ApproveInfo[0]));

    verify(service).doApproval(1, Arrays.asList(new ApproveInfo[0]));
    // TODO pass zero?
    verify(mockForumController).show(1, 0);
  }
  @Test
  public void askMoveDestination() {
    when(roleManager.getCanMoveTopics()).thenReturn(true);
    when(categoryRepository.getAllCategories()).thenReturn(new ArrayList<Category>());

    controller.askMoveDestination("return path", 10, 1, 2, 3);

    assertArrayEquals(new int[] {1, 2, 3}, (int[]) mockResult.included("topicIds"));
    assertEquals(10, mockResult.included("fromForumId"));
    assertEquals("return path", mockResult.included("returnUrl"));
    assertEquals(new ArrayList<Category>(), mockResult.included("categories"));
  }
  @Test
  public void deleteTopicsExpectSuccess() {
    when(userSession.getUser()).thenReturn(user);
    when(roleManager.getCanDeletePosts()).thenReturn(true);
    when(topicRepository.get(4)).thenReturn(new Topic());
    when(topicRepository.get(5)).thenReturn(new Topic());
    when(mockResult.redirectTo(ForumController.class)).thenReturn(mockForumController);

    controller.deleteTopics(1, null, new int[] {4, 5}, moderationLog);

    verify(service).deleteTopics(Arrays.asList(new Topic(), new Topic()), moderationLog);
    // TODO pass zero?
    verify(mockForumController).show(1, 0);
  }
Exemplo n.º 11
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);
  }