Beispiel #1
0
    def set_permissions(self, perm_spec):
        remove_object_permissions(self)
        try:
            from geonode.security.utils import (set_owner_permissions)
            set_owner_permissions(self)
        except BaseException:
            pass
        if 'users' in perm_spec and "AnonymousUser" in perm_spec['users']:
            anonymous_group = Group.objects.get(name='anonymous')
            for perm in perm_spec['users']['AnonymousUser']:
                assign_perm(perm, anonymous_group, self.get_self_resource())

        if 'groups' in perm_spec:
            for group, perms in perm_spec['groups'].items():
                group = Group.objects.get(name=group)
                for perm in perms:
                    assign_perm(perm, group, self.get_self_resource())
Beispiel #2
0
                            'users': {
                                'AnonymousUser': ['view'],
                                <username>: ['perm1','perm2','perm3'],
                                <username2>: ['perm1','perm2','perm3']
                                ...
                            }
                            'groups': [
                                <groupname>: ['perm1','perm2','perm3'],
                                <groupname2>: ['perm1','perm2','perm3'],
                                ...
                                ]
                        }
                        """

                        # default permissions for resource owner
                        set_owner_permissions(
                            _resource, members=get_obj_group_managers(_owner))

                        # Anonymous User group
                        if 'users' in permissions and "AnonymousUser" in permissions[
                                'users']:
                            anonymous_group = Group.objects.get(
                                name='anonymous')
                            for perm in permissions['users']['AnonymousUser']:
                                if _resource.polymorphic_ctype.name == 'dataset' and perm in (
                                        'change_dataset_data',
                                        'change_dataset_style',
                                        'add_dataset',
                                        'change_dataset',
                                        'delete_dataset',
                                ):
                                    assign_perm(perm, anonymous_group,