Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.1
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
coverage: none

Expand Down
2 changes: 1 addition & 1 deletion .styleci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
php:
preset: laravel
version: 8
version: 8.1
enabled:
- heredoc_indentation
- trailing_comma_in_multiline_call
Expand Down
13 changes: 13 additions & 0 deletions app/Enums/ArticlePolicyAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Enums;

enum ArticlePolicyAction: string
{
case UPDATE = 'update';
case DELETE = 'delete';
case APPROVE = 'approve';
case DISAPPROVE = 'disapprove';
case DECLINE = 'decline';
case PINNED = 'togglePinnedStatus';
}
8 changes: 8 additions & 0 deletions app/Enums/NotificationPolicyAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace App\Enums;

enum NotificationPolicyAction: string
{
case MARK_AS_READ = 'markAsRead';
}
10 changes: 10 additions & 0 deletions app/Enums/ReplyPolicyAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Enums;

enum ReplyPolicyAction: string
{
case CREATE = 'create';
case UPDATE = 'update';
case DELETE = 'delete';
}
11 changes: 11 additions & 0 deletions app/Enums/ThreadPolicyAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Enums;

enum ThreadPolicyAction: string
{
case UPDATE = 'update';
case DELETE = 'delete';
case SUBSCRIBE = 'subscribe';
case UNSUBSCRIBE = 'unsubscribe';
}
10 changes: 10 additions & 0 deletions app/Enums/UserPolicyAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Enums;

enum UserPolicyAction: string
{
case ADMIN = 'admin';
case BAN = 'ban';
case DELETE = 'delete';
}
8 changes: 4 additions & 4 deletions app/Http/Controllers/Admin/ArticlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function index()

