Get permissions related to the model specified in constructor

        Returns
        -------
        set
            A set instance of `app_label.codename` formatted permission strings
350267
def _get_model_perms(self, *args):
        
        if not hasattr(self, '_model_perms_cache'):
            if self.model is None:
                self._model_perms_cache = set()
            else:
                self._model_perms_cache = get_model_perms(self.model)
        return self._model_perms_cache
621284
def get_permissions_description(view, method):
    
    if not hasattr(view, 'permission_classes'):
        return ''

    description = ''
    for permission_class in view.permission_classes:
        if permission_class == core_permissions.ActionsPermission:
            actions_perm_description = get_actions_permission_description(view, method)
            if actions_perm_description:
                description += '\n' + actions_perm_description if description else actions_perm_description
            continue
        perm_description = get_entity_description(permission_class)
        description += '\n' + perm_description if description else perm_description

    return '### Permissions:\n' + description if description else ''
1259106
def __get_permissions(self, res, **kwargs):
        
        response = res._(**kwargs)
        return response.get('permissions', None)
417219
def get_permission(self, service, func):
        
        if self.permission:
            perm = self.permission

        elif self.prefix is False:
            # No permission will be checked
            perm = False

        elif self.prefix:
            perm = build_permission_name(service.model_class, self.prefix)

        else:
            name = func.__name__
            # check if there is a translation between default permission and method name
            action_name = METHOD_PERMISSION_TRANSLATION.get(name, name)

            perm = build_permission_name(service.model_class, action_name)
        return perm
770340
def get_permissions_assignments(self, obj=None, permission=None):
        
        session = None
        if obj is not None:
            assert isinstance(obj, Entity)
            session = object_session(obj)

            if obj.id is None:
                obj = None

        if session is None:
            session = db.session()

        pa = session.query(
            PermissionAssignment.permission, PermissionAssignment.role
        ).filter(PermissionAssignment.object == obj)

        if permission:
            pa = pa.filter(PermissionAssignment.permission == permission)

        results = {}
        for permission, role in pa.yield_per(1000):
            results.setdefault(permission, set()).add(role)

        return results
791917
def get_permissions(self):
        
        if not self.object_id:
            return []

        url = self.build_url(
            self._endpoints.get('permissions').format(id=self.object_id))

        response = self.con.get(url)
        if not response:
            return None

        data = response.json()

        # Everything received from cloud must be passed as self._cloud_data_key
        return [DriveItemPermission(parent=self, **{self._cloud_data_key: item})
                for item in data.get('value', [])]
365882
def has_import_permission(self, request):
        
        IMPORT_PERMISSION_CODE = getattr(settings, 'IMPORT_EXPORT_IMPORT_PERMISSION_CODE', None)
        if IMPORT_PERMISSION_CODE is None:
            return True

        opts = self.opts
        codename = get_permission_codename(IMPORT_PERMISSION_CODE, opts)
        return request.user.has_perm("%s.%s" % (opts.app_label, codename))
1250289
def get_permissions(self, user, obj=_nothing):
        
        rule = self._get_rule(obj)

        all_permissions = (
            attr[len('can_'):] for attr in dir(rule)
            if attr.startswith('can_')
        )

        return set(
            permission for permission in all_permissions
            if self.allows(user, permission, obj)
        )
527660
def get_requested_aosp_permissions_details(self):
        
        l = {}
        for i in self.permissions:
            try:
                l[i] = self.permission_module[i]
            except KeyError:
                # if we have not found permission do nothing
                continue
        return l
419887
def get_permissions_class(permissions_name=None):
    
    def load_permissions(permissions_name):
        """Look for a fully qualified flow permissions class."""
        try:
            return import_module('{}'.format(permissions_name)).ResolwePermissions
        except AttributeError:
            raise AttributeError("'ResolwePermissions' class not found in {} module.".format(
                permissions_name))
        except ImportError as ex:
            # The permissions module wasn't found. Display a helpful error
            # message listing all possible (built-in) permissions classes.
            permissions_dir = os.path.join(os.path.dirname(upath(__file__)), '..', 'perms')
            permissions_dir = os.path.normpath(permissions_dir)

            try:
                builtin_permissions = [
                    name for _, name, _ in pkgutil.iter_modules([permissions_dir]) if name not in ['tests']]
            except EnvironmentError:
                builtin_permissions = []
            if permissions_name not in ['resolwe.auth.{}'.format(p) for p in builtin_permissions]:
                permissions_reprs = map(repr, sorted(builtin_permissions))
                err_msg = ("{} isn't an available flow permissions class.\n"
                           "Try using 'resolwe.auth.XXX', where XXX is one of:\n"
                           "    {}\n"
                           "Error was: {}".format(permissions_name, ", ".join(permissions_reprs), ex))
                raise ImproperlyConfigured(err_msg)
            else:
                # If there's some other error, this must be an error in Django
                raise

    if permissions_name is None:
        permissions_name = settings.FLOW_API['PERMISSIONS']

    if permissions_name not in permissions_classes:
        permissions_classes[permissions_name] = load_permissions(permissions_name)

    return permissions_classes[permissions_name]
