summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <dpursehouse@collab.net>2018-09-26 05:27:00 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-09-26 05:27:00 +0000
commit2f8a5a831e518a5e03ab1e57e0dec8098d827640 (patch)
treebf62e00de4087d07a5d0b15ff2f82c366416e5c1
parent0d9cc6db67475559d4eff914f35b8ef47e928b64 (diff)
parente36486918697526cb08616154b4b93030cb616f5 (diff)
Merge changes I2c3e4cfb,I1647c5ab
* changes: PolyGerrit: Respect register URL when provided by auth scheme PolyGerrit: Add support for menus provided by plugins
-rw-r--r--polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.html13
-rw-r--r--polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js55
-rw-r--r--polygerrit-ui/app/elements/core/gr-main-header/gr-main-header_test.html67
-rw-r--r--polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js8
4 files changed, 131 insertions, 12 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 89b354842e..9822860669 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
@@ -112,12 +112,14 @@ limitations under the License.
margin: 5px 4px;
text-decoration: none;
}
+ .invisible,
.settingsButton,
gr-account-dropdown {
display: none;
}
:host([loading]) .accountContainer,
- :host([logged-in]) .loginButton {
+ :host([logged-in]) .loginButton,
+ :host([logged-in]) .registerButton {
display: none;
}
:host([logged-in]) .settingsButton,
@@ -135,7 +137,7 @@ limitations under the License.
text-overflow: ellipsis;
white-space: nowrap;
}
- .loginButton {
+ .loginButton, .registerButton {
color: var(--header-text-color);
padding: .5em 1em;
}
@@ -194,6 +196,13 @@ limitations under the License.
class="hideOnMobile"
name="header-browse-source"></gr-endpoint-decorator>
<div class="accountContainer" id="accountContainer">
+ <div class$="[[_computeIsInvisible(_registerURL)]]">
+ <a
+ class="registerButton"
+ href$="[[_registerURL]]">
+ [[_registerText]]
+ </a>
+ </div>
<a class="loginButton" href$="[[_loginURL]]">Sign in</a>
<a
class="settingsButton"
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 dad7b7c1c4..3978c658b5 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
@@ -62,6 +62,13 @@
},
];
+ // Set of authentication methods that can provide custom registration page.
+ const AUTH_TYPES_WITH_REGISTER_URL = new Set([
+ 'LDAP',
+ 'LDAP_BIND',
+ 'CUSTOM_EXTENSION',
+ ]);
+
Polymer({
is: 'gr-main-header',
@@ -102,7 +109,7 @@
_links: {
type: Array,
computed: '_computeLinks(_defaultLinks, _userLinks, _adminLinks, ' +
- '_docBaseUrl)',
+ '_topMenus, _docBaseUrl)',
},
_loginURL: {
type: String,
@@ -112,6 +119,18 @@
type: Array,
value() { return []; },
},
+ _topMenus: {
+ type: Array,
+ value() { return []; },
+ },
+ _registerText: {
+ type: String,
+ value: 'Sign up',
+ },
+ _registerURL: {
+ type: String,
+ value: null,
+ },
},
behaviors: [
@@ -159,7 +178,7 @@
return '//' + window.location.host + this.getBaseUrl() + path;
},
- _computeLinks(defaultLinks, userLinks, adminLinks, docBaseUrl) {
+ _computeLinks(defaultLinks, userLinks, adminLinks, topMenus, docBaseUrl) {
const links = defaultLinks.slice();
if (userLinks && userLinks.length > 0) {
links.push({
@@ -179,6 +198,12 @@
title: 'Browse',
links: adminLinks,
});
+ for (const m of topMenus) {
+ links.push({
+ title: m.name,
+ links: m.items.map(this._fixCustomMenuItem),
+ });
+ }
return links;
},
@@ -203,6 +228,7 @@
this.loading = true;
const promises = [
this.$.restAPI.getAccount(),
+ this.$.restAPI.getTopMenus(),
Gerrit.awaitPluginsLoaded(),
];
@@ -211,6 +237,7 @@
this._account = account;
this.loggedIn = !!account;
this.loading = false;
+ this._topMenus = result[1];
return this.getAdminLinks(account,
this.$.restAPI.getAccountCapabilities.bind(this.$.restAPI),
@@ -223,7 +250,10 @@
_loadConfig() {
this.$.restAPI.getConfig()
- .then(config => this.getDocsBaseUrl(config, this.$.restAPI))
+ .then(config => {
+ this._retrieveRegisterURL(config);
+ this.getDocsBaseUrl(config, this.$.restAPI);
+ })
.then(docBaseUrl => { this._docBaseUrl = docBaseUrl; });
},
@@ -232,11 +262,24 @@
this.$.restAPI.getPreferences().then(prefs => {
this._userLinks =
- prefs.my.map(this._fixMyMenuItem).filter(this._isSupportedLink);
+ prefs.my.map(this._fixCustomMenuItem).filter(this._isSupportedLink);
});
},
- _fixMyMenuItem(linkObj) {
+ _retrieveRegisterURL(config) {
+ if (AUTH_TYPES_WITH_REGISTER_URL.has(config.auth.auth_type)) {
+ this._registerURL = config.auth.register_url;
+ if (config.auth.register_text) {
+ this._registerText = config.auth.register_text;
+ }
+ }
+ },
+
+ _computeIsInvisible(registerURL) {
+ return registerURL ? '' : 'invisible';
+ },
+
+ _fixCustomMenuItem(linkObj) {
// Normalize all urls to PolyGerrit style.
if (linkObj.url.startsWith('#')) {
linkObj.url = linkObj.url.slice(1);
@@ -251,7 +294,7 @@
// so we'll just disable it altogether for now.
delete linkObj.target;
- // Becasue the "my menu" links may be arbitrary URLs, we don't know
+ // Because the user provided links may be arbitrary URLs, we don't know
// whether they correspond to any client routes. Mark all such links as
// external.
linkObj.external = true;
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 30e8e1fc79..b6e64ec51a 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
@@ -63,6 +63,8 @@ limitations under the License.
'none');
assert.notEqual(getComputedStyle(element.$$('.loginButton')).display,
'none');
+ assert.notEqual(getComputedStyle(element.$$('.registerButton')).display,
+ 'none');
assert.equal(getComputedStyle(element.$$('gr-account-dropdown')).display,
'none');
assert.equal(getComputedStyle(element.$$('.settingsButton')).display,
@@ -70,6 +72,8 @@ limitations under the License.
element.loggedIn = true;
assert.equal(getComputedStyle(element.$$('.loginButton')).display,
'none');
+ assert.equal(getComputedStyle(element.$$('.registerButton')).display,
+ 'none');
assert.notEqual(getComputedStyle(element.$$('gr-account-dropdown'))
.display,
'none');
@@ -81,7 +85,7 @@ limitations under the License.
assert.deepEqual([
{url: 'https://awesometown.com/#hashyhash'},
{url: 'url', target: '_blank'},
- ].map(element._fixMyMenuItem), [
+ ].map(element._fixCustomMenuItem), [
{url: 'https://awesometown.com/#hashyhash', external: true},
{url: 'url', external: true},
]);
@@ -98,7 +102,6 @@ limitations under the License.
]);
});
-
test('user links', () => {
const defaultLinks = [{
title: 'Faves',
@@ -117,13 +120,13 @@ limitations under the License.
}];
// When no admin links are passed, it should use the default.
- assert.deepEqual(element._computeLinks(defaultLinks, [], adminLinks),
+ assert.deepEqual(element._computeLinks(defaultLinks, [], adminLinks, []),
defaultLinks.concat({
title: 'Browse',
links: adminLinks,
}));
assert.deepEqual(
- element._computeLinks(defaultLinks, userLinks, adminLinks),
+ element._computeLinks(defaultLinks, userLinks, adminLinks, []),
defaultLinks.concat([
{
title: 'Your',
@@ -160,5 +163,61 @@ limitations under the License.
url: 'base/index.html',
}]);
});
+
+ test('top menus', () => {
+ const adminLinks = [{
+ name: 'Repos',
+ url: '/repos',
+ }];
+ const topMenus = [{
+ name: 'Plugins',
+ items: [{
+ name: 'Manage',
+ target: '_blank',
+ url: 'https://gerrit/plugins/plugin-manager/static/index.html',
+ }],
+ }];
+ assert.deepEqual(element._computeLinks([], [], adminLinks, topMenus), [{
+ title: 'Browse',
+ links: adminLinks,
+ },
+ {
+ title: 'Plugins',
+ links: [{
+ name: 'Manage',
+ external: true,
+ url: 'https://gerrit/plugins/plugin-manager/static/index.html',
+ }],
+ }]);
+ });
+
+ test('register URL', () => {
+ const config = {
+ auth: {
+ auth_type: 'LDAP',
+ register_url: 'https//gerrit.example.com/register',
+ },
+ };
+ element._retrieveRegisterURL(config);
+ assert.equal(element._registerURL, config.auth.register_url);
+ assert.equal(element._registerText, 'Sign up');
+
+ config.auth.register_text = 'Create account';
+ element._retrieveRegisterURL(config);
+ assert.equal(element._registerURL, config.auth.register_url);
+ assert.equal(element._registerText, config.auth.register_text);
+ });
+
+ test('register URL ignored for wrong auth type', () => {
+ const config = {
+ auth: {
+ auth_type: 'OPENID',
+ register_url: 'https//gerrit.example.com/register',
+ },
+ };
+ element._retrieveRegisterURL(config);
+ assert.equal(element._registerURL, null);
+ assert.equal(element._registerText, 'Sign up');
+ });
});
</script>
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
index 7b48454be1..0b90cdf1b6 100644
--- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
+++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
@@ -2640,6 +2640,14 @@
});
},
+ getTopMenus(opt_errFn) {
+ return this._fetchJSON({
+ url: '/config/server/top-menus',
+ errFn: opt_errFn,
+ reportUrlAsIs: true,
+ });
+ },
+
setAssignee(changeNum, assignee) {
return this._getChangeURLAndSend({
changeNum,