Class: Member

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/member.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#raw_invitation_tokenObject (readonly)

Returns the value of attribute raw_invitation_token.



14
15
16
# File 'app/models/member.rb', line 14

def raw_invitation_token
  @raw_invitation_token
end

Class Method Details

.enabled!Object



57
58
59
60
# File 'app/models/member.rb', line 57

def self.enabled!
  member_org_ids = self.where(disabled: false).map(&:organization_id)
  Organization.where(id: member_org_ids)
end

Instance Method Details

#access_locked?Boolean

Verifies whether a user is locked or not.

Returns:

  • (Boolean)


53
54
55
# File 'app/models/member.rb', line 53

def access_locked?
  !!locked_at && !lock_expired?
end

#disable!Object



62
63
64
# File 'app/models/member.rb', line 62

def disable!
  self.update_attributes(disabled: true)
end

#email_invited_byObject



18
19
20
21
22
# File 'app/models/member.rb', line 18

def email_invited_by
  self.invitation_token = ''
  self.invitation_accepted_at = Time.now
  self.save(validate: false)
end

#invite_user!Object



24
25
26
27
28
29
30
# File 'app/models/member.rb', line 24

def invite_user!
	generate_invitation_token!
  invitation_created_at = Time.now
	invitation_sent_at = Time.now
	self.save(validate: false)
	user.send_devise_notification(:invitation_instructions, self.raw_invitation_token)
end

#lock_access!(opts = { }) ⇒ Object

when you lock access, you could pass the next hash

`{ send_instructions: false } as option`.


34
35
36
37
38
39
40
41
42
# File 'app/models/member.rb', line 34

def lock_access!(opts = { })
  self.locked_at = Time.now.utc

  if unlock_strategy_enabled?(:email) && opts.fetch(:send_instructions, true)
    send_unlock_instructions
  else
    save(validate: false)
  end
end

#unlock_access!Object

Unlock a user by cleaning locked_at and failed_attempts.



45
46
47
48
49
50
# File 'app/models/member.rb', line 45

def unlock_access!
  self.locked_at = nil
  self.failed_attempts = 0 if respond_to?(:failed_attempts=)
  self.unlock_token = nil  if respond_to?(:unlock_token=)
  save(validate: false)
end