Merge pull request #3181 from mabashian/notif-related-tab

Show notification tab to notif admin users on jt/wf/project/inv source forms

Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
softwarefactory-project-zuul[bot]
2019-02-07 21:39:33 +00:00
committed by GitHub
8 changed files with 556 additions and 512 deletions

View File

@@ -4,23 +4,22 @@
* All Rights Reserved * All Rights Reserved
*************************************************/ *************************************************/
export default ['$state', '$stateParams', '$scope', 'ParseVariableString', export default ['$state', '$scope', 'ParseVariableString', 'ParseTypeChange',
'rbacUiControlService', 'ToJSON', 'ParseTypeChange', 'GroupsService',
'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions', 'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions',
'SourcesService', 'inventoryData', 'inventorySourcesOptions', 'Empty', 'SourcesService', 'inventoryData', 'inventorySourcesOptions', 'Empty',
'Wait', 'Rest', 'Alert', '$rootScope', 'i18n', 'InventoryHostsStrings', 'Wait', 'Rest', 'Alert', '$rootScope', 'i18n', 'InventoryHostsStrings',
'ProcessErrors', 'inventorySource', 'ProcessErrors', 'inventorySource', 'isNotificationAdmin',
function($state, $stateParams, $scope, ParseVariableString, function($state, $scope, ParseVariableString, ParseTypeChange,
rbacUiControlService, ToJSON,ParseTypeChange, GroupsService,
GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions, GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions,
SourcesService, inventoryData, inventorySourcesOptions, Empty, SourcesService, inventoryData, inventorySourcesOptions, Empty,
Wait, Rest, Alert, $rootScope, i18n, InventoryHostsStrings, Wait, Rest, Alert, $rootScope, i18n, InventoryHostsStrings,
ProcessErrors, inventorySource) { ProcessErrors, inventorySource, isNotificationAdmin) {
const inventorySourceData = inventorySource.get(); const inventorySourceData = inventorySource.get();
$scope.projectBasePath = GetBasePath('projects') + '?not__status=never updated'; $scope.projectBasePath = GetBasePath('projects') + '?not__status=never updated';
$scope.canAdd = inventorySourcesOptions.actions.POST; $scope.canAdd = inventorySourcesOptions.actions.POST;
$scope.isNotificationAdmin = isNotificationAdmin || false;
// instantiate expected $scope values from inventorySourceData // instantiate expected $scope values from inventorySourceData
_.assign($scope, _.assign($scope,
{credential: inventorySourceData.credential}, {credential: inventorySourceData.credential},

View File

@@ -24,6 +24,20 @@ export default {
inventorySourcesOptions: ['InventoriesService', '$stateParams', function(InventoriesService, $stateParams) { inventorySourcesOptions: ['InventoriesService', '$stateParams', function(InventoriesService, $stateParams) {
return InventoriesService.inventorySourcesOptions($stateParams.inventory_id) return InventoriesService.inventorySourcesOptions($stateParams.inventory_id)
.then((response) => response.data); .then((response) => response.data);
}],
isNotificationAdmin: ['Rest', 'ProcessErrors', 'GetBasePath', 'i18n',
function(Rest, ProcessErrors, GetBasePath, i18n) {
Rest.setUrl(`${GetBasePath('organizations')}?role_level=notification_admin_role&page_size=1`);
return Rest.get()
.then(({data}) => {
return data.count > 0;
})
.catch(({data, status}) => {
ProcessErrors(null, data, status, null, {
hdr: i18n._('Error!'),
msg: i18n._('Failed to get organizations for which this user is a notification administrator. GET returned ') + status
});
});
}] }]
} }
}; };

View File

@@ -1,34 +1,20 @@
/************************************************* /*************************************************
* Copyright (c) 2015 Ansible, Inc. * Copyright (c) 2019 Ansible, Inc.
* *
* All Rights Reserved * All Rights Reserved
*************************************************/ *************************************************/
/**
* @ngdoc function
* @name forms.function:Groups
* @description This form is for adding/editing a Group on the inventory page
*/
export default ['NotificationsList', 'i18n', function(NotificationsList, i18n){ export default ['NotificationsList', 'i18n', function(NotificationsList, i18n){
var notifications_object = { var notifications_object = {
name: 'notifications',
index: false,
basePath: "notification_templates",
include: "NotificationsList",
title: i18n._('Notifications'),
iterator: 'notification',
ngIf: "!(inventory_source_obj.source === undefined || inventory_source_obj.source === '')",
generateList: true, generateList: true,
include: "NotificationsList",
ngIf: "(current_user.is_superuser || isOrgAdmin || isNotificationAdmin) && !(inventory_source_obj.source === undefined || inventory_source_obj.source === '')",
ngClick: "$state.go('inventories.edit.inventory_sources.edit.notifications')" ngClick: "$state.go('inventories.edit.inventory_sources.edit.notifications')"
// search: {
// "or__job__inventory": ''
// }
}; };
let clone = _.clone(NotificationsList); let clone = _.clone(NotificationsList);
notifications_object = angular.extend(clone, notifications_object); notifications_object = angular.extend(clone, notifications_object);
return { return {
addTitle: i18n._('CREATE SOURCE'), addTitle: i18n._('CREATE SOURCE'),
editTitle: '{{ name }}', editTitle: '{{ name }}',
showTitle: true, showTitle: true,
@@ -438,6 +424,6 @@ return {
} }
} }
}; };
}]; }];

