Features: - Support login via phone number or email (LoginRequest) - Add members:import-roster command for Excel roster import - Merge survey emails with roster data Code Quality (Phase 1-4): - Add database locking for balance calculation - Add self-approval checks for finance workflow - Create service layer (FinanceDocumentApprovalService, PaymentVerificationService) - Add HasAccountingEntries and HasApprovalWorkflow traits - Create FormRequest classes for validation - Add status-badge component - Define authorization gates in AuthServiceProvider - Add accounting config file Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
140 lines
4.0 KiB
PHP
140 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Traits;
|
|
|
|
use App\Models\User;
|
|
use Spatie\Permission\Models\Permission;
|
|
use Spatie\Permission\Models\Role;
|
|
|
|
trait SeedsRolesAndPermissions
|
|
{
|
|
/**
|
|
* Seed all roles and permissions for testing
|
|
*/
|
|
protected function seedRolesAndPermissions(): void
|
|
{
|
|
$this->artisan('db:seed', ['--class' => 'FinancialWorkflowPermissionsSeeder', '--force' => true]);
|
|
}
|
|
|
|
/**
|
|
* Create a user with a specific role
|
|
*/
|
|
protected function createUserWithRole(string $role, array $attributes = []): User
|
|
{
|
|
$user = User::factory()->create($attributes);
|
|
$user->assignRole($role);
|
|
|
|
return $user;
|
|
}
|
|
|
|
/**
|
|
* Create an admin user
|
|
*/
|
|
protected function createAdmin(array $attributes = []): User
|
|
{
|
|
return $this->createUserWithRole('admin', $attributes);
|
|
}
|
|
|
|
/**
|
|
* Create a secretary general user (first approval stage in new workflow)
|
|
*/
|
|
protected function createSecretary(array $attributes = []): User
|
|
{
|
|
return $this->createUserWithRole('secretary_general', $attributes);
|
|
}
|
|
|
|
/**
|
|
* Create a finance cashier user
|
|
*/
|
|
protected function createCashier(array $attributes = []): User
|
|
{
|
|
return $this->createUserWithRole('finance_cashier', $attributes);
|
|
}
|
|
|
|
/**
|
|
* Create a finance accountant user
|
|
*/
|
|
protected function createAccountant(array $attributes = []): User
|
|
{
|
|
return $this->createUserWithRole('finance_accountant', $attributes);
|
|
}
|
|
|
|
/**
|
|
* Create a finance chair user
|
|
*/
|
|
protected function createChair(array $attributes = []): User
|
|
{
|
|
return $this->createUserWithRole('finance_chair', $attributes);
|
|
}
|
|
|
|
/**
|
|
* Create a finance board member user
|
|
*/
|
|
protected function createBoardMember(array $attributes = []): User
|
|
{
|
|
return $this->createUserWithRole('finance_board_member', $attributes);
|
|
}
|
|
|
|
/**
|
|
* Create a membership manager user
|
|
*/
|
|
protected function createMembershipManager(array $attributes = []): User
|
|
{
|
|
return $this->createUserWithRole('membership_manager', $attributes);
|
|
}
|
|
|
|
/**
|
|
* Create a super admin user (with all permissions)
|
|
*/
|
|
protected function createSuperAdmin(array $attributes = []): User
|
|
{
|
|
// Create super_admin role if it doesn't exist
|
|
Role::firstOrCreate(['name' => 'super_admin', 'guard_name' => 'web']);
|
|
|
|
// Grant all permissions to super_admin
|
|
$superAdminRole = Role::findByName('super_admin');
|
|
$superAdminRole->syncPermissions(Permission::all());
|
|
|
|
return $this->createUserWithRole('super_admin', $attributes);
|
|
}
|
|
|
|
/**
|
|
* Create a member role user (non-admin member)
|
|
*/
|
|
protected function createMemberUser(array $attributes = []): User
|
|
{
|
|
// Create member role if it doesn't exist
|
|
Role::firstOrCreate(['name' => 'member', 'guard_name' => 'web']);
|
|
|
|
return $this->createUserWithRole('member', $attributes);
|
|
}
|
|
|
|
/**
|
|
* Create a user with specific permissions
|
|
*/
|
|
protected function createUserWithPermissions(array $permissions, array $attributes = []): User
|
|
{
|
|
$user = User::factory()->create($attributes);
|
|
foreach ($permissions as $permission) {
|
|
Permission::findOrCreate($permission, 'web');
|
|
$user->givePermissionTo($permission);
|
|
}
|
|
|
|
return $user;
|
|
}
|
|
|
|
/**
|
|
* Get all finance approval users for new workflow (secretary, chair, board)
|
|
*/
|
|
protected function createFinanceApprovalTeam(): array
|
|
{
|
|
return [
|
|
'secretary' => $this->createSecretary(['email' => 'secretary@test.com']),
|
|
'chair' => $this->createChair(['email' => 'chair@test.com']),
|
|
'board_member' => $this->createBoardMember(['email' => 'board@test.com']),
|
|
'cashier' => $this->createCashier(['email' => 'cashier@test.com']),
|
|
'accountant' => $this->createAccountant(['email' => 'accountant@test.com']),
|
|
];
|
|
}
|
|
}
|