From 2ac8aaf87e976f14c9ac7b5dc6f89867ba7bfe4f Mon Sep 17 00:00:00 2001 From: Becky Siegel Date: Thu, 16 Feb 2017 08:58:29 -0800 Subject: [PATCH] Add admin menu skeleton Previously, people using Polygerrit did not realize how to access admin functionality in GWT. This build out a skeleton menu, and displays the appropriate menu items based on role. The page itself will still show the default admin view placeholder. Bug: Issue 5470 Change-Id: I1266dd8fb70d0afac485f1e547fae85acee7e5aa --- .../core/gr-main-header/gr-main-header.html | 3 +- .../core/gr-main-header/gr-main-header.js | 52 ++++++++++++++++++- .../gr-main-header/gr-main-header_test.html | 44 +++++++++++++++- .../gr-rest-api-interface.js | 11 ++++ 4 files changed, 105 insertions(+), 5 deletions(-) diff --git a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.html b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.html index 74dc9e759f..dc66bb63a3 100644 --- a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.html +++ b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.html @@ -61,8 +61,9 @@ limitations under the License. justify-content: flex-end; } gr-search-bar { + flex-grow: 1; margin-left: .5em; - width: 500px; + max-width: 500px; } .accountContainer:not(.loggedIn):not(.loggedOut) .loginButton, .accountContainer:not(.loggedIn):not(.loggedOut) gr-account-dropdown, diff --git a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js index ebeb9af1eb..c9abac25a8 100644 --- a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js +++ b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js @@ -14,6 +14,32 @@ (function() { 'use strict'; + var ADMIN_LINKS = [ + { + url: '/admin/groups', + name: 'Groups', + }, + { + url: '/admin/create-group', + name: 'Create Group', + capability: 'createGroup' + }, + { + url: '/admin/projects', + name: 'Projects', + }, + { + url: '/admin/create-project', + name: 'Create Project', + capability: 'createProject', + }, + { + url: '/admin/plugins', + name: 'Plugins', + capability: 'viewPlugins', + }, + ]; + var DEFAULT_LINKS = [{ title: 'Changes', links: [ @@ -46,6 +72,10 @@ }, _account: Object, + _adminLinks: { + type: Array, + value: function() { return []; }, + }, _defaultLinks: { type: Array, value: function() { @@ -54,7 +84,7 @@ }, _links: { type: Array, - computed: '_computeLinks(_defaultLinks, _userLinks)', + computed: '_computeLinks(_defaultLinks, _userLinks, _adminLinks)', }, _loginURL: { type: String, @@ -94,7 +124,7 @@ return '//' + window.location.host + path; }, - _computeLinks: function(defaultLinks, userLinks) { + _computeLinks: function(defaultLinks, userLinks, adminLinks) { var links = defaultLinks.slice(); if (userLinks && userLinks.length > 0) { links.push({ @@ -102,6 +132,12 @@ links: userLinks, }); } + if (adminLinks && adminLinks.length > 0) { + links.push({ + title: 'Admin', + links: adminLinks, + }); + } return links; }, @@ -120,6 +156,18 @@ this._userLinks = prefs.my.map(this._stripHashPrefix).filter(this._isSupportedLink); }.bind(this)); + this._loadAccountCapabilities(); + }, + + _loadAccountCapabilities: function() { + var params = ['createProject', 'createGroup', 'viewPlugins']; + return this.$.restAPI.getAccountCapabilities(params) + .then(function(capabilities) { + this._adminLinks = ADMIN_LINKS.filter(function(link) { + return !link.capability || + capabilities.hasOwnProperty(link.capability); + }); + }.bind(this)); }, _stripHashPrefix: function(linkObj) { diff --git a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header_test.html b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header_test.html index aef338b35b..75723b9103 100644 --- a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header_test.html +++ b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header_test.html @@ -33,8 +33,10 @@ limitations under the License.