aboutsummaryrefslogtreecommitdiffstats
path: root/apps/workflowengine/src/store.js
blob: 84a76a644a8e9f8483e1bb6785fe7fce281238c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
 * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

import Vue from 'vue'
import Vuex, { Store } from 'vuex'
import axios from '@nextcloud/axios'
import { confirmPassword } from '@nextcloud/password-confirmation'
import { loadState } from '@nextcloud/initial-state'
import { getApiUrl } from './helpers/api.js'

import '@nextcloud/password-confirmation/dist/style.css'

Vue.use(Vuex)

const store = new Store({
	state: {
		rules: [],
		scope: loadState('workflowengine', 'scope'),
		appstoreEnabled: loadState('workflowengine', 'appstoreenabled'),
		operations: loadState('workflowengine', 'operators'),

		plugins: Vue.observable({
			checks: {},
			operators: {},
		}),

		entities: loadState('workflowengine', 'entities'),
		events: loadState('workflowengine', 'entities')
			.map((entity) => entity.events.map(event => {
				return {
					id: `${entity.id}::${event.eventName}`,
					entity,
					...event,
				}
			})).flat(),
		checks: loadState('workflowengine', 'checks'),
	},
	mutations: {
		addRule(state, rule) {
			state.rules.push({ ...rule, valid: true })
		},
		updateRule(state, rule) {
			const index = state.rules.findIndex((item) => rule.id === item.id)
			const newRule = Object.assign({}, rule)
			Vue.set(state.rules, index, newRule)
		},
		removeRule(state, rule) {
			const index = state.rules.findIndex((item) => rule.id === item.id)
			state.rules.splice(index, 1)
		},
		addPluginCheck(state, plugin) {
			Vue.set(state.plugins.checks, plugin.class, plugin)
		},
		addPluginOperator(state, plugin) {
			plugin = Object.assign(
				{ color: 'var(--color-primary-element)' },
				plugin, state.operations[plugin.id] || {})
			if (typeof state.operations[plugin.id] !== 'undefined') {
				Vue.set(state.operations, plugin.id, plugin)
			}
		},
	},
	actions: {
		async fetchRules(context) {
			const { data } = await axios.get(getApiUrl(''))
			Object.values(data.ocs.data).flat().forEach((rule) => {
				context.commit('addRule', rule)
			})
		},
		async createNewRule(context, rule) {
			await confirmPassword()
			let entity = null
			let events = []
			if (rule.isComplex === false && rule.fixedEntity === '') {
				entity = context.state.entities.find((item) => rule.entities && rule.entities[0] === item.id)
				entity = entity || Object.values(context.state.entities)[0]
				events = [entity.events[0].eventName]
			}

			context.commit('addRule', {
				id: -(new Date().getTime()),
				class: rule.id,
				entity: entity ? entity.id : rule.fixedEntity,
				events,
				name: '', // unused in the new ui, there for legacy reasons
				checks: [
					{ class: null, operator: null, value: '' },
				],
				operation: rule.operation || '',
			})
		},
		updateRule(context, rule) {
			context.commit('updateRule', {
				...rule,
				events: typeof rule.events === 'string' ? JSON.parse(rule.events) : rule.events,
			})
		},
		removeRule(context, rule) {
			context.commit('removeRule', rule)
		},
		async pushUpdateRule(context, rule) {
			await confirmPassword()
			let result
			if (rule.id < 0) {
				result = await axios.post(getApiUrl(''), rule)
			} else {
				result = await axios.put(getApiUrl(`/${rule.id}`), rule)
			}
			Vue.set(rule, 'id', result.data.ocs.data.id)
			context.commit('updateRule', rule)
		},
		async deleteRule(context, rule) {
			await confirmPassword()
			await axios.delete(getApiUrl(`/${rule.id}`))
			context.commit('removeRule', rule)
		},
		setValid(context, { rule, valid }) {
			rule.valid = valid
			context.commit('updateRule', rule)
		},
	},
	getters: {
		getRules(state) {
			return state.rules.filter((rule) => typeof state.operations[rule.class] !== 'undefined').sort((rule1, rule2) => {
				return rule1.id - rule2.id || rule2.class - rule1.class
			})
		},
		/**
		 * @param state
		 * @return {OperatorPlugin}
		 */
		getOperationForRule(state) {
			return (rule) => state.operations[rule.class]
		},
		getEntityForOperation(state) {
			return (operation) => state.entities.find((entity) => operation.fixedEntity === entity.id)
		},
		getEventsForOperation(state) {
			return (operation) => state.events
		},

		/**
		 * Return all available checker plugins for a given entity class
		 *
		 * @param {object} state the store state
		 * @return {Function} the available plugins
		 */
		getChecksForEntity(state) {
			return (entity) => {
				return Object.values(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
					}, {})
			}
		},
	},
})

