Skip to content

Commit 65ee59b

Browse files
Refactor indexQuery method in KerangkaAcuan.php to filter results based on session year and user role
1 parent 52ef04d commit 65ee59b

File tree

8 files changed

+37
-15
lines changed

8 files changed

+37
-15
lines changed

app/Nova/BastMitra.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Helpers\Helper;
66
use App\Helpers\Policy;
77
use App\Models\KodeArsip;
8+
use App\Models\KontrakMitra;
89
use App\Models\NaskahDefault;
910
use App\Nova\Actions\GenerateBastMitra;
1011
use Laravel\Nova\Fields\BelongsTo;
@@ -31,6 +32,12 @@ public static function label()
3132
return 'BAST Mitra';
3233
}
3334

35+
public static function indexQuery(NovaRequest $request, $query)
36+
{
37+
$kontrakMitraIds = KontrakMitra::where('tahun', session('year'))->get()->pluck('id');
38+
return $query->whereIn('kontrak_mitra_id', $kontrakMitraIds);
39+
}
40+
3441
/**
3542
* The single value that should be used to represent the resource when being displayed.
3643
*

app/Nova/HonorKegiatan.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public static function label()
4444
return 'Honor Kegiatan';
4545
}
4646

47+
public static function indexQuery(NovaRequest $request, $query)
48+
{
49+
return $query->where('tahun', session('year'));
50+
}
51+
4752
/**
4853
* The single value that should be used to represent the resource when being displayed.
4954
*

app/Nova/IzinKeluar.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static function label()
2727
{
2828
return 'Izin Keluar';
2929
}
30+
3031

3132
/**
3233
* The model the resource corresponds to.
@@ -59,13 +60,7 @@ public static function label()
5960
*/
6061
public static function indexQuery(NovaRequest $request, $query)
6162
{
62-
$users = User::cache()->get('all')->where('unit_kerja_id', $request->user()->unit_kerja_id)->pluck('id')->toArray();
63-
if (Policy::make()->allowedFor('anggota')->get()) {
64-
return $query->where('user_id', $request->user()->id);
65-
}
66-
if (Policy::make()->allowedFor('koordinator')->get()) {
67-
return $query->whereIn('user_id', $users);
68-
}
63+
$query->whereYear('tanggal', session('year'));
6964
}
7065

7166
/**

app/Nova/KontrakMitra.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public static function label()
3232
return 'Kontrak Mitra';
3333
}
3434

35+
public static function indexQuery(NovaRequest $request, $query)
36+
{
37+
return $query->where('tahun', session('year'));
38+
}
39+
3540
/**
3641
* The single value that should be used to represent the resource when being displayed.
3742
*

app/Nova/NaskahKeluar.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public static function label()
3131
return 'Naskah Keluar';
3232
}
3333

34+
public static function indexQuery(NovaRequest $request, $query)
35+
{
36+
$query->whereYear('tanggal', session('year'));
37+
}
38+
3439
/**
3540
* The model the resource corresponds to.
3641
*

app/Nova/NaskahMasuk.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public static function label()
2727
return 'Naskah Masuk';
2828
}
2929

30+
public static function indexQuery(NovaRequest $request, $query)
31+
{
32+
$query->whereYear('tanggal', session('year'));
33+
}
34+
3035
/**
3136
* The model the resource corresponds to.
3237
*

app/Policies/NaskahKeluarPolicy.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function view(User $user, NaskahKeluar $naskahKeluar): bool
3636
public function create(): bool
3737
{
3838
return Policy::make()
39-
->allowedFor('all')
39+
->allowedFor('anggota,koordinator,kepala,arsiparis')
4040
->get();
4141
}
4242

@@ -46,7 +46,7 @@ public function create(): bool
4646
public function update(User $user, NaskahKeluar $naskahKeluar): bool
4747
{
4848
return Policy::make()
49-
->allowedFor('all')
49+
->allowedFor('anggota,koordinator,kepala,arsiparis')
5050
->withYear(Helper::getYearFromDate($naskahKeluar->tanggal))
5151
->get();
5252
}
@@ -57,7 +57,7 @@ public function update(User $user, NaskahKeluar $naskahKeluar): bool
5757
public function delete(User $user, NaskahKeluar $naskahKeluar): bool
5858
{
5959
return Policy::make()
60-
->allowedFor('all')
60+
->allowedFor('anggota,koordinator,kepala,arsiparis')
6161
->withYear(Helper::getYearFromDate($naskahKeluar->tanggal))
6262
->get();
6363
}
@@ -68,7 +68,7 @@ public function delete(User $user, NaskahKeluar $naskahKeluar): bool
6868
public function replicate(): bool
6969
{
7070
return Policy::make()
71-
->allowedFor('all')
71+
->allowedFor('anggota,koordinator,kepala,arsiparis')
7272
->get();
7373
}
7474
}

app/Policies/NaskahMasukPolicy.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function view(User $user, NaskahMasuk $naskahMasuk): bool
3636
public function create(): bool
3737
{
3838
return Policy::make()
39-
->allowedFor('all')
39+
->allowedFor('anggota,koordinator,kepala,arsiparis')
4040
->get();
4141
}
4242

@@ -46,7 +46,7 @@ public function create(): bool
4646
public function update(User $user, NaskahMasuk $naskahMasuk): bool
4747
{
4848
return Policy::make()
49-
->allowedFor('all')
49+
->allowedFor('anggota,koordinator,kepala,arsiparis')
5050
->withYear(Helper::getYearFromDate($naskahMasuk->tanggal))
5151
->get();
5252
}
@@ -57,7 +57,7 @@ public function update(User $user, NaskahMasuk $naskahMasuk): bool
5757
public function delete(User $user, NaskahMasuk $naskahMasuk): bool
5858
{
5959
return Policy::make()
60-
->allowedFor('all')
60+
->allowedFor('anggota,koordinator,kepala,arsiparis')
6161
->withYear(Helper::getYearFromDate($naskahMasuk->tanggal))
6262
->get();
6363
}
@@ -68,7 +68,7 @@ public function delete(User $user, NaskahMasuk $naskahMasuk): bool
6868
public function replicate(): bool
6969
{
7070
return Policy::make()
71-
->allowedFor('all')
71+
->allowedFor('anggota,koordinator,kepala,arsiparis')
7272
->get();
7373
}
7474
}

0 commit comments

Comments
 (0)