Returns user permissions
@param null|integer $user_id
@return array
15389
public function getPermissions($user_id = null)
    {
        static $permissions = array();

        if (!isset($user_id)) {
            $user_id = $this->uid;
        }

        if (isset($permissions[$user_id])) {
            return $permissions[$user_id];
        }

        $user = $this->get($user_id);

        if (empty($user['role_id'])) {
            return $permissions[$user_id] = array();
        }

        $role = array();
        if (isset($user['role_permissions'])) {
            $role['permissions'] = $user['role_permissions'];
        } else {
            $role = $this->role->get($user['role_id']);
        }

        if (empty($role['permissions'])) {
            return $permissions[$user_id] = array();
        }

        return $permissions[$user_id] = (array) $role['permissions'];
    }
789085
public function getRolesAssignedByPermission($permission_name)
    {
        $roles = user_roles();
        $roles_found = [];
        foreach ($roles as $role) {
            if ($role->hasPermission($permission_name)) {
                $roles_found[] = $role->getOriginalId();
            }
        }
        return $roles_found;
    }
921219
public function userKey($user_id, $key_id)
    {
        return $this->get('users/'.$this->encodePath($user_id).'/keys/'.$this->encodePath($key_id));
    }
1352409
public function getLimit($user_id)
    {
        if (is_numeric($user_id)) {
            $user = $this->user->get($user_id);
            if (isset($user['role_id'])) {
                return $this->getLimitByRole($user['role_id']);
            }
        }

        return $this->getDefaultLimit();
    }
462280
public function revokePermission($permission, $user_id)
    {
        $user = \App\User::findorfail($user_id);

        $user->revokePermissionTo(str_slug($permission, ' '));

        return redirect('scaffold-users/edit/'.$user_id);
    }
265199
public static function delete_by_user_id($user_id = null)
	{
		if (empty($user_id))
		{
			return true;
		}

		$results = self::all()
			->whereEquals('user_id', $user_id)
			->rows();

		foreach ($results as $result)
		{
			if (!$result->destroy())
			{
				return false;
			}
		}

		return true;
	}
48217
public function getUserAllowedRoots()
    {
        $user = $this->getUser();

        if ($user->isAdmin) {
            return null;
        }

        return \array_map('intval', (array) $user->newscategories_roots);
    }
649559
static function _get_user_by_id( $user_id ) {
            self::$_static_logger->entrance( "user_id = {$user_id}" );

            $users = self::get_all_users();

            if ( is_array( $users ) ) {
                if ( isset( $users[ $user_id ] ) &&
                     $users[ $user_id ] instanceof FS_User &&
                     $user_id == $users[ $user_id ]->id
                ) {
                    return $users[ $user_id ];
                }

                // If user wasn't found by the key, iterate over all the users collection.
                foreach ( $users as $user ) {
                    /**
                     * @var FS_User $user
                     */
                    if ( $user_id == $user->id ) {
                        return $user;
                    }
                }
            }

            return null;
        }
110092
public function checkProfileEditPermission($user_id) {
    $current_user_id = App::make('sentry')->getUser()->id;

    // edit his profile
    if ($user_id == $current_user_id) {
      return true;
    }
    // has special permission to edit other user profiles
    $edit_perm = Config::get('authentication::permissions.edit_profile');
    if ($this->hasPermission($edit_perm)) {
      return true;
    }

    return false;
  }
1127278
public function getUser($lead_id)
    {
        $end_point = $this->getResource() . "{$lead_id}?access_token=" . $this->getAccessToken();

        $data = giga_remote_get($end_point);

        return (array) $data;
    }
1085650
public function run($auth_id)
    {
        $user = ORM::for_table('users')
            ->where_equal('auth_id', $auth_id)
            ->find_one();
        if (is_object($user)) {
            return $user->as_array();
        } else {
            return [];
        }
    }
