mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-14 08:43:16 +01:00
Compare commits
7 Commits
feature/ru
...
feature/ex
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
23d64b6d7a | ||
|
|
0c58896b00 | ||
|
|
6301b0f4a1 | ||
|
|
4c993c8eb2 | ||
|
|
ae6937d012 | ||
|
|
1256fa61bd | ||
|
|
d6f80e23fb |
7
.github/workflows/phpunit-extensions.yml
vendored
7
.github/workflows/phpunit-extensions.yml
vendored
@@ -5,7 +5,7 @@ permissions:
|
|||||||
jobs:
|
jobs:
|
||||||
phpunit-extensions:
|
phpunit-extensions:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 15
|
timeout-minutes: 25
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
postgres_version: [ 15, 16, 17 ]
|
postgres_version: [ 15, 16, 17 ]
|
||||||
@@ -132,5 +132,8 @@ jobs:
|
|||||||
php artisan key:generate
|
php artisan key:generate
|
||||||
php artisan passport:keys
|
php artisan passport:keys
|
||||||
|
|
||||||
- name: "Run PHPUnit"
|
- name: "Run PHPUnit (extensions)"
|
||||||
run: php artisan test extensions/Billing/tests extensions/Services/tests extensions/Invoicing/tests --stop-on-failure
|
run: php artisan test extensions/Billing/tests extensions/Services/tests extensions/Invoicing/tests --stop-on-failure
|
||||||
|
|
||||||
|
- name: "Run PHPUnit (core)"
|
||||||
|
run: php artisan test --testsuite=Unit,Feature --stop-on-failure
|
||||||
|
|||||||
86
.oss-scanner/Dockerfile
Normal file
86
.oss-scanner/Dockerfile
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
# Build environment for Anthropic's OSS Scanner (https://github.com/anthropics/oss-scanner).
|
||||||
|
# The scanner builds this image with the repository root as the build context and then audits it without network
|
||||||
|
# access, so everything needed to run the app and its test suite (PHP + Composer deps, Node deps + built frontend,
|
||||||
|
# a local PostgreSQL and a local Gotenberg for PDF rendering) is installed here.
|
||||||
|
#
|
||||||
|
# The base image is the FrankenPHP image the production image (docker/prod/Dockerfile) is built on: in production the
|
||||||
|
# app runs as long-lived Laravel Octane workers in FrankenPHP worker mode, not as one PHP process per request.
|
||||||
|
#
|
||||||
|
# Inside the finished image:
|
||||||
|
# .oss-scanner/start-postgres.sh start the local PostgreSQL server (required for tests and the app)
|
||||||
|
# .oss-scanner/start-gotenberg.sh start the local Gotenberg server (required for PDF exports)
|
||||||
|
# php artisan test run the PHPUnit suite (needs PostgreSQL and Gotenberg running)
|
||||||
|
# .oss-scanner/start-octane.sh run the app like production on http://127.0.0.1:8000 (starts everything above)
|
||||||
|
|
||||||
|
ARG FRANKENPHP_VERSION=1.11
|
||||||
|
ARG PHP_VERSION=8.3
|
||||||
|
|
||||||
|
FROM node:20-trixie-slim AS node
|
||||||
|
|
||||||
|
FROM gotenberg/gotenberg:8 AS gotenberg
|
||||||
|
|
||||||
|
FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive \
|
||||||
|
COMPOSER_ALLOW_SUPERUSER=1 \
|
||||||
|
COMPOSER_NO_INTERACTION=1 \
|
||||||
|
OCTANE_SERVER=frankenphp \
|
||||||
|
TZ=UTC
|
||||||
|
|
||||||
|
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
|
||||||
|
COPY --from=node /usr/local/bin/node /usr/local/bin/node
|
||||||
|
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
|
||||||
|
RUN ln -s ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
|
||||||
|
&& ln -s ../lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
|
||||||
|
|
||||||
|
# PostgreSQL 17 (Debian trixie default) is one of the versions solidtime is tested against in CI.
|
||||||
|
# chromium, qpdf and exiftool are what Gotenberg needs for HTML to PDF rendering.
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends git unzip curl ca-certificates postgresql postgresql-client \
|
||||||
|
chromium fonts-liberation qpdf libimage-exiftool-perl \
|
||||||
|
&& install-php-extensions pdo_pgsql pgsql intl gd zip bcmath exif pcntl sockets soap apcu \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
|
&& echo "memory_limit=2G" > "$PHP_INI_DIR/conf.d/99-oss-scanner.ini"
|
||||||
|
|
||||||
|
# Gotenberg 8 (the PDF renderer, same image as in CI). solidtime only uses its Chromium HTML to PDF route, so LibreOffice
|
||||||
|
# and pdftk are not installed: Gotenberg only checks at startup that their binaries exist, start-gotenberg.sh disables
|
||||||
|
# the LibreOffice routes and the Chromium route does not use pdftk.
|
||||||
|
COPY --from=gotenberg /usr/bin/gotenberg /usr/local/bin/gotenberg
|
||||||
|
COPY --from=gotenberg /usr/bin/pdfcpu /usr/local/bin/pdfcpu
|
||||||
|
COPY --from=gotenberg /opt/gotenberg /opt/gotenberg
|
||||||
|
ENV CHROMIUM_BIN_PATH=/usr/bin/chromium \
|
||||||
|
CHROMIUM_HYPHEN_DATA_DIR_PATH=/opt/gotenberg/chromium-hyphen-data \
|
||||||
|
GOTENBERG_VERSIONS_DIR_PATH=/opt/gotenberg/versions \
|
||||||
|
QPDF_BIN_PATH=/usr/bin/qpdf \
|
||||||
|
EXIFTOOL_BIN_PATH=/usr/bin/exiftool \
|
||||||
|
PDFCPU_BIN_PATH=/usr/local/bin/pdfcpu \
|
||||||
|
LIBREOFFICE_BIN_PATH=/bin/false \
|
||||||
|
UNOCONVERTER_BIN_PATH=/bin/false \
|
||||||
|
PDFTK_BIN_PATH=/bin/false
|
||||||
|
|
||||||
|
# Database matching .env.ci: user root / password root, database laravel.
|
||||||
|
RUN pg_ctlcluster 17 main start \
|
||||||
|
&& runuser -u postgres -- psql -c "CREATE ROLE root WITH LOGIN SUPERUSER PASSWORD 'root';" \
|
||||||
|
&& runuser -u postgres -- createdb -O root laravel \
|
||||||
|
&& pg_ctlcluster 17 main stop
|
||||||
|
|
||||||
|
# scanner contract: the checkout lives inside the image, at /src
|
||||||
|
COPY . /src
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
RUN composer install --prefer-dist \
|
||||||
|
&& npm ci \
|
||||||
|
&& npm run build
|
||||||
|
|
||||||
|
RUN cp .env.ci .env \
|
||||||
|
&& php artisan key:generate \
|
||||||
|
&& php artisan passport:keys --force \
|
||||||
|
&& php artisan octane:install --server=frankenphp --no-interaction \
|
||||||
|
&& chmod +x .oss-scanner/*.sh
|
||||||
|
|
||||||
|
# Run the test suite so the image is known to work, but do not fail the build on test failures.
|
||||||
|
RUN .oss-scanner/start-postgres.sh \
|
||||||
|
&& .oss-scanner/start-gotenberg.sh \
|
||||||
|
&& (php artisan test || echo "WARNING: PHPUnit reported failures") \
|
||||||
|
&& kill "$(cat /tmp/gotenberg.pid)" \
|
||||||
|
&& pg_ctlcluster 17 main stop
|
||||||
18
.oss-scanner/Dockerfile.dockerignore
Normal file
18
.oss-scanner/Dockerfile.dockerignore
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Used instead of the root .dockerignore when building .oss-scanner/Dockerfile. The root one is tailored to the
|
||||||
|
# production image and excludes tests, phpunit.xml etc., which the scanner needs.
|
||||||
|
node_modules
|
||||||
|
extensions/*/node_modules
|
||||||
|
vendor
|
||||||
|
.env
|
||||||
|
public/build
|
||||||
|
public/hot
|
||||||
|
storage/*.key
|
||||||
|
storage/logs/*
|
||||||
|
coverage
|
||||||
|
test-results
|
||||||
|
playwright-report
|
||||||
|
.phpunit.cache
|
||||||
|
.phpunit.result.cache
|
||||||
|
auth.json
|
||||||
|
.DS_Store
|
||||||
|
.idea
|
||||||
16
.oss-scanner/start-gotenberg.sh
Executable file
16
.oss-scanner/start-gotenberg.sh
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Start the local Gotenberg server (PDF rendering) on 127.0.0.1:3000, matching GOTENBERG_URL in .env.ci.
|
||||||
|
# Only the Chromium routes are needed by solidtime, see .oss-scanner/Dockerfile. Stop: kill "$(cat /tmp/gotenberg.pid)"
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
if ! curl -fs http://127.0.0.1:3000/health >/dev/null; then
|
||||||
|
nohup gotenberg \
|
||||||
|
--api-port=3000 \
|
||||||
|
--libreoffice-disable-routes \
|
||||||
|
--libreoffice-auto-start=false \
|
||||||
|
--log-level=warn \
|
||||||
|
>/tmp/gotenberg.log 2>&1 &
|
||||||
|
echo $! >/tmp/gotenberg.pid
|
||||||
|
until curl -fs http://127.0.0.1:3000/health >/dev/null; do sleep 0.5; done
|
||||||
|
fi
|
||||||
|
echo "Gotenberg is running on http://127.0.0.1:3000 (log: /tmp/gotenberg.log)"
|
||||||
37
.oss-scanner/start-octane.sh
Executable file
37
.oss-scanner/start-octane.sh
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Run the app the way production does: Laravel Octane on FrankenPHP in worker mode, with the production Caddyfile.
|
||||||
|
# A worker boots the app once and then serves many requests, so state kept in memory (static properties, singletons,
|
||||||
|
# changed config, ...) survives from one request to the next. With a single worker, consecutive requests always hit the
|
||||||
|
# same worker, so such leaks between requests (e.g. between users of different organizations) reproduce reliably.
|
||||||
|
#
|
||||||
|
# Usage: .oss-scanner/start-octane.sh (OCTANE_WORKERS and OCTANE_MAX_REQUESTS can be overridden)
|
||||||
|
# Stop: php artisan octane:stop
|
||||||
|
# After changing PHP code, run `php artisan octane:reload`: workers keep the code they booted with.
|
||||||
|
set -euo pipefail
|
||||||
|
cd "$(dirname "$0")/.."
|
||||||
|
|
||||||
|
.oss-scanner/start-postgres.sh
|
||||||
|
.oss-scanner/start-gotenberg.sh
|
||||||
|
|
||||||
|
php artisan migrate --force
|
||||||
|
if [ "$(PGPASSWORD=root psql -h 127.0.0.1 -U root -d laravel -tAc 'SELECT count(*) FROM users')" = "0" ]; then
|
||||||
|
php artisan db:seed --force
|
||||||
|
fi
|
||||||
|
php artisan optimize:clear >/dev/null
|
||||||
|
|
||||||
|
nohup php artisan octane:frankenphp \
|
||||||
|
--host=127.0.0.1 \
|
||||||
|
--port=8000 \
|
||||||
|
--workers="${OCTANE_WORKERS:-1}" \
|
||||||
|
--max-requests="${OCTANE_MAX_REQUESTS:-10000}" \
|
||||||
|
--caddyfile=docker/prod/deployment/octane/FrankenPHP/Caddyfile \
|
||||||
|
>/tmp/octane.log 2>&1 &
|
||||||
|
|
||||||
|
until curl -fs -o /dev/null http://127.0.0.1:8000/login; do
|
||||||
|
if ! kill -0 $! 2>/dev/null; then
|
||||||
|
cat /tmp/octane.log
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sleep 0.5
|
||||||
|
done
|
||||||
|
echo "solidtime is running on http://127.0.0.1:8000 with Octane/FrankenPHP (log: /tmp/octane.log)"
|
||||||
7
.oss-scanner/start-postgres.sh
Executable file
7
.oss-scanner/start-postgres.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Start the local PostgreSQL server used by the test suite and the app (see .oss-scanner/Dockerfile).
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
pg_ctlcluster 17 main start 2>/dev/null || true
|
||||||
|
until pg_isready -h 127.0.0.1 -p 5432 -q; do sleep 0.5; done
|
||||||
|
echo "PostgreSQL is running on 127.0.0.1:5432 (user root, password root, database laravel)"
|
||||||
122
.oss-scanner/threat_model.md
Normal file
122
.oss-scanner/threat_model.md
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
# Threat model
|
||||||
|
|
||||||
|
## What this project does
|
||||||
|
|
||||||
|
solidtime is an open-source, multi-tenant time tracking web application (Laravel backend, Vue 3 + Inertia frontend,
|
||||||
|
PostgreSQL). It runs as a hosted SaaS (solidtime.io) and is self-hosted by many organisations. Users belong to one or
|
||||||
|
more **organizations**; inside an organization each member has a role: `owner`, `admin`, `manager`, `employee` or
|
||||||
|
`placeholder` (an imported, non-login member). What each role may do is defined in `app/Service/PermissionStore.php`.
|
||||||
|
|
||||||
|
The most important security property is **isolation**: a user must never read or modify data of an organization they
|
||||||
|
are not a member of, and within an organization a member must not exceed the permissions of their role (e.g. an
|
||||||
|
employee must not see other members' time entries, billable rates, or manage members, unless the organization settings
|
||||||
|
explicitly allow it).
|
||||||
|
|
||||||
|
## Trust boundaries
|
||||||
|
|
||||||
|
- **Super admins are fully trusted.** They are the instance operators, configured via the `SUPER_ADMINS` env
|
||||||
|
variable, and have access to the Filament admin panel (`app/Filament`), which can view and change data of every
|
||||||
|
organization and impersonate users. Anything a super admin can do through the panel (including XSS, SQL injection,
|
||||||
|
SSRF or file access that is only reachable from the panel) is not a vulnerability.
|
||||||
|
- What **is** in scope: a user who is not a super admin reaching the admin panel, or any of its actions, at all.
|
||||||
|
- Operators of a self-hosted instance (shell, database, environment, filesystem access) are trusted.
|
||||||
|
- Everyone else, including organization owners and admins when acting outside their own organization, is untrusted.
|
||||||
|
|
||||||
|
## Runtime: long-lived Octane workers
|
||||||
|
|
||||||
|
In production (the hosted SaaS and the official Docker image, `docker/prod/`) the app does **not** run as one PHP
|
||||||
|
process per request. It runs on Laravel Octane with FrankenPHP in worker mode: each worker boots the application once
|
||||||
|
and then serves many requests from different users and organizations. Anything kept in memory survives from one request
|
||||||
|
to the next unless Octane resets it (`config/octane.php` lists what is reset). This includes static properties and
|
||||||
|
static caches, container bindings registered with `singleton()` instead of `scoped()` (see
|
||||||
|
`app/Providers/AppServiceProvider.php`), objects captured by those singletons, runtime `config()` / locale / timezone
|
||||||
|
changes, macros and event listeners registered during a request, and state in third-party packages.
|
||||||
|
|
||||||
|
Request A leaving state behind that request B (another user, possibly of another organization) then sees or is
|
||||||
|
affected by is in scope, rated by its impact like any other issue (see severity below). The PHPUnit suite cannot
|
||||||
|
show this class of bug, because it boots a fresh application for every test. It has to be reproduced over HTTP against
|
||||||
|
the Octane server, see "How to exercise it".
|
||||||
|
|
||||||
|
## Where untrusted input enters
|
||||||
|
|
||||||
|
All authenticated users, including employees of any organization and anyone who self-registers (registration is open
|
||||||
|
by default), are untrusted.
|
||||||
|
|
||||||
|
- **JSON API** `routes/api.php` (`/api/v1/...`), authenticated via Passport (session cookie or personal access token).
|
||||||
|
Most routes are scoped by `{organization}` and authorised in the controllers / form requests.
|
||||||
|
- **Public, unauthenticated** endpoints: `GET /api/v1/public/reports` (shared reports, accessed by a secret), login,
|
||||||
|
registration, password reset, email verification, organization invitation acceptance (`routes/web.php`).
|
||||||
|
- **Web / Inertia routes** `routes/web.php` and Fortify/Jetstream actions in `app/Actions`.
|
||||||
|
- **Imports** (`app/Service/Import/Importers`): user-uploaded CSV and ZIP files from Toggl, Clockify, Harvest,
|
||||||
|
generic CSV and solidtime's own export format. ZIP handling is in `ZipImportHelper.php`.
|
||||||
|
- **Exports / reports** (`app/Service/Export`, `app/Service/ReportExport`): CSV/XLSX/ODS and PDF. PDFs are rendered by
|
||||||
|
sending HTML to a Gotenberg (headless Chromium) service, so user-controlled content in that HTML matters.
|
||||||
|
- **OAuth** (Passport) authorization and token endpoints.
|
||||||
|
- **Filament admin panel** (`app/Filament`): only its access control is in scope (see Trust boundaries).
|
||||||
|
|
||||||
|
## Components that matter most / least
|
||||||
|
|
||||||
|
Most important: organization scoping and role checks in the API controllers, form requests (`app/Http/Requests`),
|
||||||
|
`PermissionStore`, public report sharing, invitations and member management (role changes, ownership transfer, member
|
||||||
|
merge), authentication flows (Fortify, 2FA, email change, API tokens), import parsing.
|
||||||
|
|
||||||
|
Less important / out of scope:
|
||||||
|
- `extensions/` is empty in this repository (proprietary modules are not part of the open-source code).
|
||||||
|
- `docker/`, `k8s/`, `e2e/`, `playwright/`, `docs/` and developer tooling.
|
||||||
|
- Third-party dependencies in `vendor/` and `node_modules/`, unless solidtime uses them in an unsafe way.
|
||||||
|
|
||||||
|
## How to exercise it
|
||||||
|
|
||||||
|
- `.oss-scanner/start-postgres.sh` starts the local PostgreSQL server (user `root`, password `root`, db `laravel`).
|
||||||
|
- `.oss-scanner/start-gotenberg.sh` starts the local Gotenberg server (PDF rendering via headless Chromium) on
|
||||||
|
http://127.0.0.1:3000, so the PDF export code path, including what Chromium does with the rendered HTML, can be
|
||||||
|
exercised.
|
||||||
|
- `php artisan test` runs the PHPUnit suite (start PostgreSQL and Gotenberg first); all tests are expected to pass. Endpoint tests in `tests/Unit/Endpoint/Api/V1/` show how to create users,
|
||||||
|
organizations and members with factories and call the API with a given role; they are the quickest way to write a
|
||||||
|
reproducer. Example: `php artisan test --filter=TimeEntryEndpointTest`.
|
||||||
|
- To run the app like production: `.oss-scanner/start-octane.sh` (http://127.0.0.1:8000). It starts PostgreSQL and
|
||||||
|
Gotenberg, migrates (and seeds an empty database, see `database/seeders/DatabaseSeeder.php` for the users) and runs
|
||||||
|
Octane/FrankenPHP with the production Caddyfile and a **single worker**, so consecutive requests always hit the same
|
||||||
|
worker and leaks between requests reproduce reliably. Workers keep the code they booted with: after changing PHP
|
||||||
|
code run `php artisan octane:reload`. Stop it with `php artisan octane:stop`. Note that the test suite and the app
|
||||||
|
share the same database, so `php artisan test` wipes the app's data.
|
||||||
|
- A reproducer for a leak between requests is a script that sends request A (e.g. as a member of organization X) and
|
||||||
|
then request B (as a user of organization Y) to the running Octane server and shows that B observes A's state. API
|
||||||
|
requests can be authenticated with a personal access token, e.g. created with
|
||||||
|
`php artisan tinker --execute="echo App\Models\User::where('email', '...')->first()->createToken('t')->accessToken;"`.
|
||||||
|
- There is no network: mail delivery is not available (mail uses the `array` driver in tests), and remote resources
|
||||||
|
referenced by PDF templates (e.g. fonts from fonts.bunny.net) fail to load, so PDFs fall back to local fonts.
|
||||||
|
|
||||||
|
## How we rate severity
|
||||||
|
|
||||||
|
- **Critical**: unauthenticated access to other users' data or accounts; authentication bypass; remote code execution;
|
||||||
|
SQL injection reachable by any registered user; reading or writing data of an organization the attacker is not a
|
||||||
|
member of, including through state leaking between requests in an Octane worker.
|
||||||
|
- **High**: privilege escalation within an organization (e.g. employee to admin/owner, or performing admin-only
|
||||||
|
actions); access to data the role must not see (other members' time entries, billable rates, member emails) when
|
||||||
|
the organization settings do not allow it; stored XSS that executes in another user's session; SSRF via PDF
|
||||||
|
rendering or imports; account takeover requiring user interaction.
|
||||||
|
- **Medium**: information disclosure with limited impact, CSRF on state-changing endpoints, issues requiring an
|
||||||
|
unusual but realistic configuration, denial of service by a single authenticated request (e.g. pathological
|
||||||
|
import file).
|
||||||
|
- **Low**: everything else with real security impact.
|
||||||
|
|
||||||
|
## Anything to leave alone
|
||||||
|
|
||||||
|
Please do not report (see also `SECURITY.md`):
|
||||||
|
- Theoretical findings without a working reproducer.
|
||||||
|
- Missing or weak security headers in isolation; TLS / mail DNS configuration.
|
||||||
|
- Self-XSS; CSRF on non-state-changing endpoints (logout, theme).
|
||||||
|
- CSV / spreadsheet formula injection in exports.
|
||||||
|
- Owners or admins acting destructively within their own organization.
|
||||||
|
- Anything requiring direct DB, shell or filesystem access on a self-hosted instance.
|
||||||
|
- Anything that requires being a super admin, including issues inside the Filament admin panel.
|
||||||
|
- Missing OAuth scope enforcement (not implemented yet).
|
||||||
|
- Rate-limit tuning and generic DoS through volume of requests.
|
||||||
|
|
||||||
|
## Reports and patches
|
||||||
|
|
||||||
|
Please include the affected endpoint or code path, the attacker's role and the victim, a PHPUnit test (in the style of
|
||||||
|
`tests/Unit/Endpoint/Api/V1/`) that reproduces the issue (for leaks between requests: a script against
|
||||||
|
`.oss-scanner/start-octane.sh` instead), and a minimal patch that follows the existing patterns
|
||||||
|
(authorisation in form requests/controllers via `PermissionStore`).
|
||||||
@@ -5,8 +5,12 @@ declare(strict_types=1);
|
|||||||
namespace App\Actions\Fortify;
|
namespace App\Actions\Fortify;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Providers\FortifyServiceProvider;
|
||||||
|
use Illuminate\Auth\Passwords\PasswordBroker;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Password;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
use Laravel\Fortify\Contracts\ResetsUserPasswords;
|
use Laravel\Fortify\Contracts\ResetsUserPasswords;
|
||||||
|
|
||||||
class ResetUserPassword implements ResetsUserPasswords
|
class ResetUserPassword implements ResetsUserPasswords
|
||||||
@@ -20,6 +24,16 @@ class ResetUserPassword implements ResetsUserPasswords
|
|||||||
*/
|
*/
|
||||||
public function reset(User $user, array $input): void
|
public function reset(User $user, array $input): void
|
||||||
{
|
{
|
||||||
|
if (! FortifyServiceProvider::canResetPassword($user, $input)) {
|
||||||
|
/** @var PasswordBroker $broker */
|
||||||
|
$broker = Password::broker(config('fortify.passwords'));
|
||||||
|
$broker->deleteToken($user);
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'email' => [__('This password reset link is invalid.')],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
Validator::make($input, [
|
Validator::make($input, [
|
||||||
'password' => $this->passwordRules(),
|
'password' => $this->passwordRules(),
|
||||||
])->validate();
|
])->validate();
|
||||||
|
|||||||
@@ -160,13 +160,23 @@ class User extends Authenticatable implements AuditableContract, FilamentUser, M
|
|||||||
return 'https://ui-avatars.com/api/?name='.urlencode($name).'&color=7F9CF5&background=EBF4FF';
|
return 'https://ui-avatars.com/api/?name='.urlencode($name).'&color=7F9CF5&background=EBF4FF';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canAccessPanel(Panel $panel): bool
|
public function isSuperAdmin(): bool
|
||||||
{
|
{
|
||||||
return $this->is_placeholder === false
|
return $this->is_placeholder === false
|
||||||
&& in_array($this->email, config('auth.super_admins', []), true)
|
&& in_array($this->email, config('auth.super_admins', []), true)
|
||||||
&& $this->hasVerifiedEmail();
|
&& $this->hasVerifiedEmail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasLocalPassword(): bool
|
||||||
|
{
|
||||||
|
return is_string($this->password) && $this->password !== '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canAccessPanel(Panel $panel): bool
|
||||||
|
{
|
||||||
|
return $this->isSuperAdmin();
|
||||||
|
}
|
||||||
|
|
||||||
public function isMemberOfOrganization(Organization $organization): bool
|
public function isMemberOfOrganization(Organization $organization): bool
|
||||||
{
|
{
|
||||||
if ($this->relationLoaded('organizations')) {
|
if ($this->relationLoaded('organizations')) {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ use Illuminate\Session\Middleware\StartSession;
|
|||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||||
use Nwidart\Modules\Facades\Module;
|
use Nwidart\Modules\Facades\Module;
|
||||||
|
use Nwidart\Modules\Laravel\Module as LaravelModule;
|
||||||
use pxlrbt\FilamentEnvironmentIndicator\EnvironmentIndicatorPlugin;
|
use pxlrbt\FilamentEnvironmentIndicator\EnvironmentIndicatorPlugin;
|
||||||
|
|
||||||
class AdminPanelProvider extends PanelProvider
|
class AdminPanelProvider extends PanelProvider
|
||||||
@@ -93,22 +94,77 @@ class AdminPanelProvider extends PanelProvider
|
|||||||
$modules = Module::allEnabled();
|
$modules = Module::allEnabled();
|
||||||
|
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
|
$moduleNamespace = $this->getModuleAppNamespace($module);
|
||||||
|
|
||||||
$panel->discoverResources(
|
$panel->discoverResources(
|
||||||
in: module_path($module->getName(), 'app/Filament/Resources'),
|
in: module_path($module->getName(), 'app/Filament/Resources'),
|
||||||
for: 'Extensions\\'.$module->getName().'\\App\\Filament\\Resources'
|
for: $moduleNamespace.'\\Filament\\Resources'
|
||||||
);
|
);
|
||||||
|
|
||||||
$panel->discoverPages(
|
$panel->discoverPages(
|
||||||
in: module_path($module->getName(), 'app/Filament/Pages'),
|
in: module_path($module->getName(), 'app/Filament/Pages'),
|
||||||
for: 'Extensions\\'.$module->getName().'\\App\\Filament\\Pages'
|
for: $moduleNamespace.'\\Filament\\Pages'
|
||||||
);
|
);
|
||||||
|
|
||||||
$panel->discoverWidgets(
|
$panel->discoverWidgets(
|
||||||
in: module_path($module->getName(), 'app/Filament/Widgets'),
|
in: module_path($module->getName(), 'app/Filament/Widgets'),
|
||||||
for: 'Extensions\\'.$module->getName().'\\App\\Filament\\Widgets'
|
for: $moduleNamespace.'\\Filament\\Widgets'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $panel;
|
return $panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var array<string, string> Cache of module name => resolved app namespace. */
|
||||||
|
private static array $moduleAppNamespaces = [];
|
||||||
|
|
||||||
|
private function getModuleAppNamespace(LaravelModule $module): string
|
||||||
|
{
|
||||||
|
return self::$moduleAppNamespaces[$module->getName()] ??= $this->resolveModuleAppNamespace($module);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the PHP namespace mapped to a module's app/ directory so the
|
||||||
|
* Filament panel can discover its Resources/Pages/Widgets under the right
|
||||||
|
* namespace.
|
||||||
|
*
|
||||||
|
* Two module layouts currently coexist in this repo:
|
||||||
|
* - laravel-modules v12 (app_folder enabled): a bare namespace maps to
|
||||||
|
* app/ — e.g. "Extensions\SSO\" => app/, so classes are
|
||||||
|
* Extensions\SSO\Filament\... (this is the current convention).
|
||||||
|
* - the older layout: an "...\App" namespace maps to app/ — e.g.
|
||||||
|
* "Extensions\Billing\App\" => app/, so classes are
|
||||||
|
* Extensions\Billing\App\Filament\...
|
||||||
|
*
|
||||||
|
* The package's own namespace derivation assumes the v12 (bare) layout and
|
||||||
|
* would mis-resolve the legacy modules, so we read each module's composer
|
||||||
|
* PSR-4 map and use whichever namespace actually points at app/. The legacy
|
||||||
|
* "...\App" shape is only a fallback for when composer is missing/unreadable.
|
||||||
|
* Once every module adopts the bare layout this collapses to
|
||||||
|
* config('modules.namespace').'\\'.$module->getName().
|
||||||
|
*/
|
||||||
|
private function resolveModuleAppNamespace(LaravelModule $module): string
|
||||||
|
{
|
||||||
|
$fallback = 'Extensions\\'.$module->getName().'\\App';
|
||||||
|
|
||||||
|
$composerPath = module_path($module->getName(), 'composer.json');
|
||||||
|
$psr4 = [];
|
||||||
|
if (is_file($composerPath)) {
|
||||||
|
$composer = json_decode((string) file_get_contents($composerPath), true);
|
||||||
|
$psr4 = is_array($composer) ? ($composer['autoload']['psr-4'] ?? []) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ((array) $psr4 as $namespace => $path) {
|
||||||
|
if (is_string($namespace) && $this->normalizeComposerPath($path) === 'app') {
|
||||||
|
return rtrim($namespace, '\\');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function normalizeComposerPath(mixed $path): string
|
||||||
|
{
|
||||||
|
return trim(str_replace('\\', '/', (string) $path), '/');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,73 @@ use Laravel\Fortify\Fortify;
|
|||||||
|
|
||||||
class FortifyServiceProvider extends ServiceProvider
|
class FortifyServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Dummy bcrypt hash compared against when no user matches the submitted
|
||||||
|
* email. Hash::check is run against it so login takes the same time whether
|
||||||
|
* or not the email exists — otherwise an unknown email would skip the
|
||||||
|
* (deliberately slow) hash and return faster, letting an attacker enumerate
|
||||||
|
* registered accounts by timing the response. The plaintext is irrelevant:
|
||||||
|
* it is only ever checked against attacker-supplied input and never matches.
|
||||||
|
*/
|
||||||
|
private const ABSENT_USER_PASSWORD_HASH = '$2y$12$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authorization rules applied AFTER the password is verified. Each rule
|
||||||
|
* receives the authenticated user + request and returns whether the login
|
||||||
|
* may proceed; any rule returning false denies it. This is an extension
|
||||||
|
* point: modules (e.g. SSO enforcement) add a rule to veto a password login
|
||||||
|
* instead of replacing this credential check — which would silently drift
|
||||||
|
* from the host logic the next time it changes.
|
||||||
|
*
|
||||||
|
* @var array<int, \Closure(User, Request): bool>
|
||||||
|
*/
|
||||||
|
protected static array $loginRules = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authorization rules applied before a password reset is completed. Rules
|
||||||
|
* receive the user being reset + submitted input and return whether the
|
||||||
|
* local reset flow may set a new password for that account.
|
||||||
|
*
|
||||||
|
* @var array<int, \Closure(User, array<string, mixed>): bool>
|
||||||
|
*/
|
||||||
|
protected static array $passwordResetRules = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register an additional rule that gates password login (see $loginRules).
|
||||||
|
*
|
||||||
|
* @param \Closure(User, Request): bool $rule
|
||||||
|
*/
|
||||||
|
public static function authenticateUsingRule(\Closure $rule): void
|
||||||
|
{
|
||||||
|
static::$loginRules[] = $rule;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register an additional rule that gates password reset completion.
|
||||||
|
*
|
||||||
|
* @param \Closure(User, array<string, mixed>): bool $rule
|
||||||
|
*/
|
||||||
|
public static function resetPasswordUsingRule(\Closure $rule): void
|
||||||
|
{
|
||||||
|
static::$passwordResetRules[] = $rule;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the given user may complete the local password reset flow.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $input
|
||||||
|
*/
|
||||||
|
public static function canResetPassword(User $user, array $input = []): bool
|
||||||
|
{
|
||||||
|
foreach (static::$passwordResetRules as $rule) {
|
||||||
|
if (! $rule($user, $input)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register any application services.
|
* Register any application services.
|
||||||
*/
|
*/
|
||||||
@@ -93,7 +160,23 @@ class FortifyServiceProvider extends ServiceProvider
|
|||||||
->where('is_placeholder', '=', false)
|
->where('is_placeholder', '=', false)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($user !== null && Hash::check($request->password, $user->password)) {
|
// Always run the hash check — against the real hash, or a dummy when
|
||||||
|
// there is no user — so login timing is identical either way (see
|
||||||
|
// ABSENT_USER_PASSWORD_HASH). Passwordless accounts (SSO-only users
|
||||||
|
// have password = null) fail here, so they cannot password-login.
|
||||||
|
$existingPasswordHash = $user->password ?? self::ABSENT_USER_PASSWORD_HASH;
|
||||||
|
|
||||||
|
$passwordIsValid = Hash::check((string) $request->password, $existingPasswordHash);
|
||||||
|
|
||||||
|
if ($user !== null && $passwordIsValid) {
|
||||||
|
// Credentials are valid; now apply any registered authorization
|
||||||
|
// rules (e.g. SSO enforcement may still block password login).
|
||||||
|
foreach (static::$loginRules as $rule) {
|
||||||
|
if (! $rule($user, $request)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,56 @@ class UserService
|
|||||||
}
|
}
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
|
$this->createDefaultOrganizationForUser(
|
||||||
|
$user,
|
||||||
|
$currency,
|
||||||
|
$numberFormat,
|
||||||
|
$currencyFormat,
|
||||||
|
$dateFormat,
|
||||||
|
$intervalFormat,
|
||||||
|
$timeFormat,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a user without a password (e.g. provisioned via SSO). Such users
|
||||||
|
* can only authenticate through a linked identity provider.
|
||||||
|
*/
|
||||||
|
public function createPasswordlessUser(
|
||||||
|
string $name,
|
||||||
|
string $email,
|
||||||
|
string $timezone,
|
||||||
|
Weekday $weekStart,
|
||||||
|
?string $currency,
|
||||||
|
bool $verifyEmail = false
|
||||||
|
): User {
|
||||||
|
$user = new User;
|
||||||
|
$user->name = $name;
|
||||||
|
$user->email = strtolower($email);
|
||||||
|
$user->password = null;
|
||||||
|
$user->timezone = $timezone;
|
||||||
|
$user->week_start = $weekStart;
|
||||||
|
if ($verifyEmail) {
|
||||||
|
$user->email_verified_at = Carbon::now();
|
||||||
|
}
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$this->createDefaultOrganizationForUser($user, $currency);
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createDefaultOrganizationForUser(
|
||||||
|
User $user,
|
||||||
|
?string $currency,
|
||||||
|
?NumberFormat $numberFormat = null,
|
||||||
|
?CurrencyFormat $currencyFormat = null,
|
||||||
|
?DateFormat $dateFormat = null,
|
||||||
|
?IntervalFormat $intervalFormat = null,
|
||||||
|
?TimeFormat $timeFormat = null,
|
||||||
|
): void {
|
||||||
$organizations = app(InvitationService::class)->processAcceptedInvitations($user);
|
$organizations = app(InvitationService::class)->processAcceptedInvitations($user);
|
||||||
|
|
||||||
if ($organizations->isEmpty()) {
|
if ($organizations->isEmpty()) {
|
||||||
@@ -65,8 +115,6 @@ class UserService
|
|||||||
);
|
);
|
||||||
$this->switchCurrentOrganization($user, $organization);
|
$this->switchCurrentOrganization($user, $organization);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,10 +9,10 @@
|
|||||||
},
|
},
|
||||||
"Invoicing": {
|
"Invoicing": {
|
||||||
"repository": "solidtime-io/extension-invoicing",
|
"repository": "solidtime-io/extension-invoicing",
|
||||||
"ref": "v0.0.9"
|
"ref": "v0.0.10"
|
||||||
},
|
},
|
||||||
"Auditing": {
|
"Auditing": {
|
||||||
"repository": "solidtime-io/extension-auditing",
|
"repository": "solidtime-io/extension-auditing",
|
||||||
"ref": "v0.0.4"
|
"ref": "v0.0.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,16 @@ 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';
|
||||||
|
|
||||||
defineProps({
|
withDefaults(
|
||||||
canResetPassword: Boolean,
|
defineProps<{
|
||||||
status: String,
|
canResetPassword?: boolean;
|
||||||
});
|
status?: string;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
canResetPassword: false,
|
||||||
|
status: '',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
email: '',
|
email: '',
|
||||||
@@ -28,8 +34,8 @@ const submit = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const page = usePage<{
|
const page = usePage<{
|
||||||
flash: {
|
flash?: {
|
||||||
message: string;
|
message?: string;
|
||||||
};
|
};
|
||||||
}>();
|
}>();
|
||||||
</script>
|
</script>
|
||||||
@@ -61,6 +67,9 @@ const page = usePage<{
|
|||||||
{{ page.props.flash?.message }}
|
{{ page.props.flash?.message }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Extension seam: alternative-auth errors (e.g. SSO callback failures) -->
|
||||||
|
<slot name="error" />
|
||||||
|
|
||||||
<form @submit.prevent="submit">
|
<form @submit.prevent="submit">
|
||||||
<Field>
|
<Field>
|
||||||
<FieldLabel for="email">Email</FieldLabel>
|
<FieldLabel for="email">Email</FieldLabel>
|
||||||
@@ -103,5 +112,8 @@ const page = usePage<{
|
|||||||
</PrimaryButton>
|
</PrimaryButton>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<!-- Extension seam: alternative auth methods (e.g. SSO providers) -->
|
||||||
|
<slot name="alternatives" />
|
||||||
</AuthenticationCard>
|
</AuthenticationCard>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -10,35 +10,73 @@ import { QueryClient, VueQueryPlugin } from '@tanstack/vue-query';
|
|||||||
import { type DefineComponent } from 'vue';
|
import { type DefineComponent } from 'vue';
|
||||||
import { setupPrefetching } from '@/utils/prefetch';
|
import { setupPrefetching } from '@/utils/prefetch';
|
||||||
|
|
||||||
|
interface ExtensionManifest {
|
||||||
|
name?: string;
|
||||||
|
alias?: string;
|
||||||
|
}
|
||||||
|
|
||||||
const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
|
const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
|
||||||
const pinia = createPinia();
|
const pinia = createPinia();
|
||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
|
const extensionManifests = import.meta.glob('../../extensions/**/module.json', {
|
||||||
|
eager: true,
|
||||||
|
import: 'default',
|
||||||
|
}) as Record<string, ExtensionManifest>;
|
||||||
|
// BillingPortal is a Vue 2 component and must not be bundled into the Vue 3 app.
|
||||||
|
const extensionPages = import.meta.glob<DefineComponent>([
|
||||||
|
'../../extensions/**/resources/js/Pages/**/*.vue',
|
||||||
|
'!**/BillingPortal.vue',
|
||||||
|
]);
|
||||||
|
const extensionDirectories = Object.entries(extensionManifests).reduce<Record<string, string>>(
|
||||||
|
(directories, [path, manifest]) => {
|
||||||
|
const match = path.match(/^\.\.\/\.\.\/extensions\/([^/]+)\/module\.json$/);
|
||||||
|
const extensionDirectory = match?.[1];
|
||||||
|
|
||||||
|
if (extensionDirectory === undefined) {
|
||||||
|
return directories;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const key of [manifest.name, manifest.alias, extensionDirectory]) {
|
||||||
|
if (typeof key !== 'string' || key === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
directories[key] = extensionDirectory;
|
||||||
|
directories[key.toLowerCase()] = extensionDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
return directories;
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
function resolveExtensionDirectory(moduleName: string): string {
|
||||||
|
return (
|
||||||
|
extensionDirectories[moduleName] ??
|
||||||
|
extensionDirectories[moduleName.toLowerCase()] ??
|
||||||
|
moduleName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
createInertiaApp({
|
createInertiaApp({
|
||||||
title: (title) => `${title} - ${appName}`,
|
title: (title) => `${title} - ${appName}`,
|
||||||
resolve: (name) => {
|
resolve: (name) => {
|
||||||
if (name.includes('Invoicing::')) {
|
// "Module::Page" (both halves present) resolves to that extension's page
|
||||||
const [module, page] = name.split('::');
|
// directory; everything else is a host page under resources/js/Pages.
|
||||||
|
const [module, ...pageSegments] = name.split('::');
|
||||||
|
const page = pageSegments.join('::');
|
||||||
|
|
||||||
const pagePath = module
|
if (module && page) {
|
||||||
? `../../extensions/${module}/resources/js/Pages/${page}.vue`
|
const extensionDirectory = resolveExtensionDirectory(module);
|
||||||
: `./Pages/${page}.vue`;
|
const pagePath = `../../extensions/${extensionDirectory}/resources/js/Pages/${page}.vue`;
|
||||||
|
|
||||||
// BillingPortal is a Vue 2 Component and therefore should not be imported
|
return resolvePageComponent(pagePath, extensionPages);
|
||||||
const pages = module
|
|
||||||
? import.meta.glob<DefineComponent>([
|
|
||||||
'../../extensions/**/resources/js/Pages/*.vue',
|
|
||||||
'!**/BillingPortal.vue',
|
|
||||||
])
|
|
||||||
: import.meta.glob<DefineComponent>('./Pages/**/*.vue');
|
|
||||||
|
|
||||||
return resolvePageComponent(pagePath, pages);
|
|
||||||
} else {
|
|
||||||
return resolvePageComponent(
|
|
||||||
`./Pages/${name}.vue`,
|
|
||||||
import.meta.glob<DefineComponent>('./Pages/**/*.vue')
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return resolvePageComponent(
|
||||||
|
`./Pages/${name}.vue`,
|
||||||
|
import.meta.glob<DefineComponent>('./Pages/**/*.vue')
|
||||||
|
);
|
||||||
},
|
},
|
||||||
setup({ el, App, props, plugin }) {
|
setup({ el, App, props, plugin }) {
|
||||||
const app = createApp({ render: () => h(App, props) });
|
const app = createApp({ render: () => h(App, props) });
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ declare(strict_types=1);
|
|||||||
namespace Tests\Unit\Service;
|
namespace Tests\Unit\Service;
|
||||||
|
|
||||||
use App\Enums\Role;
|
use App\Enums\Role;
|
||||||
|
use App\Enums\Weekday;
|
||||||
use App\Models\Member;
|
use App\Models\Member;
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
|
use App\Models\OrganizationInvitation;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\ProjectMember;
|
use App\Models\ProjectMember;
|
||||||
use App\Models\TimeEntry;
|
use App\Models\TimeEntry;
|
||||||
@@ -135,4 +137,60 @@ class UserServiceTest extends TestCase
|
|||||||
$this->assertSame(Role::Owner->value, $newMember->role);
|
$this->assertSame(Role::Owner->value, $newMember->role);
|
||||||
$this->assertSame($newOrganization->getKey(), $user->currentOrganization->getKey());
|
$this->assertSame($newOrganization->getKey(), $user->currentOrganization->getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_create_passwordless_user_joins_accepted_invitation_organization_instead_of_creating_personal_one(): void
|
||||||
|
{
|
||||||
|
// Arrange — an accepted invitation exists for the email (e.g. the user
|
||||||
|
// followed the invite link, then signs up via SSO). Casing differs to
|
||||||
|
// prove the email is normalised before the invitation is matched.
|
||||||
|
$organization = Organization::factory()->create();
|
||||||
|
OrganizationInvitation::factory()
|
||||||
|
->forOrganization($organization)
|
||||||
|
->role(Role::Employee)
|
||||||
|
->accepted()
|
||||||
|
->create([
|
||||||
|
'email' => 'invitee@example.com',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$user = $this->userService->createPasswordlessUser(
|
||||||
|
'Invitee',
|
||||||
|
'Invitee@Example.com',
|
||||||
|
'UTC',
|
||||||
|
Weekday::Monday,
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Assert — invitation is materialised, no personal organization is created
|
||||||
|
$this->assertNull($user->password);
|
||||||
|
$this->assertDatabaseMissing(OrganizationInvitation::class, [
|
||||||
|
'email' => 'invitee@example.com',
|
||||||
|
]);
|
||||||
|
$user->refresh();
|
||||||
|
$this->assertSame(1, $user->organizations()->count());
|
||||||
|
$this->assertSame($organization->getKey(), $user->organizations()->first()->getKey());
|
||||||
|
$member = Member::whereBelongsTo($user)->whereBelongsTo($organization)->firstOrFail();
|
||||||
|
$this->assertSame(Role::Employee->value, $member->role);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_create_passwordless_user_creates_personal_organization_when_no_invitation_exists(): void
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
$user = $this->userService->createPasswordlessUser(
|
||||||
|
'Solo User',
|
||||||
|
'solo@example.com',
|
||||||
|
'UTC',
|
||||||
|
Weekday::Monday,
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Assert — a personal organization is created, owned by the user and set current
|
||||||
|
$user->refresh();
|
||||||
|
$this->assertNull($user->password);
|
||||||
|
$this->assertSame(1, $user->organizations()->count());
|
||||||
|
$organization = $user->organizations()->first();
|
||||||
|
$this->assertTrue($organization->personal_team);
|
||||||
|
$this->assertSame($user->getKey(), $organization->user_id);
|
||||||
|
$this->assertSame($organization->getKey(), $user->currentOrganization->getKey());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user