diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md index a34915941e..a9575ad160 100644 --- a/KNOWLEDGE_BASE.md +++ b/KNOWLEDGE_BASE.md @@ -132,15 +132,17 @@ The **Commits** tab lists the organization's own commits, newest first. The **Me While nobody has claimed an organization's page, it says so to signed-in visitors, with a **Claim** button. A member of the organization can **Claim** its page, which lists them as its admin. Only the first member to claim it becomes its admin: once a page has one, it can't be claimed again, and the Claim button is gone. Claiming asks for no extra GitHub permission: it checks that GitHub lists you among the organization's public members. GitHub keeps membership private by default, so if yours is, the page links to the organization's People page on GitHub, where you make your membership public, then claim again. You can make it private again once you're the admin. GitHub is only the way in: leaving the organization on GitHub doesn't remove you as an admin on /dev/null. -After that, members are managed on /dev/null, not mirrored from GitHub. An organization's members open its **Settings** from its page, where the **Members** tab lists everyone, each an **admin** or a **member**. Admins add people by their /dev/null handle, searching by handle or name as they type, except people they blocked or who blocked them, make them admins or members, and remove them. Any member can leave. Its last admin can't leave or become a member. Only its members see who its members are; its page lists its admins to everyone. Your organizations and your role in each are in your data export and go when you delete your account. +After that, members are managed on /dev/null, not mirrored from GitHub. An organization's members open its **Settings** from its page, where the **Members** tab lists everyone, each an **admin** or a **member**. Admins add people by their /dev/null handle, searching by handle or name as they type, except people they blocked or who blocked them, make them admins or members, and remove them. Any member can leave. Its last admin can't leave or become a member. Its page lists its admins to everyone. Only its members see who all its members are, until its admins show its **People**. Your organizations and your role in each are in your data export and go when you delete your account. Its admins and members can **post as the organization**: in the composer, in a reply's and in the quote dialog, they open their avatar and pick the organization, then switch back to themselves the same way. Every commit, reply and quote starts as yourself. A commit from an organization shows the organization alone, with its square avatar and color, at `/@{handle}/commits/{id}`: nobody else sees which member posted it. It belongs to the organization: any of its members can delete it, and none can star it, report it, vote in its poll or give it pastéis. It counts toward no one's level, and blocking or muting the person who posted it doesn't hide it. Moderators see the person who posted it, in the review queue and in reports, and can time out or ban them from their profile. If they delete their account, the organization's commits they posted stay. Its admins and members hear about the organization in their own notifications, all except whoever did it: replies to its commits, quotes of them, stars on them and commits that mention it, said as the organization's, like **replied to @laravel's commit** or **mentioned @laravel**. They all see the organization's pending and rejected commits, like whoever posted them, and all hear when one is rejected, with the reason. Someone removed from the organization keeps what they already heard and hears nothing new, and no longer sees its rejected commits or what they heard about them. They can schedule commits as the organization too, the same way: if they are no longer a member when it is due, it is canceled. When the organization replies, quotes or mentions someone, they hear it from the organization, never from whoever posted it, so blocking or muting that person doesn't silence it; its members hear nothing of what it does to its own commits or mentioning itself. Its first commit isn't announced to its followers, as a person's is. Apps can post as an organization through the API too, by sending its handle as `author`. Every organization has a color, /dev/null's blue until an admin chooses another in the **Profile** tab of its **Settings**, where its admins land: one of the same six lane colors as developers, or a custom one. It rings the organization's avatar, leads its handle, and colors its link preview. +The same tab has **People**, hidden until an admin shows it. Shown, the organization's page gets a **People** tab listing its admins and members, first joined first, to everyone, guests included, with a Follow button beside each for signed-in visitors. People across a block with you, or whom you muted, are left out. Hiding it again takes the tab away; the members stay members. + Signed in, you can **Follow** an organization from its page, which shows how many people follow it. Once you follow it, the button opens a menu where you can unfollow. Following puts the organization's own commits in your Following log, and ranks them higher in Trending, like the people you follow. **Watch**, which will also show the commits that mention the organization, is planned and shown as coming soon. The organizations you follow are listed on your Following list, above the people, a few at a time with **Show more organizations**, and count toward your following count. They are in your data export and go when you delete your account. -Sources: [organization page](resources/js/pages/organization/show.tsx), [commits](app/Queries/OrganizationCommitsQuery.php), [posting as an organization](app/Rules/OrganizationToPostAs.php), [mentions](app/Queries/OrganizationMentionsQuery.php), [organization lookups](app/Actions/UpdateCommitTopics.php), [claims](app/Http/Controllers/OrganizationAdminController.php), [color](app/Http/Controllers/OrganizationLaneController.php), [members](app/Http/Controllers/OrganizationMemberController.php). +Sources: [organization page](resources/js/pages/organization/show.tsx), [commits](app/Queries/OrganizationCommitsQuery.php), [posting as an organization](app/Rules/OrganizationToPostAs.php), [mentions](app/Queries/OrganizationMentionsQuery.php), [organization lookups](app/Actions/UpdateCommitTopics.php), [claims](app/Http/Controllers/OrganizationAdminController.php), [color](app/Http/Controllers/OrganizationLaneController.php), [members](app/Http/Controllers/OrganizationMemberController.php), [people](app/Queries/OrganizationPeopleQuery.php), [showing people](app/Http/Controllers/OrganizationPeopleVisibilityController.php). ### Developers not on /dev/null yet diff --git a/app/Actions/UpdateOrganizationPeopleVisibility.php b/app/Actions/UpdateOrganizationPeopleVisibility.php new file mode 100644 index 0000000000..74bcb4130e --- /dev/null +++ b/app/Actions/UpdateOrganizationPeopleVisibility.php @@ -0,0 +1,18 @@ +update(['shows_people' => $showsPeople]); + + event(new ProfilesUpdated([$organization->id])); + } +} diff --git a/app/Http/Controllers/OrganizationController.php b/app/Http/Controllers/OrganizationController.php index 6a311a3705..08aaea5b5b 100644 --- a/app/Http/Controllers/OrganizationController.php +++ b/app/Http/Controllers/OrganizationController.php @@ -12,11 +12,13 @@ use App\Models\User; use App\Queries\OrganizationCommitsQuery; use App\Queries\OrganizationMentionsQuery; +use App\Queries\OrganizationPeopleQuery; use App\Services\PageMetadata; use Closure; use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Container\Attributes\CurrentUser; +use Illuminate\Contracts\Pagination\CursorPaginator as CursorPage; use Illuminate\Database\Eloquent\Collection; use Illuminate\Http\RedirectResponse; use Illuminate\Pagination\CursorPaginator; @@ -28,11 +30,12 @@ { /** * Organization pages are public, at the "@handle" of users, and show the organization's GitHub profile, its own - * commits and the commits that mention it, in the lane its admins chose or /dev/null's blue, with its admins, first one first, how - * many follow it and whether the viewer does, and the organization's link preview, and its members the way to its - * settings. Like users' pages, they move for good to the handle's own case. + * commits and the commits that mention it, and its members once its admins show them, in the lane its admins chose + * or /dev/null's blue, with its admins, first one first, how many follow it and whether the viewer does, and the + * organization's link preview, and its members the way to its settings. Like users' pages, they move for good to + * the handle's own case. */ - public function show(ShowOrganizationRequest $request, #[CurrentUser] ?User $currentUser, OrganizationCommitsQuery $organizationCommits, OrganizationMentionsQuery $mentions, PageMetadata $metadata): RedirectResponse|Response + public function show(ShowOrganizationRequest $request, #[CurrentUser] ?User $currentUser, OrganizationCommitsQuery $organizationCommits, OrganizationMentionsQuery $mentions, OrganizationPeopleQuery $people, PageMetadata $metadata): RedirectResponse|Response { $organization = $request->organization(); assert($organization instanceof Organization); @@ -44,6 +47,14 @@ public function show(ShowOrganizationRequest $request, #[CurrentUser] ?User $cur return redirect(route('user.show', $organization->handle).($query === '' ? '' : "?{$query}"), 301, ['Cache-Control' => 'max-age=86400, private']); } + // Resolved once, so a refresh of the organization while the props resolve can't make the tab and its stream disagree. + $tab = $request->tab(); + + // A link to the next page of people its admins have since hidden carries a cursor the commits can't read... + if ($request->filled('cursor') && $request->string('tab')->value() === 'people' && $tab !== 'people') { + return redirect()->route('user.show', $organization->handle); + } + // What its page shows about the organization changes for everyone on its public channel, and what it shows // about the viewer's own relationship to it on theirs. $profile = new Channel('profiles.'.$organization->id); @@ -51,10 +62,15 @@ public function show(ShowOrganizationRequest $request, #[CurrentUser] ?User $cur return Inertia::render('organization/show', [ 'organization' => Inertia::live(fn (): Organization => $organization->refresh(), 'profile', $profile), - 'tab' => $request->tab(...), - 'commits' => Inertia::scroll(fn (): CursorPaginator => ShownStreams::page(($request->tab() === 'mentions' ? $mentions : $organizationCommits)->builder($organization, $currentUser) - ->cursorPaginate(20) - ->appends(['tab' => $request->tab()]))), + 'tab' => $tab, + ...$tab === 'people' ? [ + 'people' => Inertia::scroll(fn (): CursorPage => $people->page($organization, $currentUser)), + ] : [ + 'commits' => Inertia::scroll(fn (): CursorPaginator => ShownStreams::page(($tab === 'mentions' ? $mentions : $organizationCommits)->builder($organization, $currentUser) + ->cursorPaginate(20) + ->appends(['tab' => $tab]))), + ], + 'showsPeople' => Inertia::live(fn (): bool => $organization->refresh()->shows_people, 'profile', $profile), 'claimUrl' => route('organization-admin.store', $organization), // Admins land on the Profile tab, which only they have... 'settingsUrl' => $relationship(fn (): ?string => match ($currentUser instanceof User ? $organization->roleOf($currentUser) : null) { diff --git a/app/Http/Controllers/OrganizationPeopleVisibilityController.php b/app/Http/Controllers/OrganizationPeopleVisibilityController.php new file mode 100644 index 0000000000..c18725932f --- /dev/null +++ b/app/Http/Controllers/OrganizationPeopleVisibilityController.php @@ -0,0 +1,32 @@ +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(); + } +} diff --git a/app/Http/Controllers/OrganizationProfileController.php b/app/Http/Controllers/OrganizationProfileController.php index aa80bf0e59..0b80695c69 100644 --- a/app/Http/Controllers/OrganizationProfileController.php +++ b/app/Http/Controllers/OrganizationProfileController.php @@ -11,7 +11,8 @@ use Inertia\Response; /** - * The Profile tab of an organization's settings, like the user's, where its admins choose its color. + * The Profile tab of an organization's settings, like the user's, where its admins choose its color and whether its + * page shows its people. */ final readonly class OrganizationProfileController { @@ -20,6 +21,7 @@ public function edit(ShowOrganizationProfileRequest $request, Organization $orga return Inertia::render('organization-profile/edit', [ 'organization' => $organization, 'role' => OrganizationRole::Admin, + 'showsPeople' => $organization->shows_people, ]); } } diff --git a/app/Http/Requests/ShowOrganizationRequest.php b/app/Http/Requests/ShowOrganizationRequest.php index 8ef8066c62..f5f0ef519b 100644 --- a/app/Http/Requests/ShowOrganizationRequest.php +++ b/app/Http/Requests/ShowOrganizationRequest.php @@ -23,16 +23,20 @@ public function authorize(): Response public function rules(): array { return [ - 'tab' => ['nullable', 'string', 'in:commits,mentions'], + 'tab' => ['nullable', 'string', 'in:commits,mentions,people'], ]; } /** - * The organization's own commits first, then the commits that mention it. + * The organization's own commits first, then the commits that mention it, then its people when its admins show them. */ public function tab(): string { - return $this->string('tab')->value() === 'mentions' ? 'mentions' : 'commits'; + return match ($this->string('tab')->value()) { + 'mentions' => 'mentions', + 'people' => $this->organization()?->shows_people === true ? 'people' : 'commits', + default => 'commits', + }; } /** diff --git a/app/Http/Requests/UpdateOrganizationPeopleVisibilityRequest.php b/app/Http/Requests/UpdateOrganizationPeopleVisibilityRequest.php new file mode 100644 index 0000000000..78cff023ce --- /dev/null +++ b/app/Http/Requests/UpdateOrganizationPeopleVisibilityRequest.php @@ -0,0 +1,42 @@ +user(); + assert($user instanceof User); + + $organization = $this->route('organization'); + assert($organization instanceof Organization); + + return $organization->isAdmin($user) ? Response::allow() : Response::denyAsNotFound(); + } + + /** + * @return array> + */ + public function rules(): array + { + return [ + 'shows_people' => ['required', 'boolean'], + ]; + } + + public function showsPeople(): bool + { + return $this->boolean('shows_people'); + } +} diff --git a/app/Models/Organization.php b/app/Models/Organization.php index 26471fe23f..9dc58db591 100644 --- a/app/Models/Organization.php +++ b/app/Models/Organization.php @@ -29,6 +29,7 @@ * @property-read CarbonInterface|null $github_synced_at * @property-read int|null $preferred_lane * @property-read string|null $lane_color + * @property-read bool $shows_people * @property-read CarbonInterface $created_at * @property-read CarbonInterface $updated_at * @property-read Profile $profile @@ -69,6 +70,7 @@ public function casts(): array 'id' => 'string', 'preferred_lane' => 'integer', 'lane_color' => 'string', + 'shows_people' => 'boolean', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; diff --git a/app/Queries/OrganizationPeopleQuery.php b/app/Queries/OrganizationPeopleQuery.php new file mode 100644 index 0000000000..e7c95feedd --- /dev/null +++ b/app/Queries/OrganizationPeopleQuery.php @@ -0,0 +1,59 @@ + + */ + 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 + */ + 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; + } +} diff --git a/database/migrations/2026_11_06_200000_add_shows_people_to_organizations_table.php b/database/migrations/2026_11_06_200000_add_shows_people_to_organizations_table.php new file mode 100644 index 0000000000..32c18b24a9 --- /dev/null +++ b/database/migrations/2026_11_06_200000_add_shows_people_to_organizations_table.php @@ -0,0 +1,21 @@ +boolean('shows_people')->default(false); + }); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 9f49cf06e3..50d8a4659d 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -82,9 +82,10 @@ public function run(): void } /** - * Two GitHub organizations, as if someone had mentioned them: /dev/null, which the local developer manages, and - * Laravel, which they follow. Their pages list threads that mention them, and the commits they post, through their - * members, reach the Following log of whoever follows them. + * Two GitHub organizations, as if someone had mentioned them: /dev/null, which the local developer manages and whose + * page shows its people, and Laravel, which they follow and whose page keeps them hidden. Their pages list threads + * that mention them, and the commits they post, through their members, reach the Following log of whoever follows + * them. * * @param Collection $users */ @@ -98,6 +99,7 @@ private function seedOrganizations(User $localDeveloper, Collection $users): voi $localDeveloper->id => ['role' => OrganizationRole::Admin], ...array_fill_keys([$maintainer->id, $contributor->id, $reviewer->id], ['role' => OrganizationRole::Member]), ]); + $devNull->update(['shows_people' => true]); $devNull->followers()->syncWithoutDetaching($users->take(5)->modelKeys()); $laravel->admins()->syncWithoutDetaching([$artisan->id]); $laravel->followers()->syncWithoutDetaching([$localDeveloper->id, $maintainer->id]); diff --git a/resources/js/pages/organization-profile/edit.tsx b/resources/js/pages/organization-profile/edit.tsx index a609e77ccb..57342e5975 100644 --- a/resources/js/pages/organization-profile/edit.tsx +++ b/resources/js/pages/organization-profile/edit.tsx @@ -1,20 +1,62 @@ import { Form, Head, router } from '@inertiajs/react'; +import { Eye, EyeOff } from 'lucide-react'; import type { CSSProperties } from 'react'; -import { useState } from 'react'; +import { useRef, useState } from 'react'; import OrganizationLaneController from '@/actions/App/Http/Controllers/OrganizationLaneController'; +import OrganizationPeopleVisibilityController from '@/actions/App/Http/Controllers/OrganizationPeopleVisibilityController'; import Heading from '@/components/heading'; import InputError from '@/components/input-error'; import { LaneOptions } from '@/components/lane-picker'; import { OrganizationAvatar } from '@/components/organization-avatar'; +import { SegmentedControl } from '@/components/segmented-control'; import { Button } from '@/components/ui/button'; +import { usePicked } from '@/hooks/use-picked'; import AppLayout from '@/layouts/app-layout'; import OrganizationSettingsLayout from '@/layouts/organization-settings/layout'; import { organizationLaneColor, withViewTransition } from '@/lib/utils'; import type { Lane, Organization } from '@/types'; -export default function Edit({ organization }: { organization: Organization }) { +export default function Edit({ + organization, + showsPeople, +}: { + organization: Organization; + showsPeople: boolean; +}) { const { lane } = organization; const [selected, setSelected] = useState(lane); + const { picked, pick } = usePicked(); + const peopleShown = picked ?? showsPeople; + // One visibility write at a time, so the server can't save an older pick after a newer one. + const pending = useRef(false); + + const selectPeopleShown = (value: boolean): void => { + if (value === peopleShown || pending.current) { + return; + } + + pending.current = true; + let finish = (): void => {}; + + void withViewTransition(() => { + finish = pick(value); + }).then(() => + router.put( + OrganizationPeopleVisibilityController.update.url( + organization.id, + ), + { shows_people: value }, + { + preserveScroll: true, + onFinish: () => { + pending.current = false; + finish(); + }, + onSuccess: () => router.flushAll(), + }, + ), + ); + }; return ( <> @@ -98,6 +140,23 @@ export default function Edit({ organization }: { organization: Organization }) { )} + +
+
); } diff --git a/resources/js/pages/organization/show.tsx b/resources/js/pages/organization/show.tsx index c0acd0801c..97cbd9a0d7 100644 --- a/resources/js/pages/organization/show.tsx +++ b/resources/js/pages/organization/show.tsx @@ -1,11 +1,11 @@ -import { Head, Link, usePage } from '@inertiajs/react'; +import { Head, InfiniteScroll, Link, router, usePage } from '@inertiajs/react'; import { AlertCircleIcon, Flag, Link2, MapPin, Settings } from 'lucide-react'; import type { CSSProperties } from 'react'; -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import { show } from '@/actions/App/Http/Controllers/UserController'; import { BioText } from '@/components/bio-text'; import { CommitFeed, EmptyFeed } from '@/components/commit-feed'; -import { useIsFollowing } from '@/components/follow-button'; +import { FollowButton, useIsFollowing } from '@/components/follow-button'; import { GitHubIcon } from '@/components/github-icon'; import { OrganizationAvatar } from '@/components/organization-avatar'; import { OrganizationFollowButton } from '@/components/organization-follow-button'; @@ -13,16 +13,118 @@ import { PageTabs } from '@/components/page-tabs'; import { ProfileShareButton } from '@/components/profile-share-button'; import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'; import { Button } from '@/components/ui/button'; +import { Spinner } from '@/components/ui/spinner'; import { UserAvatar } from '@/components/user-avatar'; import AppLayout from '@/layouts/app-layout'; import { exactCountTitle, formatCount } from '@/lib/numbers'; -import { organizationLaneColor } from '@/lib/utils'; +import { laneColor, organizationLaneColor } from '@/lib/utils'; import type { Commit, CursorPaginated, Organization, User } from '@/types'; +type Person = User & { is_followed?: boolean; follows_you?: boolean }; + +function People({ + organization, + people, +}: { + organization: Organization; + people: CursorPaginated; +}) { + const { auth } = usePage().props; + + if (people.data.length === 0) { + return ( +
+ + Nobody you can see is a member of @{organization.handle}{' '} + yet. + +
+ ); + } + + return ( + + + + } + > +
    + {people.data.map((person) => ( +
  • + + +
    +

    + {person.name} +

    +
    +

    + @{person.handle} +

    + {person.follows_you && ( + + Follows you + + )} +
    + {person.bio && ( +

    + {person.bio} +

    + )} +
    + + {auth.user && person.id !== auth.user.id && ( + router.flushAll()} + /> + )} +
  • + ))} +
