From 9ffbb39e95ddaa287011ddc20028e259ad82e1a8 Mon Sep 17 00:00:00 2001 From: Sean Date: Mon, 20 Apr 2020 13:46:14 +0200 Subject: [PATCH] Allow set present on user list if config was set Depending on "selt self presence" config, allow users to set themselves as present on the user list --- .../user-list/user-list.component.html | 2 +- .../user-list/user-list.component.ts | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/client/src/app/site/users/components/user-list/user-list.component.html b/client/src/app/site/users/components/user-list/user-list.component.html index f5d55245b..934e08d75 100644 --- a/client/src/app/site/users/components/user-list/user-list.component.html +++ b/client/src/app/site/users/components/user-list/user-list.component.html @@ -98,7 +98,7 @@ class="checkbox-ripple-padding" (change)="setPresent(user)" [checked]="user.is_present" - [disabled]="isMultiSelect || !this.operator.hasPerms('users.can_manage')" + [disabled]="isPresentToggleDisabled(user)" > {{ 'Present' | translate }} diff --git a/client/src/app/site/users/components/user-list/user-list.component.ts b/client/src/app/site/users/components/user-list/user-list.component.ts index e9e0d1a52..2fd90a8c3 100644 --- a/client/src/app/site/users/components/user-list/user-list.component.ts +++ b/client/src/app/site/users/components/user-list/user-list.component.ts @@ -134,6 +134,10 @@ export class UserListComponent extends BaseListViewComponent implement */ public filterProps = ['full_name', 'groups', 'structure_level', 'number']; + private selfPresentConfStr = 'users_allow_self_set_present'; + + private allowSelfSetPresent: boolean; + /** * The usual constructor for components * @param titleService Serivce for setting the title @@ -176,6 +180,7 @@ export class UserListComponent extends BaseListViewComponent implement // enable multiSelect for this listView this.canMultiSelect = true; config.get('users_enable_presence_view').subscribe(state => (this._presenceViewConfigured = state)); + config.get(this.selfPresentConfStr).subscribe(allowed => (this.allowSelfSetPresent = allowed)); } /** @@ -201,6 +206,16 @@ export class UserListComponent extends BaseListViewComponent implement 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, * where the user can quick change the groups, @@ -412,6 +427,11 @@ export class UserListComponent extends BaseListViewComponent implement */ public setPresent(viewUser: ViewUser): void { viewUser.user.is_present = !viewUser.user.is_present; - this.repo.update(viewUser.user, viewUser).catch(this.raiseError); + + 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); + } } }