def setup(self):
        self.loadstatement = '{% load forum_permission_tags %}'
        self.request_factory = RequestFactory()

        self.g1 = GroupFactory.create()
        self.u1 = UserFactory.create()
        self.u2 = UserFactory.create()
        self.u1.groups.add(self.g1)
        self.u2.groups.add(self.g1)
        self.moderators = GroupFactory.create()
        self.moderator = UserFactory.create()
        self.moderator.groups.add(self.moderators)
        self.superuser = UserFactory.create(is_superuser=True)

        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level category
        self.top_level_cat = create_category_forum()

        # Set up some forums
        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)

        # Set up some topics and posts
        self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.u1)
        self.forum_2_topic = create_topic(forum=self.forum_2, poster=self.u2)
        self.post_1 = PostFactory.create(topic=self.forum_1_topic, poster=self.u1)
        self.post_2 = PostFactory.create(topic=self.forum_2_topic, poster=self.u2)
    def setUp(self):
        self.loadstatement = '{% load forum_tracking_tags %}'
        self.request_factory = RequestFactory()

        # Tracking handler
        self.tracks_handler = TrackingHandler()

        self.g1 = GroupFactory.create()
        self.u1 = UserFactory.create()
        self.u2 = UserFactory.create()
        self.u1.groups.add(self.g1)
        self.u2.groups.add(self.g1)

        # Set up a top-level category
        self.top_level_cat = create_category_forum()

        # Set up some forums
        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)

        # Set up some topics and posts
        self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.u1)
        self.forum_2_topic = create_topic(forum=self.forum_2, poster=self.u1)
        self.post_1 = PostFactory.create(topic=self.forum_1_topic, poster=self.u1)
        self.post_2 = PostFactory.create(topic=self.forum_2_topic, poster=self.u1)

        # Assign some permissions
        assign_perm('can_see_forum', self.g1, self.top_level_cat)
        assign_perm('can_read_forum', self.g1, self.top_level_cat)
        assign_perm('can_see_forum', self.g1, self.forum_1)
        assign_perm('can_read_forum', self.g1, self.forum_1)
        assign_perm('can_see_forum', self.g1, self.forum_2)
        assign_perm('can_read_forum', self.g1, self.forum_2)
예제 #3
0
 def test_knows_the_forums_whose_topics_can_be_moved(self):
     # Setup
     assign_perm('can_move_topics', self.u1, self.forum_1)
     u2 = UserFactory.create(is_superuser=True)
     u3 = UserFactory.create()
     # Run & check
     assert set(self.perm_handler.get_movable_forums(self.u1)) == set([self.forum_1, ])
     assert set(self.perm_handler.get_movable_forums(u2)) == set(Forum.objects.all())
     assert list(self.perm_handler.get_movable_forums(u3)) == []
예제 #4
0
 def test_knows_the_forums_that_can_receive_moved_topics(self):
     # Setup
     assign_perm('can_move_topics', self.u1, self.forum_1)
     u2 = UserFactory.create(is_superuser=True)
     u3 = UserFactory.create()
     # Run & check
     assert set(self.perm_handler.get_target_forums_for_moved_topics(self.u1)) == set([self.forum_1, ])
     assert set(self.perm_handler.get_target_forums_for_moved_topics(u2)) == set(Forum.objects.filter(
         type=Forum.TYPE_CHOICES.forum_post))
     assert list(self.perm_handler.get_target_forums_for_moved_topics(u3)) == []
예제 #5
0
    def setup(self):
        # Create a basic user
        self.user = UserFactory.create()

        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level forum
        self.cat = create_category_forum()
        self.top_level_forum = create_forum()
        self.other_forum = create_forum()

        # Set up a topic and some posts
        self.topic = create_topic(forum=self.top_level_forum, poster=self.user)
        self.first_post = PostFactory.create(topic=self.topic, poster=self.user)
        self.post = PostFactory.create(topic=self.topic, poster=self.user)

        # Mark the forum as read
        ForumReadTrackFactory.create(forum=self.top_level_forum, user=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_forum)
        assign_perm('can_reply_to_topics', self.user, self.top_level_forum)
        assign_perm('can_edit_own_posts', self.user, self.top_level_forum)
        assign_perm('can_delete_own_posts', self.user, self.top_level_forum)
        assign_perm('can_lock_topics', self.user, self.top_level_forum)
예제 #6
0
 def test_knows_if_a_user_has_subscribed_to_the_topic(self):
     # Setup
     self.topic.subscribers.add(self.u1)
     u2 = UserFactory.create()
     # Run & check
     assert self.topic.has_subscriber(self.u1)
     assert not self.topic.has_subscriber(u2)
예제 #7
0
 def setUp(self):
     self.rf = RequestFactory()
     self.u1 = UserFactory.create()
     self.top_level_forum = create_forum()
     self.topic = create_topic(forum=self.top_level_forum, poster=self.u1)
     self.post = PostFactory.create(topic=self.topic, poster=self.u1)
     self.topic_pk = self.topic.pk
