LP1901930 SIP mediator continued
authorBill Erickson <berickxx@gmail.com>
Wed, 25 Nov 2020 16:57:03 +0000 (08:57 -0800)
committerBill Erickson <berickxx@gmail.com>
Wed, 25 Nov 2020 16:57:03 +0000 (08:57 -0800)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/examples/opensrf_core.xml.example
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts
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/eg2/src/app/staff/admin/server/sip/delete-group-dialog.component.html
Open-ILS/src/eg2/src/app/staff/admin/server/sip/delete-group-dialog.component.ts
Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Admin.pm
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.sip-config.sql

index db89f56..8bd4d52 100644 (file)
@@ -40,6 +40,7 @@ Example OpenSRF bootstrap configuration file for Evergreen
           <service>open-ils.vandelay</service>
           <service>open-ils.serial</service>
           <service>open-ils.ebook_api</service>
+          <service>open-ils.sip2</service>
         </services>
       </router>
 
index 4b6ee5e..54553a4 100644 (file)
@@ -184,7 +184,7 @@ export class FmRecordEditorComponent
 
     // custom function for munging the record before it gets saved;
     // will get passed mode and the record itself
-    @Input() preSave: Function;
+    @Input() preSave: (mode: string, recToSave: IdlObject) => void;
 
     // recordId and record getters and setters.
     // Note that setting the this.recordId to NULL does not clear the
index 7fcfcc9..ba6b141 100644 (file)
@@ -3,7 +3,7 @@
 <a routerLink="/staff/admin/server/sip/account">
   <button class="btn btn-outline-dark label-with-material-icon">
     <span class="material-icons">reply</span>
-    <span i18n>Setting Groups</span>
+    <span i18n>SIP Accounts</span>
   </button>
 </a>
 
       fieldOrder="sip_username,setting_group,usr,workstation,transient,activity_who,enabled"
       [fieldOptions]="{
         setting_group:{customTemplate:{template:grpTemplate}},
-        usr:{customTemplate:{template:usrTemplate}}
-      }"
+        usr:{customTemplate:{template:usrTemplate}}}"
+      [preSave]="accountPreSave"
       (recordSaved)="accountSaved()" [recordId]="accountId">
     </eg-fm-record-editor>
   </div>
   <div class="col-lg-5">
     <ul>
-      <li i18n>Save account changes before modifying settings.</li>
+      <li i18n>Save account changes before modifying individual settings.</li>
       <li i18n>Setting values must be entered as valid JSON.</li>
-      <li i18n>The "Default Settings" settings group cannot be modified</li>
+      <li i18n>The "Default Settings" group cannot be modified.</li>
+      <li i18n>The same "SIP Institution" value may be used for multiple groups.</li>
     </ul>
   </div>
 </div>
index b37e38a..856ed56 100644 (file)
@@ -29,6 +29,7 @@ export class SipAccountComponent implements OnInit {
     usrId: number;
     settingsSource: GridDataSource = new GridDataSource();
     deleteGroupAccounts: IdlObject[] = [];
+    accountPreSave: (mode: string, account: IdlObject) => void;
 
     @ViewChild('cloneDialog') cloneDialog: FmRecordEditorComponent;
     @ViewChild('settingDialog') settingDialog: FmRecordEditorComponent;
@@ -80,7 +81,15 @@ export class SipAccountComponent implements OnInit {
                 {setting_group: this.account.setting_group().id()},
                 {order_by: orderBy},
             );
-        }
+        };
+
+        this.accountPreSave = (mode: string, account: IdlObject) => {
+            if (mode === 'update') {
+                // Migrate the setting group selected in our local group
+                // combobox to the object to be saved.
+                account.setting_group(this.account.setting_group().id());
+            }
+        };
     }
 
 
@@ -149,7 +158,7 @@ export class SipAccountComponent implements OnInit {
             modified.ischanged(true);
 
             this.pcrud.autoApply(settings.concat(modified)).toPromise()
-            .then(_ => this.loadAccount());
+            .then(_ => this.refreshAccount());
         });
     }
 
