Skip to content

Demo Mode #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/cachet.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,16 @@
'zh_TW' => '繁體中文',
'ph' => 'Filipino',
],

/*
|--------------------------------------------------------------------------
| Cachet Demo Mode
|--------------------------------------------------------------------------
|
| Whether to run Cachet in demo mode. This will adjust some of the default
| settings to allow Cachet to run in a demo environment.
|
*/
'demo_mode' => env('CACHET_DEMO_MODE', false),

];
16 changes: 16 additions & 0 deletions routes/console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use Cachet\Cachet;
use Cachet\Database\Seeders\DatabaseSeeder;
use Illuminate\Support\Facades\Schedule;

$demoMode = fn () => Cachet::demoMode();

// Allows Cachet to be hosted in limited deployment environments,
// where we're unable to create custom scheduled jobs.
Schedule::command('db:seed', [
'--class' => DatabaseSeeder::class,
'--force' => true,
])
->everyThirtyMinutes()
->when($demoMode);
8 changes: 8 additions & 0 deletions src/Cachet.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,12 @@ public static function getResourceApiAbilities(): array
'schedule-updates' => ['manage', 'delete'],
];
}

/**
* Determine if Cachet is running in demo mode.
*/
public static function demoMode(): bool
{
return (bool) config('cachet.demo_mode');
}
}
2 changes: 2 additions & 0 deletions src/CachetCoreServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ private function registerBladeComponents(): void
private function registerCommands(): void
{
if ($this->app->runningInConsole()) {
$this->loadRoutesFrom(__DIR__.'/../routes/console.php');

$this->commands([
Commands\MakeUserCommand::class,
Commands\SendBeaconCommand::class,
Expand Down
6 changes: 6 additions & 0 deletions src/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Hash;

class UserResource extends Resource
Expand All @@ -22,6 +23,11 @@ public static function canAccess(): bool
return auth()->user()->isAdmin();
}

public static function canEdit(Model $record): bool
{
return ! Cachet::demoMode() && (auth()->user()->is($record) || auth()->user()->isAdmin());
}

public static function form(Form $form): Form
{
return $form
Expand Down
21 changes: 21 additions & 0 deletions tests/Unit/Commands/ConsoleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Cachet\Database\Seeders\DatabaseSeeder;
use Illuminate\Console\Scheduling\Schedule;

it('registers a scheduled job', function () {
// Resolve the schedule instance from the application container
$schedule = app(Schedule::class);

$events = collect($schedule->events())->keyBy('command')->keys()->all();

// Build the expected scheduled command
$scheduledCommand = sprintf("'%s' 'artisan' db:seed --class='%s' --force='1'",
PHP_BINARY,
DatabaseSeeder::class,
);

expect($events)
->toContain($scheduledCommand);
});

Loading