Class: LatoSpaces::Membership

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/lato_spaces/membership.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionsObject

lato index



4
5
6
# File 'app/models/lato_spaces/membership.rb', line 4

def actions
  @actions
end

#emailObject

Returns the value of attribute email.



3
4
5
# File 'app/models/lato_spaces/membership.rb', line 3

def email
  @email
end

#user_infosObject

lato index



4
5
6
# File 'app/models/lato_spaces/membership.rb', line 4

def user_infos
  @user_infos
end

Instance Method Details

#send_inviteObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/lato_spaces/membership.rb', line 90

def send_invite
  if lato_invitation.blank? || lato_user.present?
    errors.add(:base, 'This user is already a member of this space.')
    return false
  end

  result = lato_invitation.send_invite
  unless result
    errors.add(:base, lato_invitation.errors.full_messages.to_sentence)
    return false
  end

  true
end

#set_preferredObject

Operations



81
82
83
84
85
86
87
88
# File 'app/models/lato_spaces/membership.rb', line 81

def set_preferred
  ActiveRecord::Base.transaction do
    LatoSpaces::Membership.where(lato_user_id: lato_user_id).update_all(preferred: false)
    update!(preferred: true)
  end

  true
end

#user_infos_labelObject

Helpers



72
73
74
75
76
# File 'app/models/lato_spaces/membership.rb', line 72

def user_infos_label
  return lato_user.full_name if lato_user.present?
  return lato_invitation.email if lato_invitation.present?
  'Unknown'
end