<commit_before><?php
namespace Biopen\CoreBundle\Services;

use Doctrine\ODM\MongoDB\DocumentManager;
use Symfony\Component\Security\Core\SecurityContext;
 
class ConfigurationService 
{
    protected $em;
    protected $securityContext;
    protected $config;

	/**
	* Constructor
	*/
	public function __construct(DocumentManager $documentManager, SecurityContext $securityContext)
	{
	   $this->em = $documentManager;
	   $this->securityContext = $securityContext;
       $this->config = $this->em->getRepository('BiopenCoreBundle:Configuration')->findConfiguration();
	}

	public function isUserAllowed($featureName, $request = null, $email = null)
	{        
        if ($email === null && $request !== null) $email = $request->get('userMail');

        $user = $this->securityContext->getToken()->getUser(); 

        if ($user == 'anon.') $user = null;

        $feature = $this->getFeatureConfig($featureName);

        // CHECK USER IS ALLOWED
        return $feature->isAllowed($user, $request ? $request->get('iframe') : false, $email);
    }

    public function getConfig()
    {
        return $this->config;
    }

    public function getFeatureConfig($featureName)
    {
        switch($featureName)
        {
            case 'report':              $feature = $this->config->getReportFeature();break;
            case 'add':                 $feature = $this->config->getAddFeature();break;
            case 'edit':                $feature = $this->config->getEditFeature();break;
            case 'directModeration':    $feature = $this->config->getDirectModerationFeature();break;
            case 'delete':              $feature = $this->config->getCollaborativeModerationFeature();break;
            case 'vote':                $feature = $this->config->getDeleteFeature();break;<commit_msg>Fixs inversed binding between name and config<commit_after><?php
namespace Biopen\CoreBundle\Services;

use Doctrine\ODM\MongoDB\DocumentManager;
use Symfony\Component\Security\Core\SecurityContext;
 
class ConfigurationService 
{
    protected $em;
    protected $securityContext;
    protected $config;

	/**
	* Constructor
	*/
	public function __construct(DocumentManager $documentManager, SecurityContext $securityContext)
	{
	   $this->em = $documentManager;
	   $this->securityContext = $securityContext;
       $this->config = $this->em->getRepository('BiopenCoreBundle:Configuration')->findConfiguration();
	}

	public function isUserAllowed($featureName, $request = null, $email = null)
	{        
        if ($email === null && $request !== null) $email = $request->get('userMail');

        $user = $this->securityContext->getToken()->getUser(); 

        if ($user == 'anon.') $user = null;

        $feature = $this->getFeatureConfig($featureName);

        // CHECK USER IS ALLOWED
        return $feature->isAllowed($user, $request ? $request->get('iframe') : false, $email);
    }

    public function getConfig()
    {
        return $this->config;
    }

    public function getFeatureConfig($featureName)
    {
        switch($featureName)
        {
            case 'report':              $feature = $this->config->getReportFeature();break;
            case 'add':                 $feature = $this->config->getAddFeature();break;
            case 'edit':                $feature = $this->config->getEditFeature();break;
            case 'directModeration':    $feature = $this->config->getDirectModerationFeature();break;
            case 'delete':              $feature = $this->config->getDeleteFeature();break;
            case 'vote':                $feature = $this->config->getCollaborativeModerationFeature();break;
{'fraction_non_alphanumeric': 0.14074479737130338, 'fraction_numerical': 0.0, 'mean_word_length': 2.890308839190628, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, 'https://': 0, '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': '369670', 'n_tokens_mistral': 996, 'n_tokens_neox': 963, 'n_words': 193}