From 43ef9f909a28e2d25426801b87fadc95d8d4b5e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 11 Aug 2015 15:20:50 +0200 Subject: [PATCH] feat(admin): admin page for all grafana organizations (list / edit view), #2457 --- CHANGELOG.md | 6 ++ pkg/api/api.go | 3 + public/app/features/admin/adminEditOrgCtrl.js | 52 ++++++++++++++++ .../app/features/admin/adminListOrgsCtrl.js | 38 ++++++++++++ ...dminUsersCtrl.js => adminListUsersCtrl.js} | 2 +- public/app/features/admin/all.js | 4 +- .../app/features/admin/partials/edit_org.html | 60 +++++++++++++++++++ public/app/features/admin/partials/orgs.html | 24 +++++++- public/app/routes/all.js | 7 ++- 9 files changed, 191 insertions(+), 5 deletions(-) create mode 100644 public/app/features/admin/adminEditOrgCtrl.js create mode 100644 public/app/features/admin/adminListOrgsCtrl.js rename public/app/features/admin/{adminUsersCtrl.js => adminListUsersCtrl.js} (90%) create mode 100644 public/app/features/admin/partials/edit_org.html diff --git a/CHANGELOG.md b/CHANGELOG.md index f8f676f0b5b..04cf919df5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 2.2 (unreleased) + +**New Features && Enhancements** +- [Issue #2457](https://github.com/grafana/grafana/issues/2457). Admin: admin page for all grafana organizations (list / edit view) + + # 2.1.1 (2015-08-11) **Fixes** diff --git a/pkg/api/api.go b/pkg/api/api.go index 7ad4ae73b4c..2d010e2649a 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -37,6 +37,8 @@ func Register(r *macaron.Macaron) { r.Get("/admin/users", reqGrafanaAdmin, Index) r.Get("/admin/users/create", reqGrafanaAdmin, Index) r.Get("/admin/users/edit/:id", reqGrafanaAdmin, Index) + r.Get("/admin/orgs", reqGrafanaAdmin, Index) + r.Get("/admin/orgs/edit/:id", reqGrafanaAdmin, Index) r.Get("/dashboard/*", reqSignedIn, Index) // sign up @@ -109,6 +111,7 @@ func Register(r *macaron.Macaron) { // orgs (admin routes) r.Group("/orgs/:orgId", func() { + r.Get("/", wrap(GetOrgById)) r.Put("/", bind(m.UpdateOrgCommand{}), wrap(UpdateOrg)) r.Get("/users", wrap(GetOrgUsers)) r.Post("/users", bind(m.AddOrgUserCommand{}), wrap(AddOrgUser)) diff --git a/public/app/features/admin/adminEditOrgCtrl.js b/public/app/features/admin/adminEditOrgCtrl.js new file mode 100644 index 00000000000..ec500704fb3 --- /dev/null +++ b/public/app/features/admin/adminEditOrgCtrl.js @@ -0,0 +1,52 @@ +define([ + 'angular', +], +function (angular) { + 'use strict'; + + var module = angular.module('grafana.controllers'); + + module.controller('AdminEditOrgCtrl', function($scope, $routeParams, backendSrv, $location) { + + $scope.init = function() { + if ($routeParams.id) { + $scope.getOrg($routeParams.id); + $scope.getOrgUsers($routeParams.id); + } + }; + + $scope.getOrg = function(id) { + backendSrv.get('/api/orgs/' + id).then(function(org) { + $scope.org = org; + }); + }; + + $scope.getOrgUsers = function(id) { + backendSrv.get('/api/orgs/' + id + '/users').then(function(orgUsers) { + $scope.orgUsers = orgUsers; + }); + }; + + $scope.update = function() { + if (!$scope.orgDetailsForm.$valid) { return; } + + backendSrv.put('/api/orgs/' + $scope.org.id, $scope.org).then(function() { + $location.path('/admin/orgs'); + }); + }; + + $scope.updateOrgUser= function(orgUser) { + backendSrv.patch('/api/orgs/' + orgUser.orgId + '/users/' + orgUser.userId, orgUser); + }; + + $scope.removeOrgUser = function(orgUser) { + backendSrv.delete('/api/orgs/' + orgUser.orgId + '/users/' + orgUser.userId).then(function() { + $scope.getOrgUsers($scope.org.id); + }); + }; + + $scope.init(); + + }); + +}); diff --git a/public/app/features/admin/adminListOrgsCtrl.js b/public/app/features/admin/adminListOrgsCtrl.js new file mode 100644 index 00000000000..380ce41faef --- /dev/null +++ b/public/app/features/admin/adminListOrgsCtrl.js @@ -0,0 +1,38 @@ +define([ + 'angular', +], +function (angular) { + 'use strict'; + + var module = angular.module('grafana.controllers'); + + module.controller('AdminListOrgsCtrl', function($scope, backendSrv) { + + $scope.init = function() { + $scope.getOrgs(); + }; + + $scope.getOrgs = function() { + backendSrv.get('/api/orgs').then(function(orgs) { + $scope.orgs = orgs; + }); + }; + + $scope.deleteOrg = function(org) { + $scope.appEvent('confirm-modal', { + title: 'Do you want to delete organization ' + org.name + '?', + icon: 'fa-trash', + yesText: 'Delete', + onConfirm: function() { + backendSrv.delete('/api/orgs/' + org.id).then(function() { + $scope.getOrgs(); + }); + } + }); + }; + + $scope.init(); + + }); + +}); diff --git a/public/app/features/admin/adminUsersCtrl.js b/public/app/features/admin/adminListUsersCtrl.js similarity index 90% rename from public/app/features/admin/adminUsersCtrl.js rename to public/app/features/admin/adminListUsersCtrl.js index 737812c5474..c89deafaf0f 100644 --- a/public/app/features/admin/adminUsersCtrl.js +++ b/public/app/features/admin/adminListUsersCtrl.js @@ -6,7 +6,7 @@ function (angular) { var module = angular.module('grafana.controllers'); - module.controller('AdminUsersCtrl', function($scope, backendSrv) { + module.controller('AdminListUsersCtrl', function($scope, backendSrv) { $scope.init = function() { $scope.getUsers(); diff --git a/public/app/features/admin/all.js b/public/app/features/admin/all.js index 35f1f4f5db9..14bff249b0e 100644 --- a/public/app/features/admin/all.js +++ b/public/app/features/admin/all.js @@ -1,5 +1,7 @@ define([ - './adminUsersCtrl', + './adminListUsersCtrl', + './adminListOrgsCtrl', + './adminEditOrgCtrl', './adminEditUserCtrl', './adminSettingsCtrl', ], function () {}); diff --git a/public/app/features/admin/partials/edit_org.html b/public/app/features/admin/partials/edit_org.html new file mode 100644 index 00000000000..aef042894ab --- /dev/null +++ b/public/app/features/admin/partials/edit_org.html @@ -0,0 +1,60 @@ + + + + +
+
+

