Skip to content

Commit

Permalink
Refactor existing Interactors for use without FormAnswer
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-l-brockwell committed Nov 27, 2024
1 parent 1f5fbc3 commit 7d273e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
22 changes: 10 additions & 12 deletions app/interactors/admin_actions/add_collaborator.rb
Original file line number Diff line number Diff line change
@@ -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!"
Expand All @@ -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
Expand Down
15 changes: 4 additions & 11 deletions app/interactors/admin_actions/search_collaborator_candidates.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 7d273e6

Please sign in to comment.