Parameters:
     - login
     - user
     - table
     - perm
171262
def hasTablePermission(self, login, user, table, perm):
    
    self.send_hasTablePermission(login, user, table, perm)
    return self.recv_hasTablePermission()
347436
def invite(name, emails, perm):
    
    with Session() as session:
        try:
            assert perm in ['rw', 'ro'], \
                   'Invalid permission: {}'.format(perm)
            result = session.VFolder(name).invite(perm, emails)
            invited_ids = result.get('invited_ids', [])
            if len(invited_ids) > 0:
                print('Invitation sent to:')
                for invitee in invited_ids:
                    print('\t- ' + invitee)
            else:
                print('No users found. Invitation was not sent.')
        except Exception as e:
            print_error(e)
            sys.exit(1)
765445
def has_perm(self, perm, forum):
        
        if not self.user.is_anonymous and not self.user.is_active:
            # An inactive user cannot have permissions
            return False
        elif self.user and self.user.is_superuser:
            # The superuser have all permissions
            return True
        return perm in self.get_perms(forum)
52927
def create_perm(self, using=None, *args, **kwargs):
        
        from django.conf import settings
        from django.contrib.auth.models import Permission
        from django.contrib.contenttypes.models import ContentType

        constance_dbs = getattr(settings, 'CONSTANCE_DBS', None)
        if constance_dbs is not None and using not in constance_dbs:
            return
        if ContentType._meta.installed and Permission._meta.installed:
            content_type, created = ContentType.objects.using(using).get_or_create(
                app_label='constance',
                model='config',
            )

            permission, created = Permission.objects.using(using).get_or_create(
                content_type=content_type,
                codename='change_config',
                defaults={'name': 'Can change config'})
299292
def users_for_perms(cls, perm_names, db_session=None):
        
        db_session = get_db_session(db_session)
        query = db_session.query(cls.model)
        query = query.filter(
            cls.models_proxy.User.id == cls.models_proxy.UserGroup.user_id
        )
        query = query.filter(
            cls.models_proxy.UserGroup.group_id
            == cls.models_proxy.GroupPermission.group_id
        )
        query = query.filter(cls.models_proxy.GroupPermission.perm_name.in_(perm_names))

        query2 = db_session.query(cls.model)
        query2 = query2.filter(
            cls.models_proxy.User.id == cls.models_proxy.UserPermission.user_id
        )
        query2 = query2.filter(
            cls.models_proxy.UserPermission.perm_name.in_(perm_names)
        )
        users = query.union(query2).order_by(cls.model.id)
        return users
1041417
public function can($perm, $member = null)
    {
        if (!$member) {
            $member = Security::getCurrentUser();
        }
        if (is_array($perm)) {
            $perm = array_map(array($this, 'can'), $perm, array_fill(0, count($perm), $member));
            return min($perm);
        }
        if ($this->hasMethod($methodName = 'can' . $perm)) {
            return $this->$methodName($member);
        } else {
            return true;
        }
    }
951245
def grantSystemPermission(self, login, user, perm):
    
    self.send_grantSystemPermission(login, user, perm)
    self.recv_grantSystemPermission()
793994
def user_group_perms_processor(request):
    
    org = None
    group = None

    if hasattr(request, "user"):
        if request.user.is_anonymous:
            group = None
        else:
            group = request.user.get_org_group()
            org = request.user.get_org()

    if group:
        context = dict(org_perms=GroupPermWrapper(group))
    else:
        context = dict()

    # make sure user_org is set on our request based on their session
    context["user_org"] = org

    return context
134301
def group_perms_for_user(cls, instance, user, db_session=None):
        
        db_session = get_db_session(db_session, instance)
        perms = resource_permissions_for_users(
            cls.models_proxy,
            ANY_PERMISSION,
            resource_ids=[instance.resource_id],
            user_ids=[user.id],
            db_session=db_session,
        )
        perms = [p for p in perms if p.type == "group"]
        # include all perms if user is the owner of this resource
        groups_dict = dict([(g.id, g) for g in user.groups])
        if instance.owner_group_id in groups_dict:
            perms.append(
                PermissionTuple(
                    user,
                    ALL_PERMISSIONS,
                    "group",
                    groups_dict.get(instance.owner_group_id),
                    instance,
                    True,
                    True,
                )
            )
        return perms
