mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-12-06 17:52:16 +00:00
Detect project members of another organization in the database consistency check
This commit is contained in:
committed by
Constantin Graf
parent
50c028ee23
commit
89d004f88c
@@ -106,6 +106,15 @@ class SelfHostDatabaseConsistency extends Command
|
||||
})->get();
|
||||
$this->logProblems($problems, 'Users have a current organization that they are not a member of', $hadAProblem);
|
||||
|
||||
// Project members need to be a member of the organization of the project
|
||||
$problems = DB::table('project_members')
|
||||
->select(['project_members.id as id'])
|
||||
->join('projects', 'project_members.project_id', '=', 'projects.id')
|
||||
->join('members', 'project_members.member_id', '=', 'members.id')
|
||||
->whereColumn('members.organization_id', '!=', 'projects.organization_id')
|
||||
->get();
|
||||
$this->logProblems($problems, 'Project members have a member that does not belong to the organization of the project', $hadAProblem);
|
||||
|
||||
return $hadAProblem ? self::FAILURE : self::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Enums\Role;
|
||||
use App\Models\Client;
|
||||
use App\Models\Organization;
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectMember;
|
||||
use App\Models\Task;
|
||||
use App\Models\TimeEntry;
|
||||
use App\Models\User;
|
||||
@@ -203,4 +204,22 @@ class SelfHostDatabaseConsistencyCommandTest extends TestCaseWithDatabase
|
||||
$output = Artisan::output();
|
||||
$this->assertSame("Consistency problem: Time entries have an end that is before the start\n - ".$timeEntry->getKey()."\n", $output);
|
||||
}
|
||||
|
||||
public function test_checks_that_project_members_belong_to_the_organization_of_the_project(): void
|
||||
{
|
||||
// Arrange
|
||||
$user = $this->createUserWithRole(Role::Owner);
|
||||
$otherUser = $this->createUserWithRole(Role::Owner);
|
||||
$project = Project::factory()->forOrganization($user->organization)->create();
|
||||
ProjectMember::factory()->forProject($project)->forMember($user->member)->create();
|
||||
$projectMember = ProjectMember::factory()->forProject($project)->forMember($otherUser->member)->create();
|
||||
|
||||
// Act
|
||||
$exitCode = $this->withoutMockingConsoleOutput()->artisan('self-host:database-consistency');
|
||||
|
||||
// Assert
|
||||
$this->assertSame(Command::FAILURE, $exitCode);
|
||||
$output = Artisan::output();
|
||||
$this->assertSame("Consistency problem: Project members have a member that does not belong to the organization of the project\n - ".$projectMember->getKey()."\n", $output);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user