public function approve(Article $article)
{
$this->authorize(ArticlePolicy::APPROVE, $article);
$this->authorize(ArticlePolicy::APPROVE->value, $article);

$this->dispatchNow(new ApproveArticle($article));

Expand All @@ -45,7 +45,7 @@ public function approve(Article $article)

public function disapprove(Article $article)
{
$this->authorize(ArticlePolicy::DISAPPROVE, $article);
$this->authorize(ArticlePolicy::DISAPPROVE->value, $article);

$this->dispatchNow(new DisapproveArticle($article));

Expand All @@ -56,7 +56,7 @@ public function disapprove(Article $article)

public function decline(Article $article)
{
$this->authorize(ArticlePolicy::DECLINE, $article);
$this->authorize(ArticlePolicy::DECLINE->value, $article);

$this->dispatchNow(new DeclineArticle($article));

Expand All @@ -67,7 +67,7 @@ public function decline(Article $article)

public function togglePinnedStatus(Article $article)
{
$this->authorize(ArticlePolicy::PINNED, $article);
$this->authorize(ArticlePolicy::PINNED->value, $article);

$article->is_pinned = ! $article->isPinned();
$article->save();
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Admin/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function index()

public function ban(User $user)
{
$this->authorize(UserPolicy::BAN, $user);
$this->authorize(UserPolicy::BAN->value, $user);

$this->dispatchNow(new BanUser($user));

Expand All @@ -43,7 +43,7 @@ public function ban(User $user)

public function unban(User $user)
{
$this->authorize(UserPolicy::BAN, $user);
$this->authorize(UserPolicy::BAN->value, $user);

$this->dispatchNow(new UnbanUser($user));

Expand All @@ -54,7 +54,7 @@ public function unban(User $user)

public function delete(User $user)
{
$this->authorize(UserPolicy::DELETE, $user);
$this->authorize(UserPolicy::DELETE->value, $user);

$this->dispatchNow(new DeleteUser($user));

Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Articles/ArticlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function store(ArticleRequest $request)

public function edit(Article $article)
{
$this->authorize(ArticlePolicy::UPDATE, $article);
$this->authorize(ArticlePolicy::UPDATE->value, $article);

return view('articles.edit', [
'article' => $article,
Expand All @@ -121,7 +121,7 @@ public function edit(Article $article)

public function update(ArticleRequest $request, Article $article)
{
$this->authorize(ArticlePolicy::UPDATE, $article);
$this->authorize(ArticlePolicy::UPDATE->value, $article);

$wasNotPreviouslySubmitted = $article->isNotSubmitted();

Expand All @@ -138,7 +138,7 @@ public function update(ArticleRequest $request, Article $article)

public function delete(Article $article)
{
$this->authorize(ArticlePolicy::DELETE, $article);
$this->authorize(ArticlePolicy::DELETE->value, $article);

$this->dispatchNow(new DeleteArticle($article));

Expand Down
14 changes: 7 additions & 7 deletions app/Http/Controllers/Forum/ThreadsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ public function store(ThreadRequest $request)

public function edit(Thread $thread)
{
$this->authorize(ThreadPolicy::UPDATE, $thread);
$this->authorize(ThreadPolicy::UPDATE->value, $thread);
$selectedTags = $thread->tags()->pluck('id')->toArray();

return view('forum.threads.edit', ['thread' => $thread, 'tags' => Tag::all(), 'selectedTags' => $selectedTags]);
}

public function update(ThreadRequest $request, Thread $thread)
{
$this->authorize(ThreadPolicy::UPDATE, $thread);
$this->authorize(ThreadPolicy::UPDATE->value, $thread);

$thread = $this->dispatchNow(UpdateThread::fromRequest($thread, $request));

Expand All @@ -112,7 +112,7 @@ public function update(ThreadRequest $request, Thread $thread)

public function delete(Thread $thread)
{
$this->authorize(ThreadPolicy::DELETE, $thread);
$this->authorize(ThreadPolicy::DELETE->value, $thread);

$this->dispatchNow(new DeleteThread($thread));

Expand All @@ -123,7 +123,7 @@ public function delete(Thread $thread)

public function markSolution(Thread $thread, Reply $reply)
{
$this->authorize(ThreadPolicy::UPDATE, $thread);
$this->authorize(ThreadPolicy::UPDATE->value, $thread);

$this->dispatchNow(new MarkThreadSolution($thread, $reply, Auth::user()));

Expand All @@ -132,7 +132,7 @@ public function markSolution(Thread $thread, Reply $reply)

public function unmarkSolution(Thread $thread)
{
$this->authorize(ThreadPolicy::UPDATE, $thread);
$this->authorize(ThreadPolicy::UPDATE->value, $thread);

$this->dispatchNow(new UnmarkThreadSolution($thread));

Expand All @@ -141,7 +141,7 @@ public function unmarkSolution(Thread $thread)

public function subscribe(Request $request, Thread $thread)
{
$this->authorize(ThreadPolicy::SUBSCRIBE, $thread);
$this->authorize(ThreadPolicy::SUBSCRIBE->value, $thread);

$this->dispatchNow(new SubscribeToSubscriptionAble($request->user(), $thread));

Expand All @@ -152,7 +152,7 @@ public function subscribe(Request $request, Thread $thread)

public function unsubscribe(Request $request, Thread $thread)
{
$this->authorize(ThreadPolicy::UNSUBSCRIBE, $thread);
$this->authorize(ThreadPolicy::UNSUBSCRIBE->value, $thread);

$this->dispatchNow(new UnsubscribeFromSubscriptionAble($request->user(), $thread));

Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/ReplyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct()

public function store(CreateReplyRequest $request)
{
$this->authorize(ReplyPolicy::CREATE, Reply::class);
$this->authorize(ReplyPolicy::CREATE->value, Reply::class);

$reply = $this->dispatchNow(CreateReply::fromRequest($request));

Expand All @@ -35,14 +35,14 @@ public function store(CreateReplyRequest $request)

public function edit(Reply $reply)
{
$this->authorize(ReplyPolicy::UPDATE, $reply);
$this->authorize(ReplyPolicy::UPDATE->value, $reply);

return view('replies.edit', compact('reply'));
}

public function update(UpdateReplyRequest $request, Reply $reply)
{
$this->authorize(ReplyPolicy::UPDATE, $reply);
$this->authorize(ReplyPolicy::UPDATE->value, $reply);

$this->dispatchNow(new UpdateReply($reply, $request->user(), $request->body()));

Expand All @@ -53,7 +53,7 @@ public function update(UpdateReplyRequest $request, Reply $reply)

public function delete(Reply $reply)
{
$this->authorize(ReplyPolicy::DELETE, $reply);
$this->authorize(ReplyPolicy::DELETE->value, $reply);

$this->dispatchNow(new DeleteReply($reply));

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Settings/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function update(UpdateProfileRequest $request)

public function destroy(Request $request)
{
$this->authorize(UserPolicy::DELETE, $user = $request->user());
$this->authorize(UserPolicy::DELETE->value, $user = $request->user());

$this->dispatchNow(new DeleteUser($user));

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Livewire/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function markAsRead(string $notificationId): void
{
$this->notificationId = $notificationId;

$this->authorize(NotificationPolicy::MARK_AS_READ, $this->notification);
$this->authorize(NotificationPolicy::MARK_AS_READ->value, $this->notification);

$this->notification->markAsRead();

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/VerifyAdmins.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class VerifyAdmins
{
public function handle(Request $request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->user()->can(UserPolicy::ADMIN, User::class)) {
if (Auth::guard($guard)->user()->can(UserPolicy::ADMIN->value, User::class)) {
return $next($request);
}

Expand Down
13 changes: 7 additions & 6 deletions app/Policies/ArticlePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

namespace App\Policies;

use App\Enums\ArticlePolicyAction;
use App\Models\Article;
use App\Models\User;

final class ArticlePolicy
{
const UPDATE = 'update';
const DELETE = 'delete';
const APPROVE = 'approve';
const DISAPPROVE = 'disapprove';
const DECLINE = 'decline';
const PINNED = 'togglePinnedStatus';
const UPDATE = ArticlePolicyAction::UPDATE;
const DELETE = ArticlePolicyAction::DELETE;
const APPROVE = ArticlePolicyAction::APPROVE;
const DISAPPROVE = ArticlePolicyAction::DISAPPROVE;
const DECLINE = ArticlePolicyAction::DECLINE;
const PINNED = ArticlePolicyAction::PINNED;

public function update(User $user, Article $article): bool
{
Expand Down
3 changes: 2 additions & 1 deletion app/Policies/NotificationPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace App\Policies;

use App\Enums\NotificationPolicyAction;
use App\Models\User;
use Illuminate\Notifications\DatabaseNotification;

final class NotificationPolicy
{
const MARK_AS_READ = 'markAsRead';
const MARK_AS_READ = NotificationPolicyAction::MARK_AS_READ;

/**
* Determine if the given notification can be marked as read by the user.
Expand Down
7 changes: 4 additions & 3 deletions app/Policies/ReplyPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace App\Policies;

use App\Enums\ReplyPolicyAction;
use App\Models\Reply;
use App\Models\User;

final class ReplyPolicy
{
const CREATE = 'create';
const UPDATE = 'update';
const DELETE = 'delete';
const CREATE = ReplyPolicyAction::CREATE;
const UPDATE = ReplyPolicyAction::UPDATE;
const DELETE = ReplyPolicyAction::DELETE;

/**
* Determine if replies can be created by the user.
Expand Down
9 changes: 5 additions & 4 deletions app/Policies/ThreadPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace App\Policies;

use App\Enums\ThreadPolicyAction;
use App\Models\Thread;
use App\Models\User;

final class ThreadPolicy
{
const UPDATE = 'update';
const DELETE = 'delete';
const SUBSCRIBE = 'subscribe';
const UNSUBSCRIBE = 'unsubscribe';
const UPDATE = ThreadPolicyAction::UPDATE;
const DELETE = ThreadPolicyAction::DELETE;
const SUBSCRIBE = ThreadPolicyAction::SUBSCRIBE;
const UNSUBSCRIBE = ThreadPolicyAction::UNSUBSCRIBE;

public function update(User $user, Thread $thread): bool
{
Expand Down
7 changes: 4 additions & 3 deletions app/Policies/UserPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace App\Policies;

use App\Enums\UserPolicyAction;
use App\Models\User;

final class UserPolicy
{
const ADMIN = 'admin';
const BAN = 'ban';
const DELETE = 'delete';
const ADMIN = UserPolicyAction::ADMIN;
const BAN = UserPolicyAction::BAN;
const DELETE = UserPolicyAction::DELETE;

public function admin(User $user): bool
{
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"type": "project",
"require": {
"php": "^8.0",
"php": "^8.1",
"algolia/scout-extended": "^1.10",
"blade-ui-kit/blade-heroicons": "^1.0",
"blade-ui-kit/blade-icons": "^1.0",
Expand Down
Loading