iron_admin 0.7.0 → 0.8.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.
Files changed (210) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +129 -1
  3. data/README.md +48 -1
  4. data/UPGRADING.md +495 -8
  5. data/app/assets/tailwind/iron_admin/engine.css +79 -4
  6. data/app/components/iron_admin/dashboards/activity_feed_component/item_component.html.haml +6 -9
  7. data/app/components/iron_admin/dashboards/activity_feed_component.html.haml +6 -5
  8. data/app/components/iron_admin/dashboards/activity_feed_component.rb +21 -24
  9. data/app/components/iron_admin/dashboards/chart_component.html.haml +3 -5
  10. data/app/components/iron_admin/dashboards/chart_component.rb +86 -24
  11. data/app/components/iron_admin/dashboards/concerns/themed_card.rb +39 -0
  12. data/app/components/iron_admin/dashboards/metric_card_component.html.haml +8 -7
  13. data/app/components/iron_admin/dashboards/metric_card_component.rb +2 -0
  14. data/app/components/iron_admin/dashboards/progress_component.html.haml +11 -7
  15. data/app/components/iron_admin/dashboards/progress_component.rb +11 -6
  16. data/app/components/iron_admin/dashboards/quick_links_component/link_component.html.haml +8 -9
  17. data/app/components/iron_admin/dashboards/quick_links_component.html.haml +6 -5
  18. data/app/components/iron_admin/dashboards/quick_links_component.rb +4 -12
  19. data/app/components/iron_admin/dashboards/recent_table_component.html.haml +15 -10
  20. data/app/components/iron_admin/dashboards/recent_table_component.rb +49 -0
  21. data/app/components/iron_admin/dashboards/stats_grid_component/stat_component.html.haml +13 -14
  22. data/app/components/iron_admin/dashboards/stats_grid_component.html.haml +1 -0
  23. data/app/components/iron_admin/dashboards/stats_grid_component.rb +9 -11
  24. data/app/components/iron_admin/filters/bar_component.html.haml +8 -6
  25. data/app/components/iron_admin/filters/bar_component.rb +56 -9
  26. data/app/components/iron_admin/filters/control_styles.rb +82 -0
  27. data/app/components/iron_admin/filters/date_range_component.html.haml +9 -4
  28. data/app/components/iron_admin/filters/date_range_component.rb +10 -6
  29. data/app/components/iron_admin/filters/search_component.html.haml +4 -4
  30. data/app/components/iron_admin/filters/search_component.rb +3 -5
  31. data/app/components/iron_admin/filters/select_filter_component.html.haml +1 -1
  32. data/app/components/iron_admin/filters/select_filter_component.rb +5 -16
  33. data/app/components/iron_admin/form/belongs_to_autocomplete_component.html.haml +9 -5
  34. data/app/components/iron_admin/form/belongs_to_autocomplete_component.rb +10 -8
  35. data/app/components/iron_admin/form/belongs_to_component.html.haml +2 -2
  36. data/app/components/iron_admin/form/belongs_to_component.rb +4 -18
  37. data/app/components/iron_admin/form/checkbox_component.rb +2 -3
  38. data/app/components/iron_admin/form/concerns/form_input_behavior.rb +1 -1
  39. data/app/components/iron_admin/form/control_classes.rb +108 -0
  40. data/app/components/iron_admin/form/date_picker_component.rb +3 -7
  41. data/app/components/iron_admin/form/field_wrapper_component.html.haml +3 -3
  42. data/app/components/iron_admin/form/field_wrapper_component.rb +3 -3
  43. data/app/components/iron_admin/form/nested_form_component.html.haml +4 -5
  44. data/app/components/iron_admin/form/nested_form_component.rb +12 -2
  45. data/app/components/iron_admin/form/select_component.html.haml +1 -1
  46. data/app/components/iron_admin/form/select_component.rb +2 -16
  47. data/app/components/iron_admin/form/text_input_component.rb +1 -5
  48. data/app/components/iron_admin/form/textarea_component.rb +1 -5
  49. data/app/components/iron_admin/layout/flash_component.html.haml +1 -1
  50. data/app/components/iron_admin/layout/flash_component.rb +4 -3
  51. data/app/components/iron_admin/layout/navbar_component.html.haml +15 -9
  52. data/app/components/iron_admin/layout/navbar_component.rb +29 -1
  53. data/app/components/iron_admin/layout/shell_component.html.haml +4 -4
  54. data/app/components/iron_admin/layout/shell_component.rb +16 -3
  55. data/app/components/iron_admin/layout/sidebar_component.html.haml +21 -25
  56. data/app/components/iron_admin/layout/sidebar_component.rb +76 -1
  57. data/app/components/iron_admin/layout/theme_switcher_component.html.haml +15 -0
  58. data/app/components/iron_admin/layout/theme_switcher_component.rb +74 -0
  59. data/app/components/iron_admin/resources/actions_component.html.haml +15 -8
  60. data/app/components/iron_admin/resources/actions_component.rb +34 -2
  61. data/app/components/iron_admin/resources/breadcrumb_component.html.haml +3 -3
  62. data/app/components/iron_admin/resources/breadcrumb_component.rb +8 -7
  63. data/app/components/iron_admin/resources/bulk_actions_component.html.haml +9 -8
  64. data/app/components/iron_admin/resources/bulk_actions_component.rb +47 -4
  65. data/app/components/iron_admin/resources/data_table_component.html.haml +15 -15
  66. data/app/components/iron_admin/resources/data_table_component.rb +34 -3
  67. data/app/components/iron_admin/resources/related_list_component.html.haml +7 -7
  68. data/app/components/iron_admin/resources/related_list_component.rb +26 -2
  69. data/app/components/iron_admin/resources/show_field_component.html.haml +3 -3
  70. data/app/components/iron_admin/resources/show_field_component.rb +10 -4
  71. data/app/components/iron_admin/resources/styles.rb +136 -0
  72. data/app/components/iron_admin/ui/alert_component.html.haml +2 -2
  73. data/app/components/iron_admin/ui/alert_component.rb +27 -31
  74. data/app/components/iron_admin/ui/badge_component.rb +40 -20
  75. data/app/components/iron_admin/ui/button_component.rb +37 -11
  76. data/app/components/iron_admin/ui/card_component.rb +3 -3
  77. data/app/components/iron_admin/ui/dropdown_component.html.haml +1 -1
  78. data/app/components/iron_admin/ui/dropdown_component.rb +34 -13
  79. data/app/components/iron_admin/ui/empty_state_component.html.haml +4 -5
  80. data/app/components/iron_admin/ui/empty_state_component.rb +2 -2
  81. data/app/components/iron_admin/ui/modal_component.html.haml +5 -5
  82. data/app/components/iron_admin/ui/modal_component.rb +6 -4
  83. data/app/components/iron_admin/ui/pagination_component.html.haml +14 -14
  84. data/app/components/iron_admin/ui/pagination_component.rb +26 -9
  85. data/app/components/iron_admin/ui/scopes_component.html.haml +2 -2
  86. data/app/components/iron_admin/ui/scopes_component.rb +44 -11
  87. data/app/components/iron_admin/ui/tooltip_component.rb +11 -4
  88. data/app/controllers/iron_admin/application_controller.rb +58 -4
  89. data/app/controllers/iron_admin/audit_controller.rb +30 -6
  90. data/app/controllers/iron_admin/concerns/action_executable.rb +37 -0
  91. data/app/controllers/iron_admin/concerns/assignable_references.rb +149 -0
  92. data/app/controllers/iron_admin/concerns/authorizable.rb +11 -0
  93. data/app/controllers/iron_admin/concerns/blank_password_filterable.rb +21 -0
  94. data/app/controllers/iron_admin/concerns/event_emittable.rb +47 -7
  95. data/app/controllers/iron_admin/concerns/filterable.rb +34 -9
  96. data/app/controllers/iron_admin/concerns/nested_permittable.rb +5 -3
  97. data/app/controllers/iron_admin/concerns/nested_tenant_check.rb +159 -0
  98. data/app/controllers/iron_admin/concerns/polymorphic_references.rb +131 -0
  99. data/app/controllers/iron_admin/concerns/scopeable.rb +54 -7
  100. data/app/controllers/iron_admin/concerns/searchable.rb +3 -3
  101. data/app/controllers/iron_admin/concerns/tenant_assignable.rb +118 -0
  102. data/app/controllers/iron_admin/concerns/tenant_containment.rb +146 -0
  103. data/app/controllers/iron_admin/exports_controller.rb +2 -2
  104. data/app/controllers/iron_admin/imports_controller.rb +1 -1
  105. data/app/controllers/iron_admin/resources_controller.rb +48 -41
  106. data/app/controllers/iron_admin/search_controller.rb +1 -2
  107. data/app/controllers/iron_admin/themes_controller.rb +50 -0
  108. data/app/controllers/iron_admin/tools_controller.rb +58 -5
  109. data/app/helpers/iron_admin/action_form_helper.rb +19 -0
  110. data/app/helpers/iron_admin/application_helper.rb +93 -16
  111. data/app/helpers/iron_admin/assignable_records_helper.rb +32 -0
  112. data/app/helpers/iron_admin/component_overrides_helper.rb +9 -4
  113. data/app/helpers/iron_admin/field_display_helper.rb +88 -43
  114. data/app/helpers/iron_admin/related_records_helper.rb +51 -0
  115. data/app/helpers/iron_admin/theme_helper.rb +56 -46
  116. data/app/javascript/iron_admin/controllers/cp_bulk_select_controller.js +12 -0
  117. data/app/javascript/iron_admin/controllers/cp_chart_controller.js +4 -0
  118. data/app/javascript/iron_admin/controllers/cp_disclosure_controller.js +19 -0
  119. data/app/javascript/iron_admin/controllers/cp_search_shortcut_controller.js +39 -0
  120. data/app/javascript/iron_admin/index.js +4 -0
  121. data/app/views/iron_admin/audit/index.html.haml +78 -81
  122. data/app/views/iron_admin/dashboard/index.html.haml +10 -9
  123. data/app/views/iron_admin/form/_action_field.html.haml +50 -0
  124. data/app/views/iron_admin/form/_nested_row.html.haml +18 -13
  125. data/app/views/iron_admin/imports/new.html.haml +14 -13
  126. data/app/views/iron_admin/imports/preview.html.haml +24 -21
  127. data/app/views/iron_admin/resources/_form.html.haml +70 -68
  128. data/app/views/iron_admin/resources/action_form.html.haml +16 -59
  129. data/app/views/iron_admin/resources/bulk_action_form.html.haml +20 -58
  130. data/app/views/iron_admin/resources/edit.html.haml +3 -3
  131. data/app/views/iron_admin/resources/index.html.haml +87 -74
  132. data/app/views/iron_admin/resources/new.html.haml +2 -2
  133. data/app/views/iron_admin/resources/show.html.haml +53 -41
  134. data/app/views/iron_admin/search/index.html.haml +17 -9
  135. data/app/views/iron_admin/shared/_pagination.html.haml +13 -10
  136. data/app/views/iron_admin/shared/error.html.haml +16 -12
  137. data/app/views/iron_admin/tools/action_form.html.haml +9 -55
  138. data/app/views/iron_admin/tools/show.html.haml +4 -5
  139. data/app/views/layouts/iron_admin/_document_head.html.haml +24 -0
  140. data/app/views/layouts/iron_admin/application.html.haml +4 -17
  141. data/app/views/layouts/iron_admin/minimal.html.haml +7 -0
  142. data/config/importmap.rb +2 -0
  143. data/config/locales/en.yml +23 -0
  144. data/config/routes.rb +1 -0
  145. data/docs/FAQ.md +87 -37
  146. data/docs/README.md +8 -2
  147. data/docs/components/README.md +6 -2
  148. data/docs/components/dashboard-components.md +24 -35
  149. data/docs/components/filter-components.md +44 -92
  150. data/docs/components/form-components.md +16 -32
  151. data/docs/components/resource-components.md +46 -27
  152. data/docs/components/ui-components.md +44 -26
  153. data/docs/getting-started/installation.md +5 -1
  154. data/docs/getting-started/quick-start.md +36 -23
  155. data/docs/guides/authentication.md +182 -42
  156. data/docs/guides/components.md +97 -15
  157. data/docs/guides/custom-adapters.md +24 -4
  158. data/docs/guides/dashboard.md +68 -44
  159. data/docs/guides/export.md +24 -8
  160. data/docs/guides/extending.md +206 -51
  161. data/docs/guides/fields.md +229 -70
  162. data/docs/guides/imports.md +33 -18
  163. data/docs/guides/resources.md +333 -111
  164. data/docs/guides/theming.md +930 -58
  165. data/docs/guides/troubleshooting.md +7 -3
  166. data/docs/plugin-system-design.md +8 -7
  167. data/docs/reference/configuration.md +51 -16
  168. data/docs/reference/routes.md +1 -0
  169. data/docs/reference/theme-properties.md +101 -38
  170. data/lib/generators/iron_admin/install/templates/initializer.rb.tt +7 -2
  171. data/lib/generators/iron_admin/install_audit/templates/create_iron_admin_audit_entries.rb.tt +2 -0
  172. data/lib/iron_admin/action_field.rb +11 -0
  173. data/lib/iron_admin/adapters/active_record.rb +95 -0
  174. data/lib/iron_admin/adapters/base.rb +107 -0
  175. data/lib/iron_admin/adapters/http/query.rb +21 -0
  176. data/lib/iron_admin/adapters/http.rb +84 -4
  177. data/lib/iron_admin/adapters/mongoid.rb +96 -2
  178. data/lib/iron_admin/audit_log.rb +64 -6
  179. data/lib/iron_admin/authentication_warning.rb +31 -0
  180. data/lib/iron_admin/concerns/filter_definable.rb +15 -1
  181. data/lib/iron_admin/concerns/nestable.rb +25 -0
  182. data/lib/iron_admin/concerns/scope_countable.rb +56 -0
  183. data/lib/iron_admin/concerns/soft_deletable.rb +28 -9
  184. data/lib/iron_admin/configuration/components.rb +14 -3
  185. data/lib/iron_admin/configuration/theme/neutral_defaults.rb +179 -0
  186. data/lib/iron_admin/configuration/theme.rb +292 -87
  187. data/lib/iron_admin/configuration.rb +340 -45
  188. data/lib/iron_admin/dashboard.rb +22 -38
  189. data/lib/iron_admin/engine.rb +16 -2
  190. data/lib/iron_admin/errors.rb +3 -0
  191. data/lib/iron_admin/field.rb +78 -17
  192. data/lib/iron_admin/field_inferrer.rb +61 -3
  193. data/lib/iron_admin/field_override_warning.rb +67 -0
  194. data/lib/iron_admin/import/import_preview.rb +56 -7
  195. data/lib/iron_admin/import/importer.rb +91 -14
  196. data/lib/iron_admin/import/tenant_precheck.rb +67 -0
  197. data/lib/iron_admin/plugin/registration.rb +64 -0
  198. data/lib/iron_admin/plugin_registry.rb +3 -2
  199. data/lib/iron_admin/policy.rb +22 -12
  200. data/lib/iron_admin/policy_coverage_warning.rb +46 -0
  201. data/lib/iron_admin/request_context.rb +18 -0
  202. data/lib/iron_admin/resource.rb +218 -77
  203. data/lib/iron_admin/resource_registry.rb +86 -13
  204. data/lib/iron_admin/scope_counts.rb +73 -0
  205. data/lib/iron_admin/tenant_scope.rb +30 -0
  206. data/lib/iron_admin/tool.rb +61 -12
  207. data/lib/iron_admin/tool_context.rb +10 -6
  208. data/lib/iron_admin/version.rb +1 -1
  209. data/lib/iron_admin.rb +29 -2
  210. metadata +37 -7
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IronAdmin
4
+ # Counts the records each scope tab of an index would list.
5
+ #
6
+ # The caller builds the relation for one scope (tenant scope, current
7
+ # filters, that scope, current search; no selected scope and no page).
8
+ # This object asks the adapter's {Adapters::Base#exact_count} for each
9
+ # scope. A +nil+ count is unknown and is left out of the hash; zero is
10
+ # kept. A count that raises is logged and left out too, so one scope
11
+ # cannot take down the index. On PostgreSQL that rescue does not protect
12
+ # the request: a failing count inside an open transaction, including a
13
+ # transactional test, aborts the transaction, and a later query on the
14
+ # page raises +PG::InFailedSqlTransaction+. With the feature off, no
15
+ # relation is built and the adapter is not asked.
16
+ class ScopeCounts
17
+ # @param resource [IronAdmin::Resource]
18
+ # @param adapter [IronAdmin::Adapters::Base]
19
+ # @param relation_for [#call] builds the relation for a scope body
20
+ def initialize(resource:, adapter:, relation_for:)
21
+ @resource = resource
22
+ @adapter = adapter
23
+ @relation_for = relation_for
24
+ end
25
+
26
+ # @return [Hash{String => Integer}] counts keyed by scope name
27
+ def to_h
28
+ return {} unless @resource.scope_counts_enabled?
29
+
30
+ @resource.all_scopes.each_with_object({}) do |definition, counts|
31
+ next if definition[:count] == false
32
+
33
+ value = count_scope(definition)
34
+ counts[definition[:name].to_s] = value unless value.nil?
35
+ end
36
+ end
37
+
38
+ # Tab label. A missing count draws the name alone; zero draws zero.
39
+ #
40
+ # @param scope [Hash] a scope definition, with +:name+
41
+ # @param counts [Hash, nil] counts keyed by scope name, String or Symbol
42
+ # @return [String]
43
+ def self.label(scope, counts)
44
+ lookup = (counts || {}).to_h.transform_keys(&:to_s)
45
+ name = scope[:name].to_s.humanize
46
+ count = lookup[scope[:name].to_s]
47
+ count.nil? ? name : "#{name} (#{count})"
48
+ end
49
+
50
+ private
51
+
52
+ # A scope whose body or count fails draws no number. The other tabs still count.
53
+ # A body that returns nil or false is the ActiveRecord idiom for "add
54
+ # nothing"; it is not a relation, and counting it would count every record.
55
+ def count_scope(definition)
56
+ relation = @relation_for.call(definition[:scope])
57
+ return if relation.nil? || relation == false
58
+
59
+ @adapter.exact_count(relation)
60
+ rescue StandardError, NotImplementedError => e
61
+ log_count_error(e)
62
+ nil
63
+ end
64
+
65
+ # Same shape as ApplicationController#log_iron_admin_error.
66
+ def log_count_error(error)
67
+ message = "[IronAdmin] #{error.class}: #{error.message}"
68
+ backtrace = Rails.backtrace_cleaner.clean(Array(error.backtrace)).first(10)
69
+ message = "#{message}\n#{backtrace.join("\n")}" if backtrace.any?
70
+ Rails.logger.error(message)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IronAdmin
4
+ # Single entry point for the configured tenant scope.
5
+ #
6
+ # Reads and records built from a scope both go through {.apply}, so a
7
+ # multi-tenant application cannot skip the filter on one surface.
8
+ module TenantScope
9
+ module_function
10
+
11
+ # Returns +relation+ scoped to the current tenant.
12
+ #
13
+ # When no tenant scope is configured, +relation+ is returned unchanged.
14
+ #
15
+ # @param relation [Object] Query relation or scope to filter
16
+ # @return [Object] The block's relation, or +relation+ itself
17
+ def apply(relation)
18
+ return relation unless configured?
19
+
20
+ IronAdmin.configuration.tenant_scope_block.call(relation)
21
+ end
22
+
23
+ # Whether {IronAdmin::Configuration#tenant_scope} was configured.
24
+ #
25
+ # @return [Boolean]
26
+ def configured?
27
+ !IronAdmin.configuration.tenant_scope_block.nil?
28
+ end
29
+ end
30
+ end
@@ -6,27 +6,44 @@ module IronAdmin
6
6
  # Tools are standalone pages that don't map to a database model.