View File

@@ -5,12 +5,12 @@
*************************************************/ *************************************************/
export default ['$scope', '$rootScope', '$stateParams', 'ProjectsForm', 'Rest', export default ['$scope', '$rootScope', '$stateParams', 'ProjectsForm', 'Rest',
'Alert', 'ProcessErrors', 'GenerateForm', 'Prompt', 'Alert', 'ProcessErrors', 'GenerateForm', 'Prompt', 'isNotificationAdmin',
'GetBasePath', 'GetProjectPath', 'Authorization', 'GetChoices', 'Empty', 'GetBasePath', 'GetProjectPath', 'Authorization', 'GetChoices', 'Empty',
'Wait', 'ProjectUpdate', '$state', 'CreateSelect2', 'ToggleNotification', 'Wait', 'ProjectUpdate', '$state', 'CreateSelect2', 'ToggleNotification',
'i18n', 'OrgAdminLookup', 'ConfigData', 'scmCredentialType', 'i18n', 'OrgAdminLookup', 'ConfigData', 'scmCredentialType',
function($scope, $rootScope, $stateParams, ProjectsForm, Rest, Alert, function($scope, $rootScope, $stateParams, ProjectsForm, Rest, Alert,
ProcessErrors, GenerateForm, Prompt, GetBasePath, ProcessErrors, GenerateForm, Prompt, isNotificationAdmin, GetBasePath,
GetProjectPath, Authorization, GetChoices, Empty, Wait, ProjectUpdate, GetProjectPath, Authorization, GetChoices, Empty, Wait, ProjectUpdate,
$state, CreateSelect2, ToggleNotification, i18n, OrgAdminLookup, $state, CreateSelect2, ToggleNotification, i18n, OrgAdminLookup,
ConfigData, scmCredentialType) { ConfigData, scmCredentialType) {
@@ -27,6 +27,7 @@ export default ['$scope', '$rootScope', '$stateParams', 'ProjectsForm', 'Rest',
$scope.base_dir = ''; $scope.base_dir = '';
const virtualEnvs = ConfigData.custom_virtualenvs || []; const virtualEnvs = ConfigData.custom_virtualenvs || [];
$scope.custom_virtualenvs_options = virtualEnvs; $scope.custom_virtualenvs_options = virtualEnvs;
$scope.isNotificationAdmin = isNotificationAdmin || false;
} }
$scope.$watch('project_obj.summary_fields.user_capabilities.edit', function(val) { $scope.$watch('project_obj.summary_fields.user_capabilities.edit', function(val) {

View File

@@ -90,6 +90,24 @@ angular.module('Projects', [])
breadcrumbs: { breadcrumbs: {
edit: '{{breadcrumb.project_name}}' edit: '{{breadcrumb.project_name}}'
}, },
resolve: {
edit: {
isNotificationAdmin: ['Rest', 'ProcessErrors', 'GetBasePath', 'i18n',
function(Rest, ProcessErrors, GetBasePath, i18n) {
Rest.setUrl(`${GetBasePath('organizations')}?role_level=notification_admin_role&page_size=1`);
return Rest.get()
.then(({data}) => {
return data.count > 0;
})
.catch(({data, status}) => {
ProcessErrors(null, data, status, null, {
hdr: i18n._('Error!'),
msg: i18n._('Failed to get organizations for which this user is a notification administrator. GET returned ') + status
});
});
}]
}
}
}) })
.then(res => { .then(res => {
const stateIndex = res.states.findIndex(s => s.name === projectsEditName); const stateIndex = res.states.findIndex(s => s.name === projectsEditName);

View File

@@ -11,22 +11,22 @@
*/ */
export default export default
[ '$filter', '$scope', '$rootScope', [ '$filter', '$scope',
'$location', '$stateParams', 'JobTemplateForm', 'GenerateForm', '$stateParams', 'JobTemplateForm', 'GenerateForm',
'Rest', 'Alert', 'ProcessErrors', 'GetBasePath', 'hashSetup', 'Rest', 'Alert', 'ProcessErrors', 'GetBasePath', 'hashSetup',
'ParseTypeChange', 'Wait', 'selectedLabels', 'i18n', 'ParseTypeChange', 'Wait', 'selectedLabels', 'i18n',
'Empty', 'Prompt', 'ToJSON', 'GetChoices', 'CallbackHelpInit', 'Empty', 'ToJSON', 'GetChoices', 'CallbackHelpInit',
'initSurvey', '$state', 'CreateSelect2', 'initSurvey', '$state', 'CreateSelect2', 'isNotificationAdmin',
'ToggleNotification','$q', 'InstanceGroupsService', 'InstanceGroupsData', 'ToggleNotification','$q', 'InstanceGroupsService', 'InstanceGroupsData',
'MultiCredentialService', 'availableLabels', 'projectGetPermissionDenied', 'MultiCredentialService', 'availableLabels', 'projectGetPermissionDenied',
'inventoryGetPermissionDenied', 'jobTemplateData', 'ParseVariableString', 'ConfigData', 'inventoryGetPermissionDenied', 'jobTemplateData', 'ParseVariableString', 'ConfigData',
function( function(
$filter, $scope, $rootScope, $filter, $scope,
$location, $stateParams, JobTemplateForm, GenerateForm, Rest, Alert, $stateParams, JobTemplateForm, GenerateForm, Rest, Alert,
ProcessErrors, GetBasePath, hashSetup, ProcessErrors, GetBasePath, hashSetup,
ParseTypeChange, Wait, selectedLabels, i18n, ParseTypeChange, Wait, selectedLabels, i18n,
Empty, Prompt, ToJSON, GetChoices, CallbackHelpInit, Empty, ToJSON, GetChoices, CallbackHelpInit,
SurveyControllerInit, $state, CreateSelect2, SurveyControllerInit, $state, CreateSelect2, isNotificationAdmin,
ToggleNotification, $q, InstanceGroupsService, InstanceGroupsData, ToggleNotification, $q, InstanceGroupsService, InstanceGroupsData,
MultiCredentialService, availableLabels, projectGetPermissionDenied, MultiCredentialService, availableLabels, projectGetPermissionDenied,
inventoryGetPermissionDenied, jobTemplateData, ParseVariableString, ConfigData inventoryGetPermissionDenied, jobTemplateData, ParseVariableString, ConfigData
@@ -64,6 +64,7 @@ export default
$scope.skip_tag_options = []; $scope.skip_tag_options = [];
const virtualEnvs = ConfigData.custom_virtualenvs || []; const virtualEnvs = ConfigData.custom_virtualenvs || [];
$scope.custom_virtualenvs_options = virtualEnvs; $scope.custom_virtualenvs_options = virtualEnvs;
$scope.isNotificationAdmin = isNotificationAdmin || false;
SurveyControllerInit({ SurveyControllerInit({
scope: $scope, scope: $scope,

View File

@@ -57,8 +57,8 @@ angular.module('templates', [surveyMaker.name, jobTemplates.name, labels.name, p
}, },
resolve: { resolve: {
add: { add: {
Inventory: ['$stateParams', 'Rest', 'GetBasePath', 'ProcessErrors', Inventory: ['$stateParams', 'Rest', 'GetBasePath', 'ProcessErrors', 'i18n',
function($stateParams, Rest, GetBasePath, ProcessErrors){ function($stateParams, Rest, GetBasePath, ProcessErrors, i18n){
if($stateParams.inventory_id){ if($stateParams.inventory_id){
let path = `${GetBasePath('inventory')}${$stateParams.inventory_id}`; let path = `${GetBasePath('inventory')}${$stateParams.inventory_id}`;
Rest.setUrl(path); Rest.setUrl(path);
@@ -67,15 +67,15 @@ angular.module('templates', [surveyMaker.name, jobTemplates.name, labels.name, p
return data.data; return data.data;
}).catch(function(response) { }).catch(function(response) {
ProcessErrors(null, response.data, response.status, null, { ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get inventory info. GET returned status: ' + msg: i18n._('Failed to get inventory info. GET returned status: ') +
response.status response.status
}); });
}); });
} }
}], }],
Project: ['Rest', 'GetBasePath', 'ProcessErrors', '$transition$', Project: ['Rest', 'GetBasePath', 'ProcessErrors', '$transition$', 'i18n',
function(Rest, GetBasePath, ProcessErrors, $transition$){ function(Rest, GetBasePath, ProcessErrors, $transition$, i18n){
if($transition$.params().credential_id){ if($transition$.params().credential_id){
let path = `${GetBasePath('projects')}?credential__id=${Number($transition$.params().credential_id)}`; let path = `${GetBasePath('projects')}?credential__id=${Number($transition$.params().credential_id)}`;
Rest.setUrl(path); Rest.setUrl(path);
@@ -84,8 +84,8 @@ angular.module('templates', [surveyMaker.name, jobTemplates.name, labels.name, p
return data.data.results[0]; return data.data.results[0];
}).catch(function(response) { }).catch(function(response) {
ProcessErrors(null, response.data, response.status, null, { ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get project info. GET returned status: ' + msg: i18n._('Failed to get project info. GET returned status: ') +
response.status response.status
}); });
}); });
@@ -98,50 +98,49 @@ angular.module('templates', [surveyMaker.name, jobTemplates.name, labels.name, p
return data.data; return data.data;
}).catch(function(response) { }).catch(function(response) {
ProcessErrors(null, response.data, response.status, null, { ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get project info. GET returned status: ' + msg: i18n._('Failed to get project info. GET returned status: ') +
response.status response.status
}); });
}); });
} }
}], }],
availableLabels: ['ProcessErrors', 'TemplatesService', availableLabels: ['ProcessErrors', 'TemplatesService', 'i18n',
function(ProcessErrors, TemplatesService) { function(ProcessErrors, TemplatesService, i18n) {
return TemplatesService.getAllLabelOptions() return TemplatesService.getAllLabelOptions()
.then(function(labels){ .then(function(labels){
return labels; return labels;
}).catch(function(response){ }).catch(function(response){
ProcessErrors(null, response.data, response.status, null, { ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get labels. GET returned status: ' + msg: i18n._('Failed to get labels. GET returned status: ') +
response.status response.status
}); });
}); });
}], }],
checkPermissions: ['Rest', 'GetBasePath', 'TemplatesService', 'Alert', 'ProcessErrors', '$state', checkPermissions: ['TemplatesService', 'Alert', 'ProcessErrors', '$state', 'i18n',
function(Rest, GetBasePath, TemplatesService, Alert, ProcessErrors, $state) { function(TemplatesService, Alert, ProcessErrors, $state, i18n) {
return TemplatesService.getJobTemplateOptions() return TemplatesService.getJobTemplateOptions()
.then(function(data) { .then(function(data) {
if (!data.actions.POST) { if (!data.actions.POST) {
$state.go("^"); $state.go("^");
Alert('Permission Error', 'You do not have permission to add a job template.', 'alert-info'); Alert(i18n._('Permission Error'), i18n._('You do not have permission to add a job template.'), 'alert-info');
} }
}).catch(function(response){ }).catch(function(response){
ProcessErrors(null, response.data, response.status, null, { ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get job template options. OPTIONS returned status: ' + msg: i18n._('Failed to get job template options. OPTIONS returned status: ') +
response.status response.status
}); });
}); });
}], }],
ConfigData: ['ConfigService', 'ProcessErrors', (ConfigService, ProcessErrors) => { ConfigData: ['ConfigService', 'ProcessErrors', 'i18n', (ConfigService, ProcessErrors, i18n) => {
return ConfigService.getConfig() return ConfigService.getConfig()
.then(response => response) .then(response => response)
.catch(({data, status}) => { .catch(({data, status}) => {
ProcessErrors(null, data, status, null, { ProcessErrors(null, data, status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get config. GET returned status: ' + msg: i18n._('Failed to get config. GET returned status: ') + status
'status: ' + status
}); });
}); });
}] }]
@@ -167,21 +166,21 @@ angular.module('templates', [surveyMaker.name, jobTemplates.name, labels.name, p
}, },
resolve: { resolve: {
edit: { edit: {
jobTemplateData: ['$stateParams', 'TemplatesService', 'ProcessErrors', jobTemplateData: ['$stateParams', 'TemplatesService', 'ProcessErrors', 'i18n',
function($stateParams, TemplatesService, ProcessErrors) { function($stateParams, TemplatesService, ProcessErrors, i18n) {
return TemplatesService.getJobTemplate($stateParams.job_template_id) return TemplatesService.getJobTemplate($stateParams.job_template_id)
.then(function(res) { .then(function(res) {
return res.data; return res.data;
}).catch(function(response){ }).catch(function(response){
ProcessErrors(null, response.data, response.status, null, { ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get job template. GET returned status: ' + msg: i18n._('Failed to get job template. GET returned status: ') +
response.status response.status
}); });
}); });
}], }],
projectGetPermissionDenied: ['Rest', 'ProcessErrors', 'jobTemplateData', projectGetPermissionDenied: ['Rest', 'ProcessErrors', 'jobTemplateData', 'i18n',
function(Rest, ProcessErrors, jobTemplateData) { function(Rest, ProcessErrors, jobTemplateData, i18n) {
if(jobTemplateData.related.project) { if(jobTemplateData.related.project) {
Rest.setUrl(jobTemplateData.related.project); Rest.setUrl(jobTemplateData.related.project);
return Rest.get() return Rest.get()
@@ -191,9 +190,8 @@ angular.module('templates', [surveyMaker.name, jobTemplates.name, labels.name, p
.catch(({data, status}) => { .catch(({data, status}) => {
if (status !== 403) { if (status !== 403) {
ProcessErrors(null, data, status, null, { ProcessErrors(null, data, status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get project. GET returned ' + msg: i18n._('Failed to get project. GET returned status: ') + status
'status: ' + status
}); });
return false; return false;
} }
@@ -206,8 +204,8 @@ angular.module('templates', [surveyMaker.name, jobTemplates.name, labels.name, p
return false; return false;
} }
}], }],
inventoryGetPermissionDenied: ['Rest', 'ProcessErrors', 'jobTemplateData', inventoryGetPermissionDenied: ['Rest', 'ProcessErrors', 'jobTemplateData', 'i18n',
function(Rest, ProcessErrors, jobTemplateData) { function(Rest, ProcessErrors, jobTemplateData, i18n) {
if(jobTemplateData.related.inventory) { if(jobTemplateData.related.inventory) {
Rest.setUrl(jobTemplateData.related.inventory); Rest.setUrl(jobTemplateData.related.inventory);
return Rest.get() return Rest.get()
@@ -217,9 +215,8 @@ angular.module('templates', [surveyMaker.name, jobTemplates.name, labels.name, p
.catch(({data, status}) => { .catch(({data, status}) => {
if (status !== 403) { if (status !== 403) {
ProcessErrors(null, data, status, null, { ProcessErrors(null, data, status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get project. GET returned ' + msg: i18n._('Failed to get project. GET returned status: ') + status
'status: ' + status
}); });
return false; return false;
} }
@@ -232,8 +229,8 @@ angular.module('templates', [surveyMaker.name, jobTemplates.name, labels.name, p
return false; return false;
} }
}], }],
InstanceGroupsData: ['$stateParams', 'Rest', 'GetBasePath', 'ProcessErrors', InstanceGroupsData: ['$stateParams', 'Rest', 'GetBasePath', 'ProcessErrors', 'i18n',
function($stateParams, Rest, GetBasePath, ProcessErrors){ function($stateParams, Rest, GetBasePath, ProcessErrors, i18n){
let path = `${GetBasePath('job_templates')}${$stateParams.job_template_id}/instance_groups/`; let path = `${GetBasePath('job_templates')}${$stateParams.job_template_id}/instance_groups/`;
Rest.setUrl(path); Rest.setUrl(path);
return Rest.get() return Rest.get()
@@ -244,46 +241,58 @@ angular.module('templates', [surveyMaker.name, jobTemplates.name, labels.name, p
}) })
.catch(({data, status}) => { .catch(({data, status}) => {
ProcessErrors(null, data, status, null, { ProcessErrors(null, data, status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get instance groups. GET returned ' + msg: i18n._('Failed to get instance groups. GET returned status: ') + status
'status: ' + status
}); });
}); });
}], }],
availableLabels: ['Rest', '$stateParams', 'GetBasePath', 'ProcessErrors', 'TemplatesService', availableLabels: ['ProcessErrors', 'TemplatesService', 'i18n',
function(Rest, $stateParams, GetBasePath, ProcessErrors, TemplatesService) { function(ProcessErrors, TemplatesService, i18n) {
return TemplatesService.getAllLabelOptions() return TemplatesService.getAllLabelOptions()
.then(function(labels){ .then(function(labels){
return labels; return labels;
}).catch(function(response){ }).catch(function(response){
ProcessErrors(null, response.data, response.status, null, { ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get labels. GET returned status: ' + msg: i18n._('Failed to get labels. GET returned status: ') +
response.status response.status
}); });
}); });
}], }],
selectedLabels: ['Rest', '$stateParams', 'GetBasePath', 'TemplatesService', 'ProcessErrors', selectedLabels: ['$stateParams', 'TemplatesService', 'ProcessErrors', 'i18n',
function(Rest, $stateParams, GetBasePath, TemplatesService, ProcessErrors) { function($stateParams, TemplatesService, ProcessErrors, i18n) {
return TemplatesService.getAllJobTemplateLabels($stateParams.job_template_id) return TemplatesService.getAllJobTemplateLabels($stateParams.job_template_id)
.then(function(labels){ .then(function(labels){
return labels; return labels;
}).catch(function(response){ }).catch(function(response){
ProcessErrors(null, response.data, response.status, null, { ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get workflow job template labels. GET returned status: ' + msg: i18n._('Failed to get workflow job template labels. GET returned status: ') +
response.status response.status
}); });
}); });
}], }],
ConfigData: ['ConfigService', 'ProcessErrors', (ConfigService, ProcessErrors) => { ConfigData: ['ConfigService', 'ProcessErrors', 'i18n', (ConfigService, ProcessErrors, i18n) => {
return ConfigService.getConfig() return ConfigService.getConfig()
.then(response => response) .then(response => response)
.catch(({data, status}) => { .catch(({data, status}) => {
ProcessErrors(null, data, status, null, { ProcessErrors(null, data, status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get config. GET returned status: ' + msg: i18n._('Failed to get config. GET returned status: ') + status
'status: ' + status });
});
}],
isNotificationAdmin: ['Rest', 'ProcessErrors', 'GetBasePath', 'i18n',
function(Rest, ProcessErrors, GetBasePath, i18n) {
Rest.setUrl(`${GetBasePath('organizations')}?role_level=notification_admin_role&page_size=1`);
return Rest.get()
.then(({data}) => {
return data.count > 0;
})
.catch(({data, status}) => {
ProcessErrors(null, data, status, null, {
hdr: i18n._('Error!'),
msg: i18n._('Failed to get organizations for which this user is a notification administrator. GET returned ') + status
}); });
}); });
}] }]
@@ -301,8 +310,8 @@ angular.module('templates', [surveyMaker.name, jobTemplates.name, labels.name, p
}, },
resolve: { resolve: {
add: { add: {
Inventory: ['$stateParams', 'Rest', 'GetBasePath', 'ProcessErrors', Inventory: ['$stateParams', 'Rest', 'GetBasePath', 'ProcessErrors', 'i18n',
function($stateParams, Rest, GetBasePath, ProcessErrors){ function($stateParams, Rest, GetBasePath, ProcessErrors, i18n){
if($stateParams.inventory_id){ if($stateParams.inventory_id){
let path = `${GetBasePath('inventory')}${$stateParams.inventory_id}`; let path = `${GetBasePath('inventory')}${$stateParams.inventory_id}`;
Rest.setUrl(path); Rest.setUrl(path);
@@ -311,38 +320,38 @@ angular.module('templates', [surveyMaker.name, jobTemplates.name, labels.name, p
return data.data; return data.data;
}).catch(function(response) { }).catch(function(response) {
ProcessErrors(null, response.data, response.status, null, { ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get inventory info. GET returned status: ' + msg: i18n._('Failed to get inventory info. GET returned status: ') +
response.status response.status
}); });
}); });
} }
}], }],
availableLabels: ['Rest', '$stateParams', 'GetBasePath', 'ProcessErrors', 'TemplatesService', availableLabels: ['ProcessErrors', 'TemplatesService', 'i18n',
function(Rest, $stateParams, GetBasePath, ProcessErrors, TemplatesService) { function(ProcessErrors, TemplatesService, i18n) {
return TemplatesService.getAllLabelOptions() return TemplatesService.getAllLabelOptions()
.then(function(labels){ .then(function(labels){
return labels; return labels;
}).catch(function(response){ }).catch(function(response){
ProcessErrors(null, response.data, response.status, null, { ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get labels. GET returned status: ' + msg: i18n._('Failed to get labels. GET returned status: ') +
response.status response.status
}); });
}); });
}], }],
checkPermissions: ['Rest', 'GetBasePath', 'TemplatesService', 'Alert', 'ProcessErrors', '$state', checkPermissions: ['TemplatesService', 'Alert', 'ProcessErrors', '$state', 'i18n',
function(Rest, GetBasePath, TemplatesService, Alert, ProcessErrors, $state) { function(TemplatesService, Alert, ProcessErrors, $state, i18n) {
return TemplatesService.getWorkflowJobTemplateOptions() return TemplatesService.getWorkflowJobTemplateOptions()
.then(function(data) { .then(function(data) {
if (!data.actions.POST) { if (!data.actions.POST) {
$state.go("^"); $state.go("^");
Alert('Permission Error', 'You do not have permission to add a workflow job template.', 'alert-info'); Alert(i18n._('Permission Error'), i18n._('You do not have permission to add a workflow job template.'), 'alert-info');
} }
}).catch(function(response){ }).catch(function(response){
ProcessErrors(null, response.data, response.status, null, { ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get workflow job template options. OPTIONS returned status: ' + msg: i18n._('Failed to get workflow job template options. OPTIONS returned status: ') +
response.status response.status
}); });
}); });
@@ -369,8 +378,8 @@ angular.module('templates', [surveyMaker.name, jobTemplates.name, labels.name, p
}, },
resolve: { resolve: {
edit: { edit: {
Inventory: ['$stateParams', 'Rest', 'GetBasePath', 'ProcessErrors', Inventory: ['$stateParams', 'Rest', 'GetBasePath', 'ProcessErrors', 'i18n',
function($stateParams, Rest, GetBasePath, ProcessErrors){ function($stateParams, Rest, GetBasePath, ProcessErrors, i18n){
if($stateParams.inventory_id){ if($stateParams.inventory_id){
let path = `${GetBasePath('inventory')}${$stateParams.inventory_id}`; let path = `${GetBasePath('inventory')}${$stateParams.inventory_id}`;
Rest.setUrl(path); Rest.setUrl(path);
@@ -379,48 +388,48 @@ angular.module('templates', [surveyMaker.name, jobTemplates.name, labels.name, p
return data.data; return data.data;
}).catch(function(response) { }).catch(function(response) {
ProcessErrors(null, response.data, response.status, null, { ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get inventory info. GET returned status: ' + msg: i18n._('Failed to get inventory info. GET returned status: ') +
response.status response.status
}); });
}); });
} }
}], }],
availableLabels: ['Rest', '$stateParams', 'GetBasePath', 'ProcessErrors', 'TemplatesService', availableLabels: ['ProcessErrors', 'TemplatesService', 'i18n',
function(Rest, $stateParams, GetBasePath, ProcessErrors, TemplatesService) { function(ProcessErrors, TemplatesService, i18n) {
return TemplatesService.getAllLabelOptions() return TemplatesService.getAllLabelOptions()
.then(function(labels){ .then(function(labels){
return labels; return labels;
}).catch(function(response){ }).catch(function(response){
ProcessErrors(null, response.data, response.status, null, { ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get labels. GET returned status: ' + msg: i18n._('Failed to get labels. GET returned status: ') +
response.status response.status
}); });
}); });
}], }],
selectedLabels: ['Rest', '$stateParams', 'GetBasePath', 'TemplatesService', 'ProcessErrors', selectedLabels: ['$stateParams', 'TemplatesService', 'ProcessErrors', 'i18n',
function(Rest, $stateParams, GetBasePath, TemplatesService, ProcessErrors) { function($stateParams, TemplatesService, ProcessErrors, i18n) {
return TemplatesService.getAllWorkflowJobTemplateLabels($stateParams.workflow_job_template_id) return TemplatesService.getAllWorkflowJobTemplateLabels($stateParams.workflow_job_template_id)
.then(function(labels){ .then(function(labels){
return labels; return labels;
}).catch(function(response){ }).catch(function(response){
ProcessErrors(null, response.data, response.status, null, { ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get workflow job template labels. GET returned status: ' + msg: i18n._('Failed to get workflow job template labels. GET returned status: ') +
response.status response.status
}); });
}); });
}], }],
workflowJobTemplateData: ['$stateParams', 'TemplatesService', 'ProcessErrors', workflowJobTemplateData: ['$stateParams', 'TemplatesService', 'ProcessErrors', 'i18n',
function($stateParams, TemplatesService, ProcessErrors) { function($stateParams, TemplatesService, ProcessErrors, i18n) {
return TemplatesService.getWorkflowJobTemplate($stateParams.workflow_job_template_id) return TemplatesService.getWorkflowJobTemplate($stateParams.workflow_job_template_id)
.then(function(res) { .then(function(res) {
return res.data; return res.data;
}).catch(function(response){ }).catch(function(response){
ProcessErrors(null, response.data, response.status, null, { ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!', hdr: i18n._('Error!'),
msg: 'Failed to get workflow job template. GET returned status: ' + msg: i18n._('Failed to get workflow job template. GET returned status: ') +
response.status response.status
}); });
}); });
@@ -433,6 +442,20 @@ angular.module('templates', [surveyMaker.name, jobTemplates.name, labels.name, p
.then(({data}) => { .then(({data}) => {
return data; return data;
}); });
}],
isNotificationAdmin: ['Rest', 'ProcessErrors', 'GetBasePath', 'i18n',
function(Rest, ProcessErrors, GetBasePath, i18n) {
Rest.setUrl(`${GetBasePath('organizations')}?role_level=notification_admin_role&page_size=1`);
return Rest.get()
.then(({data}) => {
return data.count > 0;
})
.catch(({data, status}) => {
ProcessErrors(null, data, status, null, {
hdr: i18n._('Error!'),
msg: i18n._('Failed to get organizations for which this user is a notification administrator. GET returned ') + status
});
});
}] }]
} }
} }

View File

@@ -10,12 +10,12 @@ export default [
'Wait', 'Empty', 'ToJSON', 'initSurvey', '$state', 'CreateSelect2', 'Wait', 'Empty', 'ToJSON', 'initSurvey', '$state', 'CreateSelect2',
'ParseVariableString', 'TemplatesService', 'Rest', 'ToggleNotification', 'ParseVariableString', 'TemplatesService', 'Rest', 'ToggleNotification',
'OrgAdminLookup', 'availableLabels', 'selectedLabels', 'workflowJobTemplateData', 'i18n', 'OrgAdminLookup', 'availableLabels', 'selectedLabels', 'workflowJobTemplateData', 'i18n',
'workflowLaunch', '$transitions', 'WorkflowJobTemplateModel', 'Inventory', 'workflowLaunch', '$transitions', 'WorkflowJobTemplateModel', 'Inventory', 'isNotificationAdmin',
function($scope, $stateParams, WorkflowForm, GenerateForm, Alert, function($scope, $stateParams, WorkflowForm, GenerateForm, Alert,
ProcessErrors, GetBasePath, $q, ParseTypeChange, Wait, Empty, ProcessErrors, GetBasePath, $q, ParseTypeChange, Wait, Empty,
ToJSON, SurveyControllerInit, $state, CreateSelect2, ParseVariableString, ToJSON, SurveyControllerInit, $state, CreateSelect2, ParseVariableString,
TemplatesService, Rest, ToggleNotification, OrgAdminLookup, availableLabels, selectedLabels, workflowJobTemplateData, i18n, TemplatesService, Rest, ToggleNotification, OrgAdminLookup, availableLabels, selectedLabels, workflowJobTemplateData, i18n,
workflowLaunch, $transitions, WorkflowJobTemplate, Inventory workflowLaunch, $transitions, WorkflowJobTemplate, Inventory, isNotificationAdmin
) { ) {
$scope.missingTemplates = _.has(workflowLaunch, 'node_templates_missing') && workflowLaunch.node_templates_missing.length > 0 ? true : false; $scope.missingTemplates = _.has(workflowLaunch, 'node_templates_missing') && workflowLaunch.node_templates_missing.length > 0 ? true : false;
@@ -26,6 +26,8 @@ export default [
} }
}); });
$scope.isNotificationAdmin = isNotificationAdmin || false;
const criteriaObj = { const criteriaObj = {
from: (state) => state.name === 'templates.editWorkflowJobTemplate.workflowMaker', from: (state) => state.name === 'templates.editWorkflowJobTemplate.workflowMaker',
to: (state) => state.name === 'templates.editWorkflowJobTemplate' to: (state) => state.name === 'templates.editWorkflowJobTemplate'