mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-11 17:52:15 +01:00
Added user and organization deletion system; Added coverage annotations
This commit is contained in:
committed by
Constantin Graf
parent
8857befc6c
commit
86f5ea47bb
@@ -22,7 +22,7 @@ class OrganizationFactory extends Factory
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->unique()->company(),
|
||||
'currency' => $this->faker->currencyCode,
|
||||
'currency' => $this->faker->currencyCode(),
|
||||
'billable_rate' => $this->faker->numberBetween(50, 1000) * 100,
|
||||
'user_id' => User::factory(),
|
||||
'personal_team' => true,
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Enums\Weekday;
|
||||
use App\Models\Organization;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
@@ -86,6 +87,20 @@ class UserFactory extends Factory
|
||||
});
|
||||
}
|
||||
|
||||
public function withProfilePicture(): static
|
||||
{
|
||||
$profilePhoto = $this->faker->image(null, 500, 500);
|
||||
/** @see \Illuminate\Http\FileHelpers::hashName */
|
||||
$path = 'profile-photos/'.Str::random(40).'.png';
|
||||
Storage::disk(config('jetstream.profile_photo_disk', 'public'))->put($path, $profilePhoto);
|
||||
|
||||
return $this->state(function (array $attributes) use ($path): array {
|
||||
return [
|
||||
'profile_photo_path' => $path,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the user should have a personal team.
|
||||
*/
|
||||
|
||||
@@ -20,14 +20,14 @@ return new class extends Migration
|
||||
$table->foreign('project_id')
|
||||
->references('id')
|
||||
->on('projects')
|
||||
->onDelete('restrict')
|
||||
->onUpdate('cascade');
|
||||
->restrictOnDelete()
|
||||
->cascadeOnUpdate();
|
||||
$table->uuid('user_id');
|
||||
$table->foreign('user_id')
|
||||
->references('id')
|
||||
->on('users')
|
||||
->onDelete('restrict')
|
||||
->onUpdate('cascade');
|
||||
->restrictOnDelete()
|
||||
->cascadeOnUpdate();
|
||||
$table->timestamps();
|
||||
$table->unique(['project_id', 'user_id']);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('time_entries', function (Blueprint $table) {
|
||||
$table->dropForeign(['member_id']);
|
||||
$table->foreign('member_id')
|
||||
->references('id')
|
||||
->on('members')
|
||||
->restrictOnDelete()
|
||||
->cascadeOnUpdate();
|
||||
$table->dropForeign(['client_id']);
|
||||
$table->foreign('client_id')
|
||||
->references('id')
|
||||
->on('clients')
|
||||
->restrictOnDelete()
|
||||
->cascadeOnUpdate();
|
||||
});
|
||||
Schema::table('project_members', function (Blueprint $table) {
|
||||
$table->dropForeign(['member_id']);
|
||||
$table->foreign('member_id')
|
||||
->references('id')
|
||||
->on('members')
|
||||
->restrictOnDelete()
|
||||
->cascadeOnUpdate();
|
||||
});
|
||||
Schema::table('organization_invitations', function (Blueprint $table) {
|
||||
$table->dropForeign(['organization_id']);
|
||||
$table->foreign('organization_id')
|
||||
->references('id')
|
||||
->on('organizations')
|
||||
->restrictOnDelete()
|
||||
->cascadeOnUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('time_entries', function (Blueprint $table) {
|
||||
$table->dropForeign(['member_id']);
|
||||
$table->foreign('member_id')
|
||||
->references('id')
|
||||
->on('members')
|
||||
->cascadeOnDelete()
|
||||
->cascadeOnUpdate();
|
||||
$table->dropForeign(['client_id']);
|
||||
$table->foreign('client_id')
|
||||
->references('id')
|
||||
->on('clients')
|
||||
->cascadeOnDelete()
|
||||
->cascadeOnUpdate();
|
||||
});
|
||||
Schema::table('project_members', function (Blueprint $table) {
|
||||
$table->dropForeign(['member_id']);
|
||||
$table->foreign('member_id')
|
||||
->references('id')
|
||||
->on('members')
|
||||
->cascadeOnDelete()
|
||||
->cascadeOnUpdate();
|
||||
});
|
||||
Schema::table('organization_invitations', function (Blueprint $table) {
|
||||
$table->dropForeign(['organization_id']);
|
||||
$table->foreign('organization_id')
|
||||
->references('id')
|
||||
->on('organizations')
|
||||
->cascadeOnDelete()
|
||||
->cascadeOnUpdate();
|
||||
});
|
||||
}
|
||||
};
|
||||
1137
database/schema/pgsql-schema.sql
Normal file
1137
database/schema/pgsql-schema.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -83,10 +83,10 @@ class DatabaseSeeder extends Seeder
|
||||
->count(5)
|
||||
->forMember($userWithMultipleOrganizationsAcmeMember)
|
||||
->create();
|
||||
$client = Client::factory()->forOrganization($organizationAcme)->create([
|
||||
$acmeClient = Client::factory()->forOrganization($organizationAcme)->create([
|
||||
'name' => 'Big Company',
|
||||
]);
|
||||
$bigCompanyProject = Project::factory()->forOrganization($organizationAcme)->forClient($client)->create([
|
||||
$bigCompanyProject = Project::factory()->forOrganization($organizationAcme)->forClient($acmeClient)->create([
|
||||
'name' => 'Big Company Project',
|
||||
]);
|
||||
ProjectMember::factory()->forProject($bigCompanyProject)->forMember($userAcmeEmployeeMember)->create();
|
||||
@@ -105,11 +105,11 @@ class DatabaseSeeder extends Seeder
|
||||
'name' => 'Internal Project',
|
||||
]);
|
||||
|
||||
$organization2Owner = User::factory()->create([
|
||||
$rivalOwner = User::factory()->create([
|
||||
'name' => 'Other Owner',
|
||||
'email' => 'owner@rival-company.test',
|
||||
]);
|
||||
$organizationRival = Organization::factory()->withOwner($organization2Owner)->create([
|
||||
$organizationRival = Organization::factory()->withOwner($rivalOwner)->create([
|
||||
'name' => 'Rival Corp',
|
||||
'personal_team' => true,
|
||||
'currency' => 'USD',
|
||||
@@ -120,9 +120,12 @@ class DatabaseSeeder extends Seeder
|
||||
]);
|
||||
$userRivalManagerMember = Member::factory()->forUser($userRivalManager)->forOrganization($organizationRival)->role(Role::Admin)->create();
|
||||
$userWithMultipleOrganizationsRivalMember = Member::factory()->forUser($userWithMultipleOrganizations)->forOrganization($organizationRival)->role(Role::Employee)->create();
|
||||
$otherCompanyProject = Project::factory()->forOrganization($organizationRival)->forClient($client)->create([
|
||||
$rivalClient = Client::factory()->forOrganization($organizationRival)->create([
|
||||
'name' => 'Scale Company',
|
||||
]);
|
||||
$otherCompanyProject = Project::factory()->forOrganization($organizationRival)->forClient($rivalClient)->create([
|
||||
'name' => 'Scale Company - Project ABC',
|
||||
]);
|
||||
ProjectMember::factory()->forProject($otherCompanyProject)->forMember($userRivalManagerMember)->create();
|
||||
ProjectMember::factory()->forProject($otherCompanyProject)->forMember($userWithMultipleOrganizationsRivalMember)->create();
|
||||
TimeEntry::factory()
|
||||
|
||||
Reference in New Issue
Block a user