approving news items

This commit is contained in:
HolgerHatGarKeineNode
2023-02-11 16:23:24 +01:00
parent 0b3528a4f0
commit a95e6222d2
3 changed files with 94 additions and 74 deletions

View File

@@ -33,19 +33,7 @@ class ArticleOverview extends Component
'tags', 'tags',
]) ])
->where('type', 'markdown_article') ->where('type', 'markdown_article')
->when(app()->environment('production'), ->where('news', true)
function ($query) {
if (auth()->user() && auth()
->user()
->hasRole('news-editor')) {
return;
}
$query
->whereHas('createdBy.roles',
fn($query) => $query->where('roles.name', 'news-editor'))
->where('approved', true);
}
)
->orderByDesc('created_at') ->orderByDesc('created_at')
->get(), ->get(),
])->layout('layouts.app', [ ])->layout('layouts.app', [

View File

@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
* @return void
*/
public function up()
{
Schema::table('library_items', function (Blueprint $table) {
$table->boolean('news')
->default(false);
});
}
/**
* Reverse the migrations.
* @return void
*/
public function down()
{
Schema::table('library_items', function (Blueprint $table) {
//
});
}
};

View File

@@ -23,82 +23,84 @@
<div class="mx-auto mt-2 grid max-w-lg gap-5 lg:max-w-none lg:grid-cols-3"> <div class="mx-auto mt-2 grid max-w-lg gap-5 lg:max-w-none lg:grid-cols-3">
@foreach($libraryItems as $libraryItem) @foreach($libraryItems as $libraryItem)
<div wire:key="library_item_{{ $libraryItem->id }}" @if($libraryItem->approved || $libraryItem->created_by === auth()->id() || auth()->user()?->hasRole('news-editor'))
class="flex flex-col overflow-hidden rounded-lg border-2 border-[#F7931A]"> <div wire:key="library_item_{{ $libraryItem->id }}"
<div class="flex-shrink-0 pt-6"> class="flex flex-col overflow-hidden rounded-lg border-2 border-[#F7931A]">
<a href="{{ route('article.view', ['libraryItem' => $libraryItem]) }}"> <div class="flex-shrink-0 pt-6">
<img class="h-48 w-full object-contain" <a href="{{ route('article.view', ['libraryItem' => $libraryItem]) }}">
src="{{ $libraryItem->getFirstMediaUrl('main') }}" <img class="h-48 w-full object-contain"
alt="{{ $libraryItem->name }}"> src="{{ $libraryItem->getFirstMediaUrl('main') }}"
</a> alt="{{ $libraryItem->name }}">
</div>
<div class="flex flex-1 flex-col justify-between bg-21gray p-6">
<div class="flex-1">
<p class="text-sm font-medium text-amber-600">
<div
class="text-amber-500">{{ $libraryItem->tags->pluck('name')->join(', ') }}</div>
</p>
<a href="{{ route('article.view', ['libraryItem' => $libraryItem]) }}"
class="mt-2 block">
<p class="text-xl font-semibold text-gray-200">{{ $libraryItem->name }}</p>
<p class="mt-3 text-base text-gray-300 line-clamp-6">{{ strip_tags($libraryItem->excerpt) }}</p>
</a> </a>
</div> </div>
<div class="mt-6 flex items-center"> <div class="flex flex-1 flex-col justify-between bg-21gray p-6">
<div class="flex-shrink-0"> <div class="flex-1">
<div> <div class="text-sm font-medium text-amber-600">
<span class="sr-only text-gray-200">{{ $libraryItem->lecturer->name }}</span> <div
<img class="h-10 w-10 object-cover rounded" class="text-amber-500">{{ $libraryItem->tags->pluck('name')->join(', ') }}</div>
src="{{ $libraryItem->lecturer->getFirstMediaUrl('avatar') }}"
alt="{{ $libraryItem->lecturer->name }}">
</div> </div>
<a href="{{ route('article.view', ['libraryItem' => $libraryItem]) }}"
class="mt-2 block">
<p class="text-xl font-semibold text-gray-200">{{ $libraryItem->name }}</p>
<p class="mt-3 text-base text-gray-300 line-clamp-6">{{ strip_tags($libraryItem->excerpt) }}</p>
</a>
</div> </div>
<div class="ml-3"> <div class="mt-6 flex items-center">
<p class="text-sm font-medium text-gray-200"> <div class="flex-shrink-0">
<div class="text-gray-200">{{ $libraryItem->lecturer->name }}</div> <div>
</p> <span
<div class="flex space-x-1 text-sm text-gray-500"> class="sr-only text-gray-200">{{ $libraryItem->lecturer->name }}</span>
<time datetime="2020-03-16">{{ $libraryItem->created_at->asDateTime() }}</time> <img class="h-10 w-10 object-cover rounded"
@if($libraryItem->read_time) src="{{ $libraryItem->lecturer->getFirstMediaUrl('avatar') }}"
<span aria-hidden="true">&middot;</span> alt="{{ $libraryItem->lecturer->name }}">
<span>{{ $libraryItem->read_time }} {{ __('min read') }}</span> </div>
@endif
</div> </div>
<div class="flex space-x-1 text-sm text-gray-500 justify-end items-end"> <div class="ml-3">
@if($libraryItem->created_by == auth()->id() || auth()->user()?->hasRole('news-editor')) <div class="text-sm font-medium text-gray-200">
<div> <div class="text-gray-200">{{ $libraryItem->lecturer->name }}</div>
@if(auth()->user()?->hasRole('news-editor')) </div>
<div class="flex space-x-1 text-sm text-gray-500">
<time
datetime="2020-03-16">{{ $libraryItem->created_at->asDateTime() }}</time>
@if($libraryItem->read_time)
<span aria-hidden="true">&middot;</span>
<span>{{ $libraryItem->read_time }} {{ __('min read') }}</span>
@endif
</div>
<div class="flex space-x-1 text-sm text-gray-500 justify-end items-end">
@if($libraryItem->created_by === auth()->id() || auth()->user()?->hasRole('news-editor'))
<div>
@if($libraryItem->approved) @if($libraryItem->approved)
<x-badge green>{{ __('approved') }}</x-badge> <x-badge green>{{ __('approved') }}</x-badge>
@else @else
<x-badge negative>{{ __('not approved') }}</x-badge> <x-badge negative>{{ __('not approved') }}</x-badge>
@endif @endif
@endif </div>
</div> <div>
<div> @if(!$libraryItem->approved && auth()->user()?->hasRole('news-editor'))
@if(!$libraryItem->approved && auth()->user()?->hasRole('news-editor')) <x-button
<x-button xs
xs wire:click="approve({{ $libraryItem->id }})"
wire:click="approve({{ $libraryItem->id }})" >
> <i class="fa fa-thin fa-check"></i>
<i class="fa fa-thin fa-check"></i> {{ __('Approve') }}
{{ __('Approve') }} </x-button>
@endif
</div>
<div>
<x-button xs
:href="route('news.form', ['libraryItem' => $libraryItem])">
<i class="fa fa-thin fa-edit"></i>
{{ __('Edit') }}
</x-button> </x-button>
@endif </div>
</div> @endif
<div> </div>
<x-button xs
:href="route('news.form', ['libraryItem' => $libraryItem])">
<i class="fa fa-thin fa-edit"></i>
{{ __('Edit') }}
</x-button>
</div>
@endif
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> @endif
@endforeach @endforeach
</div> </div>