-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dump sqlite schema; move permissions to seeder
- Loading branch information
1 parent
bf44ec8
commit dfeb90d
Showing
15 changed files
with
382 additions
and
119 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
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
53 changes: 1 addition & 52 deletions
53
database/migrations/2023_11_21_000002_add_default_permissions.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 |
---|---|---|
@@ -1,61 +1,10 @@ | ||
<?php | ||
|
||
use App\Models\User; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Spatie\Permission\Models\Permission; | ||
use Spatie\Permission\Models\Role; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up(): void { | ||
$roleAdmin = Role::create(['name' => 'admin']); | ||
$roleEventModerator = Role::create(['name' => 'event-moderator']); //for accepting/denying events | ||
Role::create(['name' => 'open-beta']); //for experimental features that can be enabled by users | ||
Role::create(['name' => 'closed-beta']); //for experimental features that can be only enabled by admins for specific users | ||
|
||
$permissionViewBackend = Permission::create(['name' => 'view-backend']); | ||
|
||
$permissionViewEvents = Permission::create(['name' => 'view-events']); | ||
$permissionAcceptEvents = Permission::create(['name' => 'accept-events']); | ||
$permissionDenyEvents = Permission::create(['name' => 'deny-events']); | ||
$permissionCreateEvents = Permission::create(['name' => 'create-events']); | ||
$permissionUpdateEvents = Permission::create(['name' => 'update-events']); | ||
$permissionDeleteEvents = Permission::create(['name' => 'delete-events']); | ||
|
||
$roleAdmin->givePermissionTo($permissionViewBackend); | ||
$roleAdmin->givePermissionTo($permissionViewEvents); | ||
$roleAdmin->givePermissionTo($permissionAcceptEvents); | ||
$roleAdmin->givePermissionTo($permissionDenyEvents); | ||
$roleAdmin->givePermissionTo($permissionCreateEvents); | ||
$roleAdmin->givePermissionTo($permissionUpdateEvents); | ||
$roleAdmin->givePermissionTo($permissionDeleteEvents); | ||
|
||
$roleEventModerator->givePermissionTo($permissionViewBackend); | ||
$roleEventModerator->givePermissionTo($permissionViewEvents); | ||
$roleEventModerator->givePermissionTo($permissionAcceptEvents); | ||
$roleEventModerator->givePermissionTo($permissionDenyEvents); | ||
$roleEventModerator->givePermissionTo($permissionUpdateEvents); | ||
|
||
$oldAdmins = User::where('role', 10)->get(); | ||
foreach ($oldAdmins as $oldAdmin) { | ||
$oldAdmin->assignRole('admin'); | ||
} | ||
|
||
$experimentalUsers = User::where('experimental', true)->get(); | ||
foreach ($experimentalUsers as $experimentalUser) { | ||
$experimentalUser->assignRole('open-beta'); | ||
} | ||
} | ||
|
||
public function down(): void { | ||
$admins = User::role('admin')->get(); | ||
foreach ($admins as $admin) { | ||
$admin->update(['role' => 10]); | ||
} | ||
|
||
Role::where('name', 'admin')->delete(); | ||
Role::where('name', 'event-moderator')->delete(); | ||
Role::where('name', 'open-beta')->delete(); | ||
Role::where('name', 'closed-beta')->delete(); | ||
// empty now - replaced by PermissionSeeder | ||
} | ||
}; |
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
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
16 changes: 1 addition & 15 deletions
16
database/migrations/2024_02_01_000000_add_permissions_for_manual_trips_beta.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 |
---|---|---|
@@ -1,25 +1,11 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Spatie\Permission\Models\Permission; | ||
use Spatie\Permission\Models\Role; | ||
|
||
return new class extends Migration | ||
{ | ||
|
||
public function up(): void { | ||
$permission = Permission::create(['name' => 'create-manual-trip']); | ||
|
||
Role::findByName('admin')->givePermissionTo($permission); | ||
Role::findByName('closed-beta')->givePermissionTo($permission); | ||
} | ||
|
||
public function down(): void { | ||
$permission = Permission::findByName('create-manual-trip'); | ||
|
||
Role::findByName('admin')->revokePermissionTo($permission); | ||
Role::findByName('closed-beta')->revokePermissionTo($permission); | ||
|
||
$permission->delete(); | ||
// empty now - replaced by PermissionSeeder | ||
} | ||
}; |
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.