Example #1
0
    def test_subcategories_visible_to_account_with_permissions(self):
        register_user('test_user', '*****@*****.**', '111111')
        register_user('granted_user', '*****@*****.**', '111111')
        register_user('wrong_user', '*****@*****.**', '111111')

        granted_account = AccountPrototype.get_by_nick('granted_user')
        wrong_account = AccountPrototype.get_by_nick('wrong_user')

        category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        subcategory_1 = SubCategoryPrototype.create(category=category, caption='subcat-1-caption', order=2)

        SubCategoryPrototype.create(category=category, caption='subcat-2-caption', order=1, restricted=True)

        restricted_subcategory = SubCategoryPrototype.create(category=category, caption='subcat-restricted-caption', order=0, restricted=True)

        PermissionPrototype.create(granted_account, restricted_subcategory)

        self.assertEqual([s.id for s in SubCategoryPrototype.subcategories_visible_to_account(account=None)],
                         [subcategory_1.id])

        self.assertEqual([s.id for s in SubCategoryPrototype.subcategories_visible_to_account(account=granted_account)],
                         [restricted_subcategory.id, subcategory_1.id])

        self.assertEqual([s.id for s in SubCategoryPrototype.subcategories_visible_to_account(account=wrong_account)],
                         [subcategory_1.id])
Example #2
0
    def index(self):
        categories = list(
            CategoryPrototype(category_model)
            for category_model in Category.objects.all().order_by(
                'order', 'id'))

        subcategories = SubCategoryPrototype.subcategories_visible_to_account(
            account=self.account if self.account.is_authenticated() else None)

        forum_structure = []

        read_states = {
            subcategory.id: ReadState(account=self.account)
            for subcategory in subcategories
        }

        for category in categories:
            children = []
            for subcategory in subcategories:
                if subcategory.category_id == category.id:
                    children.append(subcategory)

            forum_structure.append({
                'category': category,
                'subcategories': children
            })

        return self.template('forum/index.html', {
            'forum_structure': forum_structure,
            'read_states': read_states
        })
Example #3
0
    def test_subcategories_visible_to_account_with_permissions(self):
        register_user('test_user', '*****@*****.**', '111111')
        register_user('granted_user', '*****@*****.**', '111111')
        register_user('wrong_user', '*****@*****.**', '111111')

        granted_account = AccountPrototype.get_by_nick('granted_user')
        wrong_account = AccountPrototype.get_by_nick('wrong_user')

        category = CategoryPrototype.create(caption='cat-caption',
                                            slug='cat-slug',
                                            order=0)
        subcategory_1 = SubCategoryPrototype.create(category=category,
                                                    caption='subcat-1-caption',
                                                    order=2)

        SubCategoryPrototype.create(category=category,
                                    caption='subcat-2-caption',
                                    order=1,
                                    restricted=True)

        restricted_subcategory = SubCategoryPrototype.create(
            category=category,
            caption='subcat-restricted-caption',
            order=0,
            restricted=True)

        PermissionPrototype.create(granted_account, restricted_subcategory)

        self.assertEqual([
            s.id
            for s in SubCategoryPrototype.subcategories_visible_to_account(
                account=None)
        ], [subcategory_1.id])

        self.assertEqual([
            s.id
            for s in SubCategoryPrototype.subcategories_visible_to_account(
                account=granted_account)
        ], [restricted_subcategory.id, subcategory_1.id])

        self.assertEqual([
            s.id
            for s in SubCategoryPrototype.subcategories_visible_to_account(
                account=wrong_account)
        ], [subcategory_1.id])
Example #4
0
    def test_subcategories_visible_to_account_with_permissions(self):
        granted_account = self.accounts_factory.create_account()
        wrong_account = self.accounts_factory.create_account()

        category = CategoryPrototype.create(caption='cat-caption',
                                            slug='cat-slug',
                                            order=0)
        subcategory_1 = SubCategoryPrototype.create(category=category,
                                                    caption='subcat-1-caption',
                                                    order=2)

        SubCategoryPrototype.create(category=category,
                                    caption='subcat-2-caption',
                                    order=1,
                                    restricted=True)

        restricted_subcategory = SubCategoryPrototype.create(
            category=category,
            caption='subcat-restricted-caption',
            order=0,
            restricted=True)

        PermissionPrototype.create(granted_account, restricted_subcategory)

        self.assertEqual([
            s.id
            for s in SubCategoryPrototype.subcategories_visible_to_account(
                account=None)
        ], [subcategory_1.id])

        self.assertEqual([
            s.id
            for s in SubCategoryPrototype.subcategories_visible_to_account(
                account=granted_account)
        ], [restricted_subcategory.id, subcategory_1.id])

        self.assertEqual([
            s.id
            for s in SubCategoryPrototype.subcategories_visible_to_account(
                account=wrong_account)
        ], [subcategory_1.id])
Example #5
0
    def test_subcategories_visible_to_account_with_permissions(self):
        granted_account = self.accounts_factory.create_account()
        wrong_account = self.accounts_factory.create_account()

        category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
        subcategory_1 = SubCategoryPrototype.create(category=category, caption='subcat-1-caption', order=2)

        SubCategoryPrototype.create(category=category, caption='subcat-2-caption', order=1, restricted=True)

        restricted_subcategory = SubCategoryPrototype.create(category=category, caption='subcat-restricted-caption', order=0, restricted=True)

        PermissionPrototype.create(granted_account, restricted_subcategory)

        self.assertEqual([s.id for s in SubCategoryPrototype.subcategories_visible_to_account(account=None)],
                         [subcategory_1.id])

        self.assertEqual([s.id for s in SubCategoryPrototype.subcategories_visible_to_account(account=granted_account)],
                         [restricted_subcategory.id, subcategory_1.id])

        self.assertEqual([s.id for s in SubCategoryPrototype.subcategories_visible_to_account(account=wrong_account)],
                         [subcategory_1.id])
Example #6
0
    def index(self):
        categories = list(CategoryPrototype(category_model) for category_model in Category.objects.all().order_by('order', 'id'))

        subcategories = SubCategoryPrototype.subcategories_visible_to_account(account=self.account if self.account.is_authenticated else None)

        forum_structure = []

        read_states = {subcategory.id: ReadState(account=self.account)
                       for subcategory in subcategories}

        for category in categories:
            children = []
            for subcategory in subcategories:
                if subcategory.category_id == category.id:
                    children.append(subcategory)

            forum_structure.append({'category': category,
                                    'subcategories': children})


        return self.template('forum/index.html',
                             {'forum_structure': forum_structure,
                              'read_states': read_states} )
Example #7
0
 def read_all__all(self):
     for subcategory in SubCategoryPrototype.subcategories_visible_to_account(
             account=self.account):
         SubCategoryReadInfoPrototype.read_all_in_subcategory(
             subcategory=subcategory, account=self.account)
     return self.json_ok()
Example #8
0
 def read_all__all(self):
     for subcategory in SubCategoryPrototype.subcategories_visible_to_account(account=self.account):
         SubCategoryReadInfoPrototype.read_all_in_subcategory(subcategory=subcategory, account=self.account)
     return self.json_ok()