Revision 9c0e127b
Added by Paul Kelly about 14 years ago
- ID 9c0e127b1d42b7243403dd49d739cf8e97baa60b
app/models/user.rb | ||
---|---|---|
class User < ActiveRecord::Base
|
||
belongs_to :auth_source
|
||
has_many :changes, :class_name => 'Audit', :as => :user
|
||
|
||
has_many :hosts
|
||
has_many :usergroups, :through => :usergroup_member
|
||
has_many :direct_hosts, :as => :owner, :class_name => "Host"
|
||
|
||
validates_uniqueness_of :login, :message => "already exists"
|
||
validates_presence_of :login, :mail
|
||
... | ... | |
validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_nil => true
|
||
validates_length_of :mail, :maximum => 60, :allow_nil => true
|
||
|
||
before_destroy Ensure_not_used_by.new(:hosts)
|
||
|
||
def to_label
|
||
"#{firstname} #{lastname}"
|
||
end
|
||
alias_method :to_s, :to_label
|
||
alias_method :name, :to_label
|
||
|
||
def <=>(other)
|
||
self.name <=> other.name
|
||
end
|
||
|
||
# The text item to see in a select dropdown menu
|
||
def select_title
|
||
name + " (#{login})"
|
||
end
|
||
|
||
def self.try_to_login(login, password)
|
||
# Make sure no one can sign in with an empty password
|
||
... | ... | |
raise text
|
||
end
|
||
|
||
def indirect_hosts
|
||
all_groups = []
|
||
for usergroup in usergroups
|
||
all_groups += usergroup.all_usergroups
|
||
end
|
||
all_groups.uniq.map{|g| g.hosts}.flatten.uniq
|
||
end
|
||
|
||
def hosts
|
||
direct_hosts + indirect_hosts
|
||
end
|
||
|
||
def recipients
|
||
[mail]
|
||
end
|
||
|
||
protected
|
||
|
||
def validate
|
||
if Usergroup.all.map(&:name).include?(self.login)
|
||
errors.add_to_base "A usergroup already exists with this name"
|
||
end
|
||
end
|
||
|
||
end
|
Also available in: Unified diff
Fixes #170 - implement usergroups
Added migration
Added tests
Added MVC files
Added the routes as well
Added the program logic and additional views
Added RESTful actions for update and create
Added validations to ensure that usergroup.name and user.login do not collide
Added "recipients" method to users and usergroups. This returns a list of addresses.
Usergroup#recipients will follow all nested usergroups avoiding any loops and
return only unique addresses
Fixes #73 - Add usergroup support to hosts
Fixes #244 - Remove ActiveScaffold from the usergroup pages
and finally - added owners to host edit page and other whitespaces and
mods by ohad