7
7
  # External gems can subclass Tool to add custom admin functionality.
8
8
  #
9
+ # Declare every action with {.tool_action}. A tool that declares one or more
10
+ # actions, including actions inherited from a parent tool, dispatches only
11
+ # those names: a POST to any other name returns 404 and does not call the
12
+ # method, even when the tool defines that method. Helpers that are not
13
+ # actions should be private.
14
+ #
15
+ # A tool that declares no actions, and inherits none, still dispatches its
16
+ # own public methods.
17
+ # That fallback is deprecated and removed in 1.0. Each dispatch warns once
18
+ # per tool class and method through {IronAdmin.deprecator}. Set
19
+ # +config.strict_tool_actions+ to turn the fallback off for every tool.
20
+ #
9
21
  # @example Simple tool with declarative actions
10
- # class CacheManagerTool < IronAdmin::Tool
11
- # menu icon: "server", label: "Cache Manager", group: "System"
22
+ # module IronAdmin
23
+ # module Tools
24
+ # class CacheManagerTool < IronAdmin::Tool
25
+ # menu icon: "server", label: "Cache Manager", group: "System"
12
26
  #
13
- # tool_action :clear_all, icon: "trash", confirm: true
14
- # tool_action :flush_key,
15
- # form_fields: [{ name: :cache_key, type: :text, required: true }]
27
+ # tool_action :clear_all, icon: "trash", confirm: true
28
+ # tool_action :flush_key,
29
+ # form_fields: [{ name: :cache_key, type: :text, required: true }]
16
30
  #
