DRY
This commit is contained in:
parent
a1da8e495c
commit
d68d449f1f
|
@ -1,4 +1,5 @@
|
|||
<script>
|
||||
import { PermissionSource } from "@budibase/types"
|
||||
import { roles, permissions as permissionsStore } from "stores/backend"
|
||||
import {
|
||||
Label,
|
||||
|
@ -17,9 +18,11 @@
|
|||
export let resourceId
|
||||
export let permissions
|
||||
|
||||
const inheritedRoleId = "inherited"
|
||||
|
||||
async function changePermission(level, role) {
|
||||
try {
|
||||
if (role === "inherited") {
|
||||
if (role === inheritedRoleId) {
|
||||
await permissionsStore.remove({
|
||||
level,
|
||||
role,
|
||||
|
@ -45,14 +48,16 @@
|
|||
(p, [level, roleInfo]) => {
|
||||
p[level] = {
|
||||
selectedValue:
|
||||
roleInfo.permissionType === "INHERITED" ? "inherited" : roleInfo.role,
|
||||
roleInfo.permissionType === PermissionSource.INHERITED
|
||||
? inheritedRoleId
|
||||
: roleInfo.role,
|
||||
options: [...get(roles)],
|
||||
}
|
||||
|
||||
if (roleInfo.inheritablePermission) {
|
||||
p[level].inheritOption = roleInfo.inheritablePermission
|
||||
p[level].options.unshift({
|
||||
_id: "inherited",
|
||||
_id: inheritedRoleId,
|
||||
name: `Inherit (${
|
||||
get(roles).find(x => x._id === roleInfo.inheritablePermission).name
|
||||
})`,
|
||||
|
|
|
@ -3,6 +3,7 @@ import { features } from "@budibase/pro"
|
|||
import {
|
||||
DocumentType,
|
||||
PermissionLevel,
|
||||
PermissionSource,
|
||||
PlanType,
|
||||
Role,
|
||||
VirtualDocumentType,
|
||||
|
@ -49,12 +50,6 @@ export async function resourceActionAllowed({
|
|||
}
|
||||
}
|
||||
|
||||
enum PermissionSource {
|
||||
EXPLICIT = "EXPLICIT",
|
||||
INHERITED = "INHERITED",
|
||||
BASE = "BASE",
|
||||
}
|
||||
|
||||
type ResourcePermissions = Record<
|
||||
string,
|
||||
{ role: string; type: PermissionSource }
|
||||
|
|
|
@ -17,3 +17,9 @@ export enum PermissionType {
|
|||
QUERY = "query",
|
||||
VIEW = "view",
|
||||
}
|
||||
|
||||
export enum PermissionSource {
|
||||
EXPLICIT = "EXPLICIT",
|
||||
INHERITED = "INHERITED",
|
||||
BASE = "BASE",
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue