mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-16 09:43:18 +01:00
Compare commits
16 Commits
feature/bi
...
c45d6e2f5e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c45d6e2f5e | ||
|
|
5b12c09747 | ||
|
|
24023353f2 | ||
|
|
720d20c10e | ||
|
|
82ea9af8b5 | ||
|
|
169d522da0 | ||
|
|
45c7377802 | ||
|
|
8e57275cef | ||
|
|
efc6b55628 | ||
|
|
c12789376d | ||
|
|
4795812b60 | ||
|
|
0e00979ab8 | ||
|
|
f1426fcb5e | ||
|
|
23f512d4a4 | ||
|
|
637475e669 | ||
|
|
3ec2abb309 |
@@ -5,7 +5,8 @@ APP_KEY=base64:UNQNf1SXeASNkWux01Rj8EnHYx8FO0kAxWNDwktclkk=
|
|||||||
APP_DEBUG=true
|
APP_DEBUG=true
|
||||||
APP_URL=https://solidtime.test
|
APP_URL=https://solidtime.test
|
||||||
APP_FORCE_HTTPS=false
|
APP_FORCE_HTTPS=false
|
||||||
APP_ENABLE_REGISTRATION=true
|
# Supported values: on, off, invite-only (true/false are supported for backwards compatibility)
|
||||||
|
APP_ENABLE_REGISTRATION=on
|
||||||
SUPER_ADMINS=admin@example.com
|
SUPER_ADMINS=admin@example.com
|
||||||
PAGINATION_PER_PAGE_DEFAULT=500
|
PAGINATION_PER_PAGE_DEFAULT=500
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Actions\Fortify;
|
namespace App\Actions\Fortify;
|
||||||
|
|
||||||
|
use App\Enums\RegistrationMode;
|
||||||
use App\Enums\Weekday;
|
use App\Enums\Weekday;
|
||||||
use App\Events\NewsletterRegistered;
|
use App\Events\NewsletterRegistered;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Service\InvitationService;
|
||||||
use App\Service\IpLookup\IpLookupServiceContract;
|
use App\Service\IpLookup\IpLookupServiceContract;
|
||||||
use App\Service\TimezoneService;
|
use App\Service\TimezoneService;
|
||||||
use App\Service\UserService;
|
use App\Service\UserService;
|
||||||
@@ -31,13 +33,14 @@ class CreateNewUser implements CreatesNewUsers
|
|||||||
*/
|
*/
|
||||||
public function create(array $input): User
|
public function create(array $input): User
|
||||||
{
|
{
|
||||||
if (! config('app.enable_registration')) {
|
$registrationMode = RegistrationMode::fromConfig(config('app.enable_registration'));
|
||||||
|
if ($registrationMode === RegistrationMode::Off) {
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'email' => [__('Registration is disabled.')],
|
'email' => [__('Registration is disabled.')],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Validator::make($input, [
|
$validated = Validator::make($input, [
|
||||||
'name' => [
|
'name' => [
|
||||||
'required',
|
'required',
|
||||||
'string',
|
'string',
|
||||||
@@ -60,6 +63,20 @@ class CreateNewUser implements CreatesNewUsers
|
|||||||
],
|
],
|
||||||
])->validate();
|
])->validate();
|
||||||
|
|
||||||
|
if ($registrationMode === RegistrationMode::InviteOnly) {
|
||||||
|
$invitationService = app(InvitationService::class);
|
||||||
|
$email = (string) $validated['email'];
|
||||||
|
if (! $invitationService->hasAcceptedInvitationForEmail($email)) {
|
||||||
|
$message = $invitationService->hasPendingInvitationForEmail($email)
|
||||||
|
? __('Please accept the organization invitation sent to your email address before registering.')
|
||||||
|
: __('Registration is only available to invited users.');
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'email' => [$message],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$timezone = null;
|
$timezone = null;
|
||||||
if (array_key_exists('timezone', $input) && is_string($input['timezone'])) {
|
if (array_key_exists('timezone', $input) && is_string($input['timezone'])) {
|
||||||
if (app(TimezoneService::class)->isValid($input['timezone'])) {
|
if (app(TimezoneService::class)->isValid($input['timezone'])) {
|
||||||
|
|||||||
29
app/Enums/RegistrationMode.php
Normal file
29
app/Enums/RegistrationMode.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum RegistrationMode: string
|
||||||
|
{
|
||||||
|
case On = 'on';
|
||||||
|
case InviteOnly = 'invite-only';
|
||||||
|
case Off = 'off';
|
||||||
|
|
||||||
|
public static function fromConfig(mixed $value): self
|
||||||
|
{
|
||||||
|
if ($value === true) {
|
||||||
|
return self::On;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value === false || $value === null) {
|
||||||
|
return self::Off;
|
||||||
|
}
|
||||||
|
|
||||||
|
return match (strtolower(trim((string) $value))) {
|
||||||
|
'1', 'on', 'true' => self::On,
|
||||||
|
'invite-only' => self::InviteOnly,
|
||||||
|
default => self::Off,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,6 +36,7 @@ class OrganizationInvitationController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
return redirect(route('register'))
|
return redirect(route('register'))
|
||||||
|
->with('registration_email', $email)
|
||||||
->with('bannerText', __('Please create an account to finish joining the :organization organization.', [
|
->with('bannerText', __('Please create an account to finish joining the :organization organization.', [
|
||||||
'organization' => $organization->name,
|
'organization' => $organization->name,
|
||||||
]))
|
]))
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ class FortifyServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
Fortify::registerView(function () {
|
Fortify::registerView(function () {
|
||||||
return Inertia::render('Auth/Register', [
|
return Inertia::render('Auth/Register', [
|
||||||
|
'email' => session('registration_email', ''),
|
||||||
'terms_url' => config('auth.terms_url'),
|
'terms_url' => config('auth.terms_url'),
|
||||||
'privacy_policy_url' => config('auth.privacy_policy_url'),
|
'privacy_policy_url' => config('auth.privacy_policy_url'),
|
||||||
'newsletter_consent' => config('auth.newsletter_consent'),
|
'newsletter_consent' => config('auth.newsletter_consent'),
|
||||||
|
|||||||
@@ -18,6 +18,22 @@ use Illuminate\Support\Facades\Mail;
|
|||||||
|
|
||||||
class InvitationService
|
class InvitationService
|
||||||
{
|
{
|
||||||
|
public function hasAcceptedInvitationForEmail(string $email): bool
|
||||||
|
{
|
||||||
|
return OrganizationInvitation::query()
|
||||||
|
->whereRaw('lower(email) = ?', [strtolower($email)])
|
||||||
|
->whereNotNull('accepted_at')
|
||||||
|
->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasPendingInvitationForEmail(string $email): bool
|
||||||
|
{
|
||||||
|
return OrganizationInvitation::query()
|
||||||
|
->whereRaw('lower(email) = ?', [strtolower($email)])
|
||||||
|
->whereNull('accepted_at')
|
||||||
|
->exists();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws UserIsAlreadyMemberOfOrganizationApiException|InvitationForTheEmailAlreadyExistsApiException
|
* @throws UserIsAlreadyMemberOfOrganizationApiException|InvitationForTheEmailAlreadyExistsApiException
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
"ext-zip": "*",
|
"ext-zip": "*",
|
||||||
"brick/money": "^0.10.0",
|
"brick/money": "^0.10.0",
|
||||||
"datomatic/laravel-enum-helper": "^2.0.0",
|
"datomatic/laravel-enum-helper": "^2.0.0",
|
||||||
"dedoc/scramble": "^0.12.2",
|
"dedoc/scramble": "^0.13.43",
|
||||||
"filament/filament": "^3.2",
|
"filament/filament": "^3.2",
|
||||||
"flowframe/laravel-trend": "^0.4.0",
|
"flowframe/laravel-trend": "^0.5.0",
|
||||||
"gotenberg/gotenberg-php": "^2.8",
|
"gotenberg/gotenberg-php": "^2.8",
|
||||||
"guzzlehttp/guzzle": "^7.2",
|
"guzzlehttp/guzzle": "^7.2",
|
||||||
"inertiajs/inertia-laravel": "^2.0.3",
|
"inertiajs/inertia-laravel": "^2.0.3",
|
||||||
|
|||||||
1461
composer.lock
generated
1461
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -100,7 +100,7 @@ return [
|
|||||||
|
|
||||||
'force_https' => (bool) env('APP_FORCE_HTTPS', false),
|
'force_https' => (bool) env('APP_FORCE_HTTPS', false),
|
||||||
|
|
||||||
'enable_registration' => (bool) env('APP_ENABLE_REGISTRATION', false),
|
'enable_registration' => env('APP_ENABLE_REGISTRATION', 'off'),
|
||||||
|
|
||||||
'local_email_verification' => (bool) env('APP_LOCAL_EMAIL_VERIFICATION', false),
|
'local_email_verification' => (bool) env('APP_LOCAL_EMAIL_VERIFICATION', false),
|
||||||
|
|
||||||
|
|||||||
32
e2e/invitation-registration-prefill.spec.ts
Normal file
32
e2e/invitation-registration-prefill.spec.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { expect, test } from '../playwright/fixtures';
|
||||||
|
import { PLAYWRIGHT_BASE_URL } from '../playwright/config';
|
||||||
|
import { getInvitationAcceptUrl } from './utils/mailpit';
|
||||||
|
|
||||||
|
test('prefills the registration email after accepting an invitation', async ({ page, browser }) => {
|
||||||
|
const memberId = `${Date.now()}-${Math.floor(Math.random() * 100000)}`;
|
||||||
|
const memberEmail = `prefill-${memberId}@invitation.test`;
|
||||||
|
|
||||||
|
await page.goto(PLAYWRIGHT_BASE_URL + '/members');
|
||||||
|
await page.getByRole('button', { name: 'Invite Member' }).click();
|
||||||
|
await page.getByPlaceholder('Member Email').fill(memberEmail);
|
||||||
|
await page.getByRole('button', { name: 'Employee' }).click();
|
||||||
|
await Promise.all([
|
||||||
|
page.waitForResponse(
|
||||||
|
(response) =>
|
||||||
|
response.url().includes('/invitations') &&
|
||||||
|
response.request().method() === 'POST' &&
|
||||||
|
response.status() === 204
|
||||||
|
),
|
||||||
|
page.getByRole('button', { name: 'Invite Member', exact: true }).click(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const inviteeContext = await browser.newContext();
|
||||||
|
const inviteePage = await inviteeContext.newPage();
|
||||||
|
const acceptUrl = await getInvitationAcceptUrl(inviteePage.request, memberEmail);
|
||||||
|
await inviteePage.goto(acceptUrl);
|
||||||
|
await inviteePage.waitForURL(/\/register$/);
|
||||||
|
|
||||||
|
await expect(inviteePage.getByLabel('Email')).toHaveValue(memberEmail);
|
||||||
|
|
||||||
|
await inviteeContext.close();
|
||||||
|
});
|
||||||
@@ -9,6 +9,6 @@
|
|||||||
},
|
},
|
||||||
"Invoicing": {
|
"Invoicing": {
|
||||||
"repository": "solidtime-io/extension-invoicing",
|
"repository": "solidtime-io/extension-invoicing",
|
||||||
"ref": "v0.0.4"
|
"ref": "v0.0.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -8564,7 +8564,7 @@
|
|||||||
},
|
},
|
||||||
"resources/js/packages/ui": {
|
"resources/js/packages/ui": {
|
||||||
"name": "@solidtime/ui",
|
"name": "@solidtime/ui",
|
||||||
"version": "0.0.22",
|
"version": "0.0.23",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chroma-js": "^3.1.2",
|
"@types/chroma-js": "^3.1.2",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { type Client } from '@/packages/api/src';
|
|||||||
import ClientTableRow from '@/Components/Common/Client/ClientTableRow.vue';
|
import ClientTableRow from '@/Components/Common/Client/ClientTableRow.vue';
|
||||||
import ClientCreateModal from '@/Components/Common/Client/ClientCreateModal.vue';
|
import ClientCreateModal from '@/Components/Common/Client/ClientCreateModal.vue';
|
||||||
import ClientTableHeading from '@/Components/Common/Client/ClientTableHeading.vue';
|
import ClientTableHeading from '@/Components/Common/Client/ClientTableHeading.vue';
|
||||||
import Pagination from '@/Components/Common/Pagination.vue';
|
import Pagination from '@/packages/ui/src/Pagination.vue';
|
||||||
import { canCreateClients } from '@/utils/permissions';
|
import { canCreateClients } from '@/utils/permissions';
|
||||||
import { useProjectsQuery } from '@/utils/useProjectsQuery';
|
import { useProjectsQuery } from '@/utils/useProjectsQuery';
|
||||||
import {
|
import {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { computed, ref, watch } from 'vue';
|
|||||||
import ProjectCreateModal from '@/packages/ui/src/Project/ProjectCreateModal.vue';
|
import ProjectCreateModal from '@/packages/ui/src/Project/ProjectCreateModal.vue';
|
||||||
import ProjectTableHeading from '@/Components/Common/Project/ProjectTableHeading.vue';
|
import ProjectTableHeading from '@/Components/Common/Project/ProjectTableHeading.vue';
|
||||||
import ProjectTableRow from '@/Components/Common/Project/ProjectTableRow.vue';
|
import ProjectTableRow from '@/Components/Common/Project/ProjectTableRow.vue';
|
||||||
import Pagination from '@/Components/Common/Pagination.vue';
|
import Pagination from '@/packages/ui/src/Pagination.vue';
|
||||||
import LoadingSpinner from '@/packages/ui/src/LoadingSpinner.vue';
|
import LoadingSpinner from '@/packages/ui/src/LoadingSpinner.vue';
|
||||||
|
|
||||||
export type SortColumn =
|
export type SortColumn =
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ const max = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const backgroundColor = useCssVariable('--theme-color-card-background');
|
const backgroundColor = useCssVariable('--theme-color-card-background');
|
||||||
const borderColor = useCssVariable('--color-border');
|
const borderColor = useCssVariable('--color-border-secondary');
|
||||||
const labelColor = useCssVariable('--color-text-secondary');
|
const labelColor = useCssVariable('--color-text-secondary');
|
||||||
const chartColorRaw = useCssVariable('--theme-color-chart');
|
const chartColorRaw = useCssVariable('--theme-color-chart');
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,13 @@ import { Field, FieldLabel, FieldError } from '@/packages/ui/src/field';
|
|||||||
import PrimaryButton from '@/packages/ui/src/Buttons/PrimaryButton.vue';
|
import PrimaryButton from '@/packages/ui/src/Buttons/PrimaryButton.vue';
|
||||||
import TextInput from '@/packages/ui/src/Input/TextInput.vue';
|
import TextInput from '@/packages/ui/src/Input/TextInput.vue';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
email: string;
|
||||||
|
}>();
|
||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
name: '',
|
name: '',
|
||||||
email: '',
|
email: props.email,
|
||||||
password: '',
|
password: '',
|
||||||
password_confirmation: '',
|
password_confirmation: '',
|
||||||
terms: false,
|
terms: false,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
ArrowDownTrayIcon,
|
ArrowDownTrayIcon,
|
||||||
LockClosedIcon,
|
LockClosedIcon,
|
||||||
} from '@heroicons/vue/20/solid';
|
} from '@heroicons/vue/20/solid';
|
||||||
import Pagination from '@/Components/Common/Pagination.vue';
|
import Pagination from '@/packages/ui/src/Pagination.vue';
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@solidtime/ui",
|
"name": "@solidtime/ui",
|
||||||
"version": "0.0.22",
|
"version": "0.0.23",
|
||||||
"description": "Package containing the solidtime ui components",
|
"description": "Package containing the solidtime ui components",
|
||||||
"main": "./dist/solidtime-ui-lib.umd.cjs",
|
"main": "./dist/solidtime-ui-lib.umd.cjs",
|
||||||
"module": "./dist/solidtime-ui-lib.js",
|
"module": "./dist/solidtime-ui-lib.js",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
CommandShortcut,
|
CommandShortcut,
|
||||||
} from '../command';
|
} from '../command';
|
||||||
import { cn } from '../utils/cn';
|
import { cn } from '../utils/cn';
|
||||||
|
import { useDialogFocusRestore } from '../utils/useDialogFocusRestore';
|
||||||
import type {
|
import type {
|
||||||
CommandPaletteCommand,
|
CommandPaletteCommand,
|
||||||
CommandPaletteGroup,
|
CommandPaletteGroup,
|
||||||
@@ -36,6 +37,8 @@ const emit = defineEmits<{
|
|||||||
select: [command: CommandPaletteCommand | EntitySearchResult];
|
select: [command: CommandPaletteCommand | EntitySearchResult];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
|
||||||
|
|
||||||
// Non-empty groups for rendering
|
// Non-empty groups for rendering
|
||||||
const nonEmptyGroups = computed(() => props.groups.filter((g) => g.commands.length > 0));
|
const nonEmptyGroups = computed(() => props.groups.filter((g) => g.commands.length > 0));
|
||||||
|
|
||||||
@@ -71,7 +74,9 @@ watch(open, (isOpen) => {
|
|||||||
)
|
)
|
||||||
">
|
">
|
||||||
<DialogContent
|
<DialogContent
|
||||||
class="pointer-events-auto bg-default-background w-full max-w-lg border border-border-tertiary shadow-lg sm:rounded-lg outline-none overflow-hidden p-0 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95">
|
class="pointer-events-auto bg-default-background w-full max-w-lg border border-border-tertiary shadow-lg sm:rounded-lg outline-none overflow-hidden p-0 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95"
|
||||||
|
@open-auto-focus="onOpenAutoFocus"
|
||||||
|
@close-auto-focus="onCloseAutoFocus">
|
||||||
<CommandRoot
|
<CommandRoot
|
||||||
v-model:search-term="searchTerm"
|
v-model:search-term="searchTerm"
|
||||||
class="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
|
class="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ import {
|
|||||||
ChevronRightIcon,
|
ChevronRightIcon,
|
||||||
EllipsisHorizontalIcon,
|
EllipsisHorizontalIcon,
|
||||||
} from '@heroicons/vue/20/solid';
|
} from '@heroicons/vue/20/solid';
|
||||||
import { buttonVariants } from '@/packages/ui/src';
|
import { buttonVariants } from './Buttons/index';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from './utils/cn';
|
||||||
import { computed, watch } from 'vue';
|
import { computed, watch } from 'vue';
|
||||||
|
|
||||||
const page = defineModel<number>('page', { default: 1 });
|
const page = defineModel<number>('page', { default: 1 });
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { cn } from '../utils/cn';
|
import { cn } from '../utils/cn';
|
||||||
|
import { useDialogFocusRestore } from '../utils/useDialogFocusRestore';
|
||||||
import {
|
import {
|
||||||
DialogContent,
|
DialogContent,
|
||||||
type DialogContentEmits,
|
type DialogContentEmits,
|
||||||
@@ -20,6 +21,10 @@ const delegatedProps = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
||||||
|
|
||||||
|
// Forwarded consumer listeners run first, so a consumer can still take over
|
||||||
|
// by calling preventDefault() on close-auto-focus.
|
||||||
|
const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -36,7 +41,9 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
|||||||
'my-3 md:my-14 xl:my-24 bg-default-background grid w-full max-w-lg border border-border-tertiary shadow-lg duration-200 rounded-lg outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',
|
'my-3 md:my-14 xl:my-24 bg-default-background grid w-full max-w-lg border border-border-tertiary shadow-lg duration-200 rounded-lg outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',
|
||||||
props.class
|
props.class
|
||||||
)
|
)
|
||||||
">
|
"
|
||||||
|
@open-auto-focus="onOpenAutoFocus"
|
||||||
|
@close-auto-focus="onCloseAutoFocus">
|
||||||
<slot />
|
<slot />
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { cn } from '../utils/cn';
|
import { cn } from '../utils/cn';
|
||||||
|
import { useDialogFocusRestore } from '../utils/useDialogFocusRestore';
|
||||||
import { X } from '@lucide/vue';
|
import { X } from '@lucide/vue';
|
||||||
import {
|
import {
|
||||||
DialogClose,
|
DialogClose,
|
||||||
@@ -22,6 +23,10 @@ const delegatedProps = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
||||||
|
|
||||||
|
// Forwarded consumer listeners run first, so a consumer can still take over
|
||||||
|
// by calling preventDefault() on close-auto-focus.
|
||||||
|
const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -36,6 +41,8 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
|||||||
)
|
)
|
||||||
"
|
"
|
||||||
v-bind="forwarded"
|
v-bind="forwarded"
|
||||||
|
@open-auto-focus="onOpenAutoFocus"
|
||||||
|
@close-auto-focus="onCloseAutoFocus"
|
||||||
@pointer-down-outside="
|
@pointer-down-outside="
|
||||||
(event) => {
|
(event) => {
|
||||||
const originalEvent = event.detail.originalEvent;
|
const originalEvent = event.detail.originalEvent;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import InputLabel from './Input/InputLabel.vue';
|
|||||||
import TextInput from './Input/TextInput.vue';
|
import TextInput from './Input/TextInput.vue';
|
||||||
import LoadingSpinner from './LoadingSpinner.vue';
|
import LoadingSpinner from './LoadingSpinner.vue';
|
||||||
import Modal from './Modal.vue';
|
import Modal from './Modal.vue';
|
||||||
|
import Pagination from './Pagination.vue';
|
||||||
import ProjectBadge from './Project/ProjectBadge.vue';
|
import ProjectBadge from './Project/ProjectBadge.vue';
|
||||||
import TimeEntryCreateModal from './TimeEntry/TimeEntryCreateModal.vue';
|
import TimeEntryCreateModal from './TimeEntry/TimeEntryCreateModal.vue';
|
||||||
import TimeEntryEditModal from './TimeEntry/TimeEntryEditModal.vue';
|
import TimeEntryEditModal from './TimeEntry/TimeEntryEditModal.vue';
|
||||||
@@ -257,6 +258,7 @@ export {
|
|||||||
NumberFieldDecrement,
|
NumberFieldDecrement,
|
||||||
NumberFieldIncrement,
|
NumberFieldIncrement,
|
||||||
NumberFieldInput,
|
NumberFieldInput,
|
||||||
|
Pagination,
|
||||||
Popover,
|
Popover,
|
||||||
PopoverAnchor,
|
PopoverAnchor,
|
||||||
PopoverContent,
|
PopoverContent,
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import { describe, expect, it, vi } from 'vitest';
|
||||||
|
import { useDialogFocusRestore } from './useDialogFocusRestore';
|
||||||
|
|
||||||
|
function closeEvent() {
|
||||||
|
return new CustomEvent('focusScope.autoFocusOnUnmount', { cancelable: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('useDialogFocusRestore', () => {
|
||||||
|
it('restores focus to the element focused when the dialog opened', () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
const button = document.createElement('button');
|
||||||
|
document.body.appendChild(button);
|
||||||
|
button.focus();
|
||||||
|
|
||||||
|
const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
|
||||||
|
onOpenAutoFocus();
|
||||||
|
button.blur();
|
||||||
|
|
||||||
|
const event = closeEvent();
|
||||||
|
onCloseAutoFocus(event);
|
||||||
|
expect(event.defaultPrevented).toBe(true);
|
||||||
|
vi.runAllTimers();
|
||||||
|
expect(document.activeElement).toBe(button);
|
||||||
|
|
||||||
|
button.remove();
|
||||||
|
vi.useRealTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('focuses nothing when the dialog was opened with nothing focused', () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
const stale = document.createElement('button');
|
||||||
|
document.body.appendChild(stale);
|
||||||
|
const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
|
||||||
|
|
||||||
|
// First open from the button, then close
|
||||||
|
stale.focus();
|
||||||
|
onOpenAutoFocus();
|
||||||
|
onCloseAutoFocus(closeEvent());
|
||||||
|
vi.runAllTimers();
|
||||||
|
stale.blur();
|
||||||
|
|
||||||
|
// Second open from the body must not refocus the stale button
|
||||||
|
onOpenAutoFocus();
|
||||||
|
const event = closeEvent();
|
||||||
|
onCloseAutoFocus(event);
|
||||||
|
expect(event.defaultPrevented).toBe(true);
|
||||||
|
vi.runAllTimers();
|
||||||
|
expect(document.activeElement).toBe(document.body);
|
||||||
|
|
||||||
|
stale.remove();
|
||||||
|
vi.useRealTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not restore focus to an element that was removed', () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
const button = document.createElement('button');
|
||||||
|
document.body.appendChild(button);
|
||||||
|
button.focus();
|
||||||
|
const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
|
||||||
|
onOpenAutoFocus();
|
||||||
|
button.remove();
|
||||||
|
|
||||||
|
onCloseAutoFocus(closeEvent());
|
||||||
|
vi.runAllTimers();
|
||||||
|
expect(document.activeElement).toBe(document.body);
|
||||||
|
vi.useRealTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('leaves control to a consumer that already prevented the event', () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
const button = document.createElement('button');
|
||||||
|
document.body.appendChild(button);
|
||||||
|
button.focus();
|
||||||
|
const { onOpenAutoFocus, onCloseAutoFocus } = useDialogFocusRestore();
|
||||||
|
onOpenAutoFocus();
|
||||||
|
button.blur();
|
||||||
|
|
||||||
|
const event = closeEvent();
|
||||||
|
event.preventDefault();
|
||||||
|
onCloseAutoFocus(event);
|
||||||
|
vi.runAllTimers();
|
||||||
|
expect(document.activeElement).toBe(document.body);
|
||||||
|
|
||||||
|
button.remove();
|
||||||
|
vi.useRealTimers();
|
||||||
|
});
|
||||||
|
});
|
||||||
41
resources/js/packages/ui/src/utils/useDialogFocusRestore.ts
Normal file
41
resources/js/packages/ui/src/utils/useDialogFocusRestore.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/**
|
||||||
|
* Restores focus to the element that was focused when a dialog opened.
|
||||||
|
*
|
||||||
|
* reka-ui remembers the active element at content mount as the dialog's
|
||||||
|
* "trigger" (only when it is not the body) and refocuses it on every close,
|
||||||
|
* but it never clears that value. A dialog opened while nothing is focused
|
||||||
|
* (e.g. the command palette via Cmd+K from the body) therefore refocuses
|
||||||
|
* whatever triggered a *previous* open. Bind these handlers to
|
||||||
|
* `DialogContent`'s `open-auto-focus` / `close-auto-focus` events to restore
|
||||||
|
* exactly the previously focused element, or nothing.
|
||||||
|
*
|
||||||
|
* A consumer handler that already called `preventDefault()` on
|
||||||
|
* `close-auto-focus` keeps control; this composable then does nothing.
|
||||||
|
*/
|
||||||
|
export function useDialogFocusRestore() {
|
||||||
|
let previouslyFocused: HTMLElement | null = null;
|
||||||
|
|
||||||
|
function onOpenAutoFocus() {
|
||||||
|
const active = document.activeElement;
|
||||||
|
previouslyFocused =
|
||||||
|
active instanceof HTMLElement && active !== document.body ? active : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCloseAutoFocus(event: Event) {
|
||||||
|
const target = previouslyFocused;
|
||||||
|
previouslyFocused = null;
|
||||||
|
if (event.defaultPrevented) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Prevents both FocusScope's default restore and reka-ui's trigger refocus
|
||||||
|
event.preventDefault();
|
||||||
|
// Same tick reka-ui uses, so the dialog content is fully gone first
|
||||||
|
setTimeout(() => {
|
||||||
|
if (target?.isConnected) {
|
||||||
|
target.focus({ preventScroll: true });
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { onOpenAutoFocus, onCloseAutoFocus };
|
||||||
|
}
|
||||||
@@ -22,6 +22,13 @@ use TiMacDonald\Log\LogEntry;
|
|||||||
|
|
||||||
class RegistrationTest extends TestCaseWithDatabase
|
class RegistrationTest extends TestCaseWithDatabase
|
||||||
{
|
{
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
Config::set('app.enable_registration', 'on');
|
||||||
|
}
|
||||||
|
|
||||||
public function test_registration_screen_can_be_rendered(): void
|
public function test_registration_screen_can_be_rendered(): void
|
||||||
{
|
{
|
||||||
if (! Features::enabled(Features::registration())) {
|
if (! Features::enabled(Features::registration())) {
|
||||||
@@ -89,6 +96,77 @@ class RegistrationTest extends TestCaseWithDatabase
|
|||||||
Event::assertNotDispatched(NewsletterRegistered::class);
|
Event::assertNotDispatched(NewsletterRegistered::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_user_registration_fails_without_an_invitation_if_registration_is_invite_only(): void
|
||||||
|
{
|
||||||
|
Config::set('app.enable_registration', 'invite-only');
|
||||||
|
|
||||||
|
$response = $this->post('/register', [
|
||||||
|
'name' => 'Test User',
|
||||||
|
'email' => 'test@example.com',
|
||||||
|
'password' => 'password',
|
||||||
|
'password_confirmation' => 'password',
|
||||||
|
'terms' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertInvalid([
|
||||||
|
'email' => 'Registration is only available to invited users.',
|
||||||
|
]);
|
||||||
|
$this->assertFalse(User::query()->where('email', 'test@example.com')->exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_invited_user_can_register_if_registration_is_invite_only(): void
|
||||||
|
{
|
||||||
|
Config::set('app.enable_registration', 'invite-only');
|
||||||
|
$user = $this->createUserWithPermission();
|
||||||
|
OrganizationInvitation::factory()
|
||||||
|
->forOrganization($user->organization)
|
||||||
|
->role(Role::Employee)
|
||||||
|
->accepted()
|
||||||
|
->create([
|
||||||
|
'email' => 'Invited.User@example.com',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->post('/register', [
|
||||||
|
'name' => 'Invited User',
|
||||||
|
'email' => 'invited.user@example.com',
|
||||||
|
'password' => 'password',
|
||||||
|
'password_confirmation' => 'password',
|
||||||
|
'terms' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertValid();
|
||||||
|
$this->assertAuthenticated();
|
||||||
|
$response->assertRedirect(RouteServiceProvider::HOME);
|
||||||
|
$newUser = User::query()->where('email', 'invited.user@example.com')->firstOrFail();
|
||||||
|
$this->assertSame($user->organization->getKey(), $newUser->organizations()->firstOrFail()->getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_user_must_accept_pending_invitation_before_registration_if_registration_is_invite_only(): void
|
||||||
|
{
|
||||||
|
Config::set('app.enable_registration', 'invite-only');
|
||||||
|
$user = $this->createUserWithPermission();
|
||||||
|
OrganizationInvitation::factory()
|
||||||
|
->forOrganization($user->organization)
|
||||||
|
->role(Role::Employee)
|
||||||
|
->create([
|
||||||
|
'email' => 'test@example.com',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->post('/register', [
|
||||||
|
'name' => 'Test User',
|
||||||
|
'email' => 'test@example.com',
|
||||||
|
'password' => 'password',
|
||||||
|
'password_confirmation' => 'password',
|
||||||
|
'terms' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertInvalid([
|
||||||
|
'email' => 'Please accept the organization invitation sent to your email address before registering.',
|
||||||
|
]);
|
||||||
|
$this->assertGuest();
|
||||||
|
$this->assertFalse(User::query()->where('email', 'test@example.com')->exists());
|
||||||
|
}
|
||||||
|
|
||||||
public function test_new_user_can_not_register_with_likely_invalid_domain(): void
|
public function test_new_user_can_not_register_with_likely_invalid_domain(): void
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class OrganizationInvitationEndpointTest extends EndpointTestAbstract
|
|||||||
$response->assertRedirect(route('register'));
|
$response->assertRedirect(route('register'));
|
||||||
$response->assertSessionHas('bannerText', 'Please create an account to finish joining the '.$user->organization->name.' organization.');
|
$response->assertSessionHas('bannerText', 'Please create an account to finish joining the '.$user->organization->name.' organization.');
|
||||||
$response->assertSessionHas('bannerStyle', 'info');
|
$response->assertSessionHas('bannerStyle', 'info');
|
||||||
|
$response->assertSessionHas('registration_email', strtolower($invitation->email));
|
||||||
$invitation->refresh();
|
$invitation->refresh();
|
||||||
$this->assertNotNull($invitation->accepted_at);
|
$this->assertNotNull($invitation->accepted_at);
|
||||||
}
|
}
|
||||||
@@ -64,6 +65,7 @@ class OrganizationInvitationEndpointTest extends EndpointTestAbstract
|
|||||||
$response->assertRedirect(route('register'));
|
$response->assertRedirect(route('register'));
|
||||||
$response->assertSessionHas('bannerText', 'Please create an account to finish joining the '.$user->organization->name.' organization.');
|
$response->assertSessionHas('bannerText', 'Please create an account to finish joining the '.$user->organization->name.' organization.');
|
||||||
$response->assertSessionHas('bannerStyle', 'info');
|
$response->assertSessionHas('bannerStyle', 'info');
|
||||||
|
$response->assertSessionHas('registration_email', strtolower($invitation->email));
|
||||||
$invitation->refresh();
|
$invitation->refresh();
|
||||||
$this->assertNotNull($invitation->accepted_at);
|
$this->assertNotNull($invitation->accepted_at);
|
||||||
}
|
}
|
||||||
|
|||||||
38
tests/Unit/Enums/RegistrationModeTest.php
Normal file
38
tests/Unit/Enums/RegistrationModeTest.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Unit\Enums;
|
||||||
|
|
||||||
|
use App\Enums\RegistrationMode;
|
||||||
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
#[CoversClass(RegistrationMode::class)]
|
||||||
|
class RegistrationModeTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array<string, array{mixed, RegistrationMode}>
|
||||||
|
*/
|
||||||
|
public static function configValueProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'boolean true' => [true, RegistrationMode::On],
|
||||||
|
'on' => ['on', RegistrationMode::On],
|
||||||
|
'true' => ['true', RegistrationMode::On],
|
||||||
|
'invite-only' => ['invite-only', RegistrationMode::InviteOnly],
|
||||||
|
'boolean false' => [false, RegistrationMode::Off],
|
||||||
|
'off' => ['off', RegistrationMode::Off],
|
||||||
|
'false' => ['false', RegistrationMode::Off],
|
||||||
|
'unsupported invite alias' => ['invite', RegistrationMode::Off],
|
||||||
|
'unknown' => ['unknown', RegistrationMode::Off],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
#[DataProvider('configValueProvider')]
|
||||||
|
public function test_registration_mode_is_created_from_config_value(mixed $value, RegistrationMode $expected): void
|
||||||
|
{
|
||||||
|
$this->assertSame($expected, RegistrationMode::fromConfig($value));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user