예제 #8
0
    def setup(self):
        self.u1 = UserFactory.create()

        # Set up top-level forums: a category, a default forum and a link forum
        self.top_level_cat = create_category_forum()
        self.top_level_forum = create_forum()
        self.top_level_link = create_link_forum()
예제 #9
0
 def test_knows_if_a_moderator_can_delete_a_post(self):
     # Setup
     moderator = UserFactory.create()
     assign_perm('can_delete_posts', moderator, self.forum_1)
     # Run & check
     assert self.perm_handler.can_delete_post(self.post_1, moderator)
     assert not self.perm_handler.can_delete_post(self.post_2, moderator)
예제 #10
0
 def test_knows_if_a_user_can_approve_posts(self):
     # Setup
     u2 = UserFactory.create()
     assign_perm('can_approve_posts', self.u1, self.forum_1)
     # Run & check
     assert self.perm_handler.can_approve_posts(self.forum_1, self.u1)
     assert not self.perm_handler.can_approve_posts(self.forum_1, u2)
예제 #11
0
 def test_knows_if_a_user_can_subscribe_to_topics(self):
     # Setup
     u2 = UserFactory.create()
     assign_perm('can_read_forum', self.u1, self.forum_1)
     # Run & check
     assert self.perm_handler.can_subscribe_to_topic(self.forum_1_topic, self.u1)
     assert not self.perm_handler.can_subscribe_to_topic(self.forum_1_topic, u2)
예제 #12
0
    def setup(self):
        # Add some users
        self.u1 = UserFactory.create()
        self.g1 = GroupFactory.create()
        self.u1.groups.add(self.g1)
        self.user.groups.add(self.g1)

        # Permission handler
        self.perm_handler = PermissionHandler()

        self.top_level_cat_1 = create_category_forum()

        self.forum_1 = create_forum(parent=self.top_level_cat_1)
        self.forum_2 = create_forum(parent=self.top_level_cat_1)
        self.forum_3 = create_forum(parent=self.top_level_cat_1)

        self.topic_1 = create_topic(forum=self.forum_2, poster=self.u1)
        PostFactory.create(topic=self.topic_1, poster=self.u1)
        PostFactory.create(topic=self.topic_1, poster=self.user)

        self.topic_2 = create_topic(forum=self.forum_1, poster=self.user)
        PostFactory.create(topic=self.topic_2, poster=self.user)
        PostFactory.create(topic=self.topic_2, poster=self.u1)

        self.topic_3 = create_topic(forum=self.forum_2, poster=self.u1)
        PostFactory.create(topic=self.topic_3, poster=self.u1)

        self.topic_4 = create_topic(forum=self.forum_2, poster=self.user)
        PostFactory.create(topic=self.topic_4, poster=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.g1, self.top_level_cat_1)
        assign_perm('can_read_forum', self.g1, self.forum_1)
        assign_perm('can_read_forum', self.g1, self.forum_2)
예제 #13
0
 def test_can_use_global_permissions(self):
     # Setup
     user = UserFactory.create()
     assign_perm('can_read_forum', user, None)  # global permission
     checker = ForumPermissionChecker(user)
     # Run & check
     assert checker.has_perm('can_read_forum', self.forum)
예제 #14
0
 def test_knows_if_a_user_can_download_files(self):
     # Setup
     u2 = UserFactory.create()
     assign_perm('can_download_file', self.u1, self.forum_1)
     # Run & check
     assert self.perm_handler.can_download_files(self.forum_1, self.u1)
     assert not self.perm_handler.can_download_files(self.forum_1, u2)
예제 #15
0
 def test_knows_if_a_user_can_update_topics_to_normal_topics(self):
     # Setup
     u2 = UserFactory.create()
     assign_perm('can_edit_posts', self.u1, self.forum_1)
     # Run & check
     assert self.perm_handler.can_update_topics_to_normal_topics(self.forum_1, self.u1)
     assert not self.perm_handler.can_update_topics_to_normal_topics(self.forum_1, u2)
예제 #16
0
    def setup(self):
        self.u1 = UserFactory.create()
        self.g1 = GroupFactory.create()
        self.u1.groups.add(self.g1)

        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level category
        self.top_level_cat = create_category_forum()

        # Set up some forums
        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)
        self.forum_3 = create_link_forum(parent=self.top_level_cat)

        # Set up a top-level forum link
        self.top_level_link = create_link_forum()

        # Set up some topics
        self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.u1)
        self.forum_3_topic = create_topic(forum=self.forum_3, poster=self.u1)
        self.forum_3_topic_2 = create_topic(
            forum=self.forum_3, poster=self.u1, status=Topic.TOPIC_LOCKED)

        # Set up some posts
        self.post_1 = PostFactory.create(topic=self.forum_1_topic, poster=self.u1)
        self.post_2 = PostFactory.create(topic=self.forum_3_topic, poster=self.u1)

        # Assign some permissions
        assign_perm('can_see_forum', self.u1, self.top_level_cat)
        assign_perm('can_see_forum', self.u1, self.forum_1)
        assign_perm('can_read_forum', self.g1, self.forum_3)
