From c791c482484f54069ac116769c4d5eedabe5070c Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 28 Sep 2021 14:06:52 +0200 Subject: [PATCH 01/45] tp: adapt to new ACL interface (wip) --- .../Controller/ThirdPartyController.php | 32 +++++++++---------- .../ThirdPartyACLAwareRepository.php | 23 +++++++++++++ .../ThirdPartyACLAwareRepositoryInterface.php | 16 ++++++++++ .../Security/Voter/ThirdPartyVoter.php | 2 ++ 4 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 src/Bundle/ChillThirdPartyBundle/Repository/ThirdPartyACLAwareRepository.php create mode 100644 src/Bundle/ChillThirdPartyBundle/Repository/ThirdPartyACLAwareRepositoryInterface.php diff --git a/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php b/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php index d16934b18..dff892b99 100644 --- a/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php +++ b/src/Bundle/ChillThirdPartyBundle/Controller/ThirdPartyController.php @@ -66,8 +66,8 @@ class ThirdPartyController extends Controller $this->getUser(), new Role(ThirdPartyVoter::SHOW) ); - - $nbThirdParties = $repository->countByMemberOfCenters($centers); + + $nbThirdParties = $repository->countByMemberOfCenters($centers); // $pagination = $this->paginatorFactory->create($nbThirdParties); $thirdParties = $repository->findByMemberOfCenters( @@ -88,18 +88,18 @@ class ThirdPartyController extends Controller public function newAction(Request $request) { $this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE); - - $centers = $this->authorizationHelper + + /* $centers = $this->authorizationHelper ->getReachableCenters( - $this->getUser(), + $this->getUser(), new Role(ThirdPartyVoter::CREATE) ); - - if (count($centers) === 0) { + + if ($centers === []) { // throw new \LogicException("There should be at least one center reachable " . "if role ".ThirdPartyVoter::CREATE." is granted"); - } - + } */ + $thirdParty = new ThirdParty(); $thirdParty->setCenters(new ArrayCollection($centers)); @@ -141,18 +141,18 @@ class ThirdPartyController extends Controller public function updateAction(ThirdParty $thirdParty, Request $request) { $this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE); - - $centers = $this->authorizationHelper + + /* $centers = $this->authorizationHelper ->getReachableCenters( - $this->getUser(), + $this->getUser(), new Role(ThirdPartyVoter::CREATE) ); - - if (count($centers) === 0) { + + if ($centers === []) { throw new \LogicException("There should be at least one center reachable " . "if role ".ThirdPartyVoter::CREATE." is granted"); - } - + } */ + // we want to keep centers the users has no access to. So we will add them // later if they are removed. (this is a ugly hack but it will works $centersAssociatedNotForUsers = \array_diff( diff --git a/src/Bundle/ChillThirdPartyBundle/Repository/ThirdPartyACLAwareRepository.php b/src/Bundle/ChillThirdPartyBundle/Repository/ThirdPartyACLAwareRepository.php new file mode 100644 index 000000000..ff21d18c7 --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/Repository/ThirdPartyACLAwareRepository.php @@ -0,0 +1,23 @@ +getUser(); if (!$user instanceof User) { From e72ba4c940da286bbc63f5d942ccb7f4b395f58a Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 28 Sep 2021 15:34:15 +0200 Subject: [PATCH 02/45] bypass ACL restriction --- .../ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php b/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php index a1ce94e25..7b3e4e5b1 100644 --- a/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php +++ b/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php @@ -56,6 +56,8 @@ class ThirdPartyVoter extends AbstractChillVoter implements ProvideRoleHierarchy */ protected function voteOnAttribute($attribute, $subject, TokenInterface $token) { + return true; + $user = $token->getUser(); if (!$user instanceof User) { From 644d0420ceaa5bc485ce9dd0099ff39cc5d0a574 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 28 Sep 2021 16:23:24 +0200 Subject: [PATCH 03/45] creation of endpoints POST, PUT, PATCH, but still errors --- .../ChillThirdPartyExtension.php | 18 +++- .../Entity/ThirdParty.php | 10 +- .../Security/Voter/ThirdPartyVoter.php | 2 + .../chill.api.specs.yaml | 97 ++++++++++++++++++- 4 files changed, 116 insertions(+), 11 deletions(-) diff --git a/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php b/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php index 9b23222c6..2fd0f723d 100644 --- a/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php +++ b/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php @@ -59,7 +59,7 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte 'class' => \Chill\ThirdPartyBundle\Entity\ThirdParty::class, 'name' => 'thirdparty', 'base_path' => '/api/1.0/thirdparty/thirdparty', - 'base_role' => \Chill\ThirdPartyBundle\Security\Authorization\ThirdPartyVoter::class, + //'base_role' => \Chill\ThirdPartyBundle\Security\Authorization\ThirdPartyVoter::SHOW, //'controller' => \Chill\ThirdPartyBundle\Controller\ThirdPartyApiController::class, 'actions' => [ '_index' => [ @@ -67,19 +67,31 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte Request::METHOD_GET => true, Request::METHOD_HEAD => true, Request::METHOD_POST => true, + Request::METHOD_PATCH => true, + Request::METHOD_PUT => true + ], + 'roles' => [ + Request::METHOD_GET => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::SHOW, + Request::METHOD_HEAD => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::SHOW, + Request::METHOD_POST => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::CREATE, + Request::METHOD_PUT => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::CREATE, + Request::METHOD_PATCH => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::CREATE ], ], '_entity' => [ 'methods' => [ Request::METHOD_GET => true, Request::METHOD_HEAD => true, - Request::METHOD_POST=> true, + Request::METHOD_POST => true, + Request::METHOD_PUT => true, + Request::METHOD_PATCH => true ], 'roles' => [ Request::METHOD_GET => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::SHOW, Request::METHOD_HEAD => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::SHOW, Request::METHOD_POST => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::CREATE, - + Request::METHOD_PUT => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::CREATE, + Request::METHOD_PATCH => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::CREATE ], ] ] diff --git a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php index 0b0b3e56b..842e57b8b 100644 --- a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php +++ b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php @@ -60,7 +60,7 @@ class ThirdParty * @var string * @ORM\Column(name="name", type="string", length=255) * @Assert\Length(min="2") - * @Groups({"read"}) + * @Groups({"read", "write"}) */ private $name; @@ -69,6 +69,7 @@ class ThirdParty * @var string * @ORM\Column(name="name_company", type="string", length=255, nullable=true) * @Assert\Length(min="3") + * @Groups({"read", "write"}) */ private $nameCompany; @@ -77,6 +78,7 @@ class ThirdParty * @var string * @ORM\Column(name="acronym", type="string", length=64, nullable=true) * @Assert\Length(min="2") + * @Groups({"read", "write"}) */ private $acronym; @@ -130,7 +132,7 @@ class ThirdParty * @Assert\Regex("/^([\+{1}])([0-9\s*]{4,20})$/", * message="Invalid phone number: it should begin with the international prefix starting with ""+"", hold only digits and be smaller than 20 characters. Ex: +33123456789" * ) - * @Groups({"read"}) + * @Groups({"read", "write"}) */ private $telephone; @@ -138,7 +140,7 @@ class ThirdParty * @var string|null * @ORM\Column(name="email", type="string", length=255, nullable=true) * @Assert\Email(checkMX=false) - * @Groups({"read"}) + * @Groups({"read", "write"}) */ private $email; @@ -147,7 +149,7 @@ class ThirdParty * @ORM\ManyToOne(targetEntity="\Chill\MainBundle\Entity\Address", * cascade={"persist", "remove"}) * @ORM\JoinColumn(nullable=true, onDelete="SET NULL") - * @Groups({"read"}) + * @Groups({"read", "write"}) */ private $address; diff --git a/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php b/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php index a1ce94e25..986bfb2b9 100644 --- a/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php +++ b/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php @@ -61,6 +61,8 @@ class ThirdPartyVoter extends AbstractChillVoter implements ProvideRoleHierarchy if (!$user instanceof User) { return false; } + + return true; $centers = $this->authorizationHelper ->getReachableCenters($user, new Role($attribute)); diff --git a/src/Bundle/ChillThirdPartyBundle/chill.api.specs.yaml b/src/Bundle/ChillThirdPartyBundle/chill.api.specs.yaml index 957bf9324..c5d9346ba 100644 --- a/src/Bundle/ChillThirdPartyBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillThirdPartyBundle/chill.api.specs.yaml @@ -8,17 +8,47 @@ servers: - url: "/api" description: "Your current dev server" +components: + schemas: + Thirdparty: + type: object + properties: + id: + type: integer + readOnly: true + name: + type: string + nameCompany: + type: string + acronym: + type: string + email: + type: string + paths: /1.0/thirdparty/thirdparty.json: - get: + post: tags: - thirdparty - summary: Return a list of all thirdparty items + summary: Create a single thirdparty + requestBody: + description: "A thirdparty" + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/Thirdparty" responses: 200: - description: "ok" - 401: + description: "OK" + content: + application/json: + schema: + $ref: "#/components/schemas/Thirdparty" + 403: description: "Unauthorized" + 422: + description: "Invalid data" /1.0/thirdparty/thirdparty/{id}.json: get: @@ -41,3 +71,62 @@ paths: description: "not found" 401: description: "Unauthorized" + patch: + tags: + - thirdparty + summary: "Alter a thirdparty" + parameters: + - name: id + in: path + required: true + description: The thirdparty's id + schema: + type: integer + format: integer + minimum: 1 + requestBody: + description: "A thirdparty" + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/Thirdparty" + responses: + 401: + description: "Unauthorized" + 404: + description: "Not found" + 200: + description: "OK" + 422: + description: "Object with validation errors" + put: + tags: + - thirdparty + summary: Edit an existing thirdparty + parameters: + - name: id + in: path + required: true + description: The thirdparty's id + schema: + type: integer + format: integer + minimum: 1 + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/Thirdparty" + responses: + 401: + description: "Unauthorized" + 404: + description: "Not found" + 200: + description: "OK" + 422: + description: "Unprocessable entity (validation errors)" + 400: + description: "Bad Request" From c5fa1b883cd355ebe7d1c6dd06fd76ae84b2b3f8 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 28 Sep 2021 16:25:38 +0200 Subject: [PATCH 04/45] onthefly: adding tp i18n file --- .../public/vuejs/AccompanyingCourse/js/i18n.js | 5 +++-- .../public/vuejs/_components/OnTheFly/ThirdParty.vue | 9 ++------- .../Resources/public/vuejs/_js/i18n.js | 11 +++++++++++ 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_js/i18n.js diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/js/i18n.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/js/i18n.js index cf3a0fb7e..0ab012954 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/js/i18n.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/js/i18n.js @@ -1,4 +1,5 @@ -import { personMessages } from 'ChillPersonAssets/vuejs/_js/i18n' +import { personMessages } from 'ChillPersonAssets/vuejs/_js/i18n'; +import { thirdpartyMessages } from 'ChillThirdPartyAssets/vuejs/_js/i18n'; import { addressMessages } from 'ChillMainAssets/vuejs/Address/i18n'; const appMessages = { @@ -137,7 +138,7 @@ const appMessages = { } }; -Object.assign(appMessages.fr, personMessages.fr, addressMessages.fr); +Object.assign(appMessages.fr, personMessages.fr, thirdpartyMessages.fr, addressMessages.fr); export { appMessages diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue index 1b1207131..6d1497e2b 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue +++ b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue @@ -19,15 +19,10 @@
- -
- - -
- - + +
diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_js/i18n.js b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_js/i18n.js new file mode 100644 index 000000000..37d09320d --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_js/i18n.js @@ -0,0 +1,11 @@ +const thirdpartyMessages = { + fr: { + thirdparty: { + name: "Dénomination", + email: "Courriel", + phonenumber: "Téléphone", + } + } +}; + +export { thirdpartyMessages }; From adc94aaeea34a9e46f7c4738cddcdee307ee3322 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 28 Sep 2021 16:26:32 +0200 Subject: [PATCH 05/45] javascript syntax correction --- .../vuejs/_components/Entity/PersonRenderBox.vue | 6 +++--- .../vuejs/_components/Entity/ThirdPartyRenderBox.vue | 12 ++++++------ .../public/vuejs/_components/OnTheFly/ThirdParty.vue | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue index 0f397211e..2bc5f0b3b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue @@ -27,7 +27,7 @@
-

