diff --git a/assets/vue/services/sessionService.js b/assets/vue/services/sessionService.js index 9c338c29f38..4f53e483414 100644 --- a/assets/vue/services/sessionService.js +++ b/assets/vue/services/sessionService.js @@ -13,10 +13,17 @@ async function findUserSubscriptions(userIri, listType) { export default { /** * @param {string} iri + * @param useBasic * @returns {Promise} */ - async find(iri) { - const { data } = await api.get(iri) + async find(iri, useBasic = false) { + const endpoint = iri + const groups = useBasic ? ['session:basic'] : ['session:read'] + const { data } = await api.get(endpoint, { + params: { + 'groups[]': groups + } + }) return data }, diff --git a/assets/vue/store/cidReq.js b/assets/vue/store/cidReq.js index c0211dba3ee..fde93cb08a2 100644 --- a/assets/vue/store/cidReq.js +++ b/assets/vue/store/cidReq.js @@ -78,7 +78,7 @@ export const useCidReqStore = defineStore("cidReq", () => { } } - const setSessionByIri = async (sId) => { + const setSessionByIri = async (sId, useBasic = true) => { const sessionIri = `/api/sessions/${sId}` if (session.value && sessionIri === session.value["@id"]) { @@ -86,13 +86,13 @@ export const useCidReqStore = defineStore("cidReq", () => { } try { - session.value = await sessionService.find(sessionIri) + session.value = await sessionService.find(sessionIri, useBasic) } catch (error) { console.error(error) } } - const setCourseAndSessionById = (cId, sId = undefined) => { + const setCourseAndSessionById = (cId, sId = undefined, useBasic = true) => { if (!cId) { return Promise.resolve() } @@ -103,7 +103,7 @@ export const useCidReqStore = defineStore("cidReq", () => { return coursePromise } - const sessionPromise = setSessionByIri(sId) + const sessionPromise = setSessionByIri(sId, useBasic) return Promise.all([coursePromise, sessionPromise]) } diff --git a/src/CoreBundle/Entity/Session.php b/src/CoreBundle/Entity/Session.php index 70cb652f092..b5c002d9e70 100644 --- a/src/CoreBundle/Entity/Session.php +++ b/src/CoreBundle/Entity/Session.php @@ -6,6 +6,7 @@ namespace Chamilo\CoreBundle\Entity; +use ApiPlatform\Core\Serializer\Filter\GroupFilter; use ApiPlatform\Doctrine\Orm\Filter\OrderFilter; use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; use ApiPlatform\Metadata\ApiFilter; @@ -34,8 +35,9 @@ #[ApiResource( operations: [ new Get( + uriTemplate: '/sessions/{id}', normalizationContext: [ - 'groups' => ['session:read', 'session:item:read'], + 'groups' => ['session:basic'], ], security: "is_granted('ROLE_ADMIN') or is_granted('VIEW', object)" ), @@ -95,7 +97,7 @@ new Post(security: "is_granted('ROLE_ADMIN')"), new Delete(security: "is_granted('DELETE', object)"), ], - normalizationContext: ['groups' => ['session:read']], + normalizationContext: ['groups' => ['session:basic']], denormalizationContext: ['groups' => ['session:write']], security: "is_granted('ROLE_ADMIN')" )] @@ -104,9 +106,10 @@ #[ORM\EntityListeners([SessionListener::class])] #[ORM\Entity(repositoryClass: SessionRepository::class)] #[UniqueEntity('title')] -#[ApiFilter(filterClass: SearchFilter::class, properties: ['title' => 'partial'])] -#[ApiFilter(filterClass: PropertyFilter::class)] -#[ApiFilter(filterClass: OrderFilter::class, properties: ['id', 'title'])] +#[ApiFilter(SearchFilter::class, properties: ['title' => 'partial'])] +#[ApiFilter(PropertyFilter::class)] +#[ApiFilter(OrderFilter::class, properties: ['id', 'title'])] +#[ApiFilter(GroupFilter::class, arguments: ['parameterName' => 'groups'])] class Session implements ResourceWithAccessUrlInterface, Stringable { public const READ_ONLY = 1; @@ -121,6 +124,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable public const SESSION_ADMIN = 4; #[Groups([ + 'session:basic', 'session:read', 'session_rel_user:read', 'session_rel_course_rel_user:read', @@ -147,6 +151,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable mappedBy: 'session', targetEntity: SessionRelCourse::class, cascade: ['persist'], + fetch: 'EXTRA_LAZY', orphanRemoval: true )] protected Collection $courses; @@ -161,6 +166,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable mappedBy: 'session', targetEntity: SessionRelUser::class, cascade: ['persist', 'remove'], + fetch: 'EXTRA_LAZY', orphanRemoval: true )] protected Collection $users; @@ -219,6 +225,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable #[Assert\NotBlank] #[Groups([ + 'session:basic', 'session:read', 'session:write', 'session_rel_course_rel_user:read', @@ -233,6 +240,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable protected string $title; #[Groups([ + 'session:basic', 'session:read', 'session:write', ])] @@ -250,11 +258,11 @@ class Session implements ResourceWithAccessUrlInterface, Stringable #[ORM\Column(name: 'duration', type: 'integer', nullable: true)] protected ?int $duration = null; - #[Groups(['session:read'])] + #[Groups(['session:basic', 'session:read'])] #[ORM\Column(name: 'nbr_courses', type: 'integer', unique: false, nullable: false)] protected int $nbrCourses; - #[Groups(['session:read'])] + #[Groups(['session:basic', 'session:read'])] #[ORM\Column(name: 'nbr_users', type: 'integer', unique: false, nullable: false)] protected int $nbrUsers; @@ -263,6 +271,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable protected int $nbrClasses; #[Groups([ + 'session:basic', 'session:read', 'session:write', ])]