예제 #17
0
 def test_knows_the_list_of_forums_eligible_to_the_moderation_queue_for_a_given_user(self):
     # Setup
     u2 = UserFactory.create()
     assign_perm('can_approve_posts', self.u1, self.forum_1)
     # Run & check
     assert set(self.perm_handler.get_moderation_queue_forums(self.u1)) == set([self.forum_1, ])
     assert set(self.perm_handler.get_moderation_queue_forums(u2)) == set([])
예제 #18
0
 def test_knows_if_a_user_can_add_posts_to_a_topic(self):
     # Setup
     u2 = UserFactory.create()
     assign_perm('can_reply_to_topics', self.u1, self.forum_1)
     # Run & check
     assert self.perm_handler.can_add_post(self.forum_1_topic, self.u1)
     assert not self.perm_handler.can_add_post(self.forum_1_topic, u2)
예제 #19
0
    def setup(self):
        self.u1 = UserFactory.create()

        # Set up a top-level forum, an associated topic and a post
        self.top_level_forum = create_forum()
        self.topic = create_topic(forum=self.top_level_forum, poster=self.u1)
        self.post = PostFactory.create(topic=self.topic, poster=self.u1)
예제 #20
0
 def test_knows_that_an_inactive_user_has_no_permissions(self):
     # Setup
     user = UserFactory.create(is_active=False)
     checker = ForumPermissionChecker(user)
     # Run & check
     assert not checker.has_perm('can_see_forum', self.forum)
     assert not checker.has_perm('can_read_forum', self.forum)
     assert checker.get_perms(self.forum) == []
예제 #21
0
 def test_shows_all_forums_to_a_superuser(self):
     # Setup
     u2 = UserFactory.create(is_superuser=True)
     forums = Forum.objects.filter(parent=self.top_level_cat)
     # Run
     filtered_forums = self.perm_handler.forum_list_filter(forums, u2)
     # Check
     assert set(filtered_forums) == set([self.forum_1, self.forum_2, self.forum_3])
예제 #22
0
 def test_knows_that_user_permissions_take_precedence_over_user_global_permissions(self):
     # Setup
     user = UserFactory.create()
     assign_perm('can_read_forum', user, None)  # global permission
     assign_perm('can_read_forum', user, self.forum, has_perm=False)
     checker = ForumPermissionChecker(user)
     # Run & check
     assert not checker.has_perm('can_read_forum', self.forum)
예제 #23
0
    def setup(self):
        self.loadstatement = '{% load forum_polls_tags %}'
        self.request_factory = RequestFactory()

        self.g1 = GroupFactory.create()
        self.u1 = UserFactory.create()
        self.u2 = UserFactory.create()
        self.u1.groups.add(self.g1)
        self.u2.groups.add(self.g1)
        self.moderators = GroupFactory.create()
        self.moderator = UserFactory.create()
        self.moderator.groups.add(self.moderators)
        self.superuser = UserFactory.create(is_superuser=True)

        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level category
        self.top_level_cat = create_category_forum()

        # Set up some forums
        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)

        # Set up some topics and posts
        self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.u1)
        self.forum_2_topic = create_topic(forum=self.forum_2, poster=self.u2)
        self.post_1 = PostFactory.create(topic=self.forum_1_topic, poster=self.u1)
        self.post_2 = PostFactory.create(topic=self.forum_2_topic, poster=self.u2)
        self.poll_1 = TopicPollFactory.create(topic=self.forum_1_topic)
        self.poll_2 = TopicPollFactory.create(topic=self.forum_2_topic)

        # Assign some permissions
        assign_perm('can_see_forum', self.g1, self.forum_1)
        assign_perm('can_read_forum', self.g1, self.forum_1)
        assign_perm('can_edit_own_posts', self.g1, self.forum_1)
        assign_perm('can_delete_own_posts', self.g1, self.forum_1)
        assign_perm('can_reply_to_topics', self.g1, self.forum_1)
        assign_perm('can_see_forum', self.moderators, self.forum_1)
        assign_perm('can_read_forum', self.moderators, self.forum_1)
        assign_perm('can_edit_own_posts', self.moderators, self.forum_1)
        assign_perm('can_delete_own_posts', self.moderators, self.forum_1)
        assign_perm('can_edit_posts', self.moderators, self.forum_1)
        assign_perm('can_delete_posts', self.moderators, self.forum_1)
        assign_perm('can_vote_in_polls', self.g1, self.forum_1)
예제 #24
0
 def test_topic_is_not_auto_subscribed_when_setting_is_disabled(self):
     # Setup
     u1 = UserFactory.create()
     top_level_forum = create_forum()
     # Run
     topic = create_topic(forum=top_level_forum, poster=u1)
     PostFactory.create(topic=topic, poster=u1)
     # Check
     assert u1.topic_subscriptions.count() == 0
