hancock_cms 2.0.0 → 2.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -3
- data/app/assets/stylesheets/hancock/cms/devise.sass +32 -21
- data/app/assets/stylesheets/hancock/rails_admin/cms.theming.sass +3 -3
- data/app/controllers/concerns/hancock/current_user.rb +1 -1
- data/app/controllers/concerns/hancock/errors.rb +2 -1
- data/app/models/concerns/hancock/cacheable.rb +2 -1
- data/{config/initializers → app/models/concerns/hancock}/embedded_findable.rb +2 -2
- data/app/views/layouts/rails_admin/_footer_navigation.html.slim +1 -1
- data/app/views/layouts/rails_admin/application.html.haml +1 -1
- data/hancock_cms.gemspec +1 -1
- data/lib/generators/hancock/cms/setup_generator.rb +344 -0
- data/lib/generators/hancock/cms/templates/assets/javascripts/application.coffee.erb +1 -1
- data/lib/generators/hancock/cms/templates/assets/stylesheets/hancock/rails_admin/custom/theming.sass.erb +0 -0
- data/lib/generators/hancock/cms/templates/hancock_cms.erb +2 -0
- data/lib/hancock/admin/embedded_element.rb +3 -0
- data/lib/hancock/configuration.rb +4 -0
- data/lib/hancock/engine.rb +32 -28
- data/lib/hancock/model.rb +7 -5
- data/lib/hancock/models/mongoid/embedded_element.rb +3 -1
- data/lib/hancock/rails_admin_ext/config.rb +15 -11
- data/lib/hancock/version.rb +1 -1
- data/template.rb +17 -356
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aac27be322e86dbe06cbb665f135b45bcbaa2f26
|
4
|
+
data.tar.gz: 32d116ff67f3e7e565eeeb3c2cc2b1f6e4d2bfbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7385fdec75273456f88842cae88d01435053caee1c479155790e9469ff551908fd4a1e8c1191faa28bfc7deed0985f70ef2e3598f9f9e26aaaa6953e6d069b7
|
7
|
+
data.tar.gz: d418df9900372477a720aeae8c4d10fcf913939b0464b1cd792ef06e89b43277b33f9e2f6d00da04f48ecb868407744215f3f3cba5e2ac3a32f6ad137e4c2472
|
data/README.md
CHANGED
@@ -52,13 +52,17 @@ If not, uninstall rails and install again
|
|
52
52
|
|
53
53
|
Then, for mongoid:
|
54
54
|
|
55
|
-
rails new my_app -T -O -m https://raw.githubusercontent.com/red-rocks/hancock_cms/rails5/template.rb
|
55
|
+
rails new my_app -B -T -O -m https://raw.githubusercontent.com/red-rocks/hancock_cms/rails5/template.rb
|
56
|
+
cd my_app
|
57
|
+
rails g hancock:cms:setup
|
56
58
|
|
57
59
|
for ActiveRecord:
|
58
60
|
|
59
|
-
rails new my_app -T --database=postgresql -m https://raw.githubusercontent.com/red-rocks/hancock_cms/rails5/template.rb
|
61
|
+
rails new my_app -B -T --database=postgresql -m https://raw.githubusercontent.com/red-rocks/hancock_cms/rails5/template.rb
|
62
|
+
cd my_app
|
63
|
+
rails g hancock:cms:setup
|
60
64
|
|
61
|
-
generator creates a new RVM gemset,
|
65
|
+
generator creates a new RVM gemset, runs `bundle install` and setup some files (assets, config/initializers/*, routes, etc).
|
62
66
|
|
63
67
|
### Localization
|
64
68
|
|
@@ -8,7 +8,8 @@
|
|
8
8
|
overflow: auto
|
9
9
|
white-space: nowrap
|
10
10
|
text-align: center
|
11
|
-
|
11
|
+
font-family: "Verdana", SansSerif
|
12
|
+
font-weight: normal
|
12
13
|
&:before
|
13
14
|
height: 100%
|
14
15
|
display: inline-block
|
@@ -21,9 +22,7 @@
|
|
21
22
|
vertical-align: middle
|
22
23
|
text-align: left
|
23
24
|
background: #fff
|
24
|
-
|
25
|
-
-moz-box-shadow: 0 8px 17px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19)
|
26
|
-
box-shadow: 0 8px 17px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19)
|
25
|
+
+box-shadow(0 8px 17px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19))
|
27
26
|
min-width: 400px
|
28
27
|
|
29
28
|
.white-box
|
@@ -62,36 +61,30 @@
|
|
62
61
|
.form-control
|
63
62
|
background-image: linear-gradient(#9675ce, #9675ce), linear-gradient(rgba(120, 130, 140, 0.13), rgba(120, 130, 140, 0.13))
|
64
63
|
border: 0 none
|
65
|
-
border-radius
|
66
|
-
box-shadow
|
64
|
+
+border-radius(0)
|
65
|
+
+box-shadow(none)
|
67
66
|
background-color: rgba(0, 0, 0, 0)
|
68
67
|
background-position: center bottom, center calc(99%)
|
69
68
|
background-repeat: no-repeat
|
70
69
|
background-size: 0 2px, 100% 1px
|
71
70
|
background-color: #ffffff
|
72
|
-
box-shadow: none
|
73
71
|
color: #565656
|
74
72
|
height: 38px
|
75
73
|
width: 100%
|
76
74
|
padding: 7px 12px
|
77
|
-
transition
|
75
|
+
+transition(all 300ms linear 0s)
|
78
76
|
display: block
|
79
77
|
font-size: 14px
|
80
78
|
line-height: 1.42857143
|
81
|
-
|
82
|
-
-o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s
|
83
|
-
transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s
|
79
|
+
+transition(border-color ease-in-out .15s,box-shadow ease-in-out .15s)
|
84
80
|
input
|
85
81
|
width: 100%
|
86
|
-
height: 100%
|
87
82
|
|
88
83
|
.link-to-recover
|
89
84
|
float: right
|
90
85
|
padding-right: 10px
|
91
86
|
a
|
92
|
-
|
93
|
-
-o-transition: color ease-in-out .15s
|
94
|
-
transition: color ease-in-out .15s
|
87
|
+
+transition(color ease-in-out .15s)
|
95
88
|
color: #333C44
|
96
89
|
&:hover
|
97
90
|
color: #EF5350
|
@@ -123,9 +116,7 @@
|
|
123
116
|
cursor: pointer
|
124
117
|
max-width: 100%
|
125
118
|
color: #333C44
|
126
|
-
|
127
|
-
-o-transition: color ease-in-out .15s
|
128
|
-
transition: color ease-in-out .15s
|
119
|
+
+transition(color ease-in-out .15s)
|
129
120
|
&:hover
|
130
121
|
label
|
131
122
|
color: #EF5350
|
@@ -145,9 +136,7 @@
|
|
145
136
|
padding: 10px 16px
|
146
137
|
font-size: 18px
|
147
138
|
line-height: 1.3333333
|
148
|
-
|
149
|
-
-o-transition: all ease-in-out .15s
|
150
|
-
transition: all ease-in-out .15s
|
139
|
+
+transition(all ease-in-out .15s)
|
151
140
|
&:hover
|
152
141
|
background: rgba(#ee5350, 0.8)
|
153
142
|
border: 1px solid rgba(#ee5350, 0.8)
|
@@ -155,3 +144,25 @@
|
|
155
144
|
|
156
145
|
.form-group.links
|
157
146
|
margin-top: 25px
|
147
|
+
|
148
|
+
.devise-box .white-box form .form-group .form-control
|
149
|
+
padding: 0
|
150
|
+
input
|
151
|
+
position: relative
|
152
|
+
margin: 0
|
153
|
+
border: 0px
|
154
|
+
border-bottom: 1px solid #ccc
|
155
|
+
+transition(all 0.3s)
|
156
|
+
&:focus
|
157
|
+
border-bottom: 1px solid #3c6085
|
158
|
+
|
159
|
+
.devise-box .white-box form .form-group .checkbox-primary
|
160
|
+
min-height: auto
|
161
|
+
|
162
|
+
.devise-box .white-box form .form-group .checkbox-primary label
|
163
|
+
padding-left: 0px
|
164
|
+
input
|
165
|
+
margin: 0px
|
166
|
+
margin-right: 5px
|
167
|
+
display: inline-block
|
168
|
+
vertical-align: middle
|
@@ -608,7 +608,7 @@ a
|
|
608
608
|
td
|
609
609
|
position: relative
|
610
610
|
vertical-align: middle
|
611
|
-
text-align:
|
611
|
+
text-align: left
|
612
612
|
padding: 3px 4px 3px 4px
|
613
613
|
td.other.right, td.last.links
|
614
614
|
padding: 6px 10px 6px 0px
|
@@ -699,5 +699,5 @@ body.rails_admin .form-horizontal .tab-content .tab-pane
|
|
699
699
|
+box-shadow(inset 0 1px 1px rgba(0, 0, 0, 0.075))
|
700
700
|
+transform(border-color ease-in-out 0.15s box-shadow ease-in-out 0.15s)
|
701
701
|
|
702
|
-
body.rails_admin .table
|
703
|
-
max-width: 120px
|
702
|
+
body.rails_admin .table
|
703
|
+
max-width: 120px
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Hancock::Errors
|
2
2
|
extend ActiveSupport::Concern
|
3
|
+
|
3
4
|
included do
|
4
5
|
if Rails.env.production? || Rails.env.staging? || (respond_to?(:hancock_check_errors) and hancock_check_errors)
|
5
6
|
rescue_from Exception, with: :render_500
|
@@ -90,5 +91,5 @@ module Hancock::Errors
|
|
90
91
|
def render_error(code = 500)
|
91
92
|
render template: "hancock/errors/error_#{code}", formats: [:html], handlers: [:slim], layout: Hancock.config.error_layout, status: code
|
92
93
|
end
|
93
|
-
|
94
|
+
|
94
95
|
end
|
@@ -11,12 +11,13 @@ if Hancock.mongoid?
|
|
11
11
|
def default_cache_keys
|
12
12
|
self.class.default_cache_keys
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def cache_keys
|
16
16
|
cache_keys_str.split(/\s+/).map { |k| k.strip }.reject { |k| k.blank? }
|
17
17
|
end
|
18
18
|
field :perform_caching, type: Boolean, default: true
|
19
19
|
|
20
|
+
after_touch :clear_cache
|
20
21
|
after_save :clear_cache
|
21
22
|
after_destroy :clear_cache
|
22
23
|
def clear_cache
|
@@ -1,10 +1,10 @@
|
|
1
1
|
if defined?(Mongoid)
|
2
2
|
|
3
|
-
module
|
3
|
+
module Hancock
|
4
4
|
|
5
5
|
# Helps to override find method in an embedded document.
|
6
6
|
# Usage :
|
7
|
-
# - add to your model "include
|
7
|
+
# - add to your model "include Hancock::EmbeddedFindable"
|
8
8
|
# - override find method with:
|
9
9
|
# def self.find(id)
|
10
10
|
# find_through(Book, 'chapter', id)
|
@@ -13,7 +13,7 @@
|
|
13
13
|
RailsAdmin.I18n.init('#{I18n.locale}', JSON.parse("#{j I18n.t("admin.js").to_json}"))
|
14
14
|
|
15
15
|
%body.rails_admin
|
16
|
-
|
16
|
+
#loading.label.label-warning{style: 'display:none; position:fixed; right:20px; bottom:20px; z-index:100000'}= t('admin.loading')
|
17
17
|
%nav.admin-navbar.admin-navbar-fixed.bg-red{:role => "navigation"}
|
18
18
|
= render "layouts/rails_admin/navigation"
|
19
19
|
|
data/hancock_cms.gemspec
CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_dependency 'rails_admin_nested_set'
|
37
37
|
spec.add_dependency 'rails_admin_toggleable'
|
38
38
|
|
39
|
-
spec.add_dependency 'ack_rails_admin_settings'
|
39
|
+
spec.add_dependency 'ack_rails_admin_settings', '~> 1.2'
|
40
40
|
|
41
41
|
spec.add_dependency 'kaminari'
|
42
42
|
|
@@ -0,0 +1,344 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
# require "rails/generators/rails/app/app_generator"
|
3
|
+
|
4
|
+
module Hancock::Cms
|
5
|
+
class SetupGenerator < Rails::Generators::Base
|
6
|
+
|
7
|
+
desc 'Hancock CMS Carcass generator'
|
8
|
+
def install
|
9
|
+
|
10
|
+
####### DEVISE #######
|
11
|
+
|
12
|
+
generate "devise:install"
|
13
|
+
gsub_file 'config/initializers/devise.rb', "'please-change-me-at-config-initializers-devise@example.com'", "'noreply@#{app_name.dasherize.downcase}.ru'"
|
14
|
+
inject_into_file 'config/initializers/devise.rb', after: /^end/ do <<-TEXT
|
15
|
+
|
16
|
+
Rails.application.config.to_prepare do
|
17
|
+
Devise::SessionsController.layout "hancock/devise/sessions"
|
18
|
+
Devise::RegistrationsController.layout "hancock/devise/registrations"
|
19
|
+
Devise::ConfirmationsController.layout "hancock/devise/confirmations"
|
20
|
+
Devise::UnlocksController.layout "hancock/devise/unlocks"
|
21
|
+
Devise::PasswordsController.layout "hancock/devise/passwords"
|
22
|
+
end
|
23
|
+
TEXT
|
24
|
+
end
|
25
|
+
|
26
|
+
generate "devise", "User"
|
27
|
+
|
28
|
+
|
29
|
+
####### ROUTES #######
|
30
|
+
|
31
|
+
remove_file 'config/routes.rb'
|
32
|
+
create_file 'config/routes.rb' do <<-TEXT
|
33
|
+
Rails.application.routes.draw do
|
34
|
+
devise_for :users, controllers: {sessions: 'hancock/sessions'}
|
35
|
+
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
|
36
|
+
hancock_cms_routes
|
37
|
+
end
|
38
|
+
TEXT
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
####### INITIALIZERS #######
|
43
|
+
|
44
|
+
inject_into_file 'config/initializers/assets.rb', before: /\z/ do <<-TEXT
|
45
|
+
Rails.application.config.assets.precompile += %w( *.svg )
|
46
|
+
Rails.application.config.assets.precompile += %w( ckeditor/* )
|
47
|
+
Rails.application.config.assets.precompile += %w( codemirror.js codemirror.css codemirror/**/* )
|
48
|
+
TEXT
|
49
|
+
end
|
50
|
+
|
51
|
+
gsub_file 'config/initializers/backtrace_silencers.rb',
|
52
|
+
"# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }",
|
53
|
+
"Rails.backtrace_cleaner.add_silencer { |line| line =~ /lib\\/(haml|slim|sass|scss|coffee|compass)/ }"
|
54
|
+
|
55
|
+
if mongoid
|
56
|
+
generate "ckeditor:install", "--orm=mongoid", "--backend=paperclip"
|
57
|
+
else
|
58
|
+
generate "ckeditor:install", "--orm=active_record", "--backend=paperclip"
|
59
|
+
end
|
60
|
+
gsub_file 'config/initializers/ckeditor.rb', "# config.image_file_types = %w(jpg jpeg png gif tiff)", "config.image_file_types = %w(jpg jpeg png gif tiff svg)"
|
61
|
+
gsub_file 'config/initializers/ckeditor.rb', "# config.authorize_with :cancan", "config.authorize_with :cancancan"
|
62
|
+
gsub_file 'config/initializers/ckeditor.rb', "# config.assets_languages = ['en', 'uk']", "config.assets_languages = ['en', 'ru']"
|
63
|
+
|
64
|
+
if mongoid
|
65
|
+
remove_file 'config/initializers/cookies_serializer.rb'
|
66
|
+
create_file 'config/initializers/cookies_serializer.rb' do <<-TEXT
|
67
|
+
# Be sure to restart your server when you modify this file.
|
68
|
+
# json serializer breaks Devise + Mongoid. DO NOT ENABLE
|
69
|
+
# See https://github.com/plataformatec/devise/pull/2882
|
70
|
+
# Rails.application.config.action_dispatch.cookies_serializer = :json
|
71
|
+
Rails.application.config.action_dispatch.cookies_serializer = :marshal
|
72
|
+
TEXT
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
gsub_file 'config/initializers/filter_parameter_logging.rb', "[:password]", "[:password, :password_confirmation]"
|
77
|
+
|
78
|
+
# generate 'paperclip_optimizer:install'
|
79
|
+
# remove_file 'config/initializers/paperclip_optimizer.rb'
|
80
|
+
# generate "hancock:cms:paperclip_optimizer"
|
81
|
+
|
82
|
+
# generate 'rails_email_preview:install'
|
83
|
+
# remove_file 'app/mailer_previews/contact_mailer_preview.rb'
|
84
|
+
# create_file 'app/mailer_previews/contact_mailer_preview.rb' do <<-TEXT
|
85
|
+
# class ContactMailerPreview
|
86
|
+
# def new_message_email
|
87
|
+
# Hancock::Feedback::ContactMailer.new_message_email(Hancock::Feedback::ContactMessage.all.to_a.sample)
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
# TEXT
|
91
|
+
# end
|
92
|
+
|
93
|
+
generate "hancock:cms:config"
|
94
|
+
|
95
|
+
generate "hancock:cms:rack"
|
96
|
+
|
97
|
+
generate "hancock:cms:admin"
|
98
|
+
|
99
|
+
remove_file 'config/initializers/session_store.rb'
|
100
|
+
if mongoid
|
101
|
+
create_file 'config/initializers/session_store.rb' do <<-TEXT
|
102
|
+
# Be sure to restart your server when you modify this file.
|
103
|
+
#Rails.application.config.session_store :cookie_store, key: '_#{app_name.tableize.singularize}_session'
|
104
|
+
Rails.application.config.session_store :mongoid_store
|
105
|
+
TEXT
|
106
|
+
end
|
107
|
+
else
|
108
|
+
generate 'active_record_store:session_migration'
|
109
|
+
create_file 'config/initializers/session_store.rb' do <<-TEXT
|
110
|
+
# Be sure to restart your server when you modify this file.
|
111
|
+
#Rails.application.config.session_store :cookie_store, key: '_#{app_name.tableize.singularize}_session'
|
112
|
+
Rails.application.config.session_store :active_record_store
|
113
|
+
TEXT
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# unless mongoid
|
118
|
+
# generate 'simple_captcha'
|
119
|
+
# end
|
120
|
+
|
121
|
+
generate "simple_form:install"
|
122
|
+
|
123
|
+
|
124
|
+
####### CONTROLLERS #######
|
125
|
+
|
126
|
+
remove_file 'app/controllers/application_controller.rb'
|
127
|
+
create_file 'app/controllers/application_controller.rb' do <<-TEXT
|
128
|
+
class ApplicationController < ActionController::Base
|
129
|
+
include Hancock::Controller
|
130
|
+
end
|
131
|
+
TEXT
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
####### MODELS #######
|
136
|
+
|
137
|
+
generate "hancock:cms:ability"
|
138
|
+
|
139
|
+
gsub_file 'app/models/user.rb', '# :confirmable, :lockable, :timeoutable and :omniauthable' do <<-TEXT
|
140
|
+
include Hancock::Model
|
141
|
+
include Hancock::Enableable
|
142
|
+
include Hancock::RailsAdminPatch
|
143
|
+
def self.manager_can_default_actions
|
144
|
+
[:show, :read]
|
145
|
+
end
|
146
|
+
def manager_cannot_actions
|
147
|
+
[:new, :create, :delete, :destroy]
|
148
|
+
end
|
149
|
+
cattr_accessor :current_user
|
150
|
+
# Include default devise modules. Others available are:
|
151
|
+
# :confirmable, :lockable, :timeoutable and :omniauthable
|
152
|
+
TEXT
|
153
|
+
end
|
154
|
+
|
155
|
+
gsub_file 'app/models/user.rb', ':registerable,', ' :lockable,'
|
156
|
+
if mongoid
|
157
|
+
gsub_file 'app/models/user.rb', '# field :failed_attempts', 'field :failed_attempts'
|
158
|
+
gsub_file 'app/models/user.rb', '# field :unlock_token', 'field :unlock_token'
|
159
|
+
gsub_file 'app/models/user.rb', '# field :locked_at', 'field :locked_at'
|
160
|
+
|
161
|
+
inject_into_file 'app/models/user.rb', before: /^end/ do <<-TEXT
|
162
|
+
field :name, type: String
|
163
|
+
field :login, type: String
|
164
|
+
field :roles, type: Array, default: []
|
165
|
+
before_save do
|
166
|
+
self.roles ||= []
|
167
|
+
self.roles.reject! { |r| r.blank? }
|
168
|
+
end
|
169
|
+
AVAILABLE_ROLES = ["admin", "manager", "client"]
|
170
|
+
AVAILABLE_ROLES.each do |r|
|
171
|
+
class_eval <<-EVAL
|
172
|
+
def \#{r}?
|
173
|
+
self.roles and self.roles.include?("\#{r}")
|
174
|
+
end
|
175
|
+
scope :\#{r.pluralize}, -> { any_in(roles: "\#{r}") }
|
176
|
+
EVAL
|
177
|
+
end
|
178
|
+
def self.generate_first_admin_user
|
179
|
+
if ::User.admins.all.count == 0
|
180
|
+
_email_pass = 'admin@#{app_name.dasherize.downcase}.ru'
|
181
|
+
if ::User.new(roles: ["admin"], email: _email_pass, password: _email_pass, password_confirmation: _email_pass).save
|
182
|
+
puts "AdminUser with email and password '\#{_email_pass}' was created!"
|
183
|
+
else
|
184
|
+
puts 'Creating AdminUser error'
|
185
|
+
end
|
186
|
+
else
|
187
|
+
puts 'AdminUsers are here already'
|
188
|
+
end
|
189
|
+
end
|
190
|
+
def self.generate_first_manager_user
|
191
|
+
if ::User.managers.all.count == 0
|
192
|
+
_email_pass = 'manager@#{app_name.dasherize.downcase}.ru'
|
193
|
+
if ::User.create(roles: ["manager"], email: _email_pass, password: _email_pass, password_confirmation: _email_pass)
|
194
|
+
puts "ManagerUser with email and password '\#{_email_pass}' was created!"
|
195
|
+
else
|
196
|
+
puts 'Creating ManagerUser error'
|
197
|
+
end
|
198
|
+
else
|
199
|
+
puts 'ManagerUsers are here already'
|
200
|
+
end
|
201
|
+
end
|
202
|
+
rails_admin do
|
203
|
+
list do
|
204
|
+
field :email
|
205
|
+
field :name
|
206
|
+
field :login
|
207
|
+
field :roles do
|
208
|
+
pretty_value do
|
209
|
+
render_object = (bindings[:controller] || bindings[:view])
|
210
|
+
render_object.content_tag(:p, bindings[:object].roles.join(", ")) if render_object
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
edit do
|
215
|
+
group :login do
|
216
|
+
active false
|
217
|
+
field :email, :string do
|
218
|
+
visible do
|
219
|
+
render_object = (bindings[:controller] || bindings[:view])
|
220
|
+
render_object and (render_object.current_user.admin? or (render_object.current_user.manager? and render_object.current_user == bindings[:object]))
|
221
|
+
end
|
222
|
+
end
|
223
|
+
field :name, :string
|
224
|
+
field :login, :string do
|
225
|
+
visible do
|
226
|
+
render_object = (bindings[:controller] || bindings[:view])
|
227
|
+
render_object and render_object.current_user.admin?
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
group :roles do
|
232
|
+
active false
|
233
|
+
field :roles, :enum do
|
234
|
+
enum do
|
235
|
+
AVAILABLE_ROLES
|
236
|
+
end
|
237
|
+
multiple do
|
238
|
+
true
|
239
|
+
end
|
240
|
+
visible do
|
241
|
+
render_object = (bindings[:controller] || bindings[:view])
|
242
|
+
render_object and render_object.current_user.admin?
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
group :password do
|
247
|
+
active false
|
248
|
+
field :password do
|
249
|
+
visible do
|
250
|
+
render_object = (bindings[:controller] || bindings[:view])
|
251
|
+
render_object and (render_object.current_user.admin? or render_object.current_user == bindings[:object])
|
252
|
+
end
|
253
|
+
end
|
254
|
+
field :password_confirmation do
|
255
|
+
visible do
|
256
|
+
render_object = (bindings[:controller] || bindings[:view])
|
257
|
+
render_object and (render_object.current_user.admin? or render_object.current_user == bindings[:object])
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
TEXT
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
|
268
|
+
###### HANCOCK OTHERS ######
|
269
|
+
|
270
|
+
unless mongoid
|
271
|
+
generate "hancock:cms:migration"
|
272
|
+
generate "rails_admin_settings:migration"
|
273
|
+
end
|
274
|
+
|
275
|
+
remove_file 'app/views/layouts/application.html.erb'
|
276
|
+
generate "hancock:cms:layout"
|
277
|
+
|
278
|
+
unless mongoid
|
279
|
+
rake "db:migrate"
|
280
|
+
end
|
281
|
+
|
282
|
+
run 'rails r "User.generate_first_admin_user"'
|
283
|
+
|
284
|
+
remove_file 'app/assets/stylesheets/application.css'
|
285
|
+
remove_file 'app/assets/javascripts/application.js'
|
286
|
+
generate "hancock:cms:assets", app_name
|
287
|
+
|
288
|
+
remove_file 'public/robots.txt'
|
289
|
+
generate "hancock:cms:robots", app_name
|
290
|
+
|
291
|
+
#god+unicorn
|
292
|
+
generate "hancock:cms:unicorn_god", app_name
|
293
|
+
#scripts
|
294
|
+
generate "hancock:cms:scripts", app_name
|
295
|
+
|
296
|
+
FileUtils.cp(Pathname.new(destination_root).join('config', 'secrets.yml').to_s, Pathname.new(destination_root).join('config', 'secrets.yml.example').to_s)
|
297
|
+
|
298
|
+
unless mongoid
|
299
|
+
generate "paper_trail:install"
|
300
|
+
generate "friendly_id"
|
301
|
+
rake "db:migrate"
|
302
|
+
end
|
303
|
+
|
304
|
+
generate "rspec:install"
|
305
|
+
|
306
|
+
|
307
|
+
####### GIT #######
|
308
|
+
|
309
|
+
remove_file '.gitignore'
|
310
|
+
create_file '.gitignore' do <<-TEXT
|
311
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
312
|
+
#
|
313
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
314
|
+
# or operating system, you probably want to add a global ignore instead:
|
315
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
316
|
+
.idea
|
317
|
+
.idea/*
|
318
|
+
/.bundle
|
319
|
+
/log/*.log
|
320
|
+
/tmp/*
|
321
|
+
/public/assets
|
322
|
+
/public/ckeditor_assets
|
323
|
+
Gemfile.lock
|
324
|
+
TEXT
|
325
|
+
end
|
326
|
+
|
327
|
+
create_file 'extra/.gitkeep', ''
|
328
|
+
|
329
|
+
git :init
|
330
|
+
git add: "."
|
331
|
+
git commit: %Q{ -m 'Initial commit' }
|
332
|
+
|
333
|
+
end
|
334
|
+
|
335
|
+
def mongoid
|
336
|
+
defined? Mongoid
|
337
|
+
end
|
338
|
+
|
339
|
+
def app_name
|
340
|
+
Rails.application.class.parent_name
|
341
|
+
end
|
342
|
+
|
343
|
+
end
|
344
|
+
end
|
File without changes
|
@@ -3,8 +3,11 @@ module Hancock
|
|
3
3
|
module EmbeddedElement
|
4
4
|
def self.config(nav_label = nil, fields = {})
|
5
5
|
if nav_label.is_a?(Hash)
|
6
|
+
nav_label, fields = nav_label[:nav_label], nav_label
|
7
|
+
elsif nav_label.is_a?(Array)
|
6
8
|
nav_label, fields = nil, nav_label
|
7
9
|
end
|
10
|
+
|
8
11
|
Proc.new {
|
9
12
|
navigation_label(nav_label || I18n.t('hancock.cms'))
|
10
13
|
field :enabled, :toggle do
|
@@ -27,6 +27,8 @@ module Hancock
|
|
27
27
|
|
28
28
|
attr_accessor :captcha_on_development
|
29
29
|
|
30
|
+
attr_accessor :history_tracking
|
31
|
+
|
30
32
|
def initialize
|
31
33
|
@main_index_layout = 'application'
|
32
34
|
@error_layout = 'application'
|
@@ -43,6 +45,8 @@ module Hancock
|
|
43
45
|
@registration_captcha = @admin_enter_captcha
|
44
46
|
|
45
47
|
@captcha_on_development = false
|
48
|
+
|
49
|
+
@history_tracking = false
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|
data/lib/hancock/engine.rb
CHANGED
@@ -10,39 +10,43 @@ module Hancock
|
|
10
10
|
# Write default email settings to DB so they can be changed.
|
11
11
|
|
12
12
|
#temp
|
13
|
-
|
14
|
-
|
13
|
+
begin
|
14
|
+
if Settings and Settings.table_exists?
|
15
15
|
# Settings.default_email_from(default: 'noreply@site.domain')
|
16
16
|
# Settings.form_email(default: 'admin@site.domain')
|
17
17
|
# Settings.email_topic(default: 'с сайта')
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
initializer 'hancock_cms.paperclip' do
|
23
|
-
# require 'paperclip/style'
|
24
|
-
# module ::Paperclip
|
25
|
-
# class Style
|
26
|
-
# alias_method :processor_options_without_auto_orient, :processor_options
|
27
|
-
# def processor_options
|
28
|
-
# processor_options_without_auto_orient.merge(auto_orient: false)
|
29
|
-
# end
|
30
|
-
# end
|
31
|
-
# end
|
18
|
+
Settings.logo_image(kind: :image)
|
19
|
+
end
|
20
|
+
rescue
|
21
|
+
end
|
32
22
|
end
|
23
|
+
# initializer 'hancock_cms.paperclip' do
|
24
|
+
# # require 'paperclip/style'
|
25
|
+
# # module ::Paperclip
|
26
|
+
# # class Style
|
27
|
+
# # alias_method :processor_options_without_auto_orient, :processor_options
|
28
|
+
# # def processor_options
|
29
|
+
# # processor_options_without_auto_orient.merge(auto_orient: false)
|
30
|
+
# # end
|
31
|
+
# # end
|
32
|
+
# # end
|
33
|
+
# end
|
33
34
|
|
34
|
-
config.after_initialize do
|
35
|
-
|
36
|
-
|
35
|
+
# config.after_initialize do
|
36
|
+
# # trigger autoload so models are registered in Mongoid::Elasticearch
|
37
|
+
# # Hancock.config.search_models.map(&:constantize)
|
38
|
+
#
|
39
|
+
# # Write default email settings to DB so they can be changed.
|
40
|
+
# begin
|
41
|
+
# if Settings and Settings.table_exists?
|
42
|
+
# # Settings.default_email_from(default: 'noreply@site.domain')
|
43
|
+
# # Settings.form_email(default: 'admin@site.domain')
|
44
|
+
# # Settings.email_topic(default: 'с сайта')
|
45
|
+
# Settings.logo_image(kind: :image)
|
46
|
+
# end
|
47
|
+
# rescue
|
48
|
+
# end
|
49
|
+
# end
|
37
50
|
|
38
|
-
# Write default email settings to DB so they can be changed.
|
39
|
-
if Settings and Settings.table_exists?
|
40
|
-
# Settings.default_email_from(default: 'noreply@site.domain')
|
41
|
-
# Settings.form_email(default: 'admin@site.domain')
|
42
|
-
# Settings.email_topic(default: 'с сайта')
|
43
|
-
#
|
44
|
-
Settings.logo_image(kind: :image)
|
45
|
-
end
|
46
|
-
end
|
47
51
|
end
|
48
52
|
end
|
data/lib/hancock/model.rb
CHANGED
@@ -22,11 +22,13 @@ module Hancock
|
|
22
22
|
include RailsAdminComments::ModelCommentable
|
23
23
|
end
|
24
24
|
|
25
|
-
if Hancock.
|
26
|
-
if
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
if Hancock.config.history_tracking
|
26
|
+
if Hancock.mongoid?
|
27
|
+
if defined?(TrackablePatch)
|
28
|
+
include TrackablePatch
|
29
|
+
elsif defined?(Trackable)
|
30
|
+
include Trackable
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
@@ -84,19 +84,23 @@ module Hancock
|
|
84
84
|
if rails_admin_actions.respond_to?(action)
|
85
85
|
rails_admin_actions.send(action) do
|
86
86
|
visible do
|
87
|
-
|
88
|
-
|
89
|
-
ret = bindings[:abstract_model].model.rails_admin_visible_actions.include?(action)
|
87
|
+
if !bindings or bindings[:abstract_model].blank?
|
88
|
+
true
|
90
89
|
else
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
90
|
+
ret = false
|
91
|
+
if bindings[:abstract_model].model.respond_to?(:rails_admin_visible_actions)
|
92
|
+
ret = bindings[:abstract_model].model.rails_admin_visible_actions.include?(action)
|
93
|
+
else
|
94
|
+
if visibility = Hancock.rails_admin_config.actions_visibility[action]
|
95
|
+
if visibility.is_a?(Proc)
|
96
|
+
ret = visibility.call(self)
|
97
|
+
else
|
98
|
+
ret = visibility.include? bindings[:abstract_model].model_name
|
99
|
+
end
|
96
100
|
end
|
97
|
-
end
|
98
|
-
|
99
|
-
|
101
|
+
end # if bindings[:abstract_model].model.respond_to?(:rails_admin_visible_actions)
|
102
|
+
ret
|
103
|
+
end # !bindings or bindings[:abstract_model].blank?
|
100
104
|
end # visible do
|
101
105
|
end # rails_admin_actions.send(action) do
|
102
106
|
end # if rails_admin_actions.respond_to?(action)
|
data/lib/hancock/version.rb
CHANGED
data/template.rb
CHANGED
@@ -28,10 +28,8 @@ gem 'sass-rails', '~> 5.0'
|
|
28
28
|
gem 'compass'
|
29
29
|
gem 'compass-rails'
|
30
30
|
|
31
|
-
gem '
|
32
|
-
|
33
|
-
# #{if mongoid then "gem 'hancock_cms_mongoid'" else "gem 'hancock_cms_activerecord'" end}, github: 'red-rocks/hancock_cms', branch: 'rails5'
|
34
|
-
#{if mongoid then "gem 'hancock_cms_mongoid'" else "gem 'hancock_cms_activerecord'" end}, path: "/home/ack/www/redrocks/hancock"
|
31
|
+
gem 'rails_admin', '~> 1.1'
|
32
|
+
|
35
33
|
|
36
34
|
# #{if mongoid then "gem 'glebtv-mongoid-paperclip'" else "gem 'paperclip'" end}
|
37
35
|
# gem "image_optim"
|
@@ -39,10 +37,16 @@ gem 'rails_admin', '>= 1.0.0.rc'
|
|
39
37
|
# gem 'ack-paperclip-meta', github: "red-rocks/paperclip-meta"
|
40
38
|
|
41
39
|
# gem 'rails_admin_multiple_file_upload'
|
40
|
+
gem 'rails_admin_user_abilities', '~> 0.2.0'
|
42
41
|
# gem 'rails_admin_user_abilities', github: "red-rocks/rails_admin_user_abilities"
|
42
|
+
gem 'rails_admin_model_settings', '~> 0.3.0'
|
43
43
|
# gem 'rails_admin_model_settings', github: "red-rocks/rails_admin_model_settings"
|
44
44
|
|
45
|
-
gem '
|
45
|
+
# #{if mongoid then "gem 'hancock_cms_mongoid'" else "gem 'hancock_cms_activerecord'" end}, github: 'red-rocks/hancock_cms', branch: 'rails5'
|
46
|
+
#{if mongoid then "gem 'hancock_cms_mongoid'" else "gem 'hancock_cms_activerecord'" end}, path: "/home/ack/www/redrocks/hancock"
|
47
|
+
|
48
|
+
# gem 'recaptcha', require: 'recaptcha/rails'
|
49
|
+
# gem 'glebtv-simple_captcha'
|
46
50
|
|
47
51
|
gem 'slim-rails'
|
48
52
|
gem 'rs_russian'
|
@@ -66,7 +70,8 @@ group :development do
|
|
66
70
|
gem 'spring'
|
67
71
|
gem 'spring-watcher-listen', '~> 2.0.0'
|
68
72
|
|
69
|
-
gem 'ack_favicon_maker_rails',
|
73
|
+
gem 'ack_favicon_maker_rails', '~> 1.0.1'
|
74
|
+
# gem 'ack_favicon_maker_rails', github: 'ack43/favicon_maker_rails'
|
70
75
|
|
71
76
|
# gem 'rails_email_preview', '~> 1.0.3'
|
72
77
|
|
@@ -99,25 +104,24 @@ group :development, :test do
|
|
99
104
|
gem 'byebug', platform: :mri
|
100
105
|
end
|
101
106
|
|
102
|
-
gem 'glebtv_mongoid_userstamp', '0.7.0'
|
103
|
-
|
104
107
|
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
105
108
|
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
106
109
|
|
107
110
|
group :production do
|
108
111
|
gem "god"
|
109
112
|
end
|
113
|
+
|
114
|
+
gem 'glebtv_mongoid_userstamp', '0.7.0'
|
110
115
|
TEXT
|
111
116
|
end
|
112
117
|
|
113
|
-
RVM_RUBY_VERSION = "2.4.0-preview1"
|
118
|
+
RVM_RUBY_VERSION = "2.3.3"#"2.4.0-preview1"
|
114
119
|
create_file '.ruby-version', "#{RVM_RUBY_VERSION}\n"
|
115
120
|
create_file '.ruby-gemset', "#{app_name.underscore}\n"
|
116
|
-
# run "rvm use #{RVM_RUBY_VERSION} && rvm gemset create #{app_name}"
|
117
|
-
# run "rvm use #{RVM_RUBY_VERSION}@#{app_name} && gem install bundler"
|
118
|
-
# run "rvm gemset list"
|
119
|
-
run 'bundle install --without production'
|
120
121
|
|
122
|
+
run "rvm #{RVM_RUBY_VERSION} do rvm gemset create #{app_name.underscore}"
|
123
|
+
run "rvm #{RVM_RUBY_VERSION}@#{app_name.underscore} do gem install bundler"
|
124
|
+
run "rvm #{RVM_RUBY_VERSION}@#{app_name.underscore} do bundle install --without production"
|
121
125
|
|
122
126
|
####### CONFIG #######
|
123
127
|
|
@@ -232,346 +236,3 @@ module #{app_name.underscore.camelcase}
|
|
232
236
|
end
|
233
237
|
TEXT
|
234
238
|
end
|
235
|
-
|
236
|
-
|
237
|
-
####### DEVISE #######
|
238
|
-
|
239
|
-
generate "devise:install"
|
240
|
-
gsub_file 'config/initializers/devise.rb', "'please-change-me-at-config-initializers-devise@example.com'", "'noreply@#{app_name.dasherize.downcase}.ru'"
|
241
|
-
inject_into_file 'config/initializers/devise.rb', after: /^end/ do <<-TEXT
|
242
|
-
Rails.application.config.to_prepare do
|
243
|
-
Devise::SessionsController.layout "hancock/devise/sessions"
|
244
|
-
Devise::RegistrationsController.layout "hancock/devise/registrations"
|
245
|
-
Devise::ConfirmationsController.layout "hancock/devise/confirmations"
|
246
|
-
Devise::UnlocksController.layout "hancock/devise/unlocks"
|
247
|
-
Devise::PasswordsController.layout "hancock/devise/passwords"
|
248
|
-
end
|
249
|
-
TEXT
|
250
|
-
end
|
251
|
-
|
252
|
-
generate "devise", "User"
|
253
|
-
|
254
|
-
|
255
|
-
####### ROUTES #######
|
256
|
-
|
257
|
-
remove_file 'config/routes.rb'
|
258
|
-
create_file 'config/routes.rb' do <<-TEXT
|
259
|
-
Rails.application.routes.draw do
|
260
|
-
devise_for :users, controllers: {sessions: 'hancock/sessions'}
|
261
|
-
|
262
|
-
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
|
263
|
-
mount Ckeditor::Engine => '/ckeditor'
|
264
|
-
|
265
|
-
hancock_cms_routes
|
266
|
-
end
|
267
|
-
TEXT
|
268
|
-
end
|
269
|
-
|
270
|
-
|
271
|
-
####### INITIALIZERS #######
|
272
|
-
|
273
|
-
inject_into_file 'config/initializers/assets.rb', before: /\z/ do <<-TEXT
|
274
|
-
Rails.application.config.assets.precompile += %w( *.svg )
|
275
|
-
Rails.application.config.assets.precompile += %w( ckeditor/* )
|
276
|
-
Rails.application.config.assets.precompile += %w( codemirror.js codemirror.css codemirror/**/* )
|
277
|
-
TEXT
|
278
|
-
end
|
279
|
-
|
280
|
-
gsub_file 'config/initializers/backtrace_silencers.rb',
|
281
|
-
"# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }",
|
282
|
-
"Rails.backtrace_cleaner.add_silencer { |line| line =~ /lib\\/(haml|slim|sass|scss|coffee|compass)/ }"
|
283
|
-
|
284
|
-
if mongoid
|
285
|
-
generate "ckeditor:install", "--orm=mongoid", "--backend=paperclip"
|
286
|
-
else
|
287
|
-
generate "ckeditor:install", "--orm=active_record", "--backend=paperclip"
|
288
|
-
end
|
289
|
-
gsub_file 'config/initializers/ckeditor.rb', "# config.image_file_types = %w(jpg jpeg png gif tiff)", "config.image_file_types = %w(jpg jpeg png gif tiff svg)"
|
290
|
-
gsub_file 'config/initializers/ckeditor.rb', "# config.authorize_with :cancan", "config.authorize_with :cancancan"
|
291
|
-
gsub_file 'config/initializers/ckeditor.rb', "# config.assets_languages = ['en', 'uk']", "config.assets_languages = ['en', 'ru']"
|
292
|
-
|
293
|
-
if mongoid
|
294
|
-
remove_file 'config/initializers/cookies_serializer.rb'
|
295
|
-
create_file 'config/initializers/cookies_serializer.rb' do <<-TEXT
|
296
|
-
# Be sure to restart your server when you modify this file.
|
297
|
-
# json serializer breaks Devise + Mongoid. DO NOT ENABLE
|
298
|
-
# See https://github.com/plataformatec/devise/pull/2882
|
299
|
-
# Rails.application.config.action_dispatch.cookies_serializer = :json
|
300
|
-
Rails.application.config.action_dispatch.cookies_serializer = :marshal
|
301
|
-
TEXT
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
gsub_file 'config/initializers/filter_parameter_logging.rb', "[:password]", "[:password, :password_confirmation]"
|
306
|
-
|
307
|
-
# generate 'paperclip_optimizer:install'
|
308
|
-
# remove_file 'config/initializers/paperclip_optimizer.rb'
|
309
|
-
# generate "hancock:cms:paperclip_optimizer"
|
310
|
-
|
311
|
-
# generate 'rails_email_preview:install'
|
312
|
-
# remove_file 'app/mailer_previews/contact_mailer_preview.rb'
|
313
|
-
# create_file 'app/mailer_previews/contact_mailer_preview.rb' do <<-TEXT
|
314
|
-
# class ContactMailerPreview
|
315
|
-
# def new_message_email
|
316
|
-
# Hancock::Feedback::ContactMailer.new_message_email(Hancock::Feedback::ContactMessage.all.to_a.sample)
|
317
|
-
# end
|
318
|
-
# end
|
319
|
-
# TEXT
|
320
|
-
# end
|
321
|
-
|
322
|
-
generate "hancock:cms:config"
|
323
|
-
|
324
|
-
generate "hancock:cms:rack"
|
325
|
-
|
326
|
-
generate "hancock:cms:admin"
|
327
|
-
|
328
|
-
remove_file 'config/initializers/session_store.rb'
|
329
|
-
if mongoid
|
330
|
-
create_file 'config/initializers/session_store.rb' do <<-TEXT
|
331
|
-
# Be sure to restart your server when you modify this file.
|
332
|
-
|
333
|
-
#Rails.application.config.session_store :cookie_store, key: '_#{app_name.tableize.singularize}_session'
|
334
|
-
Rails.application.config.session_store :mongoid_store
|
335
|
-
TEXT
|
336
|
-
end
|
337
|
-
else
|
338
|
-
generate 'active_record_store:session_migration'
|
339
|
-
create_file 'config/initializers/session_store.rb' do <<-TEXT
|
340
|
-
# Be sure to restart your server when you modify this file.
|
341
|
-
|
342
|
-
#Rails.application.config.session_store :cookie_store, key: '_#{app_name.tableize.singularize}_session'
|
343
|
-
Rails.application.config.session_store :active_record_store
|
344
|
-
TEXT
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
# unless mongoid
|
349
|
-
# generate 'simple_captcha'
|
350
|
-
# end
|
351
|
-
|
352
|
-
generate "simple_form:install"
|
353
|
-
|
354
|
-
|
355
|
-
####### CONTROLLERS #######
|
356
|
-
|
357
|
-
remove_file 'app/controllers/application_controller.rb'
|
358
|
-
create_file 'app/controllers/application_controller.rb' do <<-TEXT
|
359
|
-
class ApplicationController < ActionController::Base
|
360
|
-
include Hancock::Controller
|
361
|
-
end
|
362
|
-
TEXT
|
363
|
-
end
|
364
|
-
|
365
|
-
|
366
|
-
####### MODELS #######
|
367
|
-
|
368
|
-
generate "hancock:cms:ability"
|
369
|
-
|
370
|
-
gsub_file 'app/models/user.rb', '# :confirmable, :lockable, :timeoutable and :omniauthable' do <<-TEXT
|
371
|
-
include Hancock::Model
|
372
|
-
include Hancock::Enableable
|
373
|
-
include Hancock::RailsAdminPatch
|
374
|
-
def self.manager_can_default_actions
|
375
|
-
[:show, :read]
|
376
|
-
end
|
377
|
-
def manager_cannot_actions
|
378
|
-
[:new, :create, :delete, :destroy]
|
379
|
-
end
|
380
|
-
|
381
|
-
cattr_accessor :current_user
|
382
|
-
|
383
|
-
# Include default devise modules. Others available are:
|
384
|
-
# :confirmable, :lockable, :timeoutable and :omniauthable
|
385
|
-
TEXT
|
386
|
-
end
|
387
|
-
|
388
|
-
gsub_file 'app/models/user.rb', ':registerable,', ' :lockable,'
|
389
|
-
if mongoid
|
390
|
-
gsub_file 'app/models/user.rb', '# field :failed_attempts', 'field :failed_attempts'
|
391
|
-
gsub_file 'app/models/user.rb', '# field :unlock_token', 'field :unlock_token'
|
392
|
-
gsub_file 'app/models/user.rb', '# field :locked_at', 'field :locked_at'
|
393
|
-
|
394
|
-
inject_into_file 'app/models/user.rb', before: /^end/ do <<-TEXT
|
395
|
-
|
396
|
-
field :name, type: String
|
397
|
-
field :login, type: String
|
398
|
-
field :roles, type: Array, default: []
|
399
|
-
|
400
|
-
before_save do
|
401
|
-
self.roles ||= []
|
402
|
-
self.roles.reject! { |r| r.blank? }
|
403
|
-
end
|
404
|
-
|
405
|
-
AVAILABLE_ROLES = ["admin", "manager", "client"]
|
406
|
-
|
407
|
-
AVAILABLE_ROLES.each do |r|
|
408
|
-
class_eval <<-EVAL
|
409
|
-
def \#{r}?
|
410
|
-
self.roles and self.roles.include?("\#{r}")
|
411
|
-
end
|
412
|
-
|
413
|
-
scope :\#{r.pluralize}, -> { any_in(roles: "\#{r}") }
|
414
|
-
EVAL
|
415
|
-
end
|
416
|
-
|
417
|
-
def self.generate_first_admin_user
|
418
|
-
if ::User.admins.all.count == 0
|
419
|
-
_email_pass = 'admin@#{app_name.dasherize.downcase}.ru'
|
420
|
-
if ::User.new(roles: ["admin"], email: _email_pass, password: _email_pass, password_confirmation: _email_pass).save
|
421
|
-
puts "AdminUser with email and password '\#{_email_pass}' was created!"
|
422
|
-
else
|
423
|
-
puts 'Creating AdminUser error'
|
424
|
-
end
|
425
|
-
else
|
426
|
-
puts 'AdminUsers are here already'
|
427
|
-
end
|
428
|
-
end
|
429
|
-
|
430
|
-
def self.generate_first_manager_user
|
431
|
-
if ::User.managers.all.count == 0
|
432
|
-
_email_pass = 'manager@#{app_name.dasherize.downcase}.ru'
|
433
|
-
if ::User.create(roles: ["manager"], email: _email_pass, password: _email_pass, password_confirmation: _email_pass)
|
434
|
-
puts "ManagerUser with email and password '\#{_email_pass}' was created!"
|
435
|
-
else
|
436
|
-
puts 'Creating ManagerUser error'
|
437
|
-
end
|
438
|
-
else
|
439
|
-
puts 'ManagerUsers are here already'
|
440
|
-
end
|
441
|
-
end
|
442
|
-
|
443
|
-
rails_admin do
|
444
|
-
list do
|
445
|
-
field :email
|
446
|
-
field :name
|
447
|
-
field :login
|
448
|
-
field :roles do
|
449
|
-
pretty_value do
|
450
|
-
render_object = (bindings[:controller] || bindings[:view])
|
451
|
-
render_object.content_tag(:p, bindings[:object].roles.join(", ")) if render_object
|
452
|
-
end
|
453
|
-
end
|
454
|
-
end
|
455
|
-
|
456
|
-
edit do
|
457
|
-
group :login do
|
458
|
-
active false
|
459
|
-
field :email, :string do
|
460
|
-
visible do
|
461
|
-
render_object = (bindings[:controller] || bindings[:view])
|
462
|
-
render_object and (render_object.current_user.admin? or (render_object.current_user.manager? and render_object.current_user == bindings[:object]))
|
463
|
-
end
|
464
|
-
end
|
465
|
-
field :name, :string
|
466
|
-
field :login, :string do
|
467
|
-
visible do
|
468
|
-
render_object = (bindings[:controller] || bindings[:view])
|
469
|
-
render_object and render_object.current_user.admin?
|
470
|
-
end
|
471
|
-
end
|
472
|
-
end
|
473
|
-
|
474
|
-
group :roles do
|
475
|
-
active false
|
476
|
-
field :roles, :enum do
|
477
|
-
enum do
|
478
|
-
AVAILABLE_ROLES
|
479
|
-
end
|
480
|
-
|
481
|
-
multiple do
|
482
|
-
true
|
483
|
-
end
|
484
|
-
|
485
|
-
visible do
|
486
|
-
render_object = (bindings[:controller] || bindings[:view])
|
487
|
-
render_object and render_object.current_user.admin?
|
488
|
-
end
|
489
|
-
end
|
490
|
-
end
|
491
|
-
|
492
|
-
group :password do
|
493
|
-
active false
|
494
|
-
field :password do
|
495
|
-
visible do
|
496
|
-
render_object = (bindings[:controller] || bindings[:view])
|
497
|
-
render_object and (render_object.current_user.admin? or render_object.current_user == bindings[:object])
|
498
|
-
end
|
499
|
-
end
|
500
|
-
field :password_confirmation do
|
501
|
-
visible do
|
502
|
-
render_object = (bindings[:controller] || bindings[:view])
|
503
|
-
render_object and (render_object.current_user.admin? or render_object.current_user == bindings[:object])
|
504
|
-
end
|
505
|
-
end
|
506
|
-
end
|
507
|
-
end
|
508
|
-
|
509
|
-
end
|
510
|
-
TEXT
|
511
|
-
end
|
512
|
-
end
|
513
|
-
|
514
|
-
|
515
|
-
###### HANCOCK OTHERS ######
|
516
|
-
|
517
|
-
unless mongoid
|
518
|
-
generate "hancock:cms:migration"
|
519
|
-
generate "rails_admin_settings:migration"
|
520
|
-
end
|
521
|
-
|
522
|
-
remove_file 'app/views/layouts/application.html.erb'
|
523
|
-
generate "hancock:cms:layout"
|
524
|
-
|
525
|
-
unless mongoid
|
526
|
-
rake "db:migrate"
|
527
|
-
end
|
528
|
-
|
529
|
-
remove_file 'app/assets/stylesheets/application.css'
|
530
|
-
remove_file 'app/assets/javascripts/application.js'
|
531
|
-
generate "hancock:cms:assets", app_name
|
532
|
-
|
533
|
-
remove_file 'public/robots.txt'
|
534
|
-
generate "hancock:cms:robots", app_name
|
535
|
-
|
536
|
-
#god+unicorn
|
537
|
-
generate "hancock:cms:unicorn_god", app_name
|
538
|
-
#scripts
|
539
|
-
generate "hancock:cms:scripts", app_name
|
540
|
-
|
541
|
-
FileUtils.cp(Pathname.new(destination_root).join('config', 'secrets.yml').to_s, Pathname.new(destination_root).join('config', 'secrets.yml.example').to_s)
|
542
|
-
|
543
|
-
unless mongoid
|
544
|
-
generate "paper_trail:install"
|
545
|
-
generate "friendly_id"
|
546
|
-
rake "db:migrate"
|
547
|
-
end
|
548
|
-
|
549
|
-
generate "rspec:install"
|
550
|
-
|
551
|
-
|
552
|
-
####### GIT #######
|
553
|
-
|
554
|
-
remove_file '.gitignore'
|
555
|
-
create_file '.gitignore' do <<-TEXT
|
556
|
-
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
557
|
-
#
|
558
|
-
# If you find yourself ignoring temporary files generated by your text editor
|
559
|
-
# or operating system, you probably want to add a global ignore instead:
|
560
|
-
# git config --global core.excludesfile '~/.gitignore_global'
|
561
|
-
.idea
|
562
|
-
.idea/*
|
563
|
-
|
564
|
-
/.bundle
|
565
|
-
/log/*.log
|
566
|
-
/tmp/*
|
567
|
-
/public/assets
|
568
|
-
/public/ckeditor_assets
|
569
|
-
Gemfile.lock
|
570
|
-
TEXT
|
571
|
-
end
|
572
|
-
|
573
|
-
create_file 'extra/.gitkeep', ''
|
574
|
-
|
575
|
-
git :init
|
576
|
-
git add: "."
|
577
|
-
git commit: %Q{ -m 'Initial commit' }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hancock_cms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
4
|
+
version: 2.0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kiseliev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -188,16 +188,16 @@ dependencies:
|
|
188
188
|
name: ack_rails_admin_settings
|
189
189
|
requirement: !ruby/object:Gem::Requirement
|
190
190
|
requirements:
|
191
|
-
- - "
|
191
|
+
- - "~>"
|
192
192
|
- !ruby/object:Gem::Version
|
193
|
-
version: '
|
193
|
+
version: '1.2'
|
194
194
|
type: :runtime
|
195
195
|
prerelease: false
|
196
196
|
version_requirements: !ruby/object:Gem::Requirement
|
197
197
|
requirements:
|
198
|
-
- - "
|
198
|
+
- - "~>"
|
199
199
|
- !ruby/object:Gem::Version
|
200
|
-
version: '
|
200
|
+
version: '1.2'
|
201
201
|
- !ruby/object:Gem::Dependency
|
202
202
|
name: kaminari
|
203
203
|
requirement: !ruby/object:Gem::Requirement
|
@@ -293,6 +293,7 @@ files:
|
|
293
293
|
- app/models/concerns/hancock/boolean_field.rb
|
294
294
|
- app/models/concerns/hancock/cacheable.rb
|
295
295
|
- app/models/concerns/hancock/decorators/embedded_element.rb
|
296
|
+
- app/models/concerns/hancock/embedded_findable.rb
|
296
297
|
- app/models/concerns/hancock/enableable.rb
|
297
298
|
- app/models/concerns/hancock/geocodeable.rb
|
298
299
|
- app/models/concerns/hancock/hash_field.rb
|
@@ -342,7 +343,6 @@ files:
|
|
342
343
|
- app/views/rails_admin/main/_hancock_html_ml.html.slim
|
343
344
|
- app/views/shared/_admin_link.html.slim
|
344
345
|
- app/views/shared/_messages.html.slim
|
345
|
-
- config/initializers/embedded_findable.rb
|
346
346
|
- config/initializers/hancock_cms.rb
|
347
347
|
- config/initializers/simple_captcha.rb
|
348
348
|
- config/locales/en.hancock.yml
|
@@ -371,12 +371,14 @@ files:
|
|
371
371
|
- lib/generators/hancock/cms/rack_generator.rb
|
372
372
|
- lib/generators/hancock/cms/robots_generator.rb
|
373
373
|
- lib/generators/hancock/cms/scripts_generator.rb
|
374
|
+
- lib/generators/hancock/cms/setup_generator.rb
|
374
375
|
- lib/generators/hancock/cms/templates/Gemfile.erb
|
375
376
|
- lib/generators/hancock/cms/templates/ability.erb
|
376
377
|
- lib/generators/hancock/cms/templates/admin.erb
|
377
378
|
- lib/generators/hancock/cms/templates/application.erb
|
378
379
|
- lib/generators/hancock/cms/templates/assets/javascripts/application.coffee.erb
|
379
380
|
- lib/generators/hancock/cms/templates/assets/stylesheets/application.sass.erb
|
381
|
+
- lib/generators/hancock/cms/templates/assets/stylesheets/hancock/rails_admin/custom/theming.sass.erb
|
380
382
|
- lib/generators/hancock/cms/templates/hancock_cms.erb
|
381
383
|
- lib/generators/hancock/cms/templates/model.erb
|
382
384
|
- lib/generators/hancock/cms/templates/paperclip_optimizer.erb
|
@@ -447,7 +449,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
447
449
|
version: '0'
|
448
450
|
requirements: []
|
449
451
|
rubyforge_project:
|
450
|
-
rubygems_version: 2.
|
452
|
+
rubygems_version: 2.5.1
|
451
453
|
signing_key:
|
452
454
|
specification_version: 4
|
453
455
|
summary: Please DO NOT use this gem directly, use hancock_cms_mongoid or hancock_cms_activerecord
|