Skip to content

Commit

Permalink
feat(ember): enable editing organisation through profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelinz committed Jan 5, 2024
1 parent a909ea0 commit cbe6f7b
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 76 deletions.
19 changes: 15 additions & 4 deletions ember/app/abilities/-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions ember/app/abilities/additional-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 6 additions & 6 deletions ember/app/abilities/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
22 changes: 15 additions & 7 deletions ember/app/abilities/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions ember/app/abilities/phone-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
13 changes: 8 additions & 5 deletions ember/app/models/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion ember/app/models/interest-category.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 10 in ember/app/models/interest-category.js

View workflow job for this annotation

GitHub Actions / ember-test

Replace `inverse:·"category",·async:·true` with `·inverse:·"category",·async:·true·`

Check failure on line 10 in ember/app/models/interest-category.js

View workflow job for this annotation

GitHub Actions / ember-test

Replace `inverse:·"category",·async:·true` with `·inverse:·"category",·async:·true·`
}
3 changes: 2 additions & 1 deletion ember/app/models/interest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 3 additions & 3 deletions ember/app/models/membership.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ember/app/ui/components/identity-form/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit cbe6f7b

Please sign in to comment.