cm-admin 0.7.4 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ module CmAdmin
2
+ module ViewHelpers
3
+ module ActionDropdownHelper
4
+ def available_actions(cm_model, action_type)
5
+ if action_type.eql?('custom_actions')
6
+ cm_model.available_actions.select {
7
+ |act| act if act.route_type.eql?('member') &&
8
+ [:button, :modal].include?(act.display_type) &&
9
+ act.name.present? &&
10
+ has_valid_policy(cm_model.name, act.name)
11
+ }
12
+ else
13
+ cm_model.available_actions.select {
14
+ |act| act if act.action_type.eql?(:default) &&
15
+ act.name.eql?(action_type)
16
+ } if has_valid_policy(cm_model.name, action_type)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,7 +1,6 @@
1
1
  module CmAdmin
2
2
  module ViewHelpers
3
3
  module FieldDisplayHelper
4
-
5
4
  def show_field(ar_object, field)
6
5
  content_tag(:div, class: "info-split") do
7
6
  concat show_field_label(ar_object, field)
@@ -33,7 +32,8 @@ module CmAdmin
33
32
  when :string
34
33
  ar_object.send(field.field_name).to_s
35
34
  when :datetime
36
- ar_object.send(field.field_name).strftime(field.format || "%d/%m/%Y").to_s if ar_object.send(field.field_name)
35
+ self.extend LocalTimeHelper
36
+ local_time(ar_object.send(field.field_name).strftime(field.format || "%d/%m/%Y").to_s) if ar_object.send(field.field_name)
37
37
  when :text
38
38
  ar_object.send(field.field_name)
39
39
  when :custom
@@ -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