mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 19:17:48 +00:00 
			
		
		
		
	 341487b93e
			
		
	
	341487b93e
	
	
	
		
			
			## Linear reference: https://linear.app/chatwoot/issue/CW-4649/re-imagine-assignments ## Description This PR introduces the foundation for Assignment V2 system by implementing assignment policies and their association with inboxes. Assignment policies allow configuring how conversations are distributed among agents, with support for different assignment orders (round_robin in community, balanced in enterprise) and conversation prioritization strategies Fixes # (issue) ## Type of change Please delete options that are not relevant. - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality not to work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? Test Coverage: - Controller specs for assignment policies CRUD operations - Enterprise-specific specs for balanced assignment order - Model specs for community/enterprise separation Manual Testing: 1. Create assignment policy: POST /api/v1/accounts/{id}/assignment_policies 2. List policies: GET /api/v1/accounts/{id}/assignment_policies 3. Assign policy to inbox: POST /api/v1/accounts/{id}/assignment_policies/{id}/inboxes 4. View inbox policy: GET /api/v1/accounts/{id}/inboxes/{id}/assignment_policy 5. Verify community edition ignores "balanced" assignment order 6. Verify enterprise edition supports both "round_robin" and "balanced" - testing the flows after enterprise folder deletion ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Pranav <pranavrajs@gmail.com> Co-authored-by: Pranav <pranav@chatwoot.com>
		
			
				
	
	
		
			47 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| class Api::V1::Accounts::Inboxes::AssignmentPoliciesController < Api::V1::Accounts::BaseController
 | |
|   before_action :fetch_inbox
 | |
|   before_action :fetch_assignment_policy, only: [:create]
 | |
|   before_action -> { check_authorization(AssignmentPolicy) }
 | |
|   before_action :validate_assignment_policy, only: [:show, :destroy]
 | |
| 
 | |
|   def show
 | |
|     @assignment_policy = @inbox.assignment_policy
 | |
|   end
 | |
| 
 | |
|   def create
 | |
|     # There should be only one assignment policy for an inbox.
 | |
|     # If there is a new request to add an assignment policy, we will
 | |
|     # delete the old one and attach the new policy
 | |
|     remove_inbox_assignment_policy
 | |
|     @inbox_assignment_policy = @inbox.create_inbox_assignment_policy!(assignment_policy: @assignment_policy)
 | |
|     @assignment_policy = @inbox.assignment_policy
 | |
|   end
 | |
| 
 | |
|   def destroy
 | |
|     remove_inbox_assignment_policy
 | |
|     head :ok
 | |
|   end
 | |
| 
 | |
|   private
 | |
| 
 | |
|   def remove_inbox_assignment_policy
 | |
|     @inbox.inbox_assignment_policy&.destroy
 | |
|   end
 | |
| 
 | |
|   def fetch_inbox
 | |
|     @inbox = Current.account.inboxes.find(permitted_params[:inbox_id])
 | |
|   end
 | |
| 
 | |
|   def fetch_assignment_policy
 | |
|     @assignment_policy = Current.account.assignment_policies.find(permitted_params[:assignment_policy_id])
 | |
|   end
 | |
| 
 | |
|   def permitted_params
 | |
|     params.permit(:assignment_policy_id, :inbox_id)
 | |
|   end
 | |
| 
 | |
|   def validate_assignment_policy
 | |
|     return render_not_found_error(I18n.t('errors.assignment_policy.not_found')) unless @inbox.assignment_policy
 | |
|   end
 | |
| end
 |