From 7bb53c64da2dcf88894bfd31503accdd81498f3d Mon Sep 17 00:00:00 2001 From: Thomas Duval Date: Wed, 3 Jun 2020 10:06:52 +0200 Subject: Update to new version 5.4 Signed-off-by: Thomas Duval Change-Id: Idcd868133d75928a1ffd74d749ce98503e0555ea --- dashboard/src/App.vue | 41 ++ dashboard/src/assets/logo.png | Bin 0 -> 6849 bytes dashboard/src/components/FormHeader.vue | 27 ++ dashboard/src/components/assignment/Category.vue | 103 +++++ dashboard/src/components/assignment/CreateData.vue | 75 ++++ dashboard/src/components/assignment/Policy.vue | 123 ++++++ dashboard/src/components/model/AddCategory.vue | 126 ++++++ dashboard/src/components/model/AddMetarule.vue | 111 +++++ dashboard/src/components/model/Category.vue | 64 +++ dashboard/src/components/model/CreateModel.vue | 57 +++ dashboard/src/components/model/Metarule.vue | 155 +++++++ dashboard/src/components/model/Model.vue | 112 +++++ dashboard/src/components/model/OrphanCategory.vue | 65 +++ dashboard/src/components/model/Orphans.vue | 79 ++++ dashboard/src/components/pdp/AddPolicy.vue | 64 +++ dashboard/src/components/pdp/CreatePdp.vue | 83 ++++ dashboard/src/components/pdp/Pdp.vue | 173 ++++++++ dashboard/src/components/pdp/UpdatePolicy.vue | 64 +++ .../src/components/policy/AssignPerimeter.vue | 244 +++++++++++ dashboard/src/components/policy/CreateData.vue | 75 ++++ .../src/components/policy/CreatePerimeter.vue | 73 ++++ dashboard/src/components/policy/CreatePolicy.vue | 84 ++++ dashboard/src/components/policy/CreateRule.vue | 213 ++++++++++ dashboard/src/components/policy/DataList.vue | 16 + dashboard/src/components/policy/FilterRules.vue | 24 ++ dashboard/src/components/policy/Policy.vue | 186 ++++++++ dashboard/src/components/policy/Rule.vue | 231 ++++++++++ dashboard/src/components/policy/UnusedData.vue | 89 ++++ dashboard/src/config.js | 4 + dashboard/src/helpstrings.js | 25 ++ dashboard/src/main.js | 58 +++ dashboard/src/router.js | 56 +++ dashboard/src/services/Attribute.service.js | 46 ++ dashboard/src/services/Import.service.js | 16 + dashboard/src/services/Model.service.js | 351 +++++++++++++++ dashboard/src/services/Pdp.service.js | 92 ++++ dashboard/src/services/Policy.service.js | 470 +++++++++++++++++++++ dashboard/src/services/Util.service.js | 153 +++++++ dashboard/src/views/Admin.vue | 52 +++ dashboard/src/views/Assignments.vue | 54 +++ dashboard/src/views/Auth.vue | 65 +++ dashboard/src/views/Error.vue | 8 + dashboard/src/views/Models.vue | 80 ++++ dashboard/src/views/Pdps.vue | 53 +++ dashboard/src/views/Rules.vue | 50 +++ 45 files changed, 4390 insertions(+) create mode 100644 dashboard/src/App.vue create mode 100644 dashboard/src/assets/logo.png create mode 100644 dashboard/src/components/FormHeader.vue create mode 100644 dashboard/src/components/assignment/Category.vue create mode 100644 dashboard/src/components/assignment/CreateData.vue create mode 100644 dashboard/src/components/assignment/Policy.vue create mode 100644 dashboard/src/components/model/AddCategory.vue create mode 100644 dashboard/src/components/model/AddMetarule.vue create mode 100644 dashboard/src/components/model/Category.vue create mode 100644 dashboard/src/components/model/CreateModel.vue create mode 100644 dashboard/src/components/model/Metarule.vue create mode 100644 dashboard/src/components/model/Model.vue create mode 100644 dashboard/src/components/model/OrphanCategory.vue create mode 100644 dashboard/src/components/model/Orphans.vue create mode 100644 dashboard/src/components/pdp/AddPolicy.vue create mode 100644 dashboard/src/components/pdp/CreatePdp.vue create mode 100644 dashboard/src/components/pdp/Pdp.vue create mode 100644 dashboard/src/components/pdp/UpdatePolicy.vue create mode 100644 dashboard/src/components/policy/AssignPerimeter.vue create mode 100644 dashboard/src/components/policy/CreateData.vue create mode 100644 dashboard/src/components/policy/CreatePerimeter.vue create mode 100644 dashboard/src/components/policy/CreatePolicy.vue create mode 100644 dashboard/src/components/policy/CreateRule.vue create mode 100644 dashboard/src/components/policy/DataList.vue create mode 100644 dashboard/src/components/policy/FilterRules.vue create mode 100644 dashboard/src/components/policy/Policy.vue create mode 100644 dashboard/src/components/policy/Rule.vue create mode 100644 dashboard/src/components/policy/UnusedData.vue create mode 100644 dashboard/src/config.js create mode 100644 dashboard/src/helpstrings.js create mode 100644 dashboard/src/main.js create mode 100644 dashboard/src/router.js create mode 100644 dashboard/src/services/Attribute.service.js create mode 100644 dashboard/src/services/Import.service.js create mode 100644 dashboard/src/services/Model.service.js create mode 100644 dashboard/src/services/Pdp.service.js create mode 100644 dashboard/src/services/Policy.service.js create mode 100644 dashboard/src/services/Util.service.js create mode 100644 dashboard/src/views/Admin.vue create mode 100644 dashboard/src/views/Assignments.vue create mode 100644 dashboard/src/views/Auth.vue create mode 100644 dashboard/src/views/Error.vue create mode 100644 dashboard/src/views/Models.vue create mode 100644 dashboard/src/views/Pdps.vue create mode 100644 dashboard/src/views/Rules.vue (limited to 'dashboard/src') diff --git a/dashboard/src/App.vue b/dashboard/src/App.vue new file mode 100644 index 00000000..99c5cd0d --- /dev/null +++ b/dashboard/src/App.vue @@ -0,0 +1,41 @@ + + + + + diff --git a/dashboard/src/assets/logo.png b/dashboard/src/assets/logo.png new file mode 100644 index 00000000..f3d2503f Binary files /dev/null and b/dashboard/src/assets/logo.png differ diff --git a/dashboard/src/components/FormHeader.vue b/dashboard/src/components/FormHeader.vue new file mode 100644 index 00000000..05419179 --- /dev/null +++ b/dashboard/src/components/FormHeader.vue @@ -0,0 +1,27 @@ + + + \ No newline at end of file diff --git a/dashboard/src/components/assignment/Category.vue b/dashboard/src/components/assignment/Category.vue new file mode 100644 index 00000000..0f2f921b --- /dev/null +++ b/dashboard/src/components/assignment/Category.vue @@ -0,0 +1,103 @@ + + + + + \ No newline at end of file diff --git a/dashboard/src/components/assignment/CreateData.vue b/dashboard/src/components/assignment/CreateData.vue new file mode 100644 index 00000000..63c69650 --- /dev/null +++ b/dashboard/src/components/assignment/CreateData.vue @@ -0,0 +1,75 @@ + + + diff --git a/dashboard/src/components/assignment/Policy.vue b/dashboard/src/components/assignment/Policy.vue new file mode 100644 index 00000000..6fd4afb4 --- /dev/null +++ b/dashboard/src/components/assignment/Policy.vue @@ -0,0 +1,123 @@ + + + \ No newline at end of file diff --git a/dashboard/src/components/model/AddCategory.vue b/dashboard/src/components/model/AddCategory.vue new file mode 100644 index 00000000..c22ab333 --- /dev/null +++ b/dashboard/src/components/model/AddCategory.vue @@ -0,0 +1,126 @@ + + + diff --git a/dashboard/src/components/model/AddMetarule.vue b/dashboard/src/components/model/AddMetarule.vue new file mode 100644 index 00000000..ef6e8503 --- /dev/null +++ b/dashboard/src/components/model/AddMetarule.vue @@ -0,0 +1,111 @@ + + + diff --git a/dashboard/src/components/model/Category.vue b/dashboard/src/components/model/Category.vue new file mode 100644 index 00000000..81efb1ed --- /dev/null +++ b/dashboard/src/components/model/Category.vue @@ -0,0 +1,64 @@ + + + diff --git a/dashboard/src/components/model/CreateModel.vue b/dashboard/src/components/model/CreateModel.vue new file mode 100644 index 00000000..d5403e7b --- /dev/null +++ b/dashboard/src/components/model/CreateModel.vue @@ -0,0 +1,57 @@ + + + diff --git a/dashboard/src/components/model/Metarule.vue b/dashboard/src/components/model/Metarule.vue new file mode 100644 index 00000000..1cb266bd --- /dev/null +++ b/dashboard/src/components/model/Metarule.vue @@ -0,0 +1,155 @@ + + + diff --git a/dashboard/src/components/model/Model.vue b/dashboard/src/components/model/Model.vue new file mode 100644 index 00000000..82ad992d --- /dev/null +++ b/dashboard/src/components/model/Model.vue @@ -0,0 +1,112 @@ + + + diff --git a/dashboard/src/components/model/OrphanCategory.vue b/dashboard/src/components/model/OrphanCategory.vue new file mode 100644 index 00000000..316b8095 --- /dev/null +++ b/dashboard/src/components/model/OrphanCategory.vue @@ -0,0 +1,65 @@ + + + diff --git a/dashboard/src/components/model/Orphans.vue b/dashboard/src/components/model/Orphans.vue new file mode 100644 index 00000000..b3c1c524 --- /dev/null +++ b/dashboard/src/components/model/Orphans.vue @@ -0,0 +1,79 @@ + + + \ No newline at end of file diff --git a/dashboard/src/components/pdp/AddPolicy.vue b/dashboard/src/components/pdp/AddPolicy.vue new file mode 100644 index 00000000..82ad07e2 --- /dev/null +++ b/dashboard/src/components/pdp/AddPolicy.vue @@ -0,0 +1,64 @@ + + + diff --git a/dashboard/src/components/pdp/CreatePdp.vue b/dashboard/src/components/pdp/CreatePdp.vue new file mode 100644 index 00000000..aca46413 --- /dev/null +++ b/dashboard/src/components/pdp/CreatePdp.vue @@ -0,0 +1,83 @@ + + + diff --git a/dashboard/src/components/pdp/Pdp.vue b/dashboard/src/components/pdp/Pdp.vue new file mode 100644 index 00000000..3aba3fed --- /dev/null +++ b/dashboard/src/components/pdp/Pdp.vue @@ -0,0 +1,173 @@ + + + diff --git a/dashboard/src/components/pdp/UpdatePolicy.vue b/dashboard/src/components/pdp/UpdatePolicy.vue new file mode 100644 index 00000000..f84cf37e --- /dev/null +++ b/dashboard/src/components/pdp/UpdatePolicy.vue @@ -0,0 +1,64 @@ + + + diff --git a/dashboard/src/components/policy/AssignPerimeter.vue b/dashboard/src/components/policy/AssignPerimeter.vue new file mode 100644 index 00000000..07814075 --- /dev/null +++ b/dashboard/src/components/policy/AssignPerimeter.vue @@ -0,0 +1,244 @@ + + + \ No newline at end of file diff --git a/dashboard/src/components/policy/CreateData.vue b/dashboard/src/components/policy/CreateData.vue new file mode 100644 index 00000000..ca3c5183 --- /dev/null +++ b/dashboard/src/components/policy/CreateData.vue @@ -0,0 +1,75 @@ + + + diff --git a/dashboard/src/components/policy/CreatePerimeter.vue b/dashboard/src/components/policy/CreatePerimeter.vue new file mode 100644 index 00000000..b8a9d532 --- /dev/null +++ b/dashboard/src/components/policy/CreatePerimeter.vue @@ -0,0 +1,73 @@ + + + diff --git a/dashboard/src/components/policy/CreatePolicy.vue b/dashboard/src/components/policy/CreatePolicy.vue new file mode 100644 index 00000000..b3e90c2d --- /dev/null +++ b/dashboard/src/components/policy/CreatePolicy.vue @@ -0,0 +1,84 @@ + + + diff --git a/dashboard/src/components/policy/CreateRule.vue b/dashboard/src/components/policy/CreateRule.vue new file mode 100644 index 00000000..656fa39a --- /dev/null +++ b/dashboard/src/components/policy/CreateRule.vue @@ -0,0 +1,213 @@ + + + diff --git a/dashboard/src/components/policy/DataList.vue b/dashboard/src/components/policy/DataList.vue new file mode 100644 index 00000000..40f384f3 --- /dev/null +++ b/dashboard/src/components/policy/DataList.vue @@ -0,0 +1,16 @@ + + + \ No newline at end of file diff --git a/dashboard/src/components/policy/FilterRules.vue b/dashboard/src/components/policy/FilterRules.vue new file mode 100644 index 00000000..5d685952 --- /dev/null +++ b/dashboard/src/components/policy/FilterRules.vue @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/dashboard/src/components/policy/Policy.vue b/dashboard/src/components/policy/Policy.vue new file mode 100644 index 00000000..415f6b02 --- /dev/null +++ b/dashboard/src/components/policy/Policy.vue @@ -0,0 +1,186 @@ + + + \ No newline at end of file diff --git a/dashboard/src/components/policy/Rule.vue b/dashboard/src/components/policy/Rule.vue new file mode 100644 index 00000000..c8889b86 --- /dev/null +++ b/dashboard/src/components/policy/Rule.vue @@ -0,0 +1,231 @@ + + + + + \ No newline at end of file diff --git a/dashboard/src/components/policy/UnusedData.vue b/dashboard/src/components/policy/UnusedData.vue new file mode 100644 index 00000000..48b8b642 --- /dev/null +++ b/dashboard/src/components/policy/UnusedData.vue @@ -0,0 +1,89 @@ + + + \ No newline at end of file diff --git a/dashboard/src/config.js b/dashboard/src/config.js new file mode 100644 index 00000000..2849ec7d --- /dev/null +++ b/dashboard/src/config.js @@ -0,0 +1,4 @@ +export default { + // Moon Manager URL + host: 'http://127.0.0.1:8000', +} \ No newline at end of file diff --git a/dashboard/src/helpstrings.js b/dashboard/src/helpstrings.js new file mode 100644 index 00000000..63751e78 --- /dev/null +++ b/dashboard/src/helpstrings.js @@ -0,0 +1,25 @@ +export default { + model: { + metarule: 'model.metarule' + }, + metarule: { + subject: 'metarule.subject', + object: 'meterule.object', + action: 'meterule.action' + }, + policy:{ + rules: 'policy.rules' + }, + assignPerimeter:{ + allPerimeters: 'assignPerimeter.allPerimeters', + policyPerimeters: 'assignPerimeter.policyPerimeters', + assignedPerimeters: 'assignPerimeter.assignedPerimeters' + }, + rule:{ + subjectsData: 'rule.subjectsData', + objectsData: 'rule.objectsData', + actionsData: 'rule.actionsData', + attributes: 'rule.attributes', + instructions: 'rule.instructions', + } +} \ No newline at end of file diff --git a/dashboard/src/main.js b/dashboard/src/main.js new file mode 100644 index 00000000..e18e3ebf --- /dev/null +++ b/dashboard/src/main.js @@ -0,0 +1,58 @@ +import Vue from 'vue' +import App from './App.vue' +import router from './router' +import VueResource from 'vue-resource' +import VeeValidate from 'vee-validate' +import Toasted from 'vue-toasted' + +Vue.config.productionTip = false + +Vue.use(VueResource) +Vue.use(VeeValidate) +Vue.use(Toasted) + +Vue.http.interceptors.push(function () { + return function (response) { + if (response.status == 401) { + router.push('auth'); + } else if (response.status == 0) { + router.push('error'); + } + } +}); + +var authKey = localStorage.getItem("auth-key") +if (authKey) { + Vue.http.headers.common['x-api-key'] = authKey; +} else { + router.push('auth'); +} + +Vue.toasted.register('toast', + (payload) => { + return ` + + `; + }, + + { + className: "toast-background", + position: 'top-center', + duration: 3000 + }) + + +new Vue({ + router, + render: h => h(App) +}).$mount('#app') + + diff --git a/dashboard/src/router.js b/dashboard/src/router.js new file mode 100644 index 00000000..f05d9515 --- /dev/null +++ b/dashboard/src/router.js @@ -0,0 +1,56 @@ +import Vue from 'vue' +import Router from 'vue-router' +import Models from './views/Models.vue' +import Auth from './views/Auth.vue' +import Rules from './views/Rules.vue' +import PDP from './views/Pdps.vue' +import Admin from './views/Admin.vue' +import ErrorPage from './views/Error.vue' +import Assignments from "./views/Assignments"; + +Vue.use(Router) + +export default new Router({ + routes: [ + { + path: '/auth', + name: 'auth', + component: Auth + }, + { + path: '/', + redirect: { name: 'models' } + }, + { + path: '/models', + name: 'models', + component: Models + }, + { + path: '/rules', + name: 'rules', + component: Rules + }, + { + path: '/assignments', + name: 'assignments', + component: Assignments + }, + { + path: '/pdp', + name: 'pdp', + component: PDP + }, + { + path: '/admin', + name: 'admin', + component: Admin + }, + { + path: '/error', + name: 'error', + component: ErrorPage + }, + + ] +}) diff --git a/dashboard/src/services/Attribute.service.js b/dashboard/src/services/Attribute.service.js new file mode 100644 index 00000000..a00da8f1 --- /dev/null +++ b/dashboard/src/services/Attribute.service.js @@ -0,0 +1,46 @@ +import Vue from 'vue' +import config from '../config.js' +import util from './Util.service' + +var host = config.host; + +var attributeResource; + +var attributesMap = {}; +var attributes = []; + +function loadAttributes(){ + attributeResource = Vue.resource(host + '/attributes{/id}', {}); + + attributeResource.query().then(res => { + createAttributes(res.body); + }, util.displayErrorFunction('Unable to load attributes')); +} + +function createAttributes(attributesData){ + attributes.splice(0, attributes.length); + util.cleanObject(attributesMap); + util.createInternal(attributesData.attributes, attributes, attributesMap); +} + +function getAttribute(id){ + return attributesMap[id]; +} + +function getAttributeId(name){ + for (let i = 0; i < attributes.length; i++){ + let attr = attributes[i]; + for (let j = 0; j < attr.values.length; j++){ + let value = attr.values[j]; + if (value === name){ + return attr.id; + } + } + } +} + +export default { + initialize: loadAttributes, + getAttribute: getAttribute, + getAttributeId: getAttributeId +} \ No newline at end of file diff --git a/dashboard/src/services/Import.service.js b/dashboard/src/services/Import.service.js new file mode 100644 index 00000000..f2cc77ff --- /dev/null +++ b/dashboard/src/services/Import.service.js @@ -0,0 +1,16 @@ +import Vue from 'vue' +import util from './Util.service.js' +import config from '../config.js' + +var host = config.host; + +export default { + importData: async function importData(data) { + var importResource = Vue.resource(host + '/import/', {}); + + return importResource.save(null, data).then(success, util.displayErrorFunction('Unable to import data')); + function success() { + util.displaySuccess('Data imported'); + } + } +} \ No newline at end of file diff --git a/dashboard/src/services/Model.service.js b/dashboard/src/services/Model.service.js new file mode 100644 index 00000000..b9b96743 --- /dev/null +++ b/dashboard/src/services/Model.service.js @@ -0,0 +1,351 @@ +import Vue from 'vue' +import util from './Util.service.js' +import config from '../config.js' + +var host = config.host; + +var modelResource; +var metaRuleResource; +var subjectCategoryResource; +var objectCategoryResource; +var actionCategoryResource; +var attributesResource; + +var modelsMap = {}; +var metaRulesMap = {}; +var subjectCategoriesMap = {}; +var objectCategoriesMap = {}; +var actionCategoriesMap = {}; +var attributesMap = {}; +var models = []; +var metaRules = []; +var orphanMetaRules = []; +var subjectCategories = []; +var objectCategories = []; +var actionCategories = []; +var attributes = []; +var orphanSubjectCategories = []; +var orphanObjectCategories = []; +var orphanActionCategories = []; + +var categoryMap = { + 'subject': { + resource: subjectCategoryResource, + map: subjectCategoriesMap, + list: subjectCategories, + listName: 'subject_categories' + }, + 'object': { + resource: objectCategoryResource, + map: objectCategoriesMap, + list: objectCategories, + listName: 'object_categories' + }, + 'action': { + resource: actionCategoryResource, + map: actionCategoriesMap, + list: actionCategories, + listName: 'action_categories' + }, + 'attribute' : { + resource: attributesResource, + map: attributesMap, + list: attributes, + listName: 'attributes' + } +} + + +function loadModels() { + modelResource = Vue.resource(host + '/models{/id}', {}, {patch: {method: 'PATCH'}}); + metaRuleResource = Vue.resource(host + '/meta_rules{/id}', {}, {patch: {method: 'PATCH'}}); + categoryMap['subject'].resource = subjectCategoryResource = Vue.resource(host + '/subject_categories{/id}'); + categoryMap['object'].resource = objectCategoryResource = Vue.resource(host + '/object_categories{/id}'); + categoryMap['action'].resource = actionCategoryResource = Vue.resource(host + '/action_categories{/id}'); + categoryMap['attribute'].resource = attributesResource = Vue.resource(host + '/attributes{/id}'); + var queries = [ + modelResource.query(), + metaRuleResource.query(), + subjectCategoryResource.query(), + objectCategoryResource.query(), + actionCategoryResource.query(), + attributesResource.query() + ] + + var result = Promise.all(queries).then(function (result) { + createModels(result[0].body, result[1].body, result[2].body, result[3].body, result[4].body, result[5].body) + }) + + return result; +} + +function createModels(modelsData, metarulesData, subjectCategoriesData, objectCategoriesData, actionCategoriesData, attributesData) { + util.cleanObject(modelsMap); + util.cleanObject(metaRulesMap); + util.cleanObject(subjectCategoriesMap); + util.cleanObject(objectCategoriesMap); + util.cleanObject(actionCategoriesMap); + util.cleanObject(attributesMap); + models.splice(0, models.length); + metaRules.splice(0, metaRules.length); + subjectCategories.splice(0, subjectCategories.length); + objectCategories.splice(0, objectCategories.length); + actionCategories.splice(0, actionCategories.length); + attributes.splice(0, attributes.length); + if (subjectCategoriesData.subject_categories) createCategoryInternal('subject', subjectCategoriesData.subject_categories); + if (objectCategoriesData.object_categories) createCategoryInternal('object', objectCategoriesData.object_categories); + if (actionCategoriesData.action_categories) createCategoryInternal('action', actionCategoriesData.action_categories); + if (attributesData.attributes) createCategoryInternal('attribute', attributesData.attributes); + if (metarulesData.meta_rules) createMetaRuleInternal(metarulesData.meta_rules); + if (modelsData.models) createModelInternal(modelsData.models); + + updateOrphan(); +} + +function mapModel(model) { + util.mapIdToItem(model.meta_rules, metaRulesMap); +} + +function createModelInternal(data) { + return util.createInternal(data, models, modelsMap, mapModel); +} + +function updateModelInternal(data) { + return util.updateInternal(data, modelsMap, mapModel); +} + +function removeModelInternal(id) { + return util.removeInternal(id, models, modelsMap); +} + +function mapIdToItemWithAttributes(categories, categoriesMap, attributes, attributesMap) { + let categoriesToRemove = [] + if (categories) { + var index2 = 0; + for (var index = 0; index < categories.length; index++) { + var id = categories[index]; + if (categoriesMap[id]) + categories[index] = categoriesMap[id]; + else { + if(id.includes('attributes:')){ + const newId = id.split(':')[1]; + if (attributesMap[newId]){ + attributes[index2++] = attributesMap[newId]; + } + categoriesToRemove.push(index) + } + } + } + for (let i = categoriesToRemove.length - 1; i >= 0; i--){ + categories.splice(categoriesToRemove[i], 1); + } + } +} + +function cleanCategoryByRemovingAttributes(categories, attributesMap){ + let categoriesToRemove = [] + if (categories) { + for (let index = 0; index < categories.length; index++){ + var category = categories[index]; + if (attributesMap[category.name]){ + categoriesToRemove.push(index) + } + } + for (let i = categoriesToRemove.length - 1; i >= 0; i--){ + categories.splice(categoriesToRemove[i], 1); + } + } +} + +function mapMetaRule(metaRule) { + metaRule.subjectAttributes = []; + metaRule.objectAttributes = []; + metaRule.actionAttributes = []; + mapIdToItemWithAttributes(metaRule.subject_categories, subjectCategoriesMap, metaRule.subjectAttributes, attributesMap); + mapIdToItemWithAttributes(metaRule.object_categories, objectCategoriesMap, metaRule.objectAttributes,attributesMap); + mapIdToItemWithAttributes(metaRule.action_categories, actionCategoriesMap, metaRule.actionAttributes, attributesMap); + cleanCategoryByRemovingAttributes(subjectCategories, attributesMap); + cleanCategoryByRemovingAttributes(objectCategories, attributesMap); + cleanCategoryByRemovingAttributes(actionCategories, attributesMap); +} + +function createMetaRuleInternal(data) { + return util.createInternal(data, metaRules, metaRulesMap, mapMetaRule); +} + +function updateMetaRuleInternal(data) { + return util.updateInternal(data, metaRulesMap, mapMetaRule); +} + +function removeMetaRuleInternal(id) { + return util.removeInternal(id, metaRules, metaRulesMap); +} + +function createCategoryInternal(type, data) { + var categoryValue = categoryMap[type]; + + return util.createInternal(data, categoryValue.list, categoryValue.map) +} + +function removeCategoryInternal(type, id) { + var categoryValue = categoryMap[type]; + return util.removeInternal(id, categoryValue.list, categoryValue.map); +} + +function updateOrphan() { + updateOrphanInternal(metaRules, orphanMetaRules, models, "meta_rules"); + updateOrphanInternal(subjectCategories, orphanSubjectCategories, metaRules, "subject_categories"); + updateOrphanInternal(objectCategories, orphanObjectCategories, metaRules, "object_categories"); + updateOrphanInternal(actionCategories, orphanActionCategories, metaRules, "action_categories"); +} + +function updateOrphanInternal(list, orphanList, parentList, childListName) { + orphanList.splice(0, orphanList.length); + util.pushAll(orphanList, list); + for (var i = 0; i < parentList.length; i++) { + var parent = parentList[i]; + var children = parent[childListName]; + if (children) { + for (var j = 0; j < children.length; j++) { + var child = children[j]; + if (child){ + var notOrphanIndex = util.indexOf(orphanList, "id", child.id); + if (notOrphanIndex >= 0) { + orphanList.splice(notOrphanIndex, 1); + } + else{ + for (var k = 0; k < attributes.length; k++){ + const attr = attributes[k]; + notOrphanIndex = util.indexOf(orphanList, "name", attr.id); + if (notOrphanIndex >= 0) { + orphanList.splice(notOrphanIndex, 1); + } + } + } + + } + } + } + } +} + +function getAttributesForModelId(modelId) { + let model = modelsMap[modelId]; + let attrs = [] + + for (let i = 0; i < model.meta_rules.length; i++){ + let metaRule = model.meta_rules[i]; + let j; + for (j = 0; j < metaRule.subjectAttributes.length; j++){ + attrs.push(metaRule.subjectAttributes[j]) + } + for (j = 0; j < metaRule.objectAttributes.length; j++){ + attrs.push(metaRule.objectAttributes[j]) + } + for (j = 0; j < metaRule.actionAttributes.length; j++){ + attrs.push(metaRule.actionAttributes[j]) + } + } + return attrs; +} + +export default { + initialize: loadModels, + createModels: createModels, + models: models, + metaRules: metaRules, + orphanMetaRules: orphanMetaRules, + orphanSubjectCategories: orphanSubjectCategories, + orphanObjectCategories: orphanObjectCategories, + orphanActionCategories: orphanActionCategories, + subjectCategories: subjectCategories, + objectCategories: objectCategories, + actionCategories: actionCategories, + getModel: function getModel(id) { + return modelsMap[id]; + }, + getAttributesForModelId: getAttributesForModelId, + createModel: function createModel(model) { + model.meta_rules = []; + modelResource.save(null, model).then(success, util.displayErrorFunction('Unable to create model')); + + function success(data) { + createModelInternal(data.body.models); + util.displaySuccess('Model created'); + } + }, + removeModel: function removeModel(model) { + modelResource.remove({ id: model.id }).then(success, util.displayErrorFunction('Unable to remove model')); + + function success() { + removeModelInternal(model.id); + updateOrphan(); + util.displaySuccess('Model removed'); + } + }, + updateModel: function updateModel(model) { + util.mapItemToId(model.meta_rules) + modelResource.patch({ id: model.id }, model).then(success, util.displayErrorFunction('Unable to update model')); + + function success(data) { + updateModelInternal(data.body.models); + + updateOrphan(); + util.displaySuccess('Model updated'); + } + }, + getMetaRule: function getMetaRule(id) { + return metaRulesMap[id]; + }, + createMetaRule: function createMetaRule(metaRule) { + metaRule.subject_categories = []; + metaRule.object_categories = []; + metaRule.action_categories = []; + + return metaRuleResource.save(null, metaRule).then(function (data) { + util.displaySuccess('Meta Rule created'); + return createMetaRuleInternal(data.body.meta_rules)[0]; + }, util.displayErrorFunction('Unable to create meta rule')) + }, + updateMetaRule: function updateMetaRule(metaRule) { + util.mapItemToId(metaRule.subject_categories); + util.mapItemToId(metaRule.object_categories); + util.mapItemToId(metaRule.action_categories); + metaRuleResource.patch({ id: metaRule.id }, metaRule).then(success, util.displayErrorFunction('Unable to update meta rule')); + + function success(data) { + updateMetaRuleInternal(data.body.meta_rules); + updateOrphan(); + util.displaySuccess('Meta Rule updated'); + } + }, + removeMetaRule: function removeMetaRule(metaRule) { + metaRuleResource.remove({ id: metaRule.id }).then(success, util.displayErrorFunction('Unable to remove meta rule')); + + function success() { + removeMetaRuleInternal(metaRule.id); + updateOrphan(); + util.displaySuccess('Meta Rule removed'); + } + }, + getCategory: function getCategory(type, id) { + return categoryMap[type].map[id]; + }, + createCategory: function createCategory(type, category) { + var categoryValue = categoryMap[type]; + return categoryValue.resource.save(null, category).then(function (data) { + util.displaySuccess('Category created'); + return createCategoryInternal(type, data.body[categoryValue.listName])[0]; + }, util.displayErrorFunction('Unable to create category')) + }, + removeCategory: function removeCategory(type, category) { + var categoryValue = categoryMap[type]; + categoryValue.resource.remove({ id: category.id }).then(success, util.displayErrorFunction('Unable to remove category')); + + function success() { + removeCategoryInternal(type, category.id); + updateOrphan(); + util.displaySuccess('Category removed'); + } + }, +} \ No newline at end of file diff --git a/dashboard/src/services/Pdp.service.js b/dashboard/src/services/Pdp.service.js new file mode 100644 index 00000000..e0c286a0 --- /dev/null +++ b/dashboard/src/services/Pdp.service.js @@ -0,0 +1,92 @@ +import Vue from 'vue' +import util from './Util.service.js' +import config from '../config.js' + +var host = config.host; + +var pdpResource; +var policyResource; + +var pdpsMap = {}; +var pdps = []; +var policiesMap = {}; +var policies = []; + +function loadPdps() { + pdpResource = Vue.resource(host + '/pdp{/id}', {}, {patch: {method: 'PATCH'}}); + policyResource = Vue.resource(host + '/policies{/id}', {}); + + var queries = [ + pdpResource.query(), + policyResource.query(), + ] + Promise.all(queries).then(function (result) { + createPdps(result[0].body, result[1].body) + }) + +} + +function createPdps(pdpsData, policiesData) { + pdps.splice(0, pdps.length); + policies.splice(0, policies.length); + util.cleanObject(pdpsMap); + util.cleanObject(policiesMap); + + util.createInternal(policiesData.policies, policies, policiesMap); + createPdpInternal(pdpsData.pdps); +} + +function mapPdp(pdp) { + util.mapIdToItem(pdp.security_pipeline, policiesMap); + pdp.project = pdp.vim_project_id; +} + +function createPdpInternal(data) { + return util.createInternal(data, pdps, pdpsMap, mapPdp); +} + +function updatePdpInternal(data) { + return util.updateInternal(data, pdpsMap, mapPdp); +} + +function removePdpInternal(id) { + return util.removeInternal(id, pdps, pdpsMap); +} + +export default { + initialize: loadPdps, + createPdps: createPdps, + pdps: pdps, + policies: policies, + createPdp: function createPdp(pdp) { + pdpResource.save(null, pdp).then(success, util.displayErrorFunction('Unable to create PDP')); + + function success(data) { + createPdpInternal(data.body.pdps); + util.displaySuccess('PDP created'); + } + }, + removePdp: function removePdp(pdp) { + pdpResource.remove({ id: pdp.id }).then(success, util.displayErrorFunction('Unable to remove PDP')); + + function success() { + removePdpInternal(pdp.id); + util.displaySuccess('PDP removed'); + } + }, + updatePdp: function updatePdp(pdp) { + util.mapItemToId(pdp.security_pipeline); + pdp.vim_project_id = pdp.project; + pdpResource.patch({ id: pdp.id }, pdp).then(success, util.displayErrorFunction('Unable to update PDP')); + + function success(data) { + updatePdpInternal(data.body.pdps) + util.displaySuccess('PDP updated'); + } + }, + getPolicy: function getPolicy(id) { + return policiesMap[id]; + }, +} + + diff --git a/dashboard/src/services/Policy.service.js b/dashboard/src/services/Policy.service.js new file mode 100644 index 00000000..433680e9 --- /dev/null +++ b/dashboard/src/services/Policy.service.js @@ -0,0 +1,470 @@ +import Vue from 'vue' +import util from './Util.service.js' +import ModelService from './Model.service.js' +import AttributeService from './Attribute.service' +import config from '../config.js' + +var host = config.host; + +var policyResource; +var policyRulesResource; + +var categoryMap = { + 'subject': { + arrayName: "subjectData", + mapName: "subjectDataMap", + responseName: "subject_data", + perimeterResponseName: "subjects", + assignmentResponseName: "subject_assignments", + unusedArrayName: "unusedSubjectData", + }, + 'object': { + arrayName: "objectData", + mapName: "objectDataMap", + responseName: "object_data", + perimeterResponseName: "objects", + assignmentResponseName: "object_assignments", + unusedArrayName: "unusedObjectData", + }, + 'action': { + arrayName: "actionData", + mapName: "actionDataMap", + responseName: "action_data", + perimeterResponseName: "actions", + assignmentResponseName: "action_assignments", + unusedArrayName: "unusedActionData", + } +} + +var policiesMap = {}; +var policies = []; + +function loadPolicies() { + policyResource = Vue.resource(host + '/policies{/id}', {}, {patch: {method: 'PATCH'}}); + categoryMap['subject'].policyPerimeterResource = Vue.resource(host + '/policies{/policy_id}/subjects{/perimeter_id}', {}); + categoryMap['object'].policyPerimeterResource = Vue.resource(host + '/policies{/policy_id}/objects{/perimeter_id}', {}, ); + categoryMap['action'].policyPerimeterResource = Vue.resource(host + '/policies{/policy_id}/actions{/perimeter_id}', {}, ); + categoryMap['subject'].perimeterResource = Vue.resource(host + '/subjects{/perimeter_id}', {}, {patch: {method: 'PATCH'}}); + categoryMap['object'].perimeterResource = Vue.resource(host + '/objects{/perimeter_id}', {}, {patch: {method: 'PATCH'}}); + categoryMap['action'].perimeterResource = Vue.resource(host + '/actions{/perimeter_id}', {}, {patch: {method: 'PATCH'}}); + categoryMap['subject'].assignmentResource = Vue.resource(host + '/policies{/policy_id}/subject_assignments{/perimeter_id}{/category_id}{/data_id}', {}, ); + categoryMap['object'].assignmentResource = Vue.resource(host + '/policies{/policy_id}/object_assignments{/perimeter_id}{/category_id}{/data_id}', {}, ); + categoryMap['action'].assignmentResource = Vue.resource(host + '/policies{/policy_id}/action_assignments{/perimeter_id}{/category_id}{/data_id}', {}, ); + var queries = [ + policyResource.query(), + ModelService.initialize(), + AttributeService.initialize() + ] + + Promise.all(queries).then(function (result) { + createPolicies(result[0].body); + }) +} + +function createPolicies(policiesData) { + policies.splice(0, policies.length); + util.cleanObject(policiesMap); + createPolicyInternal(policiesData.policies); +} + +function mapPolicy(policy) { + policy.rulesPopulated = false; + policy.rules = []; + policy.subjectData = []; + policy.objectData = []; + policy.actionData = []; + policy.unusedSubjectData = []; + policy.unusedObjectData = []; + policy.unusedActionData = []; + policy.attributes = []; + if (policy.model_id) { + policy.model = ModelService.getModel(policy.model_id); + policy.attributes = ModelService.getAttributesForModelId(policy.model_id); + } +} + +function createPolicyInternal(data) { + return util.createInternal(data, policies, policiesMap, mapPolicy); +} + +function removePolicyInternal(id) { + return util.removeInternal(id, policies, policiesMap); +} + +function updatePolicyInternal(data) { + return util.updateInternal(data, policiesMap, mapPolicy); +} + +function removeRuleInternal(policy, rule) { + policy.rules.splice(policy.rules.indexOf(rule), 1); + updateUnusedData(policy); +} + +function loadPolicyRule(policy) { + if (!policy.rulesPopulated) { + policyRulesResource = Vue.resource(host + '/policies{/policy_id}/rules{/rule_id}', {}, {patch: {method: 'PATCH'}}); + categoryMap['subject'].resource = Vue.resource(host + '/policies{/policy_id}/subject_data{/category_id}{/data_id}', {}); + categoryMap['object'].resource = Vue.resource(host + '/policies{/policy_id}/object_data{/category_id}{/data_id}', {}); + categoryMap['action'].resource = Vue.resource(host + '/policies{/policy_id}/action_data{/category_id}{/data_id}', {}); + var queries = [ + policyRulesResource.query({ policy_id: policy.id }), + categoryMap['subject'].resource.query({ policy_id: policy.id }), + categoryMap['object'].resource.query({ policy_id: policy.id }), + categoryMap['action'].resource.query({ policy_id: policy.id }) + ] + + Promise.all(queries).then(function (result) { + createRules(policy, result[0].body, result[1].body, result[2].body, result[3].body); + updateUnusedData(policy); + }, util.displayErrorFunction('Unable to load rules')) + } +} + +function updateUnusedData(policy) { + policy.unusedSubjectData.splice(0, policy.unusedSubjectData.length); + util.pushAll(policy.unusedSubjectData, policy.subjectData); + + policy.unusedObjectData.splice(0, policy.unusedObjectData.length); + util.pushAll(policy.unusedObjectData, policy.objectData); + + policy.unusedActionData.splice(0, policy.unusedActionData.length); + util.pushAll(policy.unusedActionData, policy.actionData); + + for (var i = 0; i < policy.rules.length; i++) { + var rule = policy.rules[i]; + removeUsedData(rule.subjectData, policy.unusedSubjectData); + removeUsedData(rule.objectData, policy.unusedObjectData); + removeUsedData(rule.actionData, policy.unusedActionData); + } +} + +function removeUsedData(list, orphanList) { + for (var j = 0; j < list.length; j++) { + var data = list[j]; + if (data) { + var notOrphanIndex = util.indexOf(orphanList, "id", data.id); + if (notOrphanIndex >= 0) { + orphanList.splice(notOrphanIndex, 1); + } + } + } +} + +function transformData(list) { + var result = {}; + for (var index = 0; index < list.length; index++) { + var data = list[index].data; + for (var key in data) { + if (data.hasOwnProperty(key)) { + result[key] = data[key]; + } + } + } + return result; +} + +function createRules(policy, rulesData, subjectsData, objectsData, actionsData) { + policy.rules = rulesData ? rulesData.rules.rules : []; + policy.subjectDataMap = transformData(subjectsData.subject_data); + policy.subjectData = util.mapToArray(policy.subjectDataMap); + policy.objectDataMap = transformData(objectsData.object_data); + policy.objectData = util.mapToArray(policy.objectDataMap); + policy.actionDataMap = transformData(actionsData.action_data); + policy.actionData = util.mapToArray(policy.actionDataMap); + for (var i = 0; i < policy.rules.length; i++) { + var rule = policy.rules[i]; + populateRule(policy, rule); + } + policy.rulesPopulated = true; +} + +function populateRule(policy, rule) { + if (rule.meta_rule_id) { + rule.metaRule = ModelService.getMetaRule(rule.meta_rule_id); + } + if (rule.metaRule) { + var j = 0; + var k, id; + rule.subjectData = []; + rule.objectData = []; + rule.actionData = []; + rule.attributeData = []; + + for (k = 0; k < rule.metaRule.subject_categories.length; k++) { + id = rule.rule[j + k]; + if (policy.subjectDataMap[id]) + rule.subjectData.push(policy.subjectDataMap[id]); + } + j += k; + for (k = 0; k < rule.metaRule.object_categories.length; k++) { + id = rule.rule[j + k]; + if (policy.objectDataMap[id]) + rule.objectData.push(policy.objectDataMap[id]); + } + j += k; + for (k = 0; k < rule.metaRule.action_categories.length; k++) { + id = rule.rule[j + k]; + if (policy.actionDataMap[id]) { + rule.actionData.push(policy.actionDataMap[id]); + } + } + + for (const value of rule.rule.values()){ + if (value.includes("attributes:")){ + let attrName = value.split(':')[1]; + let attrId = AttributeService.getAttributeId(attrName); + rule.attributeData.push({id: attrId, name: attrName}); + + } + } + } + return rule; +} + +function updateRule(policy, rule, decision){ + return new Promise(resolveUpdateRule => { + var body = { + "instructions":[ + {"decision": decision} + ] + }; + + policyRulesResource.patch({policy_id: policy.id, rule_id: rule.id}, body).then(success, util.displayErrorFunction('Unable to update Rule')); + + function success(data){ + resolveUpdateRule(data.body.rules[rule.id].instructions); + } + }); +} + +function filterRuleBySpecificItem(filteredRules, rule, items, filter){ + items.forEach(item => { + if (item){ + if (filter == null || item.name.indexOf(filter) >= 0){ + if (!(filteredRules.includes(rule))) + filteredRules.push(rule) + } + } + + }); +} + +function interArray(array1, array2){ + let inter = []; + + + for (let i = 0; i < array1.length; i++){ + for (let j = 0; j < array2.length; j++){ + if (array1[i] === array2[j]) + inter.push(array2[j]); + } + } + return inter; +} + + +function filterByRules(rules, filters){ + let filteredRules = []; + let filteredByWords = []; + + + if (filters === ""){ + filteredRules = rules; + } else { + filters = filters.split(' '); + filters.forEach( filter => { + if (filter !== "") { + let tmp = []; + rules.forEach((rule) => { + + filterRuleBySpecificItem(tmp, rule, rule.subjectData, filter); + filterRuleBySpecificItem(tmp, rule, rule.objectData, filter); + filterRuleBySpecificItem(tmp, rule, rule.actionData, filter); + filterRuleBySpecificItem(tmp, rule, rule.attributeData, filter); + + filteredByWords.push(tmp); + }); + + } + }); + + filteredRules = filteredByWords[0]; + for (let i = 1; i < filteredByWords.length; i++){ + filteredRules = interArray(filteredRules, filteredByWords[i]); + } + } + + return filteredRules; +} + +function policyRuleWithAttributes(policy){ + const meta_rules = policy.model.meta_rules; + + for (let i = 0; i < meta_rules.length; i++){ + const meta_rule = meta_rules[i]; + if (meta_rule.actionAttributes.length || meta_rule.subjectAttributes.length || meta_rule.objectAttributes.length) + return true; + } + return false; +} + +export default { + policyRuleWithAttributes: policyRuleWithAttributes, + filterByRules: filterByRules, + initialize: loadPolicies, + createPolicies: createPolicies, + policies: policies, + getPolicy: function getPolicy(id) { + return policiesMap[id]; + }, + createPolicy: function createPolicy(policy) { + policyResource.save(null, policy).then(success, util.displayErrorFunction('Unable to create Policy')); + + function success(data) { + createPolicyInternal(data.body.policies); + util.displaySuccess('Policy created'); + } + }, + removePolicy: function removePolicy(policy) { + policyResource.remove({ id: policy.id }, null).then(success, util.displayErrorFunction('Unable to remove Policy')); + + function success() { + removePolicyInternal(policy.id); + util.displaySuccess('Policy removed'); + } + }, + updatePolicy: function updatePolicy(policy) { + policyResource.patch({ id: policy.id }, policy).then(success, util.displayErrorFunction('Unable to update Policy')); + + function success(data) { + updatePolicyInternal(data.body.policies) + util.displaySuccess('Policy updated'); + } + }, + populatePolicy: loadPolicyRule, + createRules: createRules, + updateRule: updateRule, + addRuleToPolicy: function addRuleToPolicy(policy, rule) { + policyRulesResource.save({ policy_id: policy.id }, rule).then(success, util.displayErrorFunction('Unable to create Rule')); + + function success(data) { + var rules = util.mapToArray(data.body.rules); + for (var i = 0; i < rules.length; i++) { + var rule = rules[i]; + policy.rules.push(populateRule(policy, rule)) + } + util.displaySuccess('Rule created'); + updateUnusedData(policy); + } + }, + removeRuleFromPolicy: function removeRuleFromPolicy(policy, rule) { + policyRulesResource.remove({ policy_id: policy.id, rule_id: rule.id }, null).then(success, util.displayErrorFunction('Unable to remove Rule')); + + function success() { + removeRuleInternal(policy, rule); + util.displaySuccess('Rule removed'); + } + }, + createData: function createData(type, policy, categoryId, dataCategory) { + var categoryValue = categoryMap[type]; + return categoryValue.resource.save({ policy_id: policy.id, category_id: categoryId }, dataCategory).then( + function (data) { + var result = util.createInternal(data.body[categoryValue.responseName].data, policy[categoryValue.arrayName], policy[categoryValue.mapName]); + util.displaySuccess('Data created'); + util.pushAll(policy[categoryValue.unusedArrayName], result); + return result; + }, + util.displayErrorFunction('Unable to create Data') + ); + }, + removeData: function removeData(type, policy, data) { + var categoryValue = categoryMap[type]; + return categoryValue.resource.remove({ policy_id: policy.id, category_id: data.category_id, data_id: data.id }).then( + function () { + policy[categoryValue.arrayName].splice(policy.subjectData.indexOf(data), 1); + policy[categoryValue.unusedArrayName].splice(policy.unusedSubjectData.indexOf(data), 1); + delete policy[categoryValue.mapName][data.id]; + util.displaySuccess('Data removed'); + }, + util.displayErrorFunction('Unable to remove Data') + ); + }, + createPerimeter: function createPerimeter(type, policy, perimeter) { + var categoryValue = categoryMap[type]; + return categoryValue.policyPerimeterResource.save({ policy_id: policy.id }, perimeter).then( + function (data) { + util.displaySuccess('Perimeter created'); + return util.mapToArray(data.body[categoryValue.perimeterResponseName]); + }, + util.displayErrorFunction('Unable to create Perimeter') + ); + }, + removePerimeterFromPolicy: function removePerimeterFromPolicy(type, policy, perimeter) { + var categoryValue = categoryMap[type]; + + return categoryValue.policyPerimeterResource.remove({ policy_id: policy.id, perimeter_id: perimeter.id }, null).then( + function () { + util.displaySuccess('Perimeter removed'); + return perimeter; + }, + util.displayErrorFunction('Unable to remove Perimeter') + ) + }, + addPerimeterToPolicy: function addPerimeterToPolicy(type, policy, perimeter) { + var categoryValue = categoryMap[type]; + perimeter.policy_list.push(policy.id); + var perimeterClone = util.clone(perimeter); + delete perimeterClone.policy_list; + return categoryValue.policyPerimeterResource.save({ policy_id: policy.id }, perimeterClone).then( + function () { + util.displaySuccess('Perimeter added'); + }, + util.displayErrorFunction('Unable to add Perimeter') + ) + }, + loadPerimetersAndAssignments: function loadPerimetersAndAssignments(type, policy) { + var categoryValue = categoryMap[type]; + var queries = [ + categoryValue.perimeterResource.query(), + categoryValue.policyPerimeterResource.query({ policy_id: policy.id }), + categoryValue.assignmentResource.query({ policy_id: policy.id }), + ] + + return Promise.all(queries).then(function (data) { + var result = {}; + result.assignments = util.mapToArray(data[2].body[categoryValue.assignmentResponseName]); + result.perimetersMap = data[1].body[categoryValue.perimeterResponseName]; + result.perimeters = util.mapToArray(result.perimetersMap); + result.allPerimeters = util.mapToArray(data[0].body[categoryValue.perimeterResponseName]); + return result; + }, util.displayErrorFunction('Unable to load Perimeters')) + + }, + createAssignment: function createAssignment(type, policy, perimeter, data) { + var categoryValue = categoryMap[type]; + var assignment = { + "id": perimeter.id, + "category_id": data.category_id, + "data_id": data.id, + "policy_id": policy.id + } + return categoryValue.assignmentResource.save({ policy_id: policy.id }, assignment).then( + function (data) { + util.displaySuccess('Assignment created'); + return util.mapToArray(data.body[categoryValue.assignmentResponseName]); + }, + util.displayErrorFunction('Unable to create Assignment') + ) + }, + removeAssignment: function removeAssignment(type, policy, perimeter, data) { + var categoryValue = categoryMap[type]; + + return categoryValue.assignmentResource.remove({ policy_id: policy.id, perimeter_id: perimeter.id, category_id: data.category_id, data_id: data.id }, null).then( + function () { + util.displaySuccess('Assignment removed'); + }, + util.displayErrorFunction('Unable to remove Assignment') + ) + }, +} + diff --git a/dashboard/src/services/Util.service.js b/dashboard/src/services/Util.service.js new file mode 100644 index 00000000..a6b53d6f --- /dev/null +++ b/dashboard/src/services/Util.service.js @@ -0,0 +1,153 @@ +import Vue from 'vue' + +export default { + sortByName(items) { + return items + .sort((item1, item2) => { + return item1.name.localeCompare(item2.name); + }); + }, + filterAndSortByName(items, filter) { + return items + .filter(item => { + return filter == null || item.name.indexOf(filter) >= 0; + }) + .sort((item1, item2) => { + return item1.name.localeCompare(item2.name); + }); + }, + clone: function clone(src) { + return JSON.parse(JSON.stringify(src)); + }, + + mapToArray: function mapToArray(map, action) { + var result = [] + for (var key in map) { + if (map.hasOwnProperty(key)) { + var item = map[key]; + item.id = key; + if (action != null) { + action(item); + } + result.push(item); + } + } + return result; + }, + + + mapIdToItem: function mapIdToItem(array, map) { + if (array) { + for (var index = 0; index < array.length; index++) { + var id = array[index]; + if (map[id]) + array[index] = map[id]; + } + } + }, + + mapItemToId: function mapItemToId(array) { + if (array) { + for (var index = 0; index < array.length; index++) { + var item = array[index]; + array[index] = item.id; + } + } + }, + + addToMap: function addToMap(array, map) { + if (array) { + for (var index = 0; index < array.length; index++) { + var item = array[index]; + map[item.id] = item; + } + } + }, + + updateObject: function updateObject(object, newObject) { + for (var key in newObject) { + if (newObject.hasOwnProperty(key)) { + object[key] = newObject[key]; + } + } + }, + + cleanObject: function cleanObject(object) { + for (var key in object) { + if (object.hasOwnProperty(key)) { + delete object[key]; + } + } + }, + + pushAll: function pushAll(array, arrayToPush) { + for (var i = 0; i < arrayToPush.length; i += 1) { + array.push(arrayToPush[i]); + } + }, + + indexOf: function indexOf(array, property, value) { + for (var i = 0; i < array.length; i += 1) { + if (array[i][property] === value) { + return i; + } + } + return -1; + }, + + createInternal: function createInternal(data, array, map, action) { + var added = this.mapToArray(data, action) + this.addToMap(added, map); + this.pushAll(array, added); + + return added; + }, + + updateInternal: function updateInternal(data, map, action) { + var updated = this.mapToArray(data, action) + var result = [] + for (var index = 0; index < updated.length; index++) { + var item = updated[index]; + this.updateObject(map[item.id], item) + result.push(map[item.id]) + } + return result; + }, + + removeInternal: function removeInternal(id, array, map) { + var old = map[id]; + delete map[old.id]; + array.splice(array.indexOf(old), 1); + return old; + }, + + arrayToTitleMap: function arrayToTitleMap(array) { + return array.map(function (item) { + return { value: item.id, name: item.name } + }).sort(function (itemA, itemB) { + return itemA.name.localeCompare(itemB.name); + }) + }, + + displayErrorFunction: function displayErrorFunction(message) { + return function (response) { + var text = message; + if (response && response.data && response.data.message) { + text += ' (' + response.data.message + ')' + } + console.log(text); + Vue.toasted.global.toast({message: text, type: 'danger', title: 'Error'}); + } + }, + + displaySuccess: function displaySuccess(message) { + Vue.toasted.global.toast({message: message, type: 'success', title: 'Success'}); + }, + + displayError: function displayError(message) { + Vue.toasted.global.toast({message: message, type: 'danger', title: 'Error'}); + }, + + + +} \ No newline at end of file diff --git a/dashboard/src/views/Admin.vue b/dashboard/src/views/Admin.vue new file mode 100644 index 00000000..414e68a0 --- /dev/null +++ b/dashboard/src/views/Admin.vue @@ -0,0 +1,52 @@ + + + + + diff --git a/dashboard/src/views/Assignments.vue b/dashboard/src/views/Assignments.vue new file mode 100644 index 00000000..d0e500e3 --- /dev/null +++ b/dashboard/src/views/Assignments.vue @@ -0,0 +1,54 @@ + + + + + \ No newline at end of file diff --git a/dashboard/src/views/Auth.vue b/dashboard/src/views/Auth.vue new file mode 100644 index 00000000..c057e284 --- /dev/null +++ b/dashboard/src/views/Auth.vue @@ -0,0 +1,65 @@ + + + diff --git a/dashboard/src/views/Error.vue b/dashboard/src/views/Error.vue new file mode 100644 index 00000000..528fb8aa --- /dev/null +++ b/dashboard/src/views/Error.vue @@ -0,0 +1,8 @@ + + + + diff --git a/dashboard/src/views/Models.vue b/dashboard/src/views/Models.vue new file mode 100644 index 00000000..bdd46483 --- /dev/null +++ b/dashboard/src/views/Models.vue @@ -0,0 +1,80 @@ + + + diff --git a/dashboard/src/views/Pdps.vue b/dashboard/src/views/Pdps.vue new file mode 100644 index 00000000..778f23fe --- /dev/null +++ b/dashboard/src/views/Pdps.vue @@ -0,0 +1,53 @@ + + + + + diff --git a/dashboard/src/views/Rules.vue b/dashboard/src/views/Rules.vue new file mode 100644 index 00000000..042b00c0 --- /dev/null +++ b/dashboard/src/views/Rules.vue @@ -0,0 +1,50 @@ + + + -- cgit