2022-10-11 13:29:23 +00:00
|
|
|
import { ensureItemDoesntExist, ensureItemExists } from './ensure';
|
|
|
|
import { findFromList, searchSomething } from './search';
|
|
|
|
import { API } from './types';
|
|
|
|
|
2023-02-15 01:52:11 +00:00
|
|
|
export function ensureHumanIsNotOrgMember(api: API, username: string) {
|
2022-10-11 13:29:23 +00:00
|
|
|
return ensureItemDoesntExist(
|
|
|
|
api,
|
|
|
|
`${api.mgmtBaseURL}/orgs/me/members/_search`,
|
|
|
|
(member: any) => (<string>member.preferredLoginName).startsWith(username),
|
|
|
|
(member) => `${api.mgmtBaseURL}/orgs/me/members/${member.userId}`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-15 01:52:11 +00:00
|
|
|
export function ensureHumanIsOrgMember(api: API, username: string, roles: string[]) {
|
2022-10-11 13:29:23 +00:00
|
|
|
return searchSomething(
|
|
|
|
api,
|
|
|
|
`${api.mgmtBaseURL}/users/_search`,
|
|
|
|
'POST',
|
|
|
|
findFromList((user) => {
|
|
|
|
return user.userName == username;
|
|
|
|
}),
|
|
|
|
).then((user) => {
|
|
|
|
return ensureItemExists(
|
|
|
|
api,
|
|
|
|
`${api.mgmtBaseURL}/orgs/me/members/_search`,
|
|
|
|
(member: any) => member.userId == user.entity.id,
|
|
|
|
`${api.mgmtBaseURL}/orgs/me/members`,
|
|
|
|
{
|
|
|
|
userId: user.entity.id,
|
|
|
|
roles: roles,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ensureHumanIsNotProjectMember(
|
|
|
|
api: API,
|
|
|
|
projectId: string,
|
|
|
|
username: string,
|
2023-02-15 01:52:11 +00:00
|
|
|
grantId?: string,
|
|
|
|
): Cypress.Chainable<string> {
|
2022-10-11 13:29:23 +00:00
|
|
|
return ensureItemDoesntExist(
|
|
|
|
api,
|
|
|
|
`${api.mgmtBaseURL}/projects/${projectId}/${grantId ? `grants/${grantId}/` : ''}members/_search`,
|
|
|
|
(member: any) => (<string>member.preferredLoginName).startsWith(username),
|
2023-02-15 01:52:11 +00:00
|
|
|
(member) => `${api.mgmtBaseURL}/projects/${projectId}/${grantId ? `grants/${grantId}/` : ''}members/${member.userId}`,
|
2022-10-11 13:29:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ensureHumanIsProjectMember(
|
|
|
|
api: API,
|
|
|
|
projectId: string,
|
|
|
|
username: string,
|
|
|
|
roles: string[],
|
2023-02-15 01:52:11 +00:00
|
|
|
grantId?: string,
|
|
|
|
): Cypress.Chainable<string> {
|
2022-10-11 13:29:23 +00:00
|
|
|
return searchSomething(
|
|
|
|
api,
|
|
|
|
`${api.mgmtBaseURL}/users/_search`,
|
|
|
|
'POST',
|
|
|
|
findFromList((user) => {
|
|
|
|
return user.userName == username;
|
|
|
|
}),
|
|
|
|
).then((user) => {
|
|
|
|
return ensureItemExists(
|
|
|
|
api,
|
|
|
|
`${api.mgmtBaseURL}/projects/${projectId}/${grantId ? `grants/${grantId}/` : ''}members/_search`,
|
|
|
|
(member: any) => member.userId == user.entity.id,
|
|
|
|
`${api.mgmtBaseURL}/projects/${projectId}/${grantId ? `grants/${grantId}/` : ''}members`,
|
|
|
|
{
|
|
|
|
userId: user.entity.id,
|
|
|
|
roles: roles,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|