Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 Add user groups #2957

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
start working on user groups
ildyria committed Feb 8, 2025
commit 83734bc665e71cbbb651d83e6da15c5bc8a5f177
1 change: 1 addition & 0 deletions app/Constants/AccessPermissionConstants.php
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ class AccessPermissionConstants
// Id names
public const BASE_ALBUM_ID = 'base_album_id';
public const USER_ID = 'user_id';
public const USER_GROUP_ID = 'user_group_id';

// Attributes name
public const IS_LINK_REQUIRED = 'is_link_required';
20 changes: 20 additions & 0 deletions app/Models/Builders/UserGroupBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/

namespace App\Models\Builders;

use App\Eloquent\FixedQueryBuilder;

/**
* Specialized query builder for {@link \App\Models\UserGroup}.
*
* @extends FixedQueryBuilder<\App\Models\UserGroup>
*/
class UserGroupBuilder extends FixedQueryBuilder
{
}
72 changes: 72 additions & 0 deletions app/Models/UserGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace App\Models;

use App\Constants\AccessPermissionConstants as APC;
use App\Models\Builders\UserGroupBuilder;
use App\Models\Extensions\ThrowsConsistentExceptions;
use App\Models\Extensions\ToArrayThrowsNotImplemented;
use App\Models\Extensions\UTCBasedTimes;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Query\Builder as BaseBuilder;

/**
* App\Models\UserGroup.
*
* @property int $id
* @property string $name
* @property Carbon $created_at
* @property Carbon $updated_at
*/
class UserGroup extends Model
{
use UTCBasedTimes;
use ThrowsConsistentExceptions {
delete as parentDelete;
}
use ToArrayThrowsNotImplemented;

/**
* @var array<int,string> the attributes that are mass assignable
*/
protected $fillable = [
'name',
];

/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'id' => 'integer',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
}

protected $hidden = [];

/**
* Create a new Eloquent query builder for the model.
*
* @param BaseBuilder $query
*
* @return UserGroupBuilder
*/
public function newEloquentBuilder($query): UserGroupBuilder
{
return new UserGroupBuilder($query);
}

/**
* Returns the relationship between an album and its associated permissions.
*
* @return hasMany<AccessPermission,$this>
*/
public function access_permissions(): HasMany
{
return $this->hasMany(AccessPermission::class, APC::USER_GROUP_ID, 'id');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/

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_groups', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 100)->nullable(false)->unique();
$table->dateTime('created_at', 6)->nullable(false);
$table->dateTime('updated_at', 6)->nullable(false);
$table->index('id');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('user_groups');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
private const USER_ID = 'user_id';
private const USER_GROUP_ID = 'user_group_id';

/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('users_user_groups', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger(self::USER_ID)->nullable(false);
$table->unsignedInteger(self::USER_GROUP_ID)->nullable(false);
$table->dateTime('created_at', 6)->nullable(false);

$table->index([self::USER_ID]);
$table->index([self::USER_GROUP_ID]);
$table->index([self::USER_ID, self::USER_GROUP_ID]);
$table->unique([self::USER_ID, self::USER_GROUP_ID]);
$table->foreign(self::USER_ID)->references('id')->on('users')->cascadeOnUpdate()->cascadeOnDelete();
$table->foreign(self::USER_GROUP_ID)->references('id')->on('user_groups')->cascadeOnUpdate()->cascadeOnDelete();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users_user_groups');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
private const USER_GROUP_ID = 'user_group_id';

/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('access_permissions', function ($table) {
$table->unsignedInteger(self::USER_GROUP_ID)->nullable()->default(null)->after('user_id');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('access_permissions', function (Blueprint $table) {
$table->dropColumn(self::USER_GROUP_ID);
});
}
};