Repository navigation
[Settings]: Admin panel — assign Users to companies #234
Copy link
Copy link
Closed
Labels
refinedRefined with SMART plan / test suggestionsRefined with SMART plan / test suggestions
Milestone
Description
SMART Plan — As an Admin, in the admin Panel I want to be able to assign Users to multiple companies
Specific
In the Admin panel (/admin), the CompanyResource table view gains a bulk action called "Assign User". When one or more companies are selected and the action is triggered, a modal opens with a searchable select of all User records. On confirmation, the selected user is attached to every selected company via the existing company_user pivot table.
Measurable
- Selecting 2+ companies and triggering the bulk action opens a modal with a User select.
- After confirmation, a
company_userrow exists for the selected user in each selected company. - Already-attached users are not duplicated (use
syncWithoutDetachingorattachwith existence check). - A Filament success notification confirms how many companies were updated.
Achievable
- Verify
company_userpivot table andCompany::users()/User::companies()BelongsToMany relations exist —Modules/Core/Models/Company.php,Modules/Core/Models/User.php - Create
AssignUserBulkActionFilament bulk action class —Modules/Core/Filament/Admin/Resources/Companies/Tables/Actions/AssignUserBulkAction.php - Register the bulk action on
CompanyResourcetable —Modules/Core/Filament/Admin/Resources/Companies/Tables/CompanyTable.php
Relevant
Platform admins frequently need to grant a support or billing user access to a portfolio of company accounts simultaneously. This bulk action eliminates the need to open each company individually and add the user one by one.
Time-bound
Sprint 6.
Arrange · Act · Assert
// Modules/Core/Tests/Feature/Admin/CompanyUserBulkActionTest.php
#[Test]
public function it_assigns_user_to_multiple_companies(): void
{
/* Arrange */
$companies = Company::factory()->count(2)->create();
$user = User::factory()->create(['is_active' => true]);
$ids = $companies->pluck('id')->all();
/* Act */
Livewire::actingAs($this->superAdmin())
->test(ListCompanies::class)
->callBulkAction('assignUser', $ids, ['user_id' => $user->id])
->assertHasNoErrors();
/* Assert */
foreach ($companies as $company) {
$this->assertDatabaseHas('company_user', [
'company_id' => $company->id,
'user_id' => $user->id,
]);
}
}Reacted by coderabbitai
Metadata
Metadata
Assignees
Labels
refinedRefined with SMART plan / test suggestionsRefined with SMART plan / test suggestions
Activity
coderabbitai commentedon Dec 28, 2025
📝 CodeRabbit Plan Mode
Generate an implementation plan and prompts that you can use with your favorite coding agent.
Examples
🔗 Similar Issues
Related Issues
👤 Suggested Assignees
🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord!
nielsdrost7 commentedon Jan 2, 2026
@coderabbitai make pull-request with AAA test Scenario's: Arrange, Act, Assert. And also make sure you test edge cases
coderabbitai commentedon Jan 2, 2026
Coding Plan
Approach
Create comprehensive PHPUnit feature tests following the AAA pattern to verify company assignment functionality for users in the admin panel. Tests will be written using a test-driven development approach to define expected behavior before implementation.
Observations
The application uses a modular Laravel architecture with Filament 3.x for the admin panel. The Core module contains user management functionality organized with separated concerns: UserResource delegates to UserForm for form fields and UsersTable for table configuration. A many-to-many relationship already exists between User and Company models via a
company_userpivot table with anis_ownerattribute. Testing follows a consistent AAA pattern using PHPUnit with AbstractAdminPanelTestCase providing base test setup with user and company fixtures.Assumptions
Assumption 1: Where should the new tests be located?
Options Considered:
Modules/Core/Tests/Feature/UsersTest.phpModules/Core/Tests/Feature/UserCompanyAssignmentTest.phpChosen Option: 2
Rationale: Create a dedicated test file to keep company assignment tests organized separately and make it easier to locate and maintain this specific functionality's test coverage.
💡 User Tips
Regenerate the plan with different choices with
@coderabbitai <feedback>.Implementation Steps
Implement Comprehensive Tests for Company Assignment
Create feature tests following the AAA pattern to verify all aspects of company assignment functionality. These tests define expected behavior using test-driven development and will serve as specifications for the feature implementation.
Task 1: Test Company Column Display in Users Table
Verify that company assignments are correctly displayed in the users table
Modules/Core/Tests/Feature/UserCompanyAssignmentTest.phpextending AbstractAdminPanelTestCaseTask 2: Test RelationManager Company List Display
Verify the RelationManager correctly shows assigned companies with pivot attributes
Task 3: Test Attaching Companies via RelationManager
Verify that companies can be attached through the RelationManager with explicit is_owner values
Task 4: Test Attaching Company Without is_owner Flag
Verify default behavior when is_owner is not specified during attachment
Task 5: Test Detaching Companies via RelationManager
Verify companies can be removed from users individually
Task 6: Test Bulk Detach of Multiple Companies
Verify bulk deletion works correctly for multiple companies at once
Task 7: Test Edge Case - Attaching Already Assigned Company
Verify behavior when attempting to attach a company that's already assigned to the user
Task 8: Test Edge Case - Updating Pivot Attribute
Verify that is_owner can be toggled for existing assignments
Task 9: Test Edge Case - User with No Companies
Verify graceful handling when user has no company assignments
Task 10: Test Permission and Authorization
Verify that only admin users can manage company assignments
🤖 Prompt for AI agents
🚀 Next Steps
🤖 All AI agent prompts combined
💡 Iterate on the plan with:
@coderabbitai <feedback>💬 Have feedback or questions? Drop into our discord!
nielsdrost7 commentedon Jan 3, 2026
@coderabbitai
🤖 Prompt for AI agents
Create a PR with those phpunit tests
coderabbitai commentedon Jan 3, 2026
I've updated the plan above based on your feedback. Ready to proceed when you are!
[-]As an Admin, in the admin Panel I want to be able to assign Users to multiple companies[/-][+][Settings]: Admin panel — assign Users to companies[/+]nielsdrost7 commentedon Jul 24, 2026
SMART Plan — Admin panel — assign Users to companies
Specific
In the Admin panel (
/admin), theCompanyResourcetable view gains a bulk action called "Assign User". When one or more companies are selected and the action is triggered, a modal opens with a searchable select of allUserrecords. On confirmation, the selected user is attached to every selected company via the existingcompany_userpivot table.Measurable
company_userrow exists for the selected user in each selected company.syncWithoutDetachingorattachwith existence check).Achievable
company_userpivot table andCompany::users()/User::companies()BelongsToMany relations exist.AssignUserBulkActionFilament bulk action class.CompanyResourcetable.Relevant
Platform admins frequently need to grant a support or billing user access to a portfolio of company accounts simultaneously. This bulk action eliminates the need to open each company individually.
Time-bound
Sprint 6.
assign Users to companies. (Closes InvoicePlane#234)