Module: SimplyAuthorized::UserModel::InstanceMethods

Defined in:
lib/simply_authorized/user_model.rb

Instance Method Summary collapse

Instance Method Details

#after_add_role(role) ⇒ Object



55
56
# File 'lib/simply_authorized/user_model.rb', line 55

def after_add_role(role)
end

#after_remove_role(role) ⇒ Object



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

def after_remove_role(role)
end

#before_add_role(role) ⇒ Object



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

def before_add_role(role)
end

#before_remove_role(role) ⇒ Object



58
59
# File 'lib/simply_authorized/user_model.rb', line 58

def before_remove_role(role)
end

#deputizeObject



68
69
70
# File 'lib/simply_authorized/user_model.rb', line 68

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

#is_administrator?(*args) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/simply_authorized/user_model.rb', line 78

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

#is_editor?(*args) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#is_interviewer?(*args) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/simply_authorized/user_model.rb', line 86

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

#is_not_user?(user = nil) ⇒ Boolean Also known as: may_not_be_user?

Returns:

  • (Boolean)


99
100
101
# File 'lib/simply_authorized/user_model.rb', line 99

def is_not_user?(user=nil)
	!is_user?(user)
end

#is_reader?(*args) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/simply_authorized/user_model.rb', line 90

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)


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

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

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

Returns:

  • (Boolean)


94
95
96
# File 'lib/simply_authorized/user_model.rb', line 94

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)


104
105
106
# File 'lib/simply_authorized/user_model.rb', line 104

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

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

Returns:

  • (Boolean)


112
113
114
115
116
# File 'lib/simply_authorized/user_model.rb', line 112

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)


121
122
123
124
125
# File 'lib/simply_authorized/user_model.rb', line 121

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)


128
129
130
131
132
# File 'lib/simply_authorized/user_model.rb', line 128

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

#may_share_document?(document = nil) ⇒ Boolean

Returns:

  • (Boolean)


144
145
146
147
148
149
# File 'lib/simply_authorized/user_model.rb', line 144

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

#may_view_document?(document = nil) ⇒ Boolean

Returns:

  • (Boolean)


151
152
153
154
155
156
157
158
# File 'lib/simply_authorized/user_model.rb', line 151

def may_view_document?(document=nil)
	document





end

#may_view_user?(user = nil) ⇒ Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/simply_authorized/user_model.rb', line 137

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

#role_namesObject



64
65
66
# File 'lib/simply_authorized/user_model.rb', line 64

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