Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions backend/timed/tracking/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,40 @@ def test_report_update_bulk_review_and_verified(
assert response.status_code == status.HTTP_400_BAD_REQUEST


@pytest.mark.parametrize(
("review", "verified"), [(True, True), (True, False), (False, True), (False, False)]
)
def test_report_update_bulk_allows_right_review_and_verified_combinations(
superadmin_client, report, verified, review
):
EmploymentFactory.create(user=superadmin_client.user)
data = {
"data": {
"type": "report-bulks",
"id": None,
"attributes": {"verified": verified, "review": review},
}
}
url = reverse("report-bulk")
query_params = f"?id={report.id}"
response = superadmin_client.post(url + query_params, data)
report.refresh_from_db()

if review and verified:
assert response.status_code == status.HTTP_400_BAD_REQUEST

if review and not verified:
assert report.verified_by is None

if not review and verified:
assert not report.review
assert report.verified_by is not None

if not review and not verified:
assert not report.review
assert report.verified_by is None


def test_report_update_bulk_bill_non_reviewer(
internal_employee_client,
report_factory,
Expand Down
15 changes: 14 additions & 1 deletion backend/timed/tracking/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,24 @@ def bulk(self, request):

fields["verified_by"] = (verified and user) or None

if fields.get("review") or any(queryset.values_list("review", flat=True)):
if (
any(queryset.values_list("review", flat=True))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
any(queryset.values_list("review", flat=True))
queryset.filter(review=True).exists()

and verified
and fields.get("review")
) or (verified and fields.get("review")):
raise exceptions.ParseError(
_("Reports can't both be set as `review` and `verified`.")
)

if (
verified is None
and fields.get("review")
and any(queryset.values_list("verified_by", flat=True))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
and any(queryset.values_list("verified_by", flat=True))
and queryset.filter(verified_by__isnull=False).exists()

):
raise exceptions.ParseError(
_("Reports can't both be set as `review` and `verified`.")
)

if serializer.validated_data.get("billed", None) is not None and not (
user.is_superuser or user.is_accountant
):
Expand Down
22 changes: 19 additions & 3 deletions frontend/app/analysis/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,29 @@ export default class AnalysisEditController extends Controller {
return this.isAccountant || this.isSuperuser;
}

get needsReview() {
@action
needsReview(form) {
return (
this.intersectionModel?.review === null ||
this.intersectionModel?.review === true
(this.intersectionModel?.review === null ||
this.intersectionModel?.review === true) &&
form.model.change?.review !== false
);
}

@action
showVerifiedWarning(form) {
const review =
form.model.change?.review !== undefined
? form.model.change?.review
: form.model.data.review;
const verified =
form.model.change?.verified !== undefined
? form.model.change?.verified
: form.model.data.verified;

return verified && review;
}

get toolTipText() {
let result = "";
if (this.needsReview && this.canVerify) {
Expand Down
15 changes: 14 additions & 1 deletion frontend/app/analysis/edit/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@
@checked={{fi.value}}
@onChange={{fi.update}}
@title={{this.toolTipText}}
@disabled={{or (not this.canVerify) this.needsReview}}
@disabled={{or
(not this.canVerify)
(this.needsReview f)
}}
>
Verified
{{#if (eq model.verified null)}}
Expand All @@ -224,6 +227,16 @@
{{#if (not-eq f.model.verified model.verified)}}
<ChangedWarning />
{{/if}}
{{#if (this.showVerifiedWarning f)}}
<span class="text-warning ml-2">
<FaIcon
@icon="exclamation-triangle"
@prefix="fas"
/>
Reports can't be "needs review" and "verified" at
the same time.
</span>
{{/if}}
</Checkbox>
</f.input>
</div>
Expand Down
Loading