-
Notifications
You must be signed in to change notification settings - Fork 1
User profile and PDF export of memberships #42
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
base: main
Are you sure you want to change the base?
Changes from all commits
4d22a78
19c8c1b
58a7dbc
0e7b81e
b5b23ef
8d57d4e
7704b76
30dea9c
ffca066
0b96e6f
0223da5
664ef00
a0ef3b9
8277e4c
8c39e85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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, | ||
| ]); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,10 +33,18 @@ class Profile extends Component | |
| public $picture; | ||
| public $pictureUrl; | ||
|
|
||
| public function mount() | ||
| public $currentUsername; | ||
|
|
||
| public function mount($username) | ||
| { | ||
| $username = Auth::user()->username; | ||
| $user = User::findOrFailByUsername($username); | ||
| if ($username == auth()->user()->username || auth()->user()->can('superadmin', User::class)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s.o. |
||
| $this->currentUsername = $username; | ||
| } elseif ($username == auth()->user()->username) { | ||
| $this->currentUsername = auth()->user()->username; | ||
| } else { | ||
| abort('403'); | ||
| } | ||
| $user = User::findOrFailByUsername($this->currentUsername); | ||
| $this->uid = $user->getFirstAttribute('uid'); | ||
| $this->givenName = $user->getFirstAttribute('givenName'); | ||
| $this->sn = $user->getFirstAttribute('sn'); | ||
|
|
@@ -57,9 +65,6 @@ public function render() | |
| public function save() | ||
| { | ||
| $this->validate(); | ||
| if (Auth::user()->username !== $this->uid) { | ||
| abort('403'); | ||
| } | ||
| $user = User::findOrFailByUsername($this->uid); | ||
| $user->setAttribute('mail', $this->email); | ||
| $user->setAttribute('givenName', $this->givenName); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| <?php | ||
|
|
||
| namespace App\Livewire\Profile; | ||
|
|
||
| use App\Ldap\User; | ||
| use App\Ldap\Role; | ||
| use App\Models\RoleMembership; | ||
| use Barryvdh\DomPDF\Facade\Pdf; | ||
| use Livewire\Attributes\Locked; | ||
| use Livewire\Component; | ||
|
|
||
| class Memberships extends Component | ||
| { | ||
| #[Locked] | ||
| public $currentUsername; | ||
|
|
||
| public bool $showOnlyActive = true; | ||
|
|
||
| public function mount($username) | ||
| { | ||
| if ($username == auth()->user()->username || auth()->user()->can('superadmin', User::class)) { | ||
| $this->currentUsername = $username; | ||
| } elseif ($username == auth()->user()->username) { | ||
| $this->currentUsername = auth()->user()->username; | ||
| } else { | ||
| abort('403'); | ||
| } | ||
| } | ||
|
|
||
| public function getMemberships(string $username, bool $onlyActive) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. public Methoden können bei livewire auch vom client aus aufgerufen werden. Wenn du das nicht machst (wie hier?) solltest du die private machen
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moderator:innen einer Studischaft haben keinen Zugriff auf den Profil-Bereich. Damit Moderator:innen trotzdem die Möglichkeit haben, die Tätigkeitsübersicht zu exportieren und es möglichst wenig Code-Dopplung gibt, greift auch der Members-Controller auf diese Funktion zu. |
||
| { | ||
| $query = RoleMembership::where('username', $username); | ||
| if ($onlyActive) { | ||
| $query->whereNull('until'); | ||
| } | ||
| $roleMemberships = $query->get(); | ||
| $memberships = []; | ||
| foreach ($roleMemberships as $row) { | ||
| $role = Role::findOrFail('cn=' . $row->role_cn . ',' . $row->committee_dn); | ||
| $memberships[] = [ | ||
| 'role' => $role, | ||
| 'from' => $row->from, | ||
| 'until' => $row->until, | ||
| 'decided' => $row->decided, | ||
| 'comment' => $row->comment, | ||
| ]; | ||
| } | ||
| return $memberships; | ||
| } | ||
|
|
||
| public function render() | ||
| { | ||
| $memberships = $this->getMemberships($this->currentUsername, $this->showOnlyActive); | ||
|
|
||
| return view('livewire.profile.memberships', [ | ||
| 'memberships' => $memberships, | ||
| ])->title(__('Profile')); | ||
| } | ||
|
|
||
| public function exportPdf() | ||
| { | ||
| $memberships = $this->getMemberships($this->currentUsername, false); | ||
| $user = User::findOrFailByUsername($this->currentUsername); | ||
| $pdf = Pdf::loadView('pdfs.memberships', [ | ||
| 'fullName' => $user->cn[0], | ||
| 'community' => null, | ||
| 'memberships' => $memberships, | ||
| ]); | ||
|
|
||
| return response()->streamDownload(function () use ($pdf) { | ||
| echo $pdf->stream(); | ||
| }, strtolower(trans('profile.memberships')) . '_' . $this->currentUsername . '.pdf'); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| use App\Ldap\Community; | ||
| use App\Ldap\User; | ||
| use Barryvdh\DomPDF\Facade\Pdf; | ||
| use Livewire\Attributes\Rule; | ||
| use Livewire\Attributes\Url; | ||
| use Livewire\Component; | ||
|
|
@@ -87,4 +88,20 @@ public function close(): void | |
| $this->showDeleteModal = false; | ||
| unset($this->deleteMemberName, $this->deleteMemberUsername); | ||
| } | ||
|
|
||
| public function exportPdf($username) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sehe ich das Richtig, das es einmal das PDF pro Person und das andere mal das PDF pro Rolle / Realm ist?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Falls du dich auf den Zugriff aus unterschiedlichen Komponenten auf diese Funktion beziehst, dann ist der einzige Unterschied, dass im Profil kein Realm mitgegeben werden kann, da die Nutzer nicht nur einem einzigen Realm zugeordnet sein können. Beim Export über die Mitglieder-Liste eines Realms kann der aktuelle Realm für den PDF-Export mitgegeben werden, sodass auch die Studischaft im Dokument angezeigt werden kann. |
||
| { | ||
| $memberships = app('App\Livewire\Profile\Memberships')->getMemberships($username, false); | ||
| $user = User::findOrFailByUsername($username); | ||
| $community = Community::findOrFailByUid($this->community_name); | ||
| $pdf = Pdf::loadView('pdfs.memberships', [ | ||
| 'fullName' => $user->cn[0], | ||
| 'community' => $community->description[0], | ||
| 'memberships' => $memberships, | ||
| ]); | ||
|
|
||
| return response()->streamDownload(function () use ($pdf) { | ||
| echo $pdf->stream(); | ||
| }, 'memberships-' . $username . '.pdf');; | ||
| } | ||
| } | ||
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.
Vorsicht! Public probs können via client api frei verändert werden, auch wenn du da kein Input feld hin machst. Macht das hier Probleme? Evtl das [#Url] oder [#Locked] Prop verwenden stattdessen