Exemplo n.º 1
0
 def test_required_baya_groups(self):
     # The required groups for an admin site is the `or`-union of all
     # different required groups
     required_groups = site._get_required_baya_groups()
     exp = ((g('AAA') & ALLOW_ALL) | (g('AA') & ALLOW_ALL) |
            (g('AA') | g('B')))
     self.assertEqual(required_groups, exp)
Exemplo n.º 2
0
 def test_required_baya_groups(self):
     # The required groups for an admin site is the `or`-union of all
     # different required groups
     required_groups = site._get_required_baya_groups()
     exp = ((g('AAA') & ALLOW_ALL) |
            (g('AA') & ALLOW_ALL) |
            (g('AA') | g('B')))
     self.assertEqual(required_groups, exp)
Exemplo n.º 3
0
 def test_inline_decoration(self):
     # This should fail because inlines don't have any {add,change,delete}
     # views to protect.
     with self.assertRaises(TypeError):
         @requires(g('A'))
         class MyInline(InlineModelAdmin):
             pass
Exemplo n.º 4
0
 def test_inline_decoration(self):
     # This should fail because inlines don't have any {add,change,delete}
     # views to protect.
     with self.assertRaises(TypeError):
         @requires(g('A'))
         class MyInline(InlineModelAdmin):
             pass
Exemplo n.º 5
0
 def test_required_baya_groups_repeats(self):
     """Repeated roles should only be shown once."""
     admins = []
     role = g('A')
     # Mock model admins, each with the same required role
     for i in range(5):
         model = MagicMock(_meta=MagicMock(app_label='%s' % i))
         model_opts = MagicMock(_gate=MagicMock(_gate=MagicMock()))
         model_opts._gate.get_requires = role
         admins.append((model, model_opts))
     with mock.patch.object(NestedGroupsAdminSite,
                            '_get_admins_with_gate',
                            return_value=admins):
         site = NestedGroupsAdminSite()
         required_groups = site._get_required_baya_groups()
         exp = g('A')
         self.assertEqual(required_groups, exp)
Exemplo n.º 6
0
 def test_required_baya_groups_repeats(self):
     """Repeated roles should only be shown once."""
     admins = []
     role = g('A')
     # Mock model admins, each with the same required role
     for i in range(5):
         model = MagicMock(_meta=MagicMock(app_label='%s' % i))
         model_opts = MagicMock(_gate=MagicMock(
             _gate=MagicMock()))
         model_opts._gate.get_requires = role
         admins.append((model, model_opts))
     with mock.patch.object(
             NestedGroupsAdminSite,
             '_get_admins_with_gate',
             return_value=admins):
         site = NestedGroupsAdminSite()
         required_groups = site._get_required_baya_groups()
         exp = g('A')
         self.assertEqual(required_groups, exp)
Exemplo n.º 7
0
from django.contrib import admin
from django.shortcuts import render

from baya.admin import BayaModelAdmin
from baya.admin import BayaInlineMixin
from baya.admin.sites import NestedGroupsAdminSite
from baya import requires
from baya import SetMembershipNode as g
from baya.permissions import DENY_ALL

from .models import Blag
from .models import BlagEntry
from .models import PhotoBlagEntry
from .submod.models import Comment

A = g('a')
AA = g('aa')
AAA = g('aaa')
B = g('b')


class UnprotectedPhotoBlagEntryOptions(admin.ModelAdmin):
    pass


class UnprotectedPhotoBlagEntryInline(admin.TabularInline):
    model = PhotoBlagEntry


class ProtectedPhotoBlagEntryInline(BayaInlineMixin, admin.TabularInline):
    CREATE = A | B
Exemplo n.º 8
0
from baya import requires
from baya import RolesNode as g
from baya.membership import DynamicRolesNode as dg
from baya.dynamic_roles import DjangoRequestGroupFormatter as drgf
from baya.tests import views

from .models import Blag
from .views import my_view
from .views import my_undecorated_view
from .views import query_param_view
from .admin import site
from . import nested_urls1
from .submod2 import urls as sub2_urls

A = g('a')
AA = g('aa')
AAA = g('aaa')

urlpatterns = [
    url(r'^$', requires(AA)(ListView.as_view(model=Blag)), name='index'),
    url(r'^login/$',
        LoginView.as_view(template_name='registration/login.html'),
        name='login'),
    url(r'^lazy_login/$',
        LoginView.as_view(template_name='registration/login.html'),
        name='lazy_login'),
    url(r'^my_view_str/$', views.my_view, name='my_view_str'),
    url(r'^my_view/$', my_view, name='my_view'),
    url(r'^lazy_login_my_view',
        requires(AA, login_url=reverse_lazy('lazy_login'))(my_view),
Exemplo n.º 9
0
admin.autodiscover()

from baya import requires
from baya import RolesNode as g
from baya.membership import DynamicRolesNode as dg
from baya.dynamic_roles import DjangoRequestGroupFormatter as drgf

from .models import Blag
from .views import my_view
from .views import my_undecorated_view
from .views import query_param_view
from .admin import site
from . import nested_urls1
from .submod2 import urls as sub2_urls

A = g('a')
AA = g('aa')
AAA = g('aaa')


urlpatterns = patterns(
    '',
    url(r'^$', requires(AA)(ListView.as_view(model=Blag)), name='index'),
    url(r'^login/$', login, name='login'),
    url(r'^lazy_login/$', login, name='lazy_login'),
    url(r'^my_view_str/$', 'baya.tests.views.my_view', name='my_view_str'),
    url(r'^my_view/$', my_view, name='my_view'),
    url(r'^lazy_login_my_view',
        requires(AA, login_url=reverse_lazy('lazy_login'))(my_view),
        name='lazy_login_my_view'),
    # Cannot decorate string paths to views
Exemplo n.º 10
0
from django.contrib import admin
from django.shortcuts import render

from baya.admin import BayaModelAdmin
from baya.admin import BayaInlineMixin
from baya.admin.sites import NestedGroupsAdminSite
from baya import requires
from baya import SetMembershipNode as g
from baya.permissions import DENY_ALL

from .models import Blag
from .models import BlagEntry
from .models import PhotoBlagEntry
from .submod.models import Comment

A = g('a')
AA = g('aa')
AAA = g('aaa')
B = g('b')


class UnprotectedPhotoBlagEntryOptions(admin.ModelAdmin):
    pass


class UnprotectedPhotoBlagEntryInline(admin.TabularInline):
    model = PhotoBlagEntry


class ProtectedPhotoBlagEntryInline(BayaInlineMixin, admin.TabularInline):
    CREATE = A | B
Exemplo n.º 11
0
from django.contrib import admin
from django.shortcuts import render

from baya.admin import BayaModelAdmin
from baya.admin import BayaInlineMixin
from baya.admin.sites import NestedGroupsAdminSite
from baya import requires
from baya import SetMembershipNode as g
from baya.permissions import DENY_ALL

from .models import Blag
from .models import BlagEntry
from .models import PhotoBlagEntry
from .submod.models import Comment

A = g("a")
AA = g("aa")
AAA = g("aaa")
B = g("b")


class UnprotectedPhotoBlagEntryOptions(admin.ModelAdmin):
    pass


class UnprotectedPhotoBlagEntryInline(admin.TabularInline):
    model = PhotoBlagEntry


class ProtectedPhotoBlagEntryInline(BayaInlineMixin, admin.TabularInline):
    CREATE = A | B