Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
DGE
DATAtourisme
webapp-quality
Commits
e8888d38
Commit
e8888d38
authored
Apr 07, 2022
by
Blaise de Carné
Browse files
feat: ROLE_PRODUCER become ROLE_MANAGER
parent
8ce9ba77
Changes
13
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
e8888d38
...
...
@@ -3,6 +3,15 @@
Ce fichier est basé sur
[
Keep a Changelog
](
http://keepachangelog.com/
)
et le projet utilise
[
Semantic Versioning
](
http://semver.org/
)
.
## [Unreleased]
## [0.9.1] - 2022-04-07
# Modification
-
Le rôle ROLE_PRODUCER devient ROLE_MANAGER (Référent)
-
Les administrateurs peuvent maintenant modifier le rôles des utilisateurs
## [0.9.0] - 2022-04-05
### Ajout
...
...
composer.json
View file @
e8888d38
...
...
@@ -2,7 +2,7 @@
"name"
:
"datatourisme/quality-platform-webapp"
,
"type"
:
"project"
,
"description"
:
"DATAtourisme - Quality Platform web application"
,
"version"
:
"0.9.
0
"
,
"version"
:
"0.9.
1
"
,
"license"
:
"GPL-3.0-or-later"
,
"authors"
:
[
{
...
...
config/packages/security.yaml
View file @
e8888d38
...
...
@@ -41,8 +41,8 @@ security:
# switch_user: true
role_hierarchy
:
ROLE_
PRODUC
ER
:
[
ROLE_USER
]
ROLE_ADMIN
:
[
ROLE_
PRODUC
ER
]
ROLE_
MANAG
ER
:
[
ROLE_USER
]
ROLE_ADMIN
:
[
ROLE_
MANAG
ER
]
ROLE_SUPER_ADMIN
:
[
ROLE_ADMIN
]
# Easy way to control access for large sections of your site
...
...
migrations/Version20220405144431.php
0 → 100644
View file @
e8888d38
<?php
declare
(
strict_types
=
1
);
namespace
DoctrineMigrations
;
use
Doctrine\DBAL\Schema\Schema
;
use
Doctrine\Migrations\AbstractMigration
;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final
class
Version20220405144431
extends
AbstractMigration
{
public
function
getDescription
():
string
{
return
''
;
}
public
function
up
(
Schema
$schema
):
void
{
$this
->
addSql
(
'UPDATE "user" SET role = \'ROLE_MANAGER\' WHERE role = \'ROLE_PRODUCER\''
);
}
public
function
down
(
Schema
$schema
):
void
{
$this
->
addSql
(
'UPDATE "user" SET role = \'ROLE_PRODUCER\' WHERE role = \'ROLE_MANAGER\''
);
}
}
src/Command/CreateUserCommand.php
View file @
e8888d38
...
...
@@ -79,7 +79,7 @@ class CreateUserCommand extends Command
$helper
=
$this
->
getHelper
(
'question'
);
$question
=
new
Question
(
'Role (ROLE_USER) : '
,
'ROLE_USER'
);
$question
->
setValidator
(
function
(
$role
)
{
if
(
!
in_array
(
$role
,
[
'ROLE_USER'
,
'ROLE_ADMIN'
,
'ROLE_
PRODUC
ER'
]))
{
if
(
!
in_array
(
$role
,
[
'ROLE_USER'
,
'ROLE_ADMIN'
,
'ROLE_
MANAG
ER'
]))
{
throw
new
\
RuntimeException
(
'Role '
.
$role
.
' does not exists.'
);
}
return
$role
;
...
...
src/Controller/Administration/UserController.php
View file @
e8888d38
...
...
@@ -30,7 +30,7 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
/**
* @Route("/admin/user", name="user.")
* @Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_
PRODUC
ER')")
* @Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_
MANAG
ER')")
*/
class
UserController
extends
AbstractController
{
...
...
@@ -78,7 +78,7 @@ class UserController extends AbstractController
$user
=
new
User
();
$user
->
setCreatedBy
(
$currentUser
);
$user
->
setRole
(
$this
->
isGranted
(
'ROLE_ADMIN'
)
?
'ROLE_
PRODUC
ER'
:
'ROLE_USER'
);
$user
->
setRole
(
$this
->
isGranted
(
'ROLE_ADMIN'
)
?
'ROLE_
MANAG
ER'
:
'ROLE_USER'
);
$user
->
setProducer
(
$currentUser
->
getProducer
());
$user
->
setPlainPassword
(
strval
(
rand
(
10000000
,
9999999999999
)));
$user
->
setEnabled
(
false
);
...
...
src/Controller/SsoController.php
View file @
e8888d38
...
...
@@ -25,7 +25,6 @@ use Symfony\Component\Routing\Annotation\Route;
use
Symfony\Component\HttpKernel\Exception\BadRequestHttpException
;
use
Symfony\Component\Security\Core\Exception\AuthenticationException
;
use
Symfony\Component\Security\Core\Signature\Exception\ExpiredSignatureException
;
use
Symfony\Component\Security\Core\User\UserCheckerInterface
;
use
Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface
;
use
Symfony\Component\Security\Http\Authenticator\FormLoginAuthenticator
;
...
...
@@ -128,7 +127,7 @@ class SsoController extends AbstractController
$user
=
new
User
();
$user
->
setEmail
(
$payload
[
'email'
]);
$user
->
setPlainPassword
(
md5
(
time
()));
$user
->
setRole
(
'ROLE_
PRODUCER'
);
$user
->
setRole
(
'ROLE_
USER'
);
// do not assign ROLE_MANAGER to avoid wide permission
$user
->
setEnabled
(
true
);
$this
->
em
->
persist
(
$user
);
}
...
...
src/Entity/User.php
View file @
e8888d38
...
...
@@ -127,7 +127,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, GroupSe
* @var Producer
* @ORM\ManyToOne(targetEntity="Producer", inversedBy="users")
* @ORM\JoinColumn(nullable=true)
* @Assert\NotBlank(groups = {"ROLE_
PRODUC
ER", "ROLE_USER"})
* @Assert\NotBlank(groups = {"ROLE_
MANAG
ER", "ROLE_USER"})
*/
private
$producer
;
...
...
src/Form/Filter/UserFilter.php
View file @
e8888d38
...
...
@@ -69,7 +69,7 @@ class UserFilter extends AbstractType
$builder
->
add
(
'role'
,
ChoiceFilterType
::
class
,
[
'choices'
=>
[
'Utilisateur'
=>
'ROLE_USER'
,
'
Producteur
'
=>
'ROLE_
PRODUC
ER'
,
'
Référent
'
=>
'ROLE_
MANAG
ER'
,
'Administrateur'
=>
'ROLE_ADMIN'
,
'Super administrateur'
=>
'ROLE_SUPER_ADMIN'
,
],
...
...
src/Form/Type/UserType.php
View file @
e8888d38
...
...
@@ -76,7 +76,7 @@ class UserType extends AbstractType
$builder
=
$form
->
getConfig
()
->
getFormFactory
()
->
createNamedBuilder
(
'role'
,
RoleType
::
class
,
null
,
[
'choice_label'
=>
[
'ROLE_USER'
=>
'Utilisateur'
,
'ROLE_
PRODUC
ER'
=>
'
Producteur
'
,
'ROLE_
MANAG
ER'
=>
'
Référent
'
,
'ROLE_ADMIN'
=>
'Administrateur'
,
'ROLE_SUPER_ADMIN'
=>
'Super administrateur'
,
],
...
...
@@ -105,7 +105,7 @@ class UserType extends AbstractType
*/
private
function
addProducerField
(
FormInterface
$form
,
string
$role
,
User
$account
)
{
if
(
!
in_array
(
$role
,
[
'ROLE_
PRODUC
ER'
,
'ROLE_USER'
]))
{
if
(
!
in_array
(
$role
,
[
'ROLE_
MANAG
ER'
,
'ROLE_USER'
]))
{
$account
->
setProducer
(
null
);
return
;
}
...
...
src/Menu/MenuBuilder.php
View file @
e8888d38
...
...
@@ -70,7 +70,7 @@ class MenuBuilder
]);
// Administration
if
(
$this
->
authorizationChecker
->
isGranted
(
'ROLE_ADMIN'
)
||
$this
->
authorizationChecker
->
isGranted
(
'ROLE_
PRODUC
ER'
))
{
if
(
$this
->
authorizationChecker
->
isGranted
(
'ROLE_ADMIN'
)
||
$this
->
authorizationChecker
->
isGranted
(
'ROLE_
MANAG
ER'
))
{
$admin
=
$menu
->
addChild
(
'Administration'
,
[
'uri'
=>
'#'
,
'extras'
=>
[
...
...
src/Security/Voter/UserVoter.php
View file @
e8888d38
...
...
@@ -77,7 +77,7 @@ class UserVoter extends AbstractVoter
}
// producer can administrate user from the same SIT
if
(
$this
->
hasRole
(
'ROLE_
PRODUC
ER'
,
$user
)
&&
$user
->
getProducer
()
&&
$user
->
getProducer
()
==
$account
->
getProducer
())
{
if
(
$this
->
hasRole
(
'ROLE_
MANAG
ER'
,
$user
)
&&
$user
->
getProducer
()
&&
$user
->
getProducer
()
==
$account
->
getProducer
())
{
return
true
;
}
...
...
@@ -90,7 +90,7 @@ class UserVoter extends AbstractVoter
*/
private
function
canCreate
(
User
$user
):
bool
{
// return $this->hasRole('ROLE_
PRODUC
ER', $user);
// return $this->hasRole('ROLE_
MANAG
ER', $user);
return
$this
->
hasRole
(
'ROLE_ADMIN'
,
$user
);
}
...
...
@@ -157,8 +157,8 @@ class UserVoter extends AbstractVoter
*/
private
function
canSetRole
(
User
$account
,
User
$user
):
bool
{
// only
super-
admin can set role
if
(
!
$this
->
hasRole
(
'ROLE_
SUPER_
ADMIN'
,
$user
))
{
// only admin can set role
if
(
!
$this
->
hasRole
(
'ROLE_ADMIN'
,
$user
))
{
return
false
;
}
...
...
templates/macros.html.twig
View file @
e8888d38
...
...
@@ -48,7 +48,7 @@
{{
{
ROLE_SUPER_ADMIN
:
"Super administrateur"
,
ROLE_ADMIN
:
"Administrateur"
,
ROLE_
PRODUCER
:
"Producteur
"
,
ROLE_
MANAGER
:
"Référent
"
,
ROLE_USER
:
"Utilisateur"
}
[
role
]
}}
{%
endmacro
%}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment