mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
adapting classes to new interfaces
This commit is contained in:
parent
9f7fe05991
commit
7619b41cd4
@ -27,6 +27,8 @@ use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader;
|
||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||
use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter;
|
||||
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
|
||||
|
||||
/**
|
||||
* This is the class that loads and manages your bundle configuration
|
||||
@ -72,8 +74,9 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf
|
||||
{
|
||||
$container->prependExtensionConfig('security', array(
|
||||
'role_hierarchy' => array(
|
||||
'CHILL_ACTIVITY_UPDATE' => array('CHILL_ACTIVITY_SEE'),
|
||||
'CHILL_ACTIVITY_CREATE' => array('CHILL_ACTIVITY_SEE')
|
||||
ActivityVoter::UPDATE => array(ActivityVoter::SEE),
|
||||
ActivityVoter::CREATE => array(ActivityVoter::SEE),
|
||||
ActivityVoter::SEE => array(ActivityStatsVoter::STATS)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Chill\MainBundle\Export\AggregatorInterface;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -86,9 +87,28 @@ class ReasonAggregator implements AggregatorInterface
|
||||
return "Aggregate by activity reason";
|
||||
}
|
||||
|
||||
public function requiredRole()
|
||||
public function addRole()
|
||||
{
|
||||
return new Role('dummy');
|
||||
return new Role(ActivityVoter::SEE);
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
return array_combine($values, $values);
|
||||
|
||||
}
|
||||
|
||||
public function getQueryKeys($data)
|
||||
{
|
||||
// add select element
|
||||
if ($data['level'] === 'reason') {
|
||||
return array('activity_reason_id');
|
||||
} elseif ($data['level'] === 'category') {
|
||||
return array ('activity_category_id');
|
||||
} else {
|
||||
throw new \RuntimeException('the data provided are not recognised');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,9 +20,10 @@
|
||||
namespace Chill\ActivityBundle\Export\Export;
|
||||
|
||||
use Chill\MainBundle\Export\ExportInterface;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Doctrine\ORM\Query;
|
||||
use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -77,7 +78,34 @@ class CountActivity implements ExportInterface
|
||||
|
||||
public function requiredRole()
|
||||
{
|
||||
return new Role('dummy');
|
||||
return new Role(ActivityStatsVoter::STATS);
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes()
|
||||
{
|
||||
return array(\Chill\MainBundle\Export\FormatterInterface::TYPE_TABULAR);
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
if ($key !== 'export_count_activity') {
|
||||
throw new \LogicException("the key $key is not used by this export");
|
||||
}
|
||||
|
||||
$labels = array_combine($values, $values);
|
||||
$labels['_header'] = 'Number of activities';
|
||||
|
||||
return $labels;
|
||||
}
|
||||
|
||||
public function getQueryKeys($data)
|
||||
{
|
||||
return array('export_count_activity');
|
||||
}
|
||||
|
||||
public function getResult(QueryBuilder $qb, $data)
|
||||
{
|
||||
return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ use Chill\ActivityBundle\Entity\ActivityReason;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Doctrine\ORM\Query\Expr;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -90,8 +91,8 @@ class ActivityReasonFilter implements FilterInterface
|
||||
return 'Filter by reason';
|
||||
}
|
||||
|
||||
public function requiredRole()
|
||||
public function addRole()
|
||||
{
|
||||
return new Role('dummy');
|
||||
return new Role(ActivityVoter::SEE);
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,14 @@ services:
|
||||
- { name: security.voter }
|
||||
- { name: chill.role }
|
||||
|
||||
chill.activity.security.authorization.activity_stats_voter:
|
||||
class: Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter
|
||||
arguments:
|
||||
- "@chill.main.security.authorization.helper"
|
||||
tags:
|
||||
- { name: security.voter }
|
||||
- { name: chill.role }
|
||||
|
||||
|
||||
chill.activity.timeline:
|
||||
class: Chill\ActivityBundle\Timeline\TimelineActivityProvider
|
||||
|
76
Security/Authorization/ActivityStatsVoter.php
Normal file
76
Security/Authorization/ActivityStatsVoter.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Champs-Libres <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\ActivityBundle\Security\Authorization;
|
||||
|
||||
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Security\ProvideRoleInterface;
|
||||
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class ActivityStatsVoter extends AbstractChillVoter implements ProvideRoleInterface
|
||||
{
|
||||
const STATS = 'CHILL_ACTIVITY_STATS';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $helper;
|
||||
|
||||
public function __construct(AuthorizationHelper $helper)
|
||||
{
|
||||
$this->helper = $helper;
|
||||
}
|
||||
|
||||
protected function getSupportedAttributes()
|
||||
{
|
||||
return array(self::STATS, ActivityVoter::SEE);
|
||||
}
|
||||
|
||||
protected function getSupportedClasses()
|
||||
{
|
||||
return array('Chill\MainBundle\Entity\Center');
|
||||
}
|
||||
|
||||
protected function isGranted($attribute, $object, $user = null)
|
||||
{
|
||||
if (!$user instanceof \Symfony\Component\Security\Core\User\UserInterface) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->helper->userHasAccess($user, $object, $attribute);
|
||||
}
|
||||
|
||||
public function getRoles()
|
||||
{
|
||||
$this->getSupportedAttributes();
|
||||
}
|
||||
|
||||
public function getRolesWithoutScope()
|
||||
{
|
||||
$this->getSupportedAttributes();
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user