From 7dece84ba8fadbd5d7ba548380e7dbab99127b6c Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 25 Nov 2020 15:05:26 -0800 Subject: [PATCH] LP1901930 SIP mediator continued Signed-off-by: Bill Erickson --- Open-ILS/examples/fm_IDL.xml | 2 +- .../staff/admin/server/sip/account.component.html | 3 ++ .../staff/admin/server/sip/account.component.ts | 52 +++++++++++++++----- .../perlmods/lib/OpenILS/Application/SIP2/Admin.pm | 57 ++++++++++++++++++++++ .../src/sql/Pg/upgrade/XXXX.schema.sip-config.sql | 2 - 5 files changed, 101 insertions(+), 15 deletions(-) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index b8cde7e3a6..6488fc8ae7 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -13489,11 +13489,11 @@ SELECT usr, - + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/sip/account.component.html b/Open-ILS/src/eg2/src/app/staff/admin/server/sip/account.component.html index 3525d4f20f..2ee2f7c8e0 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/sip/account.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/sip/account.component.html @@ -40,6 +40,7 @@ @@ -65,6 +66,8 @@ (click)="setPassword()">Set Password + TODO password setting + { - 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); }); } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Admin.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Admin.pm index e1f201f83d..b5cb3eb8ef 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Admin.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Admin.pm @@ -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; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.sip-config.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.sip-config.sql index 2427435962..42cda6f6ec 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.sip-config.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.sip-config.sql @@ -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), -- 2.11.0