Skip to content

Commit 4465485

Browse files
committed
1 parent cf58b20 commit 4465485

File tree

2 files changed

+63
-40
lines changed

2 files changed

+63
-40
lines changed

config/permission.php

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,43 +98,68 @@
9898

9999
/*
100100
* When set to true, the method for checking permissions will be registered on the gate.
101-
* Set this to false, if you want to implement custom logic for checking permissions.
101+
* Set this to false if you want to implement custom logic for checking permissions.
102102
*/
103103

104104
'register_permission_check_method' => true,
105105

106106
/*
107-
* When set to true the package implements teams using the 'team_foreign_key'. If you want
108-
* the migrations to register the 'team_foreign_key', you must set this to true
109-
* before doing the migration. If you already did the migration then you must make a new
110-
* migration to also add 'team_foreign_key' to 'roles', 'model_has_roles', and
111-
* 'model_has_permissions'(view the latest version of package's migration file)
107+
* When set to true, Laravel\Octane\Events\OperationTerminated event listener will be registered
108+
* this will refresh permissions on every TickTerminated, TaskTerminated and RequestTerminated
109+
* NOTE: This should not be needed in most cases, but an Octane/Vapor combination benefited from it.
110+
*/
111+
'register_octane_reset_listener' => false,
112+
113+
/*
114+
* Teams Feature.
115+
* When set to true the package implements teams using the 'team_foreign_key'.
116+
* If you want the migrations to register the 'team_foreign_key', you must
117+
* set this to true before doing the migration.
118+
* If you already did the migration then you must make a new migration to also
119+
* add 'team_foreign_key' to 'roles', 'model_has_roles', and 'model_has_permissions'
120+
* (view the latest version of this package's migration file)
112121
*/
113122

114123
'teams' => false,
115124

116125
/*
117-
* When set to true, the required permission names are added to the exception
118-
* message. This could be considered an information leak in some contexts, so
119-
* the default setting is false here for optimum safety.
126+
* Passport Client Credentials Grant
127+
* When set to true the package will use Passports Client to check permissions
128+
*/
129+
130+
'use_passport_client_credentials' => false,
131+
132+
/*
133+
* When set to true, the required permission names are added to exception messages.
134+
* This could be considered an information leak in some contexts, so the default
135+
* setting is false here for optimum safety.
120136
*/
121137

122138
'display_permission_in_exception' => false,
123139

124140
/*
125-
* When set to true, the required role names are added to the exception
126-
* message. This could be considered an information leak in some contexts, so
127-
* the default setting is false here for optimum safety.
141+
* When set to true, the required role names are added to exception messages.
142+
* This could be considered an information leak in some contexts, so the default
143+
* setting is false here for optimum safety.
128144
*/
129145

130146
'display_role_in_exception' => false,
131147

132148
/*
133149
* By default wildcard permission lookups are disabled.
150+
* See documentation to understand supported syntax.
134151
*/
135152

136153
'enable_wildcard_permission' => false,
137154

155+
/*
156+
* The class to use for interpreting wildcard permissions.
157+
* If you need to modify delimiters, override the class and specify its name here.
158+
*/
159+
// 'permission.wildcard_permission' => Spatie\Permission\WildcardPermission::class,
160+
161+
/* Cache-specific settings */
162+
138163
'cache' => [
139164

140165
/*

database/migrations/2022_07_11_225131_create_permission_tables.php renamed to database/migrations/2024_03_19_114651_create_permission_tables.php

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
<?php
22

3-
use Illuminate\Database\Migrations\Migration;
4-
use Illuminate\Database\Schema\Blueprint;
53
use Illuminate\Support\Facades\Schema;
6-
use Spatie\Permission\PermissionRegistrar;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
76

8-
class CreatePermissionTables extends Migration
7+
return new class extends Migration
98
{
109
/**
1110
* Run the migrations.
12-
*
13-
* @return void
1411
*/
15-
public function up()
12+
public function up(): void
1613
{
14+
$teams = config('permission.teams');
1715
$tableNames = config('permission.table_names');
1816
$columnNames = config('permission.column_names');
19-
$teams = config('permission.teams');
17+
$pivotRole = $columnNames['role_pivot_key'] ?? 'role_id';
18+
$pivotPermission = $columnNames['permission_pivot_key'] ?? 'permission_id';
2019

2120
if (empty($tableNames)) {
2221
throw new \Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
@@ -50,67 +49,68 @@ public function up()
5049
}
5150
});
5251

