Disable "change reviewed" features when attention set is enabled

Change-Id: I325a0b190e034460cf80a50082456abc51cd43c6
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js
index dab456e..b238689 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js
@@ -300,8 +300,10 @@
       ? 0 : undefined;
   }
 
-  _computeItemNeedsReview(account, change, showReviewedState) {
-    return showReviewedState && !change.reviewed &&
+  _computeItemNeedsReview(account, change, showReviewedState, config) {
+    const isAttentionSetEnabled =
+        !!config && !!config.change && config.change.enable_attention_set;
+    return !isAttentionSetEnabled && showReviewedState && !change.reviewed &&
         !change.work_in_progress &&
         this.changeIsOpen(change) &&
         (!account || account._account_id != change.owner._account_id);
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_html.js b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_html.js
index cfcde94..a18ffd0 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_html.js
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_html.js
@@ -134,7 +134,7 @@
             account="[[account]]"
             selected$="[[_computeItemSelected(sectionIndex, index, selectedIndex)]]"
             highlight$="[[_computeItemHighlight(account, change)]]"
-            needs-review$="[[_computeItemNeedsReview(account, change, showReviewedState)]]"
+            needs-review$="[[_computeItemNeedsReview(account, change, showReviewedState, _config)]]"
             change="[[change]]"
             config="[[_config]]"
             visible-change-table-columns="[[visibleChangeTableColumns]]"
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_test.html b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_test.html
index 62763d9..16abb10 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_test.html
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_test.html
@@ -277,6 +277,15 @@
     assert.isFalse(elementItems[2].hasAttribute('needs-review'));
     assert.isFalse(elementItems[3].hasAttribute('needs-review'));
     assert.isFalse(elementItems[4].hasAttribute('needs-review'));
+
+    element._config = {
+      change: {enable_attention_set: true},
+    };
+    elementItems = dom(element.root).querySelectorAll(
+        'gr-change-list-item');
+    for (let i = 0; i < elementItems.length; i++) {
+      assert.isFalse(elementItems[i].hasAttribute('needs-review'));
+    }
   });
 
   test('no changes', () => {
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js
index 37e1b17..21ccf82 100644
--- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js
+++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js
@@ -233,6 +233,11 @@
 */
 const SKIP_ACTION_KEYS = [ChangeActions.REVERT_SUBMISSION];
 
+const SKIP_ACTION_KEYS_ATTENTION_SET = [
+  ChangeActions.REVIEWED,
+  ChangeActions.UNREVIEWED,
+];
+
 /**
  * @extends PolymerElement
  */
@@ -360,7 +365,7 @@
         type: Array,
         computed: '_computeAllActions(actions.*, revisionActions.*,' +
           'primaryActionKeys.*, _additionalActions.*, change, ' +
-          '_actionPriorityOverrides.*)',
+          '_config, _actionPriorityOverrides.*)',
       },
       _topLevelActions: {
         type: Array,
@@ -462,6 +467,7 @@
         type: Boolean,
         value: true,
       },
+      _config: Object,
     };
   }
 
@@ -487,6 +493,9 @@
   ready() {
     super.ready();
     this.$.jsAPI.addElement(this.$.jsAPI.Element.CHANGE_ACTIONS, this);
+    this.$.restAPI.getConfig().then(config => {
+      this._config = config;
+    });
     this._handleLoadingComplete();
   }
 
@@ -1515,10 +1524,11 @@
    * @param {!Array} primariesRecord
    * @param {!Array} additionalActionsRecord
    * @param {!Object} change The change object.
+   * @param {!Object} config server configuration info
    * @return {!Array}
    */
   _computeAllActions(changeActionsRecord, revisionActionsRecord,
-      primariesRecord, additionalActionsRecord, change) {
+      primariesRecord, additionalActionsRecord, change, config) {
     // Polymer 2: check for undefined
     if ([
       changeActionsRecord,
@@ -1554,7 +1564,7 @@
           // End of hack
           return action;
         })
-        .filter(action => !this._shouldSkipAction(action));
+        .filter(action => !this._shouldSkipAction(action, config));
   }
 
   _getActionPriority(action) {
@@ -1592,8 +1602,14 @@
     }
   }
 
-  _shouldSkipAction(action) {
-    return SKIP_ACTION_KEYS.includes(action.__key);
+  _shouldSkipAction(action, config) {
+    const skipActionKeys = [...SKIP_ACTION_KEYS];
+    const isAttentionSetEnabled = !!config && !!config.change
+        && config.change.enable_attention_set;
+    if (isAttentionSetEnabled) {
+      skipActionKeys.push(...SKIP_ACTION_KEYS_ATTENTION_SET);
+    }
+    return skipActionKeys.includes(action.__key);
   }
 
   _computeTopLevelActions(actionRecord, hiddenActionsRecord) {
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html
index cda53c5..5efeebd 100644
--- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html
+++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html
@@ -145,8 +145,10 @@
     });
 
     test('revert submission action is skipped', () => {
-      assert.isFalse(element._allActionValues.includes(action =>
-        action.key === 'revert_submission'));
+      assert.equal(element._allActionValues.filter(action =>
+        action.__key === 'submit').length, 1);
+      assert.equal(element._allActionValues.filter(action =>
+        action.__key === 'revert_submission').length, 0);
     });
 
     test('_shouldHideActions', () => {
@@ -1458,6 +1460,19 @@
         element.reload().then(() => { flush(done); });
       });
 
+      test('action is enabled', () => {
+        assert.equal(element._allActionValues.filter(action =>
+          action.__key === 'reviewed').length, 1);
+      });
+
+      test('action is skipped when attention set is enabled', () => {
+        element._config = {
+          change: {enable_attention_set: true},
+        };
+        assert.equal(element._allActionValues.filter(action =>
+          action.__key === 'reviewed').length, 0);
+      });
+
       test('make sure the reviewed button is not outside of the overflow menu',
           () => {
             assert.isNotOk(element.shadowRoot
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 963031a..9861a03 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
@@ -1940,10 +1940,15 @@
   }
 
   saveChangeReviewed(changeNum, reviewed) {
-    return this._getChangeURLAndSend({
-      changeNum,
-      method: 'PUT',
-      endpoint: reviewed ? '/reviewed' : '/unreviewed',
+    return this.getConfig().then(config => {
+      const isAttentionSetEnabled = !!config && !!config.change
+          && config.change.enable_attention_set;
+      if (isAttentionSetEnabled) return Promise.resolve();
+      return this._getChangeURLAndSend({
+        changeNum,
+        method: 'PUT',
+        endpoint: reviewed ? '/reviewed' : '/unreviewed',
+      });
     });
   }