Module: Authorizable::ModelMethods::ItemInstanceMethods

Defined in:
lib/authorizable.rb

Instance Method Summary collapse

Instance Method Details

#accepting_action(user, action, container, active = true) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/authorizable.rb', line 214

def accepting_action(user, action, container, active=true)
	model_name = self.class.to_s
	# Special stuff
	if !get_sa_config['sa_items'].include?(model_name.underscore) || !active
		return false
	end
     # System access
	if user.has_system_permission(model_name.underscore, action)
		return true
	end
     # Workspace access
	if self.id.nil?
		wsl = user.send(container.pluralize)
	else
		wsl = self.send(container.pluralize) & user.send(container.pluralize)
	end
     wsl.each do |ws|
		# First of all, to check if this workspace accpets these items
		if ws.available_items.to_s.split(',').include?(model_name.underscore)
			# Then with workspace full access
			if user.has_container_permission(ws.id, model_name.underscore, action, container)
				return true
			end
		end # if item available in ws
	end
	false
end

#get_sa_configObject



205
206
207
208
209
210
211
212
# File 'lib/authorizable.rb', line 205

def get_sa_config
	if File.exist?("#{RAILS_ROOT}/config/customs/sa_config.yml")
		@config ||= YAML.load_file("#{RAILS_ROOT}/config/customs/sa_config.yml")
	else
		@config ||= YAML.load_file("#{RAILS_ROOT}/config/customs/default_config.yml")
	end
     return @config
end