Skip to content

Instantly share code, notes, and snippets.

@bangpound
Created November 2, 2017 15:56
Show Gist options
  • Save bangpound/9335677564a778a1f2d8ccc7112aef76 to your computer and use it in GitHub Desktop.
Save bangpound/9335677564a778a1f2d8ccc7112aef76 to your computer and use it in GitHub Desktop.
diff --git a/app/components/ac-edit-group-modal/permissions/component.js b/app/components/ac-edit-group-modal/permissions/component.js
index ea3e7f4b0..c25dcd786 100644
--- a/app/components/ac-edit-group-modal/permissions/component.js
+++ b/app/components/ac-edit-group-modal/permissions/component.js
@@ -24,7 +24,7 @@ export default Component.extend({
*/
permissionCheckboxToggled: function(permission) {
this.set('group.' + permission.get('slug'), !permission.get('checked'));
- permission.set('checked', !permission.get('checked'));
+ permission.set('checked', !permission.get('checked'));
let permissionGroup = this.get('permissionGroups').filter((pg) => {
return pg.get('permissions').filter((p) => {
@@ -35,10 +35,13 @@ export default Component.extend({
// Set 'checkedAll' if all of the permissions options are
// still selected after this state change.
if (permissionGroup) {
- permissionGroup.set('checkedAll',
- permissionGroup.get('permissions')
+ let checkedPermissions = permissionGroup.get('permissions')
.filterBy('checked')
- .get('length') === permissionGroup.get('permissions.length'));
+ .get('length');
+ this.set('group.' + permissionGroup.get('slug'),
+ checkedPermissions > 0);
+ permissionGroup.set('checkedAll',
+ checkedPermissions === permissionGroup.get('permissions.length'));
}
},
@@ -51,6 +54,7 @@ export default Component.extend({
// 'checkedAll' needs to be toggled as well
// when permissionGroup checkbox is toggled
let toggledCheckedAll = !permissionGroup.get('checkedAll');
+ this.set('group.' + permissionGroup.get('slug'), toggledCheckedAll);
permissionGroup.set('checkedAll', toggledCheckedAll);
permissionGroup.get('permissions').forEach((perm) => {
perm.set('checked', toggledCheckedAll);
@@ -358,4 +362,4 @@ export default Component.extend({
return permissionGroupObjs;
}),
-});
+});
\ No newline at end of file
diff --git a/tests/integration/components/ac-edit-group-modal/permissions/component-test.js b/tests/integration/components/ac-edit-group-modal/permissions/component-test.js
index 96b6cce70..e3991e782 100644
--- a/tests/integration/components/ac-edit-group-modal/permissions/component-test.js
+++ b/tests/integration/components/ac-edit-group-modal/permissions/component-test.js
@@ -60,6 +60,34 @@ moduleForComponent('ac-edit-group-modal/permissions', 'Integration | Component |
}
});
+test('deals permissions should be set correctly', function(assert) {
+ // Given I have a new group and view the permissions tab
+ this.set('group', {});
+ this.render(hbs`
+ {{ac-edit-group-modal/permissions
+ group=group
+ }}
+ `);
+
+ // When I toggle the deals dropdown
+ this.$(".icon-toggle")[7].click();
+
+ // And I toggle a deals permission under pgDeal
+ this.$("#permission-checkbox-pgDealDelete").click();
+
+ let dealPermissions = this.get('group');
+ // Then my clicked deal permission should be set
+ assert.ok(
+ dealPermissions.pgDealDelete,
+ "Then my clicked deal permission should be set."
+ );
+ // And the overall deal parent permission should be set
+ assert.ok(
+ dealPermissions.pgDeal,
+ "And the overall deal parent permission should be set."
+ );
+});
+
test('it should show the custom email headers permission if the user group has permission', function(assert) {
// Render the Permissions tab for a new group being created
@@ -97,4 +125,4 @@ test('it should not show the custom email headers permission if the user group d
// Then I should not see the "Manage Custom Email Headers" displayed
assert.equal(this.$('.components_ac-edit-group-modal_permissions__group tbody').first().children().length, 4);
-});
+});
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment