2022-09-21 17:58:47 +02:00
|
|
|
export const buildGroupsEndpoints = API => {
|
|
|
|
// underlying functionality of adding/removing users/apps to groups
|
|
|
|
async function updateGroupResource(groupId, resource, operation, ids) {
|
|
|
|
if (!Array.isArray(ids)) {
|
|
|
|
ids = [ids]
|
|
|
|
}
|
2022-06-22 14:55:31 +02:00
|
|
|
return await API.post({
|
2022-09-21 17:58:47 +02:00
|
|
|
url: `/api/global/groups/${groupId}/${resource}`,
|
|
|
|
body: {
|
|
|
|
[operation]: ids,
|
|
|
|
},
|
2022-06-22 14:55:31 +02:00
|
|
|
})
|
2022-09-21 17:58:47 +02:00
|
|
|
}
|
2022-06-15 17:51:30 +02:00
|
|
|
|
2022-09-21 17:58:47 +02:00
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* Creates a user group.
|
|
|
|
* @param group the new group to create
|
|
|
|
*/
|
|
|
|
saveGroup: async group => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/global/groups",
|
|
|
|
body: group,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Gets all the user groups
|
|
|
|
*/
|
|
|
|
getGroups: async () => {
|
|
|
|
return await API.get({
|
|
|
|
url: "/api/global/groups",
|
|
|
|
})
|
|
|
|
},
|
2022-06-22 14:55:31 +02:00
|
|
|
|
2022-09-21 17:58:47 +02:00
|
|
|
/**
|
|
|
|
* Gets a group by ID
|
|
|
|
*/
|
|
|
|
getGroup: async id => {
|
|
|
|
return await API.get({
|
|
|
|
url: `/api/global/groups/${id}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a user group
|
|
|
|
* @param id the id of the config to delete
|
|
|
|
* @param rev the revision of the config to delete
|
|
|
|
*/
|
|
|
|
deleteGroup: async ({ id, rev }) => {
|
|
|
|
return await API.delete({
|
|
|
|
url: `/api/global/groups/${id}/${rev}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2023-05-04 18:38:04 +02:00
|
|
|
/**
|
|
|
|
* Gets a group users by the group id
|
|
|
|
*/
|
2023-05-10 15:19:45 +02:00
|
|
|
getGroupUsers: async ({ id, bookmark, emailSearch }) => {
|
2023-05-04 18:38:04 +02:00
|
|
|
let url = `/api/global/groups/${id}/users?`
|
|
|
|
if (bookmark) {
|
2023-05-08 14:54:43 +02:00
|
|
|
url += `bookmark=${bookmark}&`
|
|
|
|
}
|
2023-05-10 15:19:45 +02:00
|
|
|
if (emailSearch) {
|
|
|
|
url += `emailSearch=${emailSearch}&`
|
2023-05-04 18:38:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return await API.get({
|
|
|
|
url,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2022-09-21 17:58:47 +02:00
|
|
|
/**
|
|
|
|
* Adds users to a group
|
|
|
|
* @param groupId The group to update
|
|
|
|
* @param userIds The user IDs to be added
|
|
|
|
*/
|
|
|
|
addUsersToGroup: async (groupId, userIds) => {
|
|
|
|
return updateGroupResource(groupId, "users", "add", userIds)
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes users from a group
|
|
|
|
* @param groupId The group to update
|
|
|
|
* @param userIds The user IDs to be removed
|
|
|
|
*/
|
|
|
|
removeUsersFromGroup: async (groupId, userIds) => {
|
|
|
|
return updateGroupResource(groupId, "users", "remove", userIds)
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds apps to a group
|
|
|
|
* @param groupId The group to update
|
2022-09-21 23:58:06 +02:00
|
|
|
* @param appArray Array of objects, containing the appId and roleId to be added
|
2022-09-21 17:58:47 +02:00
|
|
|
*/
|
2022-09-21 23:58:06 +02:00
|
|
|
addAppsToGroup: async (groupId, appArray) => {
|
|
|
|
return updateGroupResource(groupId, "apps", "add", appArray)
|
2022-09-21 17:58:47 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes apps from a group
|
|
|
|
* @param groupId The group to update
|
2022-09-21 23:58:06 +02:00
|
|
|
* @param appArray Array of objects, containing the appId to be removed
|
2022-09-21 17:58:47 +02:00
|
|
|
*/
|
2022-09-21 23:58:06 +02:00
|
|
|
removeAppsFromGroup: async (groupId, appArray) => {
|
|
|
|
return updateGroupResource(groupId, "apps", "remove", appArray)
|
2022-09-21 17:58:47 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|