diff options
author | Dhruv Srivastava <dhruvsri@google.com> | 2020-11-04 16:00:31 +0100 |
---|---|---|
committer | Luca Milanesio <luca.milanesio@gmail.com> | 2020-11-10 16:59:52 +0000 |
commit | 13a3c0d133ca7a9293f361ceab821b8fd091a9e6 (patch) | |
tree | 523e3a40934efe88a946e1c35eb3b9d3acc73c31 | |
parent | 35c4262b51d8cefb1f3e6bfbfe94af82d5e85962 (diff) |
Only request ported drafts if user is logged in
Requesting ported drafts for non-logged in users results in 500
server response.
Change-Id: Ic04e593939f3749c77c5f67a49a0b90b1e47ae51
-rw-r--r-- | polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.ts | 13 | ||||
-rw-r--r-- | polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.js | 11 |
2 files changed, 19 insertions, 5 deletions
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.ts b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.ts index 724de9c8ce..1a89008d50 100644 --- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.ts +++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.ts @@ -2821,11 +2821,14 @@ export class GrRestApiInterface if (response) console.info(`Fetching ported drafts failed, ${response.status}`); }; - return this._getChangeURLAndFetch({ - changeNum, - endpoint: '/ported_drafts/', - revision, - errFn, + return this.getLoggedIn().then(loggedIn => { + if (!loggedIn) return {}; + return this._getChangeURLAndFetch({ + changeNum, + endpoint: '/ported_drafts/', + revision, + errFn, + }); }); } diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.js index 9c21899ab3..d75c1865d7 100644 --- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.js +++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.js @@ -1355,6 +1355,17 @@ suite('gr-rest-api-interface tests', () => { assert.isFalse(dispatchStub.called); }); + test('ported drafts are not requested user is not logged in', () => { + const change = createChange(); + sinon.stub(element, 'getLoggedIn').returns(Promise.resolve(false)); + const getChangeURLAndFetchStub = sinon.stub(element, + '_getChangeURLAndFetch'); + + element.getPortedDrafts(change._number, 'current'); + + assert.isFalse(getChangeURLAndFetchStub.called); + }); + test('saveChangeStarred', async () => { sinon.stub(element, 'getFromProjectLookup') .returns(Promise.resolve('test')); |