Module: Aven::ControllerHelpers
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/controllers/concerns/aven/controller_helpers.rb
Instance Method Summary collapse
-
#current_workspace ⇒ Object
Get the current workspace from session.
-
#current_workspace=(workspace) ⇒ Object
Set the current workspace.
-
#verify_workspace! ⇒ Object
Verify user has access to current workspace (similar to Devise’s authenticate_user!).
Instance Method Details
#current_workspace ⇒ Object
Get the current workspace from session
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/concerns/aven/controller_helpers.rb', line 10 def current_workspace return @current_workspace if defined?(@current_workspace) @current_workspace = if session[:workspace_id].present? && current_user current_user.workspaces.find_by(id: session[:workspace_id]) elsif current_user # Auto-select first workspace if none selected workspace = current_user.workspaces.first session[:workspace_id] = workspace&.id workspace end end |
#current_workspace=(workspace) ⇒ Object
Set the current workspace
24 25 26 27 |
# File 'app/controllers/concerns/aven/controller_helpers.rb', line 24 def current_workspace=(workspace) @current_workspace = workspace session[:workspace_id] = workspace&.id end |
#verify_workspace! ⇒ Object
Verify user has access to current workspace (similar to Devise’s authenticate_user!)
30 31 32 33 34 35 36 |
# File 'app/controllers/concerns/aven/controller_helpers.rb', line 30 def verify_workspace! return unless current_user.present? && current_workspace.present? unless current_user.workspaces.exists?(id: current_workspace.id) render file: Rails.public_path.join("404.html"), status: :not_found, layout: false end end |