activeadmin-nested-namespaces 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d62c7b0faddd0a79b3f85ef03abe7e392c2bd2b2
4
- data.tar.gz: 73a3cabea12b16f59a9b4234339f726b035164a2
3
+ metadata.gz: c71e81138b744889a06e3dc7f7c6c3e0899098f1
4
+ data.tar.gz: 9d0d3dc993d4b028d4bbaedbc64183481e0ec741
5
5
  SHA512:
6
- metadata.gz: 160f6d7298f8687b0f42663033018955c3e4dee1504a26326809b9587ef7cb527deed31b1cdd1d7ce96e87c3b64b47ae5ae271ada117392170e8ba530873622a
7
- data.tar.gz: 5b2bdfb51d0103b0a6935ec2a163da9f138d00983b112042e7b4ecc5948245e795b22cec7bd8fa0ab4d4b13d2cfea8340e4a2ff7f7bc0087231d06ab4d6a633b
6
+ metadata.gz: 80780964c5f7ed4020f16f93835b83f8f7e810a1f69d86218bc0079d8d9d23e95e5025674ce8e3428d5125a0dc548182058cd0895200f2c6ac483adba59af769
7
+ data.tar.gz: 2f0b87ae6cc970bdf2b5b04bfe11683fa37bac6221984779aaaac555b831d90a10bdf3e5bb2f17419952ec5189fd1f14cc05b5847ef1d3387fa43776eec197e4
data/README.md CHANGED
@@ -137,4 +137,4 @@ And in your routes.rb:
137
137
 
138
138
  ## License
139
139
 
