Fix for #6709 - Adding the option to set a role for app action, allowing users to set what level an automation can be accessed from.

This commit is contained in:
mike12345567 2022-07-15 17:13:45 +01:00
parent a4825f8f6c
commit 30b7790e65
10 changed files with 86 additions and 13 deletions

View File

@ -12,6 +12,7 @@
notifications, notifications,
Modal, Modal,
} from "@budibase/bbui" } from "@budibase/bbui"
import { ActionStepID } from "constants/backend/automations"
export let automation export let automation
let testDataModal let testDataModal
@ -82,7 +83,7 @@
in:fly|local={{ x: 500, duration: 500 }} in:fly|local={{ x: 500, duration: 500 }}
out:fly|local={{ x: 500, duration: 500 }} out:fly|local={{ x: 500, duration: 500 }}
> >
{#if block.stepId !== "LOOP"} {#if block.stepId !== ActionStepID.LOOP}
<FlowItem {testDataModal} {block} /> <FlowItem {testDataModal} {block} />
{/if} {/if}
</div> </div>

View File

@ -10,11 +10,15 @@
Select, Select,
ActionButton, ActionButton,
notifications, notifications,
Label,
} from "@budibase/bbui" } from "@budibase/bbui"
import AutomationBlockSetup from "../../SetupPanel/AutomationBlockSetup.svelte" import AutomationBlockSetup from "../../SetupPanel/AutomationBlockSetup.svelte"
import CreateWebhookModal from "components/automation/Shared/CreateWebhookModal.svelte" import CreateWebhookModal from "components/automation/Shared/CreateWebhookModal.svelte"
import ActionModal from "./ActionModal.svelte" import ActionModal from "./ActionModal.svelte"
import FlowItemHeader from "./FlowItemHeader.svelte" import FlowItemHeader from "./FlowItemHeader.svelte"
import RoleSelect from "components/design/settings/controls/RoleSelect.svelte"
import { ActionStepID, TriggerStepID } from "constants/backend/automations"
import { permissions } from "stores/backend"
export let block export let block
export let testDataModal export let testDataModal
@ -23,9 +27,12 @@
let actionModal let actionModal
let blockComplete let blockComplete
let showLooping = false let showLooping = false
let role
$: automationId = $automationStore.selectedAutomation?.automation._id
$: showBindingPicker = $: showBindingPicker =
block.stepId === "CREATE_ROW" || block.stepId === "UPDATE_ROW" block.stepId === ActionStepID.CREATE_ROW ||
block.stepId === ActionStepID.UPDATE_ROW
$: isTrigger = block.type === "TRIGGER" $: isTrigger = block.type === "TRIGGER"
@ -45,6 +52,32 @@
x => x.blockToLoop === block.id x => x.blockToLoop === block.id
) )
$: setPermissions(role)
$: getPermissions(automationId)
async function setPermissions(role) {
if (!role || !automationId) {
return
}
await permissions.save({
level: "execute",
role,
resource: automationId,
})
}
async function getPermissions(automationId) {
if (!automationId) {
return
}
const perms = await permissions.forResource(automationId)
if (!perms["execute"]) {
role = "BASIC"
} else {
role = perms["execute"]
}
}
async function removeLooping() { async function removeLooping() {
loopingSelected = false loopingSelected = false
let loopBlock = let loopBlock =
@ -205,6 +238,10 @@
</div> </div>
{/if} {/if}
{#if block.stepId === TriggerStepID.APP}
<Label>Role</Label>
<RoleSelect bind:value={role} />
{/if}
<AutomationBlockSetup <AutomationBlockSetup
schemaProperties={Object.entries(block.schema.inputs.properties)} schemaProperties={Object.entries(block.schema.inputs.properties)}
{block} {block}

View File

@ -1,6 +1,7 @@
<script> <script>
import { Icon, Divider, Tabs, Tab, TextArea, Label } from "@budibase/bbui" import { Icon, Divider, Tabs, Tab, TextArea, Label } from "@budibase/bbui"
import FlowItemHeader from "./FlowChart/FlowItemHeader.svelte" import FlowItemHeader from "./FlowChart/FlowItemHeader.svelte"
import { ActionStepID } from "constants/backend/automations"
export let automation export let automation
export let testResults export let testResults
@ -10,7 +11,7 @@
let blocks let blocks
function prepTestResults(results) { function prepTestResults(results) {
return results?.steps.filter(x => x.stepId !== "LOOP" || []) return results?.steps.filter(x => x.stepId !== ActionStepID.LOOP || [])
} }
function textArea(results, message) { function textArea(results, message) {
@ -30,7 +31,7 @@
} }
blocks = blocks blocks = blocks
.concat(automation.definition.steps || []) .concat(automation.definition.steps || [])
.filter(x => x.stepId !== "LOOP") .filter(x => x.stepId !== ActionStepID.LOOP)
} else if (filteredResults) { } else if (filteredResults) {
blocks = filteredResults || [] blocks = filteredResults || []
// make sure there is an ID for each block being displayed // make sure there is an ID for each block being displayed
@ -45,7 +46,7 @@
<div class="container"> <div class="container">
{#each blocks as block, idx} {#each blocks as block, idx}
<div class="block" style={width ? `width: ${width}` : ""}> <div class="block" style={width ? `width: ${width}` : ""}>
{#if block.stepId !== "LOOP"} {#if block.stepId !== ActionStepID.LOOP}
<FlowItemHeader <FlowItemHeader
showTestStatus={true} showTestStatus={true}
bind:showParameters bind:showParameters

View File

@ -2,6 +2,7 @@
import { Icon, Divider } from "@budibase/bbui" import { Icon, Divider } from "@budibase/bbui"
import TestDisplay from "./TestDisplay.svelte" import TestDisplay from "./TestDisplay.svelte"
import { automationStore } from "builderStore" import { automationStore } from "builderStore"
import { ActionStepID } from "constants/backend/automations"
export let automation export let automation
export let testResults export let testResults
@ -16,7 +17,7 @@
} }
blocks = blocks blocks = blocks
.concat(automation.definition.steps || []) .concat(automation.definition.steps || [])
.filter(x => x.stepId !== "LOOP") .filter(x => x.stepId !== ActionStepID.LOOP)
} else if (testResults) { } else if (testResults) {
blocks = testResults.steps || [] blocks = testResults.steps || []
} }

View File

@ -11,6 +11,7 @@
Body, Body,
Icon, Icon,
} from "@budibase/bbui" } from "@budibase/bbui"
import { TriggerStepID } from "constants/backend/automations"
let name let name
let selectedTrigger let selectedTrigger
@ -35,7 +36,7 @@
) )
automationStore.actions.addBlockToAutomation(newBlock) automationStore.actions.addBlockToAutomation(newBlock)
if (triggerVal.stepId === "WEBHOOK") { if (triggerVal.stepId === TriggerStepID.WEBHOOK) {
webhookModal.show webhookModal.show
} }