+
+ ); +} + export default function Show({ organization, tab, commits, + people, + showsPeople, claimUrl, settingsUrl, admins, @@ -30,8 +132,10 @@ export default function Show({ isFollowing, }: { organization: Organization; - tab: 'commits' | 'mentions'; - commits: CursorPaginated; + tab: 'commits' | 'mentions' | 'people'; + commits?: CursorPaginated; + people?: CursorPaginated; + showsPeople: boolean; claimUrl: string; settingsUrl: string | null; admins: User[]; @@ -40,6 +144,20 @@ export default function Show({ }) { const { props, flash } = usePage(); const { auth } = props; + const showingPeople = tab === 'people' && showsPeople; + + // Admins hid the people while they were open, so the page moves to the organization's commits... + useEffect(() => { + if (tab === 'people' && !showsPeople) { + router.visit(show(organization), { + only: ['tab', 'commits', 'people'], + reset: ['commits', 'people'], + preserveScroll: true, + replace: true, + }); + } + }, [tab, showsPeople, organization]); + // Kept until the user leaves the page, as the background reloads bring no flash and would hide it. Claiming // redirects back here, so its links don't preserve state, or this would keep the value from before the claim. const [claimFailed] = useState(flash.claimFailed); @@ -275,8 +393,8 @@ export default function Show({ - - Nobody has mentioned @{organization.handle} yet. - Mention it in a commit and it shows up here. - - ) : ( - - @{organization.handle} hasn't committed anything - yet. - - ) - } - /> + {showingPeople && people ? ( + + ) : commits ? ( + + Nobody has mentioned @{organization.handle}{' '} + yet. Mention it in a commit and it shows up + here. + + ) : ( + + @{organization.handle} hasn't committed + anything yet. + + ) + } + /> + ) : null} ); diff --git a/routes/web.php b/routes/web.php index 15be6e4484..4779170074 100644 --- a/routes/web.php +++ b/routes/web.php @@ -97,6 +97,7 @@ use App\Http\Controllers\OrganizationLaneController; use App\Http\Controllers\OrganizationMemberController; use App\Http\Controllers\OrganizationMentionController; +use App\Http\Controllers\OrganizationPeopleVisibilityController; use App\Http\Controllers\OrganizationProfileController; use App\Http\Controllers\OrganizationSitemapController; use App\Http\Controllers\OrgArchiveController; @@ -443,6 +444,9 @@ Route::put('organizations/{organization}/settings/lane', [OrganizationLaneController::class, 'update']) ->whereUuid('organization') ->name('organization-lane.update'); + Route::put('organizations/{organization}/settings/people', [OrganizationPeopleVisibilityController::class, 'update']) + ->whereUuid('organization') + ->name('organization-people-visibility.update'); // Followers the viewer knows... Route::get('@{user:handle}/followers-you-know', [UserFollowersYouKnowController::class, 'index']) diff --git a/tests/Feature/Controllers/OrganizationControllerTest.php b/tests/Feature/Controllers/OrganizationControllerTest.php index 737bc08d22..13871d8dd7 100644 --- a/tests/Feature/Controllers/OrganizationControllerTest.php +++ b/tests/Feature/Controllers/OrganizationControllerTest.php @@ -244,3 +244,97 @@ $this->get('/@laravel?user[]=a&user[]=b')->assertRedirect('/@Laravel?user[]=a&user[]=b'); $this->get('/@laravel?tag=one&tag=two')->assertRedirect('/@Laravel?tag=one&tag=two'); }); + +it('keeps the people of an organization off its page until its admins show them', function (): void { + $organization = Organization::factory()->create(['handle' => 'laravel']); + $organization->members()->attach(User::factory()->create()->id, ['role' => OrganizationRole::Member]); + + $this->get('/@laravel?tab=people') + ->assertOk() + ->assertInertia(fn ($page) => $page + ->component('organization/show') + ->where('showsPeople', false) + ->where('tab', 'commits') + ->has('commits') + ->missing('people')); +}); + +it('lists the people of an organization, first joined first, to guests too', function (): void { + $organization = Organization::factory()->create(['handle' => 'laravel', 'shows_people' => true]); + [$admin, $member] = User::factory()->count(2)->create()->all(); + $organization->members()->attach($admin->id, ['role' => OrganizationRole::Admin, 'created_at' => now()->subDay()]); + $organization->members()->attach($member->id, ['role' => OrganizationRole::Member, 'created_at' => now()]); + + $this->get('/@laravel?tab=people') + ->assertOk() + ->assertInertia(fn ($page) => $page + ->component('organization/show') + ->where('showsPeople', true) + ->where('tab', 'people') + ->missing('commits') + ->has('people.data', 2) + ->where('people.data.0.id', $admin->id) + ->where('people.data.1.id', $member->id) + ->missing('people.data.0.pivot')); +}); + +it('lists the people of an organization without anyone across a block or muted, with whether the viewer follows them', function (): void { + $organization = Organization::factory()->create(['handle' => 'laravel', 'shows_people' => true]); + $viewer = User::factory()->create(); + [$followed, $fan, $muted, $blocked, $blocker] = User::factory()->count(5)->create()->all(); + collect([$followed, $fan, $muted, $blocked, $blocker])->each(fn (User $user, int $index) => $organization->members()->attach($user->id, [ + 'role' => OrganizationRole::Member, + 'created_at' => now()->subMinutes(5 - $index), + ])); + $viewer->following()->attach($followed); + $fan->following()->attach($viewer); + $viewer->muting()->attach($muted); + $viewer->blocking()->attach($blocked); + $blocker->blocking()->attach($viewer); + + $this->actingAs($viewer)->get('/@laravel?tab=people') + ->assertOk() + ->assertInertia(fn ($page) => $page + ->has('people.data', 2) + ->where('people.data.0.id', $followed->id) + ->where('people.data.0.is_followed', true) + ->where('people.data.0.follows_you', false) + ->where('people.data.1.id', $fan->id) + ->where('people.data.1.is_followed', false) + ->where('people.data.1.follows_you', true)); +}); + +it('pages through the people of an organization, first joined first, with the tab in the link to the next page', function (): void { + $organization = Organization::factory()->create(['handle' => 'laravel', 'shows_people' => true]); + $people = User::factory()->count(31)->create(); + $people->each(fn (User $person, int $index) => $organization->members()->attach($person->id, [ + 'role' => OrganizationRole::Member, + 'created_at' => now()->subMinutes(31 - $index), + ])); + + $nextPageUrl = null; + + $this->get('/@laravel?tab=people') + ->assertOk() + ->assertInertia(function ($page) use ($people, &$nextPageUrl): void { + $page->has('people.data', 30) + ->where('people.data.0.id', $people->first()->id) + ->where('people.next_page_url', function (string $url) use (&$nextPageUrl): bool { + $nextPageUrl = $url; + + return str_contains($url, 'tab=people'); + }); + }); + + $this->get($nextPageUrl) + ->assertOk() + ->assertInertia(fn ($page) => $page + ->has('people.data', 1) + ->where('people.data.0.id', $people->last()->id) + ->missing('people.data.0.pivot')); + + // Once its admins hide the people, that link leads to the commits, without the cursor only the people can read. + $organization->update(['shows_people' => false]); + + $this->get($nextPageUrl)->assertRedirect('/@laravel'); +}); diff --git a/tests/Feature/Controllers/OrganizationPeopleVisibilityControllerTest.php b/tests/Feature/Controllers/OrganizationPeopleVisibilityControllerTest.php new file mode 100644 index 0000000000..6d2d96e993 --- /dev/null +++ b/tests/Feature/Controllers/OrganizationPeopleVisibilityControllerTest.php @@ -0,0 +1,70 @@ +create()->refresh()->shows_people)->toBeFalse(); +}); + +it('lets an admin show and hide the people of the organization, updating its page live', function (bool $showsPeople, string $message): void { + $user = User::factory()->create(); + $organization = Organization::factory()->create(['handle' => 'laravel', 'shows_people' => ! $showsPeople]); + $organization->admins()->attach($user->id); + Event::fake([ProfilesUpdated::class]); + + $this->actingAs($user) + ->from('/@laravel') + ->put(route('organization-people-visibility.update', $organization), ['shows_people' => $showsPeople]) + ->assertRedirect('/@laravel') + ->assertSessionHasNoErrors() + ->assertInertiaFlash('toast', ['type' => 'success', 'message' => $message]); + + expect($organization->refresh()->shows_people)->toBe($showsPeople); + Event::assertDispatched(ProfilesUpdated::class); +})->with([ + 'show' => [true, 'People are shown on the page.'], + 'hide' => [false, 'People are hidden from the page.'], +]); + +it('requires a yes or no', function (array $input): void { + $user = User::factory()->create(); + $organization = Organization::factory()->create(); + $organization->admins()->attach($user->id); + + $this->actingAs($user) + ->put(route('organization-people-visibility.update', $organization), $input) + ->assertSessionHasErrors('shows_people'); + + expect($organization->refresh()->shows_people)->toBeFalse(); +})->with([ + 'missing' => [[]], + 'not a boolean' => [['shows_people' => 'maybe']], +]); + +it('hides the setting from members who are not admins, and from everyone else', function (): void { + $organization = Organization::factory()->create(); + $member = User::factory()->create(); + $organization->members()->attach($member->id, ['role' => OrganizationRole::Member]); + + $this->actingAs($member) + ->put(route('organization-people-visibility.update', $organization), ['shows_people' => true]) + ->assertNotFound(); + $this->actingAs(User::factory()->create()) + ->put(route('organization-people-visibility.update', $organization), ['shows_people' => true]) + ->assertNotFound(); + + expect($organization->refresh()->shows_people)->toBeFalse(); +}); + +it('requires authentication', function (): void { + $organization = Organization::factory()->create(); + + $this->put(route('organization-people-visibility.update', $organization), ['shows_people' => true]) + ->assertRedirectToRoute('home'); +}); diff --git a/tests/Feature/Controllers/OrganizationProfileControllerTest.php b/tests/Feature/Controllers/OrganizationProfileControllerTest.php index ae74ea7022..db72508603 100644 --- a/tests/Feature/Controllers/OrganizationProfileControllerTest.php +++ b/tests/Feature/Controllers/OrganizationProfileControllerTest.php @@ -6,7 +6,7 @@ use App\Models\Organization; use App\Models\User; -it('shows admins the profile of the organization in its settings, with its color', function (): void { +it('shows admins the profile of the organization in its settings, with its color and whether it shows its people', function (): void { $user = User::factory()->create(); $organization = Organization::factory()->create(['lane_color' => '#1a2b3c']); $organization->admins()->attach($user->id); @@ -19,7 +19,8 @@ ->where('organization.id', $organization->id) ->where('role', 'admin') ->where('organization.lane', '#1a2b3c') - ->missing('organization.lane_color')); + ->missing('organization.lane_color') + ->where('showsPeople', false)); }); it('hides the profile settings from members who are not admins, and from everyone else', function (): void { diff --git a/tests/Feature/DatabaseSeederTest.php b/tests/Feature/DatabaseSeederTest.php index 773d89cd71..69be72fc41 100644 --- a/tests/Feature/DatabaseSeederTest.php +++ b/tests/Feature/DatabaseSeederTest.php @@ -142,6 +142,8 @@ ->and($laravel->profile->only(['github_id', 'avatar_url']))->toBe(['github_id' => '958072', 'avatar_url' => 'https://avatars.githubusercontent.com/u/958072?v=4']) ->and($devNull->roleOf($localDeveloper))->toBe(OrganizationRole::Admin) ->and($devNull->members()->count())->toBe(4) + ->and($devNull->shows_people)->toBeTrue() + ->and($laravel->shows_people)->toBeFalse() ->and($devNull->followers()->count())->toBe(5) ->and($laravel->roleOf($localDeveloper))->toBeNull() ->and($laravel->admins()->count())->toBe(1)