17
- # def clear_all(ctx)
18
- # Rails.cache.clear
19
- # ctx.flash[:notice] = "Cache cleared!"
20
- # end
31
+ # def clear_all(ctx)
32
+ # Rails.cache.clear
33
+ # ctx.flash[:notice] = "Cache cleared!"
34
+ # end
21
35
  #
22
- # def flush_key(ctx)
23
- # key = ctx.action_params(:cache_key)[:cache_key]
24
- # Rails.cache.delete(key)
36
+ # def flush_key(ctx)
37
+ # key = ctx.action_params(:cache_key)[:cache_key]
38
+ # Rails.cache.delete(key)
39
+ # end
40
+ # end
25
41
  # end
26
42
  # end
27
43
  class Tool
28
44
  class_attribute :menu_options, default: {}
29
45
  class_attribute :defined_tool_actions, default: []
46
+ class_attribute :access_condition, default: nil
30
47
 
31
48
  # @return [ToolContext, nil] Request context, set by ToolsController before action execution
32
49
  attr_accessor :context
@@ -58,6 +75,38 @@ module IronAdmin
58
75
  self.defined_tool_actions = defined_tool_actions + [ToolAction.new(name: name, **)]
59
76
  end
60
77
 
78
+ # Restricts who may open this tool and run its actions.
79
+ #
80
+ # The condition receives the current user. A truthy value allows; +nil+
81
+ # and +false+ deny with 403. It guards the tool page, every action and
82
+ # action form, and the legacy dispatch of undeclared methods, and the
83
+ # sidebar hides the tool from users it denies. An action's own
84
+ # +condition:+ still applies on top of it. Subclasses inherit it.
85
+ # Without it, {Configuration#default_policy} decides.
86
+ #
87
+ # @param condition [#call, nil] a callable that takes the user
88
+ # @yieldparam user [Object, nil] the current user, when given a block
89
+ # @raise [ArgumentError] when neither a callable nor a block is given
90
+ # @return [void]
91
+ # @example
92
+ # tool_access ->(user) { user&.admin? }
93
+ def tool_access(condition = nil, &block)
94
+ condition ||= block
95
+ raise ArgumentError, "tool_access needs a callable or a block" unless condition.respond_to?(:call)
96
+
97
+ self.access_condition = condition
98
+ end
99
+
100
+ # Whether +user+ may open this tool and run its actions.
101
+ #
102
+ # @param user [Object, nil]
103
+ # @return [Boolean]
104
+ def accessible_by?(user)
105
+ return IronAdmin.configuration.default_allow? if access_condition.nil?
106
+
107
+ access_condition.call(user) ? true : false
108
+ end
109
+
61
110
  # Finds a declared tool action by name.
