From 660d02527bede69d64dc0b224d40263e1fa2c037 Mon Sep 17 00:00:00 2001 From: Thiritin Date: Sun, 26 May 2024 17:29:03 +0200 Subject: [PATCH] add nextcloud info to idp --- app/Filament/Resources/GroupResource.php | 11 ++++++++-- app/Http/Resources/V1/UserinfoResource.php | 11 ++++++++++ ..._nextcloud_folder_name_to_groups_table.php | 21 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2024_05_26_152355_add_nextcloud_folder_name_to_groups_table.php diff --git a/app/Filament/Resources/GroupResource.php b/app/Filament/Resources/GroupResource.php index c0f8da2..f1f85f3 100644 --- a/app/Filament/Resources/GroupResource.php +++ b/app/Filament/Resources/GroupResource.php @@ -43,10 +43,17 @@ public static function form(Form $form): Form ->label('Public ID') ->content(fn(?Group $record): string => $record?->hashid() ?? '-'), ]), + TextInput::make('system_name') + ->label('System Name') + ->hint('Unique system name, should be left empty in most cases.') + ->unique('groups', 'system_name', ignoreRecord: true) + ->disabled(fn(?Group $record) => $record?->exists), TextInput::make('name') - ->hint('Translatable') - ->hintIcon('heroicon-m-language') ->required(), + TextInput::make('nextcloud_folder_name') + ->label('Nextcloud Folder Name') + ->hint('Leave empty if the group should not be allowed to access Nextcloud.') + ->unique('groups', 'nextcloud_folder_name', ignoreRecord: true), Textarea::make('description')->rows(5), ]), ]), diff --git a/app/Http/Resources/V1/UserinfoResource.php b/app/Http/Resources/V1/UserinfoResource.php index 0160180..beae70d 100644 --- a/app/Http/Resources/V1/UserinfoResource.php +++ b/app/Http/Resources/V1/UserinfoResource.php @@ -30,18 +30,29 @@ public function toArray($request) $data = []; $data['sub'] = $this->hashid; + $this->loadMissing('groups'); + if ($this->scopeCheck('email')) { $data['email'] = $this->email; $data['email_verified'] = !is_null($this->email_verified_at); } + if ($this->scopeCheck('profile')) { $data['name'] = $this->name; + $data['avatar'] = ($request->user()->profile_photo_path) ? Storage::disk('s3-avatars')->url($request->user()->profile_photo_path) : null; } if ($this->whenLoaded('groups') && $this->scopeCheck('groups')) { $data['groups'] = $this->groups->filter(fn(Group $group ) => $group->pivot->level !== GroupUserLevel::Invited)->pluck('hashid'); } + /** + * APP Specific: NEXTCLOUD + */ + if ($this->scopeCheck('nextcloud')) { + $data['nextcloud_groups'] = $this->groups->whereNotNull('nextcloud_folder_name')->pluck('nextcloud_folder_name'); + $data['nextcloud_admin'] = $this->groups->contains('system_name', 'nextcloud_admins'); + } return $data; } diff --git a/database/migrations/2024_05_26_152355_add_nextcloud_folder_name_to_groups_table.php b/database/migrations/2024_05_26_152355_add_nextcloud_folder_name_to_groups_table.php new file mode 100644 index 0000000..681ae74 --- /dev/null +++ b/database/migrations/2024_05_26_152355_add_nextcloud_folder_name_to_groups_table.php @@ -0,0 +1,21 @@ +string('nextcloud_folder_name')->nullable()->after('logo'); + }); + } + + public function down(): void + { + Schema::table('groups', function (Blueprint $table) { + $table->dropColumn('nextcloud_folder_name'); + }); + } +};