예제 #25
0
 def test_cannot_target_an_anonymous_user_and_a_registered_user(self):
     # Setup
     user = UserFactory.create()
     # Run & check
     with pytest.raises(ValidationError):
         perm = ForumPermissionFactory.create(is_local=True, is_global=True)
         user_perm = UserForumPermissionFactory.build(
             permission=perm, user=user, anonymous_user=True)
         user_perm.clean()
예제 #26
0
 def test_knows_that_a_superuser_has_all_the_permissions(self):
     # Setup
     user = UserFactory.create(is_active=True, is_superuser=True)
     checker = ForumPermissionChecker(user)
     # Run & check
     assert checker.has_perm('can_see_forum', self.forum)
     assert checker.has_perm('can_read_forum', self.forum)
     assert checker.get_perms(self.forum) == \
         list(ForumPermission.objects.values_list('codename', flat=True))
예제 #27
0
 def test_shows_all_forums_to_a_superuser(self):
     # Setup
     u2 = UserFactory.create(is_superuser=True)
     forums = Forum.objects.filter(parent=self.top_level_cat)
     # Run
     filtered_forums = self.perm_handler.forum_list_filter(forums, u2)
     # Check
     assert set(filtered_forums) == set(
         [self.forum_1, self.forum_2, self.forum_3])
예제 #28
0
 def test_knows_if_an_owner_of_a_post_can_edit_it(self):
     # Setup
     u2 = UserFactory.create()
     assign_perm('can_edit_own_posts', self.u1, self.forum_1)
     assign_perm('can_edit_own_posts', u2, self.forum_1)
     # Run & check
     assert self.perm_handler.can_edit_post(self.post_1, self.u1)
     assert not self.perm_handler.can_edit_post(self.post_2, self.u1)
     assert not self.perm_handler.can_edit_post(self.post_1, u2)
예제 #29
0
    def setup(self):
        self.u1 = UserFactory.create()

        # Set up a top-level forum, an associated topic and a post
        self.top_level_forum = create_forum()
        self.topic = create_topic(forum=self.top_level_forum, poster=self.u1)
        self.post = PostFactory.create(topic=self.topic, poster=self.u1)

        self.topic_pk = self.topic.pk
예제 #30
0
 def test_knows_if_an_owner_of_a_post_can_delete_it(self):
     # Setup
     u2 = UserFactory.create()
     assign_perm('can_delete_own_posts', self.u1, self.forum_1)
     assign_perm('can_delete_own_posts', u2, self.forum_1)
     # Run & check
     assert self.perm_handler.can_delete_post(self.post_1, self.u1)
     assert not self.perm_handler.can_delete_post(self.post_2, self.u1)
     assert not self.perm_handler.can_delete_post(self.post_1, u2)
예제 #31
0
 def test_knows_that_a_superuser_has_all_the_permissions(self):
     # Setup
     user = UserFactory.create(is_active=True, is_superuser=True)
     checker = ForumPermissionChecker(user)
     # Run & check
     assert checker.has_perm('can_see_forum', self.forum)
     assert checker.has_perm('can_read_forum', self.forum)
     assert checker.get_perms(self.forum) == \
         list(ForumPermission.objects.values_list('codename', flat=True))
예제 #32
0
 def test_knows_that_user_permissions_take_precedence_over_user_global_permissions(
         self):
     # Setup
     user = UserFactory.create()
     assign_perm('can_read_forum', user, None)  # global permission
     assign_perm('can_read_forum', user, self.forum, has_perm=False)
     checker = ForumPermissionChecker(user)
     # Run & check
     assert not checker.has_perm('can_read_forum', self.forum)
예제 #33
0
    def setup(self):
        self.loadstatement = '{% load forum_conversation_tags %}'
        self.request_factory = RequestFactory()

        self.g1 = GroupFactory.create()
        self.u1 = UserFactory.create()
        self.u2 = UserFactory.create()
        self.u1.groups.add(self.g1)
        self.u2.groups.add(self.g1)
        self.moderators = GroupFactory.create()
        self.moderator = UserFactory.create()
        self.moderator.groups.add(self.moderators)
        self.superuser = UserFactory.create(is_superuser=True)

        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level category
        self.top_level_cat = create_category_forum()

        # Set up some forums
        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)

        # Set up some topics and posts
        self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.u1)
        self.forum_2_topic = create_topic(forum=self.forum_2, poster=self.u2)
        self.post_1 = PostFactory.create(topic=self.forum_1_topic,
                                         poster=self.u1)
        self.post_2 = PostFactory.create(topic=self.forum_2_topic,
                                         poster=self.u2)

        # Assign some permissions
        assign_perm('can_see_forum', self.g1, self.forum_1)
        assign_perm('can_read_forum', self.g1, self.forum_1)
        assign_perm('can_edit_own_posts', self.g1, self.forum_1)
        assign_perm('can_delete_own_posts', self.g1, self.forum_1)
        assign_perm('can_reply_to_topics', self.g1, self.forum_1)
        assign_perm('can_see_forum', self.moderators, self.forum_1)
        assign_perm('can_read_forum', self.moderators, self.forum_1)
        assign_perm('can_edit_own_posts', self.moderators, self.forum_1)
        assign_perm('can_delete_own_posts', self.moderators, self.forum_1)
        assign_perm('can_edit_posts', self.moderators, self.forum_1)
        assign_perm('can_delete_posts', self.moderators, self.forum_1)
