@param User $user

@return array
965189
private function serializePermissions(User $user)
    {
        $currentUser = $this->tokenStorage->getToken()->getUser();

        $isOwner = $currentUser instanceof User && $currentUser->getUuid() === $user->getUuid();
        $isAdmin = $this->authChecker->isGranted('ROLE_ADMIN'); // todo maybe add those who have access to UserManagement tool

        // todo : move role check elsewhere
        $profileConfig = $this->config->getParameter('profile');
        $editRoles = [];
        if (!empty($profileConfig['roles_edition'])) {
            $editRoles = array_filter($this->tokenStorage->getToken()->getRoles(), function (BaseRole $role) use ($profileConfig) {
                return in_array($role->getRole(), $profileConfig['roles_edition']);
            });
        }

        return [
            'contact' => !$isOwner,
            'edit' => $isAdmin || !empty($editRoles),
            'administrate' => $isAdmin,
            'delete' => $isOwner || $isAdmin, // todo check platform param to now if current user can destroy is account
        ];
    }
851114
public function roles(User $user)
    {
        if ($this->session->hasValue(Roles::SESSION_KEY)) {
            return $this->session->value(Roles::SESSION_KEY);
        }

        $roles = $this->authorizationProvider->roles($user);
        $this->session->putValue(Roles::SESSION_KEY, $roles);
        return $roles;
    }
366560
public function getResumableDeliveries(User $user)
    {
        $deliveryExecutionService = ServiceProxy::singleton();
        $resumable = array();
        foreach ($this->getResumableStates() as $state) {
            foreach ($deliveryExecutionService->getDeliveryExecutionsByStatus($user->getIdentifier(), $state) as $execution) {
                $delivery = $execution->getDelivery();
                if ($delivery->exists()) {
                    $resumable[] = $execution;
                }
            }
        }
        return $resumable;
    }
881987
protected function loadUserRolesViaManyToMany($user)
    {
        $roles = ['ROLE_USER'];
        if (is_string($this->userRoleIdentifier)) {
            foreach ($user->get($this->userRoleIdentifier) as $role) {
                $roles[] = $role['name'];
            }
        }
        return $roles;
    }
624831
public function includeRoles(User $user)
    {
        $roles = $user->roles;
        return $this->collection($roles, new RoleTransformer());
    }
314511
public function loadUser(User $user)
    {
        // Guests do not have a user id. So do not try to load data for guests.
        if ($user->isGuest()) {
            return;
        }

        $this->db->qb([
            'table' => $this->table,
            'field' => [
                'username',
                'display_name',
                'state'
            ],
            'filter' => 'id_user=:id_user',
            'params' => [
                ':id_user' => $user->getId()
            ]
        ]);

        $data = $this->db->single();

        if (!empty($data)) {

            $user->setUsername($data['username']);

            // Use username as display_name when there is no display_name for this user
            $user->setDisplayName(empty($data['display_name']) ? $data['username'] : $data['display_name']);

            // Load the groups the user is in
            $this->db->qb([
                'table' => 'core_users_groups',
                'fields' => 'id_group',
                'filter' => 'id_user=:id_user',
                'params' => [
                    ':id_user' => $user->getId()
                ]
            ]);

            $groups = $this->db->column();

            if (!empty($groups)) {

                $user->groups->set($groups);

                // Create a prepared string and param array to use in query
                $prepared = $this->db->prepareArrayQuery('group', $groups);

                // Get and return the permissions
                $this->db->qb([
                    'table' => 'core_groups_permissions',
                    'fields' => [
                        'storage',
                        'permission'
                    ],
                    'method' => 'SELECT DISTINCT',
                    'filter' => 'id_group IN (' . $prepared['sql'] . ')',
                    'params' => $prepared['values']
                ]);

                $permissions = $this->db->all();

                foreach ($permissions as $perm) {

                    if (!array_key_exists($perm['storage'], $user->permissions)) {
                        $user->permissions[$perm['storage']] = new UserPermissions();
                    }

                    $user->permissions[$perm['storage']]->add($perm['permission']);
                }

                // Is the user an admin?
                if (!empty($user->permissions['Core']->allowedTo('admin'))) {
                    $user->setAdmin(true);
                }
            }
        }
    }
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;

    }
928370
protected function loadRecordData(User $user)
    {
        $this->setData($user->getData());

        // 清空更改状态
        $this->isChanged = false;
        $this->changedData = [];
    }
468381
public function includeAbilities(User $user)
    {
        $abilities = isset($user->selected_context_id) ? $user->selected_context->abilities : [];

        return $this->collection($abilities, new AbilityTransformer, 'ability');
    }
