Skip to content

Commit

Permalink
Merge pull request #7306 from stopfstedt/rm-user-from-learnergroup
Browse files Browse the repository at this point in the history
realigns capabilities checks for single user group removal/assignment…
  • Loading branch information
dartajax authored Jul 18, 2023
2 parents cebc918 + 97b29b7 commit 1b56002
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 287 deletions.
52 changes: 25 additions & 27 deletions app/components/learner-group/cohort-user-manager.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
<Input
@type="checkbox"
@checked={{and
(includes this.selectableUsers this.selectedUsers)
(includes @users this.selectedUsers)
this.selectedUsers.length
}}
indeterminate={{and
(not (includes this.selectableUsers this.selectedUsers))
(not (includes @users this.selectedUsers))
this.selectedUsers.length
}}
aria-label={{t "general.selectAllOrNone"}}
Expand Down Expand Up @@ -57,7 +57,7 @@
{{#each (sort-by @sortBy this.filteredUsers) as |user index|}}
<tr class={{unless user.enabled "disabled-user-account"}}>
<td class="text-left" colspan="1">
{{#if (and @canUpdate (or user.enabled this.currentUser.isRoot))}}
{{#if @canUpdate}}
<input
type="checkbox"
checked={{includes user this.selectedUsers}}
Expand All @@ -75,7 +75,7 @@
{{/unless}}
</td>
<td class="text-left" colspan="4">
{{#if (and @canUpdate (or user.enabled this.currentUser.isRoot))}}
{{#if @canUpdate}}
<button
class="inline-button"
type="button"
Expand All @@ -88,7 +88,7 @@
{{/if}}
</td>
<td class="text-left" colspan="2">
{{#if (and @canUpdate (or user.enabled this.currentUser.isRoot))}}
{{#if @canUpdate}}
<button
class="inline-button"
type="button"
Expand All @@ -101,7 +101,7 @@
{{/if}}
</td>
<td class="text-left hide-from-small-screen" colspan="5">
{{#if (and @canUpdate (or user.enabled this.currentUser.isRoot))}}
{{#if @canUpdate}}
<button
class="inline-button"
type="button"
Expand All @@ -114,27 +114,25 @@
{{/if}}
</td>
<td class="text-left" colspan="1">
{{#if user.enabled}}
{{#if (includes user this.usersBeingMoved)}}
<LoadingSpinner />
{{else if (and @canUpdate (eq this.selectedUsers.length 0))}}
<button
type="button"
class="inline-button"
{{on "click" (perform this.addSingleUser user)}}
data-test-add-user
>
<FaIcon
@icon="plus"
class="yes"
@title={{t
"general.moveToGroup"
groupTitle=@learnerGroupTitle
count=1
}}
/>
</button>
{{/if}}
{{#if (includes user this.usersBeingMoved)}}
<LoadingSpinner />
{{else if (and @canUpdate (eq this.selectedUsers.length 0))}}
<button
type="button"
class="inline-button"
{{on "click" (perform this.addSingleUser user)}}
data-test-add-user
>
<FaIcon
@icon="plus"
class="yes"
@title={{t
"general.moveToGroup"
groupTitle=@learnerGroupTitle
count=1
}}
/>
</button>
{{/if}}
</td>
</tr>
Expand Down
9 changes: 0 additions & 9 deletions app/components/learner-group/cohort-user-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ export default class LearnerGroupCohortUserManagerComponent extends Component {
return this.args.sortBy.search(/desc/) === -1;
}
get selectableUsers() {
if (this.currentUser.isRoot) {
return this.args.users;
}
return this.args.users.filter((user) => {
return user.enabled;
});
}
get filteredUsers() {
const filter = this.filter.trim().toLowerCase();
Expand Down
162 changes: 66 additions & 96 deletions app/components/learner-group/user-manager.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,12 @@
{{#each (sort-by @sortBy this.groupUsers) as |user index|}}
<tr class={{unless user.enabled "disabled-user-account" ""}}>
<td class="text-left" colspan="1">
{{#if (or user.enabled this.currentUser.isRoot)}}
<input
aria-labelledby="selected-username-{{index}}-{{templateId}}"
type="checkbox"
checked={{includes user.content this.selectedGroupUsers}}
{{on "click" (fn this.toggleGroupUserSelection user.content)}}
>
{{/if}}
<input
aria-labelledby="selected-username-{{index}}-{{templateId}}"
type="checkbox"
checked={{includes user.content this.selectedGroupUsers}}
{{on "click" (fn this.toggleGroupUserSelection user.content)}}
>
{{#unless user.enabled}}
<FaIcon
@icon="user-xmark"
Expand All @@ -77,43 +75,31 @@
{{/unless}}
</td>
<td class="text-left" colspan="4">
{{#if (or user.enabled this.currentUser.isRoot)}}
<button
class="inline-button"
type="button"
{{on "click" (fn this.toggleGroupUserSelection user.content)}}
>
<UserNameInfo id="selected-username-{{index}}-{{templateId}}" @user={{user}} />
</button>
{{else}}
<button
class="inline-button"
type="button"
{{on "click" (fn this.toggleGroupUserSelection user.content)}}
>
<UserNameInfo id="selected-username-{{index}}-{{templateId}}" @user={{user}} />
{{/if}}
</button>
</td>
<td class="text-left" colspan="2">
{{#if (or user.enabled this.currentUser.isRoot)}}
<button
class="inline-button"
type="button"
{{on "click" (fn this.toggleGroupUserSelection user.content)}}
>
{{user.campusId}}
</button>
{{else}}
<button
class="inline-button"
type="button"
{{on "click" (fn this.toggleGroupUserSelection user.content)}}
>
{{user.campusId}}
{{/if}}
</button>
</td>
<td class="text-left hide-from-small-screen" colspan="5">
{{#if (or user.enabled this.currentUser.isRoot)}}
<button
class="inline-button"
type="button"
{{on "click" (fn this.toggleGroupUserSelection user.content)}}
>
{{user.email}}
</button>
{{else}}
<button
class="inline-button"
type="button"
{{on "click" (fn this.toggleGroupUserSelection user.content)}}
>
{{user.email}}
{{/if}}
</button>
</td>
<td class="text-left" colspan="2">
<LinkTo
Expand All @@ -127,7 +113,7 @@
<td>
{{#if (includes user.content this.usersBeingRemovedFromGroup)}}
<LoadingSpinner />
{{else if user.enabled}}
{{else}}
{{#if (eq this.selectedGroupUsers.length 0)}}
<button
type="button"
Expand Down Expand Up @@ -200,14 +186,12 @@
{{#each (sort-by @sortBy this.nonGroupUsers) as |user index|}}
<tr class={{unless user.enabled "disabled-user-account" ""}}>
<td class="text-left" colspan="1">
{{#if (or user.enabled this.currentUser.isRoot)}}
<input
aria-labelledby="cohort-username-{{index}}-{{templateId}}"
type="checkbox"
checked={{includes user.content this.selectedNonGroupUsers}}
{{on "click" (fn this.toggleNonGroupUserSelection user.content)}}
>
{{/if}}
<input
aria-labelledby="cohort-username-{{index}}-{{templateId}}"
type="checkbox"
checked={{includes user.content this.selectedNonGroupUsers}}
{{on "click" (fn this.toggleNonGroupUserSelection user.content)}}
>
{{#unless user.enabled}}
<FaIcon
@icon="user-xmark"
Expand All @@ -218,43 +202,31 @@
{{/unless}}
</td>
<td class="text-left" colspan="4">
{{#if (or user.enabled this.currentUser.isRoot)}}
<button
class="inline-button"
type="button"
{{on "click" (fn this.toggleNonGroupUserSelection user.content)}}
>
<UserNameInfo id="cohort-username-{{index}}-{{templateId}}" @user={{user}} />
</button>
{{else}}
<button
class="inline-button"
type="button"
{{on "click" (fn this.toggleNonGroupUserSelection user.content)}}
>
<UserNameInfo id="cohort-username-{{index}}-{{templateId}}" @user={{user}} />
{{/if}}
</button>
</td>
<td class="text-left" colspan="2">
{{#if (or user.enabled this.currentUser.isRoot)}}
<button
class="inline-button"
type="button"
{{on "click" (fn this.toggleNonGroupUserSelection user.content)}}
>
{{user.campusId}}
</button>
{{else}}
<button
class="inline-button"
type="button"
{{on "click" (fn this.toggleNonGroupUserSelection user.content)}}
>
{{user.campusId}}
{{/if}}
</button>
</td>
<td class="text-left hide-from-small-screen" colspan="5">
{{#if (or user.enabled this.currentUser.isRoot)}}
<button
class="inline-button"
type="button"
{{on "click" (fn this.toggleNonGroupUserSelection user.content)}}
>
{{user.email}}
</button>
{{else}}
<button
class="inline-button"
type="button"
{{on "click" (fn this.toggleNonGroupUserSelection user.content)}}
>
{{user.email}}
{{/if}}
</button>
</td>
<td class="text-left" colspan="2">
<LinkTo
Expand All @@ -268,25 +240,23 @@
<td>
{{#if (includes user.content this.usersBeingAddedToGroup)}}
<LoadingSpinner />
{{else if user.enabled}}
{{#if (eq this.selectedNonGroupUsers.length 0)}}
<button
type="button"
class="link-button"
{{on "click" (perform this.addUserToGroup user.content)}}
data-test-add-user
>
<FaIcon
@icon="plus"
class="yes"
@title={{t
"general.moveToGroup"
groupTitle=@learnerGroupTitle
count=1
}}
/>
</button>
{{/if}}
{{else if (eq this.selectedNonGroupUsers.length 0)}}
<button
type="button"
class="link-button"
{{on "click" (perform this.addUserToGroup user.content)}}
data-test-add-user
>
<FaIcon
@icon="plus"
class="yes"
@title={{t
"general.moveToGroup"
groupTitle=@learnerGroupTitle
count=1
}}
/>
</button>
{{/if}}
</td>
</tr>
Expand Down
13 changes: 1 addition & 12 deletions app/components/learner-group/user-manager.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { enqueueTask, timeout } from 'ember-concurrency';
import { mapBy } from 'ilios-common/utils/array-helpers';

export default class LearnerGroupUserManagerComponent extends Component {
@service currentUser;

@tracked filter = '';
@tracked selectedGroupUsers = [];
@tracked selectedNonGroupUsers = [];
Expand All @@ -19,15 +16,7 @@ export default class LearnerGroupUserManagerComponent extends Component {
}
get selectableUsers() {
if (this.currentUser.isRoot) {
return mapBy(this.args.users, 'content');
}
return mapBy(
this.args.users.filter((user) => {
return user.get('enabled');
}),
'content'
);
return mapBy(this.args.users, 'content');
}
get filteredUsers() {
Expand Down
Loading

0 comments on commit 1b56002

Please sign in to comment.