LP1901930 SIP mediator continued
authorBill Erickson <berickxx@gmail.com>
Wed, 25 Nov 2020 23:05:26 +0000 (15:05 -0800)
committerBill Erickson <berickxx@gmail.com>
Wed, 25 Nov 2020 23:05:26 +0000 (15:05 -0800)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/examples/fm_IDL.xml
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/upgrade/XXXX.schema.sip-config.sql

index b8cde7e..6488fc8 100644 (file)
@@ -13489,11 +13489,11 @@ SELECT  usr,
                        <field name="enabled" reporter:datatype="bool" reporter:label="Enabled"/>
                        <field name="setting_group" reporter:datatype="link" reporter:label="Settings Group" oils_obj:required="true"/>
                        <field name="sip_username" reporter:datatype="text" reporter:label="SIP Username" oils_obj:required="true"/>
-                       <field name="sip_password" reporter:datatype="id" reporter:label="SIP Password" oils_obj:required="true"/>
                        <field name="usr" reporter:datatype="link" reporter:label="ILS User" oils_obj:required="true"/>
                        <field name="workstation" reporter:datatype="link" reporter:label="Workstation"/>
                        <field name="transient" reporter:datatype="bool" reporter:label="Transient"/>
                        <field name="activity_who" reporter:datatype="text" reporter:label="Activity Who"/>
+                       <field name="sip_password" reporter:datatype="id" reporter:label="SIP Password" oils_persist:virtual="true"/>
                </fields>
                <links>
                        <link field="usr" reltype="has_a" key="id" map="" class="au"/>
index 3525d4f..2ee2f7c 100644 (file)
@@ -40,6 +40,7 @@
 
     <ng-template #usrTemplate>
       <eg-combobox #usrCbox [entries]="usrCboxEntries" required="true"
+        (onChange)="usrChanged($event)"
         [selectedId]="usrId" [asyncDataSource]="usrCboxSource">
       </eg-combobox>
     </ng-template>
@@ -65,6 +66,8 @@
         (click)="setPassword()">Set Password</button>
     </ng-template>
 
+    <b>TODO password setting</b>
+
     <eg-fm-record-editor #editor
       idlClass="sipacc" [mode]="createMode ? 'create' : 'update'" 
       hiddenFields="id" displayMode="inline" [inPlaceMode]="true"
index f6d969f..d83d92b 100644 (file)
@@ -6,6 +6,7 @@ import {IdlService, IdlObject} from '@eg/core/idl.service';
 import {OrgService} from '@eg/core/org.service';
 import {NetService} from '@eg/core/net.service';
 import {AuthService} from '@eg/core/auth.service';
+import {EventService} from '@eg/core/event.service';
 import {PcrudService} from '@eg/core/pcrud.service';
 import {ToastService} from '@eg/share/toast/toast.service';
 import {StringComponent} from '@eg/share/string/string.component';
@@ -45,6 +46,8 @@ export class SipAccountComponent implements OnInit {
         private router: Router,
         private idl: IdlService,
         private net: NetService,
+        private auth: AuthService,
+        private evt: EventService,
         private pcrud: PcrudService
     ) {}
 
@@ -102,11 +105,10 @@ export class SipAccountComponent implements OnInit {
         };
 
         this.accountPreSave = (mode: string, account: IdlObject) => {
-            if (this.account.setting_group()) {
-                // Migrate the setting group selected in our local group
-                // combobox to the object to be saved.
-                account.setting_group(this.account.setting_group().id());
-            }
+            // Migrate the setting group selected in our local group
+            // combobox to the object to be saved.
+            account.setting_group(this.account.setting_group().id());
+            account.usr(this.account.usr().id());
         };
     }
 
@@ -151,6 +153,17 @@ export class SipAccountComponent implements OnInit {
         });
     }
 