62
111
  #
63
112
  # @param name [Symbol, String] Action name
@@ -7,13 +7,17 @@ module IronAdmin
7
7
  # without coupling them to the controller.
8
8
  #
9
9
  # @example Accessing context in a tool action
10
- # class ReportTool < IronAdmin::Tool
11
- # tool_action :generate
10
+ # module IronAdmin
11
+ # module Tools
12
+ # class ReportTool < IronAdmin::Tool
13
+ # tool_action :generate
12
14
  #
13
- # def generate(ctx)
14
- # user = ctx.current_user
15
- # format = ctx.action_params(:format)[:format]
16
- # ctx.flash[:notice] = "Report generated for #{user.name}"
15
+ # def generate(ctx)
16
+ # user = ctx.current_user
17
+ # format = ctx.action_params(:format)[:format]
18
+ # ctx.flash[:notice] = "Report generated for #{user.name}"
19
+ # end
20
+ # end
17
21
  # end
18
22
  # end
19
23
  class ToolContext
@@ -3,5 +3,5 @@
3
3
  module IronAdmin
4
4
  # The current version of the IronAdmin gem.
5
5
  # @return [String]
6
- VERSION = "0.7.0"
6
+ VERSION = "0.8.0"
7
7
  end
data/lib/iron_admin.rb CHANGED
@@ -2,7 +2,10 @@
2
2
 
