+ *
+ * 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 .
+#}
+
+{% extends "ChillMainBundle::Menu/verticalMenu.html.twig" %}
+{% block v_menu_title %}{{ 'Permissions Menu'|trans }}{% endblock %}
\ No newline at end of file
diff --git a/Resources/views/PermissionsGroup/edit.html.twig b/Resources/views/PermissionsGroup/edit.html.twig
new file mode 100644
index 000000000..3a53dd2da
--- /dev/null
+++ b/Resources/views/PermissionsGroup/edit.html.twig
@@ -0,0 +1,78 @@
+{% extends 'ChillMainBundle::Admin/layout_permissions.html.twig' %}
+
+{% block title %}{{ 'PermissionsGroup "%name%" edit'|trans( { '%name%': entity.name } ) }}{% endblock %}
+
+{% block admin_content -%}
+ {{ 'PermissionsGroup "%name%" edit'|trans( { '%name%': entity.name } ) }}
+
+ {{ 'Details'|trans }}
+
+ {{ form_start(edit_form) }}
+ {{ form_row(edit_form.name) }}
+ {{ form_row(edit_form.submit, { 'attr': { 'class': 'sc-button green' } } ) }}
+ {{ form_end(edit_form) }}
+
+ {{ 'Grant those permissions'|trans }} :
+
+ {%- if entity.getRoleScopes|length > 0 -%}
+
+
+
+ {{ 'Role'|trans }} |
+ {{ 'Circle'|trans }} |
+ {{ 'Actions'|trans }} |
+
+
+
+
+ {% for role_scope in entity.getRoleScopes %}
+
+
+ {{ role_scope.role|trans }}
+ {% if expanded_roles[role_scope.role]|length > 1 %}
+
+ {{ 'Which implies'|trans }} : {% for role in expanded_roles[role_scope.role] %}{{ role }}{% if not loop.last %}, {% endif %}{% endfor %}
+ {% endif %}
+ |
+
+ {%- if role_scope.scope is not null -%}
+
+ {{ role_scope.scope.name|localize_translatable_string }}
+
+ {%- else -%}
+ N/A
+ {%- endif -%}
+ |
+
+ {{ form_start(delete_role_scopes_form[role_scope.id]) }}
+ {{ form_widget(delete_role_scopes_form[role_scope.id].submit, { 'attr': { 'class': 'sc-button red' } } ) }}
+ {{ form_end(delete_role_scopes_form[role_scope.id]) }}
+ |
+
+
+ {% endfor %}
+
+
+
+ {%- else -%}
+ {{ 'This group does not provide any permission'|trans }}
+ {%- endif -%}
+
+ {{ 'Grant new permissions'|trans }}
+
+ {{ form_start(add_role_scopes_form) }}
+ {{ form_errors(add_role_scopes_form) }}
+ {{ form_row(add_role_scopes_form.composed_role_scope.role) }}
+ {{ form_row(add_role_scopes_form.composed_role_scope.scope) }}
+ {{ form_row(add_role_scopes_form.submit, { 'attr' : { 'class': 'sc-button green' } } ) }}
+ {{ form_end(add_role_scopes_form) }}
+
+
+
+{% endblock %}
diff --git a/Resources/views/PermissionsGroup/index.html.twig b/Resources/views/PermissionsGroup/index.html.twig
new file mode 100644
index 000000000..d28790177
--- /dev/null
+++ b/Resources/views/PermissionsGroup/index.html.twig
@@ -0,0 +1,41 @@
+{% extends 'ChillMainBundle::Admin/layout_permissions.html.twig' %}
+
+{% block title %}{{ 'Permissions group list'|trans }}{% endblock %}
+
+{% block admin_content -%}
+ {{ 'Permissions group list'|trans }}
+
+
+
+
+ {{ 'Name'|trans }} |
+ {{ 'Actions'|trans }} |
+
+
+
+ {% for entity in entities %}
+
+ {{ entity.name }} |
+
+
+ |
+
+ {% endfor %}
+
+
+
+
+ {% endblock %}
diff --git a/Resources/views/PermissionsGroup/new.html.twig b/Resources/views/PermissionsGroup/new.html.twig
new file mode 100644
index 000000000..e28e60992
--- /dev/null
+++ b/Resources/views/PermissionsGroup/new.html.twig
@@ -0,0 +1,20 @@
+{% extends 'ChillMainBundle::Admin/layout_permissions.html.twig' %}
+
+{% block title %}{{ 'New permission group'|trans }}{% endblock %}
+
+{% block admin_content -%}
+ {{ 'New permission group'|trans }}
+
+ {{ form_start(form) }}
+ {{ form_row(form.name) }}
+ {{ form_row(form.submit, { 'attr': { 'class': 'sc-button green' } } ) }}
+ {{ form_end(form) }}
+
+
+{% endblock %}
diff --git a/Resources/views/PermissionsGroup/show.html.twig b/Resources/views/PermissionsGroup/show.html.twig
new file mode 100644
index 000000000..025592f9a
--- /dev/null
+++ b/Resources/views/PermissionsGroup/show.html.twig
@@ -0,0 +1,66 @@
+{% extends 'ChillMainBundle::Admin/layout_permissions.html.twig' %}
+
+{% block title %}{{ 'Permission group "%name%"'|trans({ '%name%': entity.name }) }}{% endblock %}
+
+{% block admin_content -%}
+ {{ 'Permission group "%name%"'|trans({ '%name%': entity.name }) }}
+
+
+
+
+ {{ 'Name'|trans }} |
+ {{ entity.name }} |
+
+
+
+ {% if role_scopes|length > 0 %}
+ {{ 'Grant those permissions'|trans }} :
+
+
+
+
+ {{ 'Role'|trans }} |
+ {{ 'Circle'|trans }} |
+
+
+
+ {% for role_scope in role_scopes %}
+
+
+ {{ role_scope.role|trans }}
+ {% if expanded_roles[role_scope.role]|length > 1 %}
+
+ {{ 'Which implies'|trans }} : {% for role in expanded_roles[role_scope.role] %}{{ role }}{% if not loop.last %}, {% endif %}{% endfor %}
+ {% endif %}
+ |
+ {%- if role_scope.scope is not null -%}
+ {{ role_scope.scope.name|localize_translatable_string }}
+ {%- else -%}
+ N/A
+ {%- endif -%}
+ |
+
+ {% endfor %}
+
+
+
+ {% else %}
+
+ {{ 'This group does not provide any permission'|trans }}.
+
+ {{ 'add permissions'|trans|capitalize }}
+ {% endif %}
+
+
+{% endblock %}
diff --git a/Resources/views/Scope/edit.html.twig b/Resources/views/Scope/edit.html.twig
new file mode 100644
index 000000000..cd9ccb01c
--- /dev/null
+++ b/Resources/views/Scope/edit.html.twig
@@ -0,0 +1,20 @@
+{% extends 'ChillMainBundle::Admin/layout_permissions.html.twig' %}
+
+{% block title %}{{ 'Circle edit'|trans }}{% endblock %}
+
+{% block admin_content -%}
+ {{ 'Circle edit'|trans }}
+
+ {{ form_start(edit_form) }}
+ {{ form_row(edit_form.name) }}
+ {{ form_row(edit_form.submit, { 'attr' : { 'class' : 'sc-button green' } } ) }}
+ {{ form_end(edit_form) }}
+
+
+{% endblock %}
diff --git a/Resources/views/Scope/index.html.twig b/Resources/views/Scope/index.html.twig
new file mode 100644
index 000000000..b3087da49
--- /dev/null
+++ b/Resources/views/Scope/index.html.twig
@@ -0,0 +1,41 @@
+{% extends 'ChillMainBundle::Admin/layout_permissions.html.twig' %}
+
+{% block title %}{{ 'List circles'|trans }}{% endblock %}
+
+{% block admin_content -%}
+ {{ 'List circles'|trans }}
+
+
+
+
+ {% endblock %}
diff --git a/Resources/views/Scope/new.html.twig b/Resources/views/Scope/new.html.twig
new file mode 100644
index 000000000..ef3fbe58b
--- /dev/null
+++ b/Resources/views/Scope/new.html.twig
@@ -0,0 +1,20 @@
+{% extends 'ChillMainBundle::Admin/layout_permissions.html.twig' %}
+
+{% block title %}{{ 'Circle creation'|trans }}{% endblock %}
+
+{% block admin_content -%}
+ {{ 'Circle creation'|trans }}
+
+ {{ form_start(form) }}
+ {{ form_row(form.name) }}
+ {{ form_row(form.submit, { 'attr' : { 'class' : 'sc-button green' } } ) }}
+ {{ form_end(form) }}
+
+
+{% endblock %}
diff --git a/Resources/views/Scope/show.html.twig b/Resources/views/Scope/show.html.twig
new file mode 100644
index 000000000..694ab35a1
--- /dev/null
+++ b/Resources/views/Scope/show.html.twig
@@ -0,0 +1,29 @@
+{% extends 'ChillMainBundle::Admin/layout_permissions.html.twig' %}
+
+{% block title %}{{ 'Circle'|trans }}{% endblock %}
+
+{% block admin_content -%}
+ {{ 'Circle'|trans }}
+
+
+
+
+ {{ 'Name'|trans }} |
+ {{ entity.name|localize_translatable_string }} |
+
+
+
+
+
+{% endblock %}
diff --git a/Resources/views/User/edit.html.twig b/Resources/views/User/edit.html.twig
new file mode 100644
index 000000000..21ec92f96
--- /dev/null
+++ b/Resources/views/User/edit.html.twig
@@ -0,0 +1,72 @@
+{% extends 'ChillMainBundle::Admin/layout_permissions.html.twig' %}
+
+{% block title %}{{ 'User edit'|trans }}{% endblock %}
+
+{% block admin_content -%}
+ {{ 'User edit'|trans }}
+
+ {{ form_start(edit_form) }}
+
+ {{ form_row(edit_form.username) }}
+ {{ form_row(edit_form.enabled, { 'label': "User'status"}) }}
+
+ {{ form_widget(edit_form.submit, { 'attr': { 'class' : 'sc-button green center' } } ) }}
+ {{ 'Edit password'|trans }}
+
+ {{ form_end(edit_form) }}
+
+ {{ 'Permissions granted'|trans }}
+
+ {% if entity.groupcenters|length > 0 %}
+
+
+
+ {{ 'Permission group'|trans }} |
+ {{ 'Center'|trans }} |
+ |
+
+
+
+ {% for groupcenter in entity.groupcenters %}
+
+
+
+ {{ groupcenter.permissionsgroup.name }}
+
+ |
+
+
+ {{ groupcenter.center.name }}
+
+ |
+
+ {{ form_start(delete_groupcenter_form[groupcenter.id]) }}
+ {{ form_row(delete_groupcenter_form[groupcenter.id].submit, { 'attr': { 'class': 'sc-button red' } } ) }}
+ {{ form_rest(delete_groupcenter_form[groupcenter.id]) }}
+ {{ form_end(delete_groupcenter_form[groupcenter.id]) }}
+ |
+
+ {% endfor %}
+
+
+ {% else %}
+ {{ 'no permissions granted to this user'|trans }}
+ {% endif %}
+
+ {{ 'Grant new permissions'|trans }}
+
+ {{ form_start(add_groupcenter_form) }}
+ {{ form_row(add_groupcenter_form.composed_groupcenter.center) }}
+ {{ form_row(add_groupcenter_form.composed_groupcenter.permissionsgroup) }}
+ {{ form_row(add_groupcenter_form.submit, { 'attr' : { 'class': 'sc-button green' } } ) }}
+
+ {{ form_end(add_groupcenter_form) }}
+
+
+{% endblock %}
diff --git a/Resources/views/User/edit_password.html.twig b/Resources/views/User/edit_password.html.twig
new file mode 100644
index 000000000..3a54d5126
--- /dev/null
+++ b/Resources/views/User/edit_password.html.twig
@@ -0,0 +1,22 @@
+{% extends 'ChillMainBundle::Admin/layout_permissions.html.twig' %}
+
+{% block title %}{{ 'Edit password for %username%'|trans( { '%username%': entity.username } ) }}{% endblock %}
+
+{% block admin_content -%}
+ {{ 'Edit password for %username%'|trans( { '%username%': entity.username } ) }}
+
+ {{ form(edit_form) }}
+
+
+{% endblock %}
diff --git a/Resources/views/User/index.html.twig b/Resources/views/User/index.html.twig
new file mode 100644
index 000000000..948725f70
--- /dev/null
+++ b/Resources/views/User/index.html.twig
@@ -0,0 +1,41 @@
+{% extends 'ChillMainBundle::Admin/layout_permissions.html.twig' %}
+
+{% block title %}{{ 'user list'|trans|capitalize }}{% endblock %}
+
+{% block admin_content -%}
+ {{ 'user list'|trans|capitalize }}
+
+
+
+
+ {{ 'Username'|trans|capitalize }} |
+ {{ 'Actions'|trans|capitalize }} |
+
+
+
+ {% for entity in entities %}
+
+ {{ entity.username }} |
+
+
+ |
+
+ {% endfor %}
+
+
+
+
+{% endblock admin_content %}
diff --git a/Resources/views/User/new.html.twig b/Resources/views/User/new.html.twig
new file mode 100644
index 000000000..9396d072b
--- /dev/null
+++ b/Resources/views/User/new.html.twig
@@ -0,0 +1,17 @@
+{% extends 'ChillMainBundle::Admin/layout_permissions.html.twig' %}
+
+{% block title %}{{ 'User creation'|trans }}{% endblock %}
+
+{% block admin_content -%}
+ {{ 'User creation'|trans }}
+
+ {{ form(form) }}
+
+
+{% endblock %}
diff --git a/Resources/views/User/show.html.twig b/Resources/views/User/show.html.twig
new file mode 100644
index 000000000..8fa1401b0
--- /dev/null
+++ b/Resources/views/User/show.html.twig
@@ -0,0 +1,76 @@
+{% extends 'ChillMainBundle::Admin/layout_permissions.html.twig' %}
+
+{% block title %}{{ 'User %username%'|trans({ '%username%': entity.username }) }}{% endblock %}
+
+{% block admin_content -%}
+ {{ 'User %username%'|trans({ '%username%': entity.username }) }}
+
+
+
+
+ {{ 'Username' }} |
+ {{ entity.username }} |
+
+
+ {{ "User'status"|trans }} |
+
+ {%- if entity.enabled -%}
+ {{ 'Enabled, the user is active'|trans }}
+ {%- else -%}
+ {{ 'Disabled, the user is not allowed to login'|trans }}
+ {%- endif -%}
+ |
+
+
+
+
+ {{ 'Permissions granted'|trans }}
+
+ {% if entity.groupcenters|length > 0 %}
+
+
+
+ {{ 'Permission group'|trans }} |
+ {{ 'Center'|trans }} |
+ |
+
+
+
+ {% for groupcenter in entity.groupcenters %}
+
+
+
+ {{ groupcenter.permissionsgroup.name }}
+
+ |
+
+
+ {{ groupcenter.center.name }}
+
+ |
+
+ {% endfor %}
+
+
+
+ {% else %}
+ {{ 'The user does not belong to any groupcenter'|trans }}.
+
+ {{ 'Add new group centers'|trans }}
+
+
+ {% endif %}
+
+
+{% endblock admin_content %}
diff --git a/Resources/views/layoutWithVerticalMenu.html.twig b/Resources/views/layoutWithVerticalMenu.html.twig
index 0a77ed563..b6863bcb7 100644
--- a/Resources/views/layoutWithVerticalMenu.html.twig
+++ b/Resources/views/layoutWithVerticalMenu.html.twig
@@ -40,7 +40,7 @@
{% endfor %}
- {% for flashMessage in app.session.flashbag.get('danger') %}
+ {% for flashMessage in app.session.flashbag.get('error') %}
{{ flashMessage|raw }}
@@ -48,7 +48,7 @@
{% endfor %}
- {% for flashMessage in app.session.flashbag.get('info') %}
+ {% for flashMessage in app.session.flashbag.get('notice') %}
{{ flashMessage|raw }}
diff --git a/Security/Authorization/AuthorizationHelper.php b/Security/Authorization/AuthorizationHelper.php
index 881a04af4..92316102d 100644
--- a/Security/Authorization/AuthorizationHelper.php
+++ b/Security/Authorization/AuthorizationHelper.php
@@ -95,30 +95,29 @@ class AuthorizationHelper
foreach ($user->getGroupCenters() as $groupCenter){
//filter on center
if ($groupCenter->getCenter()->getId() === $entity->getCenter()->getId()) {
- //iterate on permissionGroup
- foreach($groupCenter->getPermissionGroups() as $permissionGroup) {
- //iterate on roleScopes
- foreach($permissionGroup->getRoleScopes() as $roleScope) {
- //check that the role allow to reach the required role
- if ($this->isRoleReached($role,
- new Role($roleScope->getRole()))){
- //if yes, we have a right on something...
- // perform check on scope if necessary
- if ($entity instanceof HasScopeInterface) {
- $scope = $entity->getScope();
- if ($scope === NULL) {
- return true;
- }
- if ($scope->getId() === $roleScope
- ->getScope()->getId()) {
- return true;
- }
- } else {
+ $permissionGroup = $groupCenter->getPermissionsGroup();
+ //iterate on roleScopes
+ foreach($permissionGroup->getRoleScopes() as $roleScope) {
+ //check that the role allow to reach the required role
+ if ($this->isRoleReached($role,
+ new Role($roleScope->getRole()))){
+ //if yes, we have a right on something...
+ // perform check on scope if necessary
+ if ($entity instanceof HasScopeInterface) {
+ $scope = $entity->getScope();
+ if ($scope === NULL) {
return true;
}
+ if ($scope->getId() === $roleScope
+ ->getScope()->getId()) {
+ return true;
+ }
+ } else {
+ return true;
}
}
}
+
}
}
@@ -139,25 +138,24 @@ class AuthorizationHelper
$centers = array();
foreach ($user->getGroupCenters() as $groupCenter){
- //iterate on permissionGroup
- foreach($groupCenter->getPermissionGroups() as $permissionGroup) {
- //iterate on roleScopes
- foreach($permissionGroup->getRoleScopes() as $roleScope) {
- //check that the role is in the reachable roles
- if ($this->isRoleReached($role,
- new Role($roleScope->getRole()))) {
- if ($scope === null) {
+ $permissionGroup = $groupCenter->getPermissionsGroup();
+ //iterate on roleScopes
+ foreach($permissionGroup->getRoleScopes() as $roleScope) {
+ //check that the role is in the reachable roles
+ if ($this->isRoleReached($role,
+ new Role($roleScope->getRole()))) {
+ if ($scope === null) {
+ $centers[] = $groupCenter->getCenter();
+ break 1;
+ } else {
+ if ($scope->getId() == $roleScope->getScope()->getId()){
$centers[] = $groupCenter->getCenter();
- break 2;
- } else {
- if ($scope->getId() == $roleScope->getScope()->getId()){
- $centers[] = $groupCenter->getCenter();
- break 2;
- }
- }
+ break 1;
+ }
}
}
}
+
}
return $centers;
@@ -178,15 +176,14 @@ class AuthorizationHelper
foreach ($user->getGroupCenters() as $groupCenter){
if ($center->getId() === $groupCenter->getCenter()->getId()) {
//iterate on permissionGroup
- foreach($groupCenter->getPermissionGroups() as $permissionGroup) {
- //iterate on roleScopes
- foreach($permissionGroup->getRoleScopes() as $roleScope) {
- //check that the role is in the reachable roles
- if ($this->isRoleReached($role,
- new Role($roleScope->getRole()))) {
+ $permissionGroup = $groupCenter->getPermissionsGroup();
+ //iterate on roleScopes
+ foreach($permissionGroup->getRoleScopes() as $roleScope) {
+ //check that the role is in the reachable roles
+ if ($this->isRoleReached($role,
+ new Role($roleScope->getRole()))) {
- $scopes[] = $roleScope->getScope();
- }
+ $scopes[] = $roleScope->getScope();
}
}
}
diff --git a/Security/ProvideRoleInterface.php b/Security/ProvideRoleInterface.php
new file mode 100644
index 000000000..08a48181a
--- /dev/null
+++ b/Security/ProvideRoleInterface.php
@@ -0,0 +1,53 @@
+
+ *
+ * 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 .
+ */
+
+namespace Chill\MainBundle\Security;
+
+/**
+ * Declare role
+ *
+ * The role are added to the configuration at compile time.
+ *
+ * The implemented object must be declared as a service and tagged as
+ *
+ *
+ * my_role_declaration:
+ * # ...
+ * tags:
+ * - { name: chill.role }
+ *
+ *
+ * @author Julien Fastré
+ */
+interface ProvideRoleInterface
+{
+ /**
+ * return an array of role provided by the object
+ *
+ * @return string[] array of roles (as string)
+ */
+ public function getRoles();
+
+ /**
+ * return roles which doesn't need
+ *
+ * @return string[] array of roles without scopes
+ */
+ public function getRolesWithoutScope();
+}
diff --git a/Security/RoleProvider.php b/Security/RoleProvider.php
new file mode 100644
index 000000000..e206e64b4
--- /dev/null
+++ b/Security/RoleProvider.php
@@ -0,0 +1,78 @@
+
+ *
+ * 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 .
+ */
+
+namespace Chill\MainBundle\Security;
+
+/**
+ *
+ *
+ * @author Julien Fastré
+ */
+class RoleProvider
+{
+ /**
+ *
+ * @var ProvideRoleInterface[]
+ */
+ private $providers = array();
+
+ /**
+ * Add a role provider
+ *
+ * @internal This function is called by the dependency injector: it inject provider
+ * @param \Chill\MainBundle\Security\ProvideRoleInterface $provider
+ */
+ public function addProvider(ProvideRoleInterface $provider)
+ {
+ $this->providers[] = $provider;
+ }
+
+ /**
+ *
+ * @return string[] the roles as string
+ */
+ public function getRoles()
+ {
+ $roles = array();
+ foreach ($this->providers as $provider) {
+ if ($provider->getRoles() !== NULL) {
+ $roles = array_merge($roles, $provider->getRoles());
+ }
+ }
+
+ return $roles;
+ }
+
+ /**
+ *
+ * @return string[] the roles as string
+ */
+ public function getRolesWithoutScopes()
+ {
+ $roles = array();
+ foreach ($this->providers as $provider) {
+ if ($provider->getRolesWithoutScope() !== NULL) {
+ $roles = array_merge($roles, $provider->getRolesWithoutScope());
+ }
+ }
+
+ return $roles;
+ }
+
+}
diff --git a/Test/PrepareUserTrait.php b/Test/PrepareUserTrait.php
index 83a18d2b2..697e28f5b 100644
--- a/Test/PrepareUserTrait.php
+++ b/Test/PrepareUserTrait.php
@@ -68,6 +68,7 @@ trait PrepareUserTrait
$groupCenter = (new GroupCenter())
->setCenter($permission['center']);
$permissionGroup = new PermissionsGroup();
+
foreach ($permission['permissionsGroup'] as $pg) {
$roleScope = (new RoleScope())
@@ -75,11 +76,14 @@ trait PrepareUserTrait
->setScope($pg['scope']);
;
$permissionGroup->addRoleScope($roleScope);
- $groupCenter->addPermissionGroup($permissionGroup);
+
}
+
+ $groupCenter->setPermissionsGroup($permissionGroup);
$user->addGroupCenter($groupCenter);
- }
-
+
+ }
+
return $user;
}
}
diff --git a/Tests/Controller/CenterControllerTest.php b/Tests/Controller/CenterControllerTest.php
new file mode 100644
index 000000000..4bc8521a0
--- /dev/null
+++ b/Tests/Controller/CenterControllerTest.php
@@ -0,0 +1,55 @@
+ 'admin',
+ 'PHP_AUTH_PW' => 'password',
+ ));
+
+ // Create a new entry in the database
+ $crawler = $client->request('GET', '/fr/admin/center/');
+ $this->assertEquals(200, $client->getResponse()->getStatusCode(),
+ "Unexpected HTTP status code for GET /fr/admin/center/");
+ $crawler = $client->click($crawler->selectLink('Créer un nouveau centre')->link());
+
+ // Fill in the form and submit it
+ $form = $crawler->selectButton('Créer')->form(array(
+ 'chill_mainbundle_center[name]' => 'Test center',
+ ));
+
+ $client->submit($form);
+ $crawler = $client->followRedirect();
+
+ // Check data in the show view
+ $this->assertGreaterThan(0,
+ $crawler->filter('td:contains("Test center")')->count(),
+ 'Missing element td:contains("Test center")');
+
+ // Edit the entity
+ $crawler = $client->click($crawler->selectLink('Edit')->link());
+
+ $form = $crawler->selectButton('Update')->form(array(
+ 'chill_mainbundle_center[name]' => 'Foo',
+ ));
+
+ $client->submit($form);
+ $crawler = $client->followRedirect();
+
+ // Check the element contains an attribute with value equals "Foo"
+ $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(),
+ 'Missing element [value="Foo"]');
+
+ $crawler = $client->request('GET', '/fr/admin/center/');
+
+ // Check the entity has been delete on the list
+ $this->assertRegExp('/Foo/', $client->getResponse()->getContent());
+ }
+}
diff --git a/Tests/Controller/PermissionsGroupControllerTest.php b/Tests/Controller/PermissionsGroupControllerTest.php
new file mode 100644
index 000000000..9657c4800
--- /dev/null
+++ b/Tests/Controller/PermissionsGroupControllerTest.php
@@ -0,0 +1,59 @@
+markTestSkipped();
+ }
+ /*
+ public function testCompleteScenario()
+ {
+ // Create a new client to browse the application
+ $client = static::createClient();
+
+ // Create a new entry in the database
+ $crawler = $client->request('GET', '/admin/permissionsgroup/');
+ $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /admin/permissionsgroup/");
+ $crawler = $client->click($crawler->selectLink('Create a new entry')->link());
+
+ // Fill in the form and submit it
+ $form = $crawler->selectButton('Create')->form(array(
+ 'chill_mainbundle_permissionsgroup[field_name]' => 'Test',
+ // ... other fields to fill
+ ));
+
+ $client->submit($form);
+ $crawler = $client->followRedirect();
+
+ // Check data in the show view
+ $this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")');
+
+ // Edit the entity
+ $crawler = $client->click($crawler->selectLink('Edit')->link());
+
+ $form = $crawler->selectButton('Update')->form(array(
+ 'chill_mainbundle_permissionsgroup[field_name]' => 'Foo',
+ // ... other fields to fill
+ ));
+
+ $client->submit($form);
+ $crawler = $client->followRedirect();
+
+ // Check the element contains an attribute with value equals "Foo"
+ $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]');
+
+ // Delete the entity
+ $client->submit($crawler->selectButton('Delete')->form());
+ $crawler = $client->followRedirect();
+
+ // Check the entity has been delete on the list
+ $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent());
+ }
+
+ */
+}
diff --git a/Tests/Controller/ScopeControllerTest.php b/Tests/Controller/ScopeControllerTest.php
new file mode 100644
index 000000000..73244c70c
--- /dev/null
+++ b/Tests/Controller/ScopeControllerTest.php
@@ -0,0 +1,59 @@
+ 'admin',
+ 'PHP_AUTH_PW' => 'password',
+ ));
+
+ // Create a new entry in the database
+ $crawler = $client->request('GET', '/fr/admin/scope/');
+ $this->assertEquals(200, $client->getResponse()->getStatusCode(),
+ "Unexpected HTTP status code for GET /fr/admin/scope/");
+ $crawler = $client->click($crawler->selectLink('Créer un nouveau cercle')->link());
+ // Fill in the form and submit it
+ $form = $crawler->selectButton('Créer')->form(array(
+ 'chill_mainbundle_scope[name][fr]' => 'Test en fr',
+ 'chill_mainbundle_scope[name][en]' => 'Test en en'
+ ));
+
+ $client->submit($form/*, array(
+ 'chill_mainbundle_scope' => array(
+ 'name' => array(
+ 'fr' => 'test en fr',
+ 'en' => 'test in english',
+ 'nl' => 'test in nl'
+ )
+ )
+ )*/);
+ $crawler = $client->followRedirect();
+
+ // Check data in the show view
+ $this->assertGreaterThan(0, $crawler->filter('td:contains("Test en fr")')->count(),
+ 'Missing element td:contains("Test en fr")');
+
+ // Edit the entity
+ $crawler = $client->click($crawler->selectLink('Edit')->link());
+
+ $form = $crawler->selectButton('Update')->form(array(
+ 'chill_mainbundle_scope[name][fr]' => 'Foo',
+ 'chill_mainbundle_scope[name][en]' => 'Foo en',
+ ));
+
+ $client->submit($form);
+ $crawler = $client->followRedirect();
+
+ // Check the element contains an attribute with value equals "Foo"
+ $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]');
+
+ }
+
+}
diff --git a/Tests/Controller/UserControllerTest.php b/Tests/Controller/UserControllerTest.php
new file mode 100644
index 000000000..d856cb2da
--- /dev/null
+++ b/Tests/Controller/UserControllerTest.php
@@ -0,0 +1,59 @@
+markTestSkipped();
+ }
+ /*
+ public function testCompleteScenario()
+ {
+ // Create a new client to browse the application
+ $client = static::createClient();
+
+ // Create a new entry in the database
+ $crawler = $client->request('GET', '/admin/user/');
+ $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /admin/user/");
+ $crawler = $client->click($crawler->selectLink('Create a new entry')->link());
+
+ // Fill in the form and submit it
+ $form = $crawler->selectButton('Create')->form(array(
+ 'chill_mainbundle_user[field_name]' => 'Test',
+ // ... other fields to fill
+ ));
+
+ $client->submit($form);
+ $crawler = $client->followRedirect();
+
+ // Check data in the show view
+ $this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")');
+
+ // Edit the entity
+ $crawler = $client->click($crawler->selectLink('Edit')->link());
+
+ $form = $crawler->selectButton('Update')->form(array(
+ 'chill_mainbundle_user[field_name]' => 'Foo',
+ // ... other fields to fill
+ ));
+
+ $client->submit($form);
+ $crawler = $client->followRedirect();
+
+ // Check the element contains an attribute with value equals "Foo"
+ $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]');
+
+ // Delete the entity
+ $client->submit($crawler->selectButton('Delete')->form());
+ $crawler = $client->followRedirect();
+
+ // Check the entity has been delete on the list
+ $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent());
+ }
+
+ */
+}
diff --git a/Tests/Fixtures/App/AppKernel.php b/Tests/Fixtures/App/AppKernel.php
index 16f21e1f5..4b9643491 100644
--- a/Tests/Fixtures/App/AppKernel.php
+++ b/Tests/Fixtures/App/AppKernel.php
@@ -15,7 +15,8 @@ class AppKernel extends Kernel
new \Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
- new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle()
+ new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
+ new Symfony\Bundle\MonologBundle\MonologBundle(),
);
}
diff --git a/Tests/Fixtures/App/config/config_test.yml b/Tests/Fixtures/App/config/config_test.yml
index 18856b3ac..a8a895244 100644
--- a/Tests/Fixtures/App/config/config_test.yml
+++ b/Tests/Fixtures/App/config/config_test.yml
@@ -10,6 +10,13 @@ security:
role_hierarchy:
CHILL_MASTER_ROLE: [CHILL_INHERITED_ROLE_1]
providers:
+ chain_provider:
+ chain :
+ providers: [in_memory, users]
+ in_memory:
+ memory:
+ users:
+ admin: { password: "password", roles: 'ROLE_ADMIN' }
users:
entity:
class: Chill\MainBundle\Entity\User
@@ -18,6 +25,8 @@ security:
encoders:
Chill\MainBundle\Entity\User:
algorithm: bcrypt
+ Symfony\Component\Security\Core\User\User:
+ algorithm: plaintext
firewalls:
dev:
@@ -39,5 +48,5 @@ security:
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- - { path: ^/admin, roles: ROLE_ADMIN }
+ - { path: ^/[a-z]*/admin, roles: ROLE_ADMIN }
- { path: ^/, roles: ROLE_USER }
\ No newline at end of file
diff --git a/Validation/Constraint/RoleScopeScopePresenceConstraint.php b/Validation/Constraint/RoleScopeScopePresenceConstraint.php
new file mode 100644
index 000000000..9f9b6381b
--- /dev/null
+++ b/Validation/Constraint/RoleScopeScopePresenceConstraint.php
@@ -0,0 +1,46 @@
+
+ *
+ * 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 .
+ */
+
+namespace Chill\MainBundle\Validation\Constraint;
+
+use Symfony\Component\Validator\Constraint;
+
+/**
+ * Check that a role scope has a scope if required
+ *
+ * @author Julien Fastré
+ */
+class RoleScopeScopePresenceConstraint extends Constraint
+{
+
+ public $messagePresenceRequired = "The role \"%role%\" require to be associated with "
+ . "a scope.";
+ public $messageNullRequired = "The role \"%role%\" should not be associated with a scope.";
+
+ public function validatedBy()
+ {
+ return 'role_scope_scope_presence';
+ }
+
+ public function getTargets()
+ {
+ return self::CLASS_CONSTRAINT;
+ }
+
+}
diff --git a/Validation/Validator/RoleScopeScopePresence.php b/Validation/Validator/RoleScopeScopePresence.php
new file mode 100644
index 000000000..e6681738a
--- /dev/null
+++ b/Validation/Validator/RoleScopeScopePresence.php
@@ -0,0 +1,102 @@
+
+ *
+ * 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 .
+ */
+
+namespace Chill\MainBundle\Validation\Validator;
+
+use Chill\MainBundle\Security\RoleProvider;
+use Chill\MainBundle\Entity\RoleScope;
+use Symfony\Component\Validator\Constraint;
+use Symfony\Component\Validator\ConstraintValidator;
+use Chill\MainBundle\Validation\Constraint\RoleScopeScopePresenceConstraint;
+use Psr\Log\LoggerInterface;
+use Symfony\Component\Translation\TranslatorInterface;
+
+/**
+ *
+ *
+ * @author Julien Fastré
+ */
+class RoleScopeScopePresence extends ConstraintValidator
+{
+ /**
+ *
+ * @var RoleProvider
+ */
+ private $roleProvider;
+
+ /**
+ *
+ * @var LoggerInterface
+ */
+ private $logger;
+
+ /**
+ *
+ * @var TranslatorInterface
+ */
+ private $translator;
+
+ public function __construct(RoleProvider $roleProvider, LoggerInterface $logger,
+ TranslatorInterface $translator)
+ {
+ $this->roleProvider = $roleProvider;
+ $this->logger = $logger;
+ $this->translator = $translator;
+ }
+
+ public function validate($value, Constraint $constraint)
+ {
+ if (! $value instanceof RoleScope) {
+ throw new \RuntimeException('The validated object is not an instance of roleScope');
+ }
+
+ if (! $constraint instanceof RoleScopeScopePresenceConstraint) {
+ throw new \RuntimeException('This validator should be used with RoleScopScopePresenceConstraint');
+ }
+
+ $this->logger->debug('begin validation of a role scope instance');
+
+ //if the role scope should have a scope
+ if (
+ !in_array($value->getRole(), $this->roleProvider->getRolesWithoutScopes())
+ &&
+ $value->getScope() === NULL
+ ) {
+ $this->context->buildViolation($constraint->messagePresenceRequired)
+ ->setParameter('%role%', $this->translator->trans($value->getRole()))
+ ->addViolation();
+ $this->logger->debug('the role scope should have a scope, but scope is null. Violation build.');
+ } elseif // if the scope should be null
+ (
+ in_array($value->getRole(), $this->roleProvider->getRolesWithoutScopes())
+ &&
+ ! is_null($value->getScope())
+ )
+ {
+ $this->context->buildViolation($constraint->messageNullRequired)
+ ->setParameter('%role%', $this->translator->trans($value->getRole()))
+ ->addViolation();
+ $this->logger->debug('the role scole should not have a scope, but scope is not null. Violation build.');
+ } // everything is fine !
+ else {
+ $this->logger->debug('role scope is valid. Validation finished.');
+ }
+ }
+
+}