This commit is contained in:
Adria Navarro 2023-09-04 12:11:59 +02:00
parent a1da8e495c
commit d68d449f1f
3 changed files with 15 additions and 9 deletions

View File

@ -1,4 +1,5 @@
<script> <script>
import { PermissionSource } from "@budibase/types"
import { roles, permissions as permissionsStore } from "stores/backend" import { roles, permissions as permissionsStore } from "stores/backend"
import { import {
Label, Label,
@ -17,9 +18,11 @@
export let resourceId export let resourceId
export let permissions export let permissions
const inheritedRoleId = "inherited"
async function changePermission(level, role) { async function changePermission(level, role) {
try { try {
if (role === "inherited") { if (role === inheritedRoleId) {
await permissionsStore.remove({ await permissionsStore.remove({
level, level,
role, role,
@ -45,14 +48,16 @@
(p, [level, roleInfo]) => { (p, [level, roleInfo]) => {
p[level] = { p[level] = {
selectedValue: selectedValue:
roleInfo.permissionType === "INHERITED" ? "inherited" : roleInfo.role, roleInfo.permissionType === PermissionSource.INHERITED
? inheritedRoleId
: roleInfo.role,
options: [...get(roles)], options: [...get(roles)],
} }
if (roleInfo.inheritablePermission) { if (roleInfo.inheritablePermission) {
p[level].inheritOption = roleInfo.inheritablePermission p[level].inheritOption = roleInfo.inheritablePermission
p[level].options.unshift({ p[level].options.unshift({
_id: "inherited", _id: inheritedRoleId,
name: `Inherit (${ name: `Inherit (${
get(roles).find(x => x._id === roleInfo.inheritablePermission).name get(roles).find(x => x._id === roleInfo.inheritablePermission).name
})`, })`,

View File

@ -3,6 +3,7 @@ import { features } from "@budibase/pro"
import { import {
DocumentType, DocumentType,
PermissionLevel, PermissionLevel,
PermissionSource,
PlanType, PlanType,
Role, Role,
VirtualDocumentType, VirtualDocumentType,
@ -49,12 +50,6 @@ export async function resourceActionAllowed({
} }
} }
enum PermissionSource {
EXPLICIT = "EXPLICIT",
INHERITED = "INHERITED",
BASE = "BASE",
}
type ResourcePermissions = Record< type ResourcePermissions = Record<
string, string,
{ role: string; type: PermissionSource } { role: string; type: PermissionSource }

View File

@ -17,3 +17,9 @@ export enum PermissionType {
QUERY = "query", QUERY = "query",
VIEW = "view", VIEW = "view",
} }
export enum PermissionSource {
EXPLICIT = "EXPLICIT",
INHERITED = "INHERITED",
BASE = "BASE",
}