Skip to content

Commit 12e5145

Browse files
authored
Merge pull request #148 from hypervel/feature/permission
feature: migrate spatie/laravel-permission package
2 parents fd2b493 + ae7e011 commit 12e5145

33 files changed

+3209
-5
lines changed

LICENSE.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
The MIT License (MIT)
22

3-
Copyright (c) Hyperf
4-
53
Copyright (c) Taylor Otwell
64

75
Copyright (c) Hypervel

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
"Hypervel\\Telescope\\": "src/telescope/src/",
6262
"Hypervel\\Testbench\\": "src/testbench/src/",
6363
"Hypervel\\Translation\\": "src/translation/src/",
64-
"Hypervel\\Validation\\": "src/validation/src/"
64+
"Hypervel\\Validation\\": "src/validation/src/",
65+
"Hypervel\\Permission\\": "src/permission/src/"
6566
},
6667
"files": [
6768
"src/auth/src/Functions.php",
@@ -169,7 +170,8 @@
169170
"hypervel/telescope": "self.version",
170171
"hypervel/testbench": "self.version",
171172
"hypervel/translation": "self.version",
172-
"hypervel/validation": "self.version"
173+
"hypervel/validation": "self.version",
174+
"hypervel/permission": "self.version"
173175
},
174176
"suggest": {
175177
"hyperf/redis": "Required to use redis driver. (^3.1).",
@@ -237,7 +239,8 @@
237239
"Hypervel\\Session\\ConfigProvider",
238240
"Hypervel\\Socialite\\ConfigProvider",
239241
"Hypervel\\Telescope\\ConfigProvider",
240-
"Hypervel\\Validation\\ConfigProvider"
242+
"Hypervel\\Validation\\ConfigProvider",
243+
"Hypervel\\Permission\\ConfigProvider"
241244
]
242245
},
243246
"hypervel": {

src/permission/LICENSE.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Spatie bvba [email protected]
4+
5+
Copyright (c) Hyperf
6+
7+
Copyright (c) Hypervel
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in
17+
all copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.

src/permission/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Permission for Hypervel
2+
===
3+
4+
Migrated from: https://github.com/spatie/laravel-permission
5+
6+
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/hypervel/permission)

src/permission/composer.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "hypervel/permission",
3+
"type": "library",
4+
"description": "The permission package for Hypervel.",
5+
"license": "MIT",
6+
"keywords": [
7+
"php",
8+
"hyperf",
9+
"swoole",
10+
"permission",
11+
"hypervel"
12+
],
13+
"authors": [
14+
{
15+
"name": "Albert Chen",
16+
"email": "[email protected]"
17+
}
18+
],
19+
"support": {
20+
"issues": "https://github.com/hypervel/components/issues",
21+
"source": "https://github.com/hypervel/components"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"Hypervel\\Permission\\": "src/"
26+
}
27+
},
28+
"require": {
29+
"php": "^8.2",
30+
"hypervel/auth": "^0.2",
31+
"hypervel/cache": "^0.2",
32+
"hypervel/console": "^0.2",
33+
"hypervel/core": "^0.2",
34+
"hypervel/support": "^0.2"
35+
},
36+
"config": {
37+
"sort-packages": true
38+
},
39+
"extra": {
40+
"branch-alias": {
41+
"dev-main": "0.2-dev"
42+
},
43+
"hyperf": {
44+
"config": "Hypervel\\Permission\\ConfigProvider"
45+
},
46+
"hypervel": {
47+
"providers": [
48+
"Hypervel\\Permission\\PermissionServiceProvider"
49+
]
50+
}
51+
}
52+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Hyperf\Database\Schema\Blueprint;
6+
use Hypervel\Database\Migrations\Migration;
7+
use Hypervel\Support\Facades\Schema;
8+
9+
use function Hypervel\Config\config;
10+
11+
return new class extends Migration {
12+
/**
13+
* Get the migration connection name.
14+
*/
15+
public function getConnection(): string
16+
{
17+
return config('permission.storage.database.connection')
18+
?: parent::getConnection();
19+
}
20+
21+
/**
22+
* Run the migrations.
23+
*/
24+
public function up(): void
25+
{
26+
$schema = Schema::connection($this->getConnection());
27+
28+
$schema->create('roles', function (Blueprint $table) {
29+
$table->bigIncrements('id');
30+
$table->string('name')->unique();
31+
$table->string('guard_name');
32+
$table->timestamps();
33+
34+
$table->index(['name', 'guard_name']);
35+
});
36+
37+
$schema->create('permissions', function (Blueprint $table) {
38+
$table->bigIncrements('id');
39+
$table->string('name')->unique();
40+
$table->string('guard_name');
41+
$table->timestamps();
42+
$table->index(['name', 'guard_name']);
43+
});
44+
$schema->create('role_has_permissions', function (Blueprint $table) {
45+
$table->unsignedBigInteger('permission_id');
46+
$table->unsignedBigInteger('role_id');
47+
$table->boolean('is_forbidden');
48+
$table->timestamps();
49+
50+
$table->primary(['permission_id', 'role_id']);
51+
$table->index('role_id');
52+
$table->index('permission_id');
53+
});
54+
55+
$schema->create('owner_has_permissions', function (Blueprint $table) {
56+
$table->unsignedBigInteger('permission_id');
57+
$table->morphs('owner');
58+
$table->boolean('is_forbidden');
59+
$table->timestamps();
60+
61+
$table->primary(['permission_id', 'owner_id', 'owner_type']);
62+
$table->index('owner_id');
63+
$table->index('permission_id');
64+
});
65+
66+
$schema->create('owner_has_roles', function (Blueprint $table) {
67+
$table->unsignedBigInteger('role_id');
68+
$table->morphs('owner');
69+
$table->timestamps();
70+
71+
$table->primary(['role_id', 'owner_id', 'owner_type']);
72+
$table->index('owner_id');
73+
$table->index('role_id');
74+
});
75+
}
76+
77+
/**
78+
* Reverse the migrations.
79+
*/
80+
public function down(): void
81+
{
82+
$schema = Schema::connection($this->getConnection());
83+
$schema->dropIfExists('owner_has_roles');
84+
$schema->dropIfExists('owner_has_permissions');
85+
$schema->dropIfExists('role_has_permissions');
86+
$schema->dropIfExists('permissions');
87+
$schema->dropIfExists('roles');
88+
}
89+
};

0 commit comments

Comments
 (0)