This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
[Add] Support roles #30
Milestone
Comments
Will be implemented in the next version. However, not with the expression language but as a separate field, as in the symfony security component.
|
Perhaps this will help others who are looking for a solution. I am using this implementation to get a user context: namespace App\Utils\FeatureToggle;
use App\Entity\User;
use Flagception\Model\Context;
use Flagception\Decorator\ContextDecoratorInterface;
use Symfony\Component\Security\Core\Security;
class UserContextDecorator implements ContextDecoratorInterface
{
/** @var Security */
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
public function getName(): string
{
return 'user_context_decorator';
}
public function decorate(Context $context): Context
{
$vars = $this->security->getUser() instanceof User
? [
'user_id' => $this->security->getUser()->getId(),
'user_roles' => $this->security->getUser()->getRoles(),
]
: [
'user_id' => null,
'user_roles' => [],
];
foreach ($vars as $key => $var) {
$context->add($key, $var);
}
return $context;
}
} It is important that the getUser() method is only called in the |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add one standard role provider for active features.
Example:
The text was updated successfully, but these errors were encountered: