Exemplo n.º 1
0
    def test_public_group_forum_permissions_may_view_topic(self):
        group = Group.objects.create(name='Test',
                                     category=11,
                                     public=True,
                                     creator=self.user1,
                                     owner=self.user1,
                                     autosubmission=True)
        group.members.add(self.user2)
        perms = CustomForumPermissions()
        topic = Topic.objects.create(forum=group.forum,
                                     name='Test',
                                     user=self.user1)

        # Everybody can see topics.
        self.assertTrue(perms.may_view_topic(AnonymousUser(), topic))
        self.assertTrue(perms.may_view_topic(self.user1, topic))
        self.assertTrue(perms.may_view_topic(self.user2, topic))
        self.assertTrue(perms.may_view_topic(self.user3, topic))
Exemplo n.º 2
0
    def test_may_view_topic(self):
        topic = Topic.objects.create(forum=self.forum,
                                     name="Test topic",
                                     user=self.user)

        post = Post.objects.create(topic=topic,
                                   user=self.user,
                                   body="Test post")

        user2 = User.objects.create_user(username="******",
                                         email="*****@*****.**",
                                         password="******")

        perms = CustomForumPermissions()

        # Unauthenticated
        self.assertTrue(perms.may_view_topic(user2, topic))

        # Authenticated
        self.client.login(username="******", password="******")
        self.assertTrue(perms.may_view_topic(user2, topic))

        # Topic in forum that belongs to public group and user2 is not a member
        group = AstroBinGroup.objects.create(creator=self.user,
                                             owner=self.user,
                                             name="Test group",
                                             category=101,
                                             public=True,
                                             forum=self.forum)
        self.assertFalse(perms.may_view_topic(user2, topic))

        # user2 becomes a subscriber
        topic.subscribers.add(user2)
        self.assertTrue(perms.may_view_topic(user2, topic))

        # user2 not a subscriber, but a member of the group
        topic.subscribers.remove(user2)
        group.members.add(user2)
        self.assertTrue(perms.may_view_topic(user2, topic))

        # group owner
        group.members.remove(user2)
        group.owner = user2
        group.save()
        self.assertTrue(perms.may_view_topic(user2, topic))

        # Restore status
        self.client.logout()
        self.client.login(username="******", password="******")

        user2.delete()
        post.delete()
        group.delete()
Exemplo n.º 3
0
    def test_may_view_topic(self):
        topic = Topic.objects.create(
            forum = self.forum, name = "Test topic", user = self.user)

        post = Post.objects.create(
            topic = topic, user = self.user, body = "Test post")

        user2 = User.objects.create_user(
            username = "******", email = "*****@*****.**",
            password = "******")

        perms = CustomForumPermissions()

        # Unauthenticated
        self.assertTrue(perms.may_view_topic(user2, topic))

        # Authenticated
        self.client.login(username = "******", password = "******")
        self.assertTrue(perms.may_view_topic(user2, topic))

        # Topic in forum that belongs to public group and user2 is not a member
        group = AstroBinGroup.objects.create(
            creator = self.user,
            owner = self.user,
            name = "Test group",
            category = 101,
            public = True,
            forum = self.forum)
        self.assertFalse(perms.may_view_topic(user2, topic))

        # user2 becomes a subscriber
        topic.subscribers.add(user2)
        self.assertTrue(perms.may_view_topic(user2, topic))

        # user2 not a subscriber, but a member of the group
        topic.subscribers.remove(user2)
        group.members.add(user2)
        self.assertTrue(perms.may_view_topic(user2, topic))

        # group owner
        group.members.remove(user2)
        group.owner = user2
        group.save()
        self.assertTrue(perms.may_view_topic(user2, topic))

        # Restore status
        self.client.logout()
        self.client.login(username = "******", password = "******")

        user2.delete()
        post.delete()
        group.delete()