diff options
Diffstat (limited to 'ishtar_common')
| -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 | 
3 files changed, 45 insertions, 3 deletions
| 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")), | 