예제 #34
0
    def setup(self):
        self.factory = RequestFactory()
        self.user = UserFactory.create()

        # Set up the following forum tree:
        #
        #     top_level_cat
        #         forum_1
        #         forum_2
        #             forum_2_child_1
        #     top_level_forum_1
        #     top_level_forum_2
        #         sub_cat
        #             sub_sub_forum
        #     top_level_forum_3
        #         forum_3
        #             forum_3_child_1
        #                 forum_3_child_1_1
        #                     deep_forum
        #     last_forum
        #
        self.top_level_cat = create_category_forum()

        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)
        self.forum_2_child_1 = create_forum(parent=self.forum_2)

        self.top_level_forum_1 = create_forum()

        self.top_level_forum_2 = create_forum()
        self.sub_cat = create_category_forum(parent=self.top_level_forum_2)
        self.sub_sub_forum = create_forum(parent=self.sub_cat)

        self.top_level_forum_3 = create_forum()
        self.forum_3 = create_forum(parent=self.top_level_forum_3)
        self.forum_3_child_1 = create_forum(parent=self.forum_3)
        self.forum_3_child_1_1 = create_forum(parent=self.forum_3_child_1)
        self.deep_forum = create_forum(parent=self.forum_3_child_1_1)

        self.last_forum = create_forum()

        # Set up a topic and some posts
        self.topic_1 = create_topic(forum=self.forum_1, poster=self.user)
        self.post_1 = PostFactory.create(topic=self.topic_1, poster=self.user)
        self.topic_2 = create_topic(forum=self.forum_2, poster=self.user)
        self.post_2 = PostFactory.create(topic=self.topic_2, poster=self.user)
        self.topic_3 = create_topic(forum=self.forum_2_child_1,
                                    poster=self.user)
        self.post_3 = PostFactory.create(topic=self.topic_3, poster=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_cat)
        assign_perm('can_read_forum', self.user, self.forum_1)
        assign_perm('can_read_forum', self.user, self.forum_2)
        assign_perm('can_read_forum', self.user, self.forum_2_child_1)
        assign_perm('can_read_forum', self.user, self.top_level_forum_1)
예제 #35
0
 def test_knows_that_user_permissions_take_precedence_over_group_permissions(self):
     # Setup
     user = UserFactory.create()
     group = GroupFactory.create()
     user.groups.add(group)
     assign_perm('can_read_forum', user, self.forum, has_perm=False)
     assign_perm('can_read_forum', group, self.forum, has_perm=True)
     checker = ForumPermissionChecker(user)
     # Run & check
     assert not checker.has_perm('can_read_forum', self.forum)
예제 #36
0
 def test_knows_if_a_user_can_unsubscribe_from_topics(self):
     # Setup
     self.forum_1_topic.subscribers.add(self.u1)
     u2 = UserFactory.create()
     assign_perm('can_read_forum', self.u1, self.forum_1)
     # Run & check
     assert self.perm_handler.can_unsubscribe_from_topic(
         self.forum_1_topic, self.u1)
     assert not self.perm_handler.can_unsubscribe_from_topic(
         self.forum_1_topic, u2)
예제 #37
0
 def test_knows_that_a_moderator_can_add_posts_to_a_locked_topic(self):
     # Setup
     assign_perm('can_reply_to_topics', self.u1, self.forum_1)
     assign_perm('can_reply_to_locked_topics', self.u1, self.forum_1)
     u2 = UserFactory.create()
     self.forum_1_topic.status = self.forum_1_topic.TOPIC_LOCKED
     self.forum_1_topic.save()
     # Run & check
     assert self.perm_handler.can_add_post(self.forum_1_topic, self.u1)
     assert not self.perm_handler.can_add_post(self.forum_1_topic, u2)
예제 #38
0
 def test_knows_if_a_user_can_update_topics_to_announces(self):
     # Setup
     u2 = UserFactory.create()
     assign_perm('can_edit_posts', self.u1, self.forum_1)
     assign_perm('can_post_announcements', self.u1, self.forum_1)
     # Run & check
     assert self.perm_handler.can_update_topics_to_announces(
         self.forum_1, self.u1)
     assert not self.perm_handler.can_update_topics_to_announces(
         self.forum_1, u2)
예제 #39
0
 def test_knows_that_user_permissions_take_precedence_over_group_permissions(self):
     # Setup
     user = UserFactory.create()
     group = GroupFactory.create()
     user.groups.add(group)
     assign_perm('can_read_forum', user, self.forum, has_perm=False)
     assign_perm('can_read_forum', group, self.forum, has_perm=True)
     checker = ForumPermissionChecker(user)
     # Run & check
     assert not checker.has_perm('can_read_forum', self.forum)
