22
33namespace App \Policies ;
44
5+ use App \Helpers \Helper ;
56use App \Helpers \Policy ;
7+ use App \Models \KerangkaAcuan ;
8+ use App \Models \User ;
69
710class KerangkaAcuanPolicy
811{
912 /**
1013 * Determine whether the user can view any models.
1114 */
12- public function viewAny (): bool
15+ public function viewAny (User $ user ): bool
1316 {
1417 return Policy::make ()
15- ->allowedFor ( ' all ' )
18+ ->notAllowedFor ( ' kepala,admin ' )
1619 ->get ();
1720 }
1821
1922 /**
2023 * Determine whether the user can view the model.
2124 */
22- public function view (): bool
25+ public function view (User $ user , KerangkaAcuan $ kerangkaAcuan ): bool
2326 {
2427 return Policy::make ()
25- ->allowedFor ('all ' )
28+ ->notAllowedFor ('kepala,admin ' )
29+ ->withYear (Helper::getYearFromDate ($ kerangkaAcuan ->tanggal ))
30+ ->andEqual ($ kerangkaAcuan ->unit_kerja_id , Helper::getDataPegawaiByUserId ($ user ->id , now ())->unit_kerja_id )
2631 ->get ();
2732 }
2833
2934 /**
3035 * Determine whether the user can create models.
3136 */
32- public function create (): bool
37+ public function create (User $ user ): bool
3338 {
3439 return Policy::make ()
3540 ->allowedFor ('koordinator,anggota ' )
@@ -39,37 +44,36 @@ public function create(): bool
3944 /**
4045 * Determine whether the user can update the model.
4146 */
42- public function update (): bool
47+ public function update (User $ user , KerangkaAcuan $ kerangkaAcuan ): bool
4348 {
4449 return Policy::make ()
4550 ->allowedFor ('koordinator,anggota ' )
51+ ->withYear (Helper::getYearFromDate ($ kerangkaAcuan ->tanggal ))
52+ ->andEqual ($ kerangkaAcuan ->unit_kerja_id , Helper::getDataPegawaiByUserId ($ user ->id , now ())->unit_kerja_id )
4653 ->get ();
4754 }
4855
4956 /**
5057 * Determine whether the user can delete the model.
5158 */
52- public function delete (): bool
59+ public function delete (User $ user , KerangkaAcuan $ kerangkaAcuan ): bool
5360 {
5461 return Policy::make ()
5562 ->allowedFor ('koordinator,anggota ' )
63+ ->withYear (Helper::getYearFromDate ($ kerangkaAcuan ->tanggal ))
64+ ->andEqual ($ kerangkaAcuan ->unit_kerja_id , Helper::getDataPegawaiByUserId ($ user ->id , now ())->unit_kerja_id )
5665 ->get ();
5766 }
5867
5968 /**
6069 * Determine whether the user can replicate the model.
6170 */
62- public function replicate (): bool
71+ public function replicate (User $ user , KerangkaAcuan $ kerangkaAcuan ): bool
6372 {
6473 return Policy::make ()
6574 ->allowedFor ('koordinator,anggota ' )
66- ->get ();
67- }
68-
69- public function runAction (): bool
70- {
71- return Policy::make ()
72- ->allowedFor ('all ' )
75+ ->withYear (Helper::getYearFromDate ($ kerangkaAcuan ->tanggal ))
76+ ->andEqual ($ kerangkaAcuan ->unit_kerja_id , Helper::getDataPegawaiByUserId ($ user ->id , now ())->unit_kerja_id )
7377 ->get ();
7478 }
7579}
0 commit comments