Leonid Nikitin
b5db913c24
Added functionalities to restrict certain user operations like update, password change, and deletion in demo mode. This is done to prevent demo users from modifying crucial data. Helper methods are created for standard re-usable checks. Also, Blade directive is added for frontend UI demo checks.
40 lines
1.0 KiB
PHP
40 lines
1.0 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\Helpers;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Collection;
|
|
|
|
final readonly class Helpers
|
|
{
|
|
public static function getTimeZoneList(): Collection
|
|
{
|
|
return Cache::rememberForever('timezones_list_collection', function () {
|
|
$timezone = [];
|
|
foreach (timezone_identifiers_list(\DateTimeZone::ALL) as $key => $value) {
|
|
$timezone[$value] = $value . ' (UTC ' . now($value)->format('P') . ')';
|
|
}
|
|
return collect($timezone)->sortKeys();
|
|
});
|
|
}
|
|
|
|
public static function getUserTimeZone() {
|
|
return auth()->user()?->timezone ?? config('app.user_timezone');
|
|
}
|
|
|
|
public static function isDemoMode(): bool
|
|
{
|
|
return config('app.demo_mode', false);
|
|
}
|
|
|
|
public static function isDemoModeAndUserDenyUpdate(User $user): bool
|
|
{
|
|
if (self::isDemoMode() !== true) {
|
|
return false;
|
|
}
|
|
|
|
return $user->email === config('app.demo_email');
|
|
}
|
|
}
|