diff --git a/frontend/app/abilities/report.js b/frontend/app/abilities/report.js index f0280c3b..8312e069 100644 --- a/frontend/app/abilities/report.js +++ b/frontend/app/abilities/report.js @@ -8,23 +8,49 @@ export default class ReportAbility extends Ability { return this.currentUser.user; } - get canEdit() { - const isEditable = - this.user?.isSuperuser || - (!this.model?.verifiedBy?.get("id") && - (this.model?.user?.get("id") === this.user?.get("id") || - (this.model?.user?.get("supervisors") ?? []) - .map((s) => s.id) - .includes(this.user?.get("id")))); - const isReviewer = - (this.model?.taskAssignees ?? []) - .concat( - this.model?.projectAssignees ?? [], - this.model?.customerAssignees ?? [], - ) - .filter((a) => a?.user) - .map((a) => a.user.get("id")) - .includes(this.user?.get("id")) && !this.model?.verifiedBy?.get("id"); - return isEditable || isReviewer; + get canEditSync() { + if (this.user?.isSuperuser) { + return true; + } + + if (this.model?.verifiedBy?.get("id")) { + return false; + } + + if (this.model?.user?.get("id") === this.user?.get("id")) { + return true; + } + + return false; + } + + async isReviewer() { + return ((await this.model?.taskAssignees) ?? []) + .concat( + (await this.model?.projectAssignees) ?? [], + (await this.model?.customerAssignees) ?? [], + ) + .filter((a) => a?.user) + .map((a) => a.user.get("id")) + .includes(this.user?.get("id")); + } + + async isSupervisee() { + return ((await this.model?.user?.get("supervisors")) ?? []) + .map((s) => s.id) + .includes(this.user?.get("id")); + } + + async canEditAsync() { + if (this.model?.verifiedBy?.get("id")) { + return false; + } + + const isSupervisee = await this.isSupervisee(); + if (isSupervisee) { + return true; + } + + return await this.isReviewer(); } } diff --git a/frontend/app/analysis/index/controller.js b/frontend/app/analysis/index/controller.js index a6a4b443..da2b2cd1 100644 --- a/frontend/app/analysis/index/controller.js +++ b/frontend/app/analysis/index/controller.js @@ -122,10 +122,8 @@ export default class AnalysisController extends QPController { return `The export limit is ${this.exportLimit}. Please use filters to reduce the amount of reports.`; } - get canBill() { - return ( - this.currentUser.user.isAccountant || this.currentUser.user.isSuperuser - ); + get isAccountant() { + return this.currentUser.user.isAccountant; } get appliedFilters() { @@ -362,16 +360,14 @@ export default class AnalysisController extends QPController { @action selectRow(report) { - if (this.abilities.can("edit report", report) || this.canBill) { - const selected = this.selectedReportIds; - - if (selected.includes(report.id)) { - this.selectedReportIds = A([ - ...selected.filter((id) => id !== report.id), - ]); - } else { - this.selectedReportIds = A([...selected, report.id]); - } + const selected = this.selectedReportIds; + + if (selected.includes(report.id)) { + this.selectedReportIds = A([ + ...selected.filter((id) => id !== report.id), + ]); + } else { + this.selectedReportIds = A([...selected, report.id]); } } } diff --git a/frontend/app/analysis/index/template.hbs b/frontend/app/analysis/index/template.hbs index 621c6040..56e883eb 100644 --- a/frontend/app/analysis/index/template.hbs +++ b/frontend/app/analysis/index/template.hbs @@ -330,56 +330,64 @@
{{#each reports as |report|}} {{! template-lint-disable}} -