Repository navigation
feat: let organizations show their people on their page #1516
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
danielh-official
wants to merge
2
commits into
dev-null-sh:production
Choose a base branch
from
danielh-official:feat/organization-people
base: production
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,18 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Events\ProfilesUpdated; | ||
| use App\Models\Organization; | ||
|
|
||
| final readonly class UpdateOrganizationPeopleVisibility | ||
| { | ||
| public function handle(Organization $organization, bool $showsPeople): void | ||
| { | ||
| $organization->update(['shows_people' => $showsPeople]); | ||
|
|
||
| event(new ProfilesUpdated([$organization->id])); | ||
| } | ||
| } |
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
32 changes: 32 additions & 0 deletions
32
app/Http/Controllers/OrganizationPeopleVisibilityController.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,32 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Controllers; | ||
|
|
||
| use App\Actions\UpdateOrganizationPeopleVisibility; | ||
| use App\Http\Requests\UpdateOrganizationPeopleVisibilityRequest; | ||
| use App\Models\Organization; | ||
| use Illuminate\Http\RedirectResponse; | ||
| use Inertia\Inertia; | ||
|
|
||
| /** | ||
| * Whether an organization's page shows its members to everyone, in the Profile tab of its settings. Only its admins | ||
| * choose it. | ||
| */ | ||
| final readonly class OrganizationPeopleVisibilityController | ||
| { | ||
| public function update(UpdateOrganizationPeopleVisibilityRequest $request, Organization $organization, UpdateOrganizationPeopleVisibility $action): RedirectResponse | ||
| { | ||
| $showsPeople = $request->showsPeople(); | ||
|
|
||
| $action->handle($organization, $showsPeople); | ||
|
|
||
| Inertia::flash('toast', [ | ||
| 'type' => 'success', | ||
| 'message' => $showsPeople ? 'People are shown on the page.' : 'People are hidden from the page.', | ||
| ]); | ||
|
|
||
| return back(); | ||
| } | ||
| } |
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
42 changes: 42 additions & 0 deletions
42
app/Http/Requests/UpdateOrganizationPeopleVisibilityRequest.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,42 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Requests; | ||
|
|
||
| use App\Models\Organization; | ||
| use App\Models\User; | ||
| use Illuminate\Auth\Access\Response; | ||
| use Illuminate\Foundation\Http\FormRequest; | ||
|
|
||
| final class UpdateOrganizationPeopleVisibilityRequest extends FormRequest | ||
| { | ||
| /** | ||
| * Only the organization's admins choose who sees its members, so to everyone else it looks like it does not exist. | ||
| */ | ||
| public function authorize(): Response | ||
| { | ||
| $user = $this->user(); | ||
| assert($user instanceof User); | ||
|
|
||
| $organization = $this->route('organization'); | ||
| assert($organization instanceof Organization); | ||
|
|
||
| return $organization->isAdmin($user) ? Response::allow() : Response::denyAsNotFound(); | ||
| } | ||
|
|
||
| /** | ||
| * @return array<string, array<int, string>> | ||
| */ | ||
| public function rules(): array | ||
| { | ||
| return [ | ||
| 'shows_people' => ['required', 'boolean'], | ||
| ]; | ||
| } | ||
|
|
||
| public function showsPeople(): bool | ||
| { | ||
| return $this->boolean('shows_people'); | ||
| } | ||
| } |
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,59 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Queries; | ||
|
|
||
| use App\Models\Organization; | ||
| use App\Models\User; | ||
| use Illuminate\Contracts\Pagination\CursorPaginator; | ||
| use Illuminate\Database\Eloquent\Builder; | ||
| use Illuminate\Database\Eloquent\Relations\BelongsToMany; | ||
| use Illuminate\Database\Eloquent\Relations\Pivot; | ||
|
|
||
| final readonly class OrganizationPeopleQuery | ||
| { | ||
| /** | ||
| * The organization's members, on the People tab of its page, first joined first, as the viewer, or a guest, may see | ||
| * them: without anyone across a block or muted, and with whether the viewer follows each one and each one follows | ||
| * them. | ||
| * | ||
| * @return BelongsToMany<User, Organization> | ||
| */ | ||
| public function builder(Organization $organization, ?User $viewer): BelongsToMany | ||
| { | ||
| $people = $organization->members() | ||
| ->oldest('organization_members.created_at') | ||
| ->oldest('users.id'); | ||
|
|
||
| if (! $viewer instanceof User) { | ||
| return $people; | ||
| } | ||
|
|
||
| return $people | ||
| ->whereNotIn('users.id', $viewer->idsAcrossBlocks()) | ||
| ->whereNotIn('users.id', $viewer->mutedIds()) | ||
| ->withExists([ | ||
| 'followers as is_followed' => fn (Builder $query): Builder => $query->whereKey($viewer->id), | ||
| 'following as follows_you' => fn (Builder $query): Builder => $query->whereKey($viewer->id), | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * A page of them, without the roles and join dates of the membership: the page lists its admins already. | ||
| * | ||
| * @return CursorPaginator<int, User&object{pivot: Pivot}> | ||
| */ | ||
| public function page(Organization $organization, ?User $viewer): CursorPaginator | ||
| { | ||
| $people = $this->builder($organization, $viewer) | ||
| ->cursorPaginate(30) | ||
| ->appends(['tab' => 'people']); | ||
|
|
||
| foreach ($people->items() as $person) { | ||
| $person->makeHidden('pivot'); | ||
| } | ||
|
|
||
| return $people; | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
database/migrations/2026_11_06_200000_add_shows_people_to_organizations_table.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,21 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| return new class extends Migration | ||
| { | ||
| /** | ||
| * Whether everyone sees the organization's members on a People tab of its page. Only its members see them until its | ||
| * admins switch it on. | ||
| */ | ||
| public function up(): void | ||
| { | ||
| Schema::table('organizations', function (Blueprint $table): void { | ||
| $table->boolean('shows_people')->default(false); | ||
| }); | ||
| } | ||
| }; |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.