Mark admin navigation link URLs without included base URLs
With Ifa3e19c509, the admin navigation links became a mixture of URLs generated by the new router abstraction and older URLs that are hard-coded. Whereas router-generated links already include the base URL, the base must be added to hard-coded links. With this change, boolean properties are added so that the admin view can determine whether the link already includes the base URL and avoid adding it twice. Bug: Issue 7612 Change-Id: I6ed33aeb147a1bff924c0a684ed8a0eb6ad71ad1
This commit is contained in:
		@@ -14,8 +14,11 @@
 | 
				
			|||||||
(function() {
 | 
					(function() {
 | 
				
			||||||
  'use strict';
 | 
					  'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Note: noBaseUrl: true is set on entries where the URL is not yet supported
 | 
				
			||||||
 | 
					  // by router abstraction.
 | 
				
			||||||
  const ADMIN_LINKS = [{
 | 
					  const ADMIN_LINKS = [{
 | 
				
			||||||
    name: 'Projects',
 | 
					    name: 'Projects',
 | 
				
			||||||
 | 
					    noBaseUrl: true,
 | 
				
			||||||
    url: '/admin/projects',
 | 
					    url: '/admin/projects',
 | 
				
			||||||
    view: 'gr-project-list',
 | 
					    view: 'gr-project-list',
 | 
				
			||||||
    viewableToAll: true,
 | 
					    viewableToAll: true,
 | 
				
			||||||
@@ -23,6 +26,7 @@
 | 
				
			|||||||
  }, {
 | 
					  }, {
 | 
				
			||||||
    name: 'Groups',
 | 
					    name: 'Groups',
 | 
				
			||||||
    section: 'Groups',
 | 
					    section: 'Groups',
 | 
				
			||||||
 | 
					    noBaseUrl: true,
 | 
				
			||||||
    url: '/admin/groups',
 | 
					    url: '/admin/groups',
 | 
				
			||||||
    view: 'gr-admin-group-list',
 | 
					    view: 'gr-admin-group-list',
 | 
				
			||||||
    children: [],
 | 
					    children: [],
 | 
				
			||||||
@@ -30,6 +34,7 @@
 | 
				
			|||||||
    name: 'Plugins',
 | 
					    name: 'Plugins',
 | 
				
			||||||
    capability: 'viewPlugins',
 | 
					    capability: 'viewPlugins',
 | 
				
			||||||
    section: 'Plugins',
 | 
					    section: 'Plugins',
 | 
				
			||||||
 | 
					    noBaseUrl: true,
 | 
				
			||||||
    url: '/admin/plugins',
 | 
					    url: '/admin/plugins',
 | 
				
			||||||
    view: 'gr-plugin-list',
 | 
					    view: 'gr-plugin-list',
 | 
				
			||||||
  }];
 | 
					  }];
 | 
				
			||||||
@@ -113,11 +118,13 @@
 | 
				
			|||||||
          linkCopy.subsection = {
 | 
					          linkCopy.subsection = {
 | 
				
			||||||
            name: this._projectName,
 | 
					            name: this._projectName,
 | 
				
			||||||
            view: 'gr-project',
 | 
					            view: 'gr-project',
 | 
				
			||||||
 | 
					            noBaseUrl: true,
 | 
				
			||||||
            url: `/admin/projects/${this.encodeURL(this._projectName, true)}`,
 | 
					            url: `/admin/projects/${this.encodeURL(this._projectName, true)}`,
 | 
				
			||||||
            children: [{
 | 
					            children: [{
 | 
				
			||||||
              name: 'Access',
 | 
					              name: 'Access',
 | 
				
			||||||
              detailType: 'access',
 | 
					              detailType: 'access',
 | 
				
			||||||
              view: 'gr-project-access',
 | 
					              view: 'gr-project-access',
 | 
				
			||||||
 | 
					              noBaseUrl: true,
 | 
				
			||||||
              url: `/admin/projects/` +
 | 
					              url: `/admin/projects/` +
 | 
				
			||||||
                  `${this.encodeURL(this._projectName, true)},access`,
 | 
					                  `${this.encodeURL(this._projectName, true)},access`,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
@@ -125,6 +132,7 @@
 | 
				
			|||||||
              name: 'Commands',
 | 
					              name: 'Commands',
 | 
				
			||||||
              detailType: 'commands',
 | 
					              detailType: 'commands',
 | 
				
			||||||
              view: 'gr-project-commands',
 | 
					              view: 'gr-project-commands',
 | 
				
			||||||
 | 
					              noBaseUrl: true,
 | 
				
			||||||
              url: `/admin/projects/` +
 | 
					              url: `/admin/projects/` +
 | 
				
			||||||
                  `${this.encodeURL(this._projectName, true)},commands`,
 | 
					                  `${this.encodeURL(this._projectName, true)},commands`,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
@@ -132,6 +140,7 @@
 | 
				
			|||||||
              name: 'Branches',
 | 
					              name: 'Branches',
 | 
				
			||||||
              detailType: 'branches',
 | 
					              detailType: 'branches',
 | 
				
			||||||
              view: 'gr-project-detail-list',
 | 
					              view: 'gr-project-detail-list',
 | 
				
			||||||
 | 
					              noBaseUrl: true,
 | 
				
			||||||
              url: `/admin/projects/` +
 | 
					              url: `/admin/projects/` +
 | 
				
			||||||
                  `${this.encodeURL(this._projectName, true)},branches`,
 | 
					                  `${this.encodeURL(this._projectName, true)},branches`,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
@@ -139,6 +148,7 @@
 | 
				
			|||||||
              name: 'Tags',
 | 
					              name: 'Tags',
 | 
				
			||||||
              detailType: 'tags',
 | 
					              detailType: 'tags',
 | 
				
			||||||
              view: 'gr-project-detail-list',
 | 
					              view: 'gr-project-detail-list',
 | 
				
			||||||
 | 
					              noBaseUrl: true,
 | 
				
			||||||
              url: `/admin/projects/` +
 | 
					              url: `/admin/projects/` +
 | 
				
			||||||
                  `${this.encodeURL(this._projectName, true)},tags`,
 | 
					                  `${this.encodeURL(this._projectName, true)},tags`,
 | 
				
			||||||
            }],
 | 
					            }],
 | 
				
			||||||
@@ -236,7 +246,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    _computeLinkURL(link) {
 | 
					    _computeLinkURL(link) {
 | 
				
			||||||
      if (!link || typeof link.url === 'undefined') { return ''; }
 | 
					      if (!link || typeof link.url === 'undefined') { return ''; }
 | 
				
			||||||
      if (link.target) {
 | 
					      if (link.target || !link.noBaseUrl) {
 | 
				
			||||||
        return link.url;
 | 
					        return link.url;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      return this._computeRelativeURL(link.url);
 | 
					      return this._computeRelativeURL(link.url);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -59,8 +59,14 @@ limitations under the License.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    test('link URLs', () => {
 | 
					    test('link URLs', () => {
 | 
				
			||||||
      assert.equal(
 | 
					      assert.equal(
 | 
				
			||||||
          element._computeLinkURL({url: '/test'}),
 | 
					          element._computeLinkURL({url: '/test', noBaseUrl: true}),
 | 
				
			||||||
          '//' + window.location.host + '/test');
 | 
					          '//' + window.location.host + '/test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      sandbox.stub(element, 'getBaseUrl').returns('/foo');
 | 
				
			||||||
 | 
					      assert.equal(
 | 
				
			||||||
 | 
					          element._computeLinkURL({url: '/test', noBaseUrl: true}),
 | 
				
			||||||
 | 
					          '//' + window.location.host + '/foo/test');
 | 
				
			||||||
 | 
					      assert.equal(element._computeLinkURL({url: '/test'}), '/test');
 | 
				
			||||||
      assert.equal(
 | 
					      assert.equal(
 | 
				
			||||||
          element._computeLinkURL({url: '/test', target: '_blank'}),
 | 
					          element._computeLinkURL({url: '/test', target: '_blank'}),
 | 
				
			||||||
          '/test');
 | 
					          '/test');
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user