Do not send getStatus request if the plugin is disabled for a project
Change-Id: Ibb0adcd84205dcb3c78b4fd2b3614e0765b6b856
diff --git a/ui/code-owners-service.js b/ui/code-owners-service.js
index 86dc89c..1d6f738 100644
--- a/ui/code-owners-service.js
+++ b/ui/code-owners-service.js
@@ -142,18 +142,29 @@
}
return this.restApi.getAccount();
});
- this.statusPromise = this.codeOwnerApi
- .listOwnerStatus(this.change._number)
- .then(res => {
- return {
- patchsetNumber: res.patch_set_number,
- codeOwnerStatusMap: this._formatStatuses(
- res.file_code_owner_statuses
- ),
- rawStatuses: res.file_code_owner_statuses,
- };
- });
+ this.statusPromise = this.isCodeOwnerEnabled().then(enabled => {
+ if (!enabled) {
+ return {
+ patchsetNumber: 0,
+ enabled: false,
+ codeOwnerStatusMap: new Map(),
+ rawStatuses: [],
+ };
+ }
+ return this.codeOwnerApi
+ .listOwnerStatus(this.change._number)
+ .then(res => {
+ return {
+ enabled: true,
+ patchsetNumber: res.patch_set_number,
+ codeOwnerStatusMap: this._formatStatuses(
+ res.file_code_owner_statuses
+ ),
+ rawStatuses: res.file_code_owner_statuses,
+ };
+ });
+ });
}
/**
@@ -163,7 +174,7 @@
* role 'REVIEWER' remains unchanged until the change view is reloaded.
*/
getLoggedInUserInitialRole() {
- return this.accountPromise.then((account) => {
+ return this.accountPromise.then(account => {
if (!account) {
return UserRole.ANONYMOUS;
}
@@ -175,19 +186,19 @@
) {
const commit = change.revisions[change.current_revision].commit;
if (
- commit &&
- commit.author &&
- account.email &&
- commit.author.email === account.email
+ commit &&
+ commit.author &&
+ account.email &&
+ commit.author.email === account.email
) {
return UserRole.AUTHOR;
}
}
- if(change.owner._account_id === account._account_id) {
+ if (change.owner._account_id === account._account_id) {
return UserRole.CHANGE_OWNER;
}
- if(change.reviewers) {
- if(this._accountInReviewers(change.reviewers.REVIEWER, account)) {
+ if (change.reviewers) {
+ if (this._accountInReviewers(change.reviewers.REVIEWER, account)) {
return UserRole.REVIEWER;
} else if (this._accountInReviewers(change.reviewers.CC, account)) {
return UserRole.CC;
@@ -200,7 +211,7 @@
}
_accountInReviewers(reviewers, account) {
- if(!reviewers) {
+ if (!reviewers) {
return false;
}
return reviewers.some(reviewer => reviewer._account_id === account._account_id);
@@ -208,7 +219,7 @@
getStatus() {
return this.statusPromise.then(res => {
- if (!this.isOnLatestPatchset(res.patchsetNumber)) {
+ if (res.enabled && !this.isOnLatestPatchset(res.patchsetNumber)) {
// status is outdated, abort and re-init
this.abort();
this.init();
@@ -395,15 +406,6 @@
};
}
- /**
- * Returns a promise with whether status is for latest patchset or not.
- */
- isStatusOnLatestPatchset() {
- return this.statusPromise.then(({patch_set_id}) => {
- return this.isOnLatestPatchset(patch_set_id);
- });
- }
-
isOnLatestPatchset(patchsetId) {
const latestRevision = this.change.revisions[this.change.current_revision];
return `${latestRevision._number}` === `${patchsetId}`;
@@ -458,7 +460,11 @@
}
getProjectConfig() {
- return this.codeOwnerApi.getProjectConfig(this.change.project);
+ if (!this.getProjectConfigPromise) {
+ this.getProjectConfigPromise =
+ this.codeOwnerApi.getProjectConfig(this.change.project);
+ }
+ return this.getProjectConfigPromise;
}
isCodeOwnerEnabled() {