aboutsummaryrefslogtreecommitdiffstats
path: root/moonv4/moon_gui/static/app/services
diff options
context:
space:
mode:
Diffstat (limited to 'moonv4/moon_gui/static/app/services')
-rw-r--r--moonv4/moon_gui/static/app/services/gui/alert.service.js39
-rw-r--r--moonv4/moon_gui/static/app/services/gui/browser.service.js47
-rw-r--r--moonv4/moon_gui/static/app/services/gui/form.service.js47
-rw-r--r--moonv4/moon_gui/static/app/services/gui/menu.service.js49
-rw-r--r--moonv4/moon_gui/static/app/services/gui/security.pipeline.service.js29
-rw-r--r--moonv4/moon_gui/static/app/services/gui/util.service.js66
-rw-r--r--moonv4/moon_gui/static/app/services/gui/version.service.js27
-rw-r--r--moonv4/moon_gui/static/app/services/moon/model/model.service.js105
-rw-r--r--moonv4/moon_gui/static/app/services/moon/pdp.service.js128
-rw-r--r--moonv4/moon_gui/static/app/services/moon/policy/parameters/assignements.service.js96
-rw-r--r--moonv4/moon_gui/static/app/services/moon/policy/parameters/data.service.js196
-rw-r--r--moonv4/moon_gui/static/app/services/moon/policy/parameters/perimeter.service.js419
-rw-r--r--moonv4/moon_gui/static/app/services/moon/policy/parameters/rule.service.js49
-rw-r--r--moonv4/moon_gui/static/app/services/moon/policy/policy.service.js108
-rw-r--r--moonv4/moon_gui/static/app/services/moon/rule/metadata.service.js354
-rw-r--r--moonv4/moon_gui/static/app/services/moon/rule/metarule.service.js208
-rw-r--r--moonv4/moon_gui/static/app/services/partner/authentication.service.js106
-rw-r--r--moonv4/moon_gui/static/app/services/partner/nova.service.js35
-rw-r--r--moonv4/moon_gui/static/app/services/partner/project.service.js60
19 files changed, 2168 insertions, 0 deletions
diff --git a/moonv4/moon_gui/static/app/services/gui/alert.service.js b/moonv4/moon_gui/static/app/services/gui/alert.service.js
new file mode 100644
index 00000000..8435eab1
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/gui/alert.service.js
@@ -0,0 +1,39 @@
+/**
+ * @author arnaud marhin<arnaud.marhin@orange.com>
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('alertService', alertService);
+
+ alertService.$inject = [ 'toaster'];
+
+ function alertService( toaster) {
+
+ var service = {};
+
+ service.alertError = alertError;
+ service.alertSuccess = alertSuccess;
+ service.alertInfo = alertInfo;
+
+ return service;
+
+ function alertError(msg){
+ toaster.pop('error', null, msg, 5000);
+ }
+
+ function alertSuccess(msg){
+ toaster.pop('success', null, msg, 5000);
+ }
+
+ function alertInfo(msg){
+ toaster.pop('note', null, msg, 5000);
+ }
+
+ }
+
+})();
diff --git a/moonv4/moon_gui/static/app/services/gui/browser.service.js b/moonv4/moon_gui/static/app/services/gui/browser.service.js
new file mode 100644
index 00000000..88c693a8
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/gui/browser.service.js
@@ -0,0 +1,47 @@
+/**
+ * @author arnaud marhin<arnaud.marhin@orange.com>
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('browserService', browserService);
+
+ function browserService() {
+
+ var service = {};
+
+ service.sayWho = sayWho;
+
+ return service;
+
+ function sayWho() {
+
+ var ua= navigator.userAgent, tem,
+
+ M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
+
+ if(/trident/i.test(M[1])){
+ tem= /\brv[ :]+(\d+)/g.exec(ua) || [];
+ return 'IE '+(tem[1] || '');
+ }
+
+ if(M[1]=== 'Chrome'){
+ tem= ua.match(/\bOPR\/(\d+)/);
+ if(tem!= null){ return 'Opera '+tem[1];}
+ }
+
+ M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
+
+ if((tem= ua.match(/version\/(\d+)/i))!= null) M.splice(1, 1, tem[1]);
+
+ return M.join(' ');
+
+ };
+
+ };
+
+})();
diff --git a/moonv4/moon_gui/static/app/services/gui/form.service.js b/moonv4/moon_gui/static/app/services/gui/form.service.js
new file mode 100644
index 00000000..bc137943
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/gui/form.service.js
@@ -0,0 +1,47 @@
+/**
+ * @author arnaud marhin<arnaud.marhin@orange.com>
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('formService', formService);
+
+ function formService() {
+
+ var service = {};
+
+ service.isInvalid = isInvalid;
+ service.checkFieldsValidity = checkFieldsValidity;
+
+ return service;
+
+ function isInvalid(form) {
+ return form.$invalid;
+ }
+
+ function checkFieldsValidity(form) {
+
+ var validationErrorKeys = _.keys(form.$error);
+
+ _(validationErrorKeys).each(function(anErrorKey) {
+
+ var formFields = _.values(form.$error[anErrorKey]);
+
+ _(formFields).each(function(aFormField) {
+
+ aFormField.$dirty = true;
+ aFormField.$setValidity(anErrorKey, false);
+
+ });
+
+ });
+
+ }
+
+ }
+
+})();
diff --git a/moonv4/moon_gui/static/app/services/gui/menu.service.js b/moonv4/moon_gui/static/app/services/gui/menu.service.js
new file mode 100644
index 00000000..fd90a2fa
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/gui/menu.service.js
@@ -0,0 +1,49 @@
+/**
+ * @author arnaud marhin<arnaud.marhin@orange.com>
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('menuService', menuService);
+
+ menuService.$inject = ['$state'];
+
+ function menuService($state) {
+
+ var service = {};
+
+ service.isProjectTabActive = isProjectTabActive;
+ service.isPDPTabActive = isPDPTabActive;
+ service.isPolicyTabActive = isPolicyTabActive;
+ service.isLogsTabActive = isLogsTabActive;
+ service.isModelTabActive = isModelTabActive;
+
+ return service;
+
+ function isProjectTabActive() {
+ return $state.includes('moon.project');
+ }
+
+ function isPDPTabActive() {
+ return $state.includes('moon.pdp');
+ }
+
+ function isPolicyTabActive(){
+ return $state.includes('moon.policy');
+ }
+
+ function isLogsTabActive(){
+ return $state.includes('moon.logs');
+ }
+
+ function isModelTabActive(){
+ return $state.includes('moon.model');
+ }
+
+ }
+
+})();
diff --git a/moonv4/moon_gui/static/app/services/gui/security.pipeline.service.js b/moonv4/moon_gui/static/app/services/gui/security.pipeline.service.js
new file mode 100644
index 00000000..3831e487
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/gui/security.pipeline.service.js
@@ -0,0 +1,29 @@
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('securityPipelineService', securityPipelineService);
+
+ securityPipelineService.$inject = ['SECURITY_PIPELINE_CST','policyService'];
+
+ function securityPipelineService(SECURITY_PIPELINE_CST, policyService) {
+ var service = {};
+
+ service.findAll = findAll;
+
+ return service;
+
+ function findAll(type){
+ switch(type){
+ case SECURITY_PIPELINE_CST.TYPE.POLICY :
+ return policyService.findAll();
+ default :
+ return policyService.findAll();
+ }
+
+ }
+ }
+
+})();
diff --git a/moonv4/moon_gui/static/app/services/gui/util.service.js b/moonv4/moon_gui/static/app/services/gui/util.service.js
new file mode 100644
index 00000000..7274244a
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/gui/util.service.js
@@ -0,0 +1,66 @@
+/**
+ * @author arnaud marhin<arnaud.marhin@orange.com>
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('utilService', utilService);
+
+ utilService.$inject = [];
+
+ function utilService() {
+
+ return {
+
+
+ /**
+ * Transforms an answer from server and return an array of objects instead the @param data
+
+ * @param data object : {
+ * 'typeOfTheRreturnedObject' : {
+ * 'idObject1' : {....},
+ * 'idObject2' : {....}
+ * }
+ * }
+ * @param typeOfObject
+ * @returns {Array}
+ */
+ transform : function(data, typeOfObject){
+
+ var result = [];
+
+ _.each(data[typeOfObject],function(item, key){
+ item.id = key;
+ result.push(item);
+ });
+
+ return result;
+ },
+
+ /**
+ * same as transform but with only one object
+ * @param data
+ * @param typeOfObject the first elem of the dictonnary
+ */
+ transformOne : function(data, typeOfObject){
+
+ var result = [];
+
+ _.each(data[typeOfObject], function (item, key) {
+ item.id = key;
+ result.push(item);
+ });
+
+ return result[0];
+
+ }
+
+ };
+
+ }
+
+})();
diff --git a/moonv4/moon_gui/static/app/services/gui/version.service.js b/moonv4/moon_gui/static/app/services/gui/version.service.js
new file mode 100644
index 00000000..5f9f2786
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/gui/version.service.js
@@ -0,0 +1,27 @@
+/**
+ * @author arnaud marhin<arnaud.marhin@orange.com>
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('versionService', versionService);
+
+ versionService.$inject = ['$resource'];
+
+ function versionService($resource) {
+
+ return {
+
+ version: $resource('version.json', {}, {
+ get: {method: 'GET', isArray: false}
+ })
+
+ };
+
+ }
+
+})();
diff --git a/moonv4/moon_gui/static/app/services/moon/model/model.service.js b/moonv4/moon_gui/static/app/services/moon/model/model.service.js
new file mode 100644
index 00000000..a676fc1a
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/moon/model/model.service.js
@@ -0,0 +1,105 @@
+/**
+ * @author Samy Abdallah
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('modelService', modelService);
+
+ modelService.$inject = ['$resource', 'REST_URI', 'metaRuleService', 'utilService'];
+
+ function modelService($resource, REST_URI, metaRuleService, utilService) {
+
+ return {
+
+ data: $resource(REST_URI.MODELS + ':model_id', {}, {
+ get: {method: 'GET'},
+ query: {method: 'GET'},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'},
+ update: {method: 'PATCH'}
+ }),
+
+ findAll: function () {
+
+ return this.data.query().$promise.then(function (data) {
+
+ return utilService.transform(data, 'models');
+
+ });
+
+ },
+
+
+ findAllWithCallBack : function (callback){
+
+ return this.data.query().$promise.then(function (data) {
+
+ callback( utilService.transform(data, 'models'));
+
+ });
+
+ },
+
+ findOneWithCallback : function(modelId, callback){
+
+ return this.data.get({model_id: modelId}).$promise.then(function (data) {
+
+ callback(utilService.transformOne(data, 'models'));
+
+ });
+
+ },
+
+ findOneWithMetaRules: function (modelId) {
+
+ return this.data.get({model_id: modelId}).$promise.then(function (data) {
+
+ var res = utilService.transformOne(data, 'models');
+
+ if(res.meta_rules.length > 0){
+
+ metaRuleService.findSomeWithMetaData(res.meta_rules).then(function(metaRules){
+
+ res.meta_rules_values = metaRules;
+ res.id = modelId;
+
+ return res;
+
+ });
+
+ }else{
+
+ res.meta_rules_values = [];
+ res.id = modelId;
+
+ }
+
+ return res;
+
+ });
+
+ },
+
+ delete: function (model, callbackSuccess, callbackError ) {
+
+ delete model.meta_rules_values;
+
+ this.data.remove({model_id: model.id}, model, callbackSuccess, callbackError);
+
+ },
+
+ update: function (model, callbackSuccess, callbackError) {
+
+ delete model.meta_rules_values;
+ this.data.update({model_id: model.id}, model, callbackSuccess, callbackError);
+
+ }
+
+ }
+ }
+})(); \ No newline at end of file
diff --git a/moonv4/moon_gui/static/app/services/moon/pdp.service.js b/moonv4/moon_gui/static/app/services/moon/pdp.service.js
new file mode 100644
index 00000000..822f7414
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/moon/pdp.service.js
@@ -0,0 +1,128 @@
+/**
+ * service allowing the client to interact with pdp
+ * @author arnaud marhin<arnaud.marhin@orange.com>
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('pdpService', pdpService);
+
+ pdpService.$inject = ['$q', '$resource','REST_URI', 'utilService'];
+
+ function pdpService($q, $resource, REST_URI, utilService) {
+
+ return {
+
+ data: {
+
+ pdp: $resource(REST_URI.PDP + ':pdp_id', {}, {
+ query: { method: 'GET', isArray: false },
+ get: { method: 'GET', isArray: false },
+ create: { method: 'POST' },
+ update: { method:'PATCH'},
+ remove: { method: 'DELETE' }
+ })
+
+ },
+
+ findAll: function() {
+
+ return this.data.pdp.query().$promise.then(function (data) {
+
+ return utilService.transform(data, 'pdps');
+
+ });
+
+ },
+
+ findAllWithCallBack : function (callback){
+
+ return this.data.pdp.query().$promise.then(function (data) {
+
+ callback( utilService.transform(data, 'pdps'));
+
+ });
+
+ },
+
+ findOne: function(id) {
+
+ return this.data.pdp.get({pdp_id: id}).$promise.then(function (data) {
+
+ return utilService.transformOne(data, 'pdps');
+
+ });
+
+ },
+
+ unMap: function(pdp, callbackSuccess, callbackError){
+
+ pdp.keystone_project_id = null;
+
+ if(_.has(pdp, 'project')){
+ delete pdp.project;
+ }
+
+ this.data.pdp.update({pdp_id: pdp.id}, pdp, callbackSuccess, callbackError);
+
+ },
+
+ map: function(pdp, projectId, callbackSuccess, callbackError){
+
+ pdp.keystone_project_id = projectId;
+
+ this.data.pdp.update({pdp_id: pdp.id}, pdp, callbackSuccess, callbackError);
+ },
+
+ update: function (pdp, callbackSuccess, callbackError) {
+
+ this.data.pdp.update({pdp_id: pdp.id}, pdp, callbackSuccess, callbackError);
+
+ },
+
+ mapPdpsToProjects : mapPdpsToProjects,
+
+ mapPdpsToProject : mapPdpsToProject
+
+ };
+
+ /**
+ * Will assign each project to it related pdp
+ * @param projects a list of Project, a new attribute pdp will be add, if the related pdp is existing in @param pdps
+ * @param pdps a list of Pdp
+ */
+ function mapPdpsToProjects(projects, pdps){
+
+ _.each(projects, function(project){
+
+ return mapPdpsToProject(project, pdps);
+
+ });
+ }
+
+ function mapPdpsToProject(project, pdps){
+
+ if (_.isNull(project.keystone_project_id)){
+ return false;
+ }
+
+ var index = _.findIndex(pdps, function(pdp){
+ return project.id === pdp.keystone_project_id;
+ });
+
+ if(index === -1){
+ return false;
+ }
+
+ project.pdp = pdps[index];
+
+ return true;
+ }
+
+ }
+
+})();
diff --git a/moonv4/moon_gui/static/app/services/moon/policy/parameters/assignements.service.js b/moonv4/moon_gui/static/app/services/moon/policy/parameters/assignements.service.js
new file mode 100644
index 00000000..ad7d8e8b
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/moon/policy/parameters/assignements.service.js
@@ -0,0 +1,96 @@
+/**
+ * @author Samy Abdallah
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('assignmentService', assignmentService);
+
+ assignmentService.$inject = ['$resource', 'REST_URI', 'utilService'];
+
+ function assignmentService($resource, REST_URI, utilService) {
+
+ var data = {
+
+ subject: {
+
+ policy: $resource(REST_URI.POLICIES + ':policy_id/subject_assignments/:subject_id', {}, {
+ get: {method: 'GET'},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ })
+
+ },
+
+
+ object: {
+
+ policy: $resource(REST_URI.POLICIES + ':policy_id/object_assignments/:object_id', {}, {
+ get: {method: 'GET', isArray: false},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ })
+
+ },
+
+ action: {
+
+ policy: $resource(REST_URI.POLICIES + ':policy_id/action_assignments/:action_id', {}, {
+ get: {method: 'GET', isArray: false},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ })
+
+ }
+
+ };
+
+ return {
+
+ subject : {
+
+ findAllFromPolicyWithCallback: function(policyId, callback){
+
+ data.subject.policy.get({policy_id: policyId}).$promise.then(function(data) {
+
+ callback(utilService.transform(data, 'subject_assignments'));
+
+ });
+
+ }
+ },
+
+ object : {
+
+ findAllFromPolicyWithCallback: function(policyId, callback){
+
+ data.object.policy.get({policy_id: policyId}).$promise.then(function(data) {
+
+ callback(utilService.transform(data, 'object_assignments'));
+
+ });
+
+ }
+ },
+
+ action : {
+
+ findAllFromPolicyWithCallback: function(policyId, callback){
+
+ data.action.policy.get({policy_id: policyId}).$promise.then(function(data) {
+
+ callback(utilService.transform(data, 'action_assignments'));
+
+ });
+
+ }
+ }
+
+ };
+
+ }
+})(); \ No newline at end of file
diff --git a/moonv4/moon_gui/static/app/services/moon/policy/parameters/data.service.js b/moonv4/moon_gui/static/app/services/moon/policy/parameters/data.service.js
new file mode 100644
index 00000000..22f35e45
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/moon/policy/parameters/data.service.js
@@ -0,0 +1,196 @@
+/**
+ * @author Samy Abdallah
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('dataService', dataService);
+
+ dataService.$inject = ['$resource', 'REST_URI', 'utilService'];
+
+ function dataService($resource, REST_URI, utilService) {
+
+ var data = {
+
+ subject: {
+
+ policy: $resource(REST_URI.POLICIES + ':policy_id/subject_data/:subject_id/:data_id', {}, {
+ get: {method: 'GET'},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ })
+
+ },
+
+ object: {
+
+ policy: $resource(REST_URI.POLICIES + ':policy_id/object_data/:object_id/:data_id', {}, {
+ get: {method: 'GET', isArray: false},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ })
+
+ },
+
+ action: {
+
+ policy: $resource(REST_URI.POLICIES + ':policy_id/action_data/:action_id/:data_id', {}, {
+ get: {method: 'GET', isArray: false},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ })
+
+ }
+
+ };
+
+ return {
+
+ subject : {
+
+ findAllFromPolicyWithCallback: function(policyId, callback){
+
+ data.subject.policy.get({policy_id: policyId}).$promise.then(function(data) {
+
+ callback(utilService.transform(data['subject_data'][0], 'data'));
+
+ });
+
+ },
+
+ delete: function (subject, callbackSuccess, callbackError ) {
+
+ data.subject.perimeter.remove({subject_id: subject.id}, subject, callbackSuccess, callbackError);
+
+ },
+
+ add: function (subject, callbackSuccess, callbackError ) {
+
+ data.subject.perimeter.create({}, subject, callbackSuccess, callbackError);
+
+ },
+
+ data: {
+
+ findOne: function(policyId, subjectId, dataId, callback){
+
+ data.subject.policy.get({policy_id: policyId, subject_id: subjectId, data_id : dataId}).$promise.then(function(data) {
+
+ if(data['subject_data'][0]){
+
+ callback(utilService.transformOne(data['subject_data'][0], 'data'));
+
+ }else{
+
+ callback({ });
+
+ }
+
+ });
+
+ }
+ }
+ },
+
+ object : {
+
+ findAllFromPolicyWithCallback: function(policyId, callback){
+
+ data.object.policy.get({policy_id: policyId}).$promise.then(function(data) {
+
+ callback(utilService.transform(data['object_data'][0], 'data'));
+
+ });
+
+ },
+
+ delete: function (object, callbackSuccess, callbackError ) {
+
+ data.object.perimeter.remove({object_id: object.id}, object, callbackSuccess, callbackError);
+
+ },
+
+ add:function (object, callbackSuccess, callbackError ) {
+
+ data.object.perimeter.create({}, object, callbackSuccess, callbackError);
+
+ },
+
+ data: {
+
+ findOne: function(policyId, objectId, dataId, callback){
+
+ data.object.policy.get({policy_id: policyId, object_id: objectId, data_id : dataId}).$promise.then(function(data) {
+
+
+ if(data['object_data'][0]){
+
+ callback(utilService.transformOne(data['object_data'][0], 'data'));
+
+ }else{
+
+ callback({ });
+
+ }
+
+ });
+
+ }
+ }
+ },
+
+ action : {
+
+ findAllFromPolicyWithCallback: function(policyId, callback){
+
+ data.action.policy.get({policy_id: policyId}).$promise.then(function(data) {
+
+ callback(utilService.transform(data['action_data'][0], 'data'));
+
+ });
+
+ },
+
+ delete: function (action, callbackSuccess, callbackError ) {
+
+ data.action.perimeter.remove({action_id: action.id}, action, callbackSuccess, callbackError);
+
+ },
+
+ add:function (action, callbackSuccess, callbackError ) {
+
+ data.action.perimeter.create({}, action, callbackSuccess, callbackError);
+
+ },
+
+
+ data: {
+
+ findOne: function(policyId, actionId, dataId, callback){
+
+ data.action.policy.get({policy_id: policyId, action_id: actionId, data_id : dataId}).$promise.then(function(data) {
+
+ if(data['action_data'][0]){
+
+ callback(utilService.transformOne(data['action_data'][0], 'data'));
+
+ }else{
+
+ callback({ });
+
+ }
+
+ });
+
+ }
+ }
+ }
+
+ };
+
+ }
+})(); \ No newline at end of file
diff --git a/moonv4/moon_gui/static/app/services/moon/policy/parameters/perimeter.service.js b/moonv4/moon_gui/static/app/services/moon/policy/parameters/perimeter.service.js
new file mode 100644
index 00000000..6e929aba
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/moon/policy/parameters/perimeter.service.js
@@ -0,0 +1,419 @@
+/**
+ * @author Samy Abdallah
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('perimeterService', perimeterService);
+
+ perimeterService.$inject = ['$resource', 'REST_URI', '$q', 'utilService'];
+
+ function perimeterService($resource, REST_URI, $q, utilService) {
+
+ var data = {
+
+ subject: {
+
+ perimeter: $resource(REST_URI.PERIMETERS.subject + ':subject_id', {}, {
+ get: {method: 'GET', isArray: false},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ }),
+
+ policy: $resource(REST_URI.POLICIES + ':policy_id/subjects/:subject_id', {}, {
+ get: {method: 'GET'},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ })
+
+ },
+
+
+ object: {
+
+ perimeter: $resource(REST_URI.PERIMETERS.object + ':object_id', {}, {
+ get: {method: 'GET', isArray: false},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ }),
+
+ policy: $resource(REST_URI.POLICIES + ':policy_id/objects/:object_id', {}, {
+ get: {method: 'GET', isArray: false},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ })
+
+ },
+
+ action: {
+
+ perimeter: $resource(REST_URI.PERIMETERS.action + ':action_id', {}, {
+ get: {method: 'GET', isArray: false},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ }),
+
+ policy: $resource(REST_URI.POLICIES + ':policy_id/actions/:action_id', {}, {
+ get: {method: 'GET', isArray: false},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ })
+
+ }
+
+ };
+
+ return {
+
+ subject : {
+
+ findOne: function(subjectId, callback){
+
+ data.subject.perimeter.get({subject_id: subjectId}).$promise.then(function(data) {
+
+ callback(utilService.transformOne(data, 'subjects'));
+
+ });
+
+ },
+
+ findOneReturningPromise: function (subjectId){
+
+ return data.subject.perimeter.get({subject_id: subjectId}).$promise;
+
+ },
+
+ findSome: function(subjectListId) {
+
+ var _self = this;
+
+ if(subjectListId.length === 0){
+ return [];
+ }
+
+ var promises = _(subjectListId).map( function(subjectId) {
+
+ return _self.findOneReturningPromise(subjectId);
+
+ });
+
+ return $q.all(promises).then( function(result) {
+
+ return _(result).map( function(resource) {
+
+ return utilService.transformOne(resource, 'subjects');
+
+ });
+
+ });
+
+ },
+
+ findAllFromPolicyWithCallback: function(policyId, callback){
+
+ data.subject.policy.get({policy_id: policyId}).$promise.then(function(data) {
+
+ callback(utilService.transform(data, 'subjects'));
+
+ });
+
+ },
+
+ findOneFromPolicyWithCallback: function(policyId, subjectId, callback){
+
+ data.subject.policy.get({policy_id: policyId, subject_id: subjectId}).$promise.then(function(data) {
+
+ callback(utilService.transformOne(data, 'subjects'));
+
+ });
+
+ },
+
+ findAll: function(){
+
+ return data.subject.perimeter.get().$promise.then(function(data) {
+
+ return utilService.transform(data, 'subjects');
+
+ });
+ },
+
+ findAllWithCallback: function(callback){
+
+ return data.subject.perimeter.get().$promise.then(function(data) {
+
+ callback(utilService.transform(data, 'subjects'));
+
+ });
+
+ },
+
+ delete: function (subject, callbackSuccess, callbackError ) {
+
+ data.subject.perimeter.remove({subject_id: subject.id}, subject, callbackSuccess, callbackError);
+
+ },
+
+ add: function (subject, callbackSuccess, callbackError ) {
+
+ data.subject.perimeter.create({}, subject, callbackSuccess, callbackError);
+
+ }
+ },
+
+ object : {
+
+ findOne: function(objectId, callback){
+
+ data.object.perimeter.get({object_id: objectId}).$promise.then(function(data) {
+
+ callback(utilService.transformOne(data, 'objects'));
+
+ })
+
+ },
+
+ findOneReturningPromise: function(objectId){
+
+ return data.object.perimeter.get({object_id: objectId}).$promise;
+
+ },
+
+ findSome: function(objectListId) {
+
+
+ var _self = this;
+
+ if(objectListId.length === 0){
+ return [];
+ }
+
+ var promises = _(objectListId).map( function(objectId) {
+
+ return _self.findOneReturningPromise(objectId);
+
+ });
+
+ return $q.all(promises).then( function(result) {
+
+ return _(result).map( function(resource) {
+
+ return utilService.transformOne(resource, 'objects');
+
+ });
+
+ });
+
+ },
+
+ findSomeWithCallback: function(objectListId, callback){
+
+ var _self = this;
+
+ if(objectListId.length === 0){
+ callback([]);
+ }
+
+ var promises = _(objectListId).map( function(subjectId) {
+
+ return _self.findOneReturningPromise(subjectId);
+
+ });
+
+ $q.all(promises).then( function(result) {
+
+ callback( _(result).map( function(resource) {
+
+ return utilService.transformOne(resource, 'objects');
+
+ }));
+
+ });
+
+ },
+
+ findAll : function(){
+
+ return data.object.perimeter.get().$promise.then(function(data) {
+
+ return utilService.transform(data, 'objects');
+
+ });
+
+ },
+
+ findAllFromPolicyWithCallback: function(policyId, callback){
+
+ data.object.policy.get({policy_id: policyId}).$promise.then(function(data) {
+
+ callback(utilService.transform(data, 'objects'));
+
+ });
+
+ },
+
+ findOneFromPolicyWithCallback: function(policyId, objectId, callback){
+
+
+ data.object.policy.get({policy_id: policyId, object_id: objectId}).$promise.then(function(data) {
+
+ callback(utilService.transformOne(data, 'objects'));
+
+ });
+
+ },
+
+ findAllWithCallback: function(callback){
+
+ return data.object.perimeter.get().$promise.then(function(data) {
+
+ callback(utilService.transform(data, 'objects'));
+
+ });
+
+ },
+
+ delete: function (object, callbackSuccess, callbackError ) {
+
+ data.object.perimeter.remove({object_id: object.id}, object, callbackSuccess, callbackError);
+
+ },
+
+ add:function (object, callbackSuccess, callbackError ) {
+
+ data.object.perimeter.create({}, object, callbackSuccess, callbackError);
+
+ }
+ },
+
+ action : {
+
+ findOne: function(actionId, callback){
+
+ data.action.perimeter.get({actionId: actionId}).$promise.then(function(data) {
+
+ callback(utilService.transformOne(data, 'actions'));
+
+ });
+
+ },
+
+ findOneReturningPromise: function(actionId){
+
+ return data.action.perimeter.get({actionId: actionId}).$promise;
+
+ },
+
+ findSome: function(actionListId) {
+
+ var _self = this;
+
+ if(actionListId.length === 0){
+ return [];
+ }
+
+ var promises = _(actionListId).map( function(actionId) {
+
+ return _self.findOneReturningPromise(actionId);
+
+ });
+
+ return $q.all(promises).then( function(result) {
+
+ return _(result).map( function(resource) {
+
+ return utilService.transformOne(resource, 'actions');
+
+ });
+
+ });
+
+ },
+
+ findSomeWithCallback: function(actionListId, callback){
+
+ var _self = this;
+
+ if(actionListId.length === 0){
+ callback([]);
+ }
+
+ var promises = _(actionListId).map( function(subjectId) {
+
+ return _self.findOneReturningPromise(subjectId);
+
+ });
+
+ $q.all(promises).then( function(result) {
+
+ callback( _(result).map( function(resource) {
+
+ return utilService.transformOne(resource, 'actions');
+
+ }));
+
+ });
+
+ },
+
+ findAll : function(){
+
+ return data.action.perimeter.get().$promise.then(function(data) {
+
+ return utilService.transform(data, 'actions');
+
+ });
+
+ },
+
+ findAllFromPolicyWithCallback: function(policyId, callback){
+
+ data.action.policy.get({policy_id: policyId}).$promise.then(function(data) {
+
+ callback(utilService.transform(data, 'actions'));
+
+ });
+
+ },
+
+ findOneFromPolicyWithCallback: function(policyId, actionId, callback){
+
+ data.action.policy.get({policy_id: policyId, action_id: actionId}).$promise.then(function(data) {
+
+ callback(utilService.transformOne(data, 'actions'));
+
+ });
+
+ },
+
+ findAllWithCallback: function(callback){
+
+ return data.action.perimeter.get().$promise.then(function(data) {
+
+ callback(utilService.transform(data, 'actions'));
+
+ });
+
+ },
+
+ delete: function (action, callbackSuccess, callbackError ) {
+
+ data.action.perimeter.remove({action_id: action.id}, action, callbackSuccess, callbackError);
+
+ },
+
+ add:function (action, callbackSuccess, callbackError ) {
+
+ data.action.perimeter.create({}, action, callbackSuccess, callbackError);
+
+ }
+ }
+
+ };
+
+ }
+})(); \ No newline at end of file
diff --git a/moonv4/moon_gui/static/app/services/moon/policy/parameters/rule.service.js b/moonv4/moon_gui/static/app/services/moon/policy/parameters/rule.service.js
new file mode 100644
index 00000000..b1a350ae
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/moon/policy/parameters/rule.service.js
@@ -0,0 +1,49 @@
+/**
+ * @author Samy Abdallah
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('ruleService', ruleService);
+
+ ruleService.$inject = ['$resource', 'REST_URI', 'utilService'];
+
+ function ruleService($resource, REST_URI, utilService) {
+
+ return {
+
+ data: {
+
+ policy: $resource(REST_URI.POLICIES + ':policy_id/rules/:rule_id', {}, {
+ get: {method: 'GET'},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ })
+
+ },
+
+ findAllFromPolicyWithCallback: function(policyId, callback){
+
+ this.data.policy.get({policy_id: policyId}).$promise.then(function(data) {
+
+ console.log('ruleService - findAllFromPolicyWithCallback()');
+ console.log(data);
+
+ var array = data['rules'];
+
+ console.log(JSON.stringify(array));
+ callback(utilService.transform(array, 'rules'));
+
+ });
+
+ }
+
+
+ }
+
+ }
+})(); \ No newline at end of file
diff --git a/moonv4/moon_gui/static/app/services/moon/policy/policy.service.js b/moonv4/moon_gui/static/app/services/moon/policy/policy.service.js
new file mode 100644
index 00000000..5c8ad4f5
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/moon/policy/policy.service.js
@@ -0,0 +1,108 @@
+/**
+ * Service providing access to the tenants
+ * @author arnaud marhin<arnaud.marhin@orange.com>
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('policyService', policyService);
+
+ policyService.$inject = ['$resource', 'REST_URI', 'utilService', '$q'];
+
+ function policyService($resource, REST_URI, utilService, $q) {
+
+ return {
+
+ data: {
+
+ policy: $resource(REST_URI.POLICIES + ':policy_id', {}, {
+ query: {method: 'GET'},
+ create: { method: 'POST' },
+ update: { method: 'PATCH' },
+ remove: { method: 'DELETE' }
+ })
+
+ },
+
+ findAll: function () {
+
+ return this.data.policy.query().$promise.then(function (data) {
+
+ return utilService.transform(data, 'policies');
+
+ });
+
+ },
+
+ findAllWithCallback: function (callback) {
+
+ return this.data.policy.query().$promise.then(function (data) {
+
+ callback(utilService.transform(data, 'policies'));
+
+ });
+
+ },
+
+ findOneReturningPromise: function(policyId){
+
+ return this.data.policy.get({policy_id: policyId}).$promise;
+
+ },
+
+ findSomeWithCallback: function(policyListId, callback){
+
+ var _self = this;
+
+ if(policyListId.length === 0){
+ callback([]);
+ }
+
+ var promises = _(policyListId).map( function(policyId) {
+
+ return _self.findOneReturningPromise(policyId);
+
+ });
+
+ $q.all(promises).then( function(result) {
+
+ callback( _(result).map( function(resource) {
+
+ return utilService.transformOne(resource, 'policies');
+
+ }));
+
+ });
+
+ },
+
+ findOne: function (policyId) {
+
+ return this.data.policy.get({policy_id: policyId}).$promise.then(function (data) {
+
+ return utilService.transformOne(data, 'policies');
+
+ });
+
+ },
+
+ update: function (policy, callbackSuccess, callbackError) {
+
+ this.data.policy.update({policy_id: policy.id}, policy, callbackSuccess, callbackError);
+
+ },
+
+ delete: function (policy, callbackSuccess, callbackError ) {
+
+ this.data.policy.remove({policy_id: policy.id}, policy, callbackSuccess, callbackError);
+
+ }
+
+ }
+ }
+
+})();
diff --git a/moonv4/moon_gui/static/app/services/moon/rule/metadata.service.js b/moonv4/moon_gui/static/app/services/moon/rule/metadata.service.js
new file mode 100644
index 00000000..659e0b30
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/moon/rule/metadata.service.js
@@ -0,0 +1,354 @@
+/**
+ * @author Samy Abdallah
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('metaDataService', metaDataService);
+
+ metaDataService.$inject = ['$resource', 'REST_URI', '$q', 'utilService'];
+
+ function metaDataService($resource, REST_URI, $q, utilService) {
+
+ var data = {
+
+ subject: $resource(REST_URI.METADATA.subject + ':subject_id', {}, {
+ get: {method: 'GET', isArray: false},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ }),
+
+
+ object: $resource(REST_URI.METADATA.object + ':object_id', {}, {
+ get: {method: 'GET', isArray: false},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ }),
+
+ action: $resource(REST_URI.METADATA.action + ':action_id', {}, {
+ get: {method: 'GET', isArray: false},
+ create: {method: 'POST'},
+ remove: {method: 'DELETE'}
+ })
+
+ };
+
+ return {
+
+ subject : {
+
+ findOne: function(subjectId, callback){
+
+ data.subject.get({subject_id: subjectId}).$promise.then(function(data) {
+
+ callback(utilService.transformOne(data, 'subject_categories'));
+
+ });
+
+ },
+
+ findOneReturningPromise: function (subjectId){
+
+ return data.subject.get({subject_id: subjectId}).$promise;
+
+ },
+
+ findSome: function(subjectListId) {
+
+ var _self = this;
+
+ if(subjectListId.length === 0){
+ return [];
+ }
+
+ var promises = _(subjectListId).map( function(subjectId) {
+
+ return _self.findOneReturningPromise(subjectId);
+
+ });
+
+ return $q.all(promises).then( function(result) {
+
+ return _(result).map( function(resource) {
+
+ return utilService.transformOne(resource, 'subject_categories');
+
+ });
+
+ });
+
+ },
+
+ findSomeWithCallback: function(subjectListId, callback){
+
+ var _self = this;
+
+ if(subjectListId.length === 0){
+ callback([]);
+ }
+
+ var promises = _(subjectListId).map( function(subjectId) {
+
+ return _self.findOneReturningPromise(subjectId);
+
+ });
+
+ $q.all(promises).then( function(result) {
+
+ callback( _(result).map( function(resource) {
+
+ return utilService.transformOne(resource, 'subject_categories');
+
+ }));
+
+ });
+
+ },
+
+ findAll: function(){
+
+ return data.subject.get().$promise.then(function(data) {
+
+ return utilService.transform(data, 'subject_categories');
+
+ });
+ },
+
+ findAllWithCallback: function(callback){
+
+ return data.subject.get().$promise.then(function(data) {
+
+ callback(utilService.transform(data, 'subject_categories'));
+
+ });
+
+ },
+
+ delete: function (subject, callbackSuccess, callbackError ) {
+
+ data.subject.remove({subject_id: subject.id}, subject, callbackSuccess, callbackError);
+
+ },
+
+ add: function (subject, callbackSuccess, callbackError ) {
+
+ data.subject.create({}, subject, callbackSuccess, callbackError);
+
+ }
+ },
+
+ object : {
+
+ findOne: function(objectId, callback){
+
+ data.object.get({object_id: objectId}).$promise.then(function(data) {
+
+ callback(utilService.transformOne(data, 'object_categories'));
+
+ })
+
+ },
+
+ findOneReturningPromise: function(objectId){
+
+ return data.object.get({object_id: objectId}).$promise;
+
+ },
+
+ findSome: function(objectListId) {
+
+
+ var _self = this;
+
+ if(objectListId.length === 0){
+ return [];
+ }
+
+ var promises = _(objectListId).map( function(objectId) {
+
+ return _self.findOneReturningPromise(objectId);
+
+ });
+
+ return $q.all(promises).then( function(result) {
+
+ return _(result).map( function(resource) {
+
+ return utilService.transformOne(resource, 'object_categories');
+
+ });
+
+ });
+
+ },
+
+ findSomeWithCallback: function(objectListId, callback){
+
+ var _self = this;
+
+ if(objectListId.length === 0){
+ callback([]);
+ }
+
+ var promises = _(objectListId).map( function(subjectId) {
+
+ return _self.findOneReturningPromise(subjectId);
+
+ });
+
+ $q.all(promises).then( function(result) {
+
+ callback( _(result).map( function(resource) {
+
+ return utilService.transformOne(resource, 'object_categories');
+
+ }));
+
+ });
+
+ },
+
+ findAll : function(){
+
+ return data.object.get().$promise.then(function(data) {
+
+ return utilService.transform(data, 'object_categories');
+
+ });
+
+ },
+
+ findAllWithCallback: function(callback){
+
+ return data.object.get().$promise.then(function(data) {
+
+ callback(utilService.transform(data, 'object_categories'));
+
+ });
+
+ },
+
+ delete: function (object, callbackSuccess, callbackError ) {
+
+ data.object.remove({object_id: object.id}, object, callbackSuccess, callbackError);
+
+ },
+
+ add:function (object, callbackSuccess, callbackError ) {
+
+ data.object.create({}, object, callbackSuccess, callbackError);
+
+ }
+ },
+
+ action : {
+
+ findOne: function(actionId, callback){
+
+ data.action.get({actionId: actionId}).$promise.then(function(data) {
+
+ callback(utilService.transformOne(data, 'action_categories'));
+
+ })
+
+ },
+
+ findOneReturningPromise: function(actionId){
+
+ return data.action.get({actionId: actionId}).$promise;
+
+ },
+
+ findSome: function(actionListId) {
+
+ var _self = this;
+
+ if(actionListId.length === 0){
+ return [];
+ }
+
+ var promises = _(actionListId).map( function(actionId) {
+
+ return _self.findOneReturningPromise(actionId);
+
+ });
+
+ return $q.all(promises).then( function(result) {
+
+ return _(result).map( function(resource) {
+
+ return utilService.transformOne(resource, 'action_categories');
+
+ });
+
+ });
+
+ },
+
+ findSomeWithCallback: function(actionListId, callback){
+
+ var _self = this;
+
+ if(actionListId.length === 0){
+ callback([]);
+ }
+
+ var promises = _(actionListId).map( function(subjectId) {
+
+ return _self.findOneReturningPromise(subjectId);
+
+ });
+
+ $q.all(promises).then( function(result) {
+
+ callback( _(result).map( function(resource) {
+
+ return utilService.transformOne(resource, 'action_categories');
+
+ }));
+
+ });
+
+ },
+
+ findAll : function(){
+
+ return data.action.get().$promise.then(function(data) {
+
+ return utilService.transform(data, 'action_categories');
+
+ });
+
+ },
+
+ findAllWithCallback: function(callback){
+
+ return data.action.get().$promise.then(function(data) {
+
+ callback(utilService.transform(data, 'action_categories'));
+
+ });
+
+ },
+
+ delete: function (action, callbackSuccess, callbackError ) {
+
+ data.action.remove({action_id: action.id}, action, callbackSuccess, callbackError);
+
+ },
+
+ add:function (action, callbackSuccess, callbackError ) {
+
+ data.action.create({}, action, callbackSuccess, callbackError);
+
+ }
+ }
+
+ };
+
+ }
+})(); \ No newline at end of file
diff --git a/moonv4/moon_gui/static/app/services/moon/rule/metarule.service.js b/moonv4/moon_gui/static/app/services/moon/rule/metarule.service.js
new file mode 100644
index 00000000..71a36c50
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/moon/rule/metarule.service.js
@@ -0,0 +1,208 @@
+/**
+ * @author Samy Abdallah
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('metaRuleService', metaRuleService);
+
+ metaRuleService.$inject = ['$resource', 'REST_URI', 'metaDataService', '$q', 'utilService'];
+
+ function metaRuleService($resource, REST_URI, metaDataService, $q, utilService) {
+
+ return {
+
+ data: $resource(REST_URI.METARULES + ':metarule_id', {}, {
+ query: {method: 'GET' },
+ get: {method: 'GET', isArray: false},
+ update: {method: 'PATCH'},
+ create: { method: 'POST' },
+ remove: { method: 'DELETE' }
+ }),
+
+
+ findAll: function () {
+
+ return this.data.query().$promise.then(function (data) {
+
+ return utilService.transform(data, 'meta_rules');
+
+ });
+
+ },
+
+ findAllWithCallback : function (callback) {
+
+ this.data.query().$promise.then(function (data) {
+
+ callback(utilService.transform(data, 'meta_rules'));
+
+ });
+
+ },
+
+ findSomeWithMetaData : function(metaRuleListId){
+
+ var _self = this;
+
+ if(metaRuleListId.length === 0){
+ return [];
+ }
+
+ var promises = _(metaRuleListId).map(function(objectId) {
+
+ return _self.findOneReturningPromise(objectId);
+
+ });
+
+ return $q.all(promises).then(function(result) {
+
+ return _(result).map(function(resource) {
+
+ var metaRule = utilService.transformOne(resource, 'meta_rules');
+
+ metaRule = _self.findMetaDataFromMetaRule(metaRule);
+
+ return metaRule;
+
+ });
+
+ });
+
+
+ },
+
+ findSomeWithCallback : function(metaRuleListId, callback){
+
+ var _self = this;
+
+ if(metaRuleListId.length === 0){
+ return [];
+ }
+
+ var promises = _(metaRuleListId).map(function(objectId) {
+
+ return _self.findOneReturningPromise(objectId);
+
+ });
+
+ return $q.all(promises).then(function(result) {
+
+ callback( _(result).map(function(resource) {
+
+ return utilService.transformOne(resource, 'meta_rules');
+
+ }));
+
+ });
+
+
+ },
+
+ findOneReturningPromise: function(metaRuleId){
+
+ return this.data.get({metarule_id: metaRuleId}).$promise;
+
+ },
+
+ findOne : function(metaRuleId){
+
+ return this.data.get({metarule_id: metaRuleId}).$promise.then(function(data) {
+
+ return utilService.transformOne(data, 'meta_rules');
+
+ })
+
+ },
+
+ findOneWithCallback: function(metaRuleId, callback){
+
+ this.data.get({metarule_id: metaRuleId}).$promise.then(function(data) {
+
+ callback(utilService.transformOne(data, 'meta_rules'));
+
+ });
+
+ },
+
+ findOneWithMetaData: function(metaRuleId){
+
+ var _self = this;
+
+ return this.data.get({metarule_id: metaRuleId}).$promise.then(function(data) {
+
+ var metaRule = utilService.transformOne(data, 'meta_rules');
+
+ metaRule = _self.findMetaDataFromMetaRule(metaRule);
+
+ return metaRule;
+
+ })
+
+ },
+
+ findMetaDataFromMetaRule : function (metaRule){
+
+ if(metaRule.subject_categories.length > 0){
+
+ metaDataService.subject.findSome(metaRule.subject_categories).then(function(categories){
+ metaRule.subject_categories_values = categories;
+ });
+
+ }else{
+
+ metaRule.subject_categories_values = [];
+
+ }
+
+ if(metaRule.object_categories.length > 0){
+
+ metaDataService.object.findSome(metaRule.object_categories).then(function(categories){
+ metaRule.object_categories_values = categories;
+ });
+
+ }else{
+
+ metaRule.object_categories_values = [];
+
+ }
+
+ if(metaRule.action_categories.length > 0){
+
+ metaDataService.action.findSome(metaRule.action_categories).then(function(categories){
+ metaRule.action_categories_values = categories;
+ });
+
+
+ }else{
+
+ metaRule.action_categories_values = [];
+
+ }
+
+ return metaRule;
+ },
+
+ delete: function (metaRule, callbackSuccess, callbackError ) {
+
+ this.data.remove({metarule_id: metaRule.id}, metaRule, callbackSuccess, callbackError);
+
+ },
+
+ update: function(metaRule, callbackSuccess, callbackError){
+
+ delete metaRule.subject_categories_values;
+ delete metaRule.object_categories_values;
+ delete metaRule.action_categories_values;
+
+ this.data.update({metarule_id: metaRule.id}, metaRule, callbackSuccess, callbackError);
+
+ }
+ };
+
+ }
+})(); \ No newline at end of file
diff --git a/moonv4/moon_gui/static/app/services/partner/authentication.service.js b/moonv4/moon_gui/static/app/services/partner/authentication.service.js
new file mode 100644
index 00000000..b6d3f36d
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/partner/authentication.service.js
@@ -0,0 +1,106 @@
+/**
+ * @author Samy Abdallah
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('authenticationService', authenticationService);
+
+ authenticationService.$inject = ['$resource', 'REST_URI', '$sessionStorage', '$http', '$location'];
+
+ function authenticationService($resource, REST_URI, $sessionStorage, $http, $location) {
+
+ return {
+ data: $resource(REST_URI.KEYSTONE + 'auth/tokens', {}, {
+ login: { method: 'POST' ,
+ /**
+ * Transform Response is needed to add headers into the response object
+ * @param data
+ * @param headersGetter
+ * @returns {{}}
+ */
+ transformResponse : function (data, headersGetter) {
+ var response = {};
+ response.data = angular.fromJson(data) ;
+ response.headers = headersGetter();
+ return response;
+ }
+ },
+ logout: { method: 'DELETE' }
+ }),
+
+ /**
+ *
+ * @param credentials object : {username : '', password : ''}
+ * @param callbackSuccess
+ * @param callbackError
+ * @constructor
+ */
+ Login : function (credentials, callbackSuccess, callbackError){
+ var requestData = {
+ auth:{
+ identity:{
+ methods:[
+ 'password'
+ ],
+ password:{
+ user:{
+ name: credentials.username,
+ domain:{
+ name:'Default'
+ },
+ password: credentials.password
+ }
+ }
+ },
+ scope: {
+ project: {
+ name:'admin',
+ domain:{
+ name:'Default'
+ }
+ }
+ }
+ }
+ };
+ this.data.login({}, requestData, function (response){
+ $sessionStorage.currentUser = response.data;
+ $sessionStorage.currentUser.connectionToken = response.headers['x-subject-token'];
+ SetTokenHeader(response.headers['x-subject-token']);
+ callbackSuccess();
+ }, callbackError);
+ },
+ IsConnected : IsConnected,
+ SetTokenHeader : SetTokenHeader,
+ GetTokenHeader : GetTokenHeader,
+ GetUser : GetUser,
+ Logout : Logout
+ };
+
+ function IsConnected(){
+ return _.has($sessionStorage, 'currentUser');
+ }
+
+ function Logout(){
+ delete $sessionStorage.currentUser;
+ $http.defaults.headers.common['X-Auth-Token'] = '';
+ $location.path('/');
+ }
+
+ function GetUser(){
+ return $sessionStorage.currentUser;
+ }
+
+ function GetTokenHeader(){
+ return $sessionStorage.currentUser.connectionToken;
+ }
+
+ function SetTokenHeader(token){
+ $http.defaults.headers.common['X-Auth-Token'] = token;
+ }
+ }
+})(); \ No newline at end of file
diff --git a/moonv4/moon_gui/static/app/services/partner/nova.service.js b/moonv4/moon_gui/static/app/services/partner/nova.service.js
new file mode 100644
index 00000000..38e2a0fc
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/partner/nova.service.js
@@ -0,0 +1,35 @@
+/**
+ * @author arnaud marhin<arnaud.marhin@orange.com>
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('novaService', novaService);
+
+ novaService.$inject = ['$resource'];
+
+ function novaService($resource) {
+
+ return {
+
+ data: {
+
+ image: $resource('./pip/nova/images', {}, {
+ query: {method: 'GET', isArray: false}
+ }),
+
+ flavor: $resource('./pip/nova/flavors', {}, {
+ query: {method: 'GET', isArray: false}
+ })
+
+ }
+
+ };
+
+ }
+
+})();
diff --git a/moonv4/moon_gui/static/app/services/partner/project.service.js b/moonv4/moon_gui/static/app/services/partner/project.service.js
new file mode 100644
index 00000000..4ec27f2e
--- /dev/null
+++ b/moonv4/moon_gui/static/app/services/partner/project.service.js
@@ -0,0 +1,60 @@
+/**
+ * Service providing access to the tenants
+ * @author arnaud marhin<arnaud.marhin@orange.com>
+ */
+
+(function() {
+
+ 'use strict';
+
+ angular
+ .module('moon')
+ .factory('projectService', projectService);
+
+ projectService.$inject = [ '$resource' , 'REST_URI' ];
+
+ function projectService( $resource, REST_URI) {
+
+ return {
+
+ data: {
+
+ projects: $resource(REST_URI.KEYSTONE + 'projects/:project_id', {}, {
+ query: {method: 'GET', isArray: false},
+ get: { method: 'GET', isArray: false },
+ create: { method: 'POST' },
+ remove: { method: 'DELETE' }
+ })
+
+ },
+
+ findOne: function(project_id, callback){
+
+ return this.data.projects.get({project_id: project_id}).$promise.then(function(data) {
+
+ callback(data.project);
+
+ });
+
+ },
+
+ findAll: function() {
+
+ return this.data.projects.query().$promise.then(function(listProjects) {
+
+ var result = [];
+
+ _.each(listProjects['projects'], function(item){
+ result.push(item);
+ });
+
+ return result;
+ });
+
+ }
+
+ };
+
+ }
+
+})();