From f1f187f9e81f0a3e273e9e783b241f3c24634483 Mon Sep 17 00:00:00 2001 From: Okke Harsta Date: Mon, 9 Sep 2024 13:22:52 +0200 Subject: [PATCH] JS tests for sorting / subsorting applications --- client/src/__tests__/utils/Manage.test.js | 479 ++----------------- client/src/__tests__/utils/applications.json | 156 ++++++ client/src/__tests__/utils/roles.json | 291 +++++++++++ client/src/__tests__/utils/userRoles.json | 73 +++ client/src/utils/Manage.js | 40 +- welcome/src/utils/Manage.js | 3 +- 6 files changed, 579 insertions(+), 463 deletions(-) create mode 100644 client/src/__tests__/utils/applications.json create mode 100644 client/src/__tests__/utils/roles.json create mode 100644 client/src/__tests__/utils/userRoles.json diff --git a/client/src/__tests__/utils/Manage.test.js b/client/src/__tests__/utils/Manage.test.js index 527fd20b..1a088e66 100644 --- a/client/src/__tests__/utils/Manage.test.js +++ b/client/src/__tests__/utils/Manage.test.js @@ -1,454 +1,33 @@ -import {mergeProvidersProvisioningsRoles} from "../../utils/Manage"; -import {AUTHORITIES} from "../../utils/UserRole"; - -const applications = { - "provisionings": [ - { - "scim_user": "user", - "scim_update_role_put_method": true, - "entityid": "https://scim", - "type": "provisioning", - "scim_password": "secret", - "name:en": "Scim", - "id": "7", - "scim_url": "http://localhost:8081/api/scim/v2", - "provisioning_type": "scim", - "_id": "7", - "applications": [ - { - "id": "1", - "type": "saml20_sp" - }, - { - "id": "5", - "type": "oidc10_rp" - } - ] - }, - { - "scim_user": "user", - "scim_update_role_put_method": false, - "entityid": "https://scim-patch", - "type": "provisioning", - "scim_password": "secret", - "name:en": "Scim-Patch", - "id": "8", - "scim_url": "http://localhost:8081/api/scim/v2", - "scim_user_identifier": "subject_id", - "provisioning_type": "scim", - "_id": "8", - "applications": [ - { - "id": "4", - "type": "saml20_sp" - } - ] - }, - { - "graph_client_id": "client_id", - "entityid": "https://graph", - "type": "provisioning", - "graph_tenant": "tenant", - "name:en": "graph", - "id": "9", - "graph_url": "http://localhost:8081/graph/users", - "provisioning_type": "graph", - "graph_secret": "secret", - "_id": "9", - "applications": [ - { - "id": "2", - "type": "saml20_sp" - }, - { - "id": "6", - "type": "oidc10_rp" - } - ] - }, - { - "entityid": "https://eva", - "type": "provisioning", - "name:en": "EVA", - "id": "10", - "eva_guest_account_duration": 30, - "eva_token": "secret", - "provisioning_type": "eva", - "eva_url": "http://localhost:8081/eva", - "_id": "10", - "applications": [ - { - "id": "3", - "type": "saml20_sp" - } - ] - } - ], - "providers": [ - { - "entityid": "https://calendar", - "type": "oidc10_rp", - "url": "https://default-url-calendar.org", - "name:nl": "Calendar NL", - "institutionGuid": "ad93daef-0911-e511-80d0-005056956c1a", - "OrganizationName:en": "SURF bv", - "logo": "https://static.surfconext.nl/media/idp/surfconext.png", - "name:en": "Calendar EN", - "id": "5", - "_id": "5" - }, - { - "entityid": "https://cloud", - "type": "oidc10_rp", - "url": "https://default-url-cloud.org", - "name:nl": "Cloud NL", - "OrganizationName:en": "SURF bv", - "logo": "https://static.surfconext.nl/media/idp/surfconext.png", - "name:en": "Cloud EN", - "id": "6", - "_id": "6" - }, - { - "entityid": "https://wiki", - "type": "saml20_sp", - "url": "https://default-url-wiki.org", - "name:nl": "Wiki NL", - "institutionGuid": "ad93daef-0911-e511-80d0-005056956c1a", - "OrganizationName:en": "SURF bv", - "name:en": "Wiki EN", - "id": "1", - "_id": "1" - }, - { - "entityid": "https://network", - "type": "saml20_sp", - "url": "https://default-url-network.org", - "name:nl": "Network NL", - "institutionGuid": "ad93daef-0911-e511-80d0-005056956c1a", - "OrganizationName:en": "SURF bv", - "logo": "https://static.surfconext.nl/media/idp/surfconext.png", - "name:en": "Network EN", - "id": "2", - "_id": "2" - }, - { - "entityid": "https://storage", - "type": "saml20_sp", - "url": "https://default-url-storage.org", - "name:nl": "Storage NL", - "OrganizationName:en": "SURF bv", - "logo": "https://static.surfconext.nl/media/idp/surfconext.png", - "name:en": "Storage EN", - "id": "3", - "_id": "3" - }, - { - "entityid": "https://research", - "type": "saml20_sp", - "url": "https://default-url-research.org", - "name:nl": "Research NL", - "OrganizationName:en": "SURF bv", - "logo": "https://static.surfconext.nl/media/idp/surfconext.png", - "name:en": "Research EN", - "id": "4", - "_id": "4" - } - ] -} - -const roles = [ - { - "id": 3915, - "name": "Wiki", - "shortName": "wiki", - "description": "Wiki desc", - "defaultExpiryDays": 365, - "enforceEmailEquality": false, - "eduIDOnly": false, - "blockExpiryDate": false, - "overrideSettingsAllowed": false, - "teamsOrigin": false, - "identifier": "3e267427-e2cd-4b9e-9a78-9248bede1bc4", - "userRoleCount": 2, - "applicationUsages": [ - { - "id": 4574, - "landingPage": "http://landingpage.com", - "application": { - "id": 3901, - "manageId": "1", - "manageType": "SAML20_SP", - "landingPage": "http://landingpage.com" - } - } - ], - "auditable": { - "createdAt": 1721314647.000000000, - "createdBy": "ResourceCleaner" - }, - "applicationMaps": [ - { - "landingPage": "http://landingpage.com", - "entityid": "https://wiki", - "type": "saml20_sp", - "url": "https://default-url-wiki.org", - "name:nl": "Wiki NL", - "institutionGuid": "ad93daef-0911-e511-80d0-005056956c1a", - "OrganizationName:en": "SURF bv", - "name:en": "Wiki EN", - "id": "1", - "_id": "1" - } - ] - }, - { - "id": 3916, - "name": "Network", - "shortName": "network", - "description": "Network desc", - "defaultExpiryDays": 365, - "enforceEmailEquality": false, - "eduIDOnly": false, - "blockExpiryDate": false, - "overrideSettingsAllowed": false, - "teamsOrigin": false, - "identifier": "3cec7986-ca0c-4750-a6f3-86f2ff7fb82f", - "userRoleCount": 0, - "applicationUsages": [ - { - "id": 4575, - "landingPage": "http://landingpage.com", - "application": { - "id": 3902, - "manageId": "2", - "manageType": "SAML20_SP", - "landingPage": "http://landingpage.com" - } - } - ], - "auditable": { - "createdAt": 1721314647.000000000, - "createdBy": "ResourceCleaner" - }, - "applicationMaps": [ - { - "landingPage": "http://landingpage.com", - "entityid": "https://network", - "type": "saml20_sp", - "url": "https://default-url-network.org", - "name:nl": "Network NL", - "institutionGuid": "ad93daef-0911-e511-80d0-005056956c1a", - "OrganizationName:en": "SURF bv", - "logo": "https://static.surfconext.nl/media/idp/surfconext.png", - "name:en": "Network EN", - "id": "2", - "_id": "2" - } - ] - }, - { - "id": 3917, - "name": "Storage", - "shortName": "storage", - "description": "Storage desc", - "defaultExpiryDays": 365, - "enforceEmailEquality": false, - "eduIDOnly": false, - "blockExpiryDate": false, - "overrideSettingsAllowed": false, - "teamsOrigin": false, - "identifier": "9ac14a11-fd43-4f9c-abeb-8bf811f134df", - "userRoleCount": 1, - "applicationUsages": [ - { - "id": 4576, - "landingPage": "https://landingpage.com", - "application": { - "id": 3903, - "manageId": "3", - "manageType": "SAML20_SP", - "landingPage": "https://landingpage.com" - } - }, - { - "id": 4577, - "landingPage": "https://landingpage.com", - "application": { - "id": 3904, - "manageId": "6", - "manageType": "OIDC10_RP", - "landingPage": "https://landingpage.com" - } - } - ], - "auditable": { - "createdAt": 1721314647.000000000, - "createdBy": "ResourceCleaner" - }, - "applicationMaps": [ - { - "landingPage": "https://landingpage.com", - "entityid": "https://storage", - "type": "saml20_sp", - "url": "https://default-url-storage.org", - "name:nl": "Storage NL", - "OrganizationName:en": "SURF bv", - "logo": "https://static.surfconext.nl/media/idp/surfconext.png", - "name:en": "Storage EN", - "id": "3", - "_id": "3" - }, - { - "landingPage": "https://landingpage.com", - "entityid": "https://cloud", - "type": "oidc10_rp", - "url": "https://default-url-cloud.org", - "name:nl": "Cloud NL", - "OrganizationName:en": "SURF bv", - "logo": "https://static.surfconext.nl/media/idp/surfconext.png", - "name:en": "Cloud EN", - "id": "6", - "_id": "6" - } - ] - }, - { - "id": 3918, - "name": "Research", - "shortName": "research", - "description": "Research desc", - "defaultExpiryDays": 365, - "enforceEmailEquality": false, - "eduIDOnly": false, - "blockExpiryDate": false, - "overrideSettingsAllowed": false, - "teamsOrigin": false, - "identifier": "f2c99710-0cd1-4ea2-a20c-14da698a866b", - "userRoleCount": 1, - "applicationUsages": [ - { - "id": 4578, - "landingPage": "http://landingpage.com", - "application": { - "id": 3905, - "manageId": "4", - "manageType": "SAML20_SP", - "landingPage": "http://landingpage.com" - } - } - ], - "auditable": { - "createdAt": 1721314647.000000000, - "createdBy": "ResourceCleaner" - }, - "applicationMaps": [ - { - "landingPage": "http://landingpage.com", - "entityid": "https://research", - "type": "saml20_sp", - "url": "https://default-url-research.org", - "name:nl": "Research NL", - "OrganizationName:en": "SURF bv", - "logo": "https://static.surfconext.nl/media/idp/surfconext.png", - "name:en": "Research EN", - "id": "4", - "_id": "4" - } - ] - }, - { - "id": 3919, - "name": "Calendar", - "shortName": "calendar", - "description": "Calendar desc", - "defaultExpiryDays": 365, - "enforceEmailEquality": false, - "eduIDOnly": false, - "blockExpiryDate": false, - "overrideSettingsAllowed": false, - "teamsOrigin": false, - "identifier": "75e4e7b6-5f98-45bc-9d10-9795316e6be0", - "userRoleCount": 1, - "applicationUsages": [ - { - "id": 4579, - "landingPage": "http://landingpage.com", - "application": { - "id": 3906, - "manageId": "5", - "manageType": "OIDC10_RP", - "landingPage": "http://landingpage.com" - } - } - ], - "auditable": { - "createdAt": 1721314647.000000000, - "createdBy": "ResourceCleaner" - }, - "applicationMaps": [ - { - "landingPage": "http://landingpage.com", - "entityid": "https://calendar", - "type": "oidc10_rp", - "url": "https://default-url-calendar.org", - "name:nl": "Calendar NL", - "institutionGuid": "ad93daef-0911-e511-80d0-005056956c1a", - "OrganizationName:en": "SURF bv", - "logo": "https://static.surfconext.nl/media/idp/surfconext.png", - "name:en": "Calendar EN", - "id": "5", - "_id": "5" - } - ] - }, - { - "id": 3920, - "name": "Mail", - "shortName": "mail", - "description": "Mail desc", - "defaultExpiryDays": 365, - "enforceEmailEquality": false, - "eduIDOnly": false, - "blockExpiryDate": false, - "overrideSettingsAllowed": false, - "teamsOrigin": false, - "identifier": "a2e7d57c-652c-430c-98e6-d5ac7050d979", - "userRoleCount": 0, - "applicationUsages": [ - { - "id": 4580, - "landingPage": "http://landingpage.com", - "application": { - "id": 3906, - "manageId": "5", - "manageType": "OIDC10_RP", - "landingPage": "http://landingpage.com" - } - } - ], - "auditable": { - "createdAt": 1721314647.000000000, - "createdBy": "ResourceCleaner" - }, - "applicationMaps": [ - { - "landingPage": "http://landingpage.com", - "entityid": "https://calendar", - "type": "oidc10_rp", - "url": "https://default-url-calendar.org", - "name:nl": "Calendar NL", - "institutionGuid": "ad93daef-0911-e511-80d0-005056956c1a", - "OrganizationName:en": "SURF bv", - "logo": "https://static.surfconext.nl/media/idp/surfconext.png", - "name:en": "Calendar EN", - "id": "5", - "_id": "5" - } - ] - } -] +import {mergeProvidersProvisioningsRoles, reduceApplicationFromUserRoles} from "../../utils/Manage"; +import applications from "./applications.json"; +import roles from "./roles.json"; +import userRoles from "./userRoles.json"; test("Test mergeProvidersProvisioningsRoles", () => { const results = mergeProvidersProvisioningsRoles(applications.providers, applications.provisionings, roles); expect(results.length).toEqual(6); -}) +}); + +test("Test reduceApplicationFromUserRoles", () => { + const results = reduceApplicationFromUserRoles(userRoles, "en"); + const applicationNames = results.map(app => app.applicationName); + //Sorting alphabetically on applicationName + expect(applicationNames).toEqual([ + "Calendar EN (SURF bv)", + "Research EN (SURF bv)", + "Research EN (SURF bv)", + "Wiki EN (SURF bv)", + "Wiki EN (SURF bv)", + "Wiki EN (SURF bv)" + ]); + const roleNames = results + .filter(app => app.applicationName.startsWith("Wiki")) + .map(app => app.roleName); + //Sub-sorting alphabetically on roleName + expect(roleNames).toEqual([ + "Wiki 1 Role", + "Wiki 2 Role", + "Wiki Another Role (3) - Calendar (1)" + ]); +}); + diff --git a/client/src/__tests__/utils/applications.json b/client/src/__tests__/utils/applications.json new file mode 100644 index 00000000..df630b1e --- /dev/null +++ b/client/src/__tests__/utils/applications.json @@ -0,0 +1,156 @@ +{ + "provisionings": [ + { + "scim_user": "user", + "scim_update_role_put_method": true, + "entityid": "https://scim", + "type": "provisioning", + "scim_password": "secret", + "name:en": "Scim", + "id": "7", + "scim_url": "http://localhost:8081/api/scim/v2", + "provisioning_type": "scim", + "_id": "7", + "applications": [ + { + "id": "1", + "type": "saml20_sp" + }, + { + "id": "5", + "type": "oidc10_rp" + } + ] + }, + { + "scim_user": "user", + "scim_update_role_put_method": false, + "entityid": "https://scim-patch", + "type": "provisioning", + "scim_password": "secret", + "name:en": "Scim-Patch", + "id": "8", + "scim_url": "http://localhost:8081/api/scim/v2", + "scim_user_identifier": "subject_id", + "provisioning_type": "scim", + "_id": "8", + "applications": [ + { + "id": "4", + "type": "saml20_sp" + } + ] + }, + { + "graph_client_id": "client_id", + "entityid": "https://graph", + "type": "provisioning", + "graph_tenant": "tenant", + "name:en": "graph", + "id": "9", + "graph_url": "http://localhost:8081/graph/users", + "provisioning_type": "graph", + "graph_secret": "secret", + "_id": "9", + "applications": [ + { + "id": "2", + "type": "saml20_sp" + }, + { + "id": "6", + "type": "oidc10_rp" + } + ] + }, + { + "entityid": "https://eva", + "type": "provisioning", + "name:en": "EVA", + "id": "10", + "eva_guest_account_duration": 30, + "eva_token": "secret", + "provisioning_type": "eva", + "eva_url": "http://localhost:8081/eva", + "_id": "10", + "applications": [ + { + "id": "3", + "type": "saml20_sp" + } + ] + } + ], + "providers": [ + { + "entityid": "https://calendar", + "type": "oidc10_rp", + "url": "https://default-url-calendar.org", + "name:nl": "Calendar NL", + "institutionGuid": "ad93daef-0911-e511-80d0-005056956c1a", + "OrganizationName:en": "SURF bv", + "logo": "https://static.surfconext.nl/media/idp/surfconext.png", + "name:en": "Calendar EN", + "id": "5", + "_id": "5" + }, + { + "entityid": "https://cloud", + "type": "oidc10_rp", + "url": "https://default-url-cloud.org", + "name:nl": "Cloud NL", + "OrganizationName:en": "SURF bv", + "logo": "https://static.surfconext.nl/media/idp/surfconext.png", + "name:en": "Cloud EN", + "id": "6", + "_id": "6" + }, + { + "entityid": "https://wiki", + "type": "saml20_sp", + "url": "https://default-url-wiki.org", + "name:nl": "Wiki NL", + "institutionGuid": "ad93daef-0911-e511-80d0-005056956c1a", + "OrganizationName:en": "SURF bv", + "name:en": "Wiki EN", + "id": "1", + "_id": "1" + }, + { + "entityid": "https://network", + "type": "saml20_sp", + "url": "https://default-url-network.org", + "name:nl": "Network NL", + "institutionGuid": "ad93daef-0911-e511-80d0-005056956c1a", + "OrganizationName:en": "SURF bv", + "logo": "https://static.surfconext.nl/media/idp/surfconext.png", + "name:en": "Network EN", + "id": "2", + "_id": "2" + }, + { + "entityid": "https://storage", + "type": "saml20_sp", + "url": "https://default-url-storage.org", + "name:nl": "Storage NL", + "OrganizationName:en": "SURF bv", + "logo": "https://static.surfconext.nl/media/idp/surfconext.png", + "name:en": "Storage EN", + "id": "3", + "_id": "3" + }, + { + "entityid": "https://research", + "type": "saml20_sp", + "url": "https://default-url-research.org", + "name:nl": "Research NL", + "OrganizationName:en": "SURF bv", + "logo": "https://static.surfconext.nl/media/idp/surfconext.png", + "name:en": "Research EN", + "id": "4", + "_id": "4" + } + ] +} + + diff --git a/client/src/__tests__/utils/roles.json b/client/src/__tests__/utils/roles.json new file mode 100644 index 00000000..8b54568a --- /dev/null +++ b/client/src/__tests__/utils/roles.json @@ -0,0 +1,291 @@ +[ + { + "id": 3915, + "name": "Wiki", + "shortName": "wiki", + "description": "Wiki desc", + "defaultExpiryDays": 365, + "enforceEmailEquality": false, + "eduIDOnly": false, + "blockExpiryDate": false, + "overrideSettingsAllowed": false, + "teamsOrigin": false, + "identifier": "3e267427-e2cd-4b9e-9a78-9248bede1bc4", + "userRoleCount": 2, + "applicationUsages": [ + { + "id": 4574, + "landingPage": "http://landingpage.com", + "application": { + "id": 3901, + "manageId": "1", + "manageType": "SAML20_SP", + "landingPage": "http://landingpage.com" + } + } + ], + "auditable": { + "createdAt": 1721314647.000000000, + "createdBy": "ResourceCleaner" + }, + "applicationMaps": [ + { + "landingPage": "http://landingpage.com", + "entityid": "https://wiki", + "type": "saml20_sp", + "url": "https://default-url-wiki.org", + "name:nl": "Wiki NL", + "institutionGuid": "ad93daef-0911-e511-80d0-005056956c1a", + "OrganizationName:en": "SURF bv", + "name:en": "Wiki EN", + "id": "1", + "_id": "1" + } + ] + }, + { + "id": 3916, + "name": "Network", + "shortName": "network", + "description": "Network desc", + "defaultExpiryDays": 365, + "enforceEmailEquality": false, + "eduIDOnly": false, + "blockExpiryDate": false, + "overrideSettingsAllowed": false, + "teamsOrigin": false, + "identifier": "3cec7986-ca0c-4750-a6f3-86f2ff7fb82f", + "userRoleCount": 0, + "applicationUsages": [ + { + "id": 4575, + "landingPage": "http://landingpage.com", + "application": { + "id": 3902, + "manageId": "2", + "manageType": "SAML20_SP", + "landingPage": "http://landingpage.com" + } + } + ], + "auditable": { + "createdAt": 1721314647.000000000, + "createdBy": "ResourceCleaner" + }, + "applicationMaps": [ + { + "landingPage": "http://landingpage.com", + "entityid": "https://network", + "type": "saml20_sp", + "url": "https://default-url-network.org", + "name:nl": "Network NL", + "institutionGuid": "ad93daef-0911-e511-80d0-005056956c1a", + "OrganizationName:en": "SURF bv", + "logo": "https://static.surfconext.nl/media/idp/surfconext.png", + "name:en": "Network EN", + "id": "2", + "_id": "2" + } + ] + }, + { + "id": 3917, + "name": "Storage", + "shortName": "storage", + "description": "Storage desc", + "defaultExpiryDays": 365, + "enforceEmailEquality": false, + "eduIDOnly": false, + "blockExpiryDate": false, + "overrideSettingsAllowed": false, + "teamsOrigin": false, + "identifier": "9ac14a11-fd43-4f9c-abeb-8bf811f134df", + "userRoleCount": 1, + "applicationUsages": [ + { + "id": 4576, + "landingPage": "https://landingpage.com", + "application": { + "id": 3903, + "manageId": "3", + "manageType": "SAML20_SP", + "landingPage": "https://landingpage.com" + } + }, + { + "id": 4577, + "landingPage": "https://landingpage.com", + "application": { + "id": 3904, + "manageId": "6", + "manageType": "OIDC10_RP", + "landingPage": "https://landingpage.com" + } + } + ], + "auditable": { + "createdAt": 1721314647.000000000, + "createdBy": "ResourceCleaner" + }, + "applicationMaps": [ + { + "landingPage": "https://landingpage.com", + "entityid": "https://storage", + "type": "saml20_sp", + "url": "https://default-url-storage.org", + "name:nl": "Storage NL", + "OrganizationName:en": "SURF bv", + "logo": "https://static.surfconext.nl/media/idp/surfconext.png", + "name:en": "Storage EN", + "id": "3", + "_id": "3" + }, + { + "landingPage": "https://landingpage.com", + "entityid": "https://cloud", + "type": "oidc10_rp", + "url": "https://default-url-cloud.org", + "name:nl": "Cloud NL", + "OrganizationName:en": "SURF bv", + "logo": "https://static.surfconext.nl/media/idp/surfconext.png", + "name:en": "Cloud EN", + "id": "6", + "_id": "6" + } + ] + }, + { + "id": 3918, + "name": "Research", + "shortName": "research", + "description": "Research desc", + "defaultExpiryDays": 365, + "enforceEmailEquality": false, + "eduIDOnly": false, + "blockExpiryDate": false, + "overrideSettingsAllowed": false, + "teamsOrigin": false, + "identifier": "f2c99710-0cd1-4ea2-a20c-14da698a866b", + "userRoleCount": 1, + "applicationUsages": [ + { + "id": 4578, + "landingPage": "http://landingpage.com", + "application": { + "id": 3905, + "manageId": "4", + "manageType": "SAML20_SP", + "landingPage": "http://landingpage.com" + } + } + ], + "auditable": { + "createdAt": 1721314647.000000000, + "createdBy": "ResourceCleaner" + }, + "applicationMaps": [ + { + "landingPage": "http://landingpage.com", + "entityid": "https://research", + "type": "saml20_sp", + "url": "https://default-url-research.org", + "name:nl": "Research NL", + "OrganizationName:en": "SURF bv", + "logo": "https://static.surfconext.nl/media/idp/surfconext.png", + "name:en": "Research EN", + "id": "4", + "_id": "4" + } + ] + }, + { + "id": 3919, + "name": "Calendar", + "shortName": "calendar", + "description": "Calendar desc", + "defaultExpiryDays": 365, + "enforceEmailEquality": false, + "eduIDOnly": false, + "blockExpiryDate": false, + "overrideSettingsAllowed": false, + "teamsOrigin": false, + "identifier": "75e4e7b6-5f98-45bc-9d10-9795316e6be0", + "userRoleCount": 1, + "applicationUsages": [ + { + "id": 4579, + "landingPage": "http://landingpage.com", + "application": { + "id": 3906, + "manageId": "5", + "manageType": "OIDC10_RP", + "landingPage": "http://landingpage.com" + } + } + ], + "auditable": { + "createdAt": 1721314647.000000000, + "createdBy": "ResourceCleaner" + }, + "applicationMaps": [ + { + "landingPage": "http://landingpage.com", + "entityid": "https://calendar", + "type": "oidc10_rp", + "url": "https://default-url-calendar.org", + "name:nl": "Calendar NL", + "institutionGuid": "ad93daef-0911-e511-80d0-005056956c1a", + "OrganizationName:en": "SURF bv", + "logo": "https://static.surfconext.nl/media/idp/surfconext.png", + "name:en": "Calendar EN", + "id": "5", + "_id": "5" + } + ] + }, + { + "id": 3920, + "name": "Mail", + "shortName": "mail", + "description": "Mail desc", + "defaultExpiryDays": 365, + "enforceEmailEquality": false, + "eduIDOnly": false, + "blockExpiryDate": false, + "overrideSettingsAllowed": false, + "teamsOrigin": false, + "identifier": "a2e7d57c-652c-430c-98e6-d5ac7050d979", + "userRoleCount": 0, + "applicationUsages": [ + { + "id": 4580, + "landingPage": "http://landingpage.com", + "application": { + "id": 3906, + "manageId": "5", + "manageType": "OIDC10_RP", + "landingPage": "http://landingpage.com" + } + } + ], + "auditable": { + "createdAt": 1721314647.000000000, + "createdBy": "ResourceCleaner" + }, + "applicationMaps": [ + { + "landingPage": "http://landingpage.com", + "entityid": "https://calendar", + "type": "oidc10_rp", + "url": "https://default-url-calendar.org", + "name:nl": "Calendar NL", + "institutionGuid": "ad93daef-0911-e511-80d0-005056956c1a", + "OrganizationName:en": "SURF bv", + "logo": "https://static.surfconext.nl/media/idp/surfconext.png", + "name:en": "Calendar EN", + "id": "5", + "_id": "5" + } + ] + } +] diff --git a/client/src/__tests__/utils/userRoles.json b/client/src/__tests__/utils/userRoles.json new file mode 100644 index 00000000..61a51d1f --- /dev/null +++ b/client/src/__tests__/utils/userRoles.json @@ -0,0 +1,73 @@ +[ + { + "role": { + "name": "Wiki Another Role (3) - Calendar (1)", + "description": "Wiki Another Role (3) - Calendar (1)", + "applicationMaps": [ + { + "name:nl": "Wiki NL", + "OrganizationName:en": "SURF bv", + "name:en": "Wiki EN" + }, + { + "name:nl": "Calendar NL", + "OrganizationName:en": "SURF bv", + "name:en": "Calendar EN" + } + ] + } + }, + { + "role": { + "name": "Wiki 2 Role", + "description": "Wiki 2 Role", + "applicationMaps": [ + { + "name:nl": "Wiki NL", + "OrganizationName:en": "SURF bv", + "name:en": "Wiki EN" + } + ] + }, + "authority": "INVITER" + }, + { + "role": { + "name": "Research ABC", + "description": "Research ABC Description", + "applicationMaps": [ + { + "name:nl": "Research NL", + "OrganizationName:en": "SURF bv", + "name:en": "Research EN" + } + ] + } + }, + { + "role": { + "name": "Wiki 1 Role", + "description": "Wiki 1 Role", + "applicationMaps": [ + { + "name:nl": "Wiki NL", + "OrganizationName:en": "SURF bv", + "name:en": "Wiki EN" + } + ] + } + }, + { + "role": { + "name": "Research XYZ", + "description": "Research XYZ Description", + "applicationMaps": [ + { + "name:nl": "Research NL", + "OrganizationName:en": "SURF bv", + "name:en": "Research EN" + } + ] + } + } +] \ No newline at end of file diff --git a/client/src/utils/Manage.js b/client/src/utils/Manage.js index 1c8f30cd..5e06d67c 100644 --- a/client/src/utils/Manage.js +++ b/client/src/utils/Manage.js @@ -15,6 +15,14 @@ export const singleProviderToOption = (provider, locale) => { }; } +export const applicationName = (app, locale) => { + const name = app[`name:${locale}`] || app["name:en"] + const organizationName = app[`OrganizationName:${locale}`] || app["OrganizationName:en"]; + const organisationValue = isEmpty(organizationName) ? "" : ` (${organizationName})`; + return `${name}${organisationValue}`; +} + + export const roleName = (app, locale) => { const name = app[`name:${locale}`] || app["name:en"] const organizationName = app[`OrganizationName:${locale}`] || app["OrganizationName:en"]; @@ -63,18 +71,6 @@ export const deriveRemoteApplicationAttributes = (application, locale) => { } } -export const providerInfo = provider => { - if (isEmpty(provider)) { - return { - "OrganizationName:en": "", - provisioning_type: "", - "name:en": "Unknown in Manage", - unknownInManage: true - } - } - return provider; -} - export const mergeProvidersProvisioningsRoles = (providers, provisionings, roles, locale = "en") => { /** * We want the following structure for the providers, provisionings and roles: @@ -120,3 +116,23 @@ export const mergeProvidersProvisioningsRoles = (providers, provisionings, roles })) } +export const reduceApplicationFromUserRoles = (userRoles, locale) => { + //First we need the roleName, roleDescription and applicationName for each userRole.role.applicationMaps + userRoles.forEach(userRole => userRole.role.applicationMaps + .forEach(app => { + app.applicationName = applicationName(app, locale); + app.roleName = userRole.role.name; + app.roleDescription = userRole.role.description; + })); + //Now get all applicationMaps flattened and return sorted + const applicationMaps = userRoles + .map(userRole => userRole.role.applicationMaps) + .flat() + //Applications that do not exist any longer in Manage, are marked as unknown server side + .filter(applicationMap => !applicationMap.unknown); + return applicationMaps.sort((app1, app2) => + app1.applicationName.localeCompare(app2.applicationName) || app1.roleName.localeCompare(app2.roleName) + ); +} + + diff --git a/welcome/src/utils/Manage.js b/welcome/src/utils/Manage.js index 442f5e5d..11d2b69b 100644 --- a/welcome/src/utils/Manage.js +++ b/welcome/src/utils/Manage.js @@ -19,7 +19,7 @@ export const applicationName = (app, locale) => { } export const reduceApplicationFromUserRoles = (userRoles, locale) => { - //First we need the roleName, roleDescription and applicationName and for each userRole.role.applicationMaps + //First we need the roleName, roleDescription and applicationName for each userRole.role.applicationMaps userRoles.forEach(userRole => userRole.role.applicationMaps .forEach(app => { app.applicationName = applicationName(app, locale); @@ -30,6 +30,7 @@ export const reduceApplicationFromUserRoles = (userRoles, locale) => { const applicationMaps = userRoles .map(userRole => userRole.role.applicationMaps) .flat() + //Applications that do not exist any longer in Manage, are marked as unknown server side .filter(applicationMap => !applicationMap.unknown); return applicationMaps.sort((app1, app2) => app1.applicationName.localeCompare(app2.applicationName) || app1.roleName.localeCompare(app2.roleName)