Type permission endpoints
This commit is contained in:
parent
99c3955e6d
commit
d59a3a0497
|
@ -105,9 +105,6 @@
|
|||
if (!hasSynced && application) {
|
||||
try {
|
||||
await API.syncApp(application)
|
||||
// check if user has beta access
|
||||
// const betaResponse = await API.checkBetaAccess($auth?.user?.email)
|
||||
// betaAccess = betaResponse.access
|
||||
} catch (error) {
|
||||
notifications.error("Failed to sync with production database")
|
||||
}
|
||||
|
|
|
@ -7,18 +7,10 @@ export function createPermissionStore() {
|
|||
return {
|
||||
subscribe,
|
||||
save: async ({ level, role, resource }) => {
|
||||
return await API.updatePermissionForResource({
|
||||
resourceId: resource,
|
||||
roleId: role,
|
||||
level,
|
||||
})
|
||||
return await API.updatePermissionForResource(resource, role, level)
|
||||
},
|
||||
remove: async ({ level, role, resource }) => {
|
||||
return await API.removePermissionFromResource({
|
||||
resourceId: resource,
|
||||
roleId: role,
|
||||
level,
|
||||
})
|
||||
return await API.removePermissionFromResource(resource, role, level)
|
||||
},
|
||||
forResource: async resourceId => {
|
||||
return (await API.getPermissionForResource(resourceId)).permissions
|
||||
|
|
|
@ -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
|
||||
* @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 roleId the ID of the role to update the permissions of
|
||||
* @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({
|
||||
url: `/api/permission/${roleId}/${resourceId}/${level}`,
|
||||
})
|
||||
|
@ -27,9 +54,8 @@ export const buildPermissionsEndpoints = API => ({
|
|||
* @param resourceId the ID of the resource to update
|
||||
* @param roleId the ID of the role to update the permissions of
|
||||
* @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({
|
||||
url: `/api/permission/${roleId}/${resourceId}/${level}`,
|
||||
})
|
|
@ -17,6 +17,7 @@ import { LicensingEndpoints } from "./licensing"
|
|||
import { LogEndpoints } from "./logs"
|
||||
import { MigrationEndpoints } from "./migrations"
|
||||
import { OtherEndpoints } from "./other"
|
||||
import { PermissionEndpoints } from "./permissions"
|
||||
|
||||
export enum HTTPMethod {
|
||||
POST = "POST",
|
||||
|
@ -105,4 +106,5 @@ export type APIClient = BaseAPIClient &
|
|||
LicensingEndpoints &
|
||||
LogEndpoints &
|
||||
MigrationEndpoints &
|
||||
OtherEndpoints & { [key: string]: any }
|
||||
OtherEndpoints &
|
||||
PermissionEndpoints & { [key: string]: any }
|
||||
|
|
Loading…
Reference in New Issue