cm-admin 0.7.3 → 0.7.6

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.
@@ -2,12 +2,15 @@ module CmAdmin
2
2
  module ViewHelpers
3
3
  Dir[File.expand_path("view_helpers", __dir__) + "/*.rb"].each { |f| require f }
4
4
 
5
- include PageInfoHelper
6
- include NavigationHelper
7
- include FormHelper
5
+ include ActionDropdownHelper
8
6
  include FieldDisplayHelper
9
7
  include FilterHelper
8
+ include FormHelper
10
9
  include ManageColumnPopupHelper
10
+ include NavigationHelper
11
+ include PageInfoHelper
12
+
13
+ # Included Rails view helper
11
14
  include ActionView::Helpers::FormTagHelper
12
15
  include ActionView::Helpers::TagHelper
13
16
 
@@ -0,0 +1,31 @@
1
+ require 'rails/generators'
2
+
3
+ module CmAdmin
4
+ module Generators
5
+ class AddAuthenticationGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ # This generator is used to add authentication, if no auth system is present.
9
+ # Adds authentication through devise and sets up the current user.
10
+ def add_authentication
11
+ gem "devise"
12
+ generate "devise:install"
13
+ model_name = ask("What would you like the user model to be called? [user]")
14
+ generate "devise", model_name
15
+ rake "db:migrate"
16
+ copy_file 'application_controller.rb', 'app/controllers/cm_admin/application_controller.rb'
17
+ gsub_file 'app/controllers/cm_admin/application_controller.rb', 'authenticate_user', "authenticate_#{model_name}"
18
+ copy_file 'authentication.rb', 'app/controllers/concerns/authentication.rb'
19
+ gsub_file 'app/controllers/concerns/authentication.rb', 'current_user', "current_#{model_name}"
20
+ copy_file 'current.rb', 'app/models/current.rb'
21
+ inject_into_file "app/models/#{model_name.underscore}.rb", before: "end\n" do <<-'RUBY'
22
+ # Remove this once role is setup and mentioned in zcm_admin.rb
23
+ def super_admin?
24
+ true
25
+ end
26
+ RUBY
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ module CmAdmin
2
+ class ApplicationController < ActionController::Base
3
+ include Authentication
4
+ before_action :authenticate_user!
5
+ layout 'cm_admin'
6
+ helper CmAdmin::ViewHelpers
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ module Authentication
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ before_action :check_current_user
6
+ end
7
+
8
+ private
9
+ def check_current_user
10
+ if current_user
11
+ Current.user = current_user
12
+ end
13
+ end
14
+ end
@@ -1,4 +1,6 @@
1
1
  CmAdmin.configure do |config|
2
2
  # Sets the default layout to be used for admin
3
3
  config.layout = 'admin'
4
+ # config.authorized_roles = [:super_admin?]
5
+ # config.included_models = [Admin]
4
6
  end
@@ -0,0 +1,9 @@
1
+ class Current < ActiveSupport::CurrentAttributes
2
+ attribute :user, :request_id, :user_agent, :ip_address
3
+
4
+ resets { Time.zone = nil }
5
+
6
+ def user=(user)
7
+ super
8
+ end
9
+ end