diff --git a/src/api.js b/src/api.js index 9e380b3..0ea8dc9 100644 --- a/src/api.js +++ b/src/api.js @@ -1,6 +1,31 @@ import axios from "@nextcloud/axios" import { generateUrl } from "@nextcloud/router" +/** + * @typedef {number} PrincipalType + **/ + +/** + * @enum {PrincipalType} + */ +var PrincipalTypes = { + USER: 1, + GROUP: 2, + ROLE: 3, +} + +/** + * @typedef {number} ResourceMemberPermissionLevel + **/ + +/** + * @enum {ResourceMemberPermissionLevel} + */ +var ResourceMemberPermissionLevels = { + MEMBER: 1, + MANAGER: 2, +} + /** * @typedef {{ * id: number @@ -18,24 +43,33 @@ import { generateUrl } from "@nextcloud/router" * @typedef {(FolderResource)} Resource * * @typedef {{ - * type: number, + * type: PrincipalType, * id: string, * }} Principal * * @typedef {{ * id: number * resourceId: number - * permissionLevel: number + * permissionLevel: ResourceMemberPermissionLevel * principal: Principal, * createdTimestamp: number, * lastUpdatedTimestamp: number, * }} ResourceMember * + * @typedef {{ + * id: number, + * friendlyName: string, + * membersGroup: string, + * }} Organization + * */ axios.defaults.baseURL = generateUrl("/apps/organization_folders") export default { + PrincipalTypes, + ResourceMemberPermissionLevels, + /** * * @param {number|string} resourceId Resource id @@ -43,7 +77,7 @@ export default { * @return {Promise} */ getResource(resourceId, include = "model") { - return axios.get(`/resources/${resourceId}`, { params: { include } }).then((res) => res.data) + return axios.get(`/resources/${resourceId}`, { params: { include } }).then((res) => res.data); }, /** @@ -58,16 +92,79 @@ export default { * }} updateResourceDto UpdateResourceDto * @return {Promise} */ - updateResource(resourceId, updateGroupDto) { - return axios.put(`/resources/${resourceId}`, { ...updateGroupDto }).then((res) => res.data) + updateResource(resourceId, updateGroupDto, include = "model") { + return axios.put(`/resources/${resourceId}`, { ...updateGroupDto, include }).then((res) => res.data); }, /** - * * @param {number|string} resourceId Resource id * @return {Promise>} */ getResourceMembers(resourceId) { - return axios.get(`/resources/${resourceId}/members`, {}).then((res) => res.data) + return axios.get(`/resources/${resourceId}/members`, {}).then((res) => res.data); }, + + /** + * @param {number|string} resourceId Resource id + * @param {{ + * permissionLevel: ResourceMemberPermissionLevel + * principalType: PrincipalType + * principalId: string + * }} createResourceMemberDto CreateResourceMemberDto + * @return {Promise} + */ + createResourceMember(resourceId, createResourceMemberDto) { + return axios.post(`/resources/${resourceId}/members`, { ...createResourceMemberDto }).then((res) => res.data); + }, + + /** + * @param {number|string} resourceMemberId Resource member id + * @param {{ + * permissionLevel: ResourceMemberPermissionLevel + * }} createResourceMemberDto CreateResourceMemberDto + * @return {Promise} + */ + updateResourceMember(resourceId, createResourceMemberDto) { + return axios.post(`/resources/${resourceId}/members`, { ...createResourceMemberDto }).then((res) => res.data); + }, + + /** + * @return {Promise>} + */ + getOrganizationProviders() { + return axios.get(`/organizationProviders`, {}).then((res) => res.data); + }, + + /** + * @param {string} organizationProviderId organization provider id + * @param {int} id organization id + * @return {Promise} + */ + getOrganization(organizationProviderId, id) { + return axios.get(`/organizationProviders/${organizationProviderId}/organizations/${id}`, { }).then((res) => res.data); + }, + + /** + * @param {string} organizationProviderId organization provider id + * @param {number|undefined} parentOrganizationId parent organization id (null if top level organizations) + * @return {Promise>} + */ + getSubOrganizations(organizationProviderId, parentOrganizationId) { + if(parentOrganizationId) { + return axios.get(`/organizationProviders/${organizationProviderId}/organizations/${parentOrganizationId}/subOrganizations`, { }).then((res) => res.data); + } else { + return axios.get(`/organizationProviders/${organizationProviderId}/subOrganizations`, { }).then((res) => res.data); + } + + }, + + /** + * @param {string} organizationProviderId organization provider id + * @param {number} organizationId organization id + * @return {Promise>} + */ + getRoles(organizationProviderId, organizationId) { + return axios.get(`/organizationProviders/${organizationProviderId}/organizations/${organizationId}/roles/`, { }).then((res) => res.data); + } + }