From 21706ac4a6e248f7cd2361f84094f2106f757102 Mon Sep 17 00:00:00 2001 From: Karel Hala Date: Wed, 6 Nov 2024 09:04:32 +0100 Subject: [PATCH] feat(common-auth-model): add mocked requests --- src/helpers/user/user-helper.js | 15 ++++++++++++--- src/redux/actions/user-actions.js | 30 ++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/helpers/user/user-helper.js b/src/helpers/user/user-helper.js index d3d4f706b..e81716d24 100644 --- a/src/helpers/user/user-helper.js +++ b/src/helpers/user/user-helper.js @@ -55,7 +55,10 @@ function handleError(error, reject) { reject(new Error(error.message)); } -export async function addUsers(usersData = { emails: [], isAdmin: undefined }) { +export async function addUsers(usersData = { emails: [], isAdmin: undefined, message: undefined }, isCommonAuth = false) { + if (isCommonAuth) { + return Promise.resolve(); + } const token = await insights.chrome.auth.getToken(); const requestOpts = { method: 'POST', @@ -79,7 +82,10 @@ export async function addUsers(usersData = { emails: [], isAdmin: undefined }) { return promise; } -export async function updateUserIsOrgAdminStatus(user) { +export async function updateUserIsOrgAdminStatus(user, isCommonAuth = false) { + if (isCommonAuth) { + return Promise.resolve(); + } const token = await insights.chrome.auth.getToken(); let requestOpts = { method: 'PUT', @@ -101,7 +107,10 @@ export async function updateUserIsOrgAdminStatus(user) { return promise; } -export async function updateUsers(users) { +export async function updateUsers(users, isCommonAuth = false) { + if (isCommonAuth) { + return Promise.resolve(); + } const token = await insights.chrome.auth.getToken(); let requestOpts = { method: 'PUT', diff --git a/src/redux/actions/user-actions.js b/src/redux/actions/user-actions.js index 4488a444d..050b265e4 100644 --- a/src/redux/actions/user-actions.js +++ b/src/redux/actions/user-actions.js @@ -5,12 +5,18 @@ import messages from '../../Messages'; import providerMessages from '../../locales/data.json'; import { locale } from '../../AppEntry'; -export const addUsers = (usersData) => { +/** + * An action creator function to invite new users to CRC. + * @param { emails: string[], isOrgAdmin: boolean, message: string } usersData data to be sent to server. + * @param {boolean} isCommonAuth feature flag to indicate if common auth is used or fedramp branch. + * @returns action to be dispatched + */ +export const addUsers = (usersData, isCommonAuth) => { const cache = createIntlCache(); const intl = createIntl({ locale, messages: providerMessages }, cache); return { type: ActionTypes.ADD_USERS, - payload: UserHelper.addUsers(usersData), + payload: UserHelper.addUsers(usersData, isCommonAuth), meta: { notifications: { rejected: (payload) => { @@ -36,12 +42,18 @@ export const addUsers = (usersData) => { }; }; -export const updateUserIsOrgAdminStatus = (user) => { +/** + * An action creator function to promote/demote an user to be org. admin in CRC. + * @param {id: UUID, is_org_admin: boolean} user to be promoted to organization administrator. + * @param {boolean} isCommonAuth feature flag to indicate if common auth is used or fedramp branch. + * @returns action to be dispatched + */ +export const updateUserIsOrgAdminStatus = (user, isCommonAuth) => { const cache = createIntlCache(); const intl = createIntl({ locale, messages: providerMessages }, cache); return { type: ActionTypes.UPDATE_USER_IS_ORG_ADMIN_STATUS, - payload: UserHelper.updateUserIsOrgAdminStatus(user), + payload: UserHelper.updateUserIsOrgAdminStatus(user, isCommonAuth), meta: { notifications: { fulfilled: { @@ -63,12 +75,18 @@ export const updateUserIsOrgAdminStatus = (user) => { }; }; -export const updateUsers = (userList) => { +/** + * An action creator function to change user status to active/inactive in CRC. + * @param {User} userList list of users to change their status. + * @param {boolean} isCommonAuth feature flag to indicate if common auth is used or fedramp branch. + * @returns action to be dispatched + */ +export const updateUsers = (userList, isCommonAuth) => { const cache = createIntlCache(); const intl = createIntl({ locale, messages: providerMessages }, cache); return { type: ActionTypes.UPDATE_USERS, - payload: UserHelper.updateUsers(userList), + payload: UserHelper.updateUsers(userList, isCommonAuth), meta: { notifications: { fulfilled: {