From 3115dd4feed1474e2bd18b0d694cac0716ab77b5 Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Fri, 17 Jun 2016 13:43:02 -0700 Subject: [PATCH 1/5] hiding notifcation templates on setup menu for non org admins --- .../src/setup-menu/setup-menu.partial.html | 3 ++- awx/ui/client/src/setup-menu/setup.route.js | 27 ++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/awx/ui/client/src/setup-menu/setup-menu.partial.html b/awx/ui/client/src/setup-menu/setup-menu.partial.html index f03ae05d08..ae1cdb0ee2 100644 --- a/awx/ui/client/src/setup-menu/setup-menu.partial.html +++ b/awx/ui/client/src/setup-menu/setup-menu.partial.html @@ -36,7 +36,8 @@ Create and edit scripts to dynamically load hosts from any source.

- +

Notifications

Create templates for sending notifications with Email, HipChat, Slack, and SMS. diff --git a/awx/ui/client/src/setup-menu/setup.route.js b/awx/ui/client/src/setup-menu/setup.route.js index fc080251ba..4a1d199018 100644 --- a/awx/ui/client/src/setup-menu/setup.route.js +++ b/awx/ui/client/src/setup-menu/setup.route.js @@ -6,5 +6,30 @@ export default { ncyBreadcrumb: { label: "SETTINGS" }, - templateUrl: templateUrl('setup-menu/setup-menu') + templateUrl: templateUrl('setup-menu/setup-menu'), + resolve: { + org_admin: + ['$rootScope', 'ProcessErrors', 'Rest', + function($rootScope, ProcessErrors, Rest){ + $rootScope.loginConfig.promise.then(function () { + if($rootScope.current_user.related.admin_of_organizations){ + $rootScope.orgAdmin = false; + if ($rootScope.current_user.is_superuser) { + $rootScope.orgAdmin = true; + } else { + Rest.setUrl(`/api/v1/users/${$rootScope.current_user.id}/admin_of_organizations`); + Rest.get() + .success(function(data) { + $rootScope.orgAdmin = (data.count) ? true : false; + }).error(function (data, status) { + ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', msg: 'Failed to find if users is admin of org' + status }); + }); + } + } + else{ + return; + } + }); + }] + } }; From de1d605c289d4c50122e4ec665c411804fb4258e Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Fri, 17 Jun 2016 17:09:55 -0700 Subject: [PATCH 2/5] fix for broken recent-notifications popover --- .../list.controller.js | 66 ++++++++++--------- .../notificationTemplates.list.js | 2 +- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js index edbd0cb42f..78a08c8839 100644 --- a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js +++ b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js @@ -109,41 +109,43 @@ export default } scope.showSummary = function(event, id) { + Wait('start'); + setTimeout(function(){ + if (!Empty(id)) { + var recent_notifications, + html, title = "Recent Notifications"; - if (!Empty(id)) { - var recent_notifications, - html, title = "Recent Notifications"; - - scope.notification_templates.forEach(function(notification_template){ - if(notification_template.id === id){ - recent_notifications = notification_template.summary_fields.recent_notifications; - } - }); - Wait('stop'); - if (recent_notifications.length > 0) { - html = "\n"; - html += "\n"; - html += ""; - html += ""; - html += ""; - html += "\n"; - html += "\n"; - html += "\n"; - - recent_notifications.forEach(function(row) { - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; + scope.notification_templates.forEach(function(notification_template){ + if(notification_template.id === id){ + recent_notifications = notification_template.summary_fields.recent_notifications; + } }); - html += "\n"; - html += "
StatusTime
" + ($filter('longDate')(row.created)).replace(/ /,'
') + "
\n"; + Wait('stop'); + if (recent_notifications.length > 0) { + html = "\n"; + html += "\n"; + html += ""; + html += ""; + html += ""; + html += "\n"; + html += "\n"; + html += "\n"; + + recent_notifications.forEach(function(row) { + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + }); + html += "\n"; + html += "
StatusTime
" + ($filter('longDate')(row.created)).replace(/ /,'
') + "
\n"; + } + else { + html = "

No recent notifications.

\n"; + } + attachElem(event, html, title); } - else { - html = "

No recent notifications.

\n"; - } - attachElem(event, html, title); - } + }, 100); }; scope.testNotification = function(){ diff --git a/awx/ui/client/src/notifications/notificationTemplates.list.js b/awx/ui/client/src/notifications/notificationTemplates.list.js index f365112b4e..5046f4a192 100644 --- a/awx/ui/client/src/notifications/notificationTemplates.list.js +++ b/awx/ui/client/src/notifications/notificationTemplates.list.js @@ -27,7 +27,7 @@ export default function(){ icon: "{{ 'icon-job-' + notification_template.status }}", awToolTip: "Click for recent notifications", awTipPlacement: "right", - ngClick: "showSummary($event, notification_templates.id)", + ngClick: "showSummary($event, notification_template.id)", ngClass: "" }] }, From 2de4a2d0f9dad53e636d73d29573078a20637c3c Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Fri, 17 Jun 2016 17:12:54 -0700 Subject: [PATCH 3/5] removing wait spinner on notification popover --- .../notification-templates-list/list.controller.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js index 78a08c8839..861fa18d98 100644 --- a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js +++ b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js @@ -109,7 +109,6 @@ export default } scope.showSummary = function(event, id) { - Wait('start'); setTimeout(function(){ if (!Empty(id)) { var recent_notifications, @@ -120,7 +119,6 @@ export default recent_notifications = notification_template.summary_fields.recent_notifications; } }); - Wait('stop'); if (recent_notifications.length > 0) { html = "\n"; html += "\n"; From 8a34b5712aeff710b0955ef51bb55d19678e2203 Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Mon, 20 Jun 2016 10:43:31 -0700 Subject: [PATCH 4/5] returning promise in resolve for setup menu --- awx/ui/client/src/setup-menu/setup.route.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/awx/ui/client/src/setup-menu/setup.route.js b/awx/ui/client/src/setup-menu/setup.route.js index 4a1d199018..dd92b86be6 100644 --- a/awx/ui/client/src/setup-menu/setup.route.js +++ b/awx/ui/client/src/setup-menu/setup.route.js @@ -18,12 +18,12 @@ export default { $rootScope.orgAdmin = true; } else { Rest.setUrl(`/api/v1/users/${$rootScope.current_user.id}/admin_of_organizations`); - Rest.get() - .success(function(data) { - $rootScope.orgAdmin = (data.count) ? true : false; - }).error(function (data, status) { - ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', msg: 'Failed to find if users is admin of org' + status }); - }); + return Rest.get().then(function(data){ + $rootScope.orgAdmin = (data.data.count) ? true : false; + }) + .catch(function (data, status) { + ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', msg: 'Failed to find if users is admin of org' + status }); + }); } } else{ From 11bd5570cfb614f619f3e9dc3c81f8642e86e2e5 Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Mon, 20 Jun 2016 11:37:27 -0700 Subject: [PATCH 5/5] fix for setup menu route resolve --- awx/ui/client/src/setup-menu/setup.route.js | 47 ++++++++++++--------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/awx/ui/client/src/setup-menu/setup.route.js b/awx/ui/client/src/setup-menu/setup.route.js index dd92b86be6..aac58a64cb 100644 --- a/awx/ui/client/src/setup-menu/setup.route.js +++ b/awx/ui/client/src/setup-menu/setup.route.js @@ -7,29 +7,38 @@ export default { label: "SETTINGS" }, templateUrl: templateUrl('setup-menu/setup-menu'), + controller: function(orgAdmin, $scope){ + $scope.orgAdmin = orgAdmin; + }, resolve: { - org_admin: + orgAdmin: ['$rootScope', 'ProcessErrors', 'Rest', function($rootScope, ProcessErrors, Rest){ - $rootScope.loginConfig.promise.then(function () { - if($rootScope.current_user.related.admin_of_organizations){ - $rootScope.orgAdmin = false; - if ($rootScope.current_user.is_superuser) { - $rootScope.orgAdmin = true; - } else { - Rest.setUrl(`/api/v1/users/${$rootScope.current_user.id}/admin_of_organizations`); - return Rest.get().then(function(data){ - $rootScope.orgAdmin = (data.data.count) ? true : false; - }) - .catch(function (data, status) { - ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', msg: 'Failed to find if users is admin of org' + status }); - }); + + return $rootScope.loginConfig.promise.then(function () { + if($rootScope.current_user.related.admin_of_organizations){ + $rootScope.orgAdmin = false; + if ($rootScope.current_user.is_superuser) { + return true; + } else { + Rest.setUrl(`/api/v1/users/${$rootScope.current_user.id}/admin_of_organizations`); + return Rest.get().then(function(data){ + if(data.data.count){ + return true; + } + else{ + return false; + } + }) + .catch(function (data, status) { + ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', msg: 'Failed to find if users is admin of org' + status }); + }); + } } - } - else{ - return; - } - }); + else{ + return false; + } + }); }] } };