예제 #40
0
 def test_cannot_target_an_anonymous_user_and_a_registered_user(self):
     # Setup
     user = UserFactory.create()
     # Run & check
     with pytest.raises(ValidationError):
         perm = ForumPermissionFactory.create(is_local=True, is_global=True)
         user_perm = UserForumPermissionFactory.build(permission=perm,
                                                      user=user,
                                                      anonymous_user=True)
         user_perm.clean()
예제 #41
0
 def test_knows_that_a_moderator_can_add_posts_to_a_locked_topic(self):
     # Setup
     assign_perm('can_reply_to_topics', self.u1, self.forum_1)
     assign_perm('can_reply_to_locked_topics', self.u1, self.forum_1)
     u2 = UserFactory.create()
     self.forum_1_topic.status = self.forum_1_topic.TOPIC_LOCKED
     self.forum_1_topic.save()
     # Run & check
     assert self.perm_handler.can_add_post(self.forum_1_topic, self.u1)
     assert not self.perm_handler.can_add_post(self.forum_1_topic, u2)
예제 #42
0
    def setup(self):
        self.factory = RequestFactory()
        self.user = UserFactory.create()

        # Set up the following forum tree:
        #
        #     top_level_cat
        #         forum_1
        #         forum_2
        #             forum_2_child_1
        #     top_level_forum_1
        #     top_level_forum_2
        #         sub_cat
        #             sub_sub_forum
        #     top_level_forum_3
        #         forum_3
        #             forum_3_child_1
        #                 forum_3_child_1_1
        #                     deep_forum
        #     last_forum
        #
        self.top_level_cat = create_category_forum()

        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)
        self.forum_2_child_1 = create_forum(parent=self.forum_2)

        self.top_level_forum_1 = create_forum()

        self.top_level_forum_2 = create_forum()
        self.sub_cat = create_category_forum(parent=self.top_level_forum_2)
        self.sub_sub_forum = create_forum(parent=self.sub_cat)

        self.top_level_forum_3 = create_forum()
        self.forum_3 = create_forum(parent=self.top_level_forum_3)
        self.forum_3_child_1 = create_forum(parent=self.forum_3)
        self.forum_3_child_1_1 = create_forum(parent=self.forum_3_child_1)
        self.deep_forum = create_forum(parent=self.forum_3_child_1_1)

        self.last_forum = create_forum()

        # Set up a topic and some posts
        self.topic_1 = create_topic(forum=self.forum_1, poster=self.user)
        self.post_1 = PostFactory.create(topic=self.topic_1, poster=self.user)
        self.topic_2 = create_topic(forum=self.forum_2, poster=self.user)
        self.post_2 = PostFactory.create(topic=self.topic_2, poster=self.user)
        self.topic_3 = create_topic(forum=self.forum_2_child_1, poster=self.user)
        self.post_3 = PostFactory.create(topic=self.topic_3, poster=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_cat)
        assign_perm('can_read_forum', self.user, self.forum_1)
        assign_perm('can_read_forum', self.user, self.forum_2)
        assign_perm('can_read_forum', self.user, self.forum_2_child_1)
        assign_perm('can_read_forum', self.user, self.top_level_forum_1)
예제 #43
0
 def test_knows_that_alluser_permissions_take_precedence_over_default_authenticated_permissions(
         self):  # noqa: E501
     user = UserFactory.create()
     # Negate DEFAULT_AUTHENTICATED_USER_FORUM_PERMISSIONS
     assign_perm('can_see_forum',
                 ALL_AUTHENTICATED_USERS,
                 self.forum,
                 has_perm=False)
     checker = ForumPermissionChecker(user)
     # Run & check
     assert not checker.has_perm('can_see_forum', self.forum)
예제 #44
0
    def setup(self):
        self.u1 = UserFactory.create()
        self.u2 = UserFactory.create()

        self.top_level_cat_1 = create_category_forum()
        self.top_level_cat_2 = create_category_forum()

        self.forum_1 = create_forum(parent=self.top_level_cat_1)
        self.forum_2 = create_forum(parent=self.top_level_cat_1)
        self.forum_2_child_1 = create_link_forum(parent=self.forum_2)
        self.forum_2_child_2 = create_forum(parent=self.forum_2)
        self.forum_3 = create_forum(parent=self.top_level_cat_1)

        self.forum_4 = create_forum(parent=self.top_level_cat_2)

        self.topic = create_topic(forum=self.forum_2, poster=self.u1)
        PostFactory.create(topic=self.topic, poster=self.u1)

        # Initially u2 read the previously created topic
        ForumReadTrackFactory.create(forum=self.forum_2, user=self.u2)
예제 #45
0
    def setup(self):
        self.u1 = UserFactory.create()
        self.u2 = UserFactory.create()

        self.top_level_cat_1 = create_category_forum()
        self.top_level_cat_2 = create_category_forum()

        self.forum_1 = create_forum(parent=self.top_level_cat_1)
        self.forum_2 = create_forum(parent=self.top_level_cat_1)
        self.forum_2_child_1 = create_link_forum(parent=self.forum_2)
        self.forum_2_child_2 = create_forum(parent=self.forum_2)
        self.forum_3 = create_forum(parent=self.top_level_cat_1)

        self.forum_4 = create_forum(parent=self.top_level_cat_2)

        self.topic = create_topic(forum=self.forum_2, poster=self.u1)
        PostFactory.create(topic=self.topic, poster=self.u1)

        # Initially u2 read the previously created topic
        ForumReadTrackFactory.create(forum=self.forum_2, user=self.u2)
