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