943997
private function listUserAuthorizedMetadataFields(User $user)
    {
        $acl = $this->getAclForUser($user);
        $ret = [];

        foreach ($acl->get_granted_sbas() as $databox) {
            $databoxId = $databox->get_sbas_id();
            foreach ($databox->get_meta_structure() as $databox_field) {
                $data = [
                  'name'             => $databox_field->get_name(),
                  'id'               => $databox_field->get_id(),
                  'databox_id'       => $databoxId,
                  'multivalue'       => $databox_field->is_multi(),
                  'indexable'        => $databox_field->is_indexable(),
                  'readonly'         => $databox_field->is_readonly(),
                  'business'         => $databox_field->isBusiness(),
                  'source'           => $databox_field->get_tag()->getTagname(),
                  'labels'           => [
                    'fr' => $databox_field->get_label('fr'),
                    'en' => $databox_field->get_label('en'),
                    'de' => $databox_field->get_label('de'),
                    'nl' => $databox_field->get_label('nl'),
                  ],
                ];
                $ret[] = $data;
            }

            if ($acl->can_see_business_fields($databox) === false) {
                $ret = array_values($this->removeBusinessFields($ret));
            }
        }

        return $ret;
    }
976468
public function getUserGuidedPortfolioData(Portfolio $portfolio, User $user)
    {
        return [
            'type' => ($user === $portfolio->getUser()) ? 'owned' : 'guided',
            'id' => $portfolio->getId(),
            'title' => $portfolio->getTitle(),
            'unreadComments' => $portfolio->getCountUnreadComments(),
            'commentsViewAt' => $portfolio->getCommentsViewAt()->format(DATE_W3C),
        ];
    }
481534
public function getFavouriteWorkspacesByUser(User $user)
    {
        $workspaces = [];

        /** @var WorkspaceFavourite[] $favourites */
        $favourites = $this->om
            ->getRepository('ClarolineCoreBundle:Workspace\WorkspaceFavourite')
            ->findBy([
                'user' => $user,
            ]);

        foreach ($favourites as $favourite) {
            $workspace = $favourite->getWorkspace();
            $workspaces[$workspace->getId()] = $workspace;
        }

        return $workspaces;
    }
27761
public function getData(UserInterface $user): array
    {
        $userData = array();
        $userData[ self::FIELD_ID ] = $user->getId()->toString();
        $userData[ self::FIELD_EMAIL ] = $user->getEmail()->getEmail();
        $userData[ self::FIELD_NAME ] = $user->getName();
        $userData[ self::FIELD_BIRTHDAY ] = is_null($user->getBirthday()) ? null : $user->getBirthday()->format('Y-m-d');
        $userData[ self::FIELD_LAST_LOGIN ] = $user->getLastLogin()->format('Y-m-d H:i:s');

        return $userData;
    }
1208473
private function get_notifications($user) : array {
        $notifications = $this->notifications;
        $discussion = $this->discussion;
        $forum = $this->forum;
        $renderer = $this->renderer;

        if ($forum->is_cutoff_date_reached()) {
            $notifications[] = (new notification(
                    get_string('cutoffdatereached', 'forum'),
                    notification::NOTIFY_INFO
            ))->set_show_closebutton();
        } else if ($forum->is_due_date_reached()) {
            $notifications[] = (new notification(
                    get_string('thisforumisdue', 'forum', userdate($forum->get_due_date())),
                    notification::NOTIFY_INFO
            ))->set_show_closebutton();
        } else if ($forum->has_due_date()) {
            $notifications[] = (new notification(
                    get_string('thisforumhasduedate', 'forum', userdate($forum->get_due_date())),
                    notification::NOTIFY_INFO
            ))->set_show_closebutton();
        }

        if ($forum->is_discussion_locked($discussion)) {
            $notifications[] = (new notification(
                get_string('discussionlocked', 'forum'),
                notification::NOTIFY_INFO
            ))
            ->set_extra_classes(['discussionlocked'])
            ->set_show_closebutton();
        }

        if ($forum->get_type() == 'qanda') {
            if ($this->capabilitymanager->must_post_before_viewing_discussion($user, $discussion)) {
                $notifications[] = (new notification(
                    get_string('qandanotify', 'forum')
                ))->set_show_closebutton(true);
            }
        }

        if ($forum->has_blocking_enabled()) {
            $notifications[] = (new notification(
                get_string('thisforumisthrottled', 'forum', [
                    'blockafter' => $forum->get_block_after(),
                    'blockperiod' => get_string('secondstotime' . $forum->get_block_period())
                ])
            ))->set_show_closebutton();
        }

        return array_map(function($notification) {
            return $notification->export_for_template($this->renderer);
        }, $notifications);
    }
400354
private function fetch(User $user)
    {
        return self::$cache[$user->getId()] = new \ACL($user, $this->app);
    }
1048807
public function get(User $user)
    {
        if (null !== $acl = $this->fetchFromCache($user)) {
            return $acl;
        }

        return $this->fetch($user);
    }
1102391
public static function forUser(User $user)
    {
        if ($user->getIsGuest()) {
            return Yii::$app->session;
        }

        return Yii::createObject(['class' => RemoteCartStorage::class, 'sessionCartId' => 'yz\shoppingcart\ShoppingCart']);
    }