export default store
an <sujith.h@gmail.com> - Sven Strickroth <email@cs-ware.de> - Sylvain <git@sylvain.dev> - Sylvia van Os <sylvia@hackerchick.me> - Tekhnee <info@tekhnee.org> - Temtaime <temtaime@gmail.com> - Thibaut GRIDEL <tgridel@free.fr> - Thomas Citharel <nextcloud@tcit.fr> - Thomas Ebert <thomas.ebert@usability.de> - Thomas Müller <thomas.mueller@tmit.eu> - Thomas Pulzer <t.pulzer@kniel.de> - Thomas Tanghus <thomas@tanghus.net> - Tiago Flores <tiago.flores@yahoo.com.br> - Tigran Mkrtchyan <tigran.mkrtchyan@desy.de> - Tim Dettrick <t.dettrick@uq.edu.au> - Tim Obert <tobert@w-commerce.de> - Tim Terhorst <mynamewastaken+gitlab@gmail.com> - TimObert <tobert@w-commerce.de> - Timo Förster <tfoerster@webfoersterei.de> - Tobia De Koninck <LEDfan@users.noreply.github.com> - Tobia De Koninck <tobia@ledfan.be> - Tobias Assmann <tobias.assmann@ecsec.de> - Tobias Kaminsky <tobias@kaminsky.me> - Tobias Perschon <tobias@perschon.at> - Tom Grant <TomG736@users.noreply.github.com> - Tom Needham <tom@owncloud.com> - Tomasz Grobelny <tomasz@grobelny.net> - Tomasz Paluszkiewicz <tomasz.paluszkiewicz@gmail.com> - Tor Lillqvist <tml@collabora.com> - UmbrellaCodr <umbrella@biohazard.cc> - Unknown <anpz.asutp@gmail.com> - Unpublished <unpublished@gmx.net> - Valdnet <47037905+Valdnet@users.noreply.github.com> - Vanessa Pertsch <vanessa.pertsch@nextcloud.com> - Varun Patil <radialapps@gmail.com> - Varun Patil <varunpatil@ucla.edu> - Victor Dubiniuk <dubiniuk@owncloud.com> - Viktor Szépe <viktor@szepe.net> - Vincent Chan <plus.vincchan@gmail.com> - Vincent Petry <pvince81@owncloud.com> - Vincent Petry <vincent@nextcloud.com> - Vincent Van Houtte <vvh@aplusv.be> - Vinicius Cubas Brand <vinicius@eita.org.br> - Vitor Mattos <vitor@php.rio> - Vlastimil Pecinka <pecinka@email.cz> - Volkan Gezer <volkangezer@gmail.com> - Volker <skydiablo@gmx.net> - William <william.hak57@gmail.com> - William Pain <pain.william@gmail.com> - Xheni Myrtaj <myrtajxheni@gmail.com> - Xheni Myrtaj <xheni@protonmail.com> - Xuanwo <xuanwo@yunify.com> - ZitronePlus <tobiasscharf92@gmail.com> - acsfer <12234510+acsfer@users.noreply.github.com> - acsfer <carlos@reendex.com> - adrien <adrien.waksberg@believedigital.com> - alanmeeson <alan@carefullycalculated.co.uk> - aler9 <46489434+aler9@users.noreply.github.com> - alexweirig <alex.weirig@technolink.lu> - b108@volgograd "b108@volgograd" - bbx-github <53237674+bbx-github@users.noreply.github.com> - bladewing <lukas@ifflaender-family.de> - bline <scottbeck@gmail.com> - blizzz <blizzz@arthur-schiwon.de> - brad2014 <brad2014@users.noreply.github.com> - brumsel <brumsel@losecatcher.de> - cahogan <caitlin.hogan@swiftsolar.com> - call-me-matt <nextcloud@matthiasheinisch.de> - castillo92 <37965565+castillo92@users.noreply.github.com> - cetra3 <peter@parashift.com.au> - cmeh <cmeh@users.noreply.github.com> - comradekingu <epost@anotheragency.no> - dartcafe <github@dartcafe.de> - davidgumberg <davidnoizgumberg@gmail.com> - davitol <dtoledo@solidgear.es> - dems54 <2083596+dems54@users.noreply.github.com> - duritong <peter.meier+github@immerda.ch> - eduardo <eduardo@vnexu.net> - eleith <online+github@eleith.com> - enoch <lanxenet@hotmail.com> - essys <essys@users.noreply.github.com> - exner104 <59639860+exner104@users.noreply.github.com> - fabian <fabian@web2.0-apps.de> - felixboehm <felix@webhippie.de> - fenn-cs <fenn25.fn@gmail.com> - fnuesse <felix.nuesse@t-online.de> - fnuesse <fnuesse@techfak.uni-bielefeld.de> - greta <gretadoci@gmail.com> - helix84 <helix84@centrum.sk> - hkjolhede <hkjolhede@gmail.com> - hoellen <dev@hoellen.eu> - hosting.de, Johannes Leuker <developers@hosting.de> - howardZa <33491519+howardZa@users.noreply.github.com> - ideaship <ideaship@users.noreply.github.com> - j-ed <juergen@eisfair.org> - j3l11234 <297259024@qq.com> - jaltek <jaltek@mailbox.org> - jknockaert <jasper@knockaert.nl> - jld3103 <jld3103yt@gmail.com> - josh4trunks <joshruehlig@gmail.com> - julia.kirschenheuter <julia.kirschenheuter@nextcloud.com> - karakayasemi <karakayasemi@itu.edu.tr> - kevin147147 <kevintamool@gmail.com> - korelstar <korelstar@users.noreply.github.com> - leith abdulla <online-nextcloud@eleith.com> - lui87kw <lukas.ifflaender@uni-wuerzburg.de> - luz paz <luzpaz@github.com> - luz paz <luzpaz@pm.me> - lynn-stephenson <lynn.stephenson@protonmail.com> - macjohnny <estebanmarin@gmx.ch> - marco44 <cousinmarc@gmail.com> - martin.mattel@diemattels.at <martin.mattel@diemattels.at> - martink-p <47943787+martink-p@users.noreply.github.com> - matt <34400929+call-me-matt@users.noreply.github.com> - medcloud <42641918+medcloud@users.noreply.github.com> - michaelletzgus <michaelletzgus@users.noreply.github.com> - michag86 <micha_g@arcor.de> - michag86 <michag86@arcor.de> - mmccarn <mmccarn-github@mmsionline.us> - nhirokinet <nhirokinet@nhiroki.net> - nik gaffney <nik@fo.am> - nishiki <nishiki@yaegashi.fr> - noiob <8197071+noiob@users.noreply.github.com> - noveens <noveen.sachdeva@research.iiit.ac.in> - npmbuildbot[bot] "npmbuildbot[bot]@users.noreply.github.com" - onehappycat <one.happy.cat@gmx.com> - phisch <git@philippschaffrath.de> - pjft <pjft@users.noreply.github.com> - plumbeo <plumbeo@users.noreply.github.com> - rakekniven <2069590+rakekniven@users.noreply.github.com> - rakekniven <mark.ziegler@rakekniven.de> - raul <raul@nextcloud.com> - robottod <83244577+robottod@users.noreply.github.com> - root "root@oc.(none)" - root <root@localhost.localdomain> - rubo77 <github@r.z11.de> - sammo2828 <sammo2828@gmail.com> - scambra <sergio@entrecables.com> - scolebrook <scolebrook@mac.com> - shkdee <louis.traynard@m4x.org> - simonspa <1677436+simonspa@users.noreply.github.com> - smichel17 <git@smichel.me> - sodimel <corentin@244466666.xyz> - ste101 <stephan_bauer@gmx.de> - sualko <klaus@jsxc.org> - szaimen <szaimen@e.mail.de> - tbartenstein <tbartenstein@users.noreply.github.com> - tbelau666 <thomas.belau@gmx.de> - tgrant <tom.grant760@gmail.com> - timm2k <timm2k@gmx.de> - tux-rampage <tux-rampage@users.noreply.github.com> - v1r0x <vinzenz.rosenkranz@gmail.com> - voxsim "Simon Vocella" - waleczny <michal@walczak.xyz> - zorn-v <zorn7@yandex.ru> - zulan <git@zulan.net> - Łukasz Buśko <busko.lukasz@pm.me> - Nextcloud GmbH - ownCloud GmbH - ownCloud, Inc. With help from many libraries and frameworks including: Open Collaboration Services SabreDAV jQuery …