Update conditions of disabling gr-access-section

Updates the conditions of gr-access-section to be disabled if can_upload
is false AND also not an owner of the section. This is needed for the
direct save option.

Bug: Issue 8298
Change-Id: I0c13159aaf2c52649bc9ed7c568c8b315911b1db
This commit is contained in:
Becky Siegel
2018-04-26 11:57:41 -07:00
parent e42689ced5
commit 00bb5b1ea5
4 changed files with 41 additions and 13 deletions

View File

@@ -87,7 +87,7 @@ limitations under the License.
</style>
<style include="gr-form-styles"></style>
<fieldset id="section"
class$="gr-form-styles [[_computeSectionClass(editing, _editingRef, _deleted)]]">
class$="gr-form-styles [[_computeSectionClass(editing, canUpload, ownerOf, _editingRef, _deleted)]]">
<div id="mainContainer">
<div class="header">
<div class="name">

View File

@@ -54,6 +54,8 @@
value: false,
observer: '_handleEditingChanged',
},
canUpload: Boolean,
ownerOf: Array,
_originalId: String,
_editingRef: {
type: Boolean,
@@ -214,9 +216,13 @@
this.$.editRefInput.focus();
},
_computeSectionClass(editing, editingRef, deleted) {
_isEditEnabled(canUpload, ownerOf, sectionId) {
return canUpload || ownerOf.indexOf(sectionId) >= 0;
},
_computeSectionClass(editing, canUpload, ownerOf, editingRef, deleted) {
const classList = [];
if (editing) {
if (editing && this._isEditEnabled(canUpload, ownerOf, this.section.id)) {
classList.push('editing');
}
if (editingRef) {

View File

@@ -272,26 +272,37 @@ limitations under the License.
test('_computeSectionClass', () => {
let editingRef = false;
let canUpload = false;
let ownerOf = [];
let editing = false;
let deleted = false;
assert.equal(element._computeSectionClass(editing, editingRef, deleted),
'');
assert.equal(element._computeSectionClass(editing, canUpload, ownerOf,
editingRef, deleted), '');
editing = true;
assert.equal(element._computeSectionClass(editing, editingRef, deleted),
'editing');
assert.equal(element._computeSectionClass(editing, canUpload, ownerOf,
editingRef, deleted), '');
ownerOf = ['refs/*'];
assert.equal(element._computeSectionClass(editing, canUpload, ownerOf,
editingRef, deleted), 'editing');
ownerOf = [];
canUpload = true;
assert.equal(element._computeSectionClass(editing, canUpload, ownerOf,
editingRef, deleted), 'editing');
editingRef = true;
assert.equal(element._computeSectionClass(editing, editingRef, deleted),
'editing editingRef');
assert.equal(element._computeSectionClass(editing, canUpload, ownerOf,
editingRef, deleted), 'editing editingRef');
deleted = true;
assert.equal(element._computeSectionClass(editing, editingRef, deleted),
'editing editingRef deleted');
assert.equal(element._computeSectionClass(editing, canUpload, ownerOf,
editingRef, deleted), 'editing editingRef deleted');
editingRef = false;
assert.equal(element._computeSectionClass(editing, editingRef, deleted),
'editing deleted');
assert.equal(element._computeSectionClass(editing, canUpload, ownerOf,
editingRef, deleted), 'editing deleted');
});
test('_computeEditBtnClass', () => {
@@ -356,6 +367,8 @@ limitations under the License.
assert.isFalse(element.$.section.classList.contains('deleted'));
assert.isTrue(element.$.editBtn.classList.contains('global'));
element.editing = true;
element.canUpload = true;
element.ownerOf = [];
assert.equal(getComputedStyle(element.$.editBtn).display, 'none');
});
});
@@ -382,6 +395,9 @@ limitations under the License.
assert.isFalse(element.$.section.classList.contains('deleted'));
assert.isFalse(element.$.editBtn.classList.contains('global'));
element.editing = true;
element.canUpload = true;
element.ownerOf = [];
flushAsynchronousOperations();
assert.notEqual(getComputedStyle(element.$.editBtn).display, 'none');
});
@@ -440,6 +456,8 @@ limitations under the License.
});
test('edit section reference', () => {
element.canUpload = true;
element.ownerOf = [];
element.section = {id: 'refs/for/bar', value: {permissions: {}}};
assert.isFalse(element.$.section.classList.contains('editing'));
element.editing = true;
@@ -486,6 +504,8 @@ limitations under the License.
test('remove section', () => {
element.editing = true;
element.canUpload = true;
element.ownerOf = [];
assert.isFalse(element._deleted);
assert.isNotOk(element.section.value.deleted);
MockInteractions.tap(element.$.deleteBtn);

View File

@@ -110,7 +110,9 @@ limitations under the License.
capabilities="[[_capabilities]]"
section="{{section}}"
labels="[[_labels]]"
can-upload="[[_canUpload]]"
editing="[[_editing]]"
owner-of="[[_ownerOf]]"
groups="[[_groups]]"
on-added-section-removed="_handleAddedSectionRemoved"></gr-access-section>
</template>