Class: Calnet::User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/calnet_authenticated/calnet_user.rb

Overview

requires

* uid (unique)

accessible attributes

* sn * displayname * mail * telephonenumber

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_create_and_update_by_uid(uid) ⇒ Object

Find or Create a user from a given uid, and then proceed to update the user’s information from the UCB::LDAP::Person.find_by_uid(uid) response.

Returns: user



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/calnet_authenticated/calnet_user.rb', line 33

def self.find_create_and_update_by_uid(uid)
	user = self.find_or_create_by_uid(uid)
	person = UCB::LDAP::Person.find_by_uid(uid) 
	user.update_attributes!({
		:displayname     => person.displayname,
		:sn              => person.sn.first,
		:mail            => person.mail.first || '',
		:telephonenumber => person.telephonenumber.first
	}) unless person.nil?
	user
end

.inherited(subclass) ⇒ Object

defined in plugin/engine …

def may_administrate?(*args) (self.role_names & [‘superuser’,‘administrator’]).length > 0 end

def may_read?(*args) (self.role_names & [‘superuser’,‘administrator’,‘editor’,‘interviewer’,‘reader’] ).length > 0 end

def may_edit?(*args) (self.role_names & [‘superuser’,‘administrator’,‘editor’] ).length > 0 end



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/calnet_authenticated/calnet_user.rb', line 70

def self.inherited(subclass)

	subclass.class_eval do
		#	for some reason is nil which causes problems
		self.default_scoping = []

		validates_presence_of   :uid
		validates_uniqueness_of :uid

		#	include the many may_*? for use in the controllers
		authorized

		alias_method :may_create?,  :may_edit?
		alias_method :may_update?,  :may_edit?
		alias_method :may_destroy?, :may_edit?

	end	#	class_eval
end

.search(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/calnet_authenticated/calnet_user.rb', line 12

def self.search(options={})
	conditions = {}
	includes = joins = []
	if !options[:role_name].blank?
		includes = [:roles]
		if Role.all.collect(&:name).include?(options[:role_name])
			joins = [:roles]
			conditions = ["roles.name = ?",options[:role_name]]
		end 
	end 
	self.all( 
		:joins => joins, 
		:include => includes,
		:conditions => conditions )
end

Instance Method Details

#to_sObject



45
46
47
# File 'lib/calnet_authenticated/calnet_user.rb', line 45

def to_s
	displayname
end