Type permission endpoints

This commit is contained in:
Andrew Kingston 2024-12-03 07:43:12 +00:00
parent 99c3955e6d
commit d59a3a0497
No known key found for this signature in database
4 changed files with 36 additions and 19 deletions

View File

@ -105,9 +105,6 @@
if (!hasSynced && application) { if (!hasSynced && application) {
try { try {
await API.syncApp(application) await API.syncApp(application)
// check if user has beta access
// const betaResponse = await API.checkBetaAccess($auth?.user?.email)
// betaAccess = betaResponse.access
} catch (error) { } catch (error) {
notifications.error("Failed to sync with production database") notifications.error("Failed to sync with production database")
} }

View File

@ -7,18 +7,10 @@ export function createPermissionStore() {
return { return {
subscribe, subscribe,
save: async ({ level, role, resource }) => { save: async ({ level, role, resource }) => {
return await API.updatePermissionForResource({ return await API.updatePermissionForResource(resource, role, level)
resourceId: resource,
roleId: role,
level,
})
}, },
remove: async ({ level, role, resource }) => { remove: async ({ level, role, resource }) => {
return await API.removePermissionFromResource({ return await API.removePermissionFromResource(resource, role, level)
resourceId: resource,
roleId: role,
level,
})
}, },
forResource: async resourceId => { forResource: async resourceId => {
return (await API.getPermissionForResource(resourceId)).permissions return (await API.getPermissionForResource(resourceId)).permissions

View File

@ -1,4 +1,32 @@
export const buildPermissionsEndpoints = API => ({ import {
AddPermissionResponse,
GetDependantResourcesResponse,
GetResourcePermsResponse,
PermissionLevel,
RemovePermissionResponse,
} from "@budibase/types"
import { BaseAPIClient } from "./types"
export interface PermissionEndpoints {
getPermissionForResource: (
resourceId: string
) => Promise<GetResourcePermsResponse>
updatePermissionForResource: (
resourceId: string,
roleId: string,
level: PermissionLevel
) => Promise<AddPermissionResponse>
removePermissionFromResource: (
resourceId: string,
roleId: string,
level: PermissionLevel
) => Promise<RemovePermissionResponse>
getDependants: (resourceId: string) => Promise<GetDependantResourcesResponse>
}
export const buildPermissionsEndpoints = (
API: BaseAPIClient
): PermissionEndpoints => ({
/** /**
* Gets the permission required to access a specific resource * Gets the permission required to access a specific resource
* @param resourceId the resource ID to check * @param resourceId the resource ID to check
@ -14,9 +42,8 @@ export const buildPermissionsEndpoints = API => ({
* @param resourceId the ID of the resource to update * @param resourceId the ID of the resource to update
* @param roleId the ID of the role to update the permissions of * @param roleId the ID of the role to update the permissions of
* @param level the level to assign the role for this resource * @param level the level to assign the role for this resource
* @return {Promise<*>}
*/ */
updatePermissionForResource: async ({ resourceId, roleId, level }) => { updatePermissionForResource: async (resourceId, roleId, level) => {
return await API.post({ return await API.post({
url: `/api/permission/${roleId}/${resourceId}/${level}`, url: `/api/permission/${roleId}/${resourceId}/${level}`,
}) })
@ -27,9 +54,8 @@ export const buildPermissionsEndpoints = API => ({
* @param resourceId the ID of the resource to update * @param resourceId the ID of the resource to update
* @param roleId the ID of the role to update the permissions of * @param roleId the ID of the role to update the permissions of
* @param level the level to remove the role for this resource * @param level the level to remove the role for this resource
* @return {Promise<*>}
*/ */
removePermissionFromResource: async ({ resourceId, roleId, level }) => { removePermissionFromResource: async (resourceId, roleId, level) => {
return await API.delete({ return await API.delete({
url: `/api/permission/${roleId}/${resourceId}/${level}`, url: `/api/permission/${roleId}/${resourceId}/${level}`,
}) })

View File

@ -17,6 +17,7 @@ import { LicensingEndpoints } from "./licensing"
import { LogEndpoints } from "./logs" import { LogEndpoints } from "./logs"
import { MigrationEndpoints } from "./migrations" import { MigrationEndpoints } from "./migrations"
import { OtherEndpoints } from "./other" import { OtherEndpoints } from "./other"
import { PermissionEndpoints } from "./permissions"
export enum HTTPMethod { export enum HTTPMethod {
POST = "POST", POST = "POST",
@ -105,4 +106,5 @@ export type APIClient = BaseAPIClient &
LicensingEndpoints & LicensingEndpoints &
LogEndpoints & LogEndpoints &
MigrationEndpoints & MigrationEndpoints &
OtherEndpoints & { [key: string]: any } OtherEndpoints &
PermissionEndpoints & { [key: string]: any }