View File

@ -30,6 +30,7 @@
import { LuceneUtils } from "@budibase/frontend-core" import { LuceneUtils } from "@budibase/frontend-core"
import { getSchemaForTable } from "builderStore/dataBinding" import { getSchemaForTable } from "builderStore/dataBinding"
import { Utils } from "@budibase/frontend-core" import { Utils } from "@budibase/frontend-core"
import { TriggerStepID, ActionStepID } from "constants/backend/automations"
export let block export let block
export let testData export let testData
@ -60,7 +61,7 @@
try { try {
if (isTestModal) { if (isTestModal) {
// Special case for webhook, as it requires a body, but the schema already brings back the body's contents // Special case for webhook, as it requires a body, but the schema already brings back the body's contents
if (stepId === "WEBHOOK") { if (stepId === TriggerStepID.WEBHOOK) {
automationStore.actions.addTestDataToAutomation({ automationStore.actions.addTestDataToAutomation({
body: { body: {
[key]: e.detail, [key]: e.detail,
@ -101,9 +102,9 @@
// Extract all outputs from all previous steps as available bindins // Extract all outputs from all previous steps as available bindins
let bindings = [] let bindings = []
for (let idx = 0; idx < blockIdx; idx++) { for (let idx = 0; idx < blockIdx; idx++) {
let wasLoopBlock = allSteps[idx]?.stepId === "LOOP" let wasLoopBlock = allSteps[idx]?.stepId === ActionStepID.LOOP
let isLoopBlock = let isLoopBlock =
allSteps[idx]?.stepId === "LOOP" && allSteps[idx]?.stepId === ActionStepID.LOOP &&
allSteps.find(x => x.blockToLoop === block.id) allSteps.find(x => x.blockToLoop === block.id)
// If the previous block was a loop block, decerement the index so the following // If the previous block was a loop block, decerement the index so the following
@ -345,7 +346,7 @@
<CreateWebhookModal /> <CreateWebhookModal />
</Modal> </Modal>
{#if stepId === "WEBHOOK"} {#if stepId === TriggerStepID.WEBHOOK}
<Button secondary on:click={() => webhookModal.show()}>Set Up Webhook</Button> <Button secondary on:click={() => webhookModal.show()}>Set Up Webhook</Button>
{/if} {/if}

View File

@ -3,6 +3,7 @@
import { ModalContent } from "@budibase/bbui" import { ModalContent } from "@budibase/bbui"
import { onMount } from "svelte" import { onMount } from "svelte"
import WebhookDisplay from "../automation/Shared/WebhookDisplay.svelte" import WebhookDisplay from "../automation/Shared/WebhookDisplay.svelte"
import { TriggerStepID } from "constants/backend/automations"
let webhookUrls = [] let webhookUrls = []
@ -11,7 +12,7 @@
onMount(() => { onMount(() => {
webhookUrls = automations.map(automation => { webhookUrls = automations.map(automation => {
const trigger = automation.definition.trigger const trigger = automation.definition.trigger
if (trigger?.stepId === "WEBHOOK" && trigger.inputs) { if (trigger?.stepId === TriggerStepID.WEBHOOK && trigger.inputs) {
return { return {
type: "Automation", type: "Automation",
name: automation.name, name: automation.name,

View File

@ -2,6 +2,7 @@
import { Select, Label, Input, Checkbox } from "@budibase/bbui" import { Select, Label, Input, Checkbox } from "@budibase/bbui"
import { automationStore } from "builderStore" import { automationStore } from "builderStore"
import SaveFields from "./SaveFields.svelte" import SaveFields from "./SaveFields.svelte"
import { TriggerStepID } from "constants/backend/automations"
export let parameters = {} export let parameters = {}
export let bindings = [] export let bindings = []
@ -16,7 +17,7 @@
: AUTOMATION_STATUS.NEW : AUTOMATION_STATUS.NEW
$: automations = $automationStore.automations $: automations = $automationStore.automations
.filter(a => a.definition.trigger?.stepId === "APP") .filter(a => a.definition.trigger?.stepId === TriggerStepID.APP)
.map(automation => { .map(automation => {
const schema = Object.entries( const schema = Object.entries(
automation.definition.trigger.inputs.fields || {} automation.definition.trigger.inputs.fields || {}

View File

@ -0,0 +1,28 @@
export const TriggerStepID = {
ROW_SAVED: "ROW_SAVED",
ROW_UPDATED: "ROW_UPDATED",
ROW_DELETED: "ROW_DELETED",
WEBHOOK: "WEBHOOK",
APP: "APP",
CRON: "CRON",
}
export const ActionStepID = {
SEND_EMAIL_SMTP: "SEND_EMAIL_SMTP",
CREATE_ROW: "CREATE_ROW",
UPDATE_ROW: "UPDATE_ROW",
DELETE_ROW: "DELETE_ROW",
OUTGOING_WEBHOOK: "OUTGOING_WEBHOOK",
EXECUTE_SCRIPT: "EXECUTE_SCRIPT",
EXECUTE_QUERY: "EXECUTE_QUERY",
SERVER_LOG: "SERVER_LOG",
DELAY: "DELAY",
FILTER: "FILTER",
QUERY_ROWS: "QUERY_ROWS",
LOOP: "LOOP",
// these used to be lowercase step IDs, maintain for backwards compat
discord: "discord",
slack: "slack",
zapier: "zapier",
integromat: "integromat",
}

View File

@ -13,6 +13,7 @@ const { DocumentTypes } = require("../db/utils")
const CURRENTLY_SUPPORTED_LEVELS = [ const CURRENTLY_SUPPORTED_LEVELS = [
PermissionLevels.WRITE, PermissionLevels.WRITE,
PermissionLevels.READ, PermissionLevels.READ,
PermissionLevels.EXECUTE,
] ]
exports.getPermissionType = resourceId => { exports.getPermissionType = resourceId => {