Reports a user action to the log
@param User $user The user being manipulated
@param Enums\Action $action The operation executed on the user
186043
function ReportUserAction(User $user, Enums\Action $action)
    {
        $logItem = $this->CreateLogItem(Enums\ObjectType::User(), $action);       
        if (!$action->Equals(Enums\Action::Delete()))
        {
            $logUser = new LogUser();
            $logUser->SetLogItem($logItem);
            $logUser->SetUser($user);
            $logUser->Save();
        }
    }
516010
protected function canIf(string $action, ?Authorizable $user = null): bool
    {
        return ! \is_null($user)
                    ? $this->acl->canIfAs($user, $action)
                    : $this->acl->canIf($action);
    }
192139
public function add_user_permission($user, $action)
	{
		$db =  \App::get('db');

		if ($user == 'anonymous')
		{
			$user = '0';
		}

		if (!is_numeric($user))
		{
			$query = "SELECT id FROM `#__users` WHERE username=" . $db->quote($user) . ";";
			$db->setQuery($query);
			$user_id = $db->loadResult();

			if ($user_id === false)
			{
				$this->_error("Unknown user $user");
				return false;
			}
		}
		else
		{
			$user_id = $user;
		}

		$quoted_project_id = $db->quote($this->id);
		$quoted_user_id = $db->quote($user_id);
		$values = '';

		foreach ((array) $action as $a)
		{
			if (!empty($values))
			{
				$values .= ',';
			}
			$values .= "($quoted_project_id,$quoted_user_id," . $db->quote($a) .")";
		}

		$query = "INSERT IGNORE INTO `#__trac_user_permission` (trac_project_id,user_id,action) VALUES " .  $values . ";";

		$db->setQuery($query);
		$db->query();
	}
1245151
public static function canUserRunAction($actionUid, $user = null)
    {
        if (empty($user)) $user = Yii::$app->user;

        $parts = explode('/', $actionUid);
        if ($parts === false || count($parts) < 3) {
            throw new Exception("Illegal action uniqueId format: '{$actionUid}'");
        } else {
            $actionId = array_pop($parts);
            $controllerId = array_pop($parts);
            $moduleUid = implode ('/', $parts);

            $module = Yii::$app->getModule($moduleUid);
            if (empty($module)) {
                //throw new Exception("Can't get module '{$moduleUid}'");
                return false;
            } else {
                $controller = $module->createControllerByID($controllerId);
                if ($controller instanceof YiiBaseController) {
                    //static::$_modulesControllers[$moduleUid][$controllerId] = $controller::className();
                    $behaviors = $controller->behaviors();
                    if (empty($behaviors['access']['rules'])) {
                        $rules = [];
                    } else {
                        $rules = $behaviors['access']['rules'];
                    }
                    //static::$_accessRules[$moduleUid][$controllerId] = $rules;
                } else {
                    throw new Exception("Illegal controller '{$controllerId}' in module '{$moduleUid}'");
                }
            }

            if (empty($rules)) {
                $result = true; // no rules - action allow
            } else {
                $ac = Yii::createObject(['class' => AccessControl::className(), 'user' => $user, 'rules' => $rules]);
                $action = $controller->createAction($actionId);
                $request = Yii::$app->getRequest();
                $result = false; // if rule(s) exists - deny by default
                foreach ($ac->rules as $rule) {
                    if ($rule->allows($action, $user, $request)) {
                        $result = true; // found allow rule
                        break;
                    }
                }
            }

            return $result;
        }
    }
497932
public function editAction(User $user)
    {
        $this->assignElectronicAddressOptions();

        $this->view->assignMultiple([
            'currentUser' => $this->currentUser,
            'user' => $user,
            'availableRoles' => $this->policyService->getRoles()
        ]);
    }
105119
public function outputUserInfo(User $user, OutputInterface $output)
    {
        $output->writeln([
            '  ID: <info>'.$user->getId().'</info>',
            '  eMail: <info>'.$user->getEmail().'</info>',
            '  API-Key: <info>'.$user->getApiKey().'</info>',
        ]);
    }
743451
public function apply(callable $action)
    {
        foreach ($this->each() as $k => $v) {
            call_user_func($action, $v, $k);
        }
    }
943301
protected function authorizationFailedError($resource, $action) {
    // when reading only log the error to avoid errors on the display
    $msg = ObjectFactory::getInstance('message')->
            getText("Authorization failed for action '%0%' on '%1%'.", [$action, $resource]);
    if ($action == PersistenceAction::READ) {
      self::$logger->error($msg."\n".ErrorHandler::getStackTrace());
    }
    else {
      throw new AuthorizationException($msg);
    }
  }
936285
protected function executeCliAction(Config\Action $action) : void
    {
        // since the cli has no straight way to communicate back to php
        // cli hooks have to handle sync stuff by them self
        // so no 'beforeAction' or 'afterAction' is called here
        $runner = new Action\Cli();
        $runner->execute($this->io, $action, $this->arguments);
    }
572351
public function hasPermission($action, User $user = null) {
		return $this->getServiceContainer()->getFirewall()->hasPermission($this->getName(), $action, $user);
	}
1294043
public function action(Action $action) {
        if($action->register === Action::REGISTER_AT_END) {
            $this->registerActionsLast[] = $action;
        } else {
            if($action->register) {
                $this->registerAction($action);
            }
        }
    }
465219
public function deleteUser(User $user)
    {
        $url = self::makeUserUrl($user->tenantId, $user->username);
        $this->service->prepAndSend($url, array(204), 'DELETE', null, false, 'application/json', 'application/json');
	}
44816
private function showAndEdit( Request $request, $action )
    {
        $user = $this->get( 'userfriendly_social_user.oauth_user_provider' )
                     ->findOneByUsernameSlug( $request->get( 'username_slug' ));
        if ( $user )
        {
            $currentUser = $this->get( 'security.context' )->getToken()->getUser();
            if (
                    self::SHOW == $action
                    || $currentUser->getId() == $user->getId()
                    || $this->get( 'security.context' )->isGranted( 'ROLE_ADMIN' )
            )
            {
                return $this->render( 'UserfriendlySocialUserBundle:Profile:' . $action . '.html.twig', array(
                    'user' => $user,
                ));
            }
            throw new AccessDeniedException();
        }
        throw new NotFoundHttpException();
    }
1358112
public function hasAccess(User $user, $controller, $action, $parameters) {
        return self::accessPossible($user, $controller, $action);
    }
558229
public static function accessPossible(User $user, $controller, $action) {
        return self::getImplementation()->accessPossible($user, $controller, $action);
    }
307902
public function userAllowed($action)
    {
        if (user()->isAdmin()) {
            return true;
        }

        $this->_loadPermissions();
        $allowedRoles = $this->_permissions
            ->filter(function ($rule) use ($action) {
                return $rule->get('action') == $action;
            })
            ->extract('role_id')
            ->toArray();
        $intersect = array_intersect($allowedRoles, user()->get('role_ids'));

        return !empty($intersect);
    }
742458
public function log(string $action, string $entity, array $dados, array $old)
    {
        $store = new Json("store/{$entity}");
        $dados['userlogin'] = (!empty($_SESSION['userlogin']) ? $_SESSION['userlogin']['id'] : 0);

        if ($action === "create") {
            $store->save($dados['id'], $dados);
        } else {
            foreach ($old as $item) {
                if ($action === "delete") {
                    if (!empty($item['id']))
                        $store->delete($item['id']);
                } else {
                    $store->save($item['id'], array_merge($item, $dados));
                }
            }
        }
    }