+ Organization Details +

+ +
+
+
+
    +
  • + Name +
  • +
  • + +
  • +
+
+
+
+ +
+ +
+ +

+ Organization Users +

+ + + + + + + + + + + + + + +
UsernameEmailRole
{{orgUser.login}}{{orgUser.email}} + + + + + +
+ +
+
diff --git a/public/app/features/admin/partials/orgs.html b/public/app/features/admin/partials/orgs.html index 1bb8996a825..fe87073eb6c 100644 --- a/public/app/features/admin/partials/orgs.html +++ b/public/app/features/admin/partials/orgs.html @@ -1,6 +1,6 @@ @@ -10,6 +10,26 @@ Organizations - View not implemented yet... + + + + + + + + + + +
IdName
{{org.name}} + + + Edit + +    + + + +
+ diff --git a/public/app/routes/all.js b/public/app/routes/all.js index 0adca374452..28fa833439a 100644 --- a/public/app/routes/all.js +++ b/public/app/routes/all.js @@ -80,7 +80,7 @@ define([ }) .when('/admin/users', { templateUrl: 'app/features/admin/partials/users.html', - controller : 'AdminUsersCtrl', + controller : 'AdminListUsersCtrl', }) .when('/admin/users/create', { templateUrl: 'app/features/admin/partials/new_user.html', @@ -92,6 +92,11 @@ define([ }) .when('/admin/orgs', { templateUrl: 'app/features/admin/partials/orgs.html', + controller : 'AdminListOrgsCtrl', + }) + .when('/admin/orgs/edit/:id', { + templateUrl: 'app/features/admin/partials/edit_org.html', + controller : 'AdminEditOrgCtrl', }) .when('/login', { templateUrl: 'app/partials/login.html',