+    usrChanged(entry: ComboboxEntry) {
+        if (!entry) {
+            this.account.usr(null);
+            return;
+        }
+
+        this.pcrud.retrieve('au', entry.id)
+            .subscribe(usr => this.account.usr(usr));
+    }
+
+
     // Create a new setting group
     // Clone the settings for the currently selected group into the new group
     // Point our account at the new group.
@@ -190,16 +203,31 @@ export class SipAccountComponent implements OnInit {
     }
 
     accountSaved(account) {
-        // Create/modify the account via API
 
-        /*
         if (this.createMode) {
-            this.router.navigate(
-                [`/staff/admin/server/sip/account/${result.id()}`]);
+            account.isnew(true);
         } else {
-            this.refreshAccount();
+            account.ischanged(true);
         }
-        */
+
+        this.net.request('open-ils.sip2',
+            'open-ils.sip2.account.cud', this.auth.token(), account)
+        .subscribe(acc => {
+
+            const evt = this.evt.parse(acc);
+
+            if (evt) {
+                console.error(evt);
+                return;
+            }
+
+            if (this.createMode) {
+                this.router.navigate(
+                    [`/staff/admin/server/sip/account/${account.id()}`]);
+            } else {
+                this.refreshAccount();
+            }
+        });
     }
 
     editFirstSetting(rows: any) {
@@ -232,7 +260,7 @@ export class SipAccountComponent implements OnInit {
 
     setPassword() {
         this.passwordDialog.open().subscribe(value => {
-            // API will translate this into an actor.passwd entry.
+            // API will translate this into an actor.passwd
             this.account.sip_password(value);
         });
     }
index e1f201f..b5cb3eb 100644 (file)
@@ -65,4 +65,61 @@ sub delete_setting_group {
     return 1;
 }
 
+__PACKAGE__->register_method(
+    method    => 'account_cud',
+    api_name  => 'open-ils.sip2.account.cud',
+    api_level => 1,
+    argc      => 2,
+    signature => {
+        desc     => q/Create, Update, Delete SIP accounts.  If a value is
+            stored in the virtual sip_password field on the account, the
+            value will be used as the new password for the account/,
+        params   => [{   
+            name => 'auth',
+            desc => 'Authtoken',
+            type => 'string'
+        }, {
+            name => 'account',
+            desc => 'SIP account object',
+            type => 'object'
+        }],
+        return => {
+            desc => q/Account object on success, Event on error/,
+            type => 'object'
+        }
+    }
+);
+
+sub account_cud {
+    my ($self, $client, $auth, $account) = @_;
+
+    my $e = new_editor(authtoken => $auth, xact => 1);
+    return $e->die_event unless $e->checkauth;
+    return $e->die_event unless $e->allowed('SIP_ADMIN');
+
+    if ($account->sip_password) {
+        my $pw = $e->json_query({from => ['actor.change_password', 
+            $account->usr, $account->sip_password, 'sip2']});
+
+        return $e->die_event unless $pw;
+    }
+
+    if ($account->isnew) {
+        return undef unless $e->create_sip_account($account);
+        
+    } elsif ($account->ischanged) {
+        return undef unless $e->update_sip_account($account);
+
+    } elsif ($account->isdeleted) {
+        return undef unless $e->delete_sip_account($account);
+    }
+
+    $account = $e->retrieve_sip_account($account->id);
+
+    return $e->die_event unless $e->commit;
+
+    return $account;
+}
+
+
 1;
index 2427435..42cda6f 100644 (file)
@@ -31,8 +31,6 @@ CREATE TABLE sip.account (
     setting_group   INTEGER NOT NULL REFERENCES sip.setting_group (id)
                     DEFERRABLE INITIALLY DEFERRED,
     sip_username    TEXT NOT NULL,
-    sip_password    BIGINT NOT NULL REFERENCES actor.passwd 
-                    DEFERRABLE INITIALLY DEFERRED,
     usr             BIGINT NOT NULL REFERENCES actor.usr(id)
                     DEFERRABLE INITIALLY DEFERRED,
     workstation     INTEGER REFERENCES actor.workstation(id),