예제 #46
0
    def setup(self):
        self.loadstatement = '{% load forum_tags %}'
        self.request_factory = RequestFactory()
        self.user = UserFactory.create()

        # Set up a top-level category
        self.top_level_cat = create_category_forum()

        # Set up some forums
        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)
예제 #47
0
 def test_cannot_search_forum_posts_if_the_user_has_not_the_required_permissions(self):
     # Setup
     u1 = UserFactory.create()
     self.request.user = u1
     self.request.GET = {'q': self.topic_1.first_post.content}
     form = PostgresSearchForm(self.request)
     # Run
     results = form.search()
     # Check
     assert form.is_valid()
     assert results is None
예제 #48
0
 def test_topic_is_auto_subscribed_when_setting_is_enabled(self):
     # Setup
     u1 = UserFactory.create()
     u2 = UserFactory.create()
     top_level_forum = create_forum()
     # Create topics to auto create a forum profile
     topic = create_topic(forum=top_level_forum, poster=u1)
     PostFactory.create(topic=topic, poster=u1)
     PostFactory.create(topic=topic, poster=u2)
     profile = ForumProfile.objects.get(user=u2)
     profile.auto_subscribe_posts = True
     profile.save()
     # Run
     topic = create_topic(forum=top_level_forum, poster=u1)
     PostFactory.create(topic=topic, poster=u1)
     PostFactory.create(topic=topic, poster=u2)
     PostFactory.create(topic=topic, poster=u1)
     # Check
     assert topic in u2.topic_subscriptions.all()
     assert topic not in u1.topic_subscriptions.all()
예제 #49
0
 def test_can_return_a_list_of_all_related_votes(self):
     # Setup
     u2 = UserFactory.create()
     poll = TopicPollFactory.create(topic=self.topic, max_options=2)
     option_1 = TopicPollOptionFactory.create(poll=poll)
     option_2 = TopicPollOptionFactory.create(poll=poll)
     # Run
     vote_1 = TopicPollVoteFactory.create(poll_option=option_1, voter=self.u1)
     vote_2 = TopicPollVoteFactory.create(poll_option=option_2, voter=self.u1)
     vote_3 = TopicPollVoteFactory.create(poll_option=option_2, voter=u2)
     # Check
     assert set(poll.votes) == set([vote_1, vote_2, vote_3])
예제 #50
0
 def test_knows_the_list_of_forums_eligible_to_the_moderation_queue_for_a_given_user(
         self):
     # Setup
     u2 = UserFactory.create()
     assign_perm('can_approve_posts', self.u1, self.forum_1)
     # Run & check
     assert set(self.perm_handler.get_moderation_queue_forums(
         self.u1)) == set([
             self.forum_1,
         ])
     assert set(self.perm_handler.get_moderation_queue_forums(u2)) == set(
         [])
예제 #51
0
 def test_cannot_search_forum_posts_if_the_user_has_not_the_required_permissions(self):
     # Setup
     u1 = UserFactory.create()
     form = SearchForm(
         {'q': self.topic_1.first_post.content},
         user=u1,
     )
     # Run
     results = form.search()
     # Check
     assert form.is_valid()
     assert not len(results)
예제 #52
0
    def setup(self):
        # Add some users
        self.u1 = UserFactory.create()
        self.u2 = UserFactory.create()
        self.g1 = GroupFactory.create()
        self.u1.groups.add(self.g1)
        self.u2.groups.add(self.g1)
        self.user.groups.add(self.g1)

        # Permission handler
        self.perm_handler = PermissionHandler()

        # Tracking handler
        self.tracks_handler = TrackingHandler()

        self.top_level_cat_1 = create_category_forum()
        self.top_level_cat_2 = create_category_forum()

        self.forum_1 = create_forum(parent=self.top_level_cat_1)
        self.forum_2 = create_forum(parent=self.top_level_cat_1)
        self.forum_2_child_1 = create_forum(parent=self.forum_2)
        self.forum_3 = create_forum(parent=self.top_level_cat_1)

        self.forum_4 = create_forum(parent=self.top_level_cat_2)

        self.topic = create_topic(forum=self.forum_2, poster=self.u1)
        PostFactory.create(topic=self.topic, poster=self.u1)

        # Initially u2 and user read the previously created topic
        ForumReadTrackFactory.create(forum=self.forum_2, user=self.u2)
        ForumReadTrackFactory.create(forum=self.forum_2, user=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.g1, self.top_level_cat_1)
        assign_perm('can_read_forum', self.g1, self.top_level_cat_2)
        assign_perm('can_read_forum', self.g1, self.forum_1)
        assign_perm('can_read_forum', self.g1, self.forum_2)
        assign_perm('can_read_forum', self.g1, self.forum_2_child_1)
        assign_perm('can_read_forum', self.g1, self.forum_4)
