Class: SimpleTeams::AcceptInvitationService

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/service_objects/simple_teams/accept_invitation_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id, invitation_token) ⇒ AcceptInvitationService

Returns a new instance of AcceptInvitationService.



7
8
9
10
# File 'app/service_objects/simple_teams/accept_invitation_service.rb', line 7

def initialize(user_id, invitation_token)
  @user_id = user_id
  @invitation_token  = invitation_token
end

Instance Attribute Details

#invitation_tokenObject

Returns the value of attribute invitation_token.



5
6
7
# File 'app/service_objects/simple_teams/accept_invitation_service.rb', line 5

def invitation_token
  @invitation_token
end

#user_idObject

Returns the value of attribute user_id.



5
6
7
# File 'app/service_objects/simple_teams/accept_invitation_service.rb', line 5

def user_id
  @user_id
end

Instance Method Details

#invitationObject



34
35
36
# File 'app/service_objects/simple_teams/accept_invitation_service.rb', line 34

def invitation
  @invitation ||= Invitation.find_by(token: @invitation_token)
end

#performObject



19
20
21
22
23
24
25
26
27
28
# File 'app/service_objects/simple_teams/accept_invitation_service.rb', line 19

def perform
  ActiveRecord::Base.transaction do
    membership = team.memberships.create!(
      :member => user,
      :role => invitation.role
    )
    invitation.update!(membership: membership)
    invitation.accepted!
  end
end

#userObject



30
31
32
# File 'app/service_objects/simple_teams/accept_invitation_service.rb', line 30

def user
  @user ||= SimpleTeams.member_class.find(user_id)
end

#valid?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
# File 'app/service_objects/simple_teams/accept_invitation_service.rb', line 12

def valid?
  self.errors.clear
  validate_invitation_token
  validate_user_not_a_member
  !self.errors.any?
end