drg_cms 0.6.1.0 → 0.6.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -10
- data/app/assets/fonts/ibm-plex-sans-300.woff2 +0 -0
- data/app/assets/fonts/ibm-plex-sans-400.woff2 +0 -0
- data/app/assets/fonts/ibm-plex-sans-500.woff2 +0 -0
- data/app/assets/fonts/ibm-plex-sans-600.woff2 +0 -0
- data/app/assets/fonts/ibm-plex-sans-700.woff2 +0 -0
- data/app/assets/fonts/ibm-plex-sans-italic.woff2 +0 -0
- data/app/assets/javascripts/drg_cms/drg_cms.js +178 -55
- data/app/assets/stylesheets/drg_cms/drg_cms.css +218 -94
- data/app/assets/stylesheets/drg_cms/select-multiple.css +1 -1
- data/app/controllers/cmsedit_controller.rb +29 -24
- data/app/controllers/dc_application_controller.rb +78 -166
- data/app/controllers/dc_common_controller.rb +56 -47
- data/app/controls/dc_help_control.rb +12 -0
- data/app/controls/dc_report.rb +7 -9
- data/app/controls/design_element_settings_control.rb +1 -1
- data/app/forms/all_options.yml +25 -6
- data/app/forms/dc_big_table.yml +0 -2
- data/app/forms/dc_big_table_value.yml +0 -2
- data/app/forms/dc_design.yml +1 -2
- data/app/forms/dc_folder_permission.yml +0 -2
- data/app/forms/dc_help_1.yml +2 -1
- data/app/forms/dc_json_ld.yml +0 -3
- data/app/forms/dc_menu.yml +6 -12
- data/app/forms/dc_menu_item.yml +1 -3
- data/app/forms/dc_page.yml +5 -2
- data/app/forms/dc_policy.yml +2 -5
- data/app/forms/dc_poll.yml +10 -16
- data/app/forms/dc_seo.yml +1 -2
- data/app/forms/dc_simple_menu.yml +1 -2
- data/app/forms/dc_site.yml +5 -7
- data/app/helpers/cms_common_helper.rb +2 -3
- data/app/helpers/cms_edit_helper.rb +41 -31
- data/app/helpers/cms_helper.rb +6 -6
- data/app/helpers/cms_index_helper.rb +79 -34
- data/app/helpers/dc_application_helper.rb +99 -85
- data/app/models/concerns/dc_page_concern.rb +3 -2
- data/app/models/concerns/dc_piece_concern.rb +1 -1
- data/app/models/concerns/dc_site_concern.rb +10 -4
- data/app/models/concerns/dc_user_concern.rb +3 -3
- data/app/models/dc_big_table.rb +2 -2
- data/app/models/dc_filter.rb +28 -22
- data/app/models/dc_site.rb +0 -1
- data/app/models/dc_temp.rb +7 -0
- data/app/models/drgcms_form_fields/comment.rb +11 -2
- data/app/models/drgcms_form_fields/date_picker.rb +2 -0
- data/app/models/drgcms_form_fields/drgcms_field.rb +2 -1
- data/app/models/drgcms_form_fields/embedded.rb +4 -2
- data/app/models/drgcms_form_fields/number_field.rb +4 -3
- data/app/models/drgcms_form_fields/readonly.rb +13 -17
- data/app/models/drgcms_form_fields/select.rb +16 -18
- data/app/models/drgcms_form_fields/text_autocomplete.rb +39 -23
- data/app/renderers/dc_page_renderer.rb +7 -6
- data/app/renderers/dc_poll_renderer.rb +16 -20
- data/app/views/cmsedit/_edit_stuff.html.erb +5 -2
- data/app/views/cmsedit/_form.html.erb +3 -2
- data/app/views/cmsedit/_result.html.erb +21 -18
- data/app/views/cmsedit/edit.html.erb +2 -1
- data/app/views/cmsedit/index.html.erb +1 -1
- data/app/views/cmsedit/new.html.erb +3 -2
- data/app/views/dc_common/_help.html.erb +12 -3
- data/app/views/layouts/cms.html.erb +3 -5
- data/config/locales/drgcms_en.yml +5 -2
- data/config/locales/drgcms_sl.yml +5 -2
- data/config/locales/models_en.yml +2 -0
- data/config/locales/models_sl.yml +5 -3
- data/drg_cms.gemspec +16 -16
- data/lib/drg_cms/version.rb +1 -1
- data/lib/drg_cms.rb +46 -12
- metadata +35 -29
@@ -41,9 +41,10 @@
|
|
41
41
|
# its control's would be found in model_embedded_controls.rb. By convention module names
|
42
42
|
# are declared in camel case, so our dc_page_controls.rb declares DrgcmsControls::DcPageControls module.
|
43
43
|
#
|
44
|
-
# Controls (among other) may contain
|
44
|
+
# Controls (among other) may contain 7 callback methods.
|
45
45
|
# These methods are:
|
46
46
|
# * dc_new_record
|
47
|
+
# * dc_dup_record
|
47
48
|
# * dc_before_edit
|
48
49
|
# * dc_before_save
|
49
50
|
# * dc_after_save
|
@@ -67,7 +68,7 @@
|
|
67
68
|
# if dc_user_can(DcPermission::CAN_READ)
|
68
69
|
# dc_page.where(created_by: session[:user_id])
|
69
70
|
# else
|
70
|
-
# flash[:error] = '
|
71
|
+
# flash[:error] = 'User can not perform this operation!'
|
71
72
|
# nil
|
72
73
|
# end
|
73
74
|
# end
|
@@ -76,7 +77,6 @@
|
|
76
77
|
########################################################################
|
77
78
|
class CmseditController < DcApplicationController
|
78
79
|
before_action :check_authorization, :except => [:login, :logout, :test, :run]
|
79
|
-
before_action :dc_reload_patches if Rails.env.development?
|
80
80
|
protect_from_forgery with: :null_session, only: Proc.new { |c| c.request.format.json? }
|
81
81
|
|
82
82
|
layout 'cms'
|
@@ -234,6 +234,7 @@ end
|
|
234
234
|
# duplicating document and is subroutine of create action.
|
235
235
|
########################################################################
|
236
236
|
def duplicate_document(source)
|
237
|
+
params['dup_fields'] += ',' if params['dup_fields'] # for easier field matching
|
237
238
|
dest = {}
|
238
239
|
source.attribute_names.each do |attribute_name|
|
239
240
|
next if attribute_name == '_id' # don't duplicate _id
|
@@ -294,12 +295,11 @@ def create
|
|
294
295
|
end
|
295
296
|
else # duplicate record
|
296
297
|
find_record
|
297
|
-
params['dup_fields'] += ',' if params['dup_fields'] # for easier field matching
|
298
298
|
new_doc = duplicate_document(@record)
|
299
299
|
create_new_empty_record(new_doc)
|
300
|
-
|
300
|
+
if (m = callback_method('dup_record')) then call_callback_method(m) end
|
301
|
+
update_standards
|
301
302
|
@record.save!
|
302
|
-
|
303
303
|
index
|
304
304
|
end
|
305
305
|
end
|
@@ -331,10 +331,8 @@ def update
|
|
331
331
|
end
|
332
332
|
end
|
333
333
|
|
334
|
-
if dc_user_can(DcPermission::CAN_EDIT_ALL)
|
335
|
-
(
|
336
|
-
@record.created_by == session[:user_id] and
|
337
|
-
dc_user_can(DcPermission::CAN_EDIT) )
|
334
|
+
if dc_user_can(DcPermission::CAN_EDIT_ALL) ||
|
335
|
+
(@record.respond_to?('created_by') && @record.created_by == session[:user_id] && dc_user_can(DcPermission::CAN_EDIT))
|
338
336
|
|
339
337
|
if save_data
|
340
338
|
params[:return_to] = 'index' if params[:commit] == t('drgcms.save&back') # save & back
|
@@ -688,7 +686,7 @@ def create_new_empty_record(initial_data = nil) #:nodoc:
|
|
688
686
|
@record = @tables.first[0].new(initial_data)
|
689
687
|
else
|
690
688
|
rec = @tables.first[0].find(@ids.first) # top most record
|
691
|
-
1.upto(@tables.size - 2) { |i| rec = rec.send(@tables[i][1].pluralize).find(@ids[i]) } # find embedded
|
689
|
+
1.upto(@tables.size - 2) { |i| rec = rec.send(@tables[i][1].pluralize).find(@ids[i]) } # find embedded children by ids
|
692
690
|
@record = rec.send(@tables.last[1].pluralize).new(initial_data) # new record
|
693
691
|
end
|
694
692
|
end
|
@@ -715,8 +713,9 @@ end
|
|
715
713
|
########################################################################
|
716
714
|
def save_journal(operation, changes = {})
|
717
715
|
if operation == :delete
|
718
|
-
@record.attributes.each {|k,v| changes[k] = v}
|
716
|
+
@record.attributes.each { |k, v| changes[k] = v }
|
719
717
|
end
|
718
|
+
changes.except!('created_at', 'updated_at', 'created_by', 'updated_by')
|
720
719
|
|
721
720
|
if (operation != :update) || changes.size > 0
|
722
721
|
# determine site_id
|
@@ -740,7 +739,7 @@ end
|
|
740
739
|
# Returns callback method name or nil if not defined.
|
741
740
|
########################################################################
|
742
741
|
def callback_method(key) #:nodoc:
|
743
|
-
data_key = key.gsub('_','-') # convert _ to -
|
742
|
+
data_key = key.gsub('_', '-') # convert _ to -
|
744
743
|
callback = case
|
745
744
|
when params['data'] && params['data'][data_key] then params['data'][data_key]
|
746
745
|
# dc_ + key method is present then call it automatically
|
@@ -784,9 +783,10 @@ end
|
|
784
783
|
def process_return_to(return_to)
|
785
784
|
script = case
|
786
785
|
when return_to == 'index' then return index
|
786
|
+
when return_to.match(/eval=/i) then return_to.sub('eval=', '')
|
787
787
|
when return_to.match(/parent\.reload/i) then 'parent.location.href=parent.location.href;'
|
788
788
|
when return_to.match(/reload/i) then 'location.href=location.href;'
|
789
|
-
when return_to.match(/close/i) then 'window.close();'
|
789
|
+
when return_to.match(/window.close/i) then 'window.close();'
|
790
790
|
when return_to.match(/none/i) then return
|
791
791
|
else "location.href='#{return_to}'"
|
792
792
|
end
|
@@ -830,6 +830,7 @@ def save_data
|
|
830
830
|
value = DrgcmsFormFields.const_get(v['type'].camelize).get_data(params, v['name'])
|
831
831
|
@record.send("#{v['name']}=", value)
|
832
832
|
end
|
833
|
+
|
833
834
|
# before_save callback
|
834
835
|
if (m = callback_method('before_save') )
|
835
836
|
ret = call_callback_method(m)
|
@@ -842,7 +843,7 @@ def save_data
|
|
842
843
|
update_standards() if changes.size > 0 # update only if there has been some changes
|
843
844
|
if (saved = @record.save)
|
844
845
|
operation = @record.new_record? ? :new : :update
|
845
|
-
save_journal(operation,
|
846
|
+
save_journal(operation, @record.previous_changes)
|
846
847
|
# after_save callback
|
847
848
|
if (m = callback_method('after_save') ) then call_callback_method(m) end
|
848
849
|
end
|
@@ -1006,30 +1007,34 @@ end
|
|
1006
1007
|
# Process index action for normal collections.
|
1007
1008
|
########################################################################
|
1008
1009
|
def process_collections #:nodoc
|
1009
|
-
# If result_set is not defined on form, then it will fail. :return_to should know where to go
|
1010
|
+
# If result_set is not defined on form, then it will fail. :return_to should know where to go
|
1010
1011
|
if @form['result_set'].nil?
|
1011
|
-
process_return_to(params[:return_to] || 'reload')
|
1012
|
+
process_return_to(params[:return_to] || 'reload')
|
1012
1013
|
return true
|
1013
1014
|
end
|
1014
|
-
#
|
1015
|
+
# when result set is evaluated as Rails helper
|
1016
|
+
@form['result_set']['type'] ||= 'default'
|
1017
|
+
return unless @form['result_set']['type'] == 'default'
|
1018
|
+
|
1019
|
+
# for now enable only filtering of top level documents
|
1015
1020
|
if @tables.size == 1
|
1016
1021
|
check_filter_options()
|
1017
1022
|
check_sort_options()
|
1018
1023
|
end
|
1019
|
-
# result set is defined by filter method in control object
|
1024
|
+
# result set is defined by filter method in control object
|
1020
1025
|
form_filter = @form['result_set']['filter']
|
1021
1026
|
if form_filter
|
1022
1027
|
if respond_to?(form_filter)
|
1023
1028
|
@records = send(form_filter)
|
1024
|
-
# something went wrong. flash[] should have explanation.
|
1029
|
+
# something went wrong. flash[] should have explanation.
|
1025
1030
|
if @records.class == FalseClass
|
1026
1031
|
@records = []
|
1027
1032
|
render(action: :index)
|
1028
1033
|
return true
|
1029
1034
|
end
|
1030
1035
|
process_select_and_deny_fields
|
1031
|
-
# pagination but only if not already set
|
1032
|
-
unless (@form['table'] == 'dc_memory'
|
1036
|
+
# pagination but only if not already set
|
1037
|
+
unless (@form['table'] == 'dc_memory' || @records.options[:limit])
|
1033
1038
|
per_page = (@form['result_set']['per_page'] || 30).to_i
|
1034
1039
|
@records = @records.page(params[:page]).per(per_page) if per_page > 0
|
1035
1040
|
end
|
@@ -1040,10 +1045,10 @@ def process_collections #:nodoc
|
|
1040
1045
|
if @tables.size > 1
|
1041
1046
|
rec = @tables.first[0].find(@ids.first) # top most document.id
|
1042
1047
|
1.upto(@tables.size - 2) { |i| rec = rec.send(@tables[i][1].pluralize).find(@ids[i]) } # find embedded childrens by ids
|
1043
|
-
# TO DO. When field name is different then pluralized class name. Not working yet.
|
1048
|
+
# TO DO. When field name is different then pluralized class name. Not working yet.
|
1044
1049
|
embedded_field_name = @tables.last[0] ? @tables.last[1].pluralize : @tables.last[1]
|
1045
1050
|
@records = rec.send(embedded_field_name) # current embedded set
|
1046
|
-
# sort by order if order field is present in model
|
1051
|
+
# sort by order if order field is present in model
|
1047
1052
|
if @tables.last[1].classify.constantize.respond_to?(:order)
|
1048
1053
|
@records = @records.order_by('order asc')
|
1049
1054
|
end
|
@@ -26,10 +26,10 @@
|
|
26
26
|
# application controllers.
|
27
27
|
##########################################################################
|
28
28
|
class DcApplicationController < ActionController::Base
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
protect_from_forgery with: :null_session, only: Proc.new { |c| c.request.format.json? }
|
30
|
+
before_action :dc_reload_patches if Rails.env.development?
|
31
|
+
before_action :dc_set_locale
|
32
|
+
|
33
33
|
########################################################################
|
34
34
|
# Writes anything passed as parameter to logger file.
|
35
35
|
# Very useful for debuging strange errors.
|
@@ -54,9 +54,9 @@ end
|
|
54
54
|
####################################################################
|
55
55
|
# Checks if user has required role.
|
56
56
|
#
|
57
|
-
# @param [DcPolicyRole] role can be passed as DcPolicyRole object or
|
58
|
-
#
|
59
|
-
#
|
57
|
+
# @param [DcPolicyRole or String] role can be passed as DcPolicyRole object or
|
58
|
+
# as role name. If passed as name, dc_policy_roles is searched for appropriate role.
|
59
|
+
#
|
60
60
|
# @return [Boolean] True if user has required role added to his profile.
|
61
61
|
#
|
62
62
|
# @example If user has required role
|
@@ -153,7 +153,7 @@ end
|
|
153
153
|
# Will write document to dc_visits collection unless visit comes from robot.
|
154
154
|
# It also sets session[is_robot] variable to true if robot.
|
155
155
|
########################################################################
|
156
|
-
def dc_log_visit
|
156
|
+
def dc_log_visit
|
157
157
|
if request.env["HTTP_USER_AGENT"] and request.env["HTTP_USER_AGENT"].match(/\(.*https?:\/\/.*\)/)
|
158
158
|
logger.info "ROBOT: #{Time.now.strftime('%Y.%m.%d %H:%M:%S')} id=#{@page.id} ip=#{request.remote_ip}."
|
159
159
|
session[:is_robot] = true
|
@@ -173,8 +173,8 @@ protected
|
|
173
173
|
# Checks if user can perform (read, create, edit, delete) document in specified
|
174
174
|
# table (collection).
|
175
175
|
#
|
176
|
-
# @param [Integer] Required permission level
|
177
|
-
# @param [String] Collection (table) name for which permission is queried. Defaults to params[table].
|
176
|
+
# @param [Integer] permission: Required permission level
|
177
|
+
# @param [String] table: Collection (table) name for which permission is queried. Defaults to params[table].
|
178
178
|
#
|
179
179
|
# @return [Boolean] true if user's role permits (is higher or equal then required) operation on a table (collection).
|
180
180
|
#
|
@@ -182,19 +182,14 @@ protected
|
|
182
182
|
# if dc_user_can(DcPermission::CAN_VIEW, params[:table]) then ...
|
183
183
|
############################################################################
|
184
184
|
def dc_user_can(permission, table = params[:table])
|
185
|
-
|
186
|
-
session[:user_roles].each {|r| return true if permissions[r] && permissions[r] >= permission }
|
187
|
-
false
|
188
|
-
end
|
189
|
-
|
190
|
-
def dc_user_can(permission, table = params[:table])
|
185
|
+
table = table.underscore
|
191
186
|
cache_key = ['dc_permission', table, session[:user_id], dc_get_site.id]
|
192
187
|
permissions = dc_cache_read(cache_key)
|
193
188
|
if permissions.nil?
|
194
189
|
permissions = DcPermission.permissions_for_table(table)
|
195
190
|
dc_cache_write(cache_key, permissions)
|
196
191
|
end
|
197
|
-
session[:user_roles].each {|r| return true if permissions[r] && permissions[r] >= permission }
|
192
|
+
session[:user_roles].each { |r| return true if permissions[r] && permissions[r] >= permission }
|
198
193
|
false
|
199
194
|
end
|
200
195
|
|
@@ -216,33 +211,22 @@ def dc_cache_read(keys)
|
|
216
211
|
end
|
217
212
|
end
|
218
213
|
|
219
|
-
def __dc_cache_read(keys)
|
220
|
-
p 'read', keys.join(''), Rails.cache.instance_variable_get(:@data).keys
|
221
|
-
pp Rails.cache.read(keys.join(''))
|
222
|
-
end
|
223
|
-
|
224
214
|
####################################################################
|
225
215
|
# Write data to cache
|
226
216
|
#
|
227
|
-
# @param [Array] Array of keys
|
228
|
-
# @param [Object] Data written to cache
|
217
|
+
# @param [Array] keys: Array of keys
|
218
|
+
# @param [Object] data: Data written to cache
|
229
219
|
#
|
230
220
|
# @return [Object] data so dc_cache_write can be used as last statement in method.
|
231
221
|
####################################################################
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
end
|
240
|
-
data
|
222
|
+
def dc_cache_write(keys, data)
|
223
|
+
if redis_cache_store?
|
224
|
+
keys = keys.dup
|
225
|
+
first = keys.shift
|
226
|
+
redis.hset(first, keys.join(''), Marshal.dump(data))
|
227
|
+
else
|
228
|
+
Rails.cache.write(keys.join(''), data)
|
241
229
|
end
|
242
|
-
|
243
|
-
def __dc_cache_write(keys, data)
|
244
|
-
p 'write', keys.join('')
|
245
|
-
pp Rails.cache.write(keys.join(''), data)
|
246
230
|
data
|
247
231
|
end
|
248
232
|
|
@@ -256,8 +240,8 @@ def dc_set_is_mobile
|
|
256
240
|
is_mobile = request.user_agent ? /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.match(request.user_agent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.match(request.user_agent[0..3])
|
257
241
|
: false
|
258
242
|
session[:is_mobile] = is_mobile ? 1 : 0
|
259
|
-
|
260
|
-
if request.env["HTTP_USER_AGENT "]
|
243
|
+
|
244
|
+
if request.env["HTTP_USER_AGENT "] && request.env["HTTP_USER_AGENT"].match(/\(.*https?:\/\/.*\)/)
|
261
245
|
logger.info "ROBOT: #{Time.now.strftime('%Y.%m.%d %H:%M:%S')} id=#{@page.id} ip=#{request.remote_ip}."
|
262
246
|
session[:is_robot] = true
|
263
247
|
end
|
@@ -266,24 +250,14 @@ end
|
|
266
250
|
##########################################################################
|
267
251
|
# Merge values from parameters fields (from site, page ...) into internal @options hash.
|
268
252
|
#
|
269
|
-
# @param [String] YAML string.
|
253
|
+
# @param [String] parameters: passed as YAML string.
|
270
254
|
##########################################################################
|
271
255
|
def dc_set_options(parameters)
|
272
256
|
@options ||= {}
|
273
257
|
return if parameters.to_s.size < 3
|
274
|
-
# parameters are set
|
275
|
-
parms = YAML.load(parameters) rescue
|
276
|
-
|
277
|
-
parms = {}
|
278
|
-
parameters.split("\n").each do |line|
|
279
|
-
line.chomp.split(',').each do |parm|
|
280
|
-
key, value = parm.split(':')
|
281
|
-
value = value.to_s.strip.gsub(/\'|\"/,'')
|
282
|
-
parms[key.strip] = (value == '/' ? nil : value)
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
@options.merge!(parms)
|
258
|
+
# parameters are set as YAML. This should be default in future.
|
259
|
+
parms = YAML.load(parameters) rescue {}
|
260
|
+
@options = @options.deep_merge(parms)
|
287
261
|
end
|
288
262
|
|
289
263
|
##########################################################################
|
@@ -296,7 +270,6 @@ end
|
|
296
270
|
# @return [Boolean] true when none of documents is changed.
|
297
271
|
##########################################################################
|
298
272
|
def dc_not_modified?(*documents)
|
299
|
-
# request.env.each {|k,v| p k,'*',v}
|
300
273
|
return false unless request.env.include? 'HTTP_IF_MODIFIED_SINCE'
|
301
274
|
|
302
275
|
since_date = Time.parse request.env['HTTP_IF_MODIFIED_SINCE']
|
@@ -305,7 +278,7 @@ def dc_not_modified?(*documents)
|
|
305
278
|
next unless doc.respond_to?(:updated_at)
|
306
279
|
last_modified = doc.updated_at if doc.updated_at > last_modified
|
307
280
|
end
|
308
|
-
|
281
|
+
|
309
282
|
if last_modified >= since_date then
|
310
283
|
render :nothing => true, :status => 304
|
311
284
|
return true
|
@@ -324,13 +297,13 @@ def get_design_and_render(design_doc)
|
|
324
297
|
layout = @site.site_layout.blank? ? 'content' : @site.site_layout
|
325
298
|
site_top = '<%= dc_page_top %>'
|
326
299
|
site_bottom = '<%= dc_page_bottom %>'
|
327
|
-
# lets try the rails way
|
300
|
+
# lets try the rails way
|
328
301
|
if @options[:control] && @options[:action]
|
329
302
|
controller = "#{@options[:control]}_control".classify.constantize rescue nil
|
330
303
|
extend controller if controller
|
331
304
|
return send @options[:action] if respond_to?(@options[:action])
|
332
305
|
end
|
333
|
-
# design doc present
|
306
|
+
# design doc present
|
334
307
|
if design_doc
|
335
308
|
# defined as rails view
|
336
309
|
design = if design_doc.rails_view.blank? || design_doc.rails_view == 'site'
|
@@ -344,7 +317,7 @@ def get_design_and_render(design_doc)
|
|
344
317
|
design = site_top + design + site_bottom
|
345
318
|
return render(inline: design, layout: layout) unless design.blank?
|
346
319
|
end
|
347
|
-
# Design doc not defined
|
320
|
+
# Design doc not defined
|
348
321
|
if @site.rails_view.blank?
|
349
322
|
design = site_top + @site.design + site_bottom
|
350
323
|
render(inline: design, layout: layout)
|
@@ -384,6 +357,7 @@ def dc_process_default_request
|
|
384
357
|
params[:path] = @options[:path].first if @options[:path].size > 1
|
385
358
|
# some other process request. It should fail if not defined
|
386
359
|
return send(@site.request_processor) unless @site.request_processor.blank?
|
360
|
+
|
387
361
|
# Search for page
|
388
362
|
pageclass = @site.page_klass
|
389
363
|
if params[:id]
|
@@ -405,6 +379,7 @@ def dc_process_default_request
|
|
405
379
|
end
|
406
380
|
# if @page is not found render 404 error
|
407
381
|
return dc_render_404('Page!') unless @page
|
382
|
+
|
408
383
|
dc_set_is_mobile unless session[:is_mobile] # do it only once per session
|
409
384
|
# find design if defined. Otherwise design MUST be declared in site
|
410
385
|
if @page.dc_design_id
|
@@ -427,8 +402,7 @@ def dc_process_default_request
|
|
427
402
|
get_design_and_render @design
|
428
403
|
end
|
429
404
|
|
430
|
-
|
431
|
-
# ####################################################################
|
405
|
+
###########################################################################
|
432
406
|
# Single site document kind of request handler.
|
433
407
|
#
|
434
408
|
# This request handler assumes that all data for the site is saved in the site document.
|
@@ -444,18 +418,17 @@ def dc_single_sitedoc_request
|
|
444
418
|
if @site.nil?
|
445
419
|
session[:edit_mode] ||= 0
|
446
420
|
@site = dc_get_site
|
447
|
-
|
421
|
+
# @site is not defined. render 404 error
|
448
422
|
return dc_render_404('Site!') unless @site
|
423
|
+
|
449
424
|
dc_set_options(@site.settings)
|
450
425
|
end
|
451
|
-
# HOMEPAGE. When no parameters is set
|
426
|
+
# HOMEPAGE. When no parameters is set
|
452
427
|
params[:path] = @site.homepage_link if params[:path].nil?
|
453
428
|
@parts = @site.dc_parts
|
454
429
|
@part = @parts.find_by(link: params[:path])
|
455
430
|
return dc_render_404('Part!') unless @part
|
456
|
-
|
457
|
-
# return if dc_not_modified?(@site, @part)
|
458
|
-
#
|
431
|
+
|
459
432
|
@page_title = "#{@site.page_title} #{@part.name}"
|
460
433
|
@js, @css = '', ''
|
461
434
|
get_design_and_render nil
|
@@ -466,46 +439,36 @@ end
|
|
466
439
|
# very good with non ascii chars. Since this method is used for converting from model
|
467
440
|
# to collection names it is very unwise to use non ascii chars for table (collection) names.
|
468
441
|
#
|
469
|
-
# @param [
|
470
|
-
#
|
442
|
+
# @param [Object] model_string to be converted
|
443
|
+
#
|
471
444
|
# @example
|
472
445
|
# decamelize_type(ModelName) # 'ModelName' => 'model_name'
|
473
446
|
########################################################################
|
474
|
-
def decamelize_type(
|
475
|
-
|
476
|
-
r = ''
|
477
|
-
string.to_s.each_char do |c|
|
478
|
-
r << case
|
479
|
-
when r.size == 0 then c.downcase
|
480
|
-
when c.downcase != c then '_' + c.downcase
|
481
|
-
else c
|
482
|
-
end
|
483
|
-
end
|
484
|
-
r
|
447
|
+
def decamelize_type(model_string)
|
448
|
+
model_string ? model_string.underscore : nil
|
485
449
|
end
|
486
450
|
|
487
451
|
####################################################################
|
488
452
|
# Return's error messages for the document formated for display on edit form.
|
489
453
|
#
|
490
|
-
# @param [Document]
|
491
|
-
#
|
454
|
+
# @param [Document] document object which will be examined for errors.
|
455
|
+
#
|
492
456
|
# @return [String] HTML code for displaying error on edit form.
|
493
457
|
####################################################################
|
494
458
|
def dc_error_messages_for(document)
|
495
459
|
return '' unless document.errors.any?
|
460
|
+
|
496
461
|
msg = ''
|
497
|
-
document.errors.each do |
|
498
|
-
label = t("helpers.label.#{decamelize_type(document.class)}.#{attribute}")
|
499
|
-
msg << "<li>#{label} : #{
|
462
|
+
document.errors.each do |error|
|
463
|
+
label = t("helpers.label.#{decamelize_type(document.class)}.#{error.attribute}", error.attribute)
|
464
|
+
msg << "<li>#{label} : #{error.message}</li>"
|
500
465
|
end
|
501
466
|
|
502
|
-
|
467
|
+
%(
|
503
468
|
<div class="dc-form-error">
|
504
469
|
<h2>#{t('drgcms.errors_no')} #{document.errors.size}</h2>
|
505
470
|
<ul>#{msg}</ul>
|
506
|
-
</div>
|
507
|
-
eot
|
508
|
-
html.html_safe
|
471
|
+
</div>).html_safe
|
509
472
|
end
|
510
473
|
|
511
474
|
####################################################################
|
@@ -514,8 +477,8 @@ end
|
|
514
477
|
# model errors or when saving to multiple collections and where each save must be
|
515
478
|
# checked if succesfull.
|
516
479
|
#
|
517
|
-
# @param [Document] Document object
|
518
|
-
# @param [Boolean] If true method should end in runtime error. Default = false.
|
480
|
+
# @param [Document] document: Document object to be checked
|
481
|
+
# @param [Boolean] crash: If true method should end in runtime error. Default = false.
|
519
482
|
#
|
520
483
|
# @return [String] Error messages or empty string if everything is OK.
|
521
484
|
#
|
@@ -527,16 +490,16 @@ end
|
|
527
490
|
# end
|
528
491
|
#
|
529
492
|
####################################################################
|
530
|
-
def dc_check_model(document, crash=false)
|
531
|
-
DrgCms.
|
493
|
+
def dc_check_model(document, crash = false)
|
494
|
+
DrgCms.model_check(document, crash)
|
532
495
|
end
|
533
496
|
|
534
497
|
######################################################################
|
535
498
|
# Call rake task from controller.
|
536
499
|
#
|
537
|
-
# @param [String] Rake task name
|
538
|
-
# @param [Hash] Options that will be send to task as environment variables
|
539
|
-
#
|
500
|
+
# @param [String] task: Rake task name
|
501
|
+
# @param [Hash] options: Options that will be send to task as environment variables
|
502
|
+
#
|
540
503
|
# @example Call rake task from application
|
541
504
|
# dc_call_rake('clear:all', some_parm: some_id)
|
542
505
|
######################################################################
|
@@ -551,7 +514,7 @@ end
|
|
551
514
|
# made from DRG CMS form return may be quite complicated. All ajax return combinations
|
552
515
|
# can be found in drg_cms.js file.
|
553
516
|
#
|
554
|
-
# @param [Hash] Options
|
517
|
+
# @param [Hash] opts: Options
|
555
518
|
#
|
556
519
|
# @return [JSON Response] Formatted to be used for ajax return.
|
557
520
|
#
|
@@ -616,6 +579,20 @@ def dc_reload_patches
|
|
616
579
|
end
|
617
580
|
end
|
618
581
|
|
582
|
+
########################################################################
|
583
|
+
# Will set new default locale for application
|
584
|
+
#
|
585
|
+
# @param [String] new_locale : New locale value. If omitted it will be provided from params[:locale].
|
586
|
+
# if new_locale value is 00, application's default_locale will be used.
|
587
|
+
########################################################################
|
588
|
+
def dc_set_locale(new_locale = nil)
|
589
|
+
new_locale ||= params[:locale]
|
590
|
+
if new_locale && new_locale != session[:locale]
|
591
|
+
session[:locale] = new_locale == '00' ? nil : new_locale.to_sym
|
592
|
+
end
|
593
|
+
I18n.locale = session[:locale] ? session[:locale] : I18n.default_locale
|
594
|
+
end
|
595
|
+
|
619
596
|
############################################################################
|
620
597
|
# Writes out deprication msg. It also adds site_name to message, so it is easier to
|
621
598
|
# find where the message is comming from.
|
@@ -643,51 +620,6 @@ def set_default_guest_user_role
|
|
643
620
|
session[:user_roles] = [guest.id] if guest
|
644
621
|
end
|
645
622
|
|
646
|
-
####################################################################
|
647
|
-
# Fills session with data related to successful login.
|
648
|
-
#
|
649
|
-
# @param [DcUser] user : User's document
|
650
|
-
# @param [Boolean] remember_me : false by default
|
651
|
-
####################################################################
|
652
|
-
def fill_login_data(user, remember_me=false)
|
653
|
-
session[:user_id] = user.id if user
|
654
|
-
session[:user_name] = user.name if user
|
655
|
-
session[:edit_mode] = 0
|
656
|
-
session[:user_roles] = []
|
657
|
-
# Every user has guest role
|
658
|
-
# guest = DcPolicyRole.find_by(system_name: 'guest')
|
659
|
-
# session[:user_roles] << guest.id if guest
|
660
|
-
set_default_guest_user_role
|
661
|
-
return unless user and user.active
|
662
|
-
# special for SUPERADMIN
|
663
|
-
sa = DcPolicyRole.find_by(system_name: 'superadmin')
|
664
|
-
if sa and (role = user.dc_user_roles.find_by(dc_policy_role_id: sa.id))
|
665
|
-
session[:user_roles] << role.dc_policy_role_id
|
666
|
-
session[:edit_mode] = 2
|
667
|
-
return
|
668
|
-
end
|
669
|
-
# read default policy from site. Policy might be inherited
|
670
|
-
policy_site = dc_get_site()
|
671
|
-
policy_site = DcSite.find(policy_site.inherit_policy) if policy_site.inherit_policy
|
672
|
-
default_policy = policy_site.dc_policies.find_by(is_default: true)
|
673
|
-
# load user roles
|
674
|
-
user.dc_user_roles.each do |role|
|
675
|
-
next unless role.active
|
676
|
-
next if role.valid_from and role.valid_from > Time.now.end_of_day.to_date
|
677
|
-
next if role.valid_to and role.valid_to < Time.now.to_date
|
678
|
-
# check if role is active in this site
|
679
|
-
policy_role = default_policy.dc_policy_rules.find_by(dc_policy_role_id: role.dc_policy_role_id)
|
680
|
-
next unless policy_role
|
681
|
-
# set edit_mode
|
682
|
-
session[:edit_mode] = 1 if policy_role.permission > 1
|
683
|
-
session[:user_roles] << role.dc_policy_role_id
|
684
|
-
end
|
685
|
-
# Save remember me cookie if not CMS user and remember me is selected
|
686
|
-
if session[:edit_mode] == 0 and remember_me
|
687
|
-
cookies.signed[:remember_me] = { :value => user.id, :expires => 180.days.from_now}
|
688
|
-
end
|
689
|
-
end
|
690
|
-
|
691
623
|
####################################################################
|
692
624
|
# Fills session with data related to successful login.
|
693
625
|
#
|
@@ -696,7 +628,7 @@ end
|
|
696
628
|
####################################################################
|
697
629
|
def fill_login_data(user, remember_me = false)
|
698
630
|
session[:user_id] = user.id if user
|
699
|
-
session[:user_name] = user.name if user
|
631
|
+
session[:user_name] = user.name.squish if user
|
700
632
|
session[:edit_mode] = 0
|
701
633
|
set_default_guest_user_role
|
702
634
|
return unless user&.active
|
@@ -771,7 +703,7 @@ end
|
|
771
703
|
# Evaluates Class.method in more predictable context then just calling eval
|
772
704
|
#
|
773
705
|
# @param [String] class_method defined as MyClass.method_name
|
774
|
-
# @param [Object] optional parameters send to class_method
|
706
|
+
# @param [Object] params: optional parameters send to class_method
|
775
707
|
##########################################################################
|
776
708
|
def dc_eval_class_method(class_method, params = nil)
|
777
709
|
klass, method = class_method.split('.')
|
@@ -823,28 +755,9 @@ def dc_add_meta_tag(type, name, content)
|
|
823
755
|
end
|
824
756
|
|
825
757
|
########################################################################
|
826
|
-
# Will prepare flash[:update] data, which
|
827
|
-
# on forms parent form fields.
|
828
|
-
#
|
829
|
-
# Parameters:
|
830
|
-
# [field_name] String: Field name
|
831
|
-
# [value] String: New value
|
832
|
-
# [readonly] Boolean: Field is readonly
|
833
|
-
#
|
834
|
-
########################################################################
|
835
|
-
def dc_update_form_field(field_name, value, readonly=false)
|
836
|
-
dc_deprecate('dc_update_form_field will be deprecated. Use dc_update_form_element instead.')
|
837
|
-
key_name = (readonly ? 'td_' : '') + "record_#{field_name}"
|
838
|
-
flash[:update] ||= {}
|
839
|
-
flash[:update][key_name] = value
|
840
|
-
end
|
841
|
-
|
842
|
-
########################################################################
|
843
|
-
# Will prepare flash[:update] data, which will be used for updating elements
|
758
|
+
# Will prepare flash[:update] data, which is used for updating elements
|
844
759
|
# on parent form.
|
845
760
|
#
|
846
|
-
# dc_update_form_field will be deprecated eventually.
|
847
|
-
#
|
848
761
|
# Parameters passed as hash:
|
849
762
|
# [field] String: Field name
|
850
763
|
# [head] String: Filed name in head of form
|
@@ -858,11 +771,10 @@ def dc_update_form_element(field: nil, head: nil, value:, readonly: true)
|
|
858
771
|
elsif head
|
859
772
|
"head-#{head}"
|
860
773
|
end
|
774
|
+
return if key.nil?
|
861
775
|
|
862
|
-
|
863
|
-
|
864
|
-
flash[:update][key] = value
|
865
|
-
end
|
776
|
+
flash[:update] ||= {}
|
777
|
+
flash[:update][key] = value
|
866
778
|
end
|
867
779
|
|
868
780
|
####################################################################
|