diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelperForCurrentUser.php b/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelperForCurrentUser.php new file mode 100644 index 000000000..da9c285bd --- /dev/null +++ b/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelperForCurrentUser.php @@ -0,0 +1,46 @@ +authorizationHelper = $authorizationHelper; + $this->security = $security; + } + + public function getReachableCenters(string $role, ?Scope $scope = null): array + { + if (!$this->security->getUser() instanceof User) { + return []; + } + + return $this->authorizationHelper->getReachableCenters($this->security->getUser(), $role, $scope); + } + + public function getReachableScopes(string $role, $center): array + { + if (!$this->security->getUser() instanceof User) { + return []; + } + + return $this->authorizationHelper->getReachableScopes($this->security->getUser(), $role, $center); + } +} diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelperForCurrentUserInterface.php b/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelperForCurrentUserInterface.php new file mode 100644 index 000000000..cd3459aa9 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelperForCurrentUserInterface.php @@ -0,0 +1,28 @@ +authorizationHelper = $authorizationHelper; + $this->authorizedCenterOnPersonCreation = $authorizedCenterOnPersonCreation; $this->configPersonAltNameHelper = $configPersonAltNameHelper; + $this->showCenters = $parameterBag->get('chill_main')['acl']['form_show_centers']; + } + + /** + * @Route("/api/1.0/person/creation/authorized-centers", + * name="chill_person_person_creation_authorized_centers" + * ) + */ + public function authorizedCentersForCreation(): Response + { + $centers = $this->authorizedCenterOnPersonCreation->getCenters(); + + return $this->json( + ['showCenters' => $this->showCenters, 'centers' => $centers], + Response::HTTP_OK, + [], + ['gropus' => ['read']] + ); } /** diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index a477f9adb..3843a960f 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -1567,7 +1567,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * * @return $this */ - public function setCenter(Center $center): self + public function setCenter(?Center $center): self { $modification = new DateTimeImmutable('now'); @@ -1577,7 +1577,11 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI } } - $this->centerHistory[] = $new = new PersonCenterHistory($this, $center, $modification); + if (null === $center) { + return $this; + } + + $this->centerHistory[] = new PersonCenterHistory($this, $center, $modification); return $this; } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/index.js index c9f5bb111..d2b271e17 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/index.js @@ -2,6 +2,8 @@ import { createApp } from 'vue'; import { _createI18n } from 'ChillMainAssets/vuejs/_js/i18n'; import { appMessages } from './js/i18n'; import { store } from './store'; +import VueToast from 'vue-toast-notification'; +import 'vue-toast-notification/dist/theme-sugar.css'; import App from './App.vue'; @@ -12,5 +14,11 @@ const app = createApp({ }) .use(store) .use(i18n) +.use(VueToast, { + position: "bottom-right", + type: "error", + duration: 5000, + dismissible: true +}) .component('app', App) .mount('#household_members_editor'); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/OnTheFly.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/OnTheFly.js index 338094122..c9c77991f 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/OnTheFly.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/OnTheFly.js @@ -1,3 +1,5 @@ +import {makeFetch} from 'ChillMainAssets/lib/api/apiMethods'; + /* * GET a person by id */ @@ -22,6 +24,8 @@ const getCivilities = () => throw Error('Error with request resource response'); }); +const getCentersForPersonCreation = () => makeFetch('GET', '/api/1.0/person/creation/authorized-centers', null); + /* * POST a new person */ @@ -59,6 +63,7 @@ const patchPerson = (id, body) => { }; export { + getCentersForPersonCreation, getPerson, getPersonAltNames, getCivilities, diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue index 4f8909233..8694da651 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue @@ -87,6 +87,18 @@ +
+ + +
+