Merge pull request #5317 from tsiegleauq/set_presence_on_userlist

Allow set present on user list if config was set
This commit is contained in:
Emanuel Schütze 2020-04-20 17:13:48 +02:00 committed by GitHub
commit 35ce596706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -98,7 +98,7 @@
class="checkbox-ripple-padding" class="checkbox-ripple-padding"
(change)="setPresent(user)" (change)="setPresent(user)"
[checked]="user.is_present" [checked]="user.is_present"
[disabled]="isMultiSelect || !this.operator.hasPerms('users.can_manage')" [disabled]="isPresentToggleDisabled(user)"
> >
<span>{{ 'Present' | translate }}</span> <span>{{ 'Present' | translate }}</span>
</mat-checkbox> </mat-checkbox>

View File

@ -134,6 +134,10 @@ export class UserListComponent extends BaseListViewComponent<ViewUser> implement
*/ */
public filterProps = ['full_name', 'groups', 'structure_level', 'number']; public filterProps = ['full_name', 'groups', 'structure_level', 'number'];
private selfPresentConfStr = 'users_allow_self_set_present';
private allowSelfSetPresent: boolean;
/** /**
* The usual constructor for components * The usual constructor for components
* @param titleService Serivce for setting the title * @param titleService Serivce for setting the title
@ -176,6 +180,7 @@ export class UserListComponent extends BaseListViewComponent<ViewUser> implement
// enable multiSelect for this listView // enable multiSelect for this listView
this.canMultiSelect = true; this.canMultiSelect = true;
config.get<boolean>('users_enable_presence_view').subscribe(state => (this._presenceViewConfigured = state)); config.get<boolean>('users_enable_presence_view').subscribe(state => (this._presenceViewConfigured = state));
config.get<boolean>(this.selfPresentConfStr).subscribe(allowed => (this.allowSelfSetPresent = allowed));
} }
/** /**
@ -201,6 +206,16 @@ export class UserListComponent extends BaseListViewComponent<ViewUser> implement
this.router.navigate(['./new'], { relativeTo: this.route }); this.router.navigate(['./new'], { relativeTo: this.route });
} }
public isPresentToggleDisabled(user: ViewUser): boolean {
if (this.isMultiSelect) {
return true;
} else if (this.allowSelfSetPresent && this.operator.viewUser === user) {
return false;
} else {
return !this.operator.hasPerms('users.can_manage');
}
}
/** /**
* This function opens the dialog, * This function opens the dialog,
* where the user can quick change the groups, * where the user can quick change the groups,
@ -412,6 +427,11 @@ export class UserListComponent extends BaseListViewComponent<ViewUser> implement
*/ */
public setPresent(viewUser: ViewUser): void { public setPresent(viewUser: ViewUser): void {
viewUser.user.is_present = !viewUser.user.is_present; viewUser.user.is_present = !viewUser.user.is_present;
if (this.operator.viewUser === viewUser) {
this.operator.setPresence(viewUser.user.is_present).catch(this.raiseError);
} else {
this.repo.update(viewUser.user, viewUser).catch(this.raiseError); this.repo.update(viewUser.user, viewUser).catch(this.raiseError);
} }
}
} }