def test_public_group_forum_permissions_may_create_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() # Only owner and members can create topics. self.assertFalse(perms.may_create_topic(AnonymousUser(), group.forum)) self.assertTrue(perms.may_create_topic(self.user1, group.forum)) self.assertTrue(perms.may_create_topic(self.user2, group.forum)) self.assertFalse(perms.may_create_topic(self.user3, group.forum))
def test_public_group_forum_permissions_may_view_forum(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() # Everybody can see the forum. self.assertTrue(perms.may_view_forum(AnonymousUser(), group.forum)) self.assertTrue(perms.may_view_forum(self.user1, group.forum)) self.assertTrue(perms.may_view_forum(self.user2, group.forum)) self.assertTrue(perms.may_view_forum(self.user3, group.forum))
def test_private_group_forum_permissions_may_create_post(self): group = Group.objects.create(name='Test', category=11, public=False, 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) # Only owner and members can create posts. self.assertFalse(perms.may_create_post(AnonymousUser(), topic)) self.assertTrue(perms.may_create_post(self.user1, topic)) self.assertTrue(perms.may_create_post(self.user2, topic)) self.assertFalse(perms.may_create_post(self.user3, topic))
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()
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()
def test_public_group_forum_permissions_filter_forums(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() # Only owner and members can list the forum. self.assertFalse(group.forum in perms.filter_forums( AnonymousUser(), Forum.objects.all())) self.assertTrue(group.forum in perms.filter_forums( self.user1, Forum.objects.all())) self.assertTrue(group.forum in perms.filter_forums( self.user2, Forum.objects.all())) self.assertFalse(group.forum in perms.filter_forums( self.user3, Forum.objects.all()))
def test_public_group_forum_permissions_filter_topics(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 list topics. self.assertTrue( topic in perms.filter_topics(AnonymousUser(), Topic.objects.all())) self.assertTrue( topic in perms.filter_topics(self.user1, Topic.objects.all())) self.assertTrue( topic in perms.filter_topics(self.user2, Topic.objects.all())) self.assertTrue( topic in perms.filter_topics(self.user3, Topic.objects.all()))