diff --git a/app/interactors/admin_actions/add_collaborator.rb b/app/interactors/admin_actions/add_collaborator.rb index 99a6d3773..6b4801215 100644 --- a/app/interactors/admin_actions/add_collaborator.rb +++ b/app/interactors/admin_actions/add_collaborator.rb @@ -1,17 +1,15 @@ module AdminActions class AddCollaborator - attr_reader :form_answer, - :user, - :success, - :errors + attr_reader :account, :role, :collaborator, :success, :errors - def initialize(form_answer, user) - @form_answer = form_answer - @user = user + def initialize(account:, collaborator:, role: "regular") + @account = account + @collaborator = collaborator + @role = role end def run - if user.can_be_added_to_collaborators_to_another_account? + if collaborator.can_be_added_to_collaborators_to_another_account? persist! else @errors = "can't be added as linked with another account!" @@ -27,13 +25,13 @@ def success? private def persist! - user.role = "regular" - user.account = form_answer.account + collaborator.role = role + collaborator.account = account - if user.save + if collaborator.save @success = true else - @errors = user.errors.full_messages.join(", ") + @errors = collaborator.errors.full_messages.join(", ") end end end diff --git a/app/interactors/admin_actions/search_collaborator_candidates.rb b/app/interactors/admin_actions/search_collaborator_candidates.rb index 766adb27c..4a41816b1 100644 --- a/app/interactors/admin_actions/search_collaborator_candidates.rb +++ b/app/interactors/admin_actions/search_collaborator_candidates.rb @@ -1,17 +1,10 @@ module AdminActions class SearchCollaboratorCandidates - attr_accessor :form_answer, - :account, - :existing_collaborators, - :candidates, - :query, - :error + attr_accessor :account, :existing_collaborators, :candidates, :query, :error - def initialize(form_answer, query = nil) - @query = query[:query] - @form_answer = form_answer - @account = form_answer.account - @existing_collaborators = account.users + def initialize(existing_collaborators:, params: {}) + @query = params[:query] + @existing_collaborators = existing_collaborators end def run