LP1901930 SIP Account admin improve reporting
authorBill Erickson <berickxx@gmail.com>
Wed, 17 Feb 2021 19:13:11 +0000 (14:13 -0500)
committerJason Etheridge <jason@EquinoxOLI.org>
Mon, 24 Oct 2022 17:05:29 +0000 (13:05 -0400)
* Show toasts to indicate when an account save action failed or
  succeeded.
* Adds a UNIQUE constraint to sip.account.sip_username.
* Indicates in the account edit form when a duplicate sip username was
  entered.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/admin/server/sip/account.component.html
Open-ILS/src/eg2/src/app/staff/admin/server/sip/account.component.ts
Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Admin.pm
Open-ILS/src/sql/Pg/410.schema.sip.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.sip-config.sql

index a05c0b7..a63b3ea 100644 (file)
@@ -1,5 +1,11 @@
 <eg-staff-banner bannerText="SIP Account" i18n-bannerText></eg-staff-banner>
 
+<eg-string key="staff.admin.sip.account.saved" i18n-text
+  text="SIP Account Successfully Saved"></eg-string>
+<eg-string key="staff.admin.sip.account.failed" i18n-text
+  text="SIP Account Failed to Save"></eg-string>
+
+
 <a routerLink="/staff/admin/server/sip/account">
   <button class="btn btn-outline-dark label-with-material-icon">
     <span class="material-icons">reply</span>
     <ng-template #sipUsernameTemplate>
       <div class="form-inline">
         <input type="text" class="form-control"
-          [ngModel]="account.sip_username()"
-          (ngModelChange)="account.sip_username($event)">
+          [ngModel]="account.sip_username()" (change)="sipUsernameChange($event)">
         <button class="btn btn-outline-dark ml-2" 
           [ngClass]="{'border-danger' : createMode && !account.sip_password()}"
           (click)="setPassword()">Set Password</button>
+        <span *ngIf="dupeSipUser" class="alert alert-danger ml-1 mt-2 p-1" i18n>
+          Username In Use
+        </span>
       </div>
     </ng-template>
 
index 5b279d3..5f72cd4 100644 (file)
@@ -34,6 +34,7 @@ export class SipAccountComponent implements OnInit {
     deleteGroupAccounts: IdlObject[] = [];
     accountPreSave: (mode: string, account: IdlObject) => void;
     createMode = false;
+    dupeSipUser = false;
 
     @ViewChild('cloneDialog') cloneDialog: FmRecordEditorComponent;
     @ViewChild('settingDialog') settingDialog: FmRecordEditorComponent;
@@ -48,7 +49,9 @@ export class SipAccountComponent implements OnInit {
         private net: NetService,
         private auth: AuthService,
         private evt: EventService,
-        private pcrud: PcrudService
+        private pcrud: PcrudService,
+        private toast: ToastService,
+        private strings: StringService
     ) {}
 
     ngOnInit() {
@@ -220,9 +223,14 @@ export class SipAccountComponent implements OnInit {
 
             if (evt) {
                 console.error(evt);
+                this.strings.strings['staff.admin.sip.account.failed']
+                .resolver({}).then(text => this.toast.danger(text));
                 return;
             }
 
+            this.strings.strings['staff.admin.sip.account.saved']
+            .resolver({}).then(text => this.toast.success(text));
+
             if (this.createMode) {
                 this.router.navigate(
                     [`/staff/admin/server/sip/account/${acc.id()}`]);
@@ -232,6 +240,20 @@ export class SipAccountComponent implements OnInit {
         });
     }
 
+    sipUsernameChange(evt: Event) {
+        this.dupeSipUser = false;
+        const name = (evt.target as HTMLInputElement).value;
+        if (!name) { return; }
+
+        this.account.sip_username(name);
+        const search: any = {sip_username: name};
+        if (!this.createMode) {
+            search.id = {'!=': this.accountId};
+        }
+        this.pcrud.search('sipacc', search)
+        .subscribe(existing => this.dupeSipUser = true);
+    }
+
     editFirstSetting(rows: any) {
         if (rows.length > 0) {
             this.editSetting(rows[0]);
index b5cb3eb..57bdbbb 100644 (file)
@@ -105,13 +105,13 @@ sub account_cud {
     }
 
     if ($account->isnew) {
-        return undef unless $e->create_sip_account($account);
+        return $e->die_event unless $e->create_sip_account($account);
         
     } elsif ($account->ischanged) {
-        return undef unless $e->update_sip_account($account);
+        return $e->die_event unless $e->update_sip_account($account);
 
     } elsif ($account->isdeleted) {
-        return undef unless $e->delete_sip_account($account);
+        return $e->die_event unless $e->delete_sip_account($account);
     }
 
     $account = $e->retrieve_sip_account($account->id);
index cdc1de5..c07bdcf 100644 (file)
@@ -27,7 +27,7 @@ CREATE TABLE sip.account (
     enabled         BOOLEAN NOT NULL DEFAULT TRUE,
     setting_group   INTEGER NOT NULL REFERENCES sip.setting_group (id)
                     DEFERRABLE INITIALLY DEFERRED,
-    sip_username    TEXT NOT NULL,
+    sip_username    TEXT UNIQUE NOT NULL,
     usr             BIGINT NOT NULL REFERENCES actor.usr(id)
                     DEFERRABLE INITIALLY DEFERRED,
     workstation     INTEGER REFERENCES actor.workstation(id),
index d06fea5..35b6f5b 100644 (file)
@@ -30,7 +30,7 @@ CREATE TABLE sip.account (
     enabled         BOOLEAN NOT NULL DEFAULT TRUE,
     setting_group   INTEGER NOT NULL REFERENCES sip.setting_group (id)
                     DEFERRABLE INITIALLY DEFERRED,
-    sip_username    TEXT NOT NULL,
+    sip_username    TEXT UNIQUE NOT NULL,
     usr             BIGINT NOT NULL REFERENCES actor.usr(id)
                     DEFERRABLE INITIALLY DEFERRED,
     workstation     INTEGER REFERENCES actor.workstation(id),