G
G
gitdev2021-05-21 23:24:01
symfony
gitdev, 2021-05-21 23:24:01

How to use Event Listener or Event Subscriber and/or tcnm to refactor the rights checking code?

There is a piece of code that checks the right to delete / update / change status. And I want to reorganize it so that it is not necessary to call checks every time.

Rights check method:

/**
     * @param Proposition $proposition
     * @param User $user
     * @return bool
     */
    public function checkAccessPermission(Proposition $proposition, User $user): bool
    {
        if($proposition->getUser() === $user || $proposition->getVacancy()->getUser() === $user) {
            return true;
        }
        throw new AccessDeniedException();
    }


The code that calls the check:
$this->propositionService->checkAccessPermission($proposition, $this->getUser());

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question