예제 #53
0
 def test_knows_its_percentage(self):
     # Setup
     u2 = UserFactory.create()
     poll = TopicPollFactory.create(topic=self.topic, max_options=2)
     option_1 = TopicPollOptionFactory.create(poll=poll)
     option_2 = TopicPollOptionFactory.create(poll=poll)
     TopicPollVoteFactory.create(poll_option=option_1, voter=self.u1)
     TopicPollVoteFactory.create(poll_option=option_2, voter=self.u1)
     TopicPollVoteFactory.create(poll_option=option_1, voter=u2)
     TopicPollVoteFactory.create(poll_option=option_2, voter=u2)
     # Run & check
     assert option_1.percentage == 50
     assert option_2.percentage == 50
예제 #54
0
    def test_do_nothing_if_the_post_has_been_created_by_an_anonymous_user(self):
        u1 = UserFactory.create()
        top_level_forum = create_forum()
        topic = create_topic(forum=top_level_forum, poster=u1)
        PostFactory.create(topic=topic, poster=u1)
        profile = ForumProfile.objects.get(user=u1)
        post = PostFactory.create(topic=topic, poster=None, approved=True)

        post.approved = False
        post.save()

        profile.refresh_from_db()
        assert profile.posts_count == 1
예제 #55
0
 def test_can_increase_the_posts_count_of_the_post_being_created(self):
     # Setup
     u1 = UserFactory.create()
     top_level_forum = create_forum()
     topic = create_topic(forum=top_level_forum, poster=u1)
     PostFactory.create(topic=topic, poster=u1)
     profile = ForumProfile.objects.get(user=u1)
     initial_posts_count = profile.posts_count
     # Run
     PostFactory.create(topic=topic, poster=u1, approved=True)
     # Check
     profile = refresh(profile)
     assert profile.posts_count == initial_posts_count + 1
예제 #56
0
 def test_cannot_be_validated_if_two_users_are_selected(self):
     # Setup
     user = UserFactory.create()
     site = Site.objects.get_current()
     form_data = {
         'user': user.id,
         'anonymous_user': True,
     }
     # Run
     form = PickUserForm(form_data, admin_site=site)
     # Check
     is_valid = form.is_valid()
     assert not is_valid
예제 #57
0
 def test_filter_methods_ensure_that_granted_permissions_take_precedence_over_the_same_non_granted_permissions(self):  # noqa: E501
     # Setup
     user = UserFactory.create()
     group_all_users = GroupFactory.create()
     group_specific_access = GroupFactory.create()
     user.groups.add(group_all_users)
     user.groups.add(group_specific_access)
     assign_perm('can_read_forum', group_all_users, None)  # global permission
     assign_perm('can_read_forum', group_all_users, self.top_level_cat, has_perm=False)
     assign_perm('can_read_forum', group_specific_access, self.top_level_cat, has_perm=True)
     # Run & check
     assert self.top_level_cat in \
         set(self.perm_handler._get_forums_for_user(user, ['can_read_forum']))
예제 #58
0
 def test_knows_that_granted_permissions_should_take_precedence_over_the_same_non_granted_permissions(self):  # noqa: E501
     # Setup
     user = UserFactory.create()
     group_all_users = GroupFactory.create()
     group_specific_access = GroupFactory.create()
     user.groups.add(group_all_users)
     user.groups.add(group_specific_access)
     assign_perm('can_read_forum', group_all_users, None)  # global permission
     assign_perm('can_read_forum', group_all_users, self.forum, has_perm=False)
     assign_perm('can_read_forum', group_specific_access, self.forum, has_perm=True)
     checker = ForumPermissionChecker(user)
     # Run & check
     assert checker.has_perm('can_read_forum', self.forum)
예제 #59
0
 def test_knows_that_alluser_permissions_take_precedence_over_alluser_global_permissions(self):
     # Setup
     user = UserFactory.create()
     # Test globally True but forum level False
     assign_perm('can_read_forum', ALL_AUTHENTICATED_USERS, None, has_perm=True)
     assign_perm('can_read_forum', ALL_AUTHENTICATED_USERS, self.forum, has_perm=False)
     # Test globally False but forum level True
     assign_perm('can_see_forum', ALL_AUTHENTICATED_USERS, None, has_perm=False)
     assign_perm('can_see_forum', ALL_AUTHENTICATED_USERS, self.forum, has_perm=True)
     checker = ForumPermissionChecker(user)
     # Run & check
     assert not checker.has_perm('can_read_forum', self.forum)
     assert checker.has_perm('can_see_forum', self.forum)
예제 #60
0
    def setup(self):
        self.user = UserFactory.create()
        self.factory = RequestFactory()

        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a single forum
        self.forum = create_forum()

        # Assign some permissions
        assign_perm('can_see_forum', self.user, self.forum)

        self.mixin = PermissionRequiredMixin()