Module: MegaBar::AuthorizationHelper
- Included in:
- ApplicationController
- Defined in:
- app/helpers/mega_bar/authorization_helper.rb
Instance Method Summary collapse
- #can_create?(subject) ⇒ Boolean
- #can_destroy?(subject) ⇒ Boolean
- #can_edit?(subject) ⇒ Boolean
-
#can_index?(subject) ⇒ Boolean
Permission check helpers.
-
#can_perform_action?(action, subject) ⇒ Boolean
Check if user can perform action - delegates to CCCUX if available, otherwise allows.
- #can_show?(subject) ⇒ Boolean
- #can_update?(subject) ⇒ Boolean
-
#has_mega_role? ⇒ Boolean
Check if user has Mega Role for admin access.
-
#link_if_can(action, subject, text, path, **opts) ⇒ Object
Generic action helper.
- #link_if_can_create(subject, text, path, **opts) ⇒ Object
- #link_if_can_destroy(subject, text, path, **opts) ⇒ Object
- #link_if_can_edit(subject, text, path, **opts) ⇒ Object
-
#link_if_can_index(subject, text, path, **opts) ⇒ Object
Link helpers that match CCCUX interface.
- #link_if_can_show(subject, text, path, **opts) ⇒ Object
- #link_if_can_update(subject, text, path, **opts) ⇒ Object
-
#link_if_can_with_wrapper(action, subject, text, path, **opts) ⇒ Object
Base method that handles both prepend and append options.
Instance Method Details
#can_create?(subject) ⇒ Boolean
67 68 69 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 67 def can_create?(subject) can_perform_action?(:create, subject) end |
#can_destroy?(subject) ⇒ Boolean
79 80 81 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 79 def can_destroy?(subject) can_perform_action?(:destroy, subject) end |
#can_edit?(subject) ⇒ Boolean
71 72 73 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 71 def can_edit?(subject) can_perform_action?(:edit, subject) end |
#can_index?(subject) ⇒ Boolean
Permission check helpers
59 60 61 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 59 def can_index?(subject) can_perform_action?(:index, subject) end |
#can_perform_action?(action, subject) ⇒ Boolean
Check if user can perform action - delegates to CCCUX if available, otherwise allows
18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 18 def can_perform_action?(action, subject) if defined?(Cccux::AuthorizationHelper) # CCCUX is available, use its authorization can?(action, subject) else # CCCUX not available, allow all actions true end end |
#can_show?(subject) ⇒ Boolean
63 64 65 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 63 def can_show?(subject) can_perform_action?(:show, subject) end |
#can_update?(subject) ⇒ Boolean
75 76 77 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 75 def can_update?(subject) can_perform_action?(:update, subject) end |
#has_mega_role? ⇒ Boolean
Check if user has Mega Role for admin access
84 85 86 87 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 84 def has_mega_role? return false unless defined?(Devise) && user_signed_in? current_user.has_role?('Mega Role') end |
#link_if_can(action, subject, text, path, **opts) ⇒ Object
Generic action helper
54 55 56 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 54 def link_if_can(action, subject, text, path, **opts) link_if_can_with_wrapper(action, subject, text, path, **opts) end |
#link_if_can_create(subject, text, path, **opts) ⇒ Object
37 38 39 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 37 def link_if_can_create(subject, text, path, **opts) link_if_can_with_wrapper(:create, subject, text, path, **opts) end |
#link_if_can_destroy(subject, text, path, **opts) ⇒ Object
49 50 51 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 49 def link_if_can_destroy(subject, text, path, **opts) link_if_can_with_wrapper(:destroy, subject, text, path, **opts) end |
#link_if_can_edit(subject, text, path, **opts) ⇒ Object
41 42 43 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 41 def link_if_can_edit(subject, text, path, **opts) link_if_can_with_wrapper(:edit, subject, text, path, **opts) end |
#link_if_can_index(subject, text, path, **opts) ⇒ Object
Link helpers that match CCCUX interface
29 30 31 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 29 def link_if_can_index(subject, text, path, **opts) link_if_can_with_wrapper(:index, subject, text, path, **opts) end |
#link_if_can_show(subject, text, path, **opts) ⇒ Object
33 34 35 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 33 def link_if_can_show(subject, text, path, **opts) link_if_can_with_wrapper(:show, subject, text, path, **opts) end |
#link_if_can_update(subject, text, path, **opts) ⇒ Object
45 46 47 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 45 def link_if_can_update(subject, text, path, **opts) link_if_can_with_wrapper(:update, subject, text, path, **opts) end |
#link_if_can_with_wrapper(action, subject, text, path, **opts) ⇒ Object
Base method that handles both prepend and append options
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/helpers/mega_bar/authorization_helper.rb', line 4 def link_if_can_with_wrapper(action, subject, text, path, **opts) prepend = opts.delete(:prepend) append = opts.delete(:append) if can_perform_action?(action, subject) "#{prepend}#{link_to(text, path, **opts)}#{append}".html_safe elsif opts.delete(:show_text) text else "" end end |