admin_suite 0.2.8 → 0.3.0
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 +4 -4
- data/CHANGELOG.md +38 -1
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +3 -0
- data/README.md +10 -24
- data/app/controllers/admin_suite/application_controller.rb +53 -11
- data/app/controllers/admin_suite/resources_controller.rb +63 -9
- data/app/views/admin_suite/resources/index.html.erb +3 -1
- data/app/views/admin_suite/resources/show.html.erb +2 -2
- data/lib/admin/base/filter_builder.rb +2 -1
- data/lib/admin/base/resource.rb +14 -2
- data/lib/admin_suite/auth/host_hook.rb +25 -0
- data/lib/admin_suite/auth/http_basic.rb +46 -0
- data/lib/admin_suite/auth/strategy.rb +25 -0
- data/lib/admin_suite/auth.rb +33 -0
- data/lib/admin_suite/configuration.rb +8 -0
- data/lib/admin_suite/ui/show_value_formatter.rb +2 -2
- data/lib/admin_suite/version.rb +1 -1
- data/lib/admin_suite.rb +16 -0
- data/lib/generators/admin_suite/install/templates/admin_suite.rb +24 -7
- data/test/controllers/resources_controller_test.rb +80 -0
- data/test/dummy/config/initializers/admin_suite_auth.rb +8 -0
- data/test/integration/authentication_test.rb +99 -0
- data/test/integration/authorization_test.rb +131 -0
- data/test/integration/read_only_resource_test.rb +130 -0
- data/test/lib/auth_http_basic_test.rb +62 -0
- data/test/lib/auth_resolution_test.rb +75 -0
- data/test/lib/auth_test.rb +29 -0
- data/test/lib/resource_observability_extensions_test.rb +53 -0
- data/test/test_helper.rb +43 -0
- metadata +15 -14
- data/docs/README.md +0 -26
- data/docs/actions.md +0 -98
- data/docs/configuration.md +0 -284
- data/docs/development.md +0 -64
- data/docs/docs_viewer.md +0 -79
- data/docs/fields.md +0 -188
- data/docs/installation.md +0 -80
- data/docs/portals.md +0 -140
- data/docs/releasing.md +0 -67
- data/docs/resources.md +0 -237
- data/docs/theming.md +0 -63
- data/docs/troubleshooting.md +0 -50
data/docs/resources.md
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
# Resources
|
|
2
|
-
|
|
3
|
-
Resources are defined using `Admin::Base::Resource`.
|
|
4
|
-
|
|
5
|
-
AdminSuite loads resource definition files from `AdminSuite.config.resource_globs`
|
|
6
|
-
(defaults include `config/admin_suite/resources/*.rb` and `app/admin/resources/*.rb`).
|
|
7
|
-
|
|
8
|
-
## Create a resource
|
|
9
|
-
|
|
10
|
-
A resource is a Ruby class under `Admin::Resources` ending in `Resource`.
|
|
11
|
-
|
|
12
|
-
Example:
|
|
13
|
-
|
|
14
|
-
```ruby
|
|
15
|
-
# config/admin_suite/resources/user.rb
|
|
16
|
-
module Admin
|
|
17
|
-
module Resources
|
|
18
|
-
class UserResource < Admin::Base::Resource
|
|
19
|
-
model ::User
|
|
20
|
-
portal :ops
|
|
21
|
-
section :accounts
|
|
22
|
-
|
|
23
|
-
nav label: "Users", icon: "users", order: 10
|
|
24
|
-
|
|
25
|
-
index do
|
|
26
|
-
searchable :email, :name
|
|
27
|
-
sortable :created_at, :email, default: :created_at, direction: :desc
|
|
28
|
-
paginate 50
|
|
29
|
-
|
|
30
|
-
columns do
|
|
31
|
-
column :id
|
|
32
|
-
column :email
|
|
33
|
-
column :created_at
|
|
34
|
-
column :admin, type: :toggle, toggle_field: :admin, header: "Admin?"
|
|
35
|
-
column :status, type: :label, label_color: ->(u) { u.active? ? :emerald : :slate }, label_size: :sm
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
filters do
|
|
39
|
-
filter :search, type: :text, placeholder: "Search users..."
|
|
40
|
-
filter :status, type: :select, options: [["Active", "active"], ["Inactive", "inactive"]]
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
stats do
|
|
44
|
-
stat :total, -> { User.count }, color: :slate
|
|
45
|
-
stat :new_24h, -> { User.where("created_at > ?", 24.hours.ago).count }, color: :emerald
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
form do
|
|
50
|
-
section "Basics", description: "Core account fields" do
|
|
51
|
-
field :email, type: :email, required: true
|
|
52
|
-
field :name, required: true
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
row cols: 2 do
|
|
56
|
-
field :admin, type: :toggle, help: "Grants access to internal tools."
|
|
57
|
-
field :status, type: :select, collection: [["Active", "active"], ["Inactive", "inactive"]]
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
show do
|
|
62
|
-
main do
|
|
63
|
-
panel :details, title: "User details", fields: %i[email name status created_at]
|
|
64
|
-
panel :activity, title: "Activity", render: :custom_activity_timeline
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
sidebar do
|
|
68
|
-
panel :summary, title: "Summary", fields: %i[id admin]
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
actions do
|
|
73
|
-
action :reset_password, label: "Reset password", icon: "key", confirm: "Send reset email?"
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
## Core DSL
|
|
81
|
-
|
|
82
|
-
### Model
|
|
83
|
-
|
|
84
|
-
```ruby
|
|
85
|
-
model ::User
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### Navigation placement
|
|
89
|
-
|
|
90
|
-
```ruby
|
|
91
|
-
portal :ops
|
|
92
|
-
section :accounts
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
These determine:
|
|
96
|
-
|
|
97
|
-
- URL: `/:portal/:resource_name`
|
|
98
|
-
- Sidebar placement: portal group → section group → resource link
|
|
99
|
-
|
|
100
|
-
### Navigation metadata
|
|
101
|
-
|
|
102
|
-
```ruby
|
|
103
|
-
nav label: "Users", icon: "users", order: 10
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
Also available as convenience setters:
|
|
107
|
-
|
|
108
|
-
```ruby
|
|
109
|
-
label "Users"
|
|
110
|
-
icon "users"
|
|
111
|
-
order 10
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
## Index DSL (`index do ... end`)
|
|
115
|
-
|
|
116
|
-
### Search
|
|
117
|
-
|
|
118
|
-
```ruby
|
|
119
|
-
searchable :name, :email
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Search uses `ILIKE` across the configured fields.
|
|
123
|
-
|
|
124
|
-
### Sort
|
|
125
|
-
|
|
126
|
-
```ruby
|
|
127
|
-
sortable :created_at, :email, default: :created_at, direction: :desc
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### Pagination
|
|
131
|
-
|
|
132
|
-
```ruby
|
|
133
|
-
paginate 25
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
### Columns
|
|
137
|
-
|
|
138
|
-
```ruby
|
|
139
|
-
columns do
|
|
140
|
-
column :email
|
|
141
|
-
column :job_listings, ->(u) { u.job_listings.count }
|
|
142
|
-
end
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
`column` options:
|
|
146
|
-
|
|
147
|
-
- `header:` string (defaults to a humanized name)
|
|
148
|
-
- `class:` css class for the cell
|
|
149
|
-
- `render:` custom render key (advanced)
|
|
150
|
-
- `type:` `:toggle` or `:label` (special rendering)
|
|
151
|
-
- `toggle_field:` field to flip when `type: :toggle`
|
|
152
|
-
- `label_color:` color for `type: :label` (Symbol or Proc)
|
|
153
|
-
- `label_size:` `:sm`/`:md` (or Proc)
|
|
154
|
-
- `sortable:` boolean (reserved for future per-column sorting UI)
|
|
155
|
-
|
|
156
|
-
### Filters
|
|
157
|
-
|
|
158
|
-
```ruby
|
|
159
|
-
filters do
|
|
160
|
-
filter :status, type: :select, options: [["Active", "active"], ["Inactive", "inactive"]]
|
|
161
|
-
end
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
Filter options:
|
|
165
|
-
|
|
166
|
-
- `type:` (default `:text`)
|
|
167
|
-
- `label:`
|
|
168
|
-
- `placeholder:`
|
|
169
|
-
- `options:` / `collection:` (for select-like UI)
|
|
170
|
-
- `field:` which model field to filter on (defaults to the filter name)
|
|
171
|
-
- `apply:` Proc that receives the scope (advanced)
|
|
172
|
-
|
|
173
|
-
### Stats
|
|
174
|
-
|
|
175
|
-
```ruby
|
|
176
|
-
stats do
|
|
177
|
-
stat :total, -> { User.count }, color: :slate
|
|
178
|
-
end
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
## Form DSL (`form do ... end`)
|
|
182
|
-
|
|
183
|
-
```ruby
|
|
184
|
-
form do
|
|
185
|
-
field :name, required: true
|
|
186
|
-
field :website, type: :url
|
|
187
|
-
end
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
See [Fields](fields.md) for supported types and options.
|
|
191
|
-
|
|
192
|
-
AdminSuite also supports basic layout helpers in forms:
|
|
193
|
-
|
|
194
|
-
- `section "Title" do ... end`
|
|
195
|
-
- `row cols: 2 do ... end`
|
|
196
|
-
|
|
197
|
-
## Show DSL (`show do ... end`)
|
|
198
|
-
|
|
199
|
-
Show is section-based. Sections can live in the main column or sidebar.
|
|
200
|
-
|
|
201
|
-
```ruby
|
|
202
|
-
show do
|
|
203
|
-
main do
|
|
204
|
-
panel :details, title: "Details", fields: %i[name email]
|
|
205
|
-
panel :related, title: "Projects", association: :projects, display: :table, columns: %i[id name status], paginate: true
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
sidebar do
|
|
209
|
-
panel :meta, title: "Meta", fields: %i[id created_at updated_at]
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
Panel options:
|
|
215
|
-
|
|
216
|
-
- `title:` (defaults to a humanized name)
|
|
217
|
-
- `fields:` array of field names to display
|
|
218
|
-
- `render:` custom renderer key (see `custom_renderers` in [Configuration](configuration.md))
|
|
219
|
-
- `association:` association name to render (`has_many`, `belongs_to`, etc.)
|
|
220
|
-
- `display:` `:list` (default), `:table`, or `:cards` for associations
|
|
221
|
-
- `columns:` columns for association `:table` display
|
|
222
|
-
- `link_to:` helper method name to build links for association items (optional)
|
|
223
|
-
- `paginate:` boolean, enables pagination within the association section
|
|
224
|
-
- `per_page:` items per page for association pagination
|
|
225
|
-
- `limit:` max items (if not paginating)
|
|
226
|
-
- `collapsible:` / `collapsed:` (reserved for future UI toggles)
|
|
227
|
-
|
|
228
|
-
## Actions DSL (`actions do ... end`)
|
|
229
|
-
|
|
230
|
-
```ruby
|
|
231
|
-
actions do
|
|
232
|
-
action :reindex, label: "Reindex", method: :post, confirm: "Reindex this record?"
|
|
233
|
-
end
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
See [Actions](actions.md) for how actions execute and how to define handlers.
|
|
237
|
-
|
data/docs/theming.md
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# Theming & assets
|
|
2
|
-
|
|
3
|
-
AdminSuite is designed to work in two modes:
|
|
4
|
-
|
|
5
|
-
1. **Engine-build mode (default)**: AdminSuite builds and ships its own Tailwind CSS into your host app at `assets:precompile` time.
|
|
6
|
-
2. **Host-themed mode (optional)**: your host app includes a stylesheet after AdminSuite for branding/overrides.
|
|
7
|
-
|
|
8
|
-
## Theme colors (`config.theme`)
|
|
9
|
-
|
|
10
|
-
AdminSuite uses CSS variables scoped to `body.admin-suite`.
|
|
11
|
-
|
|
12
|
-
```ruby
|
|
13
|
-
AdminSuite.configure do |config|
|
|
14
|
-
config.theme = { primary: :emerald, secondary: :cyan }
|
|
15
|
-
end
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
### Allowed values
|
|
19
|
-
|
|
20
|
-
- **Named colors**: symbols/strings like `:indigo`, `:emerald`, `:cyan`, `:amber`, `:violet`, `:slate`, etc.
|
|
21
|
-
- **Hex**: `"#4f46e5"` (uses that exact color as primary/secondary in key places)
|
|
22
|
-
|
|
23
|
-
The theme primarily drives:
|
|
24
|
-
|
|
25
|
-
- Primary links/buttons (`--admin-suite-primary`, `--admin-suite-primary-hover`)
|
|
26
|
-
- Sidebar gradient (`--admin-suite-sidebar-from/via/to`)
|
|
27
|
-
|
|
28
|
-
## Host stylesheet (`config.host_stylesheet`)
|
|
29
|
-
|
|
30
|
-
If your host app already has Tailwind (or you want to override the engine UI), you can include an additional stylesheet after AdminSuite in the engine layout:
|
|
31
|
-
|
|
32
|
-
```ruby
|
|
33
|
-
AdminSuite.configure do |config|
|
|
34
|
-
config.host_stylesheet = :app
|
|
35
|
-
end
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
This calls `stylesheet_link_tag :app` after `admin_suite.css` and `admin_suite_tailwind.css`.
|
|
39
|
-
|
|
40
|
-
## Tailwind build
|
|
41
|
-
|
|
42
|
-
AdminSuite writes an engine stylesheet into your host app during `assets:precompile`:
|
|
43
|
-
|
|
44
|
-
- Input: `AdminSuite::Engine.root/app/assets/tailwind/admin_suite.css`
|
|
45
|
-
- Output: `Rails.root/app/assets/builds/admin_suite_tailwind.css`
|
|
46
|
-
|
|
47
|
-
In development, the engine also makes a best-effort to create the output file if it’s missing, so the UI stays usable.
|
|
48
|
-
|
|
49
|
-
## Icons
|
|
50
|
-
|
|
51
|
-
AdminSuite uses lucide icons by default via `lucide-rails`.
|
|
52
|
-
|
|
53
|
-
If you need a different icon provider:
|
|
54
|
-
|
|
55
|
-
```ruby
|
|
56
|
-
AdminSuite.configure do |config|
|
|
57
|
-
config.icon_renderer = ->(name, view, **opts) do
|
|
58
|
-
# return HTML-safe SVG (string or ActiveSupport::SafeBuffer)
|
|
59
|
-
view.content_tag(:span, name, class: opts[:class])
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
```
|
|
63
|
-
|
data/docs/troubleshooting.md
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# Troubleshooting
|
|
2
|
-
|
|
3
|
-
## “My resources don’t show up in the sidebar”
|
|
4
|
-
|
|
5
|
-
Checklist:
|
|
6
|
-
|
|
7
|
-
- Your resource class:
|
|
8
|
-
- is under `Admin::Resources`
|
|
9
|
-
- ends with `Resource` (e.g. `UserResource`)
|
|
10
|
-
- sets both `portal :...` and `section :...`
|
|
11
|
-
- The file is located under one of the configured `resource_globs` paths (see [Configuration](configuration.md)).
|
|
12
|
-
|
|
13
|
-
In development, AdminSuite loads resources on-demand when building navigation. In non-development environments, you should ensure your resource files are loaded at boot (using the globs) and are not excluded by your deployment setup.
|
|
14
|
-
|
|
15
|
-
## “Constant not found” / Zeitwerk errors for host DSL files
|
|
16
|
-
|
|
17
|
-
If you store AdminSuite DSL files under `app/admin_suite/**` in the host app, those files are not constant definitions.
|
|
18
|
-
|
|
19
|
-
AdminSuite ignores `Rails.root/app/admin_suite` in Zeitwerk to prevent eager-load errors. If you still see issues:
|
|
20
|
-
|
|
21
|
-
- Ensure the DSL folder really is `app/admin_suite` (not a different path)
|
|
22
|
-
- Prefer `config/admin_suite/resources/*.rb` and `config/admin_suite/portals/*.rb` for DSL files
|
|
23
|
-
|
|
24
|
-
## “Docs viewer shows no files”
|
|
25
|
-
|
|
26
|
-
- Confirm `AdminSuite.config.docs_path` exists
|
|
27
|
-
- Ensure files are `*.md`
|
|
28
|
-
- Visit `/docs` relative to your mount path (e.g. `/internal/admin/docs`)
|
|
29
|
-
|
|
30
|
-
## “Tailwind styles are missing in production”
|
|
31
|
-
|
|
32
|
-
AdminSuite expects `assets:precompile` to run and generate:
|
|
33
|
-
|
|
34
|
-
- `app/assets/builds/admin_suite_tailwind.css` in your host app
|
|
35
|
-
|
|
36
|
-
If you don’t run precompile in your deployment pipeline, you can:
|
|
37
|
-
|
|
38
|
-
- Start running `assets:precompile`, or
|
|
39
|
-
- Build the file manually by running:
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
bin/rails admin_suite:tailwind:build
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## “Icons don’t render”
|
|
46
|
-
|
|
47
|
-
AdminSuite defaults to `lucide-rails`.
|
|
48
|
-
|
|
49
|
-
If your host app excludes it, set `AdminSuite.config.icon_renderer` to provide icons (see [Theming & assets](theming.md)).
|
|
50
|
-
|