Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ember-data v5.3 #436

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
14 changes: 0 additions & 14 deletions frontend/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*
.*/
.eslintcache

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try

# template lint ci config
.template-lintrc-ci.js
1 change: 1 addition & 0 deletions frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ module.exports = {
"ember/no-observers": "warn",
"qunit/no-assert-equal": "warn",
"ember/require-tagless-components": "warn",
"qunit/require-expect": "warn",
},
};
14 changes: 1 addition & 13 deletions frontend/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*
.eslintcache
.lint-todo/
.*/

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try
23 changes: 0 additions & 23 deletions frontend/.template-lintrc-ci.js

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/.template-lintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use strict";

module.exports = {
extends: "recommended",
extends: ["recommended"],
};
2 changes: 1 addition & 1 deletion frontend/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"ignore_dirs": ["tmp", "dist"]
"ignore_dirs": ["dist"]
}
68 changes: 49 additions & 19 deletions frontend/app/abilities/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,54 @@ export default class ReportAbility extends Ability {
}

get canEdit() {
const isEditable =
this.user?.isSuperuser ||
(!this.model?.verifiedBy?.get("id") &&
// eslint-disable-next-line ember/no-get
(this.model?.user?.get("id") === this.user?.get("id") ||
// eslint-disable-next-line ember/no-get
(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;
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 canAedit() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the naming is not ideal. What do you think of canEditAsync? Then it would be more obvious what that thing does.

if (this.model?.verifiedBy?.get("id")) {
return false;
}

const isSupervisee = await this.isSupervisee();
if (isSupervisee) {
return true;
}

const isReviewer = await this.isReviewer();

if (isReviewer) {
return true;
}

return false;
}
}
46 changes: 38 additions & 8 deletions frontend/app/analysis/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default class AnalysisEditController extends Controller {
})}`,
{
method: "GET",
}
},
);

yield this.store.pushPayload("report-intersection", res);
Expand Down Expand Up @@ -184,15 +184,45 @@ export default class AnalysisEditController extends Controller {

const queryString = toQueryString(params);

yield changeset.execute();
// this is an ugly mess, to get around the changeset using a PromiseProxy
const changes = changeset.get("changes");

const { comment, notBillable, rejected, review, billed, verified } =
changeset;
const _attributes = {
comment,
notBillable,
rejected,
review,
billed,
verified,
};

const [user, customer, project, task] = [
changeset.get("user.id") &&
this.store.peekRecord("user", changeset.get("user.id")),
changeset.get("customer.id") &&
this.store.peekRecord("customer", changeset.get("customer.id")),
changeset.get("project.id") &&
this.store.peekRecord("project", changeset.get("project.id")),
changeset.get("task.id") &&
this.store.peekRecord("task", changeset.get("task.id")),
];
const _relationships = { user, customer, project, task };

const {
data: { attributes, relationships },
} = this.intersectionModel.serialize();
} = this.store
.createRecord("report-intersection", {
..._attributes,
..._relationships,
})
.serialize();

const data = {
type: "report-bulks",
attributes: filterUnchanged(attributes, changeset.get("changes")),
relationships: filterUnchanged(relationships, changeset.get("changes")),
attributes: filterUnchanged(attributes, changes),
relationships: filterUnchanged(relationships, changes),
};

yield this.fetch.fetch(`/api/v1/reports/bulk?editable=1&${queryString}`, {
Expand Down Expand Up @@ -252,9 +282,9 @@ export default class AnalysisEditController extends Controller {
underscoreQueryParams(
serializeQueryParams(
filterQueryParams(params, "editable"),
queryParamsState(this)
)
)
queryParamsState(this),
),
),
);
}
}
6 changes: 3 additions & 3 deletions frontend/app/analysis/edit/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
{{/unless}}
{{#if
(and
f.model.change.customer
f.model.change.customer.id
(not
(eq f.model.change.customer.id model.customer.id)
)
Expand All @@ -63,7 +63,7 @@
{{/unless}}
{{#if
(and
f.model.change.project
f.model.change.project.id
(not
(eq f.model.change.project.id model.project.id)
)
Expand All @@ -82,7 +82,7 @@
{{/unless}}
{{#if
(and
f.model.change.task
f.model.change.task.id
(not (eq f.model.change.task.id model.task.id))
)
}}
Expand Down
Loading
Loading