@sprucelabs/spruce-profile-utils 15.6.16 → 15.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { Locale } from '@sprucelabs/calendar-utils';
2
- import { AbstractViewController, Authenticator, Card, CardHeader, CardViewController, FormViewController, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
+ import { AbstractViewController, Authenticator, Authorizer, Card, CardHeader, CardViewController, FormViewController, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
3
3
  import { Person, PersonSchema } from '../profile.types';
4
4
  export default class ProfileCardViewController extends AbstractViewController<Card> {
5
5
  static id: string;
@@ -20,6 +20,7 @@ export default class ProfileCardViewController extends AbstractViewController<Ca
20
20
  export interface ProfileCardLoadOptions {
21
21
  person: Person;
22
22
  authenticator: Authenticator;
23
+ authorizer: Authorizer;
23
24
  locale?: Locale;
24
25
  locationId?: string;
25
26
  organizationId?: string;
@@ -96,8 +96,8 @@ class ProfileCardViewController extends AbstractViewController {
96
96
  }
97
97
  load(options) {
98
98
  return __awaiter(this, void 0, void 0, function* () {
99
- var _a;
100
- const { person, authenticator, locale, locationId, organizationId } = assertOptions(options !== null && options !== void 0 ? options : {}, ['person', 'authenticator']);
99
+ var _a, _b;
100
+ const { person, authenticator, locale, locationId, organizationId, authorizer, } = assertOptions(options !== null && options !== void 0 ? options : {}, ['person', 'authenticator']);
101
101
  this.person = person;
102
102
  this.authenticator = authenticator;
103
103
  this.locationId = locationId;
@@ -111,7 +111,26 @@ class ProfileCardViewController extends AbstractViewController {
111
111
  else {
112
112
  this.formVc.removeSection('location');
113
113
  }
114
- yield this.formVc.setValues(Object.assign(Object.assign({}, options.person), { timezone: (_a = person.timezone) !== null && _a !== void 0 ? _a : locale === null || locale === void 0 ? void 0 : locale.getZoneName() }));
114
+ let canEditEmailAndPhone = ((_a = this.authenticator.getPerson()) === null || _a === void 0 ? void 0 : _a.id) === person.id;
115
+ if (!canEditEmailAndPhone) {
116
+ const can = yield authorizer.can({
117
+ contractId: 'people-contract',
118
+ permissionIds: ['can-edit-other-persons-private-fields'],
119
+ target: {
120
+ organizationId: this.organizationId,
121
+ locationId: this.locationId,
122
+ },
123
+ });
124
+ canEditEmailAndPhone = can['can-edit-other-persons-private-fields'];
125
+ }
126
+ if (canEditEmailAndPhone) {
127
+ this.formVc.addSection({
128
+ title: 'Contact Info',
129
+ fields: ['email', 'phone'],
130
+ atIndex: 1,
131
+ });
132
+ }
133
+ yield this.formVc.setValues(Object.assign(Object.assign({}, options.person), { timezone: (_b = person.timezone) !== null && _b !== void 0 ? _b : locale === null || locale === void 0 ? void 0 : locale.getZoneName() }));
115
134
  this.formVc.disable();
116
135
  this.cardVc.setIsBusy(false);
117
136
  });
@@ -1,5 +1,5 @@
1
1
  import { Locale } from '@sprucelabs/calendar-utils';
2
- import { AbstractViewController, Authenticator, Card, CardHeader, CardViewController, FormViewController, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
+ import { AbstractViewController, Authenticator, Authorizer, Card, CardHeader, CardViewController, FormViewController, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
3
3
  import { Person, PersonSchema } from '../profile.types';
4
4
  export default class ProfileCardViewController extends AbstractViewController<Card> {
5
5
  static id: string;
@@ -20,6 +20,7 @@ export default class ProfileCardViewController extends AbstractViewController<Ca
20
20
  export interface ProfileCardLoadOptions {
21
21
  person: Person;
22
22
  authenticator: Authenticator;
23
+ authorizer: Authorizer;
23
24
  locale?: Locale;
24
25
  locationId?: string;
25
26
  organizationId?: string;
@@ -89,7 +89,7 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
89
89
  this.formVc.disable();
90
90
  }
91
91
  async load(options) {
92
- const { person, authenticator, locale, locationId, organizationId } = (0, schema_1.assertOptions)(options ?? {}, ['person', 'authenticator']);
92
+ const { person, authenticator, locale, locationId, organizationId, authorizer, } = (0, schema_1.assertOptions)(options ?? {}, ['person', 'authenticator']);
93
93
  this.person = person;
94
94
  this.authenticator = authenticator;
95
95
  this.locationId = locationId;
@@ -105,6 +105,25 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
105
105
  else {
106
106
  this.formVc.removeSection('location');
107
107
  }
108
+ let canEditEmailAndPhone = this.authenticator.getPerson()?.id === person.id;
109
+ if (!canEditEmailAndPhone) {
110
+ const can = await authorizer.can({
111
+ contractId: 'people-contract',
112
+ permissionIds: ['can-edit-other-persons-private-fields'],
113
+ target: {
114
+ organizationId: this.organizationId,
115
+ locationId: this.locationId,
116
+ },
117
+ });
118
+ canEditEmailAndPhone = can['can-edit-other-persons-private-fields'];
119
+ }
120
+ if (canEditEmailAndPhone) {
121
+ this.formVc.addSection({
122
+ title: 'Contact Info',
123
+ fields: ['email', 'phone'],
124
+ atIndex: 1,
125
+ });
126
+ }
108
127
  await this.formVc.setValues({
109
128
  ...options.person,
110
129
  timezone: person.timezone ?? locale?.getZoneName(),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-profile-utils",
3
3
  "description": "Useeful utilities",
4
- "version": "15.6.16",
4
+ "version": "15.7.0",
5
5
  "skill": {
6
6
  "namespace": "profile"
7
7
  },