Change api interfaces

This commit is contained in:
Adria Navarro 2023-09-01 11:33:59 +02:00
parent 466f1e6132
commit 5b7756936d
8 changed files with 69 additions and 65 deletions

View File

@ -73,7 +73,7 @@
if (!perms["execute"]) {
role = "BASIC"
} else {
role = perms["execute"]
role = perms["execute"].role
}
}

View File

@ -5,7 +5,6 @@
export let resourceId
export let disabled = false
export let requiresLicence
let modal
let resourcePermissions
@ -20,9 +19,5 @@
Access
</ActionButton>
<Modal bind:this={modal}>
<ManageAccessModal
{resourceId}
{requiresLicence}
permissions={resourcePermissions}
/>
<ManageAccessModal {resourceId} permissions={resourcePermissions} />
</Modal>

View File

@ -1,5 +1,4 @@
<script>
import { licensing, admin } from "stores/portal"
import ManageAccessButton from "../ManageAccessButton.svelte"
import { getContext } from "svelte"
@ -13,17 +12,6 @@
}
return datasource.type === "table" ? datasource.tableId : datasource.id
}
var requiresLicence
$: {
if ($datasource.type === "viewV2" && !$licensing.isViewPermissionsEnabled) {
const requiredLicense = $admin?.cloud ? "Premium" : "Business"
requiresLicence = {
tier: requiredLicense,
message: `A ${requiredLicense} subscription is required to specify access level roles for this view.`,
}
}
}
</script>
<ManageAccessButton {resourceId} {requiresLicence} />
<ManageAccessButton {resourceId} />

View File

@ -15,7 +15,6 @@
export let resourceId
export let permissions
export let requiresLicence
async function changePermission(level, role) {
try {
@ -41,24 +40,20 @@
}
}
$: computedPermissions = Object.keys(permissions.permissions).reduce(
(p, c) => {
p[c] = {
selected:
permissions.permissionType[c] === "INHERITED"
? "inherited"
: permissions.permissions[c],
$: computedPermissions = Object.entries(permissions.permissions).reduce(
(p, [level, roleInfo]) => {
p[level] = {
selectedValue:
roleInfo.permissionType === "INHERITED" ? "inherited" : roleInfo.role,
options: [...get(roles)],
}
if (permissions.inheritablePermissions) {
p[c].inheritOption = permissions.inheritablePermissions[c]
p[c].options.unshift({
if (roleInfo.inheritablePermission) {
p[level].inheritOption = roleInfo.inheritablePermission
p[level].options.unshift({
_id: "inherited",
name: `Inherit (${
get(roles).find(
x => x._id === permissions.inheritablePermissions[c]
).name
get(roles).find(x => x._id === roleInfo.inheritablePermission).name
})`,
})
}
@ -66,21 +61,23 @@
},
{}
)
$: requiresPlanToModify = permissions.requiresPlanToModify
</script>
<ModalContent showCancelButton={false} confirmText="Done">
<span slot="header">
Manage Access
{#if requiresLicence}
{#if requiresPlanToModify}
<span class="lock-tag">
<Tags>
<Tag icon="LockClosed">{requiresLicence.tier}</Tag>
<Tag icon="LockClosed">{requiresPlanToModify}</Tag>
</Tags>
</span>
{/if}
</span>
{#if requiresLicence}
<Body size="S">{requiresLicence.message}</Body>
{#if requiresPlanToModify}
<Body size="S">{requiresPlanToModify}</Body>
{:else}
<Body size="S">Specify the minimum access level role for this data.</Body>
<div class="row">
@ -90,7 +87,7 @@
<Input value={capitalise(level)} disabled />
<Select
placeholder={false}
value={computedPermissions[level].selected}
value={computedPermissions[level].selectedValue}
on:change={e => changePermission(level, e.detail)}
options={computedPermissions[level].options}
getOptionLabel={x => x.name}

View File

@ -40,7 +40,7 @@
return
}
try {
roleId = (await permissions.forResource(queryToFetch._id))["read"]
roleId = (await permissions.forResource(queryToFetch._id))["read"].role
} catch (err) {
roleId = Constants.Roles.BASIC
}

View File

@ -5,6 +5,7 @@ import {
Role,
PermissionLevel,
GetResourcePermsResponse,
ResourcePermissionInfo,
} from "@budibase/types"
import { getRoleParams } from "../../db/utils"
import {
@ -162,24 +163,19 @@ export async function getResourcePerms(
ctx.body = {
permissions: Object.entries(resourcePermissions).reduce(
(p, [level, role]) => {
p[level] = role.role
p[level] = {
role: role.role,
permissionType: role.type,
inheritablePermission:
inheritablePermissions && inheritablePermissions[level].role,
}
return p
},
{} as Record<string, string>
{} as Record<string, ResourcePermissionInfo>
),
permissionType: Object.entries(resourcePermissions).reduce(
(p, [level, role]) => {
p[level] = role.type
return p
},
{} as Record<string, string>
),
inheritablePermissions:
inheritablePermissions &&
Object.entries(inheritablePermissions).reduce((p, [level, role]) => {
p[level] = role.role
return p
}, {} as Record<string, string>),
requiresPlanToModify: (
await sdk.permissions.allowsExplicitPermissions(resourceId)
).minPlan,
}
}

View File

@ -1,8 +1,9 @@
import { context, roles } from "@budibase/backend-core"
import { context, env, roles } from "@budibase/backend-core"
import { features } from "@budibase/pro"
import {
DocumentType,
PermissionLevel,
PlanType,
Role,
VirtualDocumentType,
} from "@budibase/types"
@ -60,11 +61,29 @@ type ResourcePermissions = Record<
export async function getInheritablePermissions(
resourceId: string
): Promise<ResourcePermissions | undefined> {
if (isViewID(resourceId) && (await features.isViewPermissionEnabled())) {
if (isViewID(resourceId)) {
return await getResourcePerms(extractViewInfoFromID(resourceId).tableId)
}
}
export async function allowsExplicitPermissions(resourceId: string) {
if (isViewID(resourceId)) {
const allowed = await features.isViewPermissionEnabled()
const minPlan = !allowed
? env.SELF_HOSTED
? PlanType.BUSINESS
: PlanType.PREMIUM
: undefined
return {
allowed,
minPlan,
}
}
return { allowed: true }
}
export async function getResourcePerms(
resourceId: string
): Promise<ResourcePermissions> {
@ -79,13 +98,15 @@ export async function getResourcePerms(
const permsToInherit = await getInheritablePermissions(resourceId)
const allowsExplicitPerm = (await allowsExplicitPermissions(resourceId))
.allowed
for (let level of CURRENTLY_SUPPORTED_LEVELS) {
// update the various roleIds in the resource permissions
for (let role of rolesList) {
const rolePerms = roles.checkForRoleResourceArray(
role.permissions,
resourceId
)
const rolePerms = allowsExplicitPerm
? roles.checkForRoleResourceArray(role.permissions, resourceId)
: {}
if (rolePerms[resourceId]?.indexOf(level) > -1) {
permissions[level] = {
role: roles.getExternalRoleID(role._id!, role.version),

View File

@ -1,5 +1,12 @@
export interface GetResourcePermsResponse {
permissions: Record<string, string>
permissionType: Record<string, string>
inheritablePermissions?: Record<string, string>
import { PlanType } from "../../../sdk"
export interface ResourcePermissionInfo {
role: string
permissionType: string
inheritablePermission?: string
}
export interface GetResourcePermsResponse {
permissions: Record<string, ResourcePermissionInfo>
requiresPlanToModify?: PlanType
}