53-
Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames, $teams) {
54-
$table->unsignedBigInteger(PermissionRegistrar::$pivotPermission);
52+
Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) {
53+
$table->unsignedBigInteger($pivotPermission);
5554

5655
$table->string('model_type');
5756
$table->unsignedBigInteger($columnNames['model_morph_key']);
5857
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index');
5958

60-
$table->foreign(PermissionRegistrar::$pivotPermission)
59+
$table->foreign($pivotPermission)
6160
->references('id') // permission id
6261
->on($tableNames['permissions'])
6362
->onDelete('cascade');
6463
if ($teams) {
6564
$table->unsignedBigInteger($columnNames['team_foreign_key']);
6665
$table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index');
6766

68-
$table->primary([$columnNames['team_foreign_key'], PermissionRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
67+
$table->primary([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'],
6968
'model_has_permissions_permission_model_type_primary');
7069
} else {
71-
$table->primary([PermissionRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
70+
$table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
7271
'model_has_permissions_permission_model_type_primary');
7372
}
73+
7474
});
7575

76-
Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames, $teams) {
77-
$table->unsignedBigInteger(PermissionRegistrar::$pivotRole);
76+
Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) {
77+
$table->unsignedBigInteger($pivotRole);
7878

7979
$table->string('model_type');
8080
$table->unsignedBigInteger($columnNames['model_morph_key']);
8181
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index');
8282

83-
$table->foreign(PermissionRegistrar::$pivotRole)
83+
$table->foreign($pivotRole)
8484
->references('id') // role id
8585
->on($tableNames['roles'])
8686
->onDelete('cascade');
8787
if ($teams) {
8888
$table->unsignedBigInteger($columnNames['team_foreign_key']);
8989
$table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index');
9090

91-
$table->primary([$columnNames['team_foreign_key'], PermissionRegistrar::$pivotRole, $columnNames['model_morph_key'], 'model_type'],
91+
$table->primary([$columnNames['team_foreign_key'], $pivotRole, $columnNames['model_morph_key'], 'model_type'],
9292
'model_has_roles_role_model_type_primary');
9393
} else {
94-
$table->primary([PermissionRegistrar::$pivotRole, $columnNames['model_morph_key'], 'model_type'],
94+
$table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type'],
9595
'model_has_roles_role_model_type_primary');
9696
}
9797
});
9898

99-
Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) {
100-
$table->unsignedBigInteger(PermissionRegistrar::$pivotPermission);
101-
$table->unsignedBigInteger(PermissionRegistrar::$pivotRole);
99+
Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) {
100+
$table->unsignedBigInteger($pivotPermission);
101+
$table->unsignedBigInteger($pivotRole);
102102

103-
$table->foreign(PermissionRegistrar::$pivotPermission)
103+
$table->foreign($pivotPermission)
104104
->references('id') // permission id
105105
->on($tableNames['permissions'])
106106
->onDelete('cascade');
107107

108-
$table->foreign(PermissionRegistrar::$pivotRole)
108+
$table->foreign($pivotRole)
109109
->references('id') // role id
110110
->on($tableNames['roles'])
111111
->onDelete('cascade');
112112

113-
$table->primary([PermissionRegistrar::$pivotPermission, PermissionRegistrar::$pivotRole], 'role_has_permissions_permission_id_role_id_primary');
113+
$table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary');
114114
});
115115

116116
app('cache')
@@ -120,10 +120,8 @@ public function up()
120120

121121
/**
122122
* Reverse the migrations.
123-
*
124-
* @return void
125123
*/
126-
public function down()
124+
public function down(): void
127125
{
128126
$tableNames = config('permission.table_names');
129127

@@ -137,4 +135,4 @@ public function down()
137135
Schema::drop($tableNames['roles']);
138136
Schema::drop($tableNames['permissions']);
139137
}
140-
}
138+
};

0 commit comments

Comments
 (0)