diff --git a/openApi/dashboard-api-docs.json b/openApi/dashboard-api-docs.json index 864d8a8e..926b86c6 100644 --- a/openApi/dashboard-api-docs.json +++ b/openApi/dashboard-api-docs.json @@ -3192,6 +3192,10 @@ "type" : "string" } }, + "role" : { + "type" : "string", + "description" : "User's role, available value: [MANAGER, DELEGATE, SUBDELEGATE, OPERATOR, ADMIN_EA]" + }, "surname" : { "type" : "string", "description" : "User's surname" @@ -3728,7 +3732,7 @@ }, "role" : { "type" : "string", - "description" : "User's role", + "description" : "User's role, available value: [MANAGER, DELEGATE, SUBDELEGATE, OPERATOR, ADMIN_EA]", "enum" : [ "ADMIN", "ADMIN_EA", "LIMITED" ] }, "status" : { @@ -3986,7 +3990,7 @@ }, "selcRole" : { "type" : "string", - "description" : "User's role", + "description" : "User's role, available value: [MANAGER, DELEGATE, SUBDELEGATE, OPERATOR, ADMIN_EA]", "enum" : [ "ADMIN", "ADMIN_EA", "LIMITED" ] }, "status" : { @@ -4070,7 +4074,7 @@ }, "role" : { "type" : "string", - "description" : "User's role", + "description" : "User's role, available value: [MANAGER, DELEGATE, SUBDELEGATE, OPERATOR, ADMIN_EA]", "enum" : [ "ADMIN", "ADMIN_EA", "LIMITED" ] }, "status" : { @@ -4495,6 +4499,10 @@ "items" : { "type" : "string" } + }, + "role" : { + "type" : "string", + "description" : "User's role, available value: [MANAGER, DELEGATE, SUBDELEGATE, OPERATOR, ADMIN_EA]" } } }, diff --git a/openApi/generated-dashboard/dashboard-swagger20.json b/openApi/generated-dashboard/dashboard-swagger20.json index 347dbedd..f8346b33 100644 --- a/openApi/generated-dashboard/dashboard-swagger20.json +++ b/openApi/generated-dashboard/dashboard-swagger20.json @@ -2734,6 +2734,10 @@ "type": "array", "uniqueItems": true }, + "role": { + "description": "User's role, available value: [MANAGER, DELEGATE, SUBDELEGATE, OPERATOR, ADMIN_EA]", + "type": "string" + }, "surname": { "description": "User's surname", "type": "string" @@ -3308,7 +3312,7 @@ "type": "array" }, "role": { - "description": "User's role", + "description": "User's role, available value: [MANAGER, DELEGATE, SUBDELEGATE, OPERATOR, ADMIN_EA]", "enum": [ "ADMIN", "ADMIN_EA", @@ -3596,7 +3600,7 @@ "type": "string" }, "selcRole": { - "description": "User's role", + "description": "User's role, available value: [MANAGER, DELEGATE, SUBDELEGATE, OPERATOR, ADMIN_EA]", "enum": [ "ADMIN", "ADMIN_EA", @@ -3688,7 +3692,7 @@ "description": "Authorized user product" }, "role": { - "description": "User's role", + "description": "User's role, available value: [MANAGER, DELEGATE, SUBDELEGATE, OPERATOR, ADMIN_EA]", "enum": [ "ADMIN", "ADMIN_EA", @@ -4150,6 +4154,10 @@ }, "type": "array", "uniqueItems": true + }, + "role": { + "description": "User's role, available value: [MANAGER, DELEGATE, SUBDELEGATE, OPERATOR, ADMIN_EA]", + "type": "string" } }, "title": "UserProductRoles", diff --git a/src/api/DashboardApiClient.ts b/src/api/DashboardApiClient.ts index 8a77c146..9115e5db 100644 --- a/src/api/DashboardApiClient.ts +++ b/src/api/DashboardApiClient.ts @@ -111,9 +111,10 @@ export const DashboardApi = { return extractResponse(result, 200, onRedirectToLogin); }, - getProductRoles: async (productId: string): Promise> => { + getProductRoles: async (productId: string, institutionType: string): Promise> => { const result = await apiClient.getProductRolesUsingGET({ productId, + institutionType, }); return extractResponse(result, 200, onRedirectToLogin); }, diff --git a/src/api/__mocks__/DashboardApiClient.ts b/src/api/__mocks__/DashboardApiClient.ts index 5825fb43..d25a2d07 100644 --- a/src/api/__mocks__/DashboardApiClient.ts +++ b/src/api/__mocks__/DashboardApiClient.ts @@ -311,7 +311,7 @@ export const DashboardApi = { getBillingToken: async (_partyId: string, _environment?: string, _lang?: string): Promise => new Promise((resolve) => resolve('DUMMYTOKEN')), - getProductRoles: async (_productId: string): Promise> => + getProductRoles: async (_productId: string, _institutionType: string): Promise> => new Promise((resolve) => resolve(mockedProductRoles)), getProductBrokers: async ( diff --git a/src/decorators/withSelectedPartyProduct.tsx b/src/decorators/withSelectedPartyProduct.tsx index ae022581..b72457d6 100644 --- a/src/decorators/withSelectedPartyProduct.tsx +++ b/src/decorators/withSelectedPartyProduct.tsx @@ -1,14 +1,17 @@ -import { useEffect } from 'react'; -import { useHistory, useParams } from 'react-router'; import useErrorDispatcher from '@pagopa/selfcare-common-frontend/lib/hooks/useErrorDispatcher'; import useLoading from '@pagopa/selfcare-common-frontend/lib/hooks/useLoading'; import { resolvePathVariables } from '@pagopa/selfcare-common-frontend/lib/utils/routes-utils'; +import { useEffect } from 'react'; +import { useHistory, useParams } from 'react-router'; +import { useProductRoles } from '../hooks/useProductRoles'; import { useSelectedPartyProduct } from '../hooks/useSelectedPartyProduct'; +import { Party } from '../model/Party'; import { Product } from '../model/Product'; +import { buildEmptyProductRolesLists, ProductRolesLists } from '../model/ProductRole'; +import { useAppSelector } from '../redux/hooks'; +import { partiesSelectors } from '../redux/slices/partiesSlice'; import ROUTES from '../routes'; -import { useProductRoles } from '../hooks/useProductRoles'; import { LOADING_TASK_FETCH_PRODUCT_ROLES } from '../utils/constants'; -import { buildEmptyProductRolesLists, ProductRolesLists } from '../model/ProductRole'; type ProductUrlParams = { partyId: string; @@ -29,6 +32,7 @@ export default function withSelectedPartyProduct(); const history = useHistory(); const selectedPartyProduct = useSelectedPartyProduct(productId, props.products); + const party = useAppSelector(partiesSelectors.selectPartySelected); const addError = useErrorDispatcher(); useEffect(() => { @@ -54,7 +58,7 @@ export default function withSelectedPartyProduct void): Promise => { setLoading_fetchProductRoles(true); - return fetchSelectedProductRoles(selectedPartyProduct as Product) + return fetchSelectedProductRoles({product:selectedPartyProduct as Product, party: party as Party}) .catch((reason) => { addError({ id: `FETCH_PRODUCT_ROLES_ERROR_${selectedPartyProduct?.id}`, diff --git a/src/hooks/__tests__/useProductRoles.test.tsx b/src/hooks/__tests__/useProductRoles.test.tsx index dab409c7..0b99d91a 100644 --- a/src/hooks/__tests__/useProductRoles.test.tsx +++ b/src/hooks/__tests__/useProductRoles.test.tsx @@ -1,14 +1,14 @@ -import { appStateActions } from '@pagopa/selfcare-common-frontend/lib/redux/slices/appStateSlice'; import { render, screen, waitFor } from '@testing-library/react'; +import { useEffect, useState } from 'react'; import { Provider } from 'react-redux'; +import withProductsRolesMap from '../../decorators/withProductsRolesMap'; import { Product } from '../../model/Product'; +import { ProductRole } from '../../model/ProductRole'; import { partiesActions } from '../../redux/slices/partiesSlice'; import { createStore } from '../../redux/store'; +import { mockedParties } from '../../services/__mocks__/partyService'; import { mockedPartyProducts } from '../../services/__mocks__/productService'; import { useProductRoles } from '../useProductRoles'; -import withProductsRolesMap from '../../decorators/withProductsRolesMap'; -import { useEffect, useState } from 'react'; -import { ProductRole } from '../../model/ProductRole'; jest.mock('../../services/productService'); @@ -19,7 +19,7 @@ const renderApp = (product: Product, injectedStore?: ReturnType { - fetchProductRoles(product) + fetchProductRoles({ product, party: mockedParties[0] }) .then((r) => setProductRoles(r.list)) .catch((r) => console.error(r)); }, []); diff --git a/src/hooks/useProductRoles.tsx b/src/hooks/useProductRoles.tsx index c4795f1f..08f1890a 100644 --- a/src/hooks/useProductRoles.tsx +++ b/src/hooks/useProductRoles.tsx @@ -1,4 +1,5 @@ import { useReduxCachedValueParametricRetrieverTranscoded } from '@pagopa/selfcare-common-frontend/lib/hooks/useReduxCachedValue'; +import { Party } from '../model/Party'; import { Product } from '../model/Product'; import { productRoles2ProductRolesList, @@ -8,14 +9,15 @@ import { import { partiesActions, partiesSelectors } from '../redux/slices/partiesSlice'; import { fetchProductRoles } from '../services/productService'; -export const useProductRoles = (): ((product: Product) => Promise) => +export const useProductRoles = (): ((args: { product: Product; party: Party }) => Promise) => useReduxCachedValueParametricRetrieverTranscoded( 'PRODUCT_ROLES', - (product: Product) => - fetchProductRoles(product).then((roles) => productRoles2ProductRolesList(roles)), + ({ product, party }: { product: Product; party: Party }) => + fetchProductRoles(product, party).then((roles) => productRoles2ProductRolesList(roles)), partiesSelectors.selectPartySelectedProductsRolesMap, - (roles: ProductRolesLists, product: Product) => + (roles: ProductRolesLists, { product }: { product: Product }) => partiesActions.addPartySelectedProductRoles({ [product.id]: roles }), - (productsRolesMap: ProductsRolesMap, product: Product) => productsRolesMap[product.id], - (productsRolesMap: ProductsRolesMap, product: Product) => !productsRolesMap[product.id] + (productsRolesMap: ProductsRolesMap, { product }: { product: Product }) => productsRolesMap[product.id], + (productsRolesMap: ProductsRolesMap, { product }: { product: Product }) => !productsRolesMap[product.id] ); + diff --git a/src/hooks/useProductsRolesMap.tsx b/src/hooks/useProductsRolesMap.tsx index d3a2c5e8..3510c1e0 100644 --- a/src/hooks/useProductsRolesMap.tsx +++ b/src/hooks/useProductsRolesMap.tsx @@ -1,8 +1,9 @@ import useReduxCachedValue from '@pagopa/selfcare-common-frontend/lib/hooks/useReduxCachedValue'; import { useMemo } from 'react'; +import { Party } from '../model/Party'; import { - ProductRolesLists, productRoles2ProductRolesList, + ProductRolesLists, ProductsRolesMap, } from '../model/ProductRole'; import { useAppSelector } from '../redux/hooks'; @@ -33,7 +34,7 @@ export const useProductsRolesMap = (): (() => Promise) => { const promises: Array> = activeProducts .filter((p) => !productsRolesMap[p.id]) .map((p) => - fetchProductRoles(p).then((roles) => [p.id, productRoles2ProductRolesList(roles)]) + fetchProductRoles(p, party as Party).then((roles) => [p.id, productRoles2ProductRolesList(roles)]) ); const fetched: Array<[string, ProductRolesLists]> = await Promise.all(promises); diff --git a/src/pages/dashboard/components/dashboardSideMenu/__test__/DashboardSideMenu.test.tsx b/src/pages/dashboard/components/dashboardSideMenu/__test__/DashboardSideMenu.test.tsx index 3f4ef92c..ea4e1e10 100644 --- a/src/pages/dashboard/components/dashboardSideMenu/__test__/DashboardSideMenu.test.tsx +++ b/src/pages/dashboard/components/dashboardSideMenu/__test__/DashboardSideMenu.test.tsx @@ -47,7 +47,6 @@ test('Test: render with props false', async () => { test('Test: The techpartner has not been delegated by any body, he will see the menu section and will be able to access it in empty state', async () => { const institutionPT = mockedParties.find((party) => party.description === 'Maggioli S.p.A.')!; - console.log('institutionPT', institutionPT); const { history } = renderWithProviders( new Promise((resolve) => resolve(mockedPartyProducts)); -export const fetchProductRoles = (product: Product): Promise> => { +export const fetchProductRoles = (product: Product, _party: Party): Promise> => { const out = mockedProductRoles.map((r) => Object.assign( {}, diff --git a/src/services/__tests__/productService.test.ts b/src/services/__tests__/productService.test.ts index 47432401..0f971cef 100644 --- a/src/services/__tests__/productService.test.ts +++ b/src/services/__tests__/productService.test.ts @@ -2,11 +2,12 @@ import { DashboardApi } from '../../api/DashboardApiClient'; import { StatusEnum } from '../../api/generated/b4f-dashboard/ProductsResource'; import { Product, productResource2Product } from '../../model/Product'; +import { mockedParties } from '../__mocks__/partyService'; import { - fetchProducts, - fetchProductRoles + fetchProductRoles, + fetchProducts } from '../productService'; -import { mockedPartyProducts, fetchProductRoles as fetchProductRolesMocked } from './../__mocks__/productService'; +import { fetchProductRoles as fetchProductRolesMocked, mockedPartyProducts } from './../__mocks__/productService'; // Mock the DashboardApi methods jest.mock('../../api/DashboardApiClient', () => ({ @@ -108,8 +109,8 @@ describe('productService tests', () => { ]; (fetchProductRolesMocked as jest.Mock).mockResolvedValue(mockRoles); - const result = await fetchProductRoles(mockProduct); - expect(fetchProductRolesMocked).toHaveBeenCalledWith(mockProduct); + const result = await fetchProductRoles(mockProduct, mockedParties[0]); + expect(fetchProductRolesMocked).toHaveBeenCalledWith(mockProduct, mockedParties[0]); expect(result).toEqual(mockRoles); }); @@ -142,8 +143,8 @@ describe('productService tests', () => { description: 'Admin Role Description' } ]; - const result = await fetchProductRoles(mockProduct); - expect(DashboardApi.getProductRoles).toHaveBeenCalledWith(mockProduct.id); + const result = await fetchProductRoles(mockProduct, mockedParties[0]); + expect(DashboardApi.getProductRoles).toHaveBeenCalledWith(mockProduct.id, mockedParties[0].institutionType); expect(result).toEqual(expectedRoles); }); }); diff --git a/src/services/productService.ts b/src/services/productService.ts index 48e21e05..5cf6c6f6 100644 --- a/src/services/productService.ts +++ b/src/services/productService.ts @@ -1,9 +1,10 @@ import { DashboardApi } from '../api/DashboardApiClient'; +import { Party } from '../model/Party'; import { Product, productResource2Product } from '../model/Product'; import { ProductRole } from '../model/ProductRole'; import { - mockedPartyProducts, fetchProductRoles as fetchProductRolesMocked, + mockedPartyProducts, } from './__mocks__/productService'; export const fetchProducts = (): Promise> => { @@ -17,12 +18,12 @@ export const fetchProducts = (): Promise> => { } }; -export const fetchProductRoles = (product: Product): Promise> => { +export const fetchProductRoles = (product: Product, party: Party): Promise> => { /* istanbul ignore if */ if (process.env.REACT_APP_API_MOCK_PRODUCTS === 'true') { - return fetchProductRolesMocked(product); + return fetchProductRolesMocked(product, party); } else { - return DashboardApi.getProductRoles(product.id) + return DashboardApi.getProductRoles(product.id ,party.institutionType ?? '') .then((roles) => roles ?.map((pr) => pr?.productRoles?.map((r) => ({