tolaria 1.0.0 → 1.0.1
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/.travis.yml +4 -0
- data/README.md +17 -14
- data/app/assets/stylesheets/admin/components/forms/_nested_fields.scss +2 -0
- data/app/controllers/tolaria/resource_controller.rb +18 -4
- data/app/helpers/admin/table_helper.rb +28 -23
- data/app/helpers/admin/view_helper.rb +5 -4
- data/app/models/administrator.rb +3 -3
- data/app/views/admin/tolaria_resource/_form_buttons.html.erb +5 -3
- data/app/views/admin/tolaria_resource/edit.html.erb +5 -1
- data/app/views/admin/tolaria_resource/show.html.erb +5 -1
- data/lib/tolaria.rb +1 -1
- data/lib/tolaria/active_record.rb +19 -4
- data/lib/tolaria/categories.rb +2 -2
- data/lib/tolaria/config.rb +19 -5
- data/lib/tolaria/default_config.rb +8 -36
- data/lib/tolaria/{introspection.rb → display_name.rb} +1 -1
- data/lib/tolaria/form_buildable.rb +9 -9
- data/lib/tolaria/help_links.rb +12 -7
- data/lib/tolaria/manage.rb +2 -2
- data/lib/tolaria/managed_class.rb +5 -5
- data/lib/tolaria/markdown.rb +3 -3
- data/lib/tolaria/random_tokens.rb +3 -2
- data/lib/tolaria/reload.rb +1 -1
- data/lib/tolaria/version.rb +1 -1
- data/test/integration/forbidden_routes_test.rb +105 -0
- data/tolaria.gemspec +1 -1
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c447de7756733e7206984d95df7b1cc2745b65a8
|
4
|
+
data.tar.gz: 9cafe04bae67cf2248f4a90c5c19e0f684739095
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cfa153900abd851aea97fc0d79dfb012a35218f448c690a098d495bdf5bdbc4fe26499e16bd27b9a7578e75e07f3a1613ac0ba71447bbcfe2b8ef77f04e877d
|
7
|
+
data.tar.gz: 8c6ca85bfd80d7544dfb3b5d3623147c6a29c0e161963823f2392c42f7f82060ee62a76bca94f214d84f86ba591095e2d9815a532b8e5ed9b53d134a384e87f6
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
## Tolaria
|
2
2
|
|
3
|
+
[](https://travis-ci.org/Threespot/tolaria)
|
4
|
+
|
3
5
|
Tolaria is a [content management system](https://en.wikipedia.org/wiki/Content_management_system) (CMS) framework for [Ruby on Rails](https://en.wikipedia.org/wiki/Ruby_on_Rails). It greatly speeds up the necessary—but repetitive—task of creating useful admin panels, forms, and model workflows for site authors.
|
4
6
|
|
5
7
|
[](https://cloud.githubusercontent.com/assets/769083/7573791/56eda172-f7f6-11e4-8df7-36015cf5cf85.png)
|
@@ -99,7 +101,7 @@ You can configure Tolaria's passcode paranoia in the initializer you installed a
|
|
99
101
|
|
100
102
|
### Managing a Model
|
101
103
|
|
102
|
-
Inside your ActiveRecord definition for your model, call `manage_with_tolaria`, passing configuration in the `using` Hash. [Refer to the documentation for all of the options](
|
104
|
+
Inside your ActiveRecord definition for your model, call `manage_with_tolaria`, passing configuration in the `using` Hash. [Refer to the documentation for all of the options](http://www.rubydoc.info/gems/tolaria/ActiveRecord%2FBase.manage_with_tolaria).
|
103
105
|
|
104
106
|
The icon system uses [Font Awesome][fa], and you'll need to pass one of [the icon names][fa] for the `icon` key.
|
105
107
|
|
@@ -128,7 +130,7 @@ By default, Tolaria will build a simple index screen for each model. You'll like
|
|
128
130
|
|
129
131
|
If your model was `BlogPost`, you'll need to create a file in your project at: `app/views/admin/blog_posts/_index.html.erb`.
|
130
132
|
|
131
|
-
See the [TableHelper documentation](
|
133
|
+
See the [TableHelper documentation](http://www.rubydoc.info/gems/tolaria/Admin/TableHelper) for more information.
|
132
134
|
|
133
135
|
```erb
|
134
136
|
<% # app/views/admin/blog_posts/_index.html.erb %>
|
@@ -161,7 +163,7 @@ Tolaria provides a very basic show/inspect screen for models. You'll want to pro
|
|
161
163
|
|
162
164
|
If your model was `BlogPost`, you'll need to create a file in your project at: `app/views/admin/blog_posts/_show.html.erb`.
|
163
165
|
|
164
|
-
See the [TableHelper documentation](
|
166
|
+
See the [TableHelper documentation](http://www.rubydoc.info/gems/tolaria/Admin/TableHelper) for more information.
|
165
167
|
|
166
168
|
```erb
|
167
169
|
<% # app/views/admin/blog_posts/_show.html.erb %>
|
@@ -274,11 +276,11 @@ If your model was `BlogPost`, you'll need to create a file in your project at `
|
|
274
276
|
|
275
277
|
### Provided Form Fields
|
276
278
|
|
277
|
-
You can use all of the Rails-provided fields on your forms, but Tolaria also comes with a set of advanced, JavaScript-backed fields. Make sure to [review the documentation for the form builder](
|
279
|
+
You can use all of the Rails-provided fields on your forms, but Tolaria also comes with a set of advanced, JavaScript-backed fields. Make sure to [review the documentation for the form builder](http://www.rubydoc.info/gems/tolaria/Admin/FormBuilder) to get all the details.
|
278
280
|
|
279
281
|
#### Markdown Composer
|
280
282
|
|
281
|
-
The [`markdown_composer` helper](
|
283
|
+
The [`markdown_composer` helper](http://www.rubydoc.info/gems/tolaria/Tolaria%2FFormBuildable%3Amarkdown_composer) will generate a very fancy Markdown editor, which includes text snippet tools and a fullscreen mode with live previewing.
|
282
284
|
|
283
285
|
**Important:** You cannot use this field properly if you do not set up `Tolaria.config.markdown_renderer`. Without it, the live preview will only use `simple_format`!
|
284
286
|
|
@@ -292,7 +294,7 @@ The [`markdown_composer` helper](#FIXME) will generate a very fancy Markdown edi
|
|
292
294
|
|
293
295
|
#### Searchable Select
|
294
296
|
|
295
|
-
The [`searchable_select` helper](
|
297
|
+
The [`searchable_select` helper](http://www.rubydoc.info/gems/tolaria/Tolaria%2FFormBuildable%3Asearchable_select) displays a [Chosen select field](http://harvesthq.github.io/chosen/) that authors can filter by typing.
|
296
298
|
|
297
299
|
```
|
298
300
|
<%= f.label :title, "Topics" %>
|
@@ -304,7 +306,7 @@ The [`searchable_select` helper](#FIXME) displays a [Chosen select field](http:/
|
|
304
306
|
|
305
307
|
#### Image Association Select
|
306
308
|
|
307
|
-
The [`image_association_select` helper](
|
309
|
+
The [`image_association_select` helper](http://www.rubydoc.info/gems/tolaria/Tolaria%2FFormBuildable%3Aimage_association_select) displays a `searchable_select` that provides an instant preview of the currently selected model as an image.
|
308
310
|
|
309
311
|
```erb
|
310
312
|
<%= f.label :featured_image_id, "Featured Image" %>
|
@@ -316,7 +318,7 @@ The [`image_association_select` helper](#FIXME) displays a `searchable_select` t
|
|
316
318
|
|
317
319
|
#### Timestamp Field
|
318
320
|
|
319
|
-
The [`timestamp_field` helper](
|
321
|
+
The [`timestamp_field` helper](http://www.rubydoc.info/gems/tolaria/Tolaria%2FFormBuildable%3Atimestamp_field) displays a text field that validates a provided timestamp and recovers to a template if blanked.
|
320
322
|
|
321
323
|
```erb
|
322
324
|
<%= f.label :published_at, "Publishing Date" %>
|
@@ -328,7 +330,7 @@ The [`timestamp_field` helper](#FIXME) displays a text field that validates a pr
|
|
328
330
|
|
329
331
|
#### Slug Field
|
330
332
|
|
331
|
-
The [`slug_field` helper](
|
333
|
+
The [`slug_field` helper](http://www.rubydoc.info/gems/tolaria/Tolaria%2FFormBuildable%3Aslug_field) allows you to show the parameterized value of a field in a given pattern preview.
|
332
334
|
|
333
335
|
```erb
|
334
336
|
<%= f.label :title %>
|
@@ -340,7 +342,7 @@ The [`slug_field` helper](#FIXME) allows you to show the parameterized value of
|
|
340
342
|
|
341
343
|
#### Swatch Field
|
342
344
|
|
343
|
-
The [`swatch_field` helper](
|
345
|
+
The [`swatch_field` helper](http://www.rubydoc.info/gems/tolaria/Tolaria%2FFormBuildable%3Aswatch_field) validates and displays a given hexadecimal color.
|
344
346
|
|
345
347
|
```erb
|
346
348
|
<%= f.label :color %>
|
@@ -352,7 +354,7 @@ The [`swatch_field` helper](#FIXME) validates and displays a given hexadecimal c
|
|
352
354
|
|
353
355
|
#### Image Field
|
354
356
|
|
355
|
-
The [`image_field` helper](
|
357
|
+
The [`image_field` helper](http://www.rubydoc.info/gems/tolaria/Tolaria%2FFormBuildable%3Aimage_field) displays a button that makes uploading an image a little more pleasant than a regular `file_field`.
|
356
358
|
|
357
359
|
```erb
|
358
360
|
<%= f.label :portrait %>
|
@@ -364,7 +366,7 @@ The [`image_field` helper](#FIXME) displays a button that makes uploading an ima
|
|
364
366
|
|
365
367
|
#### Attachment Field
|
366
368
|
|
367
|
-
The [`attachment_field` helper](
|
369
|
+
The [`attachment_field` helper](http://www.rubydoc.info/gems/tolaria/Tolaria%2FFormBuildable%3Aattachment_field) displays a button that makes uploading an arbirary file a little more pleasant than a regular `file_field`.
|
368
370
|
|
369
371
|
```erb
|
370
372
|
<%= f.label :portrait %>
|
@@ -392,7 +394,7 @@ If you need to run two or more `select` controls together (like for `date_select
|
|
392
394
|
|
393
395
|
#### Hints
|
394
396
|
|
395
|
-
[Inline help](
|
397
|
+
[Inline help](http://www.rubydoc.info/gems/tolaria/Tolaria%2FFormBuildable%3Ahint) is useful for reminding administrators about what should be provided for each field. Use `f.hint` to present a hint for a field.
|
396
398
|
|
397
399
|

|
398
400
|
|
@@ -489,7 +491,7 @@ If you want to add additional Sass or JavaScript to the admin system, you can cr
|
|
489
491
|
|
490
492
|
Tolaria comes with a test suite and a demo server that the test suite exercises.
|
491
493
|
|
492
|
-
To run tests, first clone the repo:
|
494
|
+
To run tests, first clone the repo or your fork of it:
|
493
495
|
|
494
496
|
```shell
|
495
497
|
$ git clone -o github git@github.com:threespot/tolaria.git
|
@@ -530,6 +532,7 @@ Our work stands on the shoulders of giants, and we're very thankful to the many
|
|
530
532
|
- [The jQuery Foundation](https://jquery.org)
|
531
533
|
- [Jeremy Ashkenas](https://twitter.com/jashkenas)
|
532
534
|
- [The Harvest Team](https://www.getharvest.com/about/meet-the-team)
|
535
|
+
- [Font Awesome and Dave Gandy](http://fontawesome.io/icons/)
|
533
536
|
|
534
537
|
### About Threespot
|
535
538
|
|
@@ -33,7 +33,7 @@ class Tolaria::ResourceController < Tolaria::TolariaController
|
|
33
33
|
|
34
34
|
if @resource.save
|
35
35
|
flash[:success] = "#{random_blingword} You created the #{@managed_class.model_name.human} “#{display_name}”."
|
36
|
-
return redirect_to
|
36
|
+
return redirect_to form_completion_redirect_path(@managed_class, @resource)
|
37
37
|
else
|
38
38
|
log_validation_errors!
|
39
39
|
flash.now[:error] = "Your changes couldn’t be saved. Please correct the following errors:"
|
@@ -55,7 +55,7 @@ class Tolaria::ResourceController < Tolaria::TolariaController
|
|
55
55
|
|
56
56
|
if @resource.save
|
57
57
|
flash[:success] = "#{random_blingword} You updated the #{@managed_class.model_name.human.downcase} “#{display_name}”."
|
58
|
-
return redirect_to
|
58
|
+
return redirect_to form_completion_redirect_path(@managed_class, @resource)
|
59
59
|
else
|
60
60
|
log_validation_errors!
|
61
61
|
flash.now[:error] = "Your changes couldn’t be saved. Please correct the following errors:"
|
@@ -73,11 +73,11 @@ class Tolaria::ResourceController < Tolaria::TolariaController
|
|
73
73
|
@resource.destroy
|
74
74
|
rescue ActiveRecord::DeleteRestrictionError => e
|
75
75
|
flash[:restricted] = "You cannot delete “#{display_name}” because other items are using it."
|
76
|
-
return redirect_to
|
76
|
+
return redirect_to form_completion_redirect_path(@managed_class, @resource)
|
77
77
|
end
|
78
78
|
|
79
79
|
flash[:destructive] = "You deleted the #{@managed_class.model_name.human.downcase} “#{display_name}”."
|
80
|
-
return redirect_to
|
80
|
+
return redirect_to form_completion_redirect_path(@managed_class)
|
81
81
|
|
82
82
|
end
|
83
83
|
|
@@ -89,6 +89,20 @@ class Tolaria::ResourceController < Tolaria::TolariaController
|
|
89
89
|
["Done!", "Okay!", "Success!"].sample
|
90
90
|
end
|
91
91
|
|
92
|
+
# Returns a path we should redirect to when the form is completed successfully.
|
93
|
+
# Handles route forbidding cases.
|
94
|
+
def form_completion_redirect_path(managed_class, resource = nil)
|
95
|
+
if managed_class.allows? :index
|
96
|
+
url_for([:admin, managed_class.klass])
|
97
|
+
elsif managed_class.allows?(:show) && resource.present?
|
98
|
+
url_for(action:"show", id:resource.id)
|
99
|
+
elsif managed_class.allows?(:edit) && resource.present?
|
100
|
+
url_for(action:"edit", id:resource.id)
|
101
|
+
else
|
102
|
+
Tolaria.config.defaut_redirect
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
92
106
|
# Load the Tolaria managed class for this controller
|
93
107
|
def load_managed_class!
|
94
108
|
@managed_class ||= Tolaria.managed_classes.find do |managed_class|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Admin::TableHelper
|
2
2
|
|
3
3
|
# Returns a `<table class="index-table">` tag with the appropriate wrapper
|
4
|
-
# and the given
|
4
|
+
# and the given `content` or block content inside it.
|
5
5
|
def index_table(content = nil, &block)
|
6
6
|
content_tag :div, class:"index-table-wrap" do
|
7
7
|
content_tag :table, class:"index-table" do
|
@@ -10,7 +10,7 @@ module Admin::TableHelper
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
# Returns a `<table class="show-table">` tag with the given
|
13
|
+
# Returns a `<table class="show-table">` tag with the given `content`
|
14
14
|
# or block content inside it.
|
15
15
|
def show_table(content = nil, &block)
|
16
16
|
content_tag :table, class:"show-table" do
|
@@ -29,20 +29,19 @@ module Admin::TableHelper
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# Returns a `<tr>` with two `<td>`s suitable for use in a `table.show-table`.
|
32
|
-
# The given
|
32
|
+
# The given `label` is placed inside the first `<td>`, while the `value`
|
33
33
|
# is placed in the second `<td>`. Options are forwarded to `content_tag`
|
34
34
|
# for the *second* `<td>`.
|
35
35
|
#
|
36
|
-
# If
|
36
|
+
# If `label` is a symbol, it is assumed to be a method on a variable named
|
37
37
|
# `@resource` in the current template, and the `<tr>` is constructed
|
38
38
|
# automatically for you by converting the symbol to a human-readable label
|
39
|
-
# and calling the named method on @resource to get the
|
39
|
+
# and calling the named method on @resource to get the `value`.
|
40
40
|
#
|
41
|
-
#
|
41
|
+
# #### Signatures
|
42
42
|
#
|
43
43
|
# # Set the values yourself, and a class on the second `<td>`
|
44
44
|
# show_tr "Slug", resource.slug, class:"monospace"
|
45
|
-
#
|
46
45
|
# # Attempt to auto-fill the row based on a method name
|
47
46
|
# show_tr :slug
|
48
47
|
def show_tr(label, value = nil, options = nil)
|
@@ -70,22 +69,20 @@ module Admin::TableHelper
|
|
70
69
|
end
|
71
70
|
|
72
71
|
# Returns a `<th>` tag, suitable for use inside a `table.index-table`.
|
73
|
-
#
|
74
|
-
#
|
72
|
+
# `field_or_label` may be any string, or a symbol naming a model column.
|
73
|
+
# `sort` may be `true`, `false`, or a symbol. See the signtures below.
|
75
74
|
#
|
76
75
|
# If the column is sortable, the `<th>` will contain a Ransack sort link
|
77
76
|
# that allows the end-user to organize the table by that column.
|
78
77
|
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
# # Create a header that sorts a named column
|
82
|
-
# index_th(:title, sort:true)
|
83
|
-
#
|
84
|
-
# # Create a header that sorts a column, with custom label
|
85
|
-
# index_th("Strange Title", sort: :title)
|
78
|
+
# #### Signatures
|
86
79
|
#
|
87
|
-
#
|
88
|
-
#
|
80
|
+
# # Create a header that sorts a named column
|
81
|
+
# index_th(:title, sort:true)
|
82
|
+
# # Create a header that sorts a column, with custom label
|
83
|
+
# index_th("Strange Title", sort: :title)
|
84
|
+
# # Create a header that can't be sorted
|
85
|
+
# index_th("Strange Title", sort:false)
|
89
86
|
def index_th(field_or_label, sort:true)
|
90
87
|
|
91
88
|
case field_or_label
|
@@ -110,9 +107,9 @@ module Admin::TableHelper
|
|
110
107
|
end
|
111
108
|
|
112
109
|
# Returns a `<td>` tag, suitable for use inside a `table.index-table`.
|
113
|
-
# If
|
114
|
-
# given
|
115
|
-
# it expects
|
110
|
+
# If `method_or_content` is a symbol, it will call that method on the
|
111
|
+
# given `resource` to obtain the content of the `<td>`. Otherwise
|
112
|
+
# it expects `method_or_content` or a passed block to provide suitable string.
|
116
113
|
#
|
117
114
|
# #### Special Options
|
118
115
|
#
|
@@ -139,8 +136,16 @@ module Admin::TableHelper
|
|
139
136
|
image = image_tag(image, size:"18x18", alt:"")
|
140
137
|
end
|
141
138
|
|
139
|
+
if @managed_class.allows? :edit
|
140
|
+
link = url_for(action:"edit", id:resource.id)
|
141
|
+
elsif @managed_class.allows? :show
|
142
|
+
link = url_for(action:"show", id:resource.id)
|
143
|
+
else
|
144
|
+
link = "#" # Guh, painted ourseves into a corner here
|
145
|
+
end
|
146
|
+
|
142
147
|
return content_tag(:td, options) do
|
143
|
-
link_to("#{image}#{content}".html_safe,
|
148
|
+
link_to("#{image}#{content}".html_safe, link)
|
144
149
|
end
|
145
150
|
|
146
151
|
end
|
@@ -151,7 +156,7 @@ module Admin::TableHelper
|
|
151
156
|
end
|
152
157
|
|
153
158
|
# Returns a `<td>` tag, suitable for use inside a `table.index-table`.
|
154
|
-
# The tag contains buttons to edit, inspect, and delete the given
|
159
|
+
# The tag contains buttons to edit, inspect, and delete the given `resource`.
|
155
160
|
def actions_td(resource)
|
156
161
|
|
157
162
|
links = []
|
@@ -17,7 +17,8 @@ module Admin::ViewHelper
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
# Returns an `<i>` tag that displays
|
20
|
+
# Returns an `<i>` tag that displays the Font Awesome icon for the given `icon`.
|
21
|
+
# Names much match those from [the Font Awesome site](http://fontawesome.io/icons/).
|
21
22
|
def fontawesome_icon(icon = "", options = {})
|
22
23
|
icon = icon.to_s.parameterize.tr("_", "-")
|
23
24
|
content_tag :i, nil, options.reverse_merge({
|
@@ -32,7 +33,7 @@ module Admin::ViewHelper
|
|
32
33
|
return "https://secure.gravatar.com/avatar/#{digest}?d=retro&s=36"
|
33
34
|
end
|
34
35
|
|
35
|
-
# Returns true if a partial is available at "admin/#{template_path}"
|
36
|
+
# Returns true if a partial is available at `"admin/#{template_path}"`
|
36
37
|
def admin_template_exists?(template_path)
|
37
38
|
lookup_context.template_exists?("admin/#{template_path}", [], true)
|
38
39
|
end
|
@@ -57,9 +58,9 @@ module Admin::ViewHelper
|
|
57
58
|
return %{Are you sure you want to delete the #{resource.model_name.human.downcase} “#{Tolaria.display_name(resource)}”? This action is not reversible.}
|
58
59
|
end
|
59
60
|
|
60
|
-
# Returns a `<span>` tag that displays the given
|
61
|
+
# Returns a `<span>` tag that displays the given `label` as a pill
|
61
62
|
# status badge. You can change the color of the pill by providing a
|
62
|
-
# six-digit hexadecimal
|
63
|
+
# six-digit hexadecimal `color` string, or passing one of the predefined
|
63
64
|
# color names: `:green`, `:red`, `:blue`, `:black`, `:grey`.
|
64
65
|
def pill(label, color: :black)
|
65
66
|
|
data/app/models/administrator.rb
CHANGED
@@ -37,8 +37,8 @@ class Administrator < ActiveRecord::Base
|
|
37
37
|
# and passcode inside the time window
|
38
38
|
# -----------------------------------------------------------------------------
|
39
39
|
|
40
|
-
# Initialize
|
41
|
-
#
|
40
|
+
# Initialize `passcode`, `passcode_expires_at`,
|
41
|
+
# `auth_token`, and `account_unlocks_at` for a new admin.
|
42
42
|
# To prevent passcode system fields from being null,
|
43
43
|
# we fill them with an immediately expired passcode.
|
44
44
|
def initialize_authentication!
|
@@ -66,7 +66,7 @@ class Administrator < ActiveRecord::Base
|
|
66
66
|
return plaintext_passcode
|
67
67
|
end
|
68
68
|
|
69
|
-
# Attempt to authenticate the account with the given plaintext
|
69
|
+
# Attempt to authenticate the account with the given plaintext `passcode`.
|
70
70
|
# Returns true if the passcode was valid, false otherwise.
|
71
71
|
def authenticate!(passcode)
|
72
72
|
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
<%=
|
3
|
-
|
1
|
+
<% if @managed_class.allows? :index %>
|
2
|
+
<%= link_to url_for([:admin, @managed_class.klass]), class:"button" do %>
|
3
|
+
<%= fontawesome_icon :close %>
|
4
|
+
Cancel
|
5
|
+
<% end %>
|
4
6
|
<% end %>
|
5
7
|
|
6
8
|
<%= button_tag type:"submit", name:nil, class:"button -primary" do %>
|
@@ -11,7 +11,11 @@
|
|
11
11
|
<h1>
|
12
12
|
<span class="crumb">
|
13
13
|
<%= fontawesome_icon @managed_class.icon %>
|
14
|
-
|
14
|
+
<% if @managed_class.allows? :index %>
|
15
|
+
<%= link_to @managed_class.model_name.human.pluralize.titleize, url_for(action:"index", controller:@managed_class.plural) %>
|
16
|
+
<% else %>
|
17
|
+
<%= @managed_class.model_name.human.pluralize.titleize %>
|
18
|
+
<% end %>
|
15
19
|
</span>
|
16
20
|
<%= content_for :title %>
|
17
21
|
</h1>
|
@@ -6,7 +6,11 @@
|
|
6
6
|
<h1>
|
7
7
|
<span class="crumb">
|
8
8
|
<%= fontawesome_icon @managed_class.icon %>
|
9
|
-
|
9
|
+
<% if @managed_class.allows? :index %>
|
10
|
+
<%= link_to @managed_class.model_name.human.pluralize.titleize, url_for(action:"index", controller:@managed_class.plural) %>
|
11
|
+
<% else %>
|
12
|
+
<%= @managed_class.model_name.human.pluralize.titleize %>
|
13
|
+
<% end %>
|
10
14
|
</span>
|
11
15
|
<%= content_for :title %>
|
12
16
|
</h1>
|
data/lib/tolaria.rb
CHANGED
@@ -21,7 +21,7 @@ require "tolaria/manage"
|
|
21
21
|
require "tolaria/active_record"
|
22
22
|
require "tolaria/help_links"
|
23
23
|
require "tolaria/routes"
|
24
|
-
require "tolaria/
|
24
|
+
require "tolaria/display_name"
|
25
25
|
require "tolaria/categories"
|
26
26
|
require "tolaria/markdown"
|
27
27
|
require "tolaria/form_buildable"
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# Adds a new DSL method to ActiveRecord model definition, allowing the
|
2
2
|
# developer to configure a model to manage with Tolaria.
|
3
3
|
# The developer passes a hash of configuration options which are
|
4
|
-
# forwarded as keyword arguments to Tolaria.manage
|
4
|
+
# forwarded as keyword arguments to `Tolaria.manage`.
|
5
5
|
|
6
6
|
class ActiveRecord::Base
|
7
7
|
|
8
8
|
# Register a model with Tolaria and allow administrators to manage it
|
9
|
-
# in the admin interface. Accepts one named parameter,
|
9
|
+
# in the admin interface. Accepts one named parameter, `using`
|
10
10
|
# which should be a Hash of options below.
|
11
11
|
#
|
12
12
|
# #### Options
|
@@ -18,8 +18,7 @@ class ActiveRecord::Base
|
|
18
18
|
# Items with lower priority are sorted first.
|
19
19
|
# The default is 10.
|
20
20
|
# - `:icon` - The Font Awesome icon to use for this model.
|
21
|
-
# Should be one of the names on the Font Awesome site
|
22
|
-
# http://fortawesome.github.io/Font-Awesome/icons/
|
21
|
+
# Should be one of the names on [the Font Awesome site](http://fortawesome.github.io/Font-Awesome/icons/)
|
23
22
|
# The default is `"file-o"`.
|
24
23
|
# - `:permitted_params` - A array of parameter names to pass to
|
25
24
|
# `params.permit()` for this model/form.
|
@@ -37,6 +36,22 @@ class ActiveRecord::Base
|
|
37
36
|
# Tolaria will pass this array as the `only:` option to the router.
|
38
37
|
# The default includes all CRUD actions:
|
39
38
|
# `[:index, :show, :new, :create, :edit, :update, :destroy]`
|
39
|
+
#
|
40
|
+
# #### Example
|
41
|
+
#
|
42
|
+
# class BlogPost < ActiveRecord::Base
|
43
|
+
# manage_with_tolaria using: {
|
44
|
+
# icon: "file-o",
|
45
|
+
# category: "Settings",
|
46
|
+
# priority: 5,
|
47
|
+
# permit_params: [
|
48
|
+
# :title,
|
49
|
+
# :body,
|
50
|
+
# :author_id,
|
51
|
+
# ]
|
52
|
+
# }
|
53
|
+
# end
|
54
|
+
|
40
55
|
def self.manage_with_tolaria(using:{})
|
41
56
|
@tolaria_management_options = using
|
42
57
|
if Tolaria.safe_management
|
data/lib/tolaria/categories.rb
CHANGED
@@ -7,8 +7,8 @@ module Tolaria
|
|
7
7
|
(self.config.menu_categories + self.managed_classes.collect(&:category)).uniq
|
8
8
|
end
|
9
9
|
|
10
|
-
# Returns all of the managed classes for the given
|
11
|
-
# sorted by their priority
|
10
|
+
# Returns all of the managed classes for the given `category`,
|
11
|
+
# sorted by their priority.
|
12
12
|
def self.classes_for_category(category)
|
13
13
|
classes = Tolaria.managed_classes.select do |managed_class|
|
14
14
|
managed_class.category == category
|
data/lib/tolaria/config.rb
CHANGED
@@ -1,20 +1,35 @@
|
|
1
1
|
module Tolaria
|
2
2
|
|
3
|
-
# Tolaria’s
|
4
|
-
# if you try to configure a key that doesn't exist.
|
3
|
+
# Tolaria’s configuration is a class so that an exception is raised
|
4
|
+
# if you try to configure a key that doesn't exist.
|
5
|
+
# Refer to the comments in the initializer that Tolaria generated for
|
6
|
+
# you when you ran `rails generate tolaria:install`.
|
5
7
|
class Configuration
|
8
|
+
# The cost factor for bcrypt
|
6
9
|
attr_accessor :bcrypt_cost
|
10
|
+
# The name of the company using this admin interface
|
7
11
|
attr_accessor :company_name
|
12
|
+
# The default redirect path when administrators log in or no better path exists
|
8
13
|
attr_accessor :default_redirect
|
14
|
+
# An array of method names Tolaria uses to attempt to convert a model to a string
|
9
15
|
attr_accessor :display_name_methods
|
16
|
+
# The `From` header for emails Tolaria sends
|
10
17
|
attr_accessor :from_address
|
18
|
+
# An array of hashes for configuring Help Links
|
11
19
|
attr_accessor :help_links
|
20
|
+
# The number of seconds that an administrator is locked out when they hit the rate-limit
|
12
21
|
attr_accessor :lockout_duration
|
22
|
+
# The number of times an administrator can flunk their passcode challenge or request a token before Tolaria disables their account.
|
13
23
|
attr_accessor :lockout_threshold
|
24
|
+
# A string that names a Markdown renderer for Tolaria to use.
|
14
25
|
attr_accessor :markdown_renderer
|
26
|
+
# An array of configured menu category labels
|
15
27
|
attr_accessor :menu_categories
|
28
|
+
# The default page size Tolaria uses when paginating
|
16
29
|
attr_accessor :page_size
|
30
|
+
# The number of seconds that a generated passcode is valid
|
17
31
|
attr_accessor :passcode_lifespan
|
32
|
+
# The default array of permitted params (internal use only)
|
18
33
|
attr_accessor :permitted_params
|
19
34
|
end
|
20
35
|
|
@@ -28,10 +43,9 @@ module Tolaria
|
|
28
43
|
|
29
44
|
# Configure Tolaria, block-style. Use something similar to:
|
30
45
|
#
|
31
|
-
#
|
46
|
+
# Tolaria.configure do |config|
|
32
47
|
# # Assign to config properties here
|
33
|
-
#
|
34
|
-
#
|
48
|
+
# end
|
35
49
|
def self.configure(&block)
|
36
50
|
yield @configuration ||= Tolaria::Configuration.new
|
37
51
|
end
|
@@ -1,51 +1,28 @@
|
|
1
|
+
# This file initializes Tolaria's default configuration, which the developer
|
2
|
+
# is expected to override.
|
3
|
+
#
|
4
|
+
# Please see lib/generators/tolaria/install/templates/tolaria_initializer.rb
|
5
|
+
# and config.rb for details.
|
6
|
+
|
1
7
|
Tolaria.configure do |config|
|
2
8
|
|
3
|
-
# The name of the company or group using this admin interface.
|
4
|
-
# Used in system navigation and HTML page titles.
|
5
9
|
config.company_name = "Company Name"
|
10
|
+
config.from_address = "Rails <tolaria@example.org>"
|
6
11
|
|
7
|
-
# Redirect the users to this route by default when logging in.
|
8
12
|
config.default_redirect = :admin_administrators
|
9
13
|
|
10
|
-
# Tolaria sends authentication emails. Set the value of the From header here.
|
11
|
-
config.from_address = "Rails <tolaria@example.org>"
|
12
|
-
|
13
|
-
# You can assign models to a category group them on the nav menu.
|
14
|
-
# Add/modify categories by changing the array below.
|
15
|
-
# Categories first in the array will be first on the menu.
|
16
14
|
config.menu_categories = ["Settings"]
|
17
15
|
|
18
|
-
# The cost factor for bcrypt.
|
19
|
-
# It is VERY DANGEROUS to set this below 10 for production.
|
20
|
-
# Use 1 in test mode to speed up your test suite.
|
21
16
|
config.bcrypt_cost = Rails.env.test?? 1 : 13
|
22
|
-
|
23
|
-
# The length of time that emailed passcodes should be valid.
|
24
|
-
# It is STRONGLY RECOMMENDED that you keep this under 30 minutes.
|
25
17
|
config.passcode_lifespan = 10.minutes
|
26
|
-
|
27
|
-
# The number of times an administrator can flunk their passcode
|
28
|
-
# challenge or request a token before Tolaria disables their account.
|
29
18
|
config.lockout_threshold = 10
|
30
|
-
|
31
|
-
# The length of time that an administrator’s account is disabled
|
32
|
-
# after they trip the lockout threshold.
|
33
19
|
config.lockout_duration = 1.hour
|
34
20
|
|
35
|
-
# An array of hashes used to construct HelpLinks
|
36
21
|
config.help_links = []
|
37
22
|
|
38
|
-
# Tolaria does not come bundled with a Markdown processing strategy.
|
39
|
-
# You must provide a string that names a Ruby constant that can process Markdown.
|
40
|
-
# The constant must respond to render(document), returning a string of HTML.
|
41
|
-
# For example: if you provide "MyMarkDownRenderer", Tolaria will
|
42
|
-
# call MyMarkdownRenderer.render(document).
|
43
23
|
config.markdown_renderer = nil
|
24
|
+
config.page_size = 15
|
44
25
|
|
45
|
-
# Tolaria attempts to convert models to a pretty “display”
|
46
|
-
# string for presenting in forms and listings.
|
47
|
-
# The methods below are tried in order on models until one responds.
|
48
|
-
# Must be an array of symbols.
|
49
26
|
config.display_name_methods = %i[
|
50
27
|
admin_name
|
51
28
|
display_name
|
@@ -59,11 +36,6 @@ Tolaria.configure do |config|
|
|
59
36
|
id
|
60
37
|
]
|
61
38
|
|
62
|
-
# The number of items on each page when paginating models.
|
63
|
-
config.page_size = 15
|
64
|
-
|
65
|
-
# Default permitted_params for all forms.
|
66
|
-
# End-developers probably shouldn’t change this.
|
67
39
|
config.permitted_params = %i[
|
68
40
|
_method
|
69
41
|
authenticity_token
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Tolaria
|
2
2
|
|
3
3
|
# Using this method, you can attempt to get a pretty “display”
|
4
|
-
# string for presenting the passed
|
4
|
+
# string for presenting the passed `resource` as a label.
|
5
5
|
def self.display_name(resource)
|
6
6
|
Tolaria.config.display_name_methods.each do |method_name|
|
7
7
|
if resource.respond_to?(method_name)
|
@@ -2,7 +2,7 @@ module Tolaria
|
|
2
2
|
module FormBuildable
|
3
3
|
|
4
4
|
# Returns a `p.hint` used to explain a nearby form field containing
|
5
|
-
# the given
|
5
|
+
# the given `hint_text`.
|
6
6
|
def hint(hint_text)
|
7
7
|
content_tag(:p, content_tag(:span, hint_text.chomp), class:"hint")
|
8
8
|
end
|
@@ -29,7 +29,7 @@ module Tolaria
|
|
29
29
|
|
30
30
|
# Creates a `searchable_select` that also shows a dynamic image preview of the selected record.
|
31
31
|
# Useful for previewing images or avatars chosen by name.
|
32
|
-
#
|
32
|
+
# `preview_url_method` should be a method name to call on the associated model instance
|
33
33
|
# that returns a fully-qualified URL to the image preview.
|
34
34
|
def image_association_select(method, collection, value_method, text_method, preview_url_method, options = {})
|
35
35
|
render(partial:"admin/shared/forms/image_association_select", locals: {
|
@@ -44,7 +44,7 @@ module Tolaria
|
|
44
44
|
})
|
45
45
|
end
|
46
46
|
|
47
|
-
# Renders a Markdown composer element for editing
|
47
|
+
# Renders a Markdown composer element for editing `method`,
|
48
48
|
# with fullscreen previewing and some text assistance tools.
|
49
49
|
# Requires that you set `Tolaria.config.markdown_renderer`.
|
50
50
|
# Options are forwarded to `text_area`.
|
@@ -57,7 +57,7 @@ module Tolaria
|
|
57
57
|
end
|
58
58
|
|
59
59
|
# Returns a file upload field with a more pleasant interface than browser
|
60
|
-
# file inputs. Changes messaging if the
|
60
|
+
# file inputs. Changes messaging if the `method` already exists.
|
61
61
|
# Options are forwarded to the hidden `file_field`.
|
62
62
|
def attachment_field(method, options = {})
|
63
63
|
render(partial:"admin/shared/forms/attachment_field", locals: {
|
@@ -68,7 +68,7 @@ module Tolaria
|
|
68
68
|
end
|
69
69
|
|
70
70
|
# Returns an image upload field with a more pleasant interface than browser
|
71
|
-
# file inputs. Changes messaging if the
|
71
|
+
# file inputs. Changes messaging if the `method` already exists.
|
72
72
|
#
|
73
73
|
# #### Special Options
|
74
74
|
#
|
@@ -147,10 +147,10 @@ module Tolaria
|
|
147
147
|
# You must use `f.has_many_header` inside the block to create headers.
|
148
148
|
#
|
149
149
|
# If you need to pass an ordered collection or otherwise not allow automatically
|
150
|
-
# determining the association objects from the
|
151
|
-
# pass the collection manually as
|
150
|
+
# determining the association objects from the `association` symbol you can
|
151
|
+
# pass the collection manually as `association_objects`.
|
152
152
|
#
|
153
|
-
# If
|
153
|
+
# If `allow_create` is `false` then the button to append a new model
|
154
154
|
# instance will be disabled. The default is `true`.
|
155
155
|
def has_many(association, association_objects = nil, allow_create:true, &block)
|
156
156
|
|
@@ -180,7 +180,7 @@ module Tolaria
|
|
180
180
|
end
|
181
181
|
|
182
182
|
# Creates a header suitable for use inside `has_many` for separating
|
183
|
-
# form elements. If
|
183
|
+
# form elements. If `allow_destroy` is `true`, controls will be exposed that allow
|
184
184
|
# removing nested instances of the model. The default is `false` to match Rails’.
|
185
185
|
def has_many_header(allow_destroy:false)
|
186
186
|
render(partial:"admin/shared/forms/has_many_header", locals: {
|
data/lib/tolaria/help_links.rb
CHANGED
@@ -2,6 +2,9 @@ module Tolaria
|
|
2
2
|
|
3
3
|
@help_links = []
|
4
4
|
|
5
|
+
# Reads `Tolaria.config.help_links` and constructs an internal array
|
6
|
+
# of HelpLink objects with the given options.
|
7
|
+
# Call `Tolaria.help_links` to receive the results.
|
5
8
|
def self.initialize_help_links!
|
6
9
|
@help_links = []
|
7
10
|
self.config.help_links.each do |hashy|
|
@@ -9,10 +12,12 @@ module Tolaria
|
|
9
12
|
end
|
10
13
|
end
|
11
14
|
|
15
|
+
# Returns all of Tolaria's configured Help Links.
|
12
16
|
def self.help_links
|
13
17
|
@help_links ||= []
|
14
18
|
end
|
15
19
|
|
20
|
+
# Class representing a configured Tolaria help link.
|
16
21
|
class HelpLink
|
17
22
|
|
18
23
|
# The title of the link
|
@@ -25,11 +30,11 @@ module Tolaria
|
|
25
30
|
attr_reader :link_to
|
26
31
|
|
27
32
|
# Create a new HelpLink with the passed settings.
|
28
|
-
# You must provide
|
33
|
+
# You must provide `title`, the title of the link.
|
29
34
|
# To configure automatic rendering of a Markdown file, provide
|
30
|
-
# a string
|
35
|
+
# a string `slug` and the path to a `markdown_file`.
|
31
36
|
# A route to view the file will be constructed for you at `/admin/help/:slug`.
|
32
|
-
# To link to an
|
37
|
+
# To link to an arbitrary path or URI, provide it as `link_to`.
|
33
38
|
def initialize(title:, slug:nil, markdown_file:nil, link_to:nil)
|
34
39
|
@title = title.to_s.freeze
|
35
40
|
@slug = slug.to_s.freeze
|
@@ -38,22 +43,22 @@ module Tolaria
|
|
38
43
|
validate!
|
39
44
|
end
|
40
45
|
|
41
|
-
# True if this HelpLink is a link to an
|
46
|
+
# True if this HelpLink is a link to an arbitrary path.
|
42
47
|
def link_type?
|
43
48
|
link_to.present?
|
44
49
|
end
|
45
50
|
|
46
|
-
# True if this HelpLink is a Markdown file
|
51
|
+
# True if this HelpLink is a Markdown file.
|
47
52
|
def markdown_type?
|
48
53
|
markdown_file.present?
|
49
54
|
end
|
50
55
|
|
51
|
-
# Quack like an ActiveRecord::Base model
|
56
|
+
# Quack like an ActiveRecord::Base model, returns slug.
|
52
57
|
def to_param
|
53
58
|
slug
|
54
59
|
end
|
55
60
|
|
56
|
-
# Raises RuntimeError if this HelpLink is incorrectly configured
|
61
|
+
# Raises RuntimeError if this HelpLink is incorrectly configured.
|
57
62
|
def validate!
|
58
63
|
|
59
64
|
if title.blank?
|
data/lib/tolaria/manage.rb
CHANGED
@@ -9,7 +9,7 @@ module Tolaria
|
|
9
9
|
@safe_mangagment
|
10
10
|
end
|
11
11
|
|
12
|
-
# Set the value of Tolaria.safe_management.
|
12
|
+
# Set the value of Tolaria.safe_management. `bool` should be truthy.
|
13
13
|
# Don't call this method directly.
|
14
14
|
def self.safe_management=(bool)
|
15
15
|
@safe_mangagment = !!bool
|
@@ -47,7 +47,7 @@ module Tolaria
|
|
47
47
|
|
48
48
|
end
|
49
49
|
|
50
|
-
# Discard a managed class instance for the given ActiveRecord::Base
|
50
|
+
# Discard a managed class instance for the given ActiveRecord::Base class
|
51
51
|
def self.discard_managed_class(klass)
|
52
52
|
@managed_classes.delete_if do |managed_class|
|
53
53
|
klass.to_s == managed_class.klass.to_s
|
@@ -1,7 +1,6 @@
|
|
1
|
-
# This class wraps an ActiveRecord::Base descendant
|
2
|
-
# and stores information that Tolaria needs to track about it
|
3
|
-
|
4
1
|
module Tolaria
|
2
|
+
|
3
|
+
# Wraps an ActiveRecord::Base descendant and stores information that Tolaria needs to track about it
|
5
4
|
class ManagedClass
|
6
5
|
|
7
6
|
# The ActiveRecord::Base model we’re managing
|
@@ -13,7 +12,7 @@ module Tolaria
|
|
13
12
|
# Items are sorted with lowest priority first in the menu
|
14
13
|
attr_accessor :priority
|
15
14
|
|
16
|
-
# The
|
15
|
+
# The Font Awesome icon to use for this resource
|
17
16
|
attr_accessor :icon
|
18
17
|
|
19
18
|
# An array of options to pass to `params.permit` for this model
|
@@ -29,7 +28,7 @@ module Tolaria
|
|
29
28
|
attr_accessor :controller_name
|
30
29
|
|
31
30
|
# An array of the route actions allowed on this resource.
|
32
|
-
# Tolaria will pass this array as the `
|
31
|
+
# Tolaria will pass this array as the `:only` option to the router
|
33
32
|
attr_accessor :allowed_actions
|
34
33
|
|
35
34
|
# A stored symbol for the `params.permit` key for this resource
|
@@ -87,4 +86,5 @@ module Tolaria
|
|
87
86
|
delegate :plural, to: :model_name
|
88
87
|
|
89
88
|
end
|
89
|
+
|
90
90
|
end
|
data/lib/tolaria/markdown.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Tolaria
|
2
2
|
|
3
|
-
#
|
4
|
-
# If no renderer has been configured,
|
3
|
+
# Contains a workflow for rendering Markdown.
|
4
|
+
# If no renderer has been configured, defers to `simple_format`.
|
5
5
|
class MarkdownRendererProxy
|
6
6
|
|
7
7
|
include ::ActionView::Helpers::TextHelper
|
8
8
|
|
9
9
|
# Calls the configured Markdown renderer, if none exists
|
10
|
-
# then uses simple_format to return more than nothing.
|
10
|
+
# then uses `simple_format` to return more than nothing.
|
11
11
|
def render(document)
|
12
12
|
if Tolaria.config.markdown_renderer.nil?
|
13
13
|
return simple_format(document)
|
@@ -2,12 +2,13 @@ module Tolaria
|
|
2
2
|
module RandomTokens
|
3
3
|
|
4
4
|
# Returns a 32-character random, alphanumeric string suitable for stronger
|
5
|
-
#
|
5
|
+
# token use like with cookies and API keys.
|
6
6
|
def self.auth_token
|
7
7
|
SecureRandom.base64(32).delete("+/=")[0..31]
|
8
8
|
end
|
9
9
|
|
10
|
-
# Returns a six-digit numeric code suitable for use as a one-time passphrase
|
10
|
+
# Returns a six-digit numeric code suitable for use as a one-time passphrase.
|
11
|
+
# Leading zeroes are possible, encompassing `000000`-`999999`.
|
11
12
|
def self.passcode
|
12
13
|
"%06d" % SecureRandom.random_number(1_000_000)
|
13
14
|
end
|
data/lib/tolaria/reload.rb
CHANGED
data/lib/tolaria/version.rb
CHANGED
@@ -0,0 +1,105 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CreateCardsMigration < ActiveRecord::Migration
|
4
|
+
def change
|
5
|
+
create_table :cards, force:true do |t|
|
6
|
+
t.timestamps null:false
|
7
|
+
t.string :title
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ForbiddenRoutesTest < ActionDispatch::IntegrationTest
|
13
|
+
|
14
|
+
def setup
|
15
|
+
ActiveRecord::Migration.verbose = false
|
16
|
+
CreateCardsMigration.new.exec_migration(ActiveRecord::Base.connection, :up)
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
CreateCardsMigration.new.exec_migration(ActiveRecord::Base.connection, :down)
|
21
|
+
ActiveRecord::Migration.verbose = true
|
22
|
+
end
|
23
|
+
|
24
|
+
test "handles classes with only the index action" do
|
25
|
+
|
26
|
+
class ::Card < ActiveRecord::Base
|
27
|
+
manage_with_tolaria using:{
|
28
|
+
allowed_actions: [:index]
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
# Re-draw the routes and reload Tolaria
|
33
|
+
Rails.application.routes.draw do
|
34
|
+
Tolaria.draw_routes(self)
|
35
|
+
end
|
36
|
+
|
37
|
+
sign_in_dummy_administrator!
|
38
|
+
visit admin_cards_path
|
39
|
+
assert page.has_content?("Cards")
|
40
|
+
refute page.has_content?("Create Card")
|
41
|
+
|
42
|
+
# Unseat the Card class so that it doesn't leak out of this test
|
43
|
+
assert Tolaria.discard_managed_class(Card), "should discard class"
|
44
|
+
Object.send(:remove_const, :Card)
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
test "handles classes with only the show action" do
|
49
|
+
|
50
|
+
class ::Card < ActiveRecord::Base
|
51
|
+
manage_with_tolaria using:{
|
52
|
+
allowed_actions: [:show]
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
# Re-draw the routes and reload Tolaria
|
57
|
+
Rails.application.routes.draw do
|
58
|
+
Tolaria.draw_routes(self)
|
59
|
+
end
|
60
|
+
|
61
|
+
Card.create(title:"Urza")
|
62
|
+
|
63
|
+
sign_in_dummy_administrator!
|
64
|
+
visit admin_card_path(Card.first.id)
|
65
|
+
assert page.has_content?("Urza")
|
66
|
+
refute page.has_content?("Delete")
|
67
|
+
|
68
|
+
# Unseat the Card class so that it doesn't leak out of this test
|
69
|
+
assert Tolaria.discard_managed_class(Card), "should discard class"
|
70
|
+
Object.send(:remove_const, :Card)
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
test "handles avoiding the index" do
|
75
|
+
|
76
|
+
class ::Card < ActiveRecord::Base
|
77
|
+
manage_with_tolaria using:{
|
78
|
+
allowed_actions: [:show, :update, :edit, :destroy, :create, :new]
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
# Re-draw the routes and reload Tolaria
|
83
|
+
Rails.application.routes.draw do
|
84
|
+
Tolaria.draw_routes(self)
|
85
|
+
end
|
86
|
+
|
87
|
+
Card.create(title:"Urza")
|
88
|
+
|
89
|
+
sign_in_dummy_administrator!
|
90
|
+
visit admin_card_path(Card.first.id)
|
91
|
+
assert page.has_content?("Urza")
|
92
|
+
assert page.has_content?("Delete")
|
93
|
+
assert page.has_content?("Edit")
|
94
|
+
|
95
|
+
assert_raises ActionView::Template::Error do
|
96
|
+
visit new_admin_card_path
|
97
|
+
end
|
98
|
+
|
99
|
+
# Unseat the Card class so that it doesn't leak out of this test
|
100
|
+
assert Tolaria.discard_managed_class(Card), "should discard class"
|
101
|
+
Object.send(:remove_const, :Card)
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
data/tolaria.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
|
28
28
|
s.add_development_dependency "capybara", "~> 2.4"
|
29
29
|
s.add_development_dependency "minitest", "~> 5.7"
|
30
|
-
s.add_development_dependency "
|
30
|
+
s.add_development_dependency "yard", "~> 0.6"
|
31
31
|
s.add_development_dependency "redcarpet", "~> 3"
|
32
32
|
s.add_development_dependency "sqlite3", "~> 1.3"
|
33
33
|
s.add_development_dependency "timecop", "~> 0.7"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tolaria
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Csuhta
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-06-
|
12
|
+
date: 2015-06-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bcrypt
|
@@ -124,19 +124,19 @@ dependencies:
|
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '5.7'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
127
|
+
name: yard
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
130
|
- - "~>"
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version: '
|
132
|
+
version: '0.6'
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
137
|
- - "~>"
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: '
|
139
|
+
version: '0.6'
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
141
|
name: redcarpet
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
@@ -189,6 +189,7 @@ extensions: []
|
|
189
189
|
extra_rdoc_files: []
|
190
190
|
files:
|
191
191
|
- ".gitignore"
|
192
|
+
- ".travis.yml"
|
192
193
|
- ".yardopts"
|
193
194
|
- CNAME
|
194
195
|
- CONTRIBUTING.md
|
@@ -327,10 +328,10 @@ files:
|
|
327
328
|
- lib/tolaria/categories.rb
|
328
329
|
- lib/tolaria/config.rb
|
329
330
|
- lib/tolaria/default_config.rb
|
331
|
+
- lib/tolaria/display_name.rb
|
330
332
|
- lib/tolaria/engine.rb
|
331
333
|
- lib/tolaria/form_buildable.rb
|
332
334
|
- lib/tolaria/help_links.rb
|
333
|
-
- lib/tolaria/introspection.rb
|
334
335
|
- lib/tolaria/manage.rb
|
335
336
|
- lib/tolaria/managed_class.rb
|
336
337
|
- lib/tolaria/markdown.rb
|
@@ -394,6 +395,7 @@ files:
|
|
394
395
|
- test/demo/public/422.html
|
395
396
|
- test/demo/public/500.html
|
396
397
|
- test/demo/public/favicon.ico
|
398
|
+
- test/integration/forbidden_routes_test.rb
|
397
399
|
- test/integration/help_link_test.rb
|
398
400
|
- test/integration/interface_test.rb
|
399
401
|
- test/integration/router_test.rb
|
@@ -486,6 +488,7 @@ test_files:
|
|
486
488
|
- test/demo/public/422.html
|
487
489
|
- test/demo/public/500.html
|
488
490
|
- test/demo/public/favicon.ico
|
491
|
+
- test/integration/forbidden_routes_test.rb
|
489
492
|
- test/integration/help_link_test.rb
|
490
493
|
- test/integration/interface_test.rb
|
491
494
|
- test/integration/router_test.rb
|