-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into 1723-Expenses
- Loading branch information
Showing
61 changed files
with
1,588 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Console\Cron\Backups; | ||
|
||
use App\Contracts\CronCommand; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class BackupClean extends CronCommand | ||
{ | ||
protected $signature = 'cron:backup-clean'; | ||
protected $description = 'Clean up old backups'; | ||
|
||
public function handle(): void | ||
{ | ||
$this->callEvent(); | ||
} | ||
|
||
public function callEvent(): void | ||
{ | ||
Artisan::call('backup:clean'); | ||
|
||
$output = trim(Artisan::output()); | ||
if (!empty($output)) { | ||
Log::info($output); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Console\Cron\Backups; | ||
|
||
use App\Contracts\CronCommand; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class BackupMonitor extends CronCommand | ||
{ | ||
protected $signature = 'cron:backup-monitor'; | ||
protected $description = 'Monitor backups health'; | ||
|
||
public function handle(): void | ||
{ | ||
$this->callEvent(); | ||
} | ||
|
||
public function callEvent(): void | ||
{ | ||
Artisan::call('backup:monitor'); | ||
|
||
$output = trim(Artisan::output()); | ||
if (!empty($output)) { | ||
Log::info($output); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Console\Cron\Backups; | ||
|
||
use App\Contracts\CronCommand; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class BackupRun extends CronCommand | ||
{ | ||
protected $signature = 'cron:backup-run'; | ||
protected $description = 'Create a new backup'; | ||
|
||
public function handle(): void | ||
{ | ||
$this->callEvent(); | ||
} | ||
|
||
public function callEvent(): void | ||
{ | ||
Artisan::call('backup:run'); | ||
|
||
$output = trim(Artisan::output()); | ||
if (!empty($output)) { | ||
Log::info($output); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Cron\Hourly; | ||
|
||
use App\Contracts\Listener; | ||
use App\Events\CronHourly; | ||
use App\Models\Invite; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
/** | ||
* Clear any expired invites | ||
*/ | ||
class ClearExpiredInvites extends Listener | ||
{ | ||
/** | ||
* @param CronHourly $event | ||
*/ | ||
public function handle(CronHourly $event): void | ||
{ | ||
Log::info('Hourly: Removing expired invites'); | ||
$invites = Invite::all(); | ||
|
||
foreach ($invites as $invite) { | ||
if ($invite->expires_at && $invite->expires_at->isPast()) { | ||
$invite->delete(); | ||
} | ||
|
||
if ($invite->usage_limit && $invite->usage_count >= $invite->usage_limit) { | ||
$invite->delete(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/Database/migrations/2023_12_15_154815_create_user_oauth_tokens_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class() extends Migration { | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('user_oauth_tokens', function (Blueprint $table) { | ||
$table->id(); | ||
$table->unsignedInteger('user_id'); | ||
$table->string('provider'); | ||
$table->string('token'); | ||
$table->string('refresh_token'); | ||
$table->dateTime('last_refreshed_at')->nullable(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('user_oauth_tokens'); | ||
} | ||
}; |
26 changes: 26 additions & 0 deletions
26
app/Database/migrations/2023_12_24_091030_drop_user_oauth_tokens_foreign_keys.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class() extends Migration { | ||
public function up(): void | ||
{ | ||
Schema::table('user_oauth_tokens', function (Blueprint $table) { | ||
$foreignKeys = Schema::getForeignKeys('user_oauth_tokens'); | ||
|
||
foreach ($foreignKeys as $foreignKey) { | ||
if (in_array('user_id', $foreignKey['columns'], true)) { | ||
$table->dropForeign(['user_id']); | ||
break; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
// | ||
} | ||
}; |
25 changes: 25 additions & 0 deletions
25
app/Database/migrations/2023_12_27_112456_create_invites_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class() extends Migration { | ||
public function up(): void | ||
{ | ||
Schema::create('invites', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('email')->nullable(); | ||
$table->string('token'); | ||
$table->integer('usage_count')->default(0); | ||
$table->integer('usage_limit')->nullable(); | ||
$table->dateTime('expires_at')->nullable(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::dropIfExists('invites'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\Contracts\Controller; | ||
use App\Http\Requests\CreateInviteRequest; | ||
use App\Models\Invite; | ||
use App\Notifications\Messages\InviteLink; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Support\Facades\Notification; | ||
use Illuminate\View\View; | ||
use Laracasts\Flash\Flash; | ||
|
||
class InviteController extends Controller | ||
{ | ||
public function index(): RedirectResponse|View | ||
{ | ||
if (!setting('general.invite_only_registrations', false)) { | ||
Flash::error('Registration is not on invite only'); | ||
return redirect(route('admin.users.index')); | ||
} | ||
|
||
$invites = Invite::all(); | ||
|
||
return view('admin.invites.index', [ | ||
'invites' => $invites, | ||
]); | ||
} | ||
|
||
public function create(): RedirectResponse|View | ||
{ | ||
if (!setting('general.invite_only_registrations', false)) { | ||
Flash::error('Registration is not on invite only'); | ||
return redirect(route('admin.users.index')); | ||
} | ||
|
||
return view('admin.invites.create'); | ||
} | ||
|
||
public function store(CreateInviteRequest $request): RedirectResponse | ||
{ | ||
if (!setting('general.invite_only_registrations', false)) { | ||
Flash::error('Registration is not on invite only'); | ||
return redirect(route('admin.users.index')); | ||
} | ||
|
||
$invite = Invite::create([ | ||
'email' => $request->get('email'), | ||
'token' => sha1(hrtime(true).str_random()), | ||
'usage_count' => 0, | ||
'usage_limit' => !is_null($request->get('email')) ? 1 : $request->get('usage_limit'), | ||
'expires_at' => $request->get('expires_at'), | ||
]); | ||
|
||
if (!is_null($request->get('email')) && get_truth_state($request->get('email_link'))) { | ||
Notification::route('mail', $request->get('email')) | ||
->notify(new InviteLink($invite)); | ||
} | ||
|
||
Flash::success('Invite created successfully. The link is: '.$invite->link); | ||
|
||
return redirect(route('admin.invites.index')); | ||
} | ||
|
||
public function destroy(int $id): RedirectResponse | ||
{ | ||
if (!setting('general.invite_only_registrations', false)) { | ||
Flash::error('Registration is not on invite only'); | ||
return redirect(route('admin.users.index')); | ||
} | ||
|
||
$invite = Invite::find($id); | ||
|
||
if (!$invite) { | ||
Flash::error('Invite not found'); | ||
return redirect(route('admin.invites.index')); | ||
} | ||
|
||
$invite->delete(); | ||
|
||
Flash::success('Invite deleted successfully'); | ||
return redirect(route('admin.invites.index')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.