-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10778 from colinux/sharerd-controller-nav-bar-pro…
…file UX: améliore la détection du type de profile utilisé pour la nav bar
- Loading branch information
Showing
11 changed files
with
105 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module NavBarProfileConcern | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
# Override this method on controller basis for more precise context or custom logic | ||
def nav_bar_profile | ||
end | ||
|
||
def fallback_nav_bar_profile | ||
return :guest if current_user.blank? | ||
|
||
nav_bar_profile_from_referrer || default_nav_bar_profile_for_user | ||
end | ||
|
||
private | ||
|
||
# Shared controllers (search, errors, release notes…) don't have specific context | ||
# Simple attempt to try to re-use the profile from the previous page | ||
# so user does'not feel lost. | ||
def nav_bar_profile_from_referrer | ||
# detect context from referer, simple (no detection when refreshing the page) | ||
params = Rails.application.routes.recognize_path(request&.referer) | ||
|
||
controller_class = "#{params[:controller].camelize}Controller".safe_constantize | ||
return if controller_class.nil? | ||
|
||
controller_instance = controller_class.new | ||
controller_instance.try(:nav_bar_profile) | ||
end | ||
|
||
# Fallback for shared controllers from user account | ||
# to the more relevant profile. | ||
def default_nav_bar_profile_for_user | ||
return :gestionnaire if current_user.gestionnaire? | ||
return :administrateur if current_user.administrateur? | ||
return :instructeur if current_user.instructeur? | ||
return :expert if current_user.expert? | ||
|
||
:user | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class SuperAdmins::SessionsController < Devise::SessionsController | ||
def nav_bar_profile = :superadmin | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters