Skip to content
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

Disable registration #300

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.ci
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_FORCE_HTTPS=false
APP_ENABLE_REGISTRATION=true
SESSION_SECURE_COOKIE=false

# Logging
Expand Down
29 changes: 12 additions & 17 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Application
APP_NAME=solidtime
APP_ENV=local
APP_KEY=base64:UNQNf1SXeASNkWux01Rj8EnHYx8FO0kAxWNDwktclkk=
APP_DEBUG=true
APP_URL=https://solidtime.test
AUDITING_ENABLED=true
APP_ENABLE_REGISTRATION=true
SUPER_ADMINS=admin@example.com
PAGINATION_PER_PAGE_DEFAULT=500

# Logging
LOG_CHANNEL=single
Expand All @@ -25,9 +28,16 @@ DB_TEST_DATABASE=laravel
DB_TEST_USERNAME=root
DB_TEST_PASSWORD=root

BROADCAST_DRIVER=log
# Broadcasting
BROADCAST_DRIVER=null

# Cache
CACHE_DRIVER=file

# Queue
QUEUE_CONNECTION=sync

# Session
SESSION_DRIVER=database
SESSION_LIFETIME=120

Expand All @@ -41,14 +51,6 @@ MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="no-reply@solidtime.test"
MAIL_FROM_NAME="${APP_NAME}"

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

# Filesystems
FILESYSTEM_DISK=s3
PUBLIC_FILESYSTEM_DISK=s3
Expand All @@ -65,16 +67,9 @@ GOTENBERG_URL=http://gotenberg:3000

VITE_HOST_NAME=vite.solidtime.test
VITE_APP_NAME="${APP_NAME}"
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

# Local setup
NGINX_HOST_NAME=solidtime.test
NETWORK_NAME=reverse-proxy-docker-traefik_routing

FORWARD_DB_PORT=5432
FORWARD_WEB_PORT=8083

PAGINATION_PER_PAGE_DEFAULT=500
42 changes: 16 additions & 26 deletions app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

namespace App\Actions\Fortify;

use App\Enums\Role;
use App\Enums\Weekday;
use App\Events\NewsletterRegistered;
use App\Models\Organization;
use App\Models\User;
use App\Service\IpLookup\IpLookupServiceContract;
use App\Service\TimezoneService;
use App\Service\UserService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use Korridor\LaravelModelValidationRules\Rules\UniqueEloquent;
Expand All @@ -34,6 +32,12 @@ class CreateNewUser implements CreatesNewUsers
*/
public function create(array $input): User
{
if (! config('app.enable_registration')) {
throw ValidationException::withMessages([
'email' => [__('Registration is disabled.')],
]);
}

Validator::make($input, [
'name' => [
'required',
Expand Down Expand Up @@ -81,30 +85,16 @@ public function create(array $input): User
$currency = $ipLookupResponse->currency;
}
$user = null;
$organization = null;
DB::transaction(function () use (&$user, &$organization, $input, $timezone, $startOfWeek, $currency): void {
$user = User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
'timezone' => $timezone ?? 'UTC',
'week_start' => $startOfWeek,
]);

$organization = new Organization;
$organization->name = explode(' ', $user->name, 2)[0]."'s Organization";
$organization->personal_team = true;
$organization->currency = $currency ?? 'EUR';
$organization->owner()->associate($user);
$organization->save();

$organization->users()->attach(
$user, [
'role' => Role::Owner->value,
]
DB::transaction(function () use (&$user, $input, $timezone, $startOfWeek, $currency): void {
$userService = app(UserService::class);
$user = $userService->createUser(
$input['name'],
$input['email'],
$input['password'],
$timezone ?? 'UTC',
$startOfWeek,
$currency ?? 'EUR',
);

$user->ownedTeams()->save($organization);
});

$newsletterConsent = isset($input['newsletter_consent']) && (bool) $input['newsletter_consent'];
Expand Down
14 changes: 2 additions & 12 deletions app/Actions/Jetstream/AddOrganizationMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
use App\Enums\Role;
use App\Models\Organization;
use App\Models\User;
use App\Service\MemberService;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\In;
use Korridor\LaravelModelValidationRules\Rules\ExistsEloquent;
use Laravel\Jetstream\Contracts\AddsTeamMembers;
use Laravel\Jetstream\Events\AddingTeamMember;
use Laravel\Jetstream\Events\TeamMemberAdded;

class AddOrganizationMember implements AddsTeamMembers
{
Expand All @@ -36,15 +34,7 @@ public function add(User $owner, Organization $organization, string $email, ?str
->where('is_placeholder', '=', false)
->firstOrFail();

AddingTeamMember::dispatch($organization, $newOrganizationMember);

DB::transaction(function () use ($organization, $newOrganizationMember, $role): void {
$organization->users()->attach(
$newOrganizationMember, ['role' => $role]
);
});

TeamMemberAdded::dispatch($organization, $newOrganizationMember);
app(MemberService::class)->addMember($newOrganizationMember, $organization, Role::from($role));
}

/**
Expand Down
89 changes: 89 additions & 0 deletions app/Console/Commands/Admin/UserCreateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands\Admin;

use App\Enums\Weekday;
use App\Models\Organization;
use App\Models\User;
use App\Service\UserService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use LogicException;

class UserCreateCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'admin:user:create
{ name : The name of the user }
{ email : The email of the user }
{ --ask-for-password : Ask for the password, otherwise the command will generate a random one }';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new user';

/**
* Execute the console command.
*/
public function handle(): int

Check warning on line 37 in app/Console/Commands/Admin/UserCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/Admin/UserCreateCommand.php#L37

Added line #L37 was not covered by tests
{
$name = $this->argument('name');
$email = $this->argument('email');
$askForPassword = (bool) $this->option('ask-for-password');

Check warning on line 41 in app/Console/Commands/Admin/UserCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/Admin/UserCreateCommand.php#L39-L41

Added lines #L39 - L41 were not covered by tests

if (User::query()->where('email', $email)->where('is_placeholder', '=', false)->exists()) {
$this->error('User with email "'.$email.'" already exists.');

Check warning on line 44 in app/Console/Commands/Admin/UserCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/Admin/UserCreateCommand.php#L43-L44

Added lines #L43 - L44 were not covered by tests

return self::FAILURE;

Check warning on line 46 in app/Console/Commands/Admin/UserCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/Admin/UserCreateCommand.php#L46

Added line #L46 was not covered by tests
}

if ($askForPassword) {
$outputPassword = false;
$password = $this->secret('Enter the password');

Check warning on line 51 in app/Console/Commands/Admin/UserCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/Admin/UserCreateCommand.php#L49-L51

Added lines #L49 - L51 were not covered by tests
} else {
$outputPassword = true;
$password = bin2hex(random_bytes(16));

Check warning on line 54 in app/Console/Commands/Admin/UserCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/Admin/UserCreateCommand.php#L53-L54

Added lines #L53 - L54 were not covered by tests
}

$user = null;
DB::transaction(function () use (&$user, $name, $email, $password): void {
$user = app(UserService::class)->createUser(
$name,
$email,
$password,
'UTC',
Weekday::Monday,
'EUR',
);
});

Check warning on line 67 in app/Console/Commands/Admin/UserCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/Admin/UserCreateCommand.php#L57-L67

Added lines #L57 - L67 were not covered by tests
/** @var Organization|null $organization */
$organization = $user->ownedTeams->first();
if ($organization === null) {
throw new LogicException('User does not have an organization');

Check warning on line 71 in app/Console/Commands/Admin/UserCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/Admin/UserCreateCommand.php#L69-L71

Added lines #L69 - L71 were not covered by tests
}

$this->info('Created user "'.$name.'" ("'.$email.'")');
$this->line('ID: '.$user->getKey());
$this->line('Name: '.$name);
$this->line('Email: '.$email);
if ($outputPassword) {
$this->line('Password: '.$password);

Check warning on line 79 in app/Console/Commands/Admin/UserCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/Admin/UserCreateCommand.php#L74-L79

Added lines #L74 - L79 were not covered by tests
}
$this->line('Timezone: '.$user->timezone);
$this->line('Week start: '.$user->week_start->value);

Check warning on line 82 in app/Console/Commands/Admin/UserCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/Admin/UserCreateCommand.php#L81-L82

Added lines #L81 - L82 were not covered by tests

// Organization
$this->line('Currency: '.$organization->currency);

Check warning on line 85 in app/Console/Commands/Admin/UserCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/Admin/UserCreateCommand.php#L85

Added line #L85 was not covered by tests

return self::SUCCESS;

Check warning on line 87 in app/Console/Commands/Admin/UserCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/Admin/UserCreateCommand.php#L87

Added line #L87 was not covered by tests
}
}
4 changes: 3 additions & 1 deletion app/Console/Commands/Admin/UserVerifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function handle(): int
$this->info('Start verifying user with email "'.$email.'"');

/** @var User|null $user */
$user = User::where('email', $email)->first();
$user = User::query()->where('email', $email)
->where('is_placeholder', '=', false)
->first();

if ($user === null) {
$this->error('User with email "'.$email.'" not found.');
Expand Down
3 changes: 2 additions & 1 deletion app/Filament/Resources/ClientResource/Pages/EditClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class EditClient extends EditRecord
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
Actions\DeleteAction::make()
->icon('heroicon-m-trash'),
];
}
}
3 changes: 2 additions & 1 deletion app/Filament/Resources/ClientResource/Pages/ListClients.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class ListClients extends ListRecords
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
Actions\CreateAction::make()
->icon('heroicon-s-plus'),
];
}
}
Loading
Loading