diff options
| -rw-r--r-- | archaeological_context_records/models.py | 1 | ||||
| -rw-r--r-- | archaeological_files/models.py | 1 | ||||
| -rw-r--r-- | archaeological_finds/models.py | 3 | ||||
| -rw-r--r-- | archaeological_operations/models.py | 3 | ||||
| -rw-r--r-- | archaeological_warehouse/models.py | 1 | ||||
| -rw-r--r-- | ishtar_common/management/commands/regenerate_permissions.py | 40 | ||||
| -rw-r--r-- | ishtar_common/menu_base.py | 5 | ||||
| -rw-r--r-- | ishtar_common/models.py | 3 | 
8 files changed, 54 insertions, 3 deletions
| diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index c558587aa..93b37d87e 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -133,6 +133,7 @@ class ContextRecord(BaseHistorizedItem, OwnPerms):          verbose_name = _(u"Context Record")          verbose_name_plural = _(u"Context Record")          permissions = ( + ("view_contextrecord", ugettext(u"Can view all Context Record")),   ("view_own_contextrecord", ugettext(u"Can view own Context Record")),   ("add_own_contextrecord", ugettext(u"Can add own Context Record")),   ("change_own_contextrecord", ugettext(u"Can change own Context Record")), diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 1bcaa2ced..8f2f513d2 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -106,6 +106,7 @@ class File(BaseHistorizedItem, OwnPerms):          verbose_name = _(u"Archaeological file")          verbose_name_plural = _(u"Archaeological files")          permissions = ( +            ("view_file", ugettext(u"Can view all Archaelogical file")),              ("view_own_file", ugettext(u"Can view own Archaelogical file")),              ("add_own_file", ugettext(u"Can add own Archaelogical file")),              ("change_own_file", ugettext(u"Can change own Archaelogical file")), diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index ce0df10cf..9c1e72e38 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -55,6 +55,7 @@ class BaseFind(BaseHistorizedItem, OwnPerms):          verbose_name = _(u"Base find")          verbose_name_plural = _(u"Base finds")          permissions = ( +            ("view_basefind", ugettext(u"Can view all Base find")),              ("view_own_basefind", ugettext(u"Can view own Base find")),              ("add_own_basefind", ugettext(u"Can add own Base find")),              ("change_own_basefind", ugettext(u"Can change own Base find")), @@ -192,6 +193,7 @@ class Find(BaseHistorizedItem, OwnPerms):          verbose_name = _(u"Find")          verbose_name_plural = _(u"Finds")          permissions = ( +            ("view_find", ugettext(u"Can view all Find")),              ("view_own_find", ugettext(u"Can view own Find")),              ("add_own_find", ugettext(u"Can add own Find")),              ("change_own_find", ugettext(u"Can change own Find")), @@ -251,6 +253,7 @@ class Treatment(BaseHistorizedItem, OwnPerms):          verbose_name = _(u"Treatment")          verbose_name_plural = _(u"Treatments")          permissions = ( +            ("view_treatment", ugettext(u"Can view all Treatment")),              ("view_own_treatment", ugettext(u"Can view own Treatment")),              ("add_own_treatment", ugettext(u"Can add own Treatment")),              ("change_own_treatment", ugettext(u"Can change own Treatment")), diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index fb6b856db..36781249f 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -131,6 +131,7 @@ class Operation(BaseHistorizedItem, OwnPerms):          verbose_name = _(u"Operation")          verbose_name_plural = _(u"Operations")          permissions = ( +            ("view_operation", ugettext(u"Can view all Operation")),              ("view_own_operation", ugettext(u"Can view own Operation")),              ("add_own_operation", ugettext(u"Can add own Operation")),              ("change_own_operation", ugettext(u"Can change own Operation")), @@ -304,6 +305,8 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms):          verbose_name = _(u"Administrative act")          verbose_name_plural = _(u"Administrative acts")          permissions = ( +            ("view_administrativeact", +             ugettext(u"Can view all Administrative act")),              ("view_own_administrativeact",               ugettext(u"Can view own Administrative act")),              ("add_own_administrativeact", diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 877d16487..d67a5768c 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -42,6 +42,7 @@ class Warehouse(Address, OwnPerms):          verbose_name = _(u"Warehouse")          verbose_name_plural = _(u"Warehouses")          permissions = ( +            ("view_warehouse", ugettext(u"Can view all Warehouse")),              ("view_own_warehouse", ugettext(u"Can view own Warehouse")),              ("add_own_warehouse", ugettext(u"Can add own Warehouse")),              ("change_own_warehouse", ugettext(u"Can change own Warehouse")), diff --git a/ishtar_common/management/commands/regenerate_permissions.py b/ishtar_common/management/commands/regenerate_permissions.py new file mode 100644 index 000000000..c2af8b353 --- /dev/null +++ b/ishtar_common/management/commands/regenerate_permissions.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2013 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. + +# See the file COPYING for details. + +import sys + +from django.db import models +from django.core.management.base import BaseCommand, CommandError +from django.contrib.contenttypes.models import ContentType + +from django.contrib.auth.models import Permission + +class Command(BaseCommand): +    args = '' +    help = 'Regenerate permissions' + +    def handle(self, *args, **options): +        for ct in ContentType.objects.all(): +            model = ct.model_class() +            if not model: +                continue +            for perm_slug, perm_label in model._meta.permissions: +                Permission.objects.get_or_create(content_type=ct, +                                    codename=perm_slug, +                                    defaults={'name':perm_label}) diff --git a/ishtar_common/menu_base.py b/ishtar_common/menu_base.py index 02e110910..37f482219 100644 --- a/ishtar_common/menu_base.py +++ b/ishtar_common/menu_base.py @@ -1,6 +1,6 @@  #!/usr/bin/env python  # -*- coding: utf-8 -*- -# Copyright (C) 2012 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2012-2013 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet>  # This program is free software: you can redistribute it and/or modify  # it under the terms of the GNU Affero General Public License as @@ -57,7 +57,8 @@ class MenuItem:              return True          for access_control in self.access_controls:              access_control = self.model._meta.app_label + '.' + access_control -            if user.has_perm(access_control, self.model): +            if user.has_perm(access_control, self.model) or \ +               access_control in user.get_group_permissions():                  return True          # manage by person type          if hasattr(user, 'ishtaruser'): diff --git a/ishtar_common/models.py b/ishtar_common/models.py index cf1448497..1cff9f8f5 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -536,6 +536,7 @@ class Organization(Address, OwnPerms):          verbose_name = _(u"Organization")          verbose_name_plural = _(u"Organizations")          permissions = ( +          ("view_organization", ugettext(u"Can view all Organization")),            ("view_own_organization", ugettext(u"Can view own Organization")),            ("add_own_organization", ugettext(u"Can add own Organization")),            ("change_own_organization", ugettext(u"Can change own Organization")), @@ -570,7 +571,7 @@ class Person(Address, OwnPerms) :          verbose_name = _(u"Person")          verbose_name_plural = _(u"Persons")          permissions = ( -            ("view_person", ugettext(u"Can view Person")), +            ("view_person", ugettext(u"Can view all Person")),              ("view_own_person", ugettext(u"Can view own Person")),              ("add_own_person", ugettext(u"Can add own Person")),              ("change_own_person", ugettext(u"Can change own Person")), | 
