示例#1
0
 def test_get_administered_sites(self):
     self._create_simple_setup()
     joe = User.objects.get(username="******")
     administered_sites = get_administered_sites(joe)
     self.assertItemsEqual([s.domain for s in administered_sites], ["foo.site.com", "bar.site.com"])
     jack = User.objects.get(username="******")
     administered_sites = get_administered_sites(jack)
     self.assertItemsEqual([s.domain for s in administered_sites], ["bar.site.com"])
示例#2
0
 def test_get_administered_sites(self):
     self._create_simple_setup()
     joe = User.objects.get(username='******')
     administered_sites = get_administered_sites(joe)
     self.assertItemsEqual([s.domain for s in administered_sites],
                           ['foo.site.com', 'bar.site.com'])
     jack = User.objects.get(username='******')
     administered_sites = get_administered_sites(jack)
     self.assertItemsEqual([s.domain for s in administered_sites],
                           ['bar.site.com'])
示例#3
0
 def test_get_administered_sites(self):
     self._create_simple_setup()
     joe = User.objects.get(username='******')
     administered_sites = get_administered_sites(joe)
     self.assertItemsEqual(
         [s.domain for s in administered_sites],
         ['foo.site.com', 'bar.site.com'])
     jack = User.objects.get(username='******')
     administered_sites = get_administered_sites(jack)
     self.assertItemsEqual(
         [s.domain for s in administered_sites],
         ['bar.site.com'])
示例#4
0
 def test_get_administered_sites_with_user_referencing_glob_page_(self):
     foo_site = Site.objects.create(name="foo.site.com", domain="foo.site.com")
     admin_user = User.objects.create(username="******", password="******")
     site_admin_perms = Permission.objects.filter(content_type__model="user")
     for perm in site_admin_perms:
         admin_user.user_permissions.add(perm)
     gpp = GlobalPagePermission.objects.create(user=admin_user)
     gpp.sites.add(foo_site)
     administered_sites = get_administered_sites(admin_user)
     self.assertEquals(len(administered_sites), 1)
     self.assertItemsEqual([s.pk for s in administered_sites], [foo_site.pk])
示例#5
0
 def test_get_administered_sites_with_user_referencing_glob_page_(self):
     foo_site = Site.objects.create(name='foo.site.com',
                                    domain='foo.site.com')
     admin_user = User.objects.create(username='******', password='******')
     site_admin_perms = Permission.objects.filter(
         content_type__model='user')
     for perm in site_admin_perms:
         admin_user.user_permissions.add(perm)
     gpp = GlobalPagePermission.objects.create(user=admin_user)
     gpp.sites.add(foo_site)
     administered_sites = get_administered_sites(admin_user)
     self.assertEquals(len(administered_sites), 1)
     self.assertItemsEqual([s.pk for s in administered_sites],
                           [foo_site.pk])
示例#6
0
def _get_user_sites(user, site_pk):
    administered_sites = get_administered_sites(user)
    if not administered_sites:
        raise PermissionDenied()

    if not site_pk:
        return (administered_sites[0], administered_sites)

    site_pk = int(site_pk)
    if all(site_pk != s.pk for s in administered_sites):
        raise PermissionDenied()
    else:
        return (next((s for s in administered_sites if site_pk == s.pk),
                     administered_sites[0]),
                administered_sites)
示例#7
0
 def has_change_permission(self, request, obj=None):
     # should be available only to superusers and to site admins that
     #   have at least one site under their control
     user = request.user
     return is_site_admin(user) and len(get_administered_sites(user)) > 0
示例#8
0
 def has_change_permission(self, request, obj=None):
     # should be available only to superusers and to site admins that
     #   have at least one site under their control
     user = request.user
     return is_site_admin(user) and len(get_administered_sites(user)) > 0