3
3
  require "iron_admin/version"
4
4
  require "iron_admin/errors"
5
+ require "iron_admin/authentication_warning"
5
6
  require "iron_admin/configuration"
7
+ require "iron_admin/tenant_scope"
8
+ require "iron_admin/request_context"
6
9
  require "iron_admin/live/poll_cache"
7
10
  require "iron_admin/live/broadcaster"
8
11
  require "iron_admin/live"
@@ -23,16 +26,20 @@ require "iron_admin/concerns/importable"
23
26
  require "iron_admin/concerns/live_updatable"
24
27
  require "iron_admin/concerns/component_overridable"
25
28
  require "iron_admin/concerns/filter_definable"
29
+ require "iron_admin/concerns/scope_countable"
30
+ require "iron_admin/scope_counts"
26
31
  require "iron_admin/filters/base_query_builder"
27
32
  require "iron_admin/filters/active_record_query_builder"
28
33
  require "iron_admin/filters/query_builder"
29
34
  require "iron_admin/resource"
30
35
  require "iron_admin/resource_registry"
36
+ require "iron_admin/field_override_warning"
31
37
  require "iron_admin/tool"
32
38
  require "iron_admin/tool_context"
33
39
  require "iron_admin/tool_action"
34
40
  require "iron_admin/tool_registry"
