administrate 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of administrate might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/app/assets/stylesheets/administrate/components/_cells.scss +2 -6
- data/app/assets/stylesheets/docs.scss +1 -0
- data/app/controllers/administrate/application_controller.rb +35 -3
- data/app/controllers/concerns/administrate/punditize.rb +36 -0
- data/app/helpers/administrate/application_helper.rb +9 -4
- data/app/views/administrate/application/_collection.html.erb +9 -7
- data/app/views/administrate/application/_form.html.erb +5 -2
- data/app/views/administrate/application/_navigation.html.erb +1 -1
- data/app/views/administrate/application/edit.html.erb +3 -3
- data/app/views/administrate/application/index.html.erb +5 -2
- data/app/views/administrate/application/new.html.erb +6 -1
- data/app/views/administrate/application/show.html.erb +3 -3
- data/app/views/fields/has_many/_index.html.erb +1 -1
- data/app/views/fields/polymorphic/_form.html.erb +11 -6
- data/app/views/fields/polymorphic/_show.html.erb +8 -4
- data/config/locales/administrate.ar.yml +6 -6
- data/config/locales/administrate.bs.yml +27 -0
- data/config/locales/administrate.ca.yml +28 -0
- data/config/locales/administrate.da.yml +6 -6
- data/config/locales/administrate.de.yml +8 -8
- data/config/locales/administrate.en.yml +6 -6
- data/config/locales/administrate.es.yml +6 -6
- data/config/locales/administrate.fr.yml +6 -6
- data/config/locales/administrate.it.yml +6 -6
- data/config/locales/administrate.ja.yml +6 -6
- data/config/locales/administrate.ko.yml +6 -6
- data/config/locales/administrate.nl.yml +6 -6
- data/config/locales/administrate.pl.yml +6 -6
- data/config/locales/administrate.pt-BR.yml +6 -6
- data/config/locales/administrate.pt.yml +6 -6
- data/config/locales/administrate.ru.yml +6 -6
- data/config/locales/administrate.sv.yml +6 -6
- data/config/locales/administrate.uk.yml +6 -6
- data/config/locales/administrate.vi.yml +6 -6
- data/config/locales/administrate.zh-CN.yml +6 -6
- data/config/locales/administrate.zh-TW.yml +6 -6
- data/docs/authorization.md +69 -0
- data/docs/customizing_attribute_partials.md +20 -1
- data/docs/customizing_dashboards.md +54 -0
- data/docs/getting_started.md +82 -1
- data/lib/administrate/field/associative.rb +4 -0
- data/lib/administrate/field/base.rb +1 -1
- data/lib/administrate/field/belongs_to.rb +4 -3
- data/lib/administrate/field/date_time.rb +13 -2
- data/lib/administrate/field/deferred.rb +6 -5
- data/lib/administrate/field/has_many.rb +2 -2
- data/lib/administrate/field/has_one.rb +16 -8
- data/lib/administrate/field/polymorphic.rb +41 -3
- data/lib/administrate/order.rb +38 -5
- data/lib/administrate/resource_resolver.rb +2 -2
- data/lib/administrate/search.rb +1 -1
- data/lib/administrate/version.rb +1 -1
- data/lib/generators/administrate/dashboard/USAGE +1 -1
- data/lib/generators/administrate/dashboard/dashboard_generator.rb +7 -1
- data/lib/generators/administrate/dashboard/templates/controller.rb.erb +2 -2
- data/lib/generators/administrate/install/install_generator.rb +13 -6
- data/lib/generators/administrate/install/templates/{application_controller.rb → application_controller.rb.erb} +1 -1
- data/lib/generators/administrate/routes/routes_generator.rb +5 -0
- data/lib/generators/administrate/routes/templates/routes.rb.erb +1 -1
- data/lib/generators/administrate/views/field_generator.rb +19 -5
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 200650aa4703202324342f17c6e1bce7642309664b28149e3aa5763d708af7cf
|
4
|
+
data.tar.gz: 2b49177bd91bc20d1c5ffcb15fb33497339163e5058e24c39d82ef7fba6bdae9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56aa3cfb03420e71ee5ce158e3ce2d98b04a2038d8322b84dcddf4ebca67e27c599806d58d61d8f7c2d39f1bec4a723ac47f2157e73ae54df0e7249e6d37a9fd
|
7
|
+
data.tar.gz: 6856dcf40b1cabea4b46e580f1379e07a79fca813040c39ae7e5018e1fb2a0c55e62ed4940872f5a28b983f762a276808b47d3954593660fd81a170f01ddf749
|
@@ -1,6 +1,4 @@
|
|
1
1
|
.cell-label {
|
2
|
-
position: relative;
|
3
|
-
|
4
2
|
&:hover {
|
5
3
|
a {
|
6
4
|
color: $action-color;
|
@@ -26,10 +24,8 @@
|
|
26
24
|
}
|
27
25
|
|
28
26
|
.cell-label__sort-indicator {
|
29
|
-
|
30
|
-
|
31
|
-
position: absolute;
|
32
|
-
right: 0;
|
27
|
+
float: right;
|
28
|
+
margin-left: 5px;
|
33
29
|
|
34
30
|
svg {
|
35
31
|
fill: $hint-grey;
|
@@ -27,8 +27,10 @@ module Administrate
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def new
|
30
|
+
resource = resource_class.new
|
31
|
+
authorize_resource(resource)
|
30
32
|
render locals: {
|
31
|
-
page: Administrate::Page::Form.new(dashboard,
|
33
|
+
page: Administrate::Page::Form.new(dashboard, resource),
|
32
34
|
}
|
33
35
|
end
|
34
36
|
|
@@ -40,6 +42,7 @@ module Administrate
|
|
40
42
|
|
41
43
|
def create
|
42
44
|
resource = resource_class.new(resource_params)
|
45
|
+
authorize_resource(resource)
|
43
46
|
|
44
47
|
if resource.save
|
45
48
|
redirect_to(
|
@@ -103,7 +106,9 @@ module Administrate
|
|
103
106
|
end
|
104
107
|
|
105
108
|
def requested_resource
|
106
|
-
@_requested_resource ||= find_resource(params[:id])
|
109
|
+
@_requested_resource ||= find_resource(params[:id]).tap do |resource|
|
110
|
+
authorize_resource(resource)
|
111
|
+
end
|
107
112
|
end
|
108
113
|
|
109
114
|
def find_resource(param)
|
@@ -120,7 +125,20 @@ module Administrate
|
|
120
125
|
|
121
126
|
def resource_params
|
122
127
|
params.require(resource_class.model_name.param_key).
|
123
|
-
permit(dashboard.permitted_attributes)
|
128
|
+
permit(dashboard.permitted_attributes).
|
129
|
+
transform_values { |v| read_param_value(v) }
|
130
|
+
end
|
131
|
+
|
132
|
+
def read_param_value(data)
|
133
|
+
if data.is_a?(ActionController::Parameters) && data[:type]
|
134
|
+
if data[:type] == Administrate::Field::Polymorphic.to_s
|
135
|
+
GlobalID::Locator.locate(data[:value])
|
136
|
+
else
|
137
|
+
raise "Unrecognised param data: #{data.inspect}"
|
138
|
+
end
|
139
|
+
else
|
140
|
+
data
|
141
|
+
end
|
124
142
|
end
|
125
143
|
|
126
144
|
delegate :dashboard_class, :resource_class, :resource_name, :namespace,
|
@@ -145,5 +163,19 @@ module Administrate
|
|
145
163
|
dashboard.collection_attributes
|
146
164
|
).any? { |_name, attribute| attribute.searchable? }
|
147
165
|
end
|
166
|
+
|
167
|
+
def show_action?(action, resource)
|
168
|
+
true
|
169
|
+
end
|
170
|
+
helper_method :show_action?
|
171
|
+
|
172
|
+
def new_resource
|
173
|
+
resource_class.new
|
174
|
+
end
|
175
|
+
helper_method :new_resource
|
176
|
+
|
177
|
+
def authorize_resource(resource)
|
178
|
+
resource
|
179
|
+
end
|
148
180
|
end
|
149
181
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
if Object.const_defined?("Pundit")
|
2
|
+
module Administrate
|
3
|
+
module Punditize
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Pundit
|
6
|
+
|
7
|
+
included do
|
8
|
+
def scoped_resource
|
9
|
+
policy_scope_admin super
|
10
|
+
end
|
11
|
+
|
12
|
+
def authorize_resource(resource)
|
13
|
+
authorize resource
|
14
|
+
end
|
15
|
+
|
16
|
+
def show_action?(action, resource)
|
17
|
+
Pundit.policy!(pundit_user, resource).send("#{action}?".to_sym)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
# Like the policy_scope method in stock Pundit, but allows the 'resolve'
|
24
|
+
# to be overridden by 'resolve_admin' for a different index scope in Admin
|
25
|
+
# controllers.
|
26
|
+
def policy_scope_admin(scope)
|
27
|
+
ps = Pundit::PolicyFinder.new(scope).scope!.new(pundit_user, scope)
|
28
|
+
if ps.respond_to? :resolve_admin
|
29
|
+
ps.resolve_admin
|
30
|
+
else
|
31
|
+
ps.resolve
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -7,11 +7,12 @@ module Administrate
|
|
7
7
|
render locals: locals, partial: field.to_partial_path
|
8
8
|
end
|
9
9
|
|
10
|
+
def class_from_resource(resource_name)
|
11
|
+
resource_name.to_s.classify.constantize
|
12
|
+
end
|
13
|
+
|
10
14
|
def display_resource_name(resource_name)
|
11
|
-
resource_name.
|
12
|
-
to_s.
|
13
|
-
classify.
|
14
|
-
constantize.
|
15
|
+
class_from_resource(resource_name).
|
15
16
|
model_name.
|
16
17
|
human(
|
17
18
|
count: PLURAL_MANY_COUNT,
|
@@ -27,6 +28,10 @@ module Administrate
|
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
31
|
+
def resource_index_route_key(resource_name)
|
32
|
+
ActiveModel::Naming.route_key(class_from_resource(resource_name))
|
33
|
+
end
|
34
|
+
|
30
35
|
def sanitized_order_params
|
31
36
|
params.permit(:search, :id, :order, :page, :per_page, :direction, :orders)
|
32
37
|
end
|
@@ -63,11 +63,13 @@ to display a collection of resources in an HTML table.
|
|
63
63
|
>
|
64
64
|
<% collection_presenter.attributes_for(resource).each do |attribute| %>
|
65
65
|
<td class="cell-data cell-data--<%= attribute.html_class %>">
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
66
|
+
<% if show_action? :show, resource -%>
|
67
|
+
<a href="<%= polymorphic_path([namespace, resource]) -%>"
|
68
|
+
class="action-show"
|
69
|
+
>
|
70
|
+
<%= render_field attribute %>
|
71
|
+
</a>
|
72
|
+
<% end -%>
|
71
73
|
</td>
|
72
74
|
<% end %>
|
73
75
|
|
@@ -76,7 +78,7 @@ to display a collection of resources in an HTML table.
|
|
76
78
|
t("administrate.actions.edit"),
|
77
79
|
[:edit, namespace, resource],
|
78
80
|
class: "action-edit",
|
79
|
-
) %></td>
|
81
|
+
) if show_action? :edit, resource%></td>
|
80
82
|
<% end %>
|
81
83
|
|
82
84
|
<% if valid_action? :destroy, collection_presenter.resource_name %>
|
@@ -86,7 +88,7 @@ to display a collection of resources in an HTML table.
|
|
86
88
|
class: "text-color-red",
|
87
89
|
method: :delete,
|
88
90
|
data: { confirm: t("administrate.actions.confirm") }
|
89
|
-
) %></td>
|
91
|
+
) if show_action? :destroy, resource %></td>
|
90
92
|
<% end %>
|
91
93
|
</tr>
|
92
94
|
<% end %>
|
@@ -18,8 +18,11 @@ and renders all form fields for a resource's editable attributes.
|
|
18
18
|
<% if page.resource.errors.any? %>
|
19
19
|
<div id="error_explanation">
|
20
20
|
<h2>
|
21
|
-
<%=
|
22
|
-
|
21
|
+
<%= t(
|
22
|
+
"administrate.form.errors",
|
23
|
+
pluralized_errors: pluralize(page.resource.errors.count, t("administrate.form.error")),
|
24
|
+
resource_name: display_resource_name(page.resource_name)
|
25
|
+
) %>
|
23
26
|
</h2>
|
24
27
|
|
25
28
|
<ul>
|
@@ -11,7 +11,7 @@ as defined by the routes in the `admin/` namespace
|
|
11
11
|
<% Administrate::Namespace.new(namespace).resources.each do |resource| %>
|
12
12
|
<%= link_to(
|
13
13
|
display_resource_name(resource),
|
14
|
-
[namespace, resource
|
14
|
+
[namespace, resource_index_route_key(resource)],
|
15
15
|
class: "navigation__link navigation__link--#{nav_link_state(resource)}"
|
16
16
|
) %>
|
17
17
|
<% end %>
|
@@ -15,7 +15,7 @@ It displays a header, and renders the `_form` partial to do the heavy lifting.
|
|
15
15
|
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
|
16
16
|
%>
|
17
17
|
|
18
|
-
<% content_for(:title) {
|
18
|
+
<% content_for(:title) { t("administrate.actions.edit_resource", name: page.page_title) } %>
|
19
19
|
|
20
20
|
<header class="main-content__header" role="banner">
|
21
21
|
<h1 class="main-content__page-title">
|
@@ -24,10 +24,10 @@ It displays a header, and renders the `_form` partial to do the heavy lifting.
|
|
24
24
|
|
25
25
|
<div>
|
26
26
|
<%= link_to(
|
27
|
-
|
27
|
+
t("administrate.actions.show_resource", name: page.page_title),
|
28
28
|
[namespace, page.resource],
|
29
29
|
class: "button",
|
30
|
-
) if valid_action? :show %>
|
30
|
+
) if valid_action?(:show) && show_action?(:show, page.resource) %>
|
31
31
|
</div>
|
32
32
|
</header>
|
33
33
|
|
@@ -42,10 +42,13 @@ It renders the `_table` partial to display details about the resources.
|
|
42
42
|
|
43
43
|
<div>
|
44
44
|
<%= link_to(
|
45
|
-
|
45
|
+
t(
|
46
|
+
"administrate.actions.new_resource",
|
47
|
+
name: page.resource_name.titleize.downcase
|
48
|
+
),
|
46
49
|
[:new, namespace, page.resource_path],
|
47
50
|
class: "button",
|
48
|
-
) if valid_action? :new %>
|
51
|
+
) if valid_action?(:new) && show_action?(:new, new_resource) %>
|
49
52
|
</div>
|
50
53
|
</header>
|
51
54
|
|
@@ -15,7 +15,12 @@ to do the heavy lifting.
|
|
15
15
|
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
|
16
16
|
%>
|
17
17
|
|
18
|
-
<% content_for(:title)
|
18
|
+
<% content_for(:title) do %>
|
19
|
+
<%= t(
|
20
|
+
"administrate.actions.new_resource",
|
21
|
+
name: display_resource_name(page.resource_name).titleize
|
22
|
+
) %>
|
23
|
+
<% end %>
|
19
24
|
|
20
25
|
<header class="main-content__header" role="banner">
|
21
26
|
<h1 class="main-content__page-title">
|
@@ -16,7 +16,7 @@ as well as a link to its edit page.
|
|
16
16
|
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Show
|
17
17
|
%>
|
18
18
|
|
19
|
-
<% content_for(:title) {
|
19
|
+
<% content_for(:title) { t("administrate.actions.show_resource", name: page.page_title) } %>
|
20
20
|
|
21
21
|
<header class="main-content__header" role="banner">
|
22
22
|
<h1 class="main-content__page-title">
|
@@ -25,10 +25,10 @@ as well as a link to its edit page.
|
|
25
25
|
|
26
26
|
<div>
|
27
27
|
<%= link_to(
|
28
|
-
|
28
|
+
t("administrate.actions.edit_resource", name: page.page_title),
|
29
29
|
[:edit, namespace, page.resource],
|
30
30
|
class: "button",
|
31
|
-
) if valid_action? :edit %>
|
31
|
+
) if valid_action?(:edit) && show_action?(:edit, page.resource) %>
|
32
32
|
</div>
|
33
33
|
</header>
|
34
34
|
|
@@ -16,4 +16,4 @@ as a count of how many objects are associated through the relationship.
|
|
16
16
|
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasMany
|
17
17
|
%>
|
18
18
|
|
19
|
-
<%= pluralize(field.data.size, field.attribute.to_s.humanize.downcase) %>
|
19
|
+
<%= pluralize(field.data.size, field.attribute.to_s.humanize.downcase.singularize) %>
|
@@ -18,10 +18,15 @@ so this partial renders a message to that effect.
|
|
18
18
|
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Polymorphic
|
19
19
|
%>
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
<%= f.fields_for field.attribute do |pf| %>
|
22
|
+
<div class="field-unit__label">
|
23
|
+
<%= pf.label :value, field.name.humanize %>
|
24
|
+
</div>
|
24
25
|
|
25
|
-
<div class="field-unit__field">
|
26
|
-
|
27
|
-
|
26
|
+
<div class="field-unit__field">
|
27
|
+
<%= pf.hidden_field(:type, value: field.class.name) %>
|
28
|
+
<%= pf.select(:value) do %>
|
29
|
+
<%= grouped_options_for_select(field.associated_resource_grouped_options, field.selected_global_id, prompt: true) %>
|
30
|
+
<% end %>
|
31
|
+
</div>
|
32
|
+
<% end %>
|
@@ -17,8 +17,12 @@ By default, the relationship is rendered as a link to the associated object.
|
|
17
17
|
%>
|
18
18
|
|
19
19
|
<% if field.data %>
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
<% if valid_action?(:show, field.attribute) %>
|
21
|
+
<%= link_to(
|
22
|
+
field.display_associated_resource,
|
23
|
+
[namespace, field.data],
|
24
|
+
) %>
|
25
|
+
<% else %>
|
26
|
+
<%= field.display_associated_resource %>
|
27
|
+
<% end %>
|
24
28
|
<% end %>
|
@@ -5,8 +5,9 @@ ar:
|
|
5
5
|
confirm: "هل أنت متأكد ؟"
|
6
6
|
destroy: "حذف"
|
7
7
|
edit: "تعديل"
|
8
|
-
|
9
|
-
|
8
|
+
edit_resource: "تعديل %{name}"
|
9
|
+
show_resource: "إظهار %{name}"
|
10
|
+
new_resource: "جديد %{name}"
|
10
11
|
back: "الى الخلف"
|
11
12
|
controller:
|
12
13
|
create:
|
@@ -19,10 +20,9 @@ ar:
|
|
19
20
|
has_many:
|
20
21
|
more: إظهار %{count} من %{total_count}
|
21
22
|
none: "لا يوجد"
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
not_supported: "غير مدعمه \"HasOne\" هذه العلاقه"
|
23
|
+
form:
|
24
|
+
error: error
|
25
|
+
errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
|
26
26
|
search:
|
27
27
|
clear: مسح البحث
|
28
28
|
label: بحث %{resource}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
bs:
|
2
|
+
administrate:
|
3
|
+
actions:
|
4
|
+
confirm: Jeste li sigurni?
|
5
|
+
destroy: Izbrisati
|
6
|
+
edit: Izmjena
|
7
|
+
edit_resource: Izmjena %{name}
|
8
|
+
show_resource: Pregled %{name}
|
9
|
+
new_resource: Novi %{name}
|
10
|
+
back: Nazad
|
11
|
+
controller:
|
12
|
+
create:
|
13
|
+
success: "%{resource} je uspješno kreiran."
|
14
|
+
destroy:
|
15
|
+
success: "%{resource} je uspješno izbrisan."
|
16
|
+
update:
|
17
|
+
success: "%{resource} je uspješno izmijenjen."
|
18
|
+
fields:
|
19
|
+
has_many:
|
20
|
+
more: Prikazuje %{count} od %{total_count}
|
21
|
+
none: Niko
|
22
|
+
form:
|
23
|
+
error: error
|
24
|
+
errors: "%{pluralized_errors} prohibited this %{resource_name} from being saved:"
|
25
|
+
search:
|
26
|
+
clear: Izbriši pretraživanje
|
27
|
+
label: Pretraga %{resource}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
---
|
2
|
+
ca:
|
3
|
+
administrate:
|
4
|
+
actions:
|
5
|
+
confirm: Estàs segur?
|
6
|
+
destroy: Destruir
|
7
|
+
edit: Editar
|
8
|
+
edit_resource: Edita %{name}
|
9
|
+
show_resource: Mostra %{name}
|
10
|
+
new_resource: Nou %{name}
|
11
|
+
back: Tornar
|
12
|
+
controller:
|
13
|
+
create:
|
14
|
+
success: "%{resource} s'ha creat amb èxit."
|
15
|
+
destroy:
|
16
|
+
success: "%{resource} s'ha destruït amb èxit."
|
17
|
+
update:
|
18
|
+
success: "%{resource} s'ha actualitzat amb èxit."
|
19
|
+
fields:
|
20
|
+
has_many:
|
21
|
+
more: Mostrant %{count} de %{total_count}
|
22
|
+
none: Cap
|
23
|
+
form:
|
24
|
+
error: error
|
25
|
+
errors: "%{pluralized_errors} han impedit que %{resource_name} es guardés amb èxit:"
|
26
|
+
search:
|
27
|
+
clear: Esborrar la cerca
|
28
|
+
label: Cerca %{resource}
|