diff --git a/.changes/unreleased/Feature-20250130-120207.yaml b/.changes/unreleased/Feature-20250130-120207.yaml new file mode 100644 index 000000000..c707205ad --- /dev/null +++ b/.changes/unreleased/Feature-20250130-120207.yaml @@ -0,0 +1,6 @@ +kind: Feature +body: Suggest all referrers within actions of the accompanying period when creating an activity +time: 2025-01-30T12:02:07.053587034+01:00 +custom: + Issue: "349" + SchemaChange: No schema change diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js index 26edac646..c910d7318 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js @@ -26,6 +26,7 @@ const store = createStore({ state: { me: null, activity: window.activity, + accompanyingPeriodWorks: [], socialIssuesOther: [], socialActionsList: [], availableLocations: [], @@ -41,7 +42,7 @@ const store = createStore({ const allEntities = [ ...store.getters.suggestedPersons, ...store.getters.suggestedRequestor, - ...store.getters.suggestedUser, + ...store.getters.suggestedUsers, ...store.getters.suggestedResources, ]; const uniqueIds = [ @@ -80,8 +81,7 @@ const store = createStore({ state.activity.activityType.thirdPartiesVisible !== 0), ); }, - suggestedUser(state) { - // console.log('current user', state.me) + suggestedUsers(state) { const existingUserIds = state.activity.users.map((p) => p.id); let suggestedUsers = state.activity.activityType.usersVisible === 0 @@ -90,11 +90,18 @@ const store = createStore({ (u) => u !== null && !existingUserIds.includes(u.id), ); + state.accompanyingPeriodWorks.forEach((work) => { + work.referrers.forEach((r) => { + if (!existingUserIds.includes(r.id)) { + suggestedUsers.push(r); + } + }); + }); // Add the current user from the state if (state.me && !existingUserIds.includes(state.me.id)) { suggestedUsers.push(state.me); } - console.log("suggested users", suggestedUsers); + // console.log("suggested users", suggestedUsers); return suggestedUsers; }, @@ -223,6 +230,9 @@ const store = createStore({ addAvailableLocationGroup(state, group) { state.availableLocations.push(group); }, + setAccompanyingPeriodWorks(state, works) { + state.accompanyingPeriodWorks = works; + }, }, actions: { addIssueSelected({ commit }, issue) { @@ -341,6 +351,17 @@ const store = createStore({ } commit("updateLocation", value); }, + async fetchAccompanyingPeriodWorks({ state, commit }) { + const accompanyingPeriodId = state.activity.accompanyingPeriod.id; + const url = `/api/1.0/person/accompanying-course/${accompanyingPeriodId}/works.json`; + try { + const works = await makeFetch("GET", url); + // console.log("works", works); + commit("setAccompanyingPeriodWorks", works); + } catch (error) { + console.error("Failed to fetch accompanying period works:", error); + } + }, getWhoAmI({ commit }) { const url = `/api/1.0/main/whoami.json`; makeFetch("GET", url).then((user) => { @@ -353,5 +374,6 @@ const store = createStore({ store.dispatch("getWhoAmI"); prepareLocations(store); +store.dispatch("fetchAccompanyingPeriodWorks"); export default store; diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php index 262a4a03d..ac7c7dec4 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php @@ -25,7 +25,7 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; use Chill\PersonBundle\Privacy\AccompanyingPeriodPrivacyEvent; -use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepository; +use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; use Chill\PersonBundle\Repository\AccompanyingPeriodRepository; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Chill\ThirdPartyBundle\Entity\ThirdParty; @@ -46,7 +46,7 @@ use Symfony\Component\Workflow\Registry; final class AccompanyingCourseApiController extends ApiController { - public function __construct(private readonly AccompanyingPeriodRepository $accompanyingPeriodRepository, private readonly AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository, private readonly EventDispatcherInterface $eventDispatcher, private readonly ReferralsSuggestionInterface $referralAvailable, private readonly Registry $registry, private readonly ValidatorInterface $validator, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} + public function __construct(private readonly AccompanyingPeriodRepository $accompanyingPeriodRepository, private readonly EventDispatcherInterface $eventDispatcher, private readonly ReferralsSuggestionInterface $referralAvailable, private readonly Registry $registry, private readonly ValidatorInterface $validator, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry, private readonly AccompanyingPeriodWorkRepository $accompanyingPeriodWorkRepository) {} public function commentApi($id, Request $request, string $_format): Response { @@ -305,6 +305,20 @@ final class AccompanyingCourseApiController extends ApiController return $this->json($accompanyingCourse->getIntensity(), Response::HTTP_OK, [], ['groups' => ['read']]); } + /** + * @ParamConverter("accompanyingPeriod", options={"id": "id"}) + */ + #[Route(path: '/api/1.0/person/accompanying-course/{id}/works.json', name: 'chill_api_person_accompanying_period_works')] + public function worksByAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): JsonResponse + { + $this->denyAccessUnlessGranted(AccompanyingPeriodVoter::SEE, $accompanyingPeriod); + + $works = $this->accompanyingPeriodWorkRepository->findBy(['accompanyingPeriod' => $accompanyingPeriod]); + dump($works); + + return $this->json($works, Response::HTTP_OK, [], ['groups' => ['read']]); + } + public function workApi($id, Request $request, string $_format): Response { return $this->addRemoveSomething( diff --git a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml index 45cccf958..637ab399d 100644 --- a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml @@ -1013,6 +1013,29 @@ paths: 200: description: "OK" + /1.0/person/accompanying-course/{id}/works.json: + get: + tags: + - accompanying-course + summary: List of accompanying period works for an accompanying period + description: Gets a list of accompanying period works for an accompanying period + parameters: + - name: id + in: path + required: true + description: The accompanying period id + schema: + type: integer + format: integer + minimum: 1 + responses: + 401: + description: "Unauthorized" + 404: + description: "Not found" + 200: + description: "OK" + /1.0/person/accompanying-course/{id}/work.json: post: tags: