quick_admin 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc9beb45bd6b82af84edf71a0d43eb3d0527c94ad3dfc81e588e9366c1e220c5
4
- data.tar.gz: 1343ec8088cb48f43f640c039295132b278690410361c0623ed721024a758a2f
3
+ metadata.gz: 63bdba520fa5bce41ca4dce1e5b4a8d20c3287d06b41b9d05e013ab36e7738e5
4
+ data.tar.gz: d076140889f8f98d75bb19e5b7ba922e8c4ed07f542287982096b5b738d95fb2
5
5
  SHA512:
6
- metadata.gz: 30f12d2e5a83062e9e308a47ce74884060cf857a457ed51fb2153b13753ef53da085c0a2d2d63fea130ca5ab82a12141e8954185113895a7f7223d43cd58a738
7
- data.tar.gz: e6e92a9acba49e5cba6600579b4d3371bef5af2ab05635af6388a36b91f0cdb25fe3dea82c6cd4332e611b67cac342df685daa86a0d7b231177dead4572b0e05
6
+ metadata.gz: 5c33376a983c0e6be53b301902d90237383976a29ccd209d731ad7e1598ed11ef441e0017c04d957eb0aba51c62873bba9f1c28d2564e790b85386c7f85c3041
7
+ data.tar.gz: 672e6998f1aa925e6fc49ce67c83d747458fe002e62172685f76e669dc8cc1f3b479d93ce19f8ae746c7931d84db4942849b4d537cc926c87a3c77a0ce650fba
@@ -86,6 +86,42 @@ body {
86
86
  padding-left: 0.5rem;
87
87
  }
88
88
 
89
+ /* Navigation Footer */
90
+ .nav-footer {
91
+ position: absolute;
92
+ bottom: 0;
93
+ left: 0;
94
+ right: 0;
95
+ padding: 1rem;
96
+ border-top: 1px solid rgba(255,255,255,0.1);
97
+ background-color: var(--dark-color);
98
+ }
99
+
100
+ .user-info {
101
+ margin-bottom: 0.5rem;
102
+ }
103
+
104
+ .user-email {
105
+ color: rgba(255,255,255,0.7);
106
+ font-size: 0.85rem;
107
+ display: block;
108
+ overflow: hidden;
109
+ text-overflow: ellipsis;
110
+ white-space: nowrap;
111
+ }
112
+
113
+ .sign-out-link {
114
+ color: rgba(255,255,255,0.8);
115
+ text-decoration: none;
116
+ padding: 0.5rem 0;
117
+ display: block;
118
+ font-size: 0.9rem;
119
+ }
120
+
121
+ .sign-out-link:hover {
122
+ color: var(--danger-color);
123
+ }
124
+
89
125
  /* Buttons */
