<commit_before><?php

namespace DirectokiBundle\Security;

use DirectokiBundle\Entity\Project;
use JMBTechnology\UserAccountsBundle\Entity\User;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

/**
 *  @license 3-clause BSD
 *  @link https://github.com/Directoki/Directoki-Core/blob/master/LICENSE.txt
 */
class ProjectVoter extends Voter {
    const ADMIN = 'admin';


    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }


    protected function supports($attribute, $subject)
    {
        // if the attribute isn't one we support, return false
        if (!in_array($attribute, array(self::ADMIN))) {
            return false;
        }

        // only vote on Post objects inside this voter
        if (!$subject instanceof Project) {
            return false;
        }

        return true;
    }

    protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
    {
        $user = $token->getUser();
        $doctrine = $this->container->get('doctrine')->getManager();

        switch ($attribute) {
            case self::ADMIN:
                // Owner definitely can
                if ($user instanceof User && $user == $subject->getOwner()) {
                    return true;
                }

                // ProjectHasAdmin
                if($doctrine->getRepository('DirectokiBundle:ProjectAdmin')->findOneBy(array('project'=>$subject, 'user'=>$user))) {
                    return true;
                }

                // Others can not.
                return false;
        }

        throw new \LogicException('This code should not be reached!');
    }



}

<commit_msg>Be clear about user access to Project Admin<commit_after><?php

namespace DirectokiBundle\Security;

use DirectokiBundle\Entity\Project;
use JMBTechnology\UserAccountsBundle\Entity\User;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

/**
 *  @license 3-clause BSD
 *  @link https://github.com/Directoki/Directoki-Core/blob/master/LICENSE.txt
 */
class ProjectVoter extends Voter {
    const ADMIN = 'admin';


    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }


    protected function supports($attribute, $subject)
    {
        // if the attribute isn't one we support, return false
        if (!in_array($attribute, array(self::ADMIN))) {
            return false;
        }

        // only vote on Post objects inside this voter
        if (!$subject instanceof Project) {
            return false;
        }

        return true;
    }

    protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
    {
        $user = $token->getUser();
        $doctrine = $this->container->get('doctrine')->getManager();

        switch ($attribute) {
            case self::ADMIN:
                // Anonymous users def can't
                if (!($user instanceof $user)) {
                    return false;
                }

                // Owner definitely can
                if ($user == $subject->getOwner()) {
                    return true;
                }

                // ProjectHasAdmin
                if($doctrine->getRepository('DirectokiBundle:ProjectAdmin')->findOneBy(array('project'=>$subject, 'user'=>$user))) {
                    return true;
                }

                // Others can not.
                return false;
        }

        throw new \LogicException('This code should not be reached!');
    }



}


{'fraction_non_alphanumeric': 0.11020822752666327, 'fraction_numerical': 0.0005078720162519045, 'mean_word_length': 2.1613162118780096, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1681975', 'n_tokens_mistral': 1053, 'n_tokens_neox': 990, 'n_words': 242}