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
This commit is contained in:
@@ -61,8 +61,9 @@ limitations under the License.
|
|||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
gr-search-bar {
|
gr-search-bar {
|
||||||
|
flex-grow: 1;
|
||||||
margin-left: .5em;
|
margin-left: .5em;
|
||||||
width: 500px;
|
max-width: 500px;
|
||||||
}
|
}
|
||||||
.accountContainer:not(.loggedIn):not(.loggedOut) .loginButton,
|
.accountContainer:not(.loggedIn):not(.loggedOut) .loginButton,
|
||||||
.accountContainer:not(.loggedIn):not(.loggedOut) gr-account-dropdown,
|
.accountContainer:not(.loggedIn):not(.loggedOut) gr-account-dropdown,
|
||||||
|
|||||||
@@ -14,6 +14,32 @@
|
|||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'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 = [{
|
var DEFAULT_LINKS = [{
|
||||||
title: 'Changes',
|
title: 'Changes',
|
||||||
links: [
|
links: [
|
||||||
@@ -46,6 +72,10 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_account: Object,
|
_account: Object,
|
||||||
|
_adminLinks: {
|
||||||
|
type: Array,
|
||||||
|
value: function() { return []; },
|
||||||
|
},
|
||||||
_defaultLinks: {
|
_defaultLinks: {
|
||||||
type: Array,
|
type: Array,
|
||||||
value: function() {
|
value: function() {
|
||||||
@@ -54,7 +84,7 @@
|
|||||||
},
|
},
|
||||||
_links: {
|
_links: {
|
||||||
type: Array,
|
type: Array,
|
||||||
computed: '_computeLinks(_defaultLinks, _userLinks)',
|
computed: '_computeLinks(_defaultLinks, _userLinks, _adminLinks)',
|
||||||
},
|
},
|
||||||
_loginURL: {
|
_loginURL: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -94,7 +124,7 @@
|
|||||||
return '//' + window.location.host + path;
|
return '//' + window.location.host + path;
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeLinks: function(defaultLinks, userLinks) {
|
_computeLinks: function(defaultLinks, userLinks, adminLinks) {
|
||||||
var links = defaultLinks.slice();
|
var links = defaultLinks.slice();
|
||||||
if (userLinks && userLinks.length > 0) {
|
if (userLinks && userLinks.length > 0) {
|
||||||
links.push({
|
links.push({
|
||||||
@@ -102,6 +132,12 @@
|
|||||||
links: userLinks,
|
links: userLinks,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (adminLinks && adminLinks.length > 0) {
|
||||||
|
links.push({
|
||||||
|
title: 'Admin',
|
||||||
|
links: adminLinks,
|
||||||
|
});
|
||||||
|
}
|
||||||
return links;
|
return links;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -120,6 +156,18 @@
|
|||||||
this._userLinks =
|
this._userLinks =
|
||||||
prefs.my.map(this._stripHashPrefix).filter(this._isSupportedLink);
|
prefs.my.map(this._stripHashPrefix).filter(this._isSupportedLink);
|
||||||
}.bind(this));
|
}.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) {
|
_stripHashPrefix: function(linkObj) {
|
||||||
|
|||||||
@@ -33,8 +33,10 @@ limitations under the License.
|
|||||||
<script>
|
<script>
|
||||||
suite('gr-main-header tests', function() {
|
suite('gr-main-header tests', function() {
|
||||||
var element;
|
var element;
|
||||||
|
var sandbox;
|
||||||
|
|
||||||
setup(function() {
|
setup(function() {
|
||||||
|
sandbox = sinon.sandbox.create();
|
||||||
stub('gr-rest-api-interface', {
|
stub('gr-rest-api-interface', {
|
||||||
getConfig: function() { return Promise.resolve({}); },
|
getConfig: function() { return Promise.resolve({}); },
|
||||||
});
|
});
|
||||||
@@ -44,6 +46,10 @@ limitations under the License.
|
|||||||
element = fixture('basic');
|
element = fixture('basic');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
teardown(function() {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
|
|
||||||
test('strip hash prefix', function() {
|
test('strip hash prefix', function() {
|
||||||
assert.deepEqual([
|
assert.deepEqual([
|
||||||
{url: '#/q/owner:self+is:draft'},
|
{url: '#/q/owner:self+is:draft'},
|
||||||
@@ -69,6 +75,30 @@ limitations under the License.
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('_loadAccountCapabilities admin', function(done) {
|
||||||
|
sandbox.stub(element.$.restAPI, 'getAccountCapabilities', function() {
|
||||||
|
return Promise.resolve({
|
||||||
|
createGroup: true,
|
||||||
|
createProject: true,
|
||||||
|
viewPlugins: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
element._loadAccountCapabilities().then(function() {
|
||||||
|
assert.equal(element._adminLinks.length, 5);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('_loadAccountCapabilities non admin', function(done) {
|
||||||
|
sandbox.stub(element.$.restAPI, 'getAccountCapabilities', function() {
|
||||||
|
return Promise.resolve({});
|
||||||
|
});
|
||||||
|
element._loadAccountCapabilities().then(function() {
|
||||||
|
assert.equal(element._adminLinks.length, 2);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('user links', function() {
|
test('user links', function() {
|
||||||
var defaultLinks = [{
|
var defaultLinks = [{
|
||||||
title: 'Faves',
|
title: 'Faves',
|
||||||
@@ -81,11 +111,21 @@ limitations under the License.
|
|||||||
name: 'Facebook',
|
name: 'Facebook',
|
||||||
url: 'https://facebook.com',
|
url: 'https://facebook.com',
|
||||||
}];
|
}];
|
||||||
assert.deepEqual(element._computeLinks(defaultLinks, []), defaultLinks);
|
var adminLinks = [{
|
||||||
assert.deepEqual(element._computeLinks(defaultLinks, userLinks),
|
url: '/admin/groups',
|
||||||
|
name: 'Groups',
|
||||||
|
}];
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
element._computeLinks(defaultLinks, [], []), defaultLinks);
|
||||||
|
assert.deepEqual(
|
||||||
|
element._computeLinks(defaultLinks, userLinks, adminLinks),
|
||||||
defaultLinks.concat({
|
defaultLinks.concat({
|
||||||
title: 'Your',
|
title: 'Your',
|
||||||
links: userLinks,
|
links: userLinks,
|
||||||
|
}, {
|
||||||
|
title: 'Admin',
|
||||||
|
links: adminLinks,
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -317,6 +317,17 @@
|
|||||||
return this._fetchSharedCacheURL('/accounts/self/groups');
|
return this._fetchSharedCacheURL('/accounts/self/groups');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getAccountCapabilities: function(opt_params) {
|
||||||
|
var queryString = '';
|
||||||
|
if (opt_params) {
|
||||||
|
queryString = '?q=' + opt_params
|
||||||
|
.map(function(param) { return encodeURIComponent(param); })
|
||||||
|
.join('&q=');
|
||||||
|
}
|
||||||
|
return this._fetchSharedCacheURL('/accounts/self/capabilities' +
|
||||||
|
queryString);
|
||||||
|
},
|
||||||
|
|
||||||
getLoggedIn: function() {
|
getLoggedIn: function() {
|
||||||
return this.getAccount().then(function(account) {
|
return this.getAccount().then(function(account) {
|
||||||
return account != null;
|
return account != null;
|
||||||
|
|||||||
Reference in New Issue
Block a user