140
- [MIT License](https://opensource.org/licenses/MIT)
140
+ [MIT](https://opensource.org/licenses/MIT)
@@ -54,15 +54,7 @@ ActiveAdmin.setup do |config|
54
54
  #
55
55
  # This setting changes the method which Active Admin calls
56
56
  # within the application controller.
57
- # config.authentication_method = :authenticate_admin_user!
58
-
59
- config.authentication_method = Proc.new do |name_path|
60
- if [config.default_namespace, :root].include?(name_path.first)
61
- :authenticate_admin_user!
62
- else
63
- "authenticate_#{name_path.map(&:to_s).join('_').underscore}_admin_user!".to_sym
64
- end
65
- end
57
+ config.authentication_method = :authenticate_admin_user!
66
58
 
67
59
  # == User Authorization
68
60
  #
@@ -94,13 +86,7 @@ ActiveAdmin.setup do |config|
94
86
  #
95
87
  # This setting changes the method which Active Admin calls
96
88
  # (within the application controller) to return the currently logged in user.
97
- config.current_user_method = Proc.new do |name_path|
98
- if [config.default_namespace, :root].include?(name_path.first)
99
- :current_admin_user
100
- else
101
- "current_#{name_path.map(&:to_s).join('_').underscore}_admin_user".to_sym
102
- end
103
- end
89
+ config.current_user_method = :current_admin_user
104
90
 
105
91
  # == Logging Out
106
92
  #
@@ -112,13 +98,7 @@ ActiveAdmin.setup do |config|
112
98
  # will call the method to return the path.
113
99
  #
114
100
  # Default:
115
- config.logout_link_path = Proc.new do |name_path|
116
- if [config.default_namespace, :root].include?(name_path.first)
117
- :destroy_admin_user_session_path
118
- else
119
- "destroy_#{name_path.map(&:to_s).join('_').underscore}_admin_user_session_path".to_sym
120
- end
121
- end
101
+ config.logout_link_path = :destroy_admin_user_session_path
122
102
 
123
103
  # This setting changes the http method used when rendering the
124
104
  # link. For example :get, :delete, :put, etc..
@@ -1,20 +1,5 @@
1
1
  Rails.application.routes.draw do
2
2
  devise_for :admin_users, ActiveAdmin::Devise.config
3
-
4
- namespace :site1 do
5
- devise_for :admin_users, ActiveAdmin::Devise.config
6
- end
7
-
8
- namespace :site2 do
9
- devise_for :admin_users, ActiveAdmin::Devise.config
10
- end
11
-
12
- namespace :site3 do
13
- namespace :demo do
14
- devise_for :admin_users, ActiveAdmin::Devise.config
15
- end
16
- end
17
-
18
3
  ActiveAdmin.routes(self)
19
4
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
20
5
  end
@@ -118,9 +118,7 @@ module ActiveAdmin
118
118
  end
119
119
 
120
120
  end
121
-
122
- # TODO: patch active_admin/orm/active_record/comments.rb
123
-
121
+
124
122
  ActiveAdmin::Comment.class_eval do
125
123
  def self.find_for_resource_in_namespace(resource, name)
126
124
  where(
@@ -265,6 +263,84 @@ module ActiveAdmin
265
263
  @body.add_class(active_admin_namespace.name_path.map(&:to_s).join('_') + '_namespace')
266
264
  end
267
265
  end
266
+
267
+ # patch - active_admin/orm/active_record/comments.rb
268
+ ActiveAdmin.after_load do |app|
269
+ app.namespaces.each do |namespace|
270
+
271
+ # Un-register default comment pages
272
+ namespace.resources.instance_variable_get(:@collection).delete_if {|k,v| v.instance_variable_get(:@resource_class_name) == '::ActiveAdmin::Comment' }
273
+
274
+ # Re-register comments pages with nested namespaces
275
+ namespace.register ActiveAdmin::Comment, as: namespace.comments_registration_name do
276
+ actions :index, :show, :create, :destroy
277
+
278
+ menu namespace.comments ? namespace.comments_menu : false
279
+
280
+ config.comments = false # Don't allow comments on comments
281
+ config.batch_actions = false # The default destroy batch action isn't showing up anyway...
282
+
283
+ scope :all, show_count: false
284
+ # Register a scope for every namespace that exists.
285
+ # The current namespace will be the default scope.
286
+ app.namespaces.map(&:name_path).sort { |x,y| x[0] <=> y[0] }.each do |name_path|
287
+ scope "/#{name_path.join('/')}", default: namespace.name_path == name_path do |scope|
288
+ scope.where namespace: name_path.to_s
289
+ end
290
+ end
291
+
292
+ # Store the author and namespace
293
+ before_save do |comment|
294
+ comment.namespace = active_admin_config.namespace.name_path
295
+ comment.author = current_active_admin_user
296
+ end
297
+
298
+ controller do
299
+ # Prevent N+1 queries
300
+ def scoped_collection
301
+ super.includes(:author, :resource)
302
+ end
303
+
304
+ # Redirect to the resource show page after comment creation
305
+ def create
306
+ create! do |success, failure|
307
+ success.html do
308
+ ActiveAdmin::Dependency.rails.redirect_back self, active_admin_root
309
+ end
310
+ failure.html do
311
+ flash[:error] = I18n.t 'active_admin.comments.errors.empty_text'
312
+ ActiveAdmin::Dependency.rails.redirect_back self, active_admin_root
313
+ end
314
+ end
315
+
316
+ def destroy
317
+ destroy! do |success, failure|
318
+ success.html do
319
+ ActiveAdmin::Dependency.rails.redirect_back self, active_admin_root
320
+ end
321
+ failure.html do
322
+ ActiveAdmin::Dependency.rails.redirect_back self, active_admin_root
323
+ end
324
+ end
325
+ end
326
+ end
327
+ end
328
+
329
+ permit_params :body, :namespace, :resource_id, :resource_type
330
+
331
+ index do
332
+ column I18n.t('active_admin.comments.resource_type'), :resource_type
333
+ column I18n.t('active_admin.comments.author_type'), :author_type
334
+ column I18n.t('active_admin.comments.resource'), :resource
335
+ column I18n.t('active_admin.comments.author'), :author
336
+ column I18n.t('active_admin.comments.body'), :body
337
+ column I18n.t('active_admin.comments.created_at'), :created_at
338
+ actions
339
+ end
340
+ end
341
+ end
342
+ end
343
+
268
344
  end
269
345
  end
270
346
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveAdmin
2
2
  module NestedNamespace
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin-nested-namespaces
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - osiutino