Skip to content

Commit f898ff1

Browse files
author
Martin Kruliš
authored
Merge pull request #227 from ReCodEx/new-roles
New roles added and set role endpoint properly registered.
2 parents 9747f9e + aa8abe3 commit f898ff1

File tree

6 files changed

+28
-31
lines changed

6 files changed

+28
-31
lines changed

app/V1Module/presenters/GroupsPresenter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ public function checkAddSupervisor(string $id, string $userId) {
648648
new Identity($user, null)
649649
);
650650

651-
if (!$this->groupAcl->canAddSupervisor($group, $user) || !$userAcl->canSupervise($group)) {
651+
if (!$this->groupAcl->canAddSupervisor($group, $user) || !$userAcl->canBecomeSupervisor($group)) {
652652
throw new ForbiddenRequestException();
653653
}
654654
}

app/V1Module/router/RouterFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ private static function createUsersRoutes(string $prefix): RouteList {
335335
$router[] = new PostRoute("$prefix/<id>", "Users:updateProfile");
336336
$router[] = new PostRoute("$prefix/<id>/settings", "Users:updateSettings");
337337
$router[] = new PostRoute("$prefix/<id>/create-local", "Users:createLocalAccount");
338+
$router[] = new PostRoute("$prefix/<id>/role", "Users:setRole");
338339
return $router;
339340
}
340341

app/V1Module/security/ACL/IGroupPermissions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ function canAssignExercise(Group $group, Exercise $exercise): bool;
3131
function canCreateExercise(Group $group): bool;
3232
function canViewPublicDetail(Group $group): bool;
3333
function canAddStudentToArchivedGroup($group, $user): bool;
34-
function canSupervise(Group $group): bool;
34+
function canBecomeSupervisor(Group $group): bool;
3535
function canSendEmail(Group $group): bool;
3636
}

app/V1Module/security/ACL/IInstancePermissions.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
use App\Model\Entity\Licence;
77

88
interface IInstancePermissions {
9-
function canAddGroup(Instance $instance): bool;
109
function canViewAll(): bool;
1110
function canViewDetail(Instance $instance): bool;
1211
function canViewGroups(Instance $instance): bool;
13-
function canViewUsers(Instance $instance): bool;
1412
function canViewLicences(Instance $instance): bool;
1513
function canAddLicence(Instance $instance): bool;
1614
function canUpdateLicence(Licence $licence): bool;
1715
function canRemoveLicence(Licence $licence): bool;
1816
function canAdd(): bool;
1917
function canUpdate(Instance $instance): bool;
2018
function canRemove(Instance $instance): bool;
21-
}
19+
}

app/V1Module/security/Roles.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ class Roles
1313
use Nette\SmartObject;
1414

1515
public const STUDENT_ROLE = "student";
16+
public const SUPERVISOR_STUDENT_ROLE = "supervisor-student";
1617
public const SUPERVISOR_ROLE = "supervisor";
18+
public const EMPOWERED_SUPERVISOR_ROLE = "empowered-supervisor";
1719
public const SUPERADMIN_ROLE = "superadmin";
1820

1921
/**
2022
* Array containing all above roles for better searching.
2123
*/
2224
public const ROLES = [
2325
self::STUDENT_ROLE,
26+
self::SUPERVISOR_STUDENT_ROLE,
2427
self::SUPERVISOR_ROLE,
28+
self::EMPOWERED_SUPERVISOR_ROLE.
2529
self::SUPERADMIN_ROLE
2630
];
2731

app/config/permissions.neon

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ roles:
44
- name: student
55
parents: unauthenticated
66

7-
- name: supervisor
7+
- name: supervisor-student
88
parents: student
99

10+
- name: supervisor
11+
parents: supervisor-student
12+
13+
- name: empowered-supervisor
14+
parents: supervisor
15+
16+
1017
- name: superadmin
1118
permissions:
1219
- allow: true
@@ -130,9 +137,9 @@ permissions:
130137

131138
- allow: true
132139
resource: group
133-
role: supervisor
140+
role: supervisor-student
134141
actions:
135-
- supervise
142+
- becomeSupervisor
136143

137144
########################
138145
# Instance permissions #
@@ -145,7 +152,6 @@ permissions:
145152
- viewAll
146153
- viewDetail
147154
- viewGroups
148-
- viewUsers
149155
- viewLicences
150156

151157
- allow: true
@@ -155,28 +161,16 @@ permissions:
155161
- viewAll
156162
- viewDetail
157163

158-
- allow: true
159-
role: supervisor
160-
resource: instance
161-
actions: addGroup
162-
conditions: instance.isMember
163-
164164
- allow: true
165165
role: student
166166
resource: instance
167167
actions:
168168
- viewGroups
169169

170-
- allow: true
171-
role: supervisor
172-
resource: instance
173-
actions: []
174-
175170
- allow: true
176171
role: superadmin # TODO instance admin role
177172
resource: instance
178173
actions:
179-
- viewUsers
180174
- viewLicences
181175
conditions:
182176
- instance.isMember
@@ -239,7 +233,7 @@ permissions:
239233
- user.isSameUser
240234

241235
- allow: true
242-
role: supervisor
236+
role: supervisor-student
243237
resource: user
244238
actions:
245239
- viewDetail
@@ -499,22 +493,22 @@ permissions:
499493
- referenceExerciseSolution.isExerciseAuthor
500494

501495
- allow: true
502-
role: supervisor
496+
role: supervisor-student
503497
resource: exercise
504498
actions:
505499
- viewDetail
506500
conditions:
507501
- exercise.isPublic
508502

509503
- allow: true
510-
role: supervisor
504+
role: supervisor-student
511505
resource: exercise
512506
actions:
513507
- viewAll
514508
- viewAllAuthors
515509

516510
- allow: true
517-
role: supervisor
511+
role: supervisor-student
518512
resource: group
519513
actions:
520514
- createExercise
@@ -553,7 +547,7 @@ permissions:
553547
- file.isRelatedToAssignment
554548

555549
- allow: true
556-
role: supervisor
550+
role: supervisor-student
557551
resource: uploadedFile
558552
actions:
559553
- download
@@ -563,7 +557,7 @@ permissions:
563557
- file.isExerciseOrAssignmentPublic
564558

565559
- allow: true
566-
role: supervisor
560+
role: supervisor-student
567561
resource: uploadedFile
568562
actions:
569563
- viewDetail
@@ -600,7 +594,7 @@ permissions:
600594
- viewAll
601595

602596
- allow: true
603-
role: supervisor
597+
role: supervisor-student
604598
resource: hardwareGroup
605599
actions:
606600
- viewAll
@@ -617,14 +611,14 @@ permissions:
617611
- viewAll
618612

619613
- allow: true
620-
role: supervisor
614+
role: supervisor-student
621615
resource: pipeline
622616
actions:
623617
- viewDetail
624618
- viewAll
625619

626620
- allow: true
627-
role: supervisor
621+
role: supervisor-student
628622
resource: pipeline
629623
actions:
630624
- update
@@ -646,7 +640,7 @@ permissions:
646640
- viewCourses
647641

648642
- allow: true
649-
role: supervisor
643+
role: supervisor-student
650644
resource: sis
651645
actions:
652646
- createTerm

0 commit comments

Comments
 (0)