Module: Authorized::UserModel::InstanceMethods

Defined in:
lib/authorized/user_model.rb

Instance Method Summary collapse

Instance Method Details

#deputizeObject



51
52
53
# File 'lib/authorized/user_model.rb', line 51

def deputize
	roles << Role.find_or_create_by_name('administrator')
end

#is_administrator?(*args) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/authorized/user_model.rb', line 61

def is_administrator?(*args)
	self.role_names.include?('administrator')
end

#is_editor?(*args) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/authorized/user_model.rb', line 65

def is_editor?(*args)
	self.role_names.include?('editor')
end

#is_interviewer?(*args) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/authorized/user_model.rb', line 69

def is_interviewer?(*args)
	self.role_names.include?('interviewer')
end

#is_reader?(*args) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/authorized/user_model.rb', line 73

def is_reader?(*args)
	self.role_names.include?('reader')
end

#is_superuser?(*args) ⇒ Boolean Also known as: is_super_user?

The 4 common CCLS roles are .…

Returns:

  • (Boolean)


56
57
58
# File 'lib/authorized/user_model.rb', line 56

def is_superuser?(*args)
	self.role_names.include?('superuser')
end

#is_user?(user = nil) ⇒ Boolean Also known as: may_be_user?

Returns:

  • (Boolean)


77
78
79
# File 'lib/authorized/user_model.rb', line 77

def is_user?(user=nil)
	!user.nil? && self == user
end

#may_administrate?(*args) ⇒ Boolean Also known as: may_view_permissions?, may_create_user_invitations?, may_view_users?, may_assign_roles?

Returns:

  • (Boolean)


82
83
84
# File 'lib/authorized/user_model.rb', line 82

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

#may_edit?(*args) ⇒ Boolean Also known as: may_maintain_pages?

Returns:

  • (Boolean)


90
91
92
93
94
# File 'lib/authorized/user_model.rb', line 90

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

#may_interview?(*args) ⇒ Boolean

Add tests for may_interview and may_read

Returns:

  • (Boolean)


99
100
101
102
103
# File 'lib/authorized/user_model.rb', line 99

def may_interview?(*args)
	(self.role_names & 
		['superuser','administrator','editor','interviewer']
	).length > 0
end

#may_read?(*args) ⇒ Boolean Also known as: may_view?

This is pretty lame as all current roles can read

Returns:

  • (Boolean)


106
107
108
109
110
# File 'lib/authorized/user_model.rb', line 106

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

#may_share_document?(document = nil) ⇒ Boolean

Returns:

  • (Boolean)


122
123
124
125
126
127
# File 'lib/authorized/user_model.rb', line 122

def may_share_document?(document=nil)
	document && ( 
		self.is_administrator? ||
		( document.owner && self == document.owner ) 
	)
end

#may_view_document?(document = nil) ⇒ Boolean

Returns:

  • (Boolean)


129
130
131
132
133
134
135
136
# File 'lib/authorized/user_model.rb', line 129

def may_view_document?(document=nil)
	document





end

#may_view_user?(user = nil) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/authorized/user_model.rb', line 115

def may_view_user?(user=nil)
	self.is_user?(user) || self.may_administrate?
end

#role_namesObject



47
48
49
# File 'lib/authorized/user_model.rb', line 47

def role_names
	roles.collect(&:name).uniq
end