Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveModel::ForbiddenAttributesProtection, PublicActivity::Common
Defined in:
app/models/user.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) auto_confirm



33
34
35
36
37
# File 'app/models/user.rb', line 33

def auto_confirm
  # set as confirmed if we are not confirming user accounts so that if that is ever turned on,
  # this new user will not be locked out
  self.confirmed_at = Time.zone.local(1824, 11, 5) if !ConcertoConfig[:confirmable]
end

- (Object) dont_delete_last_admin

last line of defense: return false so the before_destroy validation fails



50
51
52
53
54
# File 'app/models/user.rb', line 50

def dont_delete_last_admin
  if is_last_admin?
    return false
  end
end

- (Boolean) in_group?(group)

Quickly test if a user belongs to a group (this breaks if either is nil)

Returns:

  • (Boolean)


64
65
66
# File 'app/models/user.rb', line 64

def in_group?(group)
  groups.include?(group)
end

- (Boolean) is_deletable?

a user who isn't the last admin and owns no screens is deletable

Returns:

  • (Boolean)


40
41
42
# File 'app/models/user.rb', line 40

def is_deletable?
  self.screens.size == 0 && !is_last_admin?
end

- (Boolean) is_last_admin?

when we only have one user in the system who is the admin

Returns:

  • (Boolean)


45
46
47
# File 'app/models/user.rb', line 45

def is_last_admin?
  User.admin.count == 1 && self.is_admin?
end

- (Object) name

A simple name, combining the first and last name We should probably expand this so it doesn't look stupid if people only have a first name or only have a last name



59
60
61
# File 'app/models/user.rb', line 59

def name
  (first_name || "") + " " + (last_name || "")
end

- (Object) owned_feeds

Return an array of all the feeds a user owns.



69
70
71
# File 'app/models/user.rb', line 69

def owned_feeds
  leading_groups.collect{|g| g.feeds}.flatten
end

- (Object) supporting_groups(type, permissions)

Return an array of all the groups a user has a certain regular permission for.



74
75
76
77
# File 'app/models/user.rb', line 74

def supporting_groups(type, permissions)
  supporting_groups =  groups.select{|g| g.user_has_permissions?(self, :regular, type, permissions)}
  return supporting_groups
end