Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
fix(report): fix report permissions and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelinz authored and Stefan committed Apr 15, 2021
1 parent 5b707bb commit fa9386b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
6 changes: 1 addition & 5 deletions app/abilities/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ export default Ability.extend({
function() {
return (
this.get("user.isSuperuser") ||
(!(
this.get("model.verifiedBy") &&
this.get("model.verifiedBy.id") &&
this.get("model.billed")
) &&
(!(this.get("model.verifiedBy.id") && this.get("model.billed")) &&
(this.get("model.user.id") === this.get("user.id") ||
this.getWithDefault("model.user.supervisors", [])
.mapBy("id")
Expand Down
18 changes: 10 additions & 8 deletions app/components/report-row/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ const ReportRowComponent = Component.extend({

attributeBindings: ["title"],

editable() {
return this.cannot.can("edit report", this.get("report"));
},
editable: computed("report.{verifiedBy,billed}", {
get() {
return this.can.can("edit report", this.get("report"));
}
}),

title: computed("report.verifiedBy", function() {
return this.get("report.verifiedBy.id")
? `This entry was already verified by ${this.get(
title: computed("editable", function() {
return this.editable
? ""
: `This entry was already verified by ${this.get(
"report.verifiedBy.fullName"
)} and therefore not editable anymore`
: "";
)} and therefore not editable anymore`;
}),

/**
Expand Down
4 changes: 2 additions & 2 deletions app/components/report-row/template.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#task-selection disabled=(cannot 'edit report' report) task=changeset.task as |t|}}
{{#task-selection disabled=(not editable) task=changeset.task as |t|}}
<div class="form-list-cell form-group {{if changeset.error.task 'has-error'}}">{{t.customer}}</div>
<div class="form-list-cell form-group {{if changeset.error.task 'has-error'}}">{{t.project}}</div>
<div class="form-list-cell form-group {{if changeset.error.task 'has-error'}}">{{t.task}}</div>
Expand All @@ -11,7 +11,7 @@
placeholder="Comment"
name="comment"
value={{changeset.comment}}
disabled={{cannot 'edit report' report}}
disabled={{not editable}}
onchange={{action (mut changeset.comment) value='target.value'}}
data-test-report-comment
>
Expand Down
5 changes: 4 additions & 1 deletion app/index/reports/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export default Controller.extend({
});

if (!reportsToday.filterBy("isNew", true).get("length")) {
this.store.createRecord("report", { date: this.get("model") });
this.store.createRecord("report", {
date: this.get("model"),
user: this.get("user")
});
}

return reportsToday.sort(a => (a.get("isNew") ? 1 : 0));
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/components/report-row/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ module("Integration | Component | report row", function(hooks) {
verifiedBy: EmberObject.create({
id: 1,
fullName: "John Doe"
})
}),
billed: true
})
);

Expand Down

0 comments on commit fa9386b

Please sign in to comment.