+

- + {{ thirdparty.text }} {{ thirdparty.text }} {{ thirdparty.id }} - {{ $t('renderbox.type.thirdparty') }} + {{ $t('renderbox.type.thirdparty') }}
-

+

@@ -80,10 +80,10 @@ export default { } }, getGender: function() { - return this.thirdparty.gender == 'woman' ? 'renderbox.birthday.woman' : 'renderbox.birthday.man'; + return this.thirdparty.gender === 'woman' ? 'renderbox.birthday.woman' : 'renderbox.birthday.man'; }, getGenderIcon: function() { - return this.thirdparty.gender == 'woman' ? 'fa-venus' : this.thirdparty.gender == 'man' ? 'fa-mars' : 'fa-neuter'; + return this.thirdparty.gender === 'woman' ? 'fa-venus' : this.thirdparty.gender === 'man' ? 'fa-mars' : 'fa-neuter'; }, birthdate: function(){ var date = new Date(this.thirdparty.birthdate.datetime); diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue index 6d1497e2b..016db598c 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue +++ b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue @@ -1,5 +1,5 @@ diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js index 5784e8d4c..b66f4d957 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js @@ -48,7 +48,7 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise]) return state.accompanyingCourse.location !== null; }, isScopeValid(state) { - console.log('is scope valid', state.accompanyingCourse.scopes.length > 0); + //console.log('is scope valid', state.accompanyingCourse.scopes.length > 0); return state.accompanyingCourse.scopes.length > 0; }, validationKeys(state, getters) { diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue index 160d5d00b..a0e8fbebf 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue @@ -229,7 +229,7 @@ export default { return item.result.type + item.result.id; }, addPriorSuggestion() { - console.log('echo', this.hasPriorSuggestion); + //console.log('addPriorSuggestion', this.hasPriorSuggestion); if (this.hasPriorSuggestion) { console.log('addPriorSuggestion',); this.suggested.unshift(this.priorSuggestion); From 0fe248320dbeb86da63736e817b942a0604b2bf4 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 29 Sep 2021 11:21:45 +0200 Subject: [PATCH 08/45] OnTheFly (otf): fix clickable radio tab on create modal --- .../Resources/public/vuejs/_components/OnTheFly/Create.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/OnTheFly/Create.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/OnTheFly/Create.vue index 3ffb3f7df..7644043fd 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/OnTheFly/Create.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/OnTheFly/Create.vue @@ -3,7 +3,7 @@