Repository navigation
Require signed-in users to accept terms and privacy policy #1239
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
Closed
Closed
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,24 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Controllers; | ||
|
|
||
| use App\Actions\UpdateUserTermsAcceptance; | ||
| use App\Http\Requests\UpdateUserTermsRequest; | ||
| use App\Models\User; | ||
| use Illuminate\Container\Attributes\CurrentUser; | ||
| use Illuminate\Http\RedirectResponse; | ||
|
|
||
| final readonly class UserTermsController | ||
| { | ||
| /** | ||
| * Records that the person accepted the terms and privacy policy in the dialog the web shows until they do. | ||
| */ | ||
| public function update(UpdateUserTermsRequest $request, #[CurrentUser] User $user, UpdateUserTermsAcceptance $action): RedirectResponse | ||
| { | ||
| $action->handle($user); | ||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Requests; | ||
|
|
||
| use Illuminate\Foundation\Http\FormRequest; | ||
| use Illuminate\Validation\Rule; | ||
|
|
||
| /** | ||
| * The page says which version of the terms the person was shown, so a tab left open across a new version can't accept | ||
| * one it never showed them. | ||
| */ | ||
| final class UpdateUserTermsRequest extends FormRequest | ||
| { | ||
| public function authorize(): bool | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * @return array<string, list<mixed>> | ||
| */ | ||
| public function rules(): array | ||
| { | ||
| return [ | ||
| 'version' => ['required', 'string', Rule::in([config('legal.terms_version')])], | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @return array<string, string> | ||
| */ | ||
| public function messages(): array | ||
| { | ||
| return [ | ||
| 'version.in' => 'The terms changed while this page was open. Reload the page to read the new version.', | ||
| ]; | ||
| } | ||
| } |
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,129 @@ | ||
| import { Form, Link, router, usePage } from '@inertiajs/react'; | ||
| import PrivacyController from '@/actions/App/Http/Controllers/PrivacyController'; | ||
| import TermsController from '@/actions/App/Http/Controllers/TermsController'; | ||
| import UserTermsController from '@/actions/App/Http/Controllers/UserTermsController'; | ||
| import InputError from '@/components/input-error'; | ||
| import { Button } from '@/components/ui/button'; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogTitle, | ||
| } from '@/components/ui/dialog'; | ||
| import { WordmarkText } from '@/components/wordmark-text'; | ||
| import { clearRecentSearches } from '@/hooks/use-recent-searches'; | ||
| import { clearStashes } from '@/hooks/use-stash'; | ||
| import { TERMS_EFFECTIVE_DATE } from '@/lib/legal'; | ||
| import { logout } from '@/routes'; | ||
|
|
||
| /** | ||
| * Until they accept the terms and privacy policy in force, a signed-in person can't use the web: the dialog can't be | ||
| * dismissed, and a new version brings it back. The terms and privacy pages open in a new tab, where it isn't shown. | ||
| */ | ||
| export function TermsDialog() { | ||
| const { component, props } = usePage(); | ||
| const { user, termsToAccept } = props.auth; | ||
|
|
||
| if ( | ||
| user === null || | ||
| termsToAccept === null || | ||
| component === 'terms/show' || | ||
| component === 'privacy/show' | ||
| ) { | ||
| return null; | ||
| } | ||
|
|
||
| const linkClassName = 'text-foreground underline underline-offset-4'; | ||
|
|
||
| return ( | ||
| <Dialog open> | ||
| <DialogContent | ||
| showCloseButton={false} | ||
| onEscapeKeyDown={(event) => event.preventDefault()} | ||
| onInteractOutside={(event) => event.preventDefault()} | ||
| data-test="terms-dialog" | ||
| > | ||
| <DialogTitle> | ||
| {termsToAccept.updated | ||
| ? 'We updated our terms' | ||
| : 'Terms and privacy'} | ||
| </DialogTitle> | ||
| <DialogDescription asChild> | ||
| <div className="grid gap-3"> | ||
| <p> | ||
| <WordmarkText> | ||
| {termsToAccept.updated | ||
| ? `The terms of service and the privacy policy changed on ${TERMS_EFFECTIVE_DATE}. To keep using /dev/null, read them and accept them.` | ||
| : 'To keep using /dev/null, read and accept the terms of service and the privacy policy.'} | ||
| </WordmarkText> | ||
| </p> | ||
| <p> | ||
| Read the{' '} | ||
| <Link | ||
| href={TermsController.show.url()} | ||
| target="_blank" | ||
| className={linkClassName} | ||
| > | ||
| terms of service | ||
| </Link>{' '} | ||
| and the{' '} | ||
| <Link | ||
| href={PrivacyController.show.url()} | ||
| target="_blank" | ||
| className={linkClassName} | ||
| > | ||
| privacy policy | ||
| </Link> | ||
| . | ||
| </p> | ||
| </div> | ||
| </DialogDescription> | ||
|
|
||
| <Form | ||
| {...UserTermsController.update.form()} | ||
| options={{ preserveScroll: true, preserveState: true }} | ||
| className="grid gap-4" | ||
| > | ||
| {({ processing, errors }) => ( | ||
| <> | ||
| <input | ||
| type="hidden" | ||
| name="version" | ||
| value={termsToAccept.version} | ||
| /> | ||
| <InputError message={errors.version} /> | ||
| <DialogFooter className="gap-2"> | ||
| <Button | ||
| variant="outline" | ||
| asChild | ||
| disabled={processing} | ||
| > | ||
| <Link | ||
| href={logout()} | ||
| as="button" | ||
| type="button" | ||
| onClick={() => { | ||
| clearStashes(user.id); | ||
| clearRecentSearches(user.id); | ||
| router.flushAll(); | ||
| }} | ||
| > | ||
| Log out | ||
| </Link> | ||
| </Button> | ||
| <Button | ||
| type="submit" | ||
| disabled={processing} | ||
| data-test="accept-terms-button" | ||
| > | ||
| I accept | ||
| </Button> | ||
| </DialogFooter> | ||
| </> | ||
| )} | ||
| </Form> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } | ||
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
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
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.
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.
Clear drafts only after logout succeeds.
If the logout request fails or is cancelled,
onClickhas already calledclearStashes(user.id). That helper deletes stored draft text and images, while the user remains signed in. Move the cleanup to the successful logout path so a failed request does not destroy drafts. (raw.githubusercontent.com)