From: Bill Erickson Date: Thu, 1 Apr 2021 20:10:23 +0000 (-0400) Subject: LP1904036 Staged users X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=8319d4d5ff98adfcd3ead984fa317b1f55349e53;p=evergreen%2Fpines.git LP1904036 Staged users Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.html b/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.html index 39ec61ae1c..b37b5460c5 100644 --- a/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.html +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.html @@ -10,6 +10,8 @@ i18n-text text="Group Link Succeeded"> + diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.ts b/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.ts index 31635ab0c3..722ed34b82 100644 --- a/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.ts @@ -155,6 +155,8 @@ export class EditComponent implements OnInit, AfterViewInit { dupeBarcode = false; dupeUsername = false; origUsername: string; + stageUser: IdlObject; + stageUserRequestor: IdlObject; fieldPatterns: {[cls: string]: {[field: string]: RegExp}} = { au: {}, @@ -217,6 +219,7 @@ export class EditComponent implements OnInit, AfterViewInit { .then(_ => this.setSurveys()) .then(_ => this.loadPatron()) .then(_ => this.getCloneUser()) + .then(_ => this.getStageUser()) .then(_ => this.getSecondaryGroups()) .then(_ => this.applyPerms()) .then(_ => this.setEditProfiles()) @@ -279,6 +282,119 @@ export class EditComponent implements OnInit, AfterViewInit { }); } + getStageUser(): Promise { + if (!this.stageUsername) { return Promise.resolve(); } + + return this.net.request( + 'open-ils.actor', + 'open-ils.actor.user.stage.retrieve.by_username', + this.auth.token(), this.stageUsername).toPromise() + + .then(suser => { + const evt = this.evt.parse(suser); + if (evt) { + alert(evt); + return Promise.reject(evt); + } else { + this.stageUser = suser; + } + }) + .then(_ => { + + const requestor = this.stageUser.user.requesting_usr(); + if (!requestor) return; + + return this.pcrud.retrieve('au', requestor).toPromise(); + + }) + .then(reqr => this.stageUserRequestor = reqr) + .then(_ => this.copyStageData()); + } + + copyStageData() { + const cuser = this.stageUser; + const user = this.patron; + + for (let key in this.idl.classes.stgu.field_map) { + const field = this.idl.classes.au.field_map[key]; + if (field && !field.virtual) { + const value = cuser.user[key](); + if (value !== null) { + user[key] = value; + } + } + }; + + // Clear the usrname if it looks like a UUID + if (user.usrname().replace(/-/g,'').match(/[0-9a-f]{32}/)) { + user.usrname(''); + } + + // Don't use stub address if we have one from the staged user. + if (cuser.mailing_addresses().length || cuser.billing_addresses().length) { + user.addresses([]); + } + + const addrFromStage = (stageAddr: IdlObject) => { + if (!stageAddr) { return; } + + const cls = stageAddr.classname; + const addr = this.idl.create('aua'); + + addr.isnew(true); + addr.id(this.autoId--); + addr.valid('t'); + + return this.strings.interpolate('circ.patron.edit.default_addr_type') + .then(msg => addr.address_type(msg)); + + if (cls === 'stgma') { + user.mailing_address(addr); + } else { + user.billing_address(addr); + } + + user.addresses.push(addr); + + for (let key in this.idl.classes[cls].field_map) { + const field = this.idl.classes.aua.field_map[key]; + if (field && !field.virtual) { + const value = stageAddr[key](); + if (value !== null) { + addr[key](value); + } + } + } + } + + addrFromStage(cuser.mailing_addresses[0]); + addrFromStage(cuser.billing_addresses[0]); + + if (user.addresses().length == 1) { + // Only one address, use it for both purposes. + const addr = user.addresses[0]; + user.mailing_address(addr); + user.billing_address(addr); + } + + if (cuser.cards[0]) { + const card = this.idl.create('ac'); + card.isnew(true); + card.id(this.autoId--); + card.barcode(cuser.cards[0].barcode()); + user.card(card); + user.cards([card]); + + if (!user.usrname()) { + user.usrname(card.barcode()); + } + } + + cuser.settings.forEach(setting => { + this.userSettings[setting.setting()] = Boolean(setting.value()); + }); + } + copyCloneData(clone: IdlObject) { const patron = this.patron;