codesniffer fixes
This commit is contained in:
@@ -191,7 +191,7 @@ class Conductor
|
||||
if ($separatorPos !== false) {
|
||||
$operator = '==';
|
||||
$valueList = explode('|', $value);
|
||||
foreach($valueList as $valueItem) {
|
||||
foreach ($valueList as $valueItem) {
|
||||
$this->appendFilter($field, $operator, $valueItem, 'OR');
|
||||
}
|
||||
continue 2;
|
||||
@@ -289,14 +289,14 @@ class Conductor
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(count($condition) < 3 && $condition[0] !== '') {
|
||||
if(count($condition) < 2) {
|
||||
if (count($condition) < 3 && $condition[0] !== '') {
|
||||
if (count($condition) < 2) {
|
||||
$condition[1] = 'LIKE';
|
||||
}
|
||||
$condition[2] = '%';
|
||||
}
|
||||
|
||||
if(count($condition) === 3) {
|
||||
if (count($condition) === 3) {
|
||||
list($field, $operator, $value) = $condition;
|
||||
|
||||
if ($item !== null) {
|
||||
@@ -781,8 +781,11 @@ class Conductor
|
||||
* @param string $outerJoin The join for this filter group.
|
||||
* @return void
|
||||
*/
|
||||
final public function appendFilterString(string $rawFilter, array|null $limitFields = null, string $outerJoin = 'AND'): void
|
||||
{
|
||||
final public function appendFilterString(
|
||||
string $rawFilter,
|
||||
array|null $limitFields = null,
|
||||
string $outerJoin = 'AND'
|
||||
): void {
|
||||
if ($rawFilter === '') {
|
||||
return;
|
||||
}
|
||||
@@ -924,18 +927,26 @@ class Conductor
|
||||
*/
|
||||
public function fields(Model $model): array
|
||||
{
|
||||
$visibleFields = Cache::remember("model:{$model->getTable()}:visible", now()->addDays(28), function () use ($model) {
|
||||
$fields = $model->getVisible();
|
||||
if (empty($fields) === true) {
|
||||
$fields = Cache::remember("schema:{$model->getTable()}:columns", now()->addDays(28), function () use ($model) {
|
||||
return $model->getConnection()
|
||||
->getSchemaBuilder()
|
||||
->getColumnListing($model->getTable());
|
||||
});
|
||||
}
|
||||
$visibleFields = Cache::remember(
|
||||
"model:{$model->getTable()}:visible",
|
||||
now()->addDays(28),
|
||||
function () use ($model) {
|
||||
$fields = $model->getVisible();
|
||||
if (empty($fields) === true) {
|
||||
$fields = Cache::remember(
|
||||
"schema:{$model->getTable()}:columns",
|
||||
now()->addDays(28),
|
||||
function () use ($model) {
|
||||
return $model->getConnection()
|
||||
->getSchemaBuilder()
|
||||
->getColumnListing($model->getTable());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return $fields;
|
||||
});
|
||||
return $fields;
|
||||
}
|
||||
);
|
||||
|
||||
$appends = $model->getAppends();
|
||||
if (is_array($appends) === true) {
|
||||
|
||||
@@ -34,6 +34,7 @@ class EventConductor extends Conductor
|
||||
* Run a scope query on the collection before anything else.
|
||||
*
|
||||
* @param Builder $builder The builder in use.
|
||||
* @return void
|
||||
*/
|
||||
public function scope(Builder $builder): void
|
||||
{
|
||||
|
||||
@@ -96,7 +96,7 @@ class MediaConductor extends Conductor
|
||||
if ($user === null || $user->hasPermission($model->security_data) === false) {
|
||||
return false;
|
||||
}
|
||||
} else if($model->security_type !== '' && strcasecmp('password', $model->security_type) !== 0) {
|
||||
} elseif ($model->security_type !== '' && strcasecmp('password', $model->security_type) !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -168,8 +168,17 @@ class MediaConductor extends Conductor
|
||||
return UserConductor::includeModel(request(), 'user', $user);
|
||||
}
|
||||
|
||||
public function includeJobs(Model $model) {
|
||||
$jobs = $model->jobs()->select(['id','created_at','updated_at','user_id','status','status_text','progress'])->orderBy('created_at', 'desc')->get();
|
||||
/**
|
||||
* Include job models in Media
|
||||
*
|
||||
* @param Model $model The reference model.
|
||||
* @return mixed
|
||||
*/
|
||||
public function includeJobs(Model $model)
|
||||
{
|
||||
$jobs = $model->jobs()
|
||||
->select(['id','created_at','updated_at','user_id','status','status_text','progress'])
|
||||
->orderBy('created_at', 'desc')->get();
|
||||
return $jobs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,10 @@ class SubscriptionConductor extends Conductor
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
return ($user !== null && ((strcasecmp($model->email, $user->email) === 0 && $user->email_verified_at !== null) || $user->hasPermission('admin/subscriptions') === true));
|
||||
return ($user !== null && (
|
||||
(strcasecmp($model->email, $user->email) === 0 && $user->email_verified_at !== null) ||
|
||||
$user->hasPermission('admin/subscriptions') === true
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,6 +39,7 @@ class SubscriptionConductor extends Conductor
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
return ($user !== null && ((strcasecmp($model->email, $user->email) === 0 && $user->email_verified_at !== null) || $user->hasPermission('admin/subscriptions') === true));
|
||||
return ($user !== null && ((strcasecmp($model->email, $user->email) === 0 &&
|
||||
$user->email_verified_at !== null) || $user->hasPermission('admin/subscriptions') === true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,11 @@ class UserConductor extends Conductor
|
||||
$data = $model->toArray();
|
||||
$limit = $this->fields($model);
|
||||
|
||||
if ($user === null || ($user->hasPermission('admin/users') === false && strcasecmp($user->id, $model->id) !== 0)) {
|
||||
if (
|
||||
$user === null || (
|
||||
$user->hasPermission('admin/users') === false && strcasecmp($user->id, $model->id) !== 0
|
||||
)
|
||||
) {
|
||||
$limit = ['id', 'display_name'];
|
||||
} else {
|
||||
$data['permissions'] = $user->permissions;
|
||||
|
||||
@@ -21,18 +21,21 @@ class CleanupTempFiles extends Command
|
||||
*/
|
||||
protected $description = 'Delete temporary files that are older that 1 day';
|
||||
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): void
|
||||
{
|
||||
$keepTime = 1 * 24 * 60 * 60; // 1 Day
|
||||
$keepTime = (1 * 24 * 60 * 60); // 1 Day
|
||||
$currentTimeStamp = time();
|
||||
$deletedFileCount = 0;
|
||||
|
||||
foreach (glob(storage_path('app/tmp/*')) as $filename) {
|
||||
$fileModifiedTimeStamp = filemtime($filename);
|
||||
if($currentTimeStamp - $fileModifiedTimeStamp > $keepTime) {
|
||||
if (($currentTimeStamp - $fileModifiedTimeStamp) > $keepTime) {
|
||||
unlink($filename);
|
||||
$deletedFileCount++;
|
||||
}
|
||||
|
||||
@@ -21,10 +21,13 @@ class RemoveStaleMediaJobs extends Command
|
||||
*/
|
||||
protected $description = 'Remove media_jobs that have not been modified for 48 hours';
|
||||
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): void
|
||||
{
|
||||
$threshold = now()->subHours(48);
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ class Kernel extends ConsoleKernel
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule The schedule.
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
@@ -21,6 +22,8 @@ class Kernel extends ConsoleKernel
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands(): void
|
||||
{
|
||||
|
||||
@@ -58,6 +58,8 @@ class Enum
|
||||
/**
|
||||
* Returns a message from the enum subclass
|
||||
*
|
||||
* @param integer $messageIndex The message index to retrieve.
|
||||
* @param string $defaultMessage Message to use if index does not exist.
|
||||
* @return string
|
||||
*/
|
||||
public static function getMessage(int $messageIndex, string $defaultMessage = 'Unknown'): string
|
||||
|
||||
@@ -2,14 +2,11 @@
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use App\Mail\ExceptionMail;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Throwable;
|
||||
use PDOException;
|
||||
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
@@ -31,6 +28,8 @@ class Handler extends ExceptionHandler
|
||||
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
@@ -65,14 +64,19 @@ class Handler extends ExceptionHandler
|
||||
|
||||
$this->reportable(function (Throwable $e) {
|
||||
if ($this->shouldReport($e) === true) {
|
||||
if(App::runningUnitTests() === false) {
|
||||
if (App::runningUnitTests() === false) {
|
||||
$this->sendEmail($e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send email
|
||||
*
|
||||
* @param Throwable $exception Throwable object.
|
||||
* @return void
|
||||
*/
|
||||
public function sendEmail(Throwable $exception)
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -61,7 +61,7 @@ function arrayDefaultValue(string $key, array $arr, mixed $value): mixed
|
||||
*
|
||||
* @param string $val The value to check.
|
||||
* @param array $arr The array to check.
|
||||
* @return bool
|
||||
* @return boolean
|
||||
*/
|
||||
function existsInArray(string $val, array $arr): bool
|
||||
{
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
/* Temp File Helper Functions */
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Generate a temporary file path.
|
||||
@@ -18,7 +17,8 @@ function generateTempFilePath(string $extension = '', string $part = ''): string
|
||||
mkdir($temporaryDir, 0777, true);
|
||||
}
|
||||
|
||||
return $temporaryDir . DIRECTORY_SEPARATOR . uniqid('upload_', true) . ($extension !== '' ? ".{$extension}" : '') . ($part !== '' ? ".part-{$part}" : '');
|
||||
return $temporaryDir . DIRECTORY_SEPARATOR . uniqid('upload_', true) . ($extension !== '' ? ".{$extension}" : '') .
|
||||
($part !== '' ? ".part-{$part}" : '');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ function tempFileInfo(string $filePath): array
|
||||
$part = '';
|
||||
|
||||
// Extract the part if it's present
|
||||
if (preg_match('/\.part-(\d+)$/', $filePath, $matches)) {
|
||||
if (preg_match('/\.part-(\d+)$/', $filePath, $matches) !== false) {
|
||||
$part = $matches[1];
|
||||
$filePath = substr($filePath, 0, -strlen($matches[0]));
|
||||
}
|
||||
@@ -44,7 +44,7 @@ function tempFileInfo(string $filePath): array
|
||||
$extension = '';
|
||||
|
||||
// If there's an extension, separate it
|
||||
if (isset($info['extension'])) {
|
||||
if (isset($info['extension']) === true) {
|
||||
$extension = $info['extension'];
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ function tempFileInfo(string $filePath): array
|
||||
* @param string $name The file name.
|
||||
* @param string $extension The file extension to use.
|
||||
* @param string $part The file part number.
|
||||
* @return bool If the file exists.
|
||||
* @return boolean If the file exists.
|
||||
*/
|
||||
function tempFileExists(string $dir, string $name, string $extension = '', string $part = ''): bool
|
||||
{
|
||||
@@ -85,7 +85,8 @@ function tempFileExists(string $dir, string $name, string $extension = '', strin
|
||||
*/
|
||||
function constructTempFileName(string $dir, string $name, string $extension = '', string $part = ''): string
|
||||
{
|
||||
$filename = $dir . DIRECTORY_SEPARATOR . $name . ($extension !== '' ? ".{$extension}" : '') . ($part !== "" ? ".part-{$part}" : '');
|
||||
$filename = $dir . DIRECTORY_SEPARATOR . $name . ($extension !== '' ? ".{$extension}" : '') .
|
||||
($part !== "" ? ".part-{$part}" : '');
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,11 @@ class AnalyticsController extends ApiController
|
||||
'ip' => $request->ip()
|
||||
];
|
||||
|
||||
if ($user !== null && $user->hasPermission('admin/analytics') === true && $request->has('session') === true) {
|
||||
if (
|
||||
$user !== null &&
|
||||
$user->hasPermission('admin/analytics') === true &&
|
||||
$request->has('session') === true
|
||||
) {
|
||||
$data['session_id'] = $request->input('session_id');
|
||||
$analytics = AnalyticsItemRequest::create($data);
|
||||
} else {
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Models\Attachment;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AttachmentController extends ApiController
|
||||
{
|
||||
/**
|
||||
* ApplicationController constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth:sanctum')
|
||||
->except(['store', 'destroyByEmail']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Attachment $attachment
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Attachment $attachment)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Attachment $attachment
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Attachment $attachment)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Attachment $attachment
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Attachment $attachment)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Attachment $attachment
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Attachment $attachment)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ class AuthController extends ApiController
|
||||
* Current User details
|
||||
*
|
||||
* @param Request $request Current request data.
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function me(Request $request): JsonResponse
|
||||
{
|
||||
@@ -48,7 +49,11 @@ class AuthController extends ApiController
|
||||
{
|
||||
$user = User::where('email', '=', $request->input('email'))->first();
|
||||
|
||||
if ($user !== null && strlen($user->password) > 0 && Hash::check($request->input('password'), $user->password) === true) {
|
||||
if (
|
||||
$user !== null &&
|
||||
strlen($user->password) > 0 &&
|
||||
Hash::check($request->input('password'), $user->password) === true
|
||||
) {
|
||||
if ($user->email_verified_at === null) {
|
||||
return $this->respondWithErrors([
|
||||
'email' => 'Email address has not been verified.'
|
||||
@@ -86,6 +91,7 @@ class AuthController extends ApiController
|
||||
* Logout current user
|
||||
*
|
||||
* @param Request $request Current request data.
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function logout(Request $request): JsonResponse
|
||||
{
|
||||
|
||||
@@ -10,8 +10,10 @@ use App\Conductors\UserConductor;
|
||||
use App\Http\Requests\EventRequest;
|
||||
use App\Models\Media;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class EventController extends ApiController
|
||||
{
|
||||
@@ -120,7 +122,13 @@ class EventController extends ApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function userList(Request $request, Event $event)
|
||||
/**
|
||||
* List users of Event
|
||||
* @param Request $request The HTTP request.
|
||||
* @param Event $event Event model.
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function userList(Request $request, Event $event): JsonResponse
|
||||
{
|
||||
$authUser = $request->user();
|
||||
$eventUsers = $event->users;
|
||||
@@ -136,16 +144,28 @@ class EventController extends ApiController
|
||||
});
|
||||
}
|
||||
|
||||
return $this->respondAsResource(UserConductor::collection($request, $eventUsers), ['isCollection' => true, 'resourceName' => 'users']);
|
||||
return $this->respondAsResource(
|
||||
UserConductor::collection($request, $eventUsers),
|
||||
[
|
||||
'isCollection' => true,
|
||||
'resourceName' => 'users'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
}//end if
|
||||
|
||||
return $this->respondForbidden();
|
||||
}
|
||||
|
||||
public function userAdd(Request $request, Event $event)
|
||||
/**
|
||||
* Add user to Event
|
||||
* @param Request $request The HTTP request.
|
||||
* @param Event $event Event model.
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function userAdd(Request $request, Event $event): JsonResponse
|
||||
{
|
||||
$authUser = $request->user();
|
||||
if ($authUser !== null && $authUser->hasPermission('admin/events') === true) {
|
||||
@@ -177,12 +197,26 @@ class EventController extends ApiController
|
||||
return $this->respondForbidden();
|
||||
}
|
||||
|
||||
public function userUpdate(Request $request, Event $event)
|
||||
/**
|
||||
* Update user
|
||||
* @param Request $request The HTTP request.
|
||||
* @param Event $event Event model.
|
||||
* @return void
|
||||
*/
|
||||
public function userUpdate(Request $request, Event $event): void
|
||||
{
|
||||
// only admin/events permitted
|
||||
}
|
||||
|
||||
public function userDelete(Request $request, Event $event, User $user)
|
||||
/**
|
||||
* Delete user from event
|
||||
*
|
||||
* @param Request $request The HTTP request.
|
||||
* @param Event $event Event model.
|
||||
* @param User $user User model.
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function userDelete(Request $request, Event $event, User $user): JsonResponse
|
||||
{
|
||||
$authUser = $request->user();
|
||||
if ($authUser !== null && $authUser->hasPermission('admin/events') === true) {
|
||||
|
||||
@@ -45,7 +45,12 @@ class LogController extends ApiController
|
||||
|
||||
$before = $request->get('before');
|
||||
if ($before !== null) {
|
||||
$before = preg_split("/([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/", $before, -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));
|
||||
$before = preg_split(
|
||||
"/([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/",
|
||||
$before,
|
||||
-1,
|
||||
(PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)
|
||||
);
|
||||
if (count($before) !== 6) {
|
||||
$before = null;
|
||||
}
|
||||
@@ -53,7 +58,12 @@ class LogController extends ApiController
|
||||
|
||||
$after = $request->get('after');
|
||||
if ($after !== null) {
|
||||
$after = preg_split("/([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/", $after, -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));
|
||||
$after = preg_split(
|
||||
"/([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/",
|
||||
$after,
|
||||
-1,
|
||||
(PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)
|
||||
);
|
||||
if (count($after) !== 6) {
|
||||
$after = null;
|
||||
}
|
||||
@@ -77,30 +87,59 @@ class LogController extends ApiController
|
||||
$logContent = file_get_contents($logFile['path']);
|
||||
}
|
||||
|
||||
$logArray = preg_split("/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: (?:(?!\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: )[\s\S])*)/", $logContent, -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));
|
||||
$logArray = preg_split(
|
||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
"/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: (?:(?!\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: )[\s\S])*)/",
|
||||
$logContent,
|
||||
-1,
|
||||
(PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)
|
||||
);
|
||||
|
||||
$logContent = '';
|
||||
$logLineCount = 0;
|
||||
$logLineSkip = false;
|
||||
foreach (array_reverse($logArray) as $logLine) {
|
||||
$lineDate = preg_split("/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2}): /", $logLine, -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));
|
||||
$lineDate = preg_split(
|
||||
"/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2}): /",
|
||||
$logLine,
|
||||
-1,
|
||||
(PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)
|
||||
);
|
||||
if (count($lineDate) >= 6) {
|
||||
$logLineSkip = false;
|
||||
|
||||
// Is line before
|
||||
if ($before !== null && ($lineDate[0] > $before[0] || $lineDate[1] > $before[1] || $lineDate[2] > $before[2] || $lineDate[3] > $before[3] || $lineDate[4] > $before[4] || $lineDate[5] > $before[5])) {
|
||||
if (
|
||||
$before !== null && (
|
||||
$lineDate[0] > $before[0] ||
|
||||
$lineDate[1] > $before[1] ||
|
||||
$lineDate[2] > $before[2] ||
|
||||
$lineDate[3] > $before[3] ||
|
||||
$lineDate[4] > $before[4] ||
|
||||
$lineDate[5] > $before[5]
|
||||
)
|
||||
) {
|
||||
$logLineSkip = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Is line after
|
||||
if ($after !== null && ($after[0] > $lineDate[0] || $after[1] > $lineDate[1] || $after[2] > $lineDate[2] || $after[3] > $lineDate[3] || $after[4] > $lineDate[4] || $after[5] > $lineDate[5])) {
|
||||
if (
|
||||
$after !== null && (
|
||||
$after[0] > $lineDate[0] ||
|
||||
$after[1] > $lineDate[1] ||
|
||||
$after[2] > $lineDate[2] ||
|
||||
$after[3] > $lineDate[3] ||
|
||||
$after[4] > $lineDate[4] ||
|
||||
$after[5] > $lineDate[5]
|
||||
)
|
||||
) {
|
||||
$logLineSkip = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
$logLineCount += 1;
|
||||
}
|
||||
}//end if
|
||||
|
||||
if ($logLineCount > $lines) {
|
||||
break;
|
||||
|
||||
@@ -10,6 +10,7 @@ use App\Models\Media;
|
||||
use App\Models\MediaJob;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -123,7 +124,9 @@ class MediaController extends ApiController
|
||||
case UPLOAD_ERR_PARTIAL:
|
||||
return $this->respondWithErrors([$file => 'The file upload was interrupted.']);
|
||||
default:
|
||||
return $this->respondWithErrors([$file => 'An error occurred uploading the file to the server.']);
|
||||
return $this->respondWithErrors(
|
||||
[$file => 'An error occurred uploading the file to the server.']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,12 +154,16 @@ class MediaController extends ApiController
|
||||
}
|
||||
|
||||
if ($request->has('name') === true || $file !== null) {
|
||||
$data['name'] = $request->has('chunk') === true ? $request->get('name', '') : $file->getClientOriginalName();
|
||||
$data['name'] = (
|
||||
$request->has('chunk') === true ? $request->get('name', '') : $file->getClientOriginalName()
|
||||
);
|
||||
}
|
||||
|
||||
if ($file !== null) {
|
||||
$data['size'] = $request->has('chunk') === true ? intval($request->get('size', 0)) : $file->getSize();
|
||||
$data['mime_type'] = $request->has('chunk') === true ? $request->get('mime_type', '') : $file->getMimeType();
|
||||
$data['mime_type'] = (
|
||||
$request->has('chunk') === true ? $request->get('mime_type', '') : $file->getMimeType()
|
||||
);
|
||||
}
|
||||
|
||||
if ($request->has('storage') === true || $file !== null) {
|
||||
@@ -167,36 +174,42 @@ class MediaController extends ApiController
|
||||
$data['security']['type'] = $request->get('security_type', '');
|
||||
$data['security']['data'] = $request->get('security_data', '');
|
||||
|
||||
if($data['security']['type'] === '') {
|
||||
if ($data['security']['type'] === '') {
|
||||
$data['security']['data'] = '';
|
||||
}
|
||||
|
||||
if($medium === null || strcasecmp($data['security']['type'], $medium->security_type) !== 0) {
|
||||
if($request->has('storage') === false) {
|
||||
if ($medium === null || strcasecmp($data['security']['type'], $medium->security_type) !== 0) {
|
||||
if ($request->has('storage') === false) {
|
||||
$mime_type = $request->get('mime_type', $medium === null ? '' : $medium->mime_type);
|
||||
$data['storage'] = Media::recommendedStorage($mime_type, $data['security']['type']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists('storage', $data) === true &&
|
||||
(array_key_exists('security', $data) === true && array_key_exists('type', $data['security']) === true) &&
|
||||
if (
|
||||
array_key_exists('storage', $data) === true && (
|
||||
array_key_exists('security', $data) === true &&
|
||||
array_key_exists('type', $data['security']) === true
|
||||
) &&
|
||||
array_key_exists('mime_type', $data) === true &&
|
||||
$data['mime_type'] !== "") {
|
||||
$data['mime_type'] !== ""
|
||||
) {
|
||||
$error = Media::verifyStorage($data['mime_type'], $data['security']['type'], $data['storage']);
|
||||
// Log::error($data['mime_type'] . ' - ' . $data['security']['type'] . ' - ' . $data['storage']);
|
||||
switch($error) {
|
||||
case Media::STORAGE_VALID:
|
||||
break;
|
||||
case Media::STORAGE_MIME_MISSING:
|
||||
return $this->respondWithErrors(['mime_type' => 'The file type is required.']);
|
||||
case Media::STORAGE_NOT_FOUND:
|
||||
return $this->respondWithErrors(['storage' => 'Storage was not found.']);
|
||||
case Media::STORAGE_INVALID_SECURITY:
|
||||
return $this->respondWithErrors(['storage' => 'Storage invalid for this security requirement.']);
|
||||
default:
|
||||
return $this->respondWithErrors(['storage' => 'Storage verification error occurred.']);
|
||||
}
|
||||
switch ($error) {
|
||||
case Media::STORAGE_VALID:
|
||||
break;
|
||||
case Media::STORAGE_MIME_MISSING:
|
||||
return $this->respondWithErrors(['mime_type' => 'The file type is required.']);
|
||||
case Media::STORAGE_NOT_FOUND:
|
||||
return $this->respondWithErrors(['storage' => 'Storage was not found.']);
|
||||
case Media::STORAGE_INVALID_SECURITY:
|
||||
return $this->respondWithErrors(
|
||||
['storage' => 'Storage invalid for this security requirement.']
|
||||
);
|
||||
default:
|
||||
return $this->respondWithErrors(['storage' => 'Storage verification error occurred.']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->has('transform') === true) {
|
||||
@@ -211,7 +224,12 @@ class MediaController extends ApiController
|
||||
} elseif (preg_match('/^crop-(\d+)-(\d+)$/', $value, $matches) !== false) {
|
||||
$transform['crop'] = ['width' => $matches[1], 'height' => $matches[2]];
|
||||
} elseif (preg_match('/^crop-(\d+)-(\d+)-(\d+)-(\d+)$/', $value, $matches) !== false) {
|
||||
$transform['crop'] = ['width' => $matches[1], 'height' => $matches[2], 'x' => $matches[3], 'y' => $matches[4]];
|
||||
$transform['crop'] = [
|
||||
'width' => $matches[1],
|
||||
'height' => $matches[2],
|
||||
'x' => $matches[3],
|
||||
'y' => $matches[4]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -252,7 +270,10 @@ class MediaController extends ApiController
|
||||
return $this->respondServerError();
|
||||
}
|
||||
|
||||
$temporaryFilePath = generateTempFilePath(pathinfo($data['name'], PATHINFO_EXTENSION), $request->get('chunk', ''));
|
||||
$temporaryFilePath = generateTempFilePath(
|
||||
pathinfo($data['name'], PATHINFO_EXTENSION),
|
||||
$request->get('chunk', '')
|
||||
);
|
||||
copy($file->path(), $temporaryFilePath);
|
||||
|
||||
if ($request->has('chunk') === true) {
|
||||
@@ -293,15 +314,15 @@ class MediaController extends ApiController
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
||||
* @param \App\Models\Media $medium Specified media.
|
||||
* @param \App\Models\Media $media Specified media.
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function download(Request $request, Media $media)
|
||||
public function download(Request $request, Media $media): Response
|
||||
{
|
||||
$headers = [];
|
||||
|
||||
/* Check file exists */
|
||||
if(Storage::disk($media->storage)->exists($media->name) === false) {
|
||||
if (Storage::disk($media->storage)->exists($media->name) === false) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
@@ -328,17 +349,22 @@ class MediaController extends ApiController
|
||||
/* no security */
|
||||
$headerPragma = 'public';
|
||||
$headerExpires = $updated_at->addMonth()->toRfc2822String();
|
||||
} else if (strcasecmp('password', $media->security_type) === 0) {
|
||||
} elseif (strcasecmp('password', $media->security_type) === 0) {
|
||||
/* password */
|
||||
if(
|
||||
if (
|
||||
($user === null || $user->hasPermission('admin/media') === false) &&
|
||||
($request->has('password') === false || $request->get('password') !== $media->security_data)) {
|
||||
($request->has('password') === false || $request->get('password') !== $media->security_data)
|
||||
) {
|
||||
return $this->respondForbidden();
|
||||
}
|
||||
} else if (strcasecmp('permission', $media->security_type) === 0) {
|
||||
} elseif (strcasecmp('permission', $media->security_type) === 0) {
|
||||
/* permission */
|
||||
if(
|
||||
$user === null || ($user->hasPermission('admin/media') === false && $user->hasPermission($media->security_data) === false)) {
|
||||
if (
|
||||
$user === null || (
|
||||
$user->hasPermission('admin/media') === false &&
|
||||
$user->hasPermission($media->security_data) === false
|
||||
)
|
||||
) {
|
||||
return $this->respondForbidden();
|
||||
}
|
||||
}//end if
|
||||
@@ -374,8 +400,10 @@ class MediaController extends ApiController
|
||||
|
||||
$stream = Storage::disk($media->storage)->readStream($media->name);
|
||||
return response()->stream(
|
||||
function() use($stream) {
|
||||
while(ob_get_level() > 0) ob_end_flush();
|
||||
function () use ($stream) {
|
||||
while (ob_get_level() > 0) {
|
||||
ob_end_flush();
|
||||
}
|
||||
fpassthru($stream);
|
||||
},
|
||||
200,
|
||||
@@ -400,7 +428,9 @@ class MediaController extends ApiController
|
||||
case UPLOAD_ERR_PARTIAL:
|
||||
return $this->respondWithErrors([$errorKey => 'The file upload was interrupted.']);
|
||||
default:
|
||||
return $this->respondWithErrors([$errorKey => 'An error occurred uploading the file to the server.']);
|
||||
return $this->respondWithErrors(
|
||||
[$errorKey => 'An error occurred uploading the file to the server.']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,10 @@ class MediaJobController extends ApiController
|
||||
public function show(Request $request, MediaJob $mediaJob)
|
||||
{
|
||||
if (MediaJobConductor::viewable($mediaJob) === true) {
|
||||
return $this->respondAsResource(MediaJobConductor::model($request, $mediaJob), ['resourceName' => 'media_job']);
|
||||
return $this->respondAsResource(
|
||||
MediaJobConductor::model($request, $mediaJob),
|
||||
['resourceName' => 'media_job']
|
||||
);
|
||||
}
|
||||
|
||||
return $this->respondForbidden();
|
||||
|
||||
@@ -101,7 +101,10 @@ class OCRController extends ApiController
|
||||
$tesseractImageFilterFunc = function ($filter, $options = null) use ($curlResult, $curlSize, $ocr) {
|
||||
$result = '';
|
||||
$img = imagecreatefromstring($curlResult);
|
||||
if ($img !== false && (($options !== null && imagefilter($img, $filter, $options) === true) || ($options === null && imagefilter($img, $filter) === true))) {
|
||||
if (
|
||||
$img !== false && (($options !== null && imagefilter($img, $filter, $options) === true) ||
|
||||
($options === null && imagefilter($img, $filter) === true))
|
||||
) {
|
||||
ob_start();
|
||||
imagepng($img);
|
||||
$imgData = ob_get_contents();
|
||||
|
||||
@@ -2,17 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Conductors\MediaConductor;
|
||||
use App\Conductors\ShortlinkConductor;
|
||||
use App\Enum\HttpResponseCodes;
|
||||
use App\Http\Requests\MediaRequest;
|
||||
use App\Http\Requests\ShortlinkRequest;
|
||||
use App\Models\Media;
|
||||
use App\Models\Shortlink;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Laravel\Sanctum\PersonalAccessToken;
|
||||
|
||||
class ShortlinkController extends ApiController
|
||||
{
|
||||
@@ -85,8 +79,8 @@ class ShortlinkController extends ApiController
|
||||
/**
|
||||
* Update the media resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\ShortlinkRequest $request The update request.
|
||||
* @param \App\Models\Shortlink $medium The specified shortlink.
|
||||
* @param \App\Http\Requests\ShortlinkRequest $request The update request.
|
||||
* @param \App\Models\Shortlink $shortlink The specified shortlink.
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(ShortlinkRequest $request, Shortlink $shortlink)
|
||||
@@ -102,7 +96,7 @@ class ShortlinkController extends ApiController
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Shortlink $medium Specified shortlink.
|
||||
* @param \App\Models\Shortlink $shortlink Specified shortlink.
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Shortlink $shortlink)
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Conductors\SubscriptionConductor;
|
||||
use App\Enum\HttpResponseCodes;
|
||||
use App\Models\Subscription;
|
||||
use App\Http\Requests\SubscriptionRequest;
|
||||
use App\Jobs\SendEmailJob;
|
||||
use App\Mail\SubscriptionConfirm;
|
||||
use App\Mail\SubscriptionUnsubscribed;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SubscriptionController extends ApiController
|
||||
{
|
||||
/**
|
||||
* ApplicationController constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth:sanctum')
|
||||
->except(['store', 'destroyByEmail']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of subscribers.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
list($collection, $total) = SubscriptionConductor::request($request);
|
||||
|
||||
return $this->respondAsResource(
|
||||
$collection,
|
||||
['isCollection' => true,
|
||||
'appendData' => ['total' => $total]
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified user.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request The endpoint request.
|
||||
* @param \App\Models\Subscription $subscription The subscription model.
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Request $request, Subscription $subscription)
|
||||
{
|
||||
if (SubscriptionConductor::viewable($subscription) === true) {
|
||||
return $this->respondAsResource(SubscriptionConductor::model($request, $subscription));
|
||||
}
|
||||
|
||||
return $this->respondForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a subscriber email in the database.
|
||||
*
|
||||
* @param \App\Http\Requests\SubscriptionRequest $request The subscriber update request.
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(SubscriptionRequest $request)
|
||||
{
|
||||
if (SubscriptionConductor::creatable() === true) {
|
||||
Subscription::create($request->all());
|
||||
dispatch((new SendEmailJob($request->email, new SubscriptionConfirm($request->email))))->onQueue('mail');
|
||||
|
||||
return $this->respondCreated();
|
||||
} else {
|
||||
return $this->respondForbidden();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\SubscriptionRequest $request The subscription update request.
|
||||
* @param \App\Models\Subscription $subscription The specified subscription.
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(SubscriptionRequest $request, Subscription $subscription)
|
||||
{
|
||||
// if (EventConductor::updatable($event) === true) {
|
||||
// $event->update($request->all());
|
||||
// return $this->respondAsResource(EventConductor::model($request, $event));
|
||||
// }
|
||||
|
||||
// return $this->respondForbidden();
|
||||
|
||||
|
||||
// $input = [];
|
||||
// $updatable = ['username', 'first_name', 'last_name', 'email', 'phone', 'password'];
|
||||
|
||||
// if ($request->user()->hasPermission('admin/user') === true) {
|
||||
// $updatable = array_merge($updatable, ['email_verified_at']);
|
||||
// } elseif ($request->user()->is($user) !== true) {
|
||||
// return $this->respondForbidden();
|
||||
// }
|
||||
|
||||
// $input = $request->only($updatable);
|
||||
// if (array_key_exists('password', $input) === true) {
|
||||
// $input['password'] = Hash::make($request->input('password'));
|
||||
// }
|
||||
|
||||
// $user->update($input);
|
||||
|
||||
// return $this->respondAsResource((new UserFilter($request))->filter($user));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the user from the database.
|
||||
*
|
||||
* @param Subscription $subscription The specified subscription.
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Subscription $subscription)
|
||||
{
|
||||
if (SubscriptionConductor::destroyable($subscription) === true) {
|
||||
$subscription->delete();
|
||||
return $this->respondNoContent();
|
||||
} else {
|
||||
return $this->respondForbidden();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the user from the database.
|
||||
*
|
||||
* @param SubscriptionRequest $request The specified subscription.
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroyByEmail(SubscriptionRequest $request)
|
||||
{
|
||||
$subscription = Subscription::where('email', $request->email)->first();
|
||||
if ($subscription !== null) {
|
||||
$subscription->delete();
|
||||
dispatch((new SendEmailJob($request->email, new SubscriptionUnsubscribed($request->email))))->onQueue('mail');
|
||||
}
|
||||
|
||||
return $this->respondNoContent();
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,10 @@ class UserController extends ApiController
|
||||
{
|
||||
if (UserConductor::creatable() === true) {
|
||||
$user = User::create($request->all());
|
||||
return $this->respondAsResource(UserConductor::model($request, $user), ['respondCode' => HttpResponseCodes::HTTP_CREATED]);
|
||||
return $this->respondAsResource(
|
||||
UserConductor::model($request, $user),
|
||||
['respondCode' => HttpResponseCodes::HTTP_CREATED]
|
||||
);
|
||||
} else {
|
||||
return $this->respondForbidden();
|
||||
}
|
||||
@@ -145,6 +148,7 @@ class UserController extends ApiController
|
||||
* Register a new user
|
||||
*
|
||||
* @param \App\Http\Requests\UserRegisterRequest $request The register user request.
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function register(UserRegisterRequest $request): JsonResponse
|
||||
{
|
||||
@@ -285,6 +289,7 @@ class UserController extends ApiController
|
||||
* Resend a new verify email
|
||||
*
|
||||
* @param \App\Http\Requests\UserResendVerifyEmailRequest $request The resend verify email request.
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function resendVerifyEmail(UserResendVerifyEmailRequest $request): JsonResponse
|
||||
{
|
||||
@@ -338,10 +343,15 @@ class UserController extends ApiController
|
||||
*
|
||||
* @param Request $request The http request.
|
||||
* @param User $user The specified user.
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function eventList(Request $request, User $user): JsonResponse
|
||||
{
|
||||
if ($request->user() !== null && ($request->user() === $user || $request->user()->hasPermission('admin/events') === true)) {
|
||||
if (
|
||||
$request->user() !== null && (
|
||||
$request->user() === $user || $request->user()->hasPermission('admin/events') === true
|
||||
)
|
||||
) {
|
||||
$collection = $user->events;
|
||||
$total = $collection->count();
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ class LogRequest
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Illuminate\Http\Request $request HTTP Request.
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next Closure.
|
||||
* @param Illuminate\Http\Request $request HTTP Request.
|
||||
* @param \Closure $next Closure.
|
||||
* @return Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
|
||||
@@ -13,9 +13,10 @@ class RedirectIfAuthenticated
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Request $request Request.
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
||||
* @param string|null ...$guards Guards.
|
||||
* @param Request $request Request.
|
||||
* @param \Closure $next Closure.
|
||||
* @param string|null ...$guards Guards.
|
||||
* @return Response
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, string ...$guards): Response
|
||||
{
|
||||
|
||||
@@ -13,9 +13,9 @@ class UnmangleRequest
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Request $request Request.
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next Next.
|
||||
* @param string|null ...$guards Guards.
|
||||
* @param Request $request Request.
|
||||
* @param \Closure $next Next.
|
||||
* @param string|null ...$guards Guards.
|
||||
* @return Response response.
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, string ...$guards): Response
|
||||
|
||||
@@ -12,7 +12,9 @@ class UseSanctumGuard
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
||||
* @param Request $request Request object.
|
||||
* @param \Closure $next Closure object.
|
||||
* @return Response
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
|
||||
@@ -9,12 +9,18 @@ class BaseRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
if (request()->isMethod('post') === true && method_exists($this, 'postAuthorize') === true) {
|
||||
return $this->postAuthorize();
|
||||
} elseif ((request()->isMethod('put') === true || request()->isMethod('patch') === true) && method_exists($this, 'putAuthorize') === true) {
|
||||
} elseif (
|
||||
(
|
||||
request()->isMethod('put') === true || request()->isMethod('patch') === true
|
||||
) && method_exists($this, 'putAuthorize') === true
|
||||
) {
|
||||
return $this->putAuthorize();
|
||||
} elseif (request()->isMethod('delete') === true && method_exists($this, 'destroyAuthorize') === true) {
|
||||
return $this->deleteAuthorize();
|
||||
@@ -38,7 +44,11 @@ class BaseRequest extends FormRequest
|
||||
|
||||
if (method_exists($this, 'postRules') === true && request()->isMethod('post') === true) {
|
||||
$rules = $this->mergeRules($rules, $this->postRules());
|
||||
} elseif (method_exists($this, 'putRules') === true && (request()->isMethod('put') === true || request()->isMethod('patch') === true)) {
|
||||
} elseif (
|
||||
method_exists($this, 'putRules') === true && (
|
||||
request()->isMethod('put') === true || request()->isMethod('patch') === true
|
||||
)
|
||||
) {
|
||||
$rules = $this->mergeRules($rules, $this->putRules());
|
||||
} elseif (method_exists($this, 'destroyRules') === true && request()->isMethod('delete') === true) {
|
||||
$rules = $this->mergeRules($rules, $this->destroyRules());
|
||||
@@ -52,6 +62,7 @@ class BaseRequest extends FormRequest
|
||||
*
|
||||
* @param array $collection1 The first collection of rules.
|
||||
* @param array $collection2 The second collection of rules to merge.
|
||||
* @return array
|
||||
*/
|
||||
private function mergeRules(array $collection1, array $collection2): array
|
||||
{
|
||||
|
||||
@@ -6,6 +6,11 @@ use Illuminate\Validation\Rule;
|
||||
|
||||
class MediaRequest extends BaseRequest
|
||||
{
|
||||
/**
|
||||
* POST request rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function postRules(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -34,6 +34,8 @@ class SubscriptionRequest extends BaseRequest
|
||||
|
||||
/**
|
||||
* Get the custom error messages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
|
||||
@@ -21,8 +21,12 @@ class UserRequest extends BaseRequest
|
||||
$isAdminUser = $user->hasPermission('admin/users');
|
||||
|
||||
return [
|
||||
'first_name' => ($isAdminUser === true ? 'required_with:last_name,display_name,phone' : 'required') . '|string|max:255|min:2',
|
||||
'last_name' => ($isAdminUser === true ? 'required_with:first_name,display_name,phone' : 'required') . '|string|max:255|min:2',
|
||||
'first_name' => (
|
||||
$isAdminUser === true ? 'required_with:last_name,display_name,phone' : 'required'
|
||||
) . '|string|max:255|min:2',
|
||||
'last_name' => (
|
||||
$isAdminUser === true ? 'required_with:first_name,display_name,phone' : 'required'
|
||||
) . '|string|max:255|min:2',
|
||||
'display_name' => [
|
||||
$isAdminUser === true ? 'required_with:first_name,last_name,phone' : 'required',
|
||||
'string',
|
||||
|
||||
@@ -107,7 +107,7 @@ class MediaWorkerJob implements ShouldQueue
|
||||
}
|
||||
|
||||
if ($storage === '') {
|
||||
if(count($security) === 0 || $security['type'] === '') {
|
||||
if (count($security) === 0 || $security['type'] === '') {
|
||||
if (strpos($data['mime_type'], 'image/') === 0) {
|
||||
$storage = 'local';
|
||||
} else {
|
||||
@@ -126,7 +126,7 @@ class MediaWorkerJob implements ShouldQueue
|
||||
}
|
||||
}
|
||||
|
||||
if($exists === true) {
|
||||
if ($exists === true) {
|
||||
$pathInfo = pathinfo($data['name']);
|
||||
$basename = $pathInfo['filename'];
|
||||
$extension = $pathInfo['extension'];
|
||||
|
||||
@@ -47,6 +47,8 @@ class SendEmailJob implements ShouldQueue
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
|
||||
@@ -54,6 +54,8 @@ class ChangeEmailVerify extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
@@ -64,6 +66,8 @@ class ChangeEmailVerify extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
|
||||
@@ -54,6 +54,8 @@ class ChangedEmail extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
@@ -64,6 +66,8 @@ class ChangedEmail extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
|
||||
@@ -36,6 +36,8 @@ class ChangedPassword extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
@@ -46,6 +48,8 @@ class ChangedPassword extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
|
||||
@@ -53,6 +53,8 @@ class Contact extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
@@ -63,6 +65,8 @@ class Contact extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
|
||||
@@ -45,6 +45,8 @@ class EmailVerify extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
@@ -55,6 +57,8 @@ class EmailVerify extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
|
||||
@@ -25,6 +25,8 @@ class ExceptionMail extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
@@ -35,6 +37,8 @@ class ExceptionMail extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
|
||||
@@ -45,6 +45,8 @@ class ForgotPassword extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
@@ -55,6 +57,8 @@ class ForgotPassword extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
|
||||
@@ -36,6 +36,8 @@ class SubscriptionConfirm extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
@@ -46,6 +48,8 @@ class SubscriptionConfirm extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
|
||||
@@ -36,6 +36,8 @@ class SubscriptionUnsubscribed extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
@@ -46,6 +48,8 @@ class SubscriptionUnsubscribed extends Mailable
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*
|
||||
* @return Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use App\Traits\Uuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class EventUser extends Model
|
||||
{
|
||||
@@ -24,6 +25,8 @@ class EventUser extends Model
|
||||
|
||||
/**
|
||||
* Get the event for this attachment.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function event(): BelongsTo
|
||||
{
|
||||
@@ -32,6 +35,8 @@ class EventUser extends Model
|
||||
|
||||
/**
|
||||
* Get the user for this attachment.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
|
||||
@@ -21,6 +21,8 @@ use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Intervention\Image\Facades\Image;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use SplFileInfo;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
@@ -155,8 +157,8 @@ class Media extends Model
|
||||
/**
|
||||
* Variants Get Mutator.
|
||||
*
|
||||
* @param mixed $value The value to mutate.
|
||||
* @param bool $raw Values are not run through urlencode.
|
||||
* @param mixed $value The value to mutate.
|
||||
* @param boolean $raw Values are not run through urlencode.
|
||||
* @return array|null The mutated value.
|
||||
*/
|
||||
public function getVariantsAttribute(mixed $value, bool $raw = false): array|null
|
||||
@@ -165,10 +167,10 @@ class Media extends Model
|
||||
$decodedValue = json_decode($value, true);
|
||||
|
||||
// Check if the decoded value is an array
|
||||
if ($raw == false && is_array($decodedValue)) {
|
||||
if ($raw === false && is_array($decodedValue) === true) {
|
||||
// Loop through the array and encode each value
|
||||
foreach ($decodedValue as &$item) {
|
||||
if (is_string($item)) {
|
||||
if (is_string($item) === true) {
|
||||
$item = rawurlencode($item);
|
||||
}
|
||||
}
|
||||
@@ -278,7 +280,10 @@ class Media extends Model
|
||||
*/
|
||||
public function deleteFile(): void
|
||||
{
|
||||
if (strlen($this->storage) > 0 && strlen($this->name) > 0 && Storage::disk($this->storage)->exists($this->name) === true) {
|
||||
if (
|
||||
strlen($this->storage) > 0 && strlen($this->name) > 0 &&
|
||||
Storage::disk($this->storage)->exists($this->name) === true
|
||||
) {
|
||||
Storage::disk($this->storage)->delete($this->name);
|
||||
}
|
||||
|
||||
@@ -322,13 +327,14 @@ class Media extends Model
|
||||
/**
|
||||
* Get URL path
|
||||
*
|
||||
* @param array $replacements Replace variables in URL.
|
||||
* @return string
|
||||
*/
|
||||
public function getUrlPath(array $replacements = []): string
|
||||
{
|
||||
$url = config("filesystems.disks.$this->storage.url");
|
||||
|
||||
if (!empty($replacements)) {
|
||||
if (empty($replacements) !== true) {
|
||||
foreach ($replacements as $key => $value) {
|
||||
$placeholder = '{' . $key . '}';
|
||||
$url = str_replace($placeholder, $value, $url);
|
||||
@@ -992,12 +998,26 @@ class Media extends Model
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function jobs(): HasMany {
|
||||
/**
|
||||
* Get the associated job models
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function jobs(): HasMany
|
||||
{
|
||||
return $this->hasMany(MediaJob::class, 'media_id');
|
||||
}
|
||||
|
||||
public static function recommendedStorage(string $mime_type, string $security_type): string {
|
||||
if($security_type === '') {
|
||||
/**
|
||||
* Get the recommended storage ID based on mime and security
|
||||
*
|
||||
* @param string $mime_type The file mime type.
|
||||
* @param string $security_type The security requested.
|
||||
* @return string
|
||||
*/
|
||||
public static function recommendedStorage(string $mime_type, string $security_type): string
|
||||
{
|
||||
if ($security_type === '') {
|
||||
if (strpos($mime_type, 'image/') === 0) {
|
||||
return('local');
|
||||
} else {
|
||||
@@ -1008,9 +1028,18 @@ class Media extends Model
|
||||
return('private');
|
||||
}
|
||||
|
||||
public static function verifyStorage($mime_type, $security_type, &$storage): int {
|
||||
if($storage === '') {
|
||||
if($security_type === '') {
|
||||
/**
|
||||
* Verify the storage exists. May change the storage value.
|
||||
*
|
||||
* @param mixed $mime_type File mime type.
|
||||
* @param mixed $security_type Requested security type.
|
||||
* @param mixed $storage Reference to the requested storage type.
|
||||
* @return integer Error code.
|
||||
*/
|
||||
public static function verifyStorage(mixed $mime_type, mixed $security_type, mixed &$storage): int
|
||||
{
|
||||
if ($storage === '') {
|
||||
if ($security_type === '') {
|
||||
if (strpos($mime_type, 'image/') === 0) {
|
||||
$storage = 'local';
|
||||
} else {
|
||||
@@ -1021,11 +1050,11 @@ class Media extends Model
|
||||
}
|
||||
} else {
|
||||
$disks = config('filesystems.disks');
|
||||
if(array_key_exists($storage, $disks) === false) {
|
||||
if (array_key_exists($storage, $disks) === false) {
|
||||
return Media::STORAGE_NOT_FOUND;
|
||||
}
|
||||
|
||||
if($security_type !== '' && strcasecmp($storage, 'private') !== 0) {
|
||||
if ($security_type !== '' && strcasecmp($storage, 'private') !== 0) {
|
||||
return Media::STORAGE_INVALID_SECURITY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,9 +102,9 @@ class MediaJob extends Model
|
||||
/**
|
||||
* Set MediaJob status details.
|
||||
*
|
||||
* @param string $status The status string.
|
||||
* @param string $text The status text.
|
||||
* @param integer $progress The status progress value.
|
||||
* @param string $status The status string.
|
||||
* @param string $text The status text.
|
||||
* @param integer $progress The status progress value.
|
||||
* @param integer $progress_max The status progress maximum value.
|
||||
* @return void
|
||||
*/
|
||||
@@ -180,12 +180,14 @@ class MediaJob extends Model
|
||||
$data['size'] = filesize($newFile);
|
||||
$data['mime_type'] = $mime;
|
||||
|
||||
if(array_key_exists('storage', $data) === true &&
|
||||
array_key_exists('security_type', $data) === true &&
|
||||
array_key_exists('mime_type', $data) === true &&
|
||||
$data['mime_type'] !== "") {
|
||||
if (
|
||||
array_key_exists('storage', $data) === true &&
|
||||
array_key_exists('security_type', $data) === true &&
|
||||
array_key_exists('mime_type', $data) === true &&
|
||||
$data['mime_type'] !== ""
|
||||
) {
|
||||
$error = Media::verifyStorage($data['mime_type'], $data['security_type'], $data['storage']);
|
||||
switch($error) {
|
||||
switch ($error) {
|
||||
case Media::STORAGE_VALID:
|
||||
break;
|
||||
case Media::STORAGE_MIME_MISSING:
|
||||
@@ -206,7 +208,7 @@ class MediaJob extends Model
|
||||
$this->data = json_encode($data);
|
||||
$this->setStatusQueued();
|
||||
MediaWorkerJob::dispatch($this)->onQueue('media');
|
||||
}
|
||||
}//end if
|
||||
}//end if
|
||||
} else {
|
||||
$this->setStatusQueued();
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use App\Traits\Uuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Permission extends Model
|
||||
{
|
||||
@@ -24,6 +25,8 @@ class Permission extends Model
|
||||
|
||||
/**
|
||||
* Get the User associated with this model
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use App\Traits\Uuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserLogins extends Model
|
||||
{
|
||||
@@ -28,6 +29,8 @@ class UserLogins extends Model
|
||||
|
||||
/**
|
||||
* Get the file user
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
|
||||
@@ -19,6 +19,8 @@ class AuthServiceProvider extends ServiceProvider
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
|
||||
@@ -9,6 +9,8 @@ class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
|
||||
@@ -26,6 +26,8 @@ class EventServiceProvider extends ServiceProvider
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
@@ -34,6 +36,8 @@ class EventServiceProvider extends ServiceProvider
|
||||
|
||||
/**
|
||||
* Determine if events and listeners should be automatically discovered.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function shouldDiscoverEvents(): bool
|
||||
{
|
||||
|
||||
@@ -23,6 +23,8 @@ class RouteServiceProvider extends ServiceProvider
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, and other route configuration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
@@ -31,9 +33,10 @@ class RouteServiceProvider extends ServiceProvider
|
||||
// });
|
||||
|
||||
$rateLimitEnabled = true;
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
|
||||
if (app()->environment('testing')) {
|
||||
if (app()->environment('testing') === true) {
|
||||
$rateLimitEnabled = false;
|
||||
} elseif ($user !== null && $user->hasPermission('admin/ratelimit') === true) {
|
||||
// Admin users with the "admin/ratelimit" permission are not rate limited
|
||||
@@ -42,7 +45,7 @@ class RouteServiceProvider extends ServiceProvider
|
||||
|
||||
if ($rateLimitEnabled === true) {
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(800)->by($request->user()?->id ?: $request->ip());
|
||||
return Limit::perMinute(800)->by(isset($request->user()->id) === true ?: $request->ip());
|
||||
});
|
||||
} else {
|
||||
RateLimiter::for('api', function () {
|
||||
|
||||
@@ -22,6 +22,7 @@ class Recaptcha implements Rule
|
||||
*
|
||||
* @param mixed $attribute Attribute name.
|
||||
* @param mixed $value Attribute value.
|
||||
* @return boolean
|
||||
*/
|
||||
public function passes(mixed $attribute, mixed $value): bool
|
||||
{
|
||||
@@ -41,6 +42,8 @@ class Recaptcha implements Rule
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message(): string
|
||||
{
|
||||
|
||||
@@ -20,15 +20,19 @@ class UniqueFileName implements Rule
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param mixed $attribute Attribute name.
|
||||
* @param mixed $value Attribute value.
|
||||
* @return boolean
|
||||
*/
|
||||
public function passes(string $attribute, $value): bool
|
||||
public function passes(mixed $attribute, mixed $value): bool
|
||||
{
|
||||
return (Media::fileExists($value) === false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message(): string
|
||||
{
|
||||
|
||||
@@ -47,6 +47,7 @@ class Uniqueish implements Rule
|
||||
* Set the ID of the record to be ignored.
|
||||
*
|
||||
* @param mixed $id The ID to ignore.
|
||||
* @return App\Rules\Uniqueish
|
||||
*/
|
||||
public function ignore(mixed $id): static
|
||||
{
|
||||
@@ -59,6 +60,7 @@ class Uniqueish implements Rule
|
||||
*
|
||||
* @param mixed $attribute Not used.
|
||||
* @param mixed $value The value to compare.
|
||||
* @return boolean
|
||||
*/
|
||||
public function passes(mixed $attribute, mixed $value): bool
|
||||
{
|
||||
@@ -83,7 +85,7 @@ class Uniqueish implements Rule
|
||||
|
||||
foreach ($results as $result) {
|
||||
$resultValue = preg_replace('/[^A-Za-z0-9]/', '', strtolower($result->{$columnName}));
|
||||
if ($resultValue === $similarValue && $result->id != $this->ignoreId) {
|
||||
if ($resultValue === $similarValue && $result->id !== $this->ignoreId) {
|
||||
return false; // Value already exists in the table
|
||||
}
|
||||
}
|
||||
@@ -95,6 +97,8 @@ class Uniqueish implements Rule
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message(): string
|
||||
{
|
||||
|
||||
@@ -64,6 +64,11 @@ trait HasGallery
|
||||
return $this->morphMany(\App\Models\Gallery::class, 'addendum');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the article's gallery collection.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Collection The gallery collection
|
||||
*/
|
||||
public function getGallery(): Collection
|
||||
{
|
||||
return Cache::remember($this->galleryCacheKey(), now()->addDays(28), function () {
|
||||
|
||||
@@ -8,6 +8,8 @@ trait Uuids
|
||||
{
|
||||
/**
|
||||
* Boot function from Laravel.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function bootUuids(): void
|
||||
{
|
||||
@@ -20,6 +22,8 @@ trait Uuids
|
||||
|
||||
/**
|
||||
* Get the value indicating whether the IDs are incrementing.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getIncrementing(): bool
|
||||
{
|
||||
@@ -28,6 +32,8 @@ trait Uuids
|
||||
|
||||
/**
|
||||
* Get the auto-incrementing key type.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getKeyType(): string
|
||||
{
|
||||
|
||||
@@ -36,7 +36,7 @@ return [
|
||||
'secret' => env('PUSHER_APP_SECRET'),
|
||||
'app_id' => env('PUSHER_APP_ID'),
|
||||
'options' => [
|
||||
'host' => env('PUSHER_HOST') ?: 'api-' . env('PUSHER_APP_CLUSTER', 'mt1') . '.pusher.com',
|
||||
'host' => env('PUSHER_HOST') === null ?: 'api-' . env('PUSHER_APP_CLUSTER', 'mt1') . '.pusher.com',
|
||||
'port' => env('PUSHER_PORT', 443),
|
||||
'scheme' => env('PUSHER_SCHEME', 'https'),
|
||||
'encrypted' => true,
|
||||
|
||||
@@ -34,7 +34,8 @@ return [
|
||||
|--------------------------------------------------------------------------
|
||||
| Socket connect timeout
|
||||
|--------------------------------------------------------------------------
|
||||
| This option defines the maximum time to wait in seconds for socket connection attempts before failure or timeout, default null = no limit.
|
||||
| This option defines the maximum time to wait in seconds for socket connection attempts before failure or timeout,
|
||||
| default null = no limit.
|
||||
*/
|
||||
'socket_connect_timeout' => env('CLAMAV_SOCKET_CONNECT_TIMEOUT', null),
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ return [
|
||||
'prefix_indexes' => true,
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
'options' => extension_loaded('pdo_mysql') === true ? array_filter([
|
||||
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
|
||||
@@ -9,6 +9,8 @@ trait CreatesApplication
|
||||
{
|
||||
/**
|
||||
* Creates the application.
|
||||
*
|
||||
* @return \Illuminate\Foundation\Application
|
||||
*/
|
||||
public function createApplication(): Application
|
||||
{
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
use App\Models\User;
|
||||
@@ -11,15 +13,29 @@ final class ArticlesApiTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Faker Factory instance.
|
||||
* @var Faker\Factory
|
||||
*/
|
||||
protected $faker;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->faker = FakerFactory::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that any user can view an article if it's published and not in the future.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAnyUserCanViewArticle(): void
|
||||
{
|
||||
// Create an event
|
||||
@@ -51,6 +67,11 @@ final class ArticlesApiTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that an admin can create, update, and delete articles.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAdminCanCreateUpdateDeleteArticle(): void
|
||||
{
|
||||
// Create a user with the admin/events permission
|
||||
@@ -102,6 +123,11 @@ final class ArticlesApiTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a non-admin user cannot create, update, or delete articles.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNonAdminCannotCreateUpdateDeleteArticle(): void
|
||||
{
|
||||
// Create a user without admin/events permission
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
use App\Models\User;
|
||||
@@ -9,6 +11,20 @@ final class AuthApiTest extends TestCase
|
||||
use RefreshDatabase;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the login, user retrieval, and logout functionality of the Auth API.
|
||||
*
|
||||
* This test performs the following steps:
|
||||
* 1. Creates a new user using a factory.
|
||||
* 2. Attempts a successful login with the correct credentials,
|
||||
* checks for a 200 status code, and verifies the structure of the returned token.
|
||||
* 3. Retrieves the authenticated user's data using the token,
|
||||
* checks for a 200 status code, and verifies the returned user data.
|
||||
* 4. Logs out the authenticated user using the token and checks for a 204 status code.
|
||||
* 5. Attempts a failed login with incorrect credentials and checks for a 422 status code.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLogin(): void
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -8,6 +10,17 @@ final class ContactFormTest extends TestCase
|
||||
use RefreshDatabase;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the contact form submission API endpoint.
|
||||
*
|
||||
* This test performs two POST requests to the '/api/contact' endpoint
|
||||
* using the `postJson` method. The first request contains valid data and
|
||||
* should return a 201 status code, indicating a successful creation.
|
||||
* The second request omits the 'email' field, which should cause a
|
||||
* validation error and return a 422 status code.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testContactForm(): void
|
||||
{
|
||||
$formData = [
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
use App\Models\User;
|
||||
@@ -12,15 +14,29 @@ final class EventsApiTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Faker Factory instance.
|
||||
* @var Faker\Factory
|
||||
*/
|
||||
protected $faker;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->faker = FakerFactory::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that any user can view an event if it's published and not in the future.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAnyUserCanViewEvent(): void
|
||||
{
|
||||
// Create an event
|
||||
@@ -52,6 +68,11 @@ final class EventsApiTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that any user cannot see draft events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAnyUserCannotSeeDraftEvent(): void
|
||||
{
|
||||
// Create a draft event
|
||||
@@ -85,6 +106,11 @@ final class EventsApiTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that an admin can create, update, and delete events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAdminCanCreateUpdateDeleteEvent(): void
|
||||
{
|
||||
// Create a user with the admin/events permission
|
||||
@@ -139,6 +165,11 @@ final class EventsApiTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a non-admin user cannot create, update, or delete events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNonAdminCannotCreateUpdateDeleteEvent(): void
|
||||
{
|
||||
// Create a user without admin/events permission
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
@@ -10,6 +12,11 @@ final class UsersApiTest extends TestCase
|
||||
use RefreshDatabase;
|
||||
|
||||
|
||||
/**
|
||||
* Tests that non-admin users can only view basic user info.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNonAdminUsersCanOnlyViewBasicUserInfo(): void
|
||||
{
|
||||
// create a non-admin user
|
||||
@@ -67,6 +74,11 @@ final class UsersApiTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that guests cannot create a user via the API.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGuestCannotCreateUser(): void
|
||||
{
|
||||
$userData = [
|
||||
@@ -81,6 +93,11 @@ final class UsersApiTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that guests can register a user via the API.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGuestCanRegisterUser(): void
|
||||
{
|
||||
$userData = [
|
||||
@@ -98,6 +115,11 @@ final class UsersApiTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that duplicate email or display name entries cannot be created.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCannotCreateDuplicateEmailOrDisplayName(): void
|
||||
{
|
||||
$userData = [
|
||||
@@ -121,6 +143,11 @@ final class UsersApiTest extends TestCase
|
||||
$response->assertJsonValidationErrors(['display_name', 'email']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a user can only update their own user info.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUserCanOnlyUpdateOwnUser(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
@@ -149,6 +176,11 @@ final class UsersApiTest extends TestCase
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a user cannot delete users via the API.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUserCannotDeleteUsers(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
@@ -165,6 +197,11 @@ final class UsersApiTest extends TestCase
|
||||
$this->assertDatabaseHas('users', ['id' => $otherUser->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that an admin can update any user's info.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAdminCanUpdateAnyUser(): void
|
||||
{
|
||||
$admin = User::factory()->create();
|
||||
@@ -200,6 +237,11 @@ final class UsersApiTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that an admin can delete any user via the API.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAdminCanDeleteAnyUser(): void
|
||||
{
|
||||
$admin = User::factory()->create();
|
||||
|
||||
@@ -9,6 +9,11 @@ abstract class TestCase extends BaseTestCase
|
||||
use CreatesApplication;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
@@ -8,6 +8,8 @@ final class ExampleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_that_true_is_true(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user