Skip to content

Commit 6d56c21

Browse files
committed
start working on user groups
1 parent 50e467b commit 6d56c21

6 files changed

Lines changed: 207 additions & 0 deletions

app/Constants/AccessPermissionConstants.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class AccessPermissionConstants
1717
// Id names
1818
public const BASE_ALBUM_ID = 'base_album_id';
1919
public const USER_ID = 'user_id';
20+
public const USER_GROUP_ID = 'user_group_id';
2021

2122
// Attributes name
2223
public const IS_LINK_REQUIRED = 'is_link_required';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2025 LycheeOrg.
7+
*/
8+
9+
namespace App\Models\Builders;
10+
11+
use App\Eloquent\FixedQueryBuilder;
12+
13+
/**
14+
* Specialized query builder for {@link \App\Models\UserGroup}.
15+
*
16+
* @extends FixedQueryBuilder<\App\Models\UserGroup>
17+
*/
18+
class UserGroupBuilder extends FixedQueryBuilder
19+
{
20+
}

app/Models/UserGroup.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use App\Constants\AccessPermissionConstants as APC;
6+
use App\Models\Builders\UserGroupBuilder;
7+
use App\Models\Extensions\ThrowsConsistentExceptions;
8+
use App\Models\Extensions\ToArrayThrowsNotImplemented;
9+
use App\Models\Extensions\UTCBasedTimes;
10+
use Illuminate\Database\Eloquent\Model;
11+
use Illuminate\Database\Eloquent\Relations\HasMany;
12+
use Illuminate\Database\Query\Builder as BaseBuilder;
13+
14+
/**
15+
* App\Models\UserGroup.
16+
*
17+
* @property int $id
18+
* @property string $name
19+
* @property Carbon $created_at
20+
* @property Carbon $updated_at
21+
*/
22+
class UserGroup extends Model
23+
{
24+
use UTCBasedTimes;
25+
use ThrowsConsistentExceptions {
26+
delete as parentDelete;
27+
}
28+
use ToArrayThrowsNotImplemented;
29+
30+
/**
31+
* @var array<int,string> the attributes that are mass assignable
32+
*/
33+
protected $fillable = [
34+
'name',
35+
];
36+
37+
/**
38+
* @return array<string, string>
39+
*/
40+
protected function casts(): array
41+
{
42+
return [
43+
'id' => 'integer',
44+
'created_at' => 'datetime',
45+
'updated_at' => 'datetime',
46+
];
47+
}
48+
49+
protected $hidden = [];
50+
51+
/**
52+
* Create a new Eloquent query builder for the model.
53+
*
54+
* @param BaseBuilder $query
55+
*
56+
* @return UserGroupBuilder
57+
*/
58+
public function newEloquentBuilder($query): UserGroupBuilder
59+
{
60+
return new UserGroupBuilder($query);
61+
}
62+
63+
/**
64+
* Returns the relationship between an album and its associated permissions.
65+
*
66+
* @return hasMany<AccessPermission,$this>
67+
*/
68+
public function access_permissions(): HasMany
69+
{
70+
return $this->hasMany(AccessPermission::class, APC::USER_GROUP_ID, 'id');
71+
}
72+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2025 LycheeOrg.
7+
*/
8+
9+
use Illuminate\Database\Migrations\Migration;
10+
use Illuminate\Database\Schema\Blueprint;
11+
use Illuminate\Support\Facades\Schema;
12+
13+
return new class() extends Migration {
14+
/**
15+
* Run the migrations.
16+
*/
17+
public function up(): void
18+
{
19+
Schema::create('user_groups', function (Blueprint $table) {
20+
$table->increments('id');
21+
$table->string('name', 100)->nullable(false)->unique();
22+
$table->dateTime('created_at', 6)->nullable(false);
23+
$table->dateTime('updated_at', 6)->nullable(false);
24+
$table->index('id');
25+
});
26+
}
27+
28+
/**
29+
* Reverse the migrations.
30+
*/
31+
public function down(): void
32+
{
33+
Schema::dropIfExists('user_groups');
34+
}
35+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2025 LycheeOrg.
7+
*/
8+
9+
use Illuminate\Database\Migrations\Migration;
10+
use Illuminate\Database\Schema\Blueprint;
11+
use Illuminate\Support\Facades\Schema;
12+
13+
return new class() extends Migration {
14+
private const USER_ID = 'user_id';
15+
private const USER_GROUP_ID = 'user_group_id';
16+
17+
/**
18+
* Run the migrations.
19+
*/
20+
public function up(): void
21+
{
22+
Schema::create('users_user_groups', function (Blueprint $table) {
23+
$table->increments('id');
24+
$table->unsignedInteger(self::USER_ID)->nullable(false);
25+
$table->unsignedInteger(self::USER_GROUP_ID)->nullable(false);
26+
$table->dateTime('created_at', 6)->nullable(false);
27+
28+
$table->index([self::USER_ID]);
29+
$table->index([self::USER_GROUP_ID]);
30+
$table->index([self::USER_ID, self::USER_GROUP_ID]);
31+
$table->unique([self::USER_ID, self::USER_GROUP_ID]);
32+
$table->foreign(self::USER_ID)->references('id')->on('users')->cascadeOnUpdate()->cascadeOnDelete();
33+
$table->foreign(self::USER_GROUP_ID)->references('id')->on('user_groups')->cascadeOnUpdate()->cascadeOnDelete();
34+
});
35+
}
36+
37+
/**
38+
* Reverse the migrations.
39+
*/
40+
public function down(): void
41+
{
42+
Schema::dropIfExists('users_user_groups');
43+
}
44+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2025 LycheeOrg.
7+
*/
8+
9+
use Illuminate\Database\Migrations\Migration;
10+
use Illuminate\Database\Schema\Blueprint;
11+
use Illuminate\Support\Facades\Schema;
12+
13+
return new class() extends Migration {
14+
private const USER_GROUP_ID = 'user_group_id';
15+
16+
/**
17+
* Run the migrations.
18+
*/
19+
public function up(): void
20+
{
21+
Schema::table('access_permissions', function ($table) {
22+
$table->unsignedInteger(self::USER_GROUP_ID)->nullable()->default(null)->after('user_id');
23+
});
24+
}
25+
26+
/**
27+
* Reverse the migrations.
28+
*/
29+
public function down(): void
30+
{
31+
Schema::table('access_permissions', function (Blueprint $table) {
32+
$table->dropColumn(self::USER_GROUP_ID);
33+
});
34+
}
35+
};

0 commit comments

Comments
 (0)