Add demo mode restrictions to user operations.

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.
This commit is contained in:
2023-12-05 00:53:04 +06:00
parent ebc2dfd944
commit b5db913c24
10 changed files with 67 additions and 5 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Helpers;
use App\Models\User;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Collection;
@@ -21,4 +22,18 @@ final readonly class Helpers
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');
}
}