From c16f3253b215cacb609161517bec6c6104d5e185 Mon Sep 17 00:00:00 2001 From: Andrey Gubskiy Date: Wed, 29 Jan 2025 23:50:08 +0200 Subject: [PATCH 1/8] Use mocked modules --- src/CampusClient.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CampusClient.js b/src/CampusClient.js index 340748de..8e5e67a2 100644 --- a/src/CampusClient.js +++ b/src/CampusClient.js @@ -150,6 +150,10 @@ export const getCurrentUser = async (ignoreCache) => { const user = await response.json(); if (!!user) { + + // use default modules as temporary solution + user.modules = ['PersonalArea', 'Information', 'EmploymentSystem']; + localStorage.setItem(cachedUserInfoKey, JSON.stringify(user)); } From d9e8ce0fe6e27b115d06283071f97735766426d2 Mon Sep 17 00:00:00 2001 From: Andrey Gubskiy Date: Thu, 30 Jan 2025 10:19:59 +0200 Subject: [PATCH 2/8] Load available modules via new endpoint --- src/CampusClient.js | 5 +++-- src/Security.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/CampusClient.js b/src/CampusClient.js index 8e5e67a2..93948b37 100644 --- a/src/CampusClient.js +++ b/src/CampusClient.js @@ -150,9 +150,10 @@ export const getCurrentUser = async (ignoreCache) => { const user = await response.json(); if (!!user) { + const modulesResponse = await callApi('profile/modules', 'GET'); + const modules = await modulesResponse.json(); - // use default modules as temporary solution - user.modules = ['PersonalArea', 'Information', 'EmploymentSystem']; + user.modules = modules; localStorage.setItem(cachedUserInfoKey, JSON.stringify(user)); } diff --git a/src/Security.js b/src/Security.js index ea5f21c1..0c202158 100644 --- a/src/Security.js +++ b/src/Security.js @@ -5,6 +5,7 @@ * @returns {boolean} */ export const hasAccessToModule = (user, module) => { + console.log(user); if (!user || !user.modules) { return false; } @@ -27,8 +28,8 @@ export const hasProfile = (user, profile) => { }; export const Modules = { - PersonalArea: 'PersonalArea', - Information: 'Information', + PersonalArea: 'profile', + Information: 'help', EmploymentSystem: 'EmploymentSystem' }; From 3eee965986466a17014c4caba3ae8ad9c91ef2e6 Mon Sep 17 00:00:00 2001 From: Andrey Gubskiy Date: Thu, 30 Jan 2025 10:20:42 +0200 Subject: [PATCH 3/8] Simplify code --- src/CampusClient.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/CampusClient.js b/src/CampusClient.js index 93948b37..17b90f73 100644 --- a/src/CampusClient.js +++ b/src/CampusClient.js @@ -151,9 +151,8 @@ export const getCurrentUser = async (ignoreCache) => { if (!!user) { const modulesResponse = await callApi('profile/modules', 'GET'); - const modules = await modulesResponse.json(); - user.modules = modules; + user.modules = await modulesResponse.json(); localStorage.setItem(cachedUserInfoKey, JSON.stringify(user)); } From 4dfdbf5119cd9b1725bae6a587980b849103660d Mon Sep 17 00:00:00 2001 From: Andrey Gubskiy Date: Thu, 30 Jan 2025 10:30:10 +0200 Subject: [PATCH 4/8] Cleanup --- src/Security.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Security.js b/src/Security.js index 0c202158..af987dd4 100644 --- a/src/Security.js +++ b/src/Security.js @@ -5,7 +5,7 @@ * @returns {boolean} */ export const hasAccessToModule = (user, module) => { - console.log(user); + if (!user || !user.modules) { return false; } From d410cf6647b1a9e3673670dfff7d37627ef1227a Mon Sep 17 00:00:00 2001 From: Andrey Gubskiy Date: Thu, 30 Jan 2025 10:30:38 +0200 Subject: [PATCH 5/8] remove new line --- src/Security.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Security.js b/src/Security.js index af987dd4..4d5e310a 100644 --- a/src/Security.js +++ b/src/Security.js @@ -5,7 +5,6 @@ * @returns {boolean} */ export const hasAccessToModule = (user, module) => { - if (!user || !user.modules) { return false; } From 1e9ada9d70deb5eb9a6c4a30110d3c092e504b7a Mon Sep 17 00:00:00 2001 From: Andrey Gubskiy Date: Thu, 30 Jan 2025 23:04:36 +0200 Subject: [PATCH 6/8] Simplify logic --- src/CampusClient.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/CampusClient.js b/src/CampusClient.js index 17b90f73..f7641023 100644 --- a/src/CampusClient.js +++ b/src/CampusClient.js @@ -150,9 +150,13 @@ export const getCurrentUser = async (ignoreCache) => { const user = await response.json(); if (!!user) { - const modulesResponse = await callApi('profile/modules', 'GET'); + user.modules = ['profile', 'help']; - user.modules = await modulesResponse.json(); + console.log(user); + + if (!!user.studentProfile) { + user.modules = ['profile', 'help', 'EmploymentSystem']; + } localStorage.setItem(cachedUserInfoKey, JSON.stringify(user)); } From a4ba95e8a0864b2d03058e07a0999b07d9fe78b1 Mon Sep 17 00:00:00 2001 From: Andrey Gubskiy Date: Thu, 30 Jan 2025 23:10:14 +0200 Subject: [PATCH 7/8] Simplify logic --- src/CampusClient.js | 9 ++++++--- src/Security.js | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/CampusClient.js b/src/CampusClient.js index f7641023..53b3b970 100644 --- a/src/CampusClient.js +++ b/src/CampusClient.js @@ -1,4 +1,5 @@ import ApplicationConfiguration from './ApplicationConfiguration'; +import * as Security from './Security'; /** * Application configuration @@ -150,12 +151,14 @@ export const getCurrentUser = async (ignoreCache) => { const user = await response.json(); if (!!user) { - user.modules = ['profile', 'help']; + user.modules = [ + Security.Modules.Information, + Security.Modules.PersonalArea, + ]; - console.log(user); if (!!user.studentProfile) { - user.modules = ['profile', 'help', 'EmploymentSystem']; + user.modules.push(Security.Modules.EmploymentSystem); } localStorage.setItem(cachedUserInfoKey, JSON.stringify(user)); diff --git a/src/Security.js b/src/Security.js index 4d5e310a..ea5f21c1 100644 --- a/src/Security.js +++ b/src/Security.js @@ -27,8 +27,8 @@ export const hasProfile = (user, profile) => { }; export const Modules = { - PersonalArea: 'profile', - Information: 'help', + PersonalArea: 'PersonalArea', + Information: 'Information', EmploymentSystem: 'EmploymentSystem' }; From 64daabae07008689e8be0fd928f67af1631d00b4 Mon Sep 17 00:00:00 2001 From: Andrey Gubskiy Date: Thu, 30 Jan 2025 23:11:16 +0200 Subject: [PATCH 8/8] Cleanup code --- src/CampusClient.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CampusClient.js b/src/CampusClient.js index 53b3b970..81e7b660 100644 --- a/src/CampusClient.js +++ b/src/CampusClient.js @@ -156,7 +156,6 @@ export const getCurrentUser = async (ignoreCache) => { Security.Modules.PersonalArea, ]; - if (!!user.studentProfile) { user.modules.push(Security.Modules.EmploymentSystem); }