35
41
  require "iron_admin/policy"
42
+ require "iron_admin/policy_coverage_warning"
36
43
  require "iron_admin/dashboard"
37
44
  require "iron_admin/import/parser/csv"
38
45
  require "iron_admin/import/parser/json"
@@ -40,6 +47,7 @@ require "iron_admin/import/column_mapper"
40
47
  require "iron_admin/import/type_caster"
41
48
  require "iron_admin/import/import_preview"
42
49
  require "iron_admin/import/import_result"
50
+ require "iron_admin/import/tenant_precheck"
43
51
  require "iron_admin/import/importer"
44
52
  require "iron_admin/audit_log"
45
53
  require "iron_admin/menu_item"
@@ -98,7 +106,7 @@ require "iron_admin/engine"
98
106
  #
99
107
  # IronAdmin.configure do |config|
100
108
  # config.title = "My Admin"
101
- # config.authenticate { |c| c.redirect_to "/login" unless c.current_user }
109
+ # config.authenticate { |c| c.redirect_to "/login" unless c.session[:user_id] }
102
110
  # end
103
111
  #
104
112
  # @see IronAdmin::Resource
@@ -109,6 +117,16 @@ module IronAdmin
109
117
  # @return [Class, nil] The dashboard class for the application
110
118
  attr_accessor :dashboard_class
111
119
 
120
+ # Deprecation reporter for IronAdmin.
121
+ #
122
+ # Registered on +Rails.application.deprecators+ as +:iron_admin+, so
123
+ # +config.active_support.deprecation+ silences it or makes it raise.
124
+ #
125
+ # @return [ActiveSupport::Deprecation]
126
+ def deprecator
127
+ @deprecator ||= ActiveSupport::Deprecation.new("1.0", "IronAdmin")
128
+ end
129
+
112
130
  # Returns the global configuration instance.
113
131
  #
114
132
  # @return [IronAdmin::Configuration] The configuration object
@@ -155,9 +173,18 @@ module IronAdmin
155
173
  def reset_configuration!
156
174
  @configuration = Configuration.new
157
175
  @dashboard_class = nil
176
+ RequestContext.reset
158
177
  Live.reset! if defined?(Live)
159
178
  end
160
179
 
180
+ # The theme of the current request, resolved by {Configuration#resolve_theme}
181
+ # before authentication; the default theme outside a request.
182
+ #
183
+ # @return [IronAdmin::Configuration::Theme]
184
+ def current_theme
185
+ RequestContext.theme || configuration.theme_for(configuration.default_theme)
186
+ end
187
+
161
188
  def register_field_type(type_name, &)
162
189
  FieldTypeRegistry.register(type_name, &)
163
190
  end
@@ -167,7 +194,7 @@ module IronAdmin
167
194
  # Call this from a host initializer (config/initializers/iron_admin.rb)
168
195
  # after +require+-ing the plugin gem. The plugin's setup block runs
169
196
  # immediately, wiring its extensions (menu items, component overrides,
170
- # field types, ...) into the current install.
197
+ # field types, themes, ...) into the current install.
171
198
  #
172
199
  # @note EXPERIMENTAL — unstable until 1.0. The plugin API is not covered by
173
200
  # the zero-breaking-changes invariant and may change before GA.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - RubyLab
@@ -209,14 +209,14 @@ dependencies:
209
209
  requirements:
210
210
  - - "~>"
211
211
  - !ruby/object:Gem::Version
212
- version: '7.0'
212
+ version: '8.0'
213
213
  type: :development
214
214
  prerelease: false
215
215
  version_requirements: !ruby/object:Gem::Requirement
216
216
  requirements:
217
217
  - - "~>"
218
218
  - !ruby/object:Gem::Version
219
- version: '7.0'
219
+ version: '8.0'
220
220
  - !ruby/object:Gem::Dependency
221
221
  name: rubocop
222
222
  requirement: !ruby/object:Gem::Requirement
@@ -279,14 +279,14 @@ dependencies:
279
279
  requirements:
280
280
  - - "~>"
281
281
  - !ruby/object:Gem::Version
282
- version: '0.22'
282
+ version: '1.3'
283
283
  type: :development
284
284
  prerelease: false
285
285
  version_requirements: !ruby/object:Gem::Requirement
286
286
  requirements:
287
287
  - - "~>"
288
288
  - !ruby/object:Gem::Version
289
- version: '0.22'
289
+ version: '1.3'
290
290
  - !ruby/object:Gem::Dependency
291
291
  name: simplecov-console
292
292
  requirement: !ruby/object:Gem::Requirement
@@ -361,6 +361,7 @@ files:
361
361
  - app/components/iron_admin/dashboards/activity_feed_component/item_component.html.haml
362
362
  - app/components/iron_admin/dashboards/chart_component.html.haml
363
363
  - app/components/iron_admin/dashboards/chart_component.rb
