# Pull Request Template ## Description Unconfirmed agents (pending email verification) were incorrectly appearing in the "assign agent" dropdown for macros and automations. This fix filters out unconfirmed agents from these dropdowns and adds backend validation to prevent assignment of unconfirmed agents. Fixes #13223 ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? **Backend tests:** ```bash docker compose run --rm rails bundle exec rspec spec/services/action_service_spec.rb ``` - Added tests for confirmed agent assignment (should succeed) - Added tests for unconfirmed agent assignment (should be skipped) **Frontend tests:** ```bash docker compose run --rm rails pnpm test app/javascript/dashboard/composables/spec/useMacros.spec.js ``` - Updated mocks to use `getVerifiedAgents` getter **Manual testing:** 1. Create an unconfirmed agent via platform 2. Navigate to Settings → Macros → New Macro → Add "Assign Agent" action 3. Verify unconfirmed agent does NOT appear in dropdown 4. Navigate to Settings → Automations → New Automation → Add "Assign Agent" action 5. Verify unconfirmed agent does NOT appear in dropdown ## Checklist: - [x] My code follows the style guidelines of this project - [x] 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 - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Sojan Jose <sojan@pepalo.com>
114 lines
2.9 KiB
Ruby
114 lines
2.9 KiB
Ruby
class ActionService
|
|
include EmailHelper
|
|
|
|
def initialize(conversation)
|
|
@conversation = conversation.reload
|
|
@account = @conversation.account
|
|
end
|
|
|
|
def mute_conversation(_params)
|
|
@conversation.mute!
|
|
end
|
|
|
|
def snooze_conversation(_params)
|
|
@conversation.snoozed!
|
|
end
|
|
|
|
def resolve_conversation(_params)
|
|
@conversation.resolved!
|
|
end
|
|
|
|
def open_conversation(_params)
|
|
@conversation.open!
|
|
end
|
|
|
|
def pending_conversation(_params)
|
|
@conversation.pending!
|
|
end
|
|
|
|
def change_status(status)
|
|
@conversation.update!(status: status[0])
|
|
end
|
|
|
|
def change_priority(priority)
|
|
@conversation.update!(priority: (priority[0] == 'nil' ? nil : priority[0]))
|
|
end
|
|
|
|
def add_label(labels)
|
|
return if labels.empty?
|
|
|
|
@conversation.reload.add_labels(labels)
|
|
end
|
|
|
|
def assign_agent(agent_ids = [])
|
|
return @conversation.update!(assignee_id: nil) if agent_ids[0] == 'nil'
|
|
|
|
return unless agent_belongs_to_inbox?(agent_ids)
|
|
|
|
@agent = @account.users.find_by(id: agent_ids)
|
|
|
|
return unless @agent.present? && @agent.confirmed?
|
|
|
|
@conversation.update!(assignee_id: @agent.id)
|
|
end
|
|
|
|
def remove_label(labels)
|
|
return if labels.empty?
|
|
|
|
labels = @conversation.label_list - labels
|
|
@conversation.update(label_list: labels)
|
|
end
|
|
|
|
def assign_team(team_ids = [])
|
|
# FIXME: The explicit checks for zero or nil (string) is bad. Move
|
|
# this to a separate unassign action.
|
|
should_unassign = team_ids.blank? || %w[nil 0].include?(team_ids[0].to_s)
|
|
return @conversation.update!(team_id: nil) if should_unassign
|
|
|
|
# check if team belongs to account only if team_id is present
|
|
# if team_id is nil, then it means that the team is being unassigned
|
|
return unless !team_ids[0].nil? && team_belongs_to_account?(team_ids)
|
|
|
|
@conversation.update!(team_id: team_ids[0])
|
|
end
|
|
|
|
def remove_assigned_team(_params)
|
|
@conversation.update!(team_id: nil)
|
|
end
|
|
|
|
def send_email_transcript(emails)
|
|
return unless @account.email_transcript_enabled?
|
|
|
|
emails = emails[0].gsub(/\s+/, '').split(',')
|
|
|
|
emails.each do |email|
|
|
break unless @account.within_email_rate_limit?
|
|
|
|
email = parse_email_variables(@conversation, email)
|
|
ConversationReplyMailer.with(account: @conversation.account).conversation_transcript(@conversation, email)&.deliver_later
|
|
@account.increment_email_sent_count
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def agent_belongs_to_inbox?(agent_ids)
|
|
member_ids = @conversation.inbox.members.pluck(:user_id)
|
|
assignable_agent_ids = member_ids + @account.administrators.ids
|
|
|
|
assignable_agent_ids.include?(agent_ids[0])
|
|
end
|
|
|
|
def team_belongs_to_account?(team_ids)
|
|
@account.team_ids.include?(team_ids[0])
|
|
end
|
|
|
|
def conversation_a_tweet?
|
|
return false if @conversation.additional_attributes.blank?
|
|
|
|
@conversation.additional_attributes['type'] == 'tweet'
|
|
end
|
|
end
|
|
|
|
ActionService.include_mod_with('ActionService')
|