-
Notifications
You must be signed in to change notification settings - Fork 1
Sync users instead of roles into LDAP groups #41
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
Open
schlagma
wants to merge
2
commits into
main
Choose a base branch
from
sync-script
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <?php | ||
|
|
||
| namespace App\Console\Commands; | ||
|
|
||
| use App\Ldap\Community; | ||
| use App\Ldap\Group; | ||
| use App\Models\GroupMembership; | ||
| use Illuminate\Console\Command; | ||
|
|
||
| class MoveGroupRolesFromLdapToDatabase extends Command | ||
| { | ||
| /** | ||
| * The name and signature of the console command. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $signature = 'app:move-group-roles-from-ldap-to-database | ||
| {community? : The short name to search for of the community} | ||
| {group? : The short name to search for of the group}'; | ||
|
|
||
| /** | ||
| * The console command description. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $description = 'Command description'; | ||
|
|
||
| /** | ||
| * Execute the console command. | ||
| */ | ||
| public function handle() | ||
| { | ||
| $realms = Community::query() | ||
| ->list() // only first level | ||
| ->setDn(Community::$rootDn) | ||
| ->search('ou', $this->argument('community')) | ||
| ->get(); | ||
|
|
||
| foreach ($realms as $realm) { | ||
| $groups = Group::fromCommunity($realm->getFirstAttribute('ou')) | ||
| ->search('ou', $this->argument('group')) | ||
| ->get(); | ||
|
|
||
| foreach ($groups as $group) { | ||
| $this->comment("> " . $group->getDn()); | ||
|
|
||
| // get roles | ||
| $roles = $group->members()->get(); | ||
|
|
||
| foreach ($roles as $role) { | ||
| $this->comment($role); | ||
| GroupMembership::create([ | ||
| 'group_dn' => $group->getDn(), | ||
| 'role_dn' => $role, | ||
| ]); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| namespace App\Models; | ||
|
|
||
| use Carbon\Carbon; | ||
| use Illuminate\Database\Eloquent\Builder; | ||
| use Illuminate\Database\Eloquent\Model; | ||
| use Illuminate\Database\Eloquent\Relations\HasMany; | ||
|
|
||
| /** | ||
| * @property integer $group_id | ||
| * @property Group $group | ||
| * @property Role $role | ||
| */ | ||
|
|
||
| class GroupMembership extends Model | ||
| { | ||
| /** | ||
| * The table associated with the model. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $table = 'role_group_relation'; | ||
|
|
||
| /** | ||
| * @var array | ||
| */ | ||
| protected $fillable = [ | ||
| 'group_dn', | ||
| 'role_dn', | ||
| ]; | ||
|
|
||
| public function roles(): HasMany | ||
| { | ||
| return $this->hasMany(Role::class); | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
database/migrations/2025_06_27_095320_create_role_group_relation.php
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php | ||
|
|
||
| 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('role_group_relation', function (Blueprint $table) { | ||
| $table->id(); | ||
| $table->string('group_dn'); | ||
| $table->string('role_dn'); | ||
| $table->timestamps(); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| */ | ||
| public function down(): void | ||
| { | ||
| Schema::dropIfExists('role_group_relation'); | ||
| } | ||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wie soll hier der migrationspfad von bestehenden Daten sein? aka ließt die bisherigen Gruppen aus speichert die zusammensetzung in der DB und stups mal das neue sync script.
2 Möglichkeiten: entweder die migration macht das mit, oder es gibt ein cmd Command Befehl den man dann ausführen muss - dass müsste dann auch ins Changelog beim Release.
imho ist variante 2 etwas robuster, generiert aber auch code den man "nie wieder" braucht (also außer halt genau bei dem Versionssprung).
Weiterer kleiner Vorteil von V2 ist, dass das frische migrieren long term etwas schneller ist, wenn mans in ein seperates command auslagert
Meinungen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Das hier wäre noch zu klären @schlagma