516657
def _get_all_permissions(opts):
    ""
    perms = []
    for action in settings.DEFAULT_PERMISSIONS:
        perms.append((_get_permission_codename(action, opts), 'Can %s %s' % (action, opts.verbose_name_raw)))
    return perms + list(opts.permissions)
1337935
def get_permissions(self, role):
        """"""
        target_role = AuthGroup.objects(role=role, creator=self.client).first()
        if not target_role:
            return '[]'
        targets = AuthPermission.objects(groups=target_role, creator=self.client).only('name')
        return json.loads(targets.to_json())
1240120
def grant_permissions(self, proxy_model):
        
        ContentType = apps.get_model('contenttypes', 'ContentType')
        try:
            Permission = apps.get_model('auth', 'Permission')
        except LookupError:
            return

        # searched_perms will hold the permissions we're looking for as (content_type, (codename, name))
        searched_perms = []
        ctype = ContentType.objects.get_for_model(proxy_model)
        for perm in self.default_permissions:
            searched_perms.append((
                '{0}_{1}'.format(perm, proxy_model._meta.model_name),
                "Can {0} {1}".format(perm, proxy_model._meta.verbose_name_raw)
            ))

        all_perms = set(Permission.objects.filter(
            content_type=ctype,
        ).values_list(
            'content_type', 'codename'
        ))
        permissions = [
            Permission(codename=codename, name=name, content_type=ctype)
            for codename, name in searched_perms if (ctype.pk, codename) not in all_perms
        ]
        Permission.objects.bulk_create(permissions)
631612
def get_required_permissions(self, request):
        
        perms = []

        if not self.permission_required:
            return perms

        if isinstance(self.permission_required, string_types):
            perms = [self.permission_required, ]
        elif isinstance(self.permission_required, Iterable):
            perms = [perm for perm in self.permission_required]
        else:
            raise ImproperlyConfigured(
                '\'PermissionRequiredMixin\' requires \'permission_required\' '
                'attribute to be set to \'<app_label>.<permission codename>\' but is set to {} '
                'instead'.format(self.permission_required)
            )
        return perms
665717
def check_permissions(self):
        
        # Variable to supply some feedback
        changed_permissions = []
        changed_users = []
        warnings = []

        # Check that all the permissions are available.
        for model, perms in ASSIGNED_PERMISSIONS.items():
            if model == 'profile':
                model_obj = get_profile_model()
            else: model_obj = get_user_model()

            model_content_type = ContentType.objects.get_for_model(model_obj)

            for perm in perms:
                try:
                    Permission.objects.get(codename=perm[0],
                                           content_type=model_content_type)
                except Permission.DoesNotExist:
                    changed_permissions.append(perm[1])
                    Permission.objects.create(name=perm[1],
                                              codename=perm[0],
                                              content_type=model_content_type)

        # it is safe to rely on settings.ANONYMOUS_USER_NAME since it is a
        # requirement of django-guardian
        for user in get_user_model().objects.exclude(username=settings.ANONYMOUS_USER_NAME):
            try:
                user_profile = get_user_profile(user=user)
            except ObjectDoesNotExist:
                warnings.append(_("No profile found for %(username)s") \
                                    % {'username': user.username})
            else:
                all_permissions = get_perms(user, user_profile) + get_perms(user, user)

                for model, perms in ASSIGNED_PERMISSIONS.items():
                    if model == 'profile':
                        perm_object = get_user_profile(user=user)
                    else: perm_object = user

                    for perm in perms:
                        if perm[0] not in all_permissions:
                            assign_perm(perm[0], user, perm_object)
                            changed_users.append(user)

        return (changed_permissions, changed_users, warnings)
1174878
def get_permission_object(self):
        
        if not isinstance(self, BaseCreateView):
            # We do NOT want to call get_object in a BaseCreateView, see issue #85
            if hasattr(self, 'get_object') and callable(self.get_object):
                # Requires SingleObjectMixin or equivalent ``get_object`` method
                return self.get_object()
        return None
761366
def permissions(self):
        
        perms = set(super(DocumentWorkflow, self).permissions())
        if g:
            if hasattr(g, 'permissions'):
                perms.update(g.permissions or [])
            if hasattr(self.document, 'permissions'):
                perms = self.document.permissions(current_auth.actor, perms)
        return perms