Skip to content

Commit b831f27

Browse files
authored
Merge pull request #751 from Yelinz/feat-admin-edit
feat(ember): allow admins to always edit the form
2 parents 2e7176f + 9686c32 commit b831f27

File tree

4 files changed

+66
-17
lines changed

4 files changed

+66
-17
lines changed

caluma/extensions/permissions.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@
1717

1818

1919
class MySAGWPermission(BasePermission):
20-
def _is_admin_or_sagw(self, info):
20+
def _is_admin(self, info):
21+
groups = info.context.user.groups
22+
return "admin" in groups
23+
24+
def _is_sagw(self, info):
2125
groups = info.context.user.groups
22-
return "admin" in groups or "sagw" in groups
26+
return "sagw" in groups
27+
28+
def _is_admin_or_sagw(self, info):
29+
return self._is_admin(info) or self._is_sagw(info)
2330

2431
def _can_access_case(self, info, case):
2532
case_ids = get_cases_for_user(info.context.user)
@@ -84,7 +91,10 @@ def has_permission_for_save_document_answer(self, mutation, info, answer):
8491

8592
case = self._get_case_for_doc(answer.document)
8693

87-
if not self._is_admin_or_sagw(info) and not (
94+
if self._is_admin(info):
95+
return True
96+
97+
if not (
8898
self._can_access_case(info, case)
8999
or self._is_own(info, answer.document.family)
90100
):

ember/app/abilities/case.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export default class CaseAbility extends BaseAbility {
1111
}
1212

1313
get canEdit() {
14-
return this.hasAccess(this.model);
14+
return (
15+
this.isAdmin ||
16+
(this.model.hasSubmitOrReviseWorkItem && this.hasAccess(this.model))
17+
);
1518
}
1619

1720
get canDelete() {

ember/app/ui/cases/detail/edit/controller.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ export default class CasesDetailEditController extends Controller {
66
@service can;
77

88
get disabled() {
9-
return !(
10-
this.model.hasSubmitOrReviseWorkItem &&
11-
this.can.can("edit case", this.model)
12-
);
9+
return !this.can.can("edit case", this.model);
1310
}
1411
}

ember/tests/unit/ui/cases/detail/edit/controller-test.js

+48-9
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,67 @@ module("Unit | Controller | cases/detail/edit", function (hooks) {
77
setupTest(hooks);
88

99
hooks.beforeEach(function () {
10+
ENV.APP.caluma = {};
11+
ENV.APP.caluma.documentEditableTaskSlugs = ["test"];
12+
this.controller = this.owner.lookup("controller:cases/detail/edit");
13+
this.controller.model = {
14+
hasEditableWorkItem: false,
15+
accesses: [{ email: "test@test.com" }],
16+
};
17+
});
18+
19+
test("no access", function (assert) {
1020
this.owner.register(
1121
"service:session",
1222
{
1323
isAuthenticated: true,
1424
data: {
1525
authenticated: {
16-
userinfo: { email: "lorem@ipsum.co", mysagw_groups: ["sagw"] },
26+
userinfo: { email: "lorem@ipsum.co", mysagw_groups: [] },
1727
},
1828
},
1929
},
2030
{ instantiate: false }
2131
);
32+
33+
assert.true(this.controller.disabled);
2234
});
2335

24-
test("it is setup properly", function (assert) {
25-
ENV.APP.caluma = {};
26-
ENV.APP.caluma.documentEditableTaskSlugs = ["test"];
27-
const controller = this.owner.lookup("controller:cases/detail/edit");
28-
controller.model = {
29-
hasEditableWorkItem: false,
30-
accesses: [{ email: "test@test.com" }],
36+
test("admin access", function (assert) {
37+
this.owner.register(
38+
"service:session",
39+
{
40+
isAuthenticated: true,
41+
data: {
42+
authenticated: {
43+
userinfo: { email: "lorem@ipsum.co", mysagw_groups: ["admin"] },
44+
},
45+
},
46+
},
47+
{ instantiate: false }
48+
);
49+
50+
assert.false(this.controller.disabled);
51+
});
52+
53+
test("user access", function (assert) {
54+
this.owner.register(
55+
"service:session",
56+
{
57+
isAuthenticated: true,
58+
data: {
59+
authenticated: {
60+
userinfo: { email: "lorem@ipsum.co", mysagw_groups: [] },
61+
},
62+
},
63+
},
64+
{ instantiate: false }
65+
);
66+
this.controller.model = {
67+
hasEditableWorkItem: true,
68+
accesses: [{ email: "lorem@ipsum.co" }],
3169
};
32-
assert.true(controller.disabled);
70+
71+
assert.true(this.controller.disabled);
3372
});
3473
});

0 commit comments

Comments
 (0)