@@ -157,48 +166,15 @@ export class SipAccountComponent implements OnInit {
 
         this.deleteGroupDialog.open().subscribe(
             ok => {
-                console.log('group deleted');
+                if (ok) {
+                    this.refreshAccount();
+                }
             }
         );
-
-
-        /*
-        const grp = this.account.setting_group();
-
-        // Find accounts that use this group
-        this.pcrud.search('sipacc', {setting_group: grp.id()}, {atomic: true})
-
-        // Confirm deletion
-        .pipe(switchMap(accounts => {
-            this.deleteGroupAccounts = accounts;
-            return this.confirmDelete.open();
-        })
-
-        // Modify accounts that use this group so the delete can continue
-        .pipe(switchMap(approved => {
-            if (!approved) { return of(); }
-
-            // Clone the accounts so we can avoid modifying the currently
-            // edited account, which can lead to fleshing-related JS errors
-            const clones = accounts.map(acc => {
-                const one = this.idl.clone(acc);
-                one.setting_group(1); // defaults
-                return one;
-            });
-
-            return this.pcrud.update(clones);
-        })
-        .pipe(switchMap(result => {
-            if (!result) { return of(); }
-            return this.pcrud.remove(grp);
-        })
-        .pipe(tap(result => {
-            if (result)
-        */
     }
 
     accountSaved() {
-        this.loadAccount();
+        this.refreshAccount();
     }
 
     editFirstSetting(rows: any) {
@@ -207,23 +183,23 @@ export class SipAccountComponent implements OnInit {
         }
     }
 
+    refreshAccount() {
+        this.loadAccount().subscribe(_ => {
+            setTimeout(() => {
+                if (this.settingGrid) {
+                    this.settingGrid.reload();
+                }
+            });
+        });
+    }
+
     editSetting(row: any) {
         // Default Settings group is read-only
         if (row.setting_group() === 1) { return; }
 
         this.settingDialog.record = this.idl.clone(row);
         this.settingDialog.open().subscribe(
-            ok => {
-                // Easier to simply refresh the whole account.
-                // After refresh, force a grid reload.
-                this.loadAccount().subscribe(ok2 => {
-                    setTimeout(() => {
-                        if (this.settingGrid) {
-                            this.settingGrid.reload();
-                        }
-                    });
-                });
-            },
+            ok => this.refreshAccount(),
             err => {} // todo toast
         );
     }
index d1eb51b..b8ae758 100644 (file)
@@ -30,7 +30,7 @@
   </div>
   <div class="modal-footer">
     <button type="button" class="btn btn-success" 
-      (click)="close(true)" i18n>Confirm</button>
+      (click)="doDelete(true)" i18n>Confirm</button>
     <button type="button" class="btn btn-warning" 
       (click)="close(false)" i18n>Cancel</button>
   </div>
index 1912a99..1c43fab 100644 (file)
@@ -30,7 +30,7 @@ export class DeleteGroupDialogComponent extends DialogComponent implements OnIni
 
     constructor(
         private modal: NgbModal,
-        private idl: IdlService,
+        private auth: AuthService,
         private net: NetService
     ) {
         super(modal);
@@ -38,7 +38,6 @@ export class DeleteGroupDialogComponent extends DialogComponent implements OnIni
 
     ngOnInit() {
         this.onOpen$.subscribe(_ => {
-            console.log('my group', this.group);
             this.trimmedSettingGroups = this.settingGroups.filter(
                 entry => entry.id !== this.group.id());
         });
@@ -49,5 +48,12 @@ export class DeleteGroupDialogComponent extends DialogComponent implements OnIni
             this.targetGroup = entry.id;
         }
     }
+
+    doDelete() {
+        this.net.request('open-ils.sip2',
+            'open-ils.sip2.setting_group.delete',
+            this.auth.token(), this.group.id(), this.targetGroup
+        ).subscribe(ok => this.close((Number(ok) === 1)));
+    }
 }
 
index fc51337..e1f201f 100644 (file)
@@ -40,11 +40,12 @@ __PACKAGE__->register_method(
     }
 );
 
-sub dispatch_sip2_request {
+sub delete_setting_group {
     my ($self, $client, $auth, $del_grp_id, $xfer_grp_id) = @_;
     $xfer_grp_id ||= 1; # Defaults Group
     
     my $e = new_editor(authtoken => $auth, xact => 1);
+    return $e->die_event unless $e->checkauth;
     return $e->die_event unless $e->allowed('SIP_ADMIN');
 
     return $e->die_event unless
@@ -58,7 +59,8 @@ sub dispatch_sip2_request {
     }
 
     # note: sip.setting objects are deleted via cascade
-    return $e->die_event unless $e->delete_sip_setting_group($grp);
+    return $e->die_event 
+        unless $e->delete_sip_setting_group($grp) && $e->commit;
 
     return 1;
 }
index 3835e8f..16e08cf 100644 (file)
@@ -123,6 +123,12 @@ VALUES (
         'Checkout override copy alert message',
         'sipset', 'description')
 ), (
+    1, 'checkout.override.COPY_NOT_AVAILABLE', 'true',
+    oils_i18n_gettext(
+        (SELECT id FROM sip.setting WHERE name = 'checkout.override.COPY_NOT_AVAILABLE'),
+        'Checkout override copy not available message',
+        'sipset', 'description')
+), (
     1, 'checkin.override.COPY_ALERT_MESSAGE', 'true',
     oils_i18n_gettext(
         (SELECT id FROM sip.setting WHERE name = 'checkin.override.COPY_ALERT_MESSAGE'),