425770
protected function _get_sns_accounts( $user_id ) {
		$sns_accounts     = $this->_sns_accounts();
		$sns_account_keys = array_keys( $sns_accounts );

		$sns_accounts = [];

		foreach ( $sns_account_keys as $sns_account_key ) {
			$sns_account = get_the_author_meta( $sns_account_key, $user_id );
			if ( ! $sns_account ) {
				continue;
			}
			$sns_accounts[ $sns_account_key ] = $sns_account;
		}

		return $sns_accounts;
	}
1259178
public function isSuperadmin($user_id = null)
    {
        if (isset($user_id)) {
            return $this->getSuperadminId() == $user_id;
        }

        return $this->getSuperadminId() == $this->uid;
    }
475743
def get_user_permissions(self, user_id):
        """"""
        permissions = self.user_service.getPermissions(id=user_id)
        return sorted(permissions, key=itemgetter('keyName'))
257888
public function getPermissionsByUserID($user_id, string $role_slug)
    {
        if (session('user.abilities') == null) {

            // Gera um cache de permissões
            // para evitar consultas ao banco de dados

            $cache_all   = [];
            $cache_slugs = [];
            $roles = \Acl\Models\AclRole::all();
            foreach($roles as $item) {
                $cache_all[$item->slug] = $item->toArray();
                $cache_slugs[$item->id] = $item->slug;
            }

            // As permissões setadas para o usuário tem precedência
            $user_permissions = \Acl\Models\AclUserPermission::where('user_id', $user_id)->get();
            if ($user_permissions->count() > 0) {
                foreach($user_permissions as $item) {
                    if (isset($cache_slugs[$item->role_id])) {
                        $slug = $cache_slugs[$item->role_id];
                        $cache_all[$slug]['permissions'] = $item->toArray();
                    }
                }

                if(isset($cache_all[$role_slug]) && isset($cache_all[$role_slug]['permissions'])) {
                    // A função de acesso foi encontrada nas permissões de usuário
                    \Acl\Core::traceCurrentAbilityOrigin('user');
                }
            }
            // Quando não existem permissões setadas para o usuário,
            // as permissões do grupo são usadas no lugar
            else {

                $group_relation = \Acl\Models\AclUser::find($user_id)->groupRelation;
                if($group_relation != null) {
                    $group_id = $group_relation->group_id;
                    $group_permissions = \Acl\Models\AclGroupPermission::where('group_id', $group_id)->get();
                } else {
                    $group_permissions = collect([]);
                }
                foreach($group_permissions as $item) {
                    if (isset($cache_slugs[$item->role_id])) {
                        $slug = $cache_slugs[$item->role_id];
                        $cache_all[$slug]['permissions'] = $item->toArray();
                    }
                }

                if(isset($cache_all[$role_slug]) && isset($cache_all[$role_slug]['permissions'])) {
                    // A função de acesso foi encontrada nas permissões de grupo
                    \Acl\Core::traceCurrentAbilityOrigin('group');
                }
            }

            session([ 'user.abilities' => collect($cache_all) ]);
        }

        $user_abilities = session('user.abilities');

        if (isset($user_abilities[$role_slug]) && isset($user_abilities[$role_slug]['permissions'])) {
            // A função de acesso foi encontrada
            return $user_abilities[$role_slug];
        } else {
            return null;
        }
    }
1322328
public function getClientUser($client_id, $user_id)
    {
        $sql = 'SELECT * from %s where client_id = :client_id and user_id = :user_id';
        $sql = sprintf($sql, $this->config['client_user_table']);

        return $this->fetch($sql, compact('client_id', 'user_id'));
    }
345921
public function getResourcesPermissions(User $user, $resources)
    {
        $permissions = [];
        if(!is_null($user)){
            try {
                $permissionManager = $this->getServiceManager()->get(PermissionInterface::SERVICE_ID);
                $supportedRights   = $permissionManager->getSupportedRights();
                $permissions['supportedRights'] = $supportedRights;

                if(count($supportedRights) > 0){
                    $uris = $this->getUris($resources);

                    $permissions['data'] = $permissionManager->getPermissions($user, $uris);
                }
            } catch(\Exception $e){
                \common_Logger::w('Unable to retrieve permssions ' . $e->getMessage());
            }
        }
        return $permissions;

    }