441873
def get_perms(self, forum):
        
        # An inactive user has no permissions.
        if not self.user.is_anonymous and not self.user.is_active:
            return []

        user_model = get_user_model()
        user_groups_related_name = user_model.groups.field.related_query_name()

        if forum.id not in self._forum_perms_cache:
            if self.user and self.user.is_superuser:
                # The superuser has all the permissions.
                perms = list(ForumPermission.objects.values_list('codename', flat=True))
            elif self.user:
                default_auth_forum_perms = (
                    machina_settings.DEFAULT_AUTHENTICATED_USER_FORUM_PERMISSIONS
                )

                user_kwargs_filter = (
                    {'anonymous_user': True} if self.user.is_anonymous
                    else {'user': self.user}
                )

                # Fetches the permissions of the considered user for the given forum.
                user_perms = (
                    UserForumPermission.objects.select_related()
                    .filter(**user_kwargs_filter)
                    .filter(Q(forum__isnull=True) | Q(forum=forum))
                )

                # Computes the list of permissions that are granted for all the forums.
                globally_granted_user_perms = list(
                    filter(lambda p: p.has_perm and p.forum_id is None, user_perms)
                )
                globally_granted_user_perms = [
                    p.permission.codename for p in globally_granted_user_perms
                ]

                # Computes the list of permissions that are granted on a per-forum basis.
                per_forum_granted_user_perms = list(
                    filter(lambda p: p.has_perm and p.forum_id is not None, user_perms)
                )
                per_forum_granted_user_perms = [
                    p.permission.codename for p in per_forum_granted_user_perms
                ]

                # Computes the list of permissions that are not granted on a per-forum basis.
                per_forum_nongranted_user_perms = list(
                    filter(lambda p: not p.has_perm and p.forum_id is not None, user_perms)
                )
                per_forum_nongranted_user_perms = [
                    p.permission.codename for p in per_forum_nongranted_user_perms
                ]

                # If the considered user have no global permissions, the permissions defined by the
                # DEFAULT_AUTHENTICATED_USER_FORUM_PERMISSIONS settings are used instead.
                if self.user.is_authenticated and not globally_granted_user_perms:
                    globally_granted_user_perms = default_auth_forum_perms

                # Finally computes the list of permission codenames that are granted to the user for
                # the considered forum.
                granted_user_perms = [
                    c for c in globally_granted_user_perms if
                    c not in per_forum_nongranted_user_perms
                ]
                granted_user_perms += per_forum_granted_user_perms
                granted_user_perms = set(granted_user_perms)

                perms = granted_user_perms

                # If the user is a registered user, we have to check the permissions of its groups
                # in order to determine the additional permissions they could have.
                if not self.user.is_anonymous:
                    group_perms = (
                        GroupForumPermission.objects.select_related()
                        .filter(**{'group__{}'.format(user_groups_related_name): self.user})
                        .filter(Q(forum__isnull=True) | Q(forum=forum))
                    )

                    globally_granted_group_perms = list(
                        filter(lambda p: p.has_perm and p.forum_id is None, group_perms)
                    )
                    globally_granted_group_perms = [
                        p.permission.codename for p in globally_granted_group_perms
                    ]

                    per_forum_granted_group_perms = list(
                        filter(lambda p: p.has_perm and p.forum_id is not None, group_perms)
                    )
                    per_forum_granted_group_perms = [
                        p.permission.codename for p in per_forum_granted_group_perms
                    ]

                    per_forum_nongranted_group_perms = list(
                        filter(lambda p: not p.has_perm and p.forum_id is not None, group_perms)
                    )
                    per_forum_nongranted_group_perms = [
                        p.permission.codename for p in per_forum_nongranted_group_perms
                    ]

                    granted_group_perms = [
                        c for c in globally_granted_group_perms if
                        c not in per_forum_nongranted_group_perms
                    ]
                    granted_group_perms += per_forum_granted_group_perms
                    granted_group_perms = filter(
                        lambda x: x not in per_forum_nongranted_user_perms, granted_group_perms
                    )
                    granted_group_perms = set(granted_group_perms)

                    # Includes the permissions granted for the user' groups in the initial set of
                    # permission codenames.
                    perms |= granted_group_perms

            self._forum_perms_cache[forum.id] = perms

        return self._forum_perms_cache[forum.id]
1364122
async def setHiveKey(self, path, value):
        '''  '''
        perm = ('hive:set',) + path
        self.user.allowed(perm)
        return await self.cell.hive.set(path, value)
1061805
def add_perm(perm,**kwargs):
    
    #check_perm(kwargs.get('user_id'), 'add_perm')
    perm_i = Perm(name=perm.name, code=perm.code)
    db.DBSession.add(perm_i)
    db.DBSession.flush()

    return perm_i
743406
public static function getFromString($perm)
    {
        list ($app, $code) = explode('.', trim($perm));
        $sql = new Pluf_SQL('code_name=%s AND application=%s', array(
            $code,
            $app
        ));
        $permModel = new User_Role();
        $perms = $permModel->getList(array(
            'filter' => $sql->gen()
        ));
        if ($perms->count() != 1) { // permission does not exist
            if(Pluf::f('core_permession_autoCreate', true)){
                $permModel->code_name = $code;
                $permModel->application = $app;
                if($permModel->create()){
                    return $permModel;
                }
            }
            return false;
        }
        return $perms[0];
    }
1281955
def by_resource_user_and_perm(
        cls, user_id, perm_name, resource_id, db_session=None
    ):
        
        db_session = get_db_session(db_session)

        query = db_session.query(cls.model).filter(cls.model.user_id == user_id)
        query = query.filter(cls.model.resource_id == resource_id)
        query = query.filter(cls.model.perm_name == perm_name)
        return query.first()
443633
def delete_user_permissions(self, user, perm, obj, check_groups=False):
        
        user_perms = self.user_permissions(user, perm, obj, check_groups=False)
        if not user_perms.filter(object_id=obj.id):
            return
        perms = self.user_permissions(user, perm, obj).filter(object_id=obj.id)
        perms.delete()
145524
public function permissions($table) {
		$table = config('center.tables.' . $table);
		$permissions = DB::table(config('center.db.permissions'))->where('table', $table->name)->lists('level', 'user_id');
		$users = DB::table(config('center.db.users'))->get();
		foreach ($users as &$user) {
			$user->level = (isset($permissions[$user->id])) ? $permissions[$user->id] : null;
		}
		$permission_levels = LoginController::getPermissionLevels();
		return view('center::tables.permissions', compact('users', 'table', 'permission_levels'));
	}
1139283
def set_role_perm(role_id, perm_id,**kwargs):
    
    #check_perm(kwargs.get('user_id'), 'edit_perm')

    _get_perm(perm_id)
    role_i = _get_role(role_id)
    roleperm_i = RolePerm(role_id=role_id, perm_id=perm_id)

    role_i.roleperms.append(roleperm_i)

    db.DBSession.flush()

    return role_i