Skip to content

Commit

Permalink
Internal: Improve loading courseHome page - refs BT#21784
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbeeznest committed Jun 21, 2024
1 parent 60cd1e4 commit 1da244f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
12 changes: 5 additions & 7 deletions assets/vue/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,12 @@ router.beforeResolve(async (to) => {

if ("CourseHome" === to.name) {
cid = parseInt(to.params?.id ?? 0)
const useBasic = true
await cidReqStore.setCourseAndSessionById(cid, sid, useBasic)
}

if (cid) {
await cidReqStore.setCourseAndSessionById(cid, sid)
} else {
if (cid) {
await cidReqStore.setCourseAndSessionById(cid, sid)
} else {
cidReqStore.resetCid()
}
cidReqStore.resetCid()
}
})

Expand Down
2 changes: 1 addition & 1 deletion assets/vue/services/sessionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
* @returns {Promise<Object>}
*/
async find(iri, useBasic = false) {
const endpoint = useBasic ? `${iri}/basic` : iri
const endpoint = iri
const groups = useBasic ? ['session:basic'] : ['session:read']
const { data } = await api.get(endpoint, {
params: {
Expand Down
4 changes: 2 additions & 2 deletions assets/vue/store/cidReq.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const useCidReqStore = defineStore("cidReq", () => {
}
}

const setSessionByIri = async (sId, useBasic = false) => {
const setSessionByIri = async (sId, useBasic = true) => {
const sessionIri = `/api/sessions/${sId}`

if (session.value && sessionIri === session.value["@id"]) {
Expand All @@ -92,7 +92,7 @@ export const useCidReqStore = defineStore("cidReq", () => {
}
}

const setCourseAndSessionById = (cId, sId = undefined, useBasic = false) => {
const setCourseAndSessionById = (cId, sId = undefined, useBasic = true) => {
if (!cId) {
return Promise.resolve()
}
Expand Down
17 changes: 6 additions & 11 deletions src/CoreBundle/Entity/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,17 +34,10 @@

#[ApiResource(
operations: [
new Get(
uriTemplate: '/sessions/{id}/basic',
normalizationContext: [
'groups' => ['session:basic'],
],
security: "is_granted('ROLE_ADMIN') or is_granted('VIEW', object)"
),
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)"
),
Expand Down Expand Up @@ -112,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;
Expand Down

0 comments on commit 1da244f

Please sign in to comment.