feat: Restrict company user access to media and journalist management until company and partner media data is complete, and remove journalist permissions from seeders.
This commit is contained in:
parent
25b856acde
commit
904552bd68
@ -47,10 +47,18 @@ class CustomMedia extends Page
|
||||
|
||||
public ?PartnerMedia $media = null;
|
||||
|
||||
public bool $restricted = false;
|
||||
|
||||
public array $data = [];
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
if (auth()->user()->hasRole('Perusahaan') && ! auth()->user()->company) {
|
||||
$this->restricted = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->company = auth()->user()->company;
|
||||
|
||||
$media = $this->company?->partnerMedia;
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
use App\Models\Journalist;
|
||||
use Asmit\FilamentUpload\Forms\Components\AdvancedFileUpload;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
@ -260,11 +261,27 @@ public static function table(Table $table): Table
|
||||
->defaultSort('created_at', 'desc')
|
||||
->deferFilters(false)
|
||||
->modifyQueryUsing(function (Builder $query) {
|
||||
if (auth()->user()->hasRole('Perusahaan') && ! auth()->user()->company?->partnerMedia) {
|
||||
$query->whereRaw('1 = 0');
|
||||
}
|
||||
|
||||
$query->when(auth()->user()->hasRole('Perusahaan'), function (Builder $q) {
|
||||
return $q->whereHas('partnerMedia.company', function (Builder $q) {
|
||||
$q->where('user_id', auth()->id());
|
||||
});
|
||||
});
|
||||
})
|
||||
->when(auth()->user()->hasRole('Perusahaan') && ! auth()->user()->company?->partnerMedia, function (Table $table) {
|
||||
return $table
|
||||
->emptyStateHeading('Akses Dibatasi')
|
||||
->emptyStateDescription('Mohon lengkapi data Media Anda terlebih dahulu.')
|
||||
->emptyStateIcon(Heroicon::LockClosed)
|
||||
->emptyStateActions([
|
||||
Action::make('completeMedia')
|
||||
->label('Lengkapi Data Media')
|
||||
->url(route('filament.dashboard.pages.manage.media'))
|
||||
->button(),
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,10 @@ class ManageJournalists extends ManageRecords
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
if (auth()->user()->hasRole('Perusahaan') && ! auth()->user()->company?->partnerMedia) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
CreateAction::make()
|
||||
->label('Tambah')
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
class PartnerMedia extends Model implements HasMedia
|
||||
{
|
||||
use HasFactory, InteractsWithMedia, SoftDeletes;
|
||||
use HasFactory, InteractsWithMedia,SoftDeletes;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
@ -54,11 +54,6 @@ public function taskAssignments(): BelongsToMany
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function taskAssignmentMedias(): HasMany
|
||||
{
|
||||
return $this->hasMany(TaskAssignmentMedia::class);
|
||||
}
|
||||
|
||||
public function cooperations(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Cooperation::class, 'cooperation_media')
|
||||
|
||||
@ -150,17 +150,6 @@ public function run(): void
|
||||
"RestoreAny:IssueManagement",
|
||||
"Replicate:IssueManagement",
|
||||
"Reorder:IssueManagement",
|
||||
"ViewAny:Journalist",
|
||||
"View:Journalist",
|
||||
"Create:Journalist",
|
||||
"Update:Journalist",
|
||||
"Delete:Journalist",
|
||||
"Restore:Journalist",
|
||||
"ForceDelete:Journalist",
|
||||
"ForceDeleteAny:Journalist",
|
||||
"RestoreAny:Journalist",
|
||||
"Replicate:Journalist",
|
||||
"Reorder:Journalist",
|
||||
"ViewAny:MediaMonitoring",
|
||||
"View:MediaMonitoring",
|
||||
"Create:MediaMonitoring",
|
||||
@ -321,17 +310,6 @@ public function run(): void
|
||||
"RestoreAny:IssueManagement",
|
||||
"Replicate:IssueManagement",
|
||||
"Reorder:IssueManagement",
|
||||
"ViewAny:Journalist",
|
||||
"View:Journalist",
|
||||
"Create:Journalist",
|
||||
"Update:Journalist",
|
||||
"Delete:Journalist",
|
||||
"Restore:Journalist",
|
||||
"ForceDelete:Journalist",
|
||||
"ForceDeleteAny:Journalist",
|
||||
"RestoreAny:Journalist",
|
||||
"Replicate:Journalist",
|
||||
"Reorder:Journalist",
|
||||
"ViewAny:MediaMonitoring",
|
||||
"View:MediaMonitoring",
|
||||
"Create:MediaMonitoring",
|
||||
@ -393,17 +371,6 @@ public function run(): void
|
||||
"RestoreAny:News",
|
||||
"Replicate:News",
|
||||
"Reorder:News",
|
||||
"ViewAny:Journalist",
|
||||
"View:Journalist",
|
||||
"Create:Journalist",
|
||||
"Update:Journalist",
|
||||
"Delete:Journalist",
|
||||
"Restore:Journalist",
|
||||
"ForceDelete:Journalist",
|
||||
"ForceDeleteAny:Journalist",
|
||||
"RestoreAny:Journalist",
|
||||
"Replicate:Journalist",
|
||||
"Reorder:Journalist",
|
||||
"ViewAny:Classification",
|
||||
"View:Classification",
|
||||
"ViewAny:SubClassification",
|
||||
|
||||
@ -1,9 +1,42 @@
|
||||
<x-filament-panels::page>
|
||||
<form wire:submit="save">
|
||||
{{ $this->form }}
|
||||
@if ($this->restricted)
|
||||
<div style="display: flex; align-items: center; justify-content: center; min-height: 60vh; width: 100%;"
|
||||
class="fi-restricted-wrapper">
|
||||
<div style="width: 100%; max-width: 28rem; margin: 0 auto; padding: 2rem; text-align: center;">
|
||||
|
||||
<div style="margin-top:20px;">
|
||||
<x-filament::button type="submit">Simpan</x-filament::button>
|
||||
<div style="display: flex; justify-content: center; margin-bottom: 1.5rem;">
|
||||
<div style="padding: 0.75rem;">
|
||||
<x-filament::icon icon="heroicon-o-lock-closed"
|
||||
style="width: 3.5rem; height: 3.5rem; color: #6B7280;" class="dark:text-gray-400" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2 style="font-size: 1.25rem; font-weight: 700; letter-spacing: -0.025em; margin-bottom: 0.75rem;"
|
||||
class="dark:text-white">
|
||||
Akses Dibatasi
|
||||
</h2>
|
||||
|
||||
<p style="font-size: 0.875rem; line-height: 1.25rem; color: #6B7280; margin-bottom: 2rem;"
|
||||
class="dark:text-gray-400">
|
||||
Silakan lengkapi data perusahaan Anda terlebih dahulu untuk dapat mengelola informasi media.
|
||||
</p>
|
||||
|
||||
<div style="display: flex; justify-content: center;">
|
||||
<x-filament::button :href="route('filament.dashboard.pages.manage.company')" tag="a" size="md" style="width: 100%;">
|
||||
Lengkapi Data Perusahaan
|
||||
</x-filament::button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@else
|
||||
<form wire:submit="save">
|
||||
{{ $this->form }}
|
||||
|
||||
<div class="mt-6">
|
||||
<x-filament::button type="submit">
|
||||
Simpan
|
||||
</x-filament::button>
|
||||
</div>
|
||||
</form>
|
||||
@endif
|
||||
</x-filament-panels::page>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user