File tree Expand file tree Collapse file tree 7 files changed +156
-1
lines changed Expand file tree Collapse file tree 7 files changed +156
-1
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \V1Module \Presenters ;
4
+
5
+ use App \Exceptions \ForbiddenRequestException ;
6
+ use App \Model \Entity \Notification ;
7
+ use App \Model \Repository \Notifications ;
8
+ use App \Security \ACL \INotificationPermissions ;
9
+
10
+ class NotificationsPresenter extends BasePresenter {
11
+
12
+ /**
13
+ * @var INotificationPermissions
14
+ * @inject
15
+ */
16
+ public $ notificationAcl ;
17
+
18
+ /**
19
+ * @var Notifications
20
+ * @inject
21
+ */
22
+ public $ notifications ;
23
+
24
+
25
+ public function checkDefault () {
26
+ if (!$ this ->notificationAcl ->canViewCurrent ()) {
27
+ throw new ForbiddenRequestException ();
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Get all notifications which are currently active.
33
+ * @GET
34
+ */
35
+ public function actionDefault () {
36
+ $ notifications = $ this ->notifications ->findAllCurrent ();
37
+ $ notifications = array_filter ($ notifications ,
38
+ function (Notification $ notification ) {
39
+ return $ this ->notificationAcl ->canViewDetail ($ notification );
40
+ });
41
+
42
+ $ this ->sendSuccessResponse ($ notifications );
43
+ }
44
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Security \ACL ;
4
+
5
+ use App \Model \Entity \Notification ;
6
+
7
+ interface INotificationPermissions {
8
+ function canViewAll (): bool ;
9
+ function canViewCurrent (): bool ;
10
+ function canViewDetail (Notification $ notification );
11
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Security \Policies ;
4
+
5
+ use App \Model \Entity \Notification ;
6
+ use App \Security \Authorizator ;
7
+ use App \Security \Identity ;
8
+
9
+ class NotificationPermissionPolicy implements IPermissionPolicy {
10
+
11
+ /** @var Authorizator */
12
+ private $ authorizator ;
13
+
14
+ public function getAssociatedClass () {
15
+ return Notification::class;
16
+ }
17
+
18
+ public function __construct (Authorizator $ authorizator ) {
19
+ $ this ->authorizator = $ authorizator ;
20
+ }
21
+
22
+
23
+ public function hasRole (Identity $ identity , Notification $ notification ) {
24
+ $ user = $ identity ->getUserData ();
25
+ if (!$ user ) {
26
+ return false ;
27
+ }
28
+
29
+ // TODO
30
+ }
31
+
32
+ public function isGlobal (Identity $ identity , Notification $ notification ) {
33
+ return $ notification ->getGroups ()->isEmpty ();
34
+ }
35
+
36
+ public function isGroupsMember (Identity $ identity , Notification $ notification ) {
37
+ $ user = $ identity ->getUserData ();
38
+ if (!$ user ) {
39
+ return false ;
40
+ }
41
+
42
+ foreach ($ notification ->getGroups () as $ group ) {
43
+ $ isMember = $ group ->isMemberOfSubgroup ($ user );
44
+ if ($ isMember ) {
45
+ return true ;
46
+ }
47
+ }
48
+
49
+ return false ;
50
+ }
51
+ }
Original file line number Diff line number Diff line change 196
196
email : App\Security\ACL\IEmailPermissions
197
197
shadowAssignment : App\Security\ACL\IShadowAssignmentPermissions
198
198
shadowAssignmentPoints : App\Security\ACL\IShadowAssignmentPointsPermissions
199
+ notification : App\Security\ACL\INotificationPermissions
199
200
policies :
200
201
group : App\Security\Policies\GroupPermissionPolicy
201
202
instance : App\Security\Policies\InstancePermissionPolicy
213
214
sisBoundGroup : App\Security\Policies\SisBoundGroupPermissionPolicy
214
215
shadowAssignment : App\Security\Policies\ShadowAssignmentPermissionPolicy
215
216
shadowAssignmentPoints : App\Security\Policies\ShadowAssignmentPointsPermissionPolicy
217
+ notification : App\Security\Policies\NotificationPermissionPolicy
216
218
217
219
extensions :
218
220
console : Kdyby\Console\DI\ConsoleExtension
@@ -366,6 +368,7 @@ services:
366
368
- App\Model\Repository\SisValidTerms
367
369
- App\Model\Repository\ShadowAssignments
368
370
- App\Model\Repository\ShadowAssignmentPointsRepository
371
+ - App\Model\Repository\Notifications
369
372
370
373
# views factories
371
374
- App\Model\View\ExerciseViewFactory
Original file line number Diff line number Diff line change 13
13
- name : empowered-supervisor
14
14
parents : supervisor
15
15
16
-
17
16
- name : superadmin
17
+
18
18
permissions :
19
19
- allow : true
20
20
role : superadmin
@@ -767,3 +767,25 @@ permissions:
767
767
- remove
768
768
conditions :
769
769
- assignmentPoints.isSupervisor
770
+
771
+ # ###########################
772
+ # Notification permissions #
773
+ # ###########################
774
+
775
+ - allow : true
776
+ role : scope-read-all
777
+ resource : notification
778
+ actions :
779
+ - viewAll
780
+ - viewCurrent
781
+ - viewDetail
782
+
783
+ - allow : true
784
+ resource : notification
785
+ actions :
786
+ - viewDetail
787
+ conditions :
788
+ - notification.hasRole
789
+ - or :
790
+ - notification.isGlobal
791
+ - notification.isGroupsMember
Original file line number Diff line number Diff line change @@ -304,6 +304,26 @@ public function isMemberOf(User $user) {
304
304
return $ this ->getActiveMembers (GroupMembership::TYPE_ALL )->contains ($ user );
305
305
}
306
306
307
+ /**
308
+ * Is member of this group or any subgroup.
309
+ * @note Is member or supervisor or admin, whole package of members.
310
+ * @param User $user
311
+ * @return bool
312
+ */
313
+ public function isMemberOfSubgroup (User $ user ) {
314
+ if ($ this ->isAdminOf ($ user ) || $ this ->isMemberOf ($ user )) {
315
+ return true ;
316
+ }
317
+
318
+ foreach ($ this ->childGroups as $ childGroup ) {
319
+ if ($ childGroup ->isMemberOfSubgroup ($ user )) {
320
+ return true ;
321
+ }
322
+ }
323
+
324
+ return false ;
325
+ }
326
+
307
327
/**
308
328
* @ORM\ManyToMany(targetEntity="User")
309
329
*/
Original file line number Diff line number Diff line change @@ -11,4 +11,8 @@ class Notifications extends BaseSoftDeleteRepository {
11
11
public function __construct (EntityManager $ em ) {
12
12
parent ::__construct ($ em , Notification::class);
13
13
}
14
+
15
+ public function findAllCurrent (): array {
16
+ // TODO
17
+ }
14
18
}
You can’t perform that action at this time.
0 commit comments