Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(common-auth-model): add mocked requests #1695

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/helpers/user/user-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
30 changes: 24 additions & 6 deletions src/redux/actions/user-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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: {
Expand All @@ -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: {
Expand Down