Class: EasyAdmin::Permissions::PermissionDeniedComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
lib/easy_admin/permissions/permission_denied_component.rb

Instance Method Summary collapse

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(permission:, user: nil, context: nil) ⇒ PermissionDeniedComponent

Returns a new instance of PermissionDeniedComponent.



4
5
6
7
8
# File 'lib/easy_admin/permissions/permission_denied_component.rb', line 4

def initialize(permission:, user: nil, context: nil)
  @permission = permission
  @user = user
  @context = context
end

Instance Method Details

#view_templateObject



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
# File 'lib/easy_admin/permissions/permission_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-gray-400", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24") do
          path(stroke_linecap: "round", stroke_linejoin: "round", stroke_width: "2", 
               d: "M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z")
        end
      end

      # Title
      h2(class: "text-3xl font-bold text-gray-900 mb-4") { "Access Denied" }

      # Description
      div(class: "text-gray-600 mb-6 space-y-2") do
        p { "You don't have permission to access this resource." }
        if @permission
          div(class: "text-sm bg-gray-100 px-3 py-2 rounded-lg font-mono") do
            span(class: "text-gray-500") { "Required permission: " }
            span(class: "text-red-600 font-semibold") { @permission }
          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-500 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
          if @user.respond_to?(:roles) && @user.roles.any?
            p(class: "mt-2") do
              span { "Your roles: " }
              @user.roles.active.each_with_index do |role, index|
                span(class: "inline-flex items-center px-2 py-1 rounded-full text-xs bg-blue-100 text-blue-800 mr-1") do
                  role.name
                end
              end
            end
          end
        end
      end

      # Actions
      div(class: "space-y-3") do
        # Go back button
        button(
          onclick: "history.back()",
          class: "w-full px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors font-medium"
        ) do
          "← Go Back"
        end

        # Contact admin link (if configured)
        if support_contact_available?
          a(
            href: support_contact_url,
            class: "inline-block text-sm text-blue-600 hover:text-blue-800 transition-colors"
          ) do
            "Contact administrator for access"
          end
        end
      end

      # Additional info
      div(class: "mt-8 pt-6 border-t border-gray-200 text-xs text-gray-400") do
        p { "If you believe this is an error, please contact your administrator." }
        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 { "Permission: #{@permission}" }
            p { "Context: #{@context}" } if @context
            p { "User ID: #{@user&.id}" }
            p { "Time: #{Time.current}" }
          end
        end
      end
    end
  end
end