Class: CitizenBudgetModelController

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/citizen_budget_model_controller.rb

Instance Method Summary collapse

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/controllers/citizen_budget_model_controller.rb', line 14

def admin?
  user_signed_in? && current_user.organization_id.nil?
end

#check_authorization!Object



18
19
20
21
22
# File 'app/controllers/citizen_budget_model_controller.rb', line 18

def check_authorization!
  unless admin?
    head :forbidden
  end
end

#set_localeObject



10
11
12
# File 'app/controllers/citizen_budget_model_controller.rb', line 10

def set_locale
  session[:locale] = I18n.locale = params[:locale] || session[:locale] || I18n.default_locale
end

#simulatorsObject



24
25
26
# File 'app/controllers/citizen_budget_model_controller.rb', line 24

def simulators
  @simulators_collection ||= admin? ? CitizenBudgetModel::Simulator : current_user.organization.simulators
end

#sort(collection) ⇒ Object



32
33
34
35
36
37
# File 'app/controllers/citizen_budget_model_controller.rb', line 32

def sort(collection)
  collection.each do |object|
    object.update_attributes position: params[object.class.model_name.param_key].index(object.id.to_s)
  end
  render nothing: true, status: 204
end

#usersObject



28
29
30
# File 'app/controllers/citizen_budget_model_controller.rb', line 28

def users
  @users_collection ||= admin? ? CitizenBudgetModel::User : current_user.organization.users
end