364
+ - app/components/iron_admin/dashboards/concerns/themed_card.rb
364
365
  - app/components/iron_admin/dashboards/metric_card_component.html.haml
365
366
  - app/components/iron_admin/dashboards/metric_card_component.rb
366
367
  - app/components/iron_admin/dashboards/progress_component.html.haml
@@ -375,6 +376,7 @@ files:
375
376
  - app/components/iron_admin/dashboards/stats_grid_component/stat_component.html.haml
376
377
  - app/components/iron_admin/filters/bar_component.html.haml
377
378
  - app/components/iron_admin/filters/bar_component.rb
379
+ - app/components/iron_admin/filters/control_styles.rb
378
380
  - app/components/iron_admin/filters/date_range_component.html.haml
379
381
  - app/components/iron_admin/filters/date_range_component.rb
380
382
  - app/components/iron_admin/filters/search_component.html.haml
@@ -388,6 +390,7 @@ files:
388
390
  - app/components/iron_admin/form/checkbox_component.html.haml
389
391
  - app/components/iron_admin/form/checkbox_component.rb
390
392
  - app/components/iron_admin/form/concerns/form_input_behavior.rb
393
+ - app/components/iron_admin/form/control_classes.rb
391
394
  - app/components/iron_admin/form/date_picker_component.rb
392
395
  - app/components/iron_admin/form/field_wrapper_component.html.haml
393
396
  - app/components/iron_admin/form/field_wrapper_component.rb
@@ -405,6 +408,8 @@ files:
405
408
  - app/components/iron_admin/layout/shell_component.rb
406
409
  - app/components/iron_admin/layout/sidebar_component.html.haml
407
410
  - app/components/iron_admin/layout/sidebar_component.rb
411
+ - app/components/iron_admin/layout/theme_switcher_component.html.haml
412
+ - app/components/iron_admin/layout/theme_switcher_component.rb
408
413
  - app/components/iron_admin/resources/actions_component.html.haml
409
414
  - app/components/iron_admin/resources/actions_component.rb
410
415
  - app/components/iron_admin/resources/breadcrumb_component.html.haml
@@ -417,6 +422,7 @@ files:
417
422
  - app/components/iron_admin/resources/related_list_component.rb
418
423
  - app/components/iron_admin/resources/show_field_component.html.haml
419
424
  - app/components/iron_admin/resources/show_field_component.rb
425
+ - app/components/iron_admin/resources/styles.rb
420
426
  - app/components/iron_admin/ui/alert_component.html.haml
421
427
  - app/components/iron_admin/ui/alert_component.rb
422
428
  - app/components/iron_admin/ui/badge_component.rb
@@ -438,32 +444,44 @@ files:
438
444
  - app/controllers/iron_admin/application_controller.rb
439
445
  - app/controllers/iron_admin/audit_controller.rb
440
446
  - app/controllers/iron_admin/concerns/action_executable.rb
447
+ - app/controllers/iron_admin/concerns/assignable_references.rb
441
448
  - app/controllers/iron_admin/concerns/authorizable.rb
449
+ - app/controllers/iron_admin/concerns/blank_password_filterable.rb
442
450
  - app/controllers/iron_admin/concerns/event_emittable.rb
443
451
  - app/controllers/iron_admin/concerns/filterable.rb
444
452
  - app/controllers/iron_admin/concerns/index_returnable.rb
445
453
  - app/controllers/iron_admin/concerns/index_state_preservable.rb
446
454
  - app/controllers/iron_admin/concerns/json_params_coercion.rb
447
455
  - app/controllers/iron_admin/concerns/nested_permittable.rb
456
+ - app/controllers/iron_admin/concerns/nested_tenant_check.rb
457
+ - app/controllers/iron_admin/concerns/polymorphic_references.rb
448
458
  - app/controllers/iron_admin/concerns/scopeable.rb
449
459
  - app/controllers/iron_admin/concerns/searchable.rb
460
+ - app/controllers/iron_admin/concerns/tenant_assignable.rb
461
+ - app/controllers/iron_admin/concerns/tenant_containment.rb
450
462
  - app/controllers/iron_admin/dashboard_controller.rb
451
463
  - app/controllers/iron_admin/exports_controller.rb
452
464
  - app/controllers/iron_admin/imports_controller.rb
453
465
  - app/controllers/iron_admin/live_controller.rb
454
466
  - app/controllers/iron_admin/resources_controller.rb
455
467
  - app/controllers/iron_admin/search_controller.rb
468
+ - app/controllers/iron_admin/themes_controller.rb
456
469
  - app/controllers/iron_admin/tools_controller.rb
470
+ - app/helpers/iron_admin/action_form_helper.rb
457
471
  - app/helpers/iron_admin/application_helper.rb
472
+ - app/helpers/iron_admin/assignable_records_helper.rb
458
473
  - app/helpers/iron_admin/component_overrides_helper.rb
459
474
  - app/helpers/iron_admin/field_display_helper.rb
475
+ - app/helpers/iron_admin/related_records_helper.rb
460
476
  - app/helpers/iron_admin/theme_helper.rb
461
477
  - app/javascript/iron_admin/controllers/cp_alert_controller.js
462
478
  - app/javascript/iron_admin/controllers/cp_bulk_select_controller.js
463
479
  - app/javascript/iron_admin/controllers/cp_chart_controller.js
464
480
  - app/javascript/iron_admin/controllers/cp_color_field_controller.js
