diff --git a/ember/app/abilities/-base.js b/ember/app/abilities/-base.js index c7846534e..6f9c462ed 100644 --- a/ember/app/abilities/-base.js +++ b/ember/app/abilities/-base.js @@ -28,16 +28,27 @@ export default class BaseAbility extends Ability { return this.isStaff || this.isAdmin; } - isOwnIdentity(identity) { + isOwnIdentity(idpId) { if (!this.session.isAuthenticated) { return false; } - return identity.idpId === this.session.data.authenticated.userinfo.sub; + return idpId === this.session.data.authenticated.userinfo.sub; } - isStaffOrOwnIdentity(identity) { - return this.isStaffOrAdmin || this.isOwnIdentity(identity); + canEditIdentity(identity) { + if (this.isStaffOrAdmin) { + return true; + } else if (this.model.isOrganisation) { + return this.model.members.any( + (member) => + member.authorized && + !member.isInactive && + this.isOwnIdentity(member.identity.get("idpId")) + ); + } + + return this.isOwnIdentity(identity.idpId); } hasAccess(calumaCase) { diff --git a/ember/app/abilities/additional-email.js b/ember/app/abilities/additional-email.js index 895fcdc9e..290b7a7e1 100644 --- a/ember/app/abilities/additional-email.js +++ b/ember/app/abilities/additional-email.js @@ -6,14 +6,14 @@ export default class AdditionalEmailAbility extends BaseAbility { } canAdd() { - return this.isStaffOrOwnIdentity(this.model); + return this.canEditIdentity(this.model); } canEdit() { - return this.isStaffOrOwnIdentity(this.model); + return this.canEditIdentity(this.model); } canDelete() { - return this.isStaffOrOwnIdentity(this.model); + return this.canEditIdentity(this.model); } } diff --git a/ember/app/abilities/address.js b/ember/app/abilities/address.js index 895fcdc9e..f979ace30 100644 --- a/ember/app/abilities/address.js +++ b/ember/app/abilities/address.js @@ -5,15 +5,15 @@ export default class AdditionalEmailAbility extends BaseAbility { return this.isStaff; } - canAdd() { - return this.isStaffOrOwnIdentity(this.model); + get canAdd() { + return this.canEditIdentity(this.model); } - canEdit() { - return this.isStaffOrOwnIdentity(this.model); + get canEdit() { + return this.canEditIdentity(this.model); } - canDelete() { - return this.isStaffOrOwnIdentity(this.model); + get canDelete() { + return this.canEditIdentity(this.model); } } diff --git a/ember/app/abilities/identity.js b/ember/app/abilities/identity.js index a9433bc14..9ab76fa73 100644 --- a/ember/app/abilities/identity.js +++ b/ember/app/abilities/identity.js @@ -4,20 +4,28 @@ export default class IdentityAbility extends BaseAbility { get canList() { return this.isStaff; } + get canAdd() { return this.isStaff; } - get canEditOrganisation() { + + get canEdit() { + return this.canEditIdentity(this.model); + } + + get canDelete() { return this.isStaff; } - canAddInterest() { - return this.isStaffOrOwnIdentity(this.model); + + get canEditOrganisation() { + return this.isStaff; } - canRemoveInterest() { - return this.isStaffOrOwnIdentity(this.model); + + get canAddInterest() { + return this.canEditIdentity(this.model); } - canEdit() { - return this.isStaffOrOwnIdentity(this.model); + get canRemoveInterest() { + return this.canEditIdentity(this.model); } } diff --git a/ember/app/abilities/phone-number.js b/ember/app/abilities/phone-number.js index e50469389..81dfc23a3 100644 --- a/ember/app/abilities/phone-number.js +++ b/ember/app/abilities/phone-number.js @@ -5,14 +5,14 @@ export default class PhoneNumberAbility extends BaseAbility { return this.isStaff; } canAdd() { - return this.isStaffOrOwnIdentity(this.model); + return this.canEditIdentity(this.model); } canEdit() { - return this.isStaffOrOwnIdentity(this.model); + return this.canEditIdentity(this.model); } canDelete() { - return this.isStaffOrOwnIdentity(this.model); + return this.canEditIdentity(this.model); } } diff --git a/ember/app/models/identity.js b/ember/app/models/identity.js index 486bb2f36..da6f5a6a0 100644 --- a/ember/app/models/identity.js +++ b/ember/app/models/identity.js @@ -12,9 +12,6 @@ export default class IdentityModel extends LocalizedModel { @attr lastName; @attr email; @attr language; - @hasMany("additional-email") additionalEmails; - @hasMany("phone-number") phoneNumbers; - @hasMany("interest") interests; @attr isOrganisation; @attr isExpertAssociation; @attr isAdvisoryBoard; @@ -23,8 +20,14 @@ export default class IdentityModel extends LocalizedModel { @attr hasMembers; @attr isAuthorized; - @hasMany("membership") memberships; - @hasMany("membership") members; + @hasMany("additional-email", { inverse: "identity", async: true }) + additionalEmails; + @hasMany("phone-number", { inverse: "identity", async: true }) phoneNumbers; + @hasMany("address", { inverse: "identity", async: true }) address; + @hasMany("interest", { async: true }) interests; + + @hasMany("membership", { inverse: "identity", async: true }) memberships; + @hasMany("membership", { inverse: "organisation", async: true }) members; // special attribute from org-memberships endpoint @attr roles; diff --git a/ember/app/models/interest-category.js b/ember/app/models/interest-category.js index 5526d5cb8..aaf63334f 100644 --- a/ember/app/models/interest-category.js +++ b/ember/app/models/interest-category.js @@ -4,7 +4,8 @@ import { localizedAttr, LocalizedModel } from "ember-localized-model"; export default class InterestCategoryModel extends LocalizedModel { @localizedAttr title; @attr description; - @hasMany interests; @attr archived; @attr public; + + @hasMany("interest", {inverse: "category", async: true}) interests; } diff --git a/ember/app/models/interest.js b/ember/app/models/interest.js index 8cddaf6cf..7f79dfa15 100644 --- a/ember/app/models/interest.js +++ b/ember/app/models/interest.js @@ -4,6 +4,7 @@ import { localizedAttr, LocalizedModel } from "ember-localized-model"; export default class InterestModel extends LocalizedModel { @localizedAttr title; @attr description; - @belongsTo("interest-category") category; @attr archived; + @belongsTo("interest-category", { inverse: "interests", async: true }) + category; } diff --git a/ember/app/models/membership.js b/ember/app/models/membership.js index acc92d430..e5a3a1052 100644 --- a/ember/app/models/membership.js +++ b/ember/app/models/membership.js @@ -12,9 +12,9 @@ const membershipInactive = (membership) => { export { membershipInactive }; export default class MembershipModel extends LocalizedModel { - @belongsTo("identity", { inverse: "memberships" }) identity; - @belongsTo("identity", { inverse: "members" }) organisation; - @belongsTo("membership-role") role; + @belongsTo("identity", { inverse: "memberships", async: true }) identity; + @belongsTo("identity", { inverse: "members", async: true }) organisation; + @belongsTo("membership-role", { async: true }) role; @attr authorized; @attr timeSlot; @attr nextElection; diff --git a/ember/app/ui/components/identity-form/component.js b/ember/app/ui/components/identity-form/component.js index 8b8f367e2..ecc08ba7c 100644 --- a/ember/app/ui/components/identity-form/component.js +++ b/ember/app/ui/components/identity-form/component.js @@ -119,7 +119,7 @@ export default class IdentityFormComponent extends Component { this.args.onSave?.(changeset.data); if (this.backToIdentities) { - this.router.transitionTo("identities"); + this.router.transitionTo(this.cancelRoute); } } catch (error) { console.error(error); diff --git a/ember/app/ui/components/identity-form/template.hbs b/ember/app/ui/components/identity-form/template.hbs index 2345d868e..b15ea50af 100644 --- a/ember/app/ui/components/identity-form/template.hbs +++ b/ember/app/ui/components/identity-form/template.hbs @@ -1,9 +1,14 @@ -
+
{{#if this.changeset}} {{#unless @customEndpoint}}
@@ -40,7 +52,10 @@ @label={{t "components.identity-form.label.isAdvisoryBoard"}} @type="checkbox" @name="isAdvisoryBoard" - @disabled={{or (cannot "edit identity" this.changeset.data) @readOnlyView}} + @disabled={{or + (cannot "edit identity" this.changeset.data) + @readOnlyView + }} />
@@ -51,7 +66,10 @@ {{/if}}
@@ -63,7 +81,10 @@ @options={{this.salutations}} @optionLabelPath="label" @optionTargetPath="value" - @disabled={{or (cannot "edit identity" this.changeset.data) @readOnlyView}} + @disabled={{or + (cannot "edit identity" this.changeset.data) + @readOnlyView + }} />
@@ -74,7 +95,10 @@ @options={{this.titles}} @optionLabelPath="label" @optionTargetPath="value" - @disabled={{or (cannot "edit identity" this.changeset.data) @readOnlyView}} + @disabled={{or + (cannot "edit identity" this.changeset.data) + @readOnlyView + }} />
@@ -83,14 +107,20 @@
@@ -103,14 +133,12 @@ >
{{#if this.changeset.idpId}}

- + {{~t "components.identity-form.hint.email"~}}

@@ -137,7 +169,10 @@ @options={{this.languages}} @optionLabelPath="label" @optionTargetPath="value" - @disabled={{or (cannot "edit identity" this.changeset.data) @readOnlyView}} + @disabled={{or + (cannot "edit identity" this.changeset.data) + @readOnlyView + }} /> {{#if @profileView}} @@ -147,8 +182,7 @@ @disabled={{cannot "edit identity" this.changeset.data}} />
- {{else if @readOnlyView}} - {{else}} + {{else if @readOnlyView}}{{else}}
- {{#unless this.changeset.isNew}} + {{#if (and (not this.changeset.isNew) (can "delete identity"))}} - {{/unless}} + {{/if}}
- + {{t "global.cancel"}} @@ -189,4 +226,4 @@ {{/if}} {{/if}} -
+ \ No newline at end of file diff --git a/ember/app/ui/components/identity-memberships/template.hbs b/ember/app/ui/components/identity-memberships/template.hbs index 77aa36769..544933aef 100644 --- a/ember/app/ui/components/identity-memberships/template.hbs +++ b/ember/app/ui/components/identity-memberships/template.hbs @@ -11,10 +11,15 @@ {{#if this.memberships.length}}