Load checks from the backend

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2019-09-06 13:47:11 +02:00
parent c665d5475a
commit d6b3af9d77
No known key found for this signature in database
GPG key ID: 4C614C6ED2CDE6DF
5 changed files with 44 additions and 53 deletions

View file

@ -50,9 +50,9 @@ export default {
}
},
computed: {
...mapState({
Checks: (state) => state.plugins.checks
}),
Checks() {
return this.$store.getters.getChecksForEntity(this.rule.entity)
},
operators() {
if (!this.currentOption) { return [] }
return this.Checks[this.currentOption.class].operators

View file

@ -1,5 +1,5 @@
<template>
<div class="section rule" :style="{ borderLeftColor: operation.color }">
<div class="section rule" :style="{ borderLeftColor: operation.color || '' }">
<!-- TODO: icon-confirm -->
<div class="trigger">
<p>

View file

@ -1,38 +0,0 @@
const ALL_CHECKS = [
'OCA\\WorkflowEngine\\Check\\FileMimeType',
'OCA\\WorkflowEngine\\Check\\FileName',
'OCA\\WorkflowEngine\\Check\\FileSize',
'OCA\\WorkflowEngine\\Check\\FileSystemTags',
'OCA\\WorkflowEngine\\Check\\RequestRemoteAddress',
'OCA\\WorkflowEngine\\Check\\RequestTime',
'OCA\\WorkflowEngine\\Check\\RequestURL',
'OCA\\WorkflowEngine\\Check\\RequestUserAgent',
'OCA\\WorkflowEngine\\Check\\UserGroupMembership'
]
const Operators = {}
/**
* Extend operators for testing
*/
Operators['OCA\\TestExample\\Operation1'] = {
id: 'OCA\\TestExample\\Operation1',
name: 'Rename file',
description: '🚧 For UI mocking only',
iconClass: 'icon-address-white',
color: 'var(--color-success)',
operation: 'deny'
}
Operators['OCA\\TestExample\\Operation2'] = {
id: 'OCA\\TestExample\\Operation2',
name: 'Notify me',
description: '🚧 For UI mocking only',
iconClass: 'icon-comment-white',
color: 'var(--color-warning)',
operation: 'deny'
}
export {
Operators,
ALL_CHECKS
}

View file

@ -24,7 +24,6 @@ import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'nextcloud-axios'
import { getApiUrl } from './helpers/api'
import { ALL_CHECKS } from './services/Operation'
import confirmPassword from 'nextcloud-password-confirmation'
Vue.use(Vuex)
@ -40,13 +39,7 @@ const store = new Vuex.Store({
operators: {}
}),
entities: OCP.InitialState.loadState('workflowengine', 'entities').map(entity => {
return {
...entity,
// TODO: move to backend data once checks are provided
checks: [...ALL_CHECKS]
}
}),
entities: OCP.InitialState.loadState('workflowengine', 'entities'),
events: OCP.InitialState.loadState('workflowengine', 'entities')
.map((entity) => entity.events.map(event => {
return {
@ -54,7 +47,8 @@ const store = new Vuex.Store({
entity,
...event
}
})).flat()
})).flat(),
checks: OCP.InitialState.loadState('workflowengine', 'checks')
},
mutations: {
addRule(state, rule) {
@ -149,6 +143,20 @@ const store = new Vuex.Store({
},
getEventsForOperation(state) {
return (operation) => state.events
},
/**
* Return all available checker plugins for a given entity class
*/
getChecksForEntity(state) {
return (entity) => {
return state.checks
.filter((check) => check.supportedEntities.indexOf(entity) > -1 || check.supportedEntities.length === 0)
.map((check) => state.plugins.checks[check.id])
.reduce((obj, item) => {
obj[item.class] = item
return obj
}, {})
}
}
}
})

View file

@ -4,7 +4,6 @@ import store from './store'
import Settings from './components/Workflow'
import FileValues from './components/Values/file'
import {Operators} from './services/Operation';
/**
* A plugin for displaying a custom value field for checks
@ -63,7 +62,29 @@ window.OCA.WorkflowEngine = Object.assign({}, OCA.WorkflowEngine, {
// Register shipped checks for file entity
FileValues.forEach((checkPlugin) => window.OCA.WorkflowEngine.registerCheck(checkPlugin))
Object.values(Operators).forEach((operatorPlugin) => window.OCA.WorkflowEngine.registerOperator(operatorPlugin))
/**
* FIXME: remove before merge as this is for UI testing only
*/
const demo = [
{
id: 'OCA\\TestExample\\Operation1',
name: 'Rename file',
description: '🚧 For UI mocking only',
iconClass: 'icon-address-white',
color: 'var(--color-success)',
operation: 'deny'
},
{
id: 'OCA\\TestExample\\Operation2',
name: 'Notify me',
description: '🚧 For UI mocking only',
iconClass: 'icon-comment-white',
color: 'var(--color-warning)',
operation: 'deny'
}
]
demo.forEach((operatorPlugin) => window.OCA.WorkflowEngine.registerOperator(operatorPlugin))
Vue.use(Vuex)
Vue.prototype.t = t