diff --git a/src/mocks/handlers.js b/src/mocks/handlers.js index c6ca5a9f1ffd7464851ae1e501857b360306df38..fefc3d9c669555f3881ded216b363dd1b1cb6e12 100644 --- a/src/mocks/handlers.js +++ b/src/mocks/handlers.js @@ -9,6 +9,7 @@ import MockServerConfig from './mock_server-config.json'; import MockUsers from './mock_users.json'; import MockSimulations from './mock_simulations.json'; import MockUserGroups from './mock_user-groups.json'; +import MockGDPR from './mock_gdpr.json'; import ImageAI from '../assets/images/Artificial_Intelligence_2.jpg'; @@ -48,7 +49,15 @@ export const handlers = [ rest.get(`${config.api.proxy.url}${endpoints.proxy.identity.me.groups.url}`, (req, res, ctx) => { return res(ctx.json(MockUserGroups)); }), + rest.get(`${config.api.proxy.url}${endpoints.proxy.identity.url}${endpoints.proxy.identity.gdpr}`, + (req, res, ctx) => { + return res(ctx.json(MockGDPR)); + }), rest.get(`${config.api.proxy.url}${endpoints.proxy.identity.url}/:userID`, (req, res, ctx) => { return res(ctx.json(MockUsers[1])); - }) + }), + rest.post(`${config.api.proxy.url}${endpoints.proxy.identity.url}${endpoints.proxy.identity.gdpr}`, + (req, res, ctx) => { + return res(ctx.json({"status":"success"})); + }) ]; \ No newline at end of file diff --git a/src/mocks/mock_gdpr.json b/src/mocks/mock_gdpr.json new file mode 100644 index 0000000000000000000000000000000000000000..5f7e96e64f6e6afdd5960f51cd34db5bb41f0548 --- /dev/null +++ b/src/mocks/mock_gdpr.json @@ -0,0 +1,3 @@ +{ + "gdpr": false +} \ No newline at end of file diff --git a/src/services/proxy/__tests__/nrp-user-service.test.js b/src/services/proxy/__tests__/nrp-user-service.test.js index 7561dcfb858bf5b20c18b2e2f84599821b8dc7a1..b3c184ebbe5989bf80b1d11f84c9df6f79eb5ebd 100644 --- a/src/services/proxy/__tests__/nrp-user-service.test.js +++ b/src/services/proxy/__tests__/nrp-user-service.test.js @@ -71,4 +71,12 @@ test('can determine group membership for administrators', async () => { test('can retrieve cluster reservations', async () => { expect(await NrpUserService.instance.getReservation()).toBe(undefined); +}); + +test('can retrieve false gdpr status', async () => { + expect(await NrpUserService.instance.getGdpr()).toEqual({"gdpr": false}); +}); + +test('can set gdpr status', async () => { + expect(await NrpUserService.instance.setGdpr()).toEqual({"status":"success"}); }); \ No newline at end of file diff --git a/src/services/proxy/data/endpoints.json b/src/services/proxy/data/endpoints.json index 2ab2653147217a8d0853ad87705cd1b8d10fbcb0..d1ced87b78704bdda5965e1b06b3ce41113ba3ec 100644 --- a/src/services/proxy/data/endpoints.json +++ b/src/services/proxy/data/endpoints.json @@ -16,7 +16,8 @@ "groups": { "url": "/identity/me/groups" } - } + }, + "gdpr": "/gdpr" }, "server": { "url": "/server" diff --git a/src/services/proxy/nrp-user-service.js b/src/services/proxy/nrp-user-service.js index 58d8ac224f694234dd68a099c7e247db597f9641..5bd1c50425a63bccb98630c48338d4132d5dbc8d 100644 --- a/src/services/proxy/nrp-user-service.js +++ b/src/services/proxy/nrp-user-service.js @@ -14,7 +14,7 @@ const PROXY_URL = config.api.proxy.url; const IDENTITY_BASE_URL = `${PROXY_URL}${endpoints.proxy.identity.url}`; const IDENTITY_ME_URL = `${PROXY_URL}${endpoints.proxy.identity.me.url}`; const IDENTITY_ME_GROUPS_URL = `${PROXY_URL}${endpoints.proxy.identity.me.groups.url}`; - +const GDPR_URL = `${IDENTITY_BASE_URL}${endpoints.proxy.identity.gdpr}`; /** * Service managing all data related to NRP users. */ @@ -112,6 +112,22 @@ class NrpUserService extends HttpService { getReservation() { return window.sessionStorage.getItem('clusterReservation'); } + + /** + * Get the GDPR status for current user. + * @returns {promise} Contains the GDPR status for the current user + */ + async getGdpr() { + return await (await this.httpRequestGET(GDPR_URL)).json(); + } + + /** + * Set the accepted GDPR status for current user. + * @returns {promise} Response for the current user + */ + async setGdpr() { + return await (await this.httpRequestPOST(GDPR_URL)).json(); + } } export default NrpUserService;