Use imported AccessBehavior
This change removes usage of global Gerrit.AccessBehavior and replace it with direct import. Also, the AccessMixin is removed, because it was introduced as a workaround for polylint tests and is no longer needed. Change-Id: Ib484e7f4a46d7a61d5727cb9dbc0d972bfad0d22
This commit is contained in:
@@ -14,164 +14,142 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
(function(window) {
|
||||
'use strict';
|
||||
|
||||
window.Gerrit = window.Gerrit || {};
|
||||
|
||||
/** @polymerBehavior Gerrit.AccessBehavior */
|
||||
Gerrit.AccessBehavior = {
|
||||
properties: {
|
||||
permissionValues: {
|
||||
type: Object,
|
||||
readOnly: true,
|
||||
value: {
|
||||
abandon: {
|
||||
id: 'abandon',
|
||||
name: 'Abandon',
|
||||
},
|
||||
addPatchSet: {
|
||||
id: 'addPatchSet',
|
||||
name: 'Add Patch Set',
|
||||
},
|
||||
create: {
|
||||
id: 'create',
|
||||
name: 'Create Reference',
|
||||
},
|
||||
createTag: {
|
||||
id: 'createTag',
|
||||
name: 'Create Annotated Tag',
|
||||
},
|
||||
createSignedTag: {
|
||||
id: 'createSignedTag',
|
||||
name: 'Create Signed Tag',
|
||||
},
|
||||
delete: {
|
||||
id: 'delete',
|
||||
name: 'Delete Reference',
|
||||
},
|
||||
deleteChanges: {
|
||||
id: 'deleteChanges',
|
||||
name: 'Delete Changes',
|
||||
},
|
||||
deleteOwnChanges: {
|
||||
id: 'deleteOwnChanges',
|
||||
name: 'Delete Own Changes',
|
||||
},
|
||||
editAssignee: {
|
||||
id: 'editAssignee',
|
||||
name: 'Edit Assignee',
|
||||
},
|
||||
editHashtags: {
|
||||
id: 'editHashtags',
|
||||
name: 'Edit Hashtags',
|
||||
},
|
||||
editTopicName: {
|
||||
id: 'editTopicName',
|
||||
name: 'Edit Topic Name',
|
||||
},
|
||||
forgeAuthor: {
|
||||
id: 'forgeAuthor',
|
||||
name: 'Forge Author Identity',
|
||||
},
|
||||
forgeCommitter: {
|
||||
id: 'forgeCommitter',
|
||||
name: 'Forge Committer Identity',
|
||||
},
|
||||
forgeServerAsCommitter: {
|
||||
id: 'forgeServerAsCommitter',
|
||||
name: 'Forge Server Identity',
|
||||
},
|
||||
owner: {
|
||||
id: 'owner',
|
||||
name: 'Owner',
|
||||
},
|
||||
publishDrafts: {
|
||||
id: 'publishDrafts',
|
||||
name: 'Publish Drafts',
|
||||
},
|
||||
push: {
|
||||
id: 'push',
|
||||
name: 'Push',
|
||||
},
|
||||
pushMerge: {
|
||||
id: 'pushMerge',
|
||||
name: 'Push Merge Commit',
|
||||
},
|
||||
read: {
|
||||
id: 'read',
|
||||
name: 'Read',
|
||||
},
|
||||
rebase: {
|
||||
id: 'rebase',
|
||||
name: 'Rebase',
|
||||
},
|
||||
removeReviewer: {
|
||||
id: 'removeReviewer',
|
||||
name: 'Remove Reviewer',
|
||||
},
|
||||
submit: {
|
||||
id: 'submit',
|
||||
name: 'Submit',
|
||||
},
|
||||
submitAs: {
|
||||
id: 'submitAs',
|
||||
name: 'Submit (On Behalf Of)',
|
||||
},
|
||||
toggleWipState: {
|
||||
id: 'toggleWipState',
|
||||
name: 'Toggle Work In Progress State',
|
||||
},
|
||||
viewPrivateChanges: {
|
||||
id: 'viewPrivateChanges',
|
||||
name: 'View Private Changes',
|
||||
},
|
||||
/** @polymerBehavior Gerrit.AccessBehavior */
|
||||
export const AccessBehavior = {
|
||||
properties: {
|
||||
permissionValues: {
|
||||
type: Object,
|
||||
readOnly: true,
|
||||
value: {
|
||||
abandon: {
|
||||
id: 'abandon',
|
||||
name: 'Abandon',
|
||||
},
|
||||
addPatchSet: {
|
||||
id: 'addPatchSet',
|
||||
name: 'Add Patch Set',
|
||||
},
|
||||
create: {
|
||||
id: 'create',
|
||||
name: 'Create Reference',
|
||||
},
|
||||
createTag: {
|
||||
id: 'createTag',
|
||||
name: 'Create Annotated Tag',
|
||||
},
|
||||
createSignedTag: {
|
||||
id: 'createSignedTag',
|
||||
name: 'Create Signed Tag',
|
||||
},
|
||||
delete: {
|
||||
id: 'delete',
|
||||
name: 'Delete Reference',
|
||||
},
|
||||
deleteChanges: {
|
||||
id: 'deleteChanges',
|
||||
name: 'Delete Changes',
|
||||
},
|
||||
deleteOwnChanges: {
|
||||
id: 'deleteOwnChanges',
|
||||
name: 'Delete Own Changes',
|
||||
},
|
||||
editAssignee: {
|
||||
id: 'editAssignee',
|
||||
name: 'Edit Assignee',
|
||||
},
|
||||
editHashtags: {
|
||||
id: 'editHashtags',
|
||||
name: 'Edit Hashtags',
|
||||
},
|
||||
editTopicName: {
|
||||
id: 'editTopicName',
|
||||
name: 'Edit Topic Name',
|
||||
},
|
||||
forgeAuthor: {
|
||||
id: 'forgeAuthor',
|
||||
name: 'Forge Author Identity',
|
||||
},
|
||||
forgeCommitter: {
|
||||
id: 'forgeCommitter',
|
||||
name: 'Forge Committer Identity',
|
||||
},
|
||||
forgeServerAsCommitter: {
|
||||
id: 'forgeServerAsCommitter',
|
||||
name: 'Forge Server Identity',
|
||||
},
|
||||
owner: {
|
||||
id: 'owner',
|
||||
name: 'Owner',
|
||||
},
|
||||
publishDrafts: {
|
||||
id: 'publishDrafts',
|
||||
name: 'Publish Drafts',
|
||||
},
|
||||
push: {
|
||||
id: 'push',
|
||||
name: 'Push',
|
||||
},
|
||||
pushMerge: {
|
||||
id: 'pushMerge',
|
||||
name: 'Push Merge Commit',
|
||||
},
|
||||
read: {
|
||||
id: 'read',
|
||||
name: 'Read',
|
||||
},
|
||||
rebase: {
|
||||
id: 'rebase',
|
||||
name: 'Rebase',
|
||||
},
|
||||
removeReviewer: {
|
||||
id: 'removeReviewer',
|
||||
name: 'Remove Reviewer',
|
||||
},
|
||||
submit: {
|
||||
id: 'submit',
|
||||
name: 'Submit',
|
||||
},
|
||||
submitAs: {
|
||||
id: 'submitAs',
|
||||
name: 'Submit (On Behalf Of)',
|
||||
},
|
||||
toggleWipState: {
|
||||
id: 'toggleWipState',
|
||||
name: 'Toggle Work In Progress State',
|
||||
},
|
||||
viewPrivateChanges: {
|
||||
id: 'viewPrivateChanges',
|
||||
name: 'View Private Changes',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {!Object} obj
|
||||
* @return {!Array} returns a sorted array sorted by the id of the original
|
||||
* object.
|
||||
*/
|
||||
toSortedArray(obj) {
|
||||
if (!obj) { return []; }
|
||||
return Object.keys(obj)
|
||||
.map(key => {
|
||||
return {
|
||||
id: key,
|
||||
value: obj[key],
|
||||
};
|
||||
})
|
||||
.sort((a, b) =>
|
||||
// Since IDs are strings, use localeCompare.
|
||||
a.id.localeCompare(b.id)
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function defineEmptyMixin() {
|
||||
// This is a temporary function.
|
||||
// Polymer linter doesn't process correctly the following code:
|
||||
// class MyElement extends Polymer.mixinBehaviors([legacyBehaviors], ...) {...}
|
||||
// To workaround this issue, the mock mixin is declared in this method.
|
||||
// In the following changes, legacy behaviors will be converted to mixins.
|
||||
|
||||
/**
|
||||
* @polymer
|
||||
* @mixinFunction
|
||||
*/
|
||||
Gerrit.AccessMixin = base =>
|
||||
class extends base {
|
||||
static get properties() {
|
||||
/**
|
||||
* @param {!Object} obj
|
||||
* @return {!Array} returns a sorted array sorted by the id of the original
|
||||
* object.
|
||||
*/
|
||||
toSortedArray(obj) {
|
||||
if (!obj) { return []; }
|
||||
return Object.keys(obj)
|
||||
.map(key => {
|
||||
return {
|
||||
permissionValues: {
|
||||
type: Object,
|
||||
},
|
||||
id: key,
|
||||
value: obj[key],
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
})(window);
|
||||
})
|
||||
.sort((a, b) =>
|
||||
// Since IDs are strings, use localeCompare.
|
||||
a.id.localeCompare(b.id)
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
// TODO(dmfilippov) Remove the following lines with assignments
|
||||
// Plugins can use the behavior because it was accessible with
|
||||
// the global Gerrit... variable. To avoid breaking changes in plugins
|
||||
// temporary assign global variables.
|
||||
window.Gerrit = window.Gerrit || {};
|
||||
window.Gerrit.AccessBehavior = AccessBehavior;
|
||||
|
||||
@@ -31,8 +31,8 @@ limitations under the License.
|
||||
|
||||
<script type="module">
|
||||
import '../../test/common-test-setup.js';
|
||||
import './gr-access-behavior.js';
|
||||
import {Polymer} from '@polymer/polymer/lib/legacy/polymer-fn.js';
|
||||
import {AccessBehavior} from './gr-access-behavior.js';
|
||||
suite('gr-access-behavior tests', () => {
|
||||
let element;
|
||||
|
||||
@@ -40,7 +40,7 @@ suite('gr-access-behavior tests', () => {
|
||||
// Define a Polymer element that uses this behavior.
|
||||
Polymer({
|
||||
is: 'test-element',
|
||||
behaviors: [Gerrit.AccessBehavior],
|
||||
behaviors: [AccessBehavior],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import '../../../scripts/bundled-polymer.js';
|
||||
import '../../../behaviors/gr-access-behavior/gr-access-behavior.js';
|
||||
import '@polymer/iron-input/iron-input.js';
|
||||
import '../../../styles/gr-form-styles.js';
|
||||
import '../../../styles/shared-styles.js';
|
||||
@@ -30,6 +29,7 @@ import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class.js';
|
||||
import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
|
||||
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
|
||||
import {htmlTemplate} from './gr-access-section_html.js';
|
||||
import {AccessBehavior} from '../../../behaviors/gr-access-behavior/gr-access-behavior.js';
|
||||
|
||||
/**
|
||||
* Fired when the section has been modified or removed.
|
||||
@@ -52,11 +52,10 @@ const ON_BEHALF_OF = '(On Behalf Of)';
|
||||
const LABEL = 'Label';
|
||||
|
||||
/**
|
||||
* @appliesMixin Gerrit.AccessMixin
|
||||
* @extends Polymer.Element
|
||||
*/
|
||||
class GrAccessSection extends mixinBehaviors( [
|
||||
Gerrit.AccessBehavior,
|
||||
AccessBehavior,
|
||||
], GestureEventListeners(
|
||||
LegacyElementMixin(
|
||||
PolymerElement))) {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
import '../../../scripts/bundled-polymer.js';
|
||||
|
||||
import '../../../behaviors/gr-access-behavior/gr-access-behavior.js';
|
||||
import '@polymer/paper-toggle-button/paper-toggle-button.js';
|
||||
import '../../../styles/gr-form-styles.js';
|
||||
import '../../../styles/gr-menu-page-styles.js';
|
||||
@@ -31,6 +30,7 @@ import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-l
|
||||
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
|
||||
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
|
||||
import {htmlTemplate} from './gr-permission_html.js';
|
||||
import {AccessBehavior} from '../../../behaviors/gr-access-behavior/gr-access-behavior.js';
|
||||
|
||||
const MAX_AUTOCOMPLETE_RESULTS = 20;
|
||||
|
||||
@@ -47,12 +47,11 @@ const RANGE_NAMES = [
|
||||
/**
|
||||
* Fired when a permission that was previously added was removed.
|
||||
*
|
||||
* @appliesMixin Gerrit.AccessMixin
|
||||
* @event added-permission-removed
|
||||
* @extends Polymer.Element
|
||||
*/
|
||||
class GrPermission extends mixinBehaviors( [
|
||||
Gerrit.AccessBehavior,
|
||||
AccessBehavior,
|
||||
], GestureEventListeners(
|
||||
LegacyElementMixin(
|
||||
PolymerElement))) {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
import '../../../scripts/bundled-polymer.js';
|
||||
|
||||
import '../../../behaviors/gr-access-behavior/gr-access-behavior.js';
|
||||
import '../../../behaviors/gr-url-encoding-behavior/gr-url-encoding-behavior.js';
|
||||
import '../../../styles/gr-menu-page-styles.js';
|
||||
import '../../../styles/gr-subpage-styles.js';
|
||||
@@ -32,6 +31,7 @@ import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mix
|
||||
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
|
||||
import {htmlTemplate} from './gr-repo-access_html.js';
|
||||
import {BaseUrlBehavior} from '../../../behaviors/base-url-behavior/base-url-behavior.js';
|
||||
import {AccessBehavior} from '../../../behaviors/gr-access-behavior/gr-access-behavior.js';
|
||||
|
||||
const Defs = {};
|
||||
|
||||
@@ -84,12 +84,11 @@ Defs.sections;
|
||||
Defs.projectAccessInput;
|
||||
|
||||
/**
|
||||
* @appliesMixin Gerrit.AccessMixin
|
||||
* @appliesMixin Gerrit.URLEncodingMixin
|
||||
* @extends Polymer.Element
|
||||
*/
|
||||
class GrRepoAccess extends mixinBehaviors( [
|
||||
Gerrit.AccessBehavior,
|
||||
AccessBehavior,
|
||||
BaseUrlBehavior,
|
||||
Gerrit.URLEncodingBehavior,
|
||||
], GestureEventListeners(
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
import '../../../scripts/bundled-polymer.js';
|
||||
|
||||
import '@polymer/iron-autogrow-textarea/iron-autogrow-textarea.js';
|
||||
import '../../../behaviors/gr-access-behavior/gr-access-behavior.js';
|
||||
import '../../../behaviors/gr-url-encoding-behavior/gr-url-encoding-behavior.js';
|
||||
import '../../../styles/gr-form-styles.js';
|
||||
import '../../../styles/shared-styles.js';
|
||||
@@ -30,6 +29,7 @@ import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mix
|
||||
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
|
||||
import {htmlTemplate} from './gr-rule-editor_html.js';
|
||||
import {BaseUrlBehavior} from '../../../behaviors/base-url-behavior/base-url-behavior.js';
|
||||
import {AccessBehavior} from '../../../behaviors/gr-access-behavior/gr-access-behavior.js';
|
||||
|
||||
/**
|
||||
* Fired when the rule has been modified or removed.
|
||||
@@ -79,12 +79,11 @@ const FORCE_EDIT_OPTIONS = [
|
||||
];
|
||||
|
||||
/**
|
||||
* @appliesMixin Gerrit.AccessMixin
|
||||
* @appliesMixin Gerrit.URLEncodingMixin
|
||||
* @extends Polymer.Element
|
||||
*/
|
||||
class GrRuleEditor extends mixinBehaviors( [
|
||||
Gerrit.AccessBehavior,
|
||||
AccessBehavior,
|
||||
BaseUrlBehavior,
|
||||
Gerrit.URLEncodingBehavior,
|
||||
], GestureEventListeners(
|
||||
|
||||
Reference in New Issue
Block a user