create Access Control Model

This commit is contained in:
2014-10-28 18:24:34 +01:00
parent ec3e08ff79
commit 7fc8b1ca1e
14 changed files with 501 additions and 48 deletions

View File

@@ -39,21 +39,30 @@ class LoadCenters extends AbstractFixture implements OrderedFixtureInterface
return 100;
}
public static $centers = array(
array(
'name' => 'Center A',
'ref' => 'centerA'
),
array(
'name' => 'Center B',
'ref' => 'centerB'
)
);
public static $refs = array();
public function load(ObjectManager $manager)
{
$centerA = new Center();
$centerA->setName('Center A');
$manager->persist($centerA);
$this->addReference('centerA', $centerA);
$centerB = new Center();
$centerB->setName('center B');
$manager->persist($centerB);
$this->addReference('centerB', $centerB);
foreach (static::$centers as $new) {
$centerA = new Center();
$centerA->setName($new['name']);
$manager->persist($centerA);
$this->addReference($new['ref'], $centerA);
static::$refs[] = $new['ref'];
}
$manager->flush();
}
}

View File

@@ -0,0 +1,63 @@
<?php
/*
* Chill is a suite of a modules, Chill is a software for social workers
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.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\MainBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Chill\MainBundle\Entity\GroupCenter;
use Chill\MainBundle\DataFixtures\ORM\LoadCenters;
use Chill\MainBundle\DataFixtures\ORM\LoadPermissionsGroup;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class LoadGroupCenters extends AbstractFixture implements OrderedFixtureInterface
{
public function getOrder()
{
return 500;
}
public static $refs = array();
public function load(ObjectManager $manager)
{
foreach (LoadCenters::$refs as $centerRef) {
foreach (LoadPermissionsGroup::$refs as $permissionGroupRef) {
$GroupCenter = new GroupCenter();
$GroupCenter->setCenter($this->getReference($centerRef));
$GroupCenter->addPermissionGroup($this->getReference($permissionGroupRef));
$manager->persist($GroupCenter);
$reference = $centerRef.'_'.$permissionGroupRef;
$this->addReference($reference, $GroupCenter);
static::$refs[] = $reference;
echo "Creating $reference... \n";
}
}
$manager->flush();
}
}

View File

@@ -0,0 +1,87 @@
<?php
/*
* Chill is a suite of a modules, Chill is a software for social workers
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.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\MainBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Chill\MainBundle\Entity\PermissionsGroup;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class LoadPermissionsGroup extends AbstractFixture implements OrderedFixtureInterface
{
public function getOrder()
{
return 400;
}
public static $permissionGroup = array(
array(
'name' => 'social',
'role_scopes' => array(
'role_scope_CHILL_FOO_EDIT_social',
'role_scope_CHILL_FOO_SEE_administrative',
"role_scope_CHILL_FOO_EDIT_all"
)
),
array(
'name' => 'administrative',
'role_scopes' => array(
"role_scope_CHILL_FOO_SEE_social",
"role_scope_CHILL_FOO_EDIT_administrative",
"role_scope_CHILL_FOO_EDIT_all"
)
),
array(
'name' => 'direction',
'role_scopes' => array(
"role_scope_CHILL_FOO_EDIT_all",
"role_scope_CHILL_FOO_SEE_DETAILS_social",
"role_scope_CHILL_FOO_SEE_DETAILS_administrative"
)
)
);
public static $refs = array();
public function load(ObjectManager $manager)
{
foreach (static::$permissionGroup as $new) {
$permissionGroup = new PermissionsGroup();
$permissionGroup->setName($new['name']);
foreach ($new['role_scopes'] as $roleScopeRef) {
$permissionGroup->addRoleScope($this->getReference($roleScopeRef));
}
$manager->persist($permissionGroup);
$reference = 'permission_group_'.$new['name'];
echo "Creating $reference \n";
$this->setReference($reference, $permissionGroup);
static::$refs[] = $reference;
}
$manager->flush();
}
}

View File

@@ -46,6 +46,13 @@ class LoadRoleScopes extends AbstractFixture implements OrderedFixtureInterface
'nl' => 'zie foo'
)
),
'CHILL_FOO_SEE_DETAILS' => array(
'names' => array(
'fr' => 'voir foo avec détails',
'en' => 'see foo with details',
'nl' => 'zie foo in details'
)
),
'CHILL_FOO_EDIT' => array(
'names' => array(
'fr' => 'modifier foo',
@@ -66,7 +73,7 @@ class LoadRoleScopes extends AbstractFixture implements OrderedFixtureInterface
->setScope($this->getReference($scopeReference))
;
$reference = 'role_scope_'.$key.'_'.$this->getReference($scopeReference)->getName()['en'];
var_dump($reference);
echo "Creating $reference \n";
$this->addReference($reference, $roleScope);
$manager->persist($roleScope);
static::$references[] = $reference;

View File

@@ -7,15 +7,20 @@ use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Chill\MainBundle\DataFixtures\ORM\LoadCenters;
use Chill\MainBundle\DataFixtures\ORM\LoadPermissionsGroup;
use Chill\MainBundle\Entity\User;
/**
* Load agents into database
* Load fixtures users into database
*
* create a user for each permission_group and center.
* username and password are identicals.
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class LoadUsers extends AbstractFixture implements ContainerAwareInterface
class LoadUsers extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
{
/**
*
* @var ContainerInterface
@@ -26,15 +31,42 @@ class LoadUsers extends AbstractFixture implements ContainerAwareInterface
{
return 1000;
}
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
public static $refs = array();
public function load(ObjectManager $manager)
{
foreach(LoadCenters::$refs as $centerRef) {
foreach(LoadPermissionsGroup::$refs as $permissionGroupRef) {
$user = new User();
$permissionGroup = $this->getReference($permissionGroupRef);
$center = $this->getReference($centerRef);
$username = $center->getName().'_'.$permissionGroup->getName();
$user->setUsername($username)
->setPassword($this->container->get('security.encoder_factory')
->getEncoder($user)
->encodePassword($username, $user->getSalt()));
$user->addGroupCenter($this->getReference($centerRef.'_'.$permissionGroupRef));
$manager->persist($user);
$this->addReference($username, $user);
static::$refs[] = $user->getUsername();
echo "Creating user with username ".$user->getUsername()."... \n";
}
}
$manager->flush();
}
public function setContainer(ContainerInterface $container = null)
{
if (NULL === $container) {
throw new \LogicException('$container should not be null');
}
$this->container = $container;
}
}