481
+ - app/javascript/iron_admin/controllers/cp_disclosure_controller.js
465
482
  - app/javascript/iron_admin/controllers/cp_modal_controller.js
466
483
  - app/javascript/iron_admin/controllers/cp_nested_form_controller.js
484
+ - app/javascript/iron_admin/controllers/cp_search_shortcut_controller.js
467
485
  - app/javascript/iron_admin/controllers/cp_sidebar_controller.js
468
486
  - app/javascript/iron_admin/controllers/filter_operator_controller.js
469
487
  - app/javascript/iron_admin/index.js
@@ -471,6 +489,7 @@ files:
471
489
  - app/views/iron_admin/audit/index.html.haml
472
490
  - app/views/iron_admin/dashboard/index.html.haml
473
491
  - app/views/iron_admin/fields/_custom_input.html.haml
492
+ - app/views/iron_admin/form/_action_field.html.haml
474
493
  - app/views/iron_admin/form/_nested_row.html.haml
475
494
  - app/views/iron_admin/imports/new.html.haml
476
495
  - app/views/iron_admin/imports/preview.html.haml
@@ -486,7 +505,9 @@ files:
486
505
  - app/views/iron_admin/shared/error.html.haml
487
506
  - app/views/iron_admin/tools/action_form.html.haml
488
507
  - app/views/iron_admin/tools/show.html.haml
508
+ - app/views/layouts/iron_admin/_document_head.html.haml
489
509
  - app/views/layouts/iron_admin/application.html.haml
510
+ - app/views/layouts/iron_admin/minimal.html.haml
490
511
  - config/importmap.rb
491
512
  - config/locales/en.yml
492
513
  - config/routes.rb
@@ -539,20 +560,24 @@ files:
539
560
  - lib/iron_admin/adapters/mongoid/column_descriptor.rb
540
561
  - lib/iron_admin/adapters/registry.rb
541
562
  - lib/iron_admin/audit_log.rb
563
+ - lib/iron_admin/authentication_warning.rb
542
564
  - lib/iron_admin/concerns/component_overridable.rb
543
565
  - lib/iron_admin/concerns/filter_definable.rb
544
566
  - lib/iron_admin/concerns/importable.rb
545
567
  - lib/iron_admin/concerns/live_updatable.rb
546
568
  - lib/iron_admin/concerns/nestable.rb
569
+ - lib/iron_admin/concerns/scope_countable.rb
547
570
  - lib/iron_admin/concerns/soft_deletable.rb
548
571
  - lib/iron_admin/configuration.rb
549
572
  - lib/iron_admin/configuration/components.rb
550
573
  - lib/iron_admin/configuration/theme.rb
574
+ - lib/iron_admin/configuration/theme/neutral_defaults.rb
551
575
  - lib/iron_admin/dashboard.rb
552
576
  - lib/iron_admin/engine.rb
553
577
  - lib/iron_admin/errors.rb
554
578
  - lib/iron_admin/field.rb
555
579
  - lib/iron_admin/field_inferrer.rb
580
+ - lib/iron_admin/field_override_warning.rb
556
581
  - lib/iron_admin/field_type_config.rb
557
582
  - lib/iron_admin/field_type_registry.rb
558
583
  - lib/iron_admin/filters/active_record_query_builder.rb
@@ -566,6 +591,7 @@ files:
566
591
  - lib/iron_admin/import/importer.rb
567
592
  - lib/iron_admin/import/parser/csv.rb
568
593
  - lib/iron_admin/import/parser/json.rb
594
+ - lib/iron_admin/import/tenant_precheck.rb
569
595
  - lib/iron_admin/import/type_caster.rb
570
596
  - lib/iron_admin/live.rb
571
597
  - lib/iron_admin/live/broadcaster.rb
@@ -578,8 +604,12 @@ files:
578
604
  - lib/iron_admin/plugin/registration.rb
579
605
  - lib/iron_admin/plugin_registry.rb
580
606
  - lib/iron_admin/policy.rb
607
+ - lib/iron_admin/policy_coverage_warning.rb
608
+ - lib/iron_admin/request_context.rb
581
609
  - lib/iron_admin/resource.rb
582
610
  - lib/iron_admin/resource_registry.rb
611
+ - lib/iron_admin/scope_counts.rb
612
+ - lib/iron_admin/tenant_scope.rb
583
613
  - lib/iron_admin/tool.rb
584
614
  - lib/iron_admin/tool_action.rb
585
615
  - lib/iron_admin/tool_context.rb
@@ -591,8 +621,8 @@ licenses:
591
621
  - MIT
592
622
  metadata:
593
623
  homepage_uri: https://github.com/rubylab-app/iron_admin
594
- source_code_uri: https://github.com/rubylab-app/iron_admin/tree/v0.7.0
595
- changelog_uri: https://github.com/rubylab-app/iron_admin/blob/v0.7.0/CHANGELOG.md
624
+ source_code_uri: https://github.com/rubylab-app/iron_admin/tree/v0.8.0
625
+ changelog_uri: https://github.com/rubylab-app/iron_admin/blob/v0.8.0/CHANGELOG.md
596
626
  documentation_uri: https://rubylab-app.github.io/iron_admin/
597
627
  bug_tracker_uri: https://github.com/rubylab-app/iron_admin/issues
598
628
  rubygems_mfa_required: 'true'