Class: EasyAdmin::Permissions::RoleDeniedComponent
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- EasyAdmin::Permissions::RoleDeniedComponent
- Defined in:
- lib/easy_admin/permissions/role_denied_component.rb
Instance Method Summary collapse
-
#initialize(role:, user: nil, context: nil) ⇒ RoleDeniedComponent
constructor
A new instance of RoleDeniedComponent.
- #view_template ⇒ Object
Methods inherited from BaseComponent
#easy_admin_url_helpers, #helpers, #rails_url_helpers
Methods included from Component
#current_user_can?, #current_user_has_role?, #if_can, #if_has_role, #permission_attrs, #permission_button, #permission_case, #permission_classes, #permission_field, #permission_link, #unless_can, #unless_has_role
Methods included from FieldsHelper
#field_component, #render_field
Methods included from DashboardsHelper
#delta_badge_classes, #metric_value_classes, #render_card, #sparkline_color, #sparkline_points, #trend_direction, #trend_icon, #trend_indicator_classes
Constructor Details
#initialize(role:, user: nil, context: nil) ⇒ RoleDeniedComponent
Returns a new instance of RoleDeniedComponent.
4 5 6 7 8 |
# File 'lib/easy_admin/permissions/role_denied_component.rb', line 4 def initialize(role:, user: nil, context: nil) @role = role @user = user @context = context end |
Instance Method Details
#view_template ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/easy_admin/permissions/role_denied_component.rb', line 10 def view_template div(class: "min-h-96 flex items-center justify-center p-8") do div(class: "text-center max-w-md mx-auto") do # Icon div(class: "mb-6") do svg(class: "w-20 h-20 mx-auto text-amber-400", fill: "currentColor", viewBox: "0 0 24 24") do path(d: "M5 16L3 14L5 12L3 10L5 8L11 14L5 16ZM19 8L21 10L19 12L21 14L19 16L13 10L19 8ZM12 2L15.09 8.26L22 9L17 14L18.18 21L12 17.77L5.82 21L7 14L2 9L8.91 8.26L12 2Z") end end # Title h2(class: "text-3xl font-bold text-gray-900 mb-4") { "Role Required" } # Description div(class: "text-gray-600 mb-6 space-y-2") do p { "You need a specific role to access this resource." } if @role div(class: "text-sm bg-amber-50 px-3 py-2 rounded-lg border border-amber-200") do span(class: "text-gray-500") { "Required role: " } span(class: "text-amber-700 font-semibold") { @role.to_s.humanize } end end if @context div(class: "text-sm text-gray-500") do span { "Context: " } span(class: "font-medium") { @context.to_s } end end end # User info (if available) if @user div(class: "text-sm text-gray-600 mb-6 p-3 bg-gray-50 rounded-lg") do p do span { "Signed in as: " } span(class: "font-medium text-gray-700") { @user.email || @user.name || "User ##{@user.id}" } end # Show current roles if @user.respond_to?(:roles) current_roles = @user.roles.active if current_roles.any? p(class: "mt-2") do span { "Your current roles: " } current_roles.each do |role| span(class: "inline-flex items-center px-2 py-1 rounded-full text-xs bg-green-100 text-green-800 mr-1") do role.name end end end else p(class: "mt-2 text-gray-500 italic") { "No roles assigned" } end end # Show what the required role would give access to if show_role_benefits? div(class: "mt-3 pt-3 border-t border-gray-200") do p(class: "text-xs text-gray-500 mb-2") { "The #{@role.to_s.humanize} role includes:" } div(class: "text-xs text-gray-600 space-y-1") do .each do || div(class: "flex items-center") do span(class: "text-green-500 mr-1") { "✓" } span { .humanize } end end end end end end end # Actions div(class: "space-y-3") do # Go back button ( onclick: "history.back()", class: "w-full px-6 py-3 bg-amber-600 text-white rounded-lg hover:bg-amber-700 transition-colors font-medium" ) do "← Go Back" end # Request role access (if configured) if role_request_available? a( href: role_request_url, class: "inline-block text-sm text-amber-600 hover:text-amber-800 transition-colors" ) do "Request #{@role.to_s.humanize} role access" end end end # Additional info div(class: "mt-8 pt-6 border-t border-gray-200 text-xs text-gray-400") do p { "Contact your administrator to request the required role." } if Rails.env.development? div(class: "mt-2 p-2 bg-yellow-50 rounded text-yellow-700 text-left font-mono text-xs") do p { "Dev info:" } p { "Required role: #{@role}" } p { "Context: #{@context}" } if @context p { "User ID: #{@user&.id}" } p { "Current roles: #{@user&.roles&.pluck(:name)&.join(', ')}" } if @user&.respond_to?(:roles) p { "Time: #{Time.current}" } end end end end end end |