90
126
  .btn {
91
127
  display: inline-block;
@@ -10,16 +10,28 @@ module QuickAdmin
10
10
  private
11
11
 
12
12
  def authenticate_admin_user!
13
- if QuickAdmin.config.devise_enabled?
14
- authenticate_user!
13
+ auth_method = QuickAdmin.config.authenticate_method
14
+
15
+ if auth_method.present?
16
+ # Use explicitly configured method
17
+ send(auth_method)
18
+ elsif defined?(Devise)
19
+ # Auto-detect Devise authentication method
20
+ if respond_to?(:authenticate_admin!, true)
21
+ authenticate_admin!
22
+ elsif respond_to?(:authenticate_user!, true)
23
+ authenticate_user!
24
+ end
15
25
  elsif QuickAdmin.config.authentication == :custom
16
- # Override this method in your application
26
+ # Custom authentication - override admin_authenticated? in your app
17
27
  head :unauthorized unless admin_authenticated?
18
28
  end
19
29
  end
20
30
 
21
31
  def authentication_required?
22
- QuickAdmin.config.authentication.present?
32
+ QuickAdmin.config.authentication.present? ||
33
+ QuickAdmin.config.authenticate_method.present? ||
34
+ defined?(Devise)
23
35
  end
24
36
 
25
37
  def admin_authenticated?
@@ -205,5 +205,33 @@ module QuickAdmin
205
205
  find_field = @resource_config.find_by_field
206
206
  find_field == 'id' ? resource.id : resource.send(find_field)
207
207
  end
208
+
209
+ # Returns the current user using the configured method.
210
+ # @return [Object, nil] the current user or nil
211
+ def quick_admin_current_user
212
+ method_name = QuickAdmin.config.resolved_current_user_method
213
+ return nil unless respond_to?(method_name, true)
214
+ send(method_name)
215
+ end
216
+
217
+ # Returns a display string for the current user.
218
+ # Tries email, name, username, or falls back to "Admin".
219
+ # @return [String] display name for the user
220
+ def quick_admin_user_display
221
+ user = quick_admin_current_user
222
+ return "Admin" unless user
223
+
224
+ user.try(:email) || user.try(:name) || user.try(:username) || "Admin"
225
+ end
226
+
227
+ # Returns the sign out path if available.
228
+ # @return [String, nil] the sign out path or nil
229
+ def quick_admin_sign_out_path
230
+ path = QuickAdmin.config.resolved_sign_out_path
231
+ return path if path.is_a?(String)
232
+
233
+ # If it's a proc, call it
234
+ path.respond_to?(:call) ? path.call : nil
235
+ end
208
236
  end
209
237
  end
@@ -24,6 +24,20 @@
24
24
  <li><%= link_to resource.display_name, quick_admin.resources_path(name), class: "nav-link" %></li>
25
25
  <% end %>
26
26
  </ul>
27
+
28
+ <div class="nav-footer">
29
+ <% if quick_admin_current_user %>
30
+ <div class="user-info">
31
+ <span class="user-email"><%= quick_admin_user_display %></span>
32
+ </div>
33
+ <% end %>
34
+ <% if quick_admin_sign_out_path %>
35
+ <%= link_to "Sign Out", quick_admin_sign_out_path,
36
+ method: QuickAdmin.config.sign_out_method,
37
+ data: { turbo_method: QuickAdmin.config.sign_out_method },
38
+ class: "nav-link sign-out-link" %>
39
+ <% end %>
40
+ </div>
27
41
  </nav>
28
42
 
29
43
  <main class="quick-admin-main">
@@ -10,9 +10,14 @@ module QuickAdmin
10
10
  # @attr per_page [Integer] number of records per page (default: 25)
11
11
  # @attr mount_path [String] URL path where admin is mounted (default: '/admin')
12
12
  # @attr app_name [String] application name shown in UI (default: 'QuickAdmin')
13
+ # @attr sign_out_path [String, Proc] path for sign out link (default: auto-detect)
14
+ # @attr sign_out_method [Symbol] HTTP method for sign out (default: :delete)
15
+ # @attr current_user_method [Symbol] method to get current user (default: :current_user)
13
16
  class Configuration
14
17
  attr_accessor :authentication, :css_framework, :text_editor, :turbo_enabled,
15
- :stimulus_enabled, :per_page, :mount_path, :app_name
18
+ :stimulus_enabled, :per_page, :mount_path, :app_name,
19
+ :sign_out_path, :sign_out_method, :current_user_method,
20
+ :authenticate_method
16
21
 
17
22
  # Initializes a new Configuration with default values.
18
23
  def initialize
@@ -24,6 +29,10 @@ module QuickAdmin
24
29
  @per_page = 25 # Reasonable default pagination
25
30
  @mount_path = '/admin' # Standard admin path
26
31
  @app_name = 'QuickAdmin' # Default app name
32
+ @sign_out_path = nil # Auto-detect from Devise or set manually
33
+ @sign_out_method = :delete # Default HTTP method for sign out
34
+ @current_user_method = :current_user # Method to get current user
35
+ @authenticate_method = nil # Auto-detect or set manually (e.g., :authenticate_admin!)
27
36
  end
28
37
 
29
38
  # Checks if Devise authentication is enabled and available.
@@ -55,5 +64,42 @@ module QuickAdmin
55
64
  def lexical_enabled?
56
65
  text_editor == :lexical
57
66
  end
67
+
68
+ # Returns the resolved sign out path.
69
+ # Auto-detects Devise path if not explicitly set.
70
+ # @return [String, nil] the sign out path or nil if not available
71
+ def resolved_sign_out_path
72
+ return sign_out_path if sign_out_path.present?
73
+
74
+ # Auto-detect Devise sign out path (even if not explicitly configured)
75
+ if defined?(Devise)
76
+ # Check for Admin model first, then User
77
+ if defined?(Admin)
78
+ '/admins/sign_out'
79
+ else
80
+ '/users/sign_out'
81
+ end
82
+ else
83
+ nil
84
+ end
85
+ end
86
+
87
+ # Returns the resolved current user method.
88
+ # Auto-detects based on available Devise models.
89
+ # @return [Symbol] the method name to get current user
90
+ def resolved_current_user_method
91
+ return current_user_method if current_user_method != :current_user
92
+
93
+ # Auto-detect based on Devise models
94
+ if defined?(Devise)
95
+ if defined?(Admin)
96
+ :current_admin
97
+ else
98
+ :current_user
99
+ end
100
+ else
101
+ current_user_method
102
+ end
103
+ end
58
104
  end
59
105
  end
@@ -1,3 +1,3 @@
1
1
  module QuickAdmin
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quick_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nezir Zahirovic