barkest_core 1.5.3.0
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.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +254 -0
- data/MIT-LICENSE +20 -0
- data/README.md +364 -0
- data/Rakefile +37 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-Bold.ttf +0 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-BoldItalic.ttf +0 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-Italic.ttf +0 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-Regular.ttf +0 -0
- data/app/assets/images/barkest_core/.keep +0 -0
- data/app/assets/images/barkest_core/barcode-B.svg +181 -0
- data/app/assets/javascripts/barkest_core/.keep +0 -0
- data/app/assets/javascripts/barkest_core/application.js +22 -0
- data/app/assets/javascripts/barkest_core/bootstrap-datepicker.js +1800 -0
- data/app/assets/javascripts/barkest_core/field_init.js +7 -0
- data/app/assets/javascripts/barkest_core/jquery.doubleScroll.js +112 -0
- data/app/assets/javascripts/barkest_core/masked_edit.js +25 -0
- data/app/assets/javascripts/barkest_core/system_status.js.erb +201 -0
- data/app/assets/stylesheets/barkest_core/.keep +0 -0
- data/app/assets/stylesheets/barkest_core/application.css +17 -0
- data/app/assets/stylesheets/barkest_core/custom.css.scss +264 -0
- data/app/assets/stylesheets/barkest_core/datepicker3.css +790 -0
- data/app/controllers/.keep +0 -0
- data/app/controllers/access_groups_controller.rb +74 -0
- data/app/controllers/account_activations_controller.rb +29 -0
- data/app/controllers/application_controller.rb +5 -0
- data/app/controllers/barkest_core/application_controller_base.rb +113 -0
- data/app/controllers/barkest_core/engine_controller_base.rb +15 -0
- data/app/controllers/barkest_core/testsub_controller.rb +21 -0
- data/app/controllers/contact_controller.rb +32 -0
- data/app/controllers/log_view_controller.rb +31 -0
- data/app/controllers/password_resets_controller.rb +126 -0
- data/app/controllers/sessions_controller.rb +64 -0
- data/app/controllers/status_controller.rb +150 -0
- data/app/controllers/system_config_controller.rb +238 -0
- data/app/controllers/system_update_controller.rb +164 -0
- data/app/controllers/test_access_controller.rb +44 -0
- data/app/controllers/test_report_controller.rb +75 -0
- data/app/controllers/users_controller.rb +218 -0
- data/app/helpers/.keep +0 -0
- data/app/helpers/barkest_core/application_helper.rb +134 -0
- data/app/helpers/barkest_core/form_helper.rb +469 -0
- data/app/helpers/barkest_core/html_helper.rb +70 -0
- data/app/helpers/barkest_core/misc_helper.rb +68 -0
- data/app/helpers/barkest_core/pdf_helper.rb +180 -0
- data/app/helpers/barkest_core/recaptcha_helper.rb +115 -0
- data/app/helpers/barkest_core/sessions_helper.rb +94 -0
- data/app/helpers/barkest_core/status_helper.rb +118 -0
- data/app/helpers/barkest_core/users_helper.rb +32 -0
- data/app/mailers/.keep +0 -0
- data/app/mailers/application_mailer.rb +5 -0
- data/app/mailers/barkest_core/application_mailer_base.rb +30 -0
- data/app/mailers/barkest_core/contact_form.rb +20 -0
- data/app/mailers/barkest_core/user_mailer.rb +44 -0
- data/app/models/.keep +0 -0
- data/app/models/access_group.rb +121 -0
- data/app/models/access_group_group_member.rb +13 -0
- data/app/models/access_group_user_member.rb +11 -0
- data/app/models/barkest_core/auth_config.rb +95 -0
- data/app/models/barkest_core/authorize_failure.rb +7 -0
- data/app/models/barkest_core/contact_message.rb +37 -0
- data/app/models/barkest_core/database_config.rb +223 -0
- data/app/models/barkest_core/db_table.rb +21 -0
- data/app/models/barkest_core/email_config.rb +132 -0
- data/app/models/barkest_core/global_status.rb +267 -0
- data/app/models/barkest_core/log_entry.rb +101 -0
- data/app/models/barkest_core/log_view_options.rb +51 -0
- data/app/models/barkest_core/ms_sql_db_definition.rb +441 -0
- data/app/models/barkest_core/ms_sql_definition.rb +221 -0
- data/app/models/barkest_core/ms_sql_function.rb +423 -0
- data/app/models/barkest_core/not_logged_in.rb +7 -0
- data/app/models/barkest_core/pdf_table_builder.rb +407 -0
- data/app/models/barkest_core/self_update_config.rb +37 -0
- data/app/models/barkest_core/user_alert.rb +29 -0
- data/app/models/barkest_core/user_alert_generators.rb +58 -0
- data/app/models/barkest_core/user_manager.rb +404 -0
- data/app/models/barkest_core/work_path.rb +74 -0
- data/app/models/disable_user.rb +18 -0
- data/app/models/ldap_access_group.rb +15 -0
- data/app/models/system_config.rb +99 -0
- data/app/models/user.rb +405 -0
- data/app/models/user_login_history.rb +11 -0
- data/app/views/.keep +0 -0
- data/app/views/access_groups/_form.html.erb +19 -0
- data/app/views/access_groups/edit.html.erb +2 -0
- data/app/views/access_groups/index.html.erb +32 -0
- data/app/views/access_groups/new.html.erb +2 -0
- data/app/views/access_groups/show.html.erb +4 -0
- data/app/views/barkest_core/contact_form/contact.html.erb +16 -0
- data/app/views/barkest_core/contact_form/contact.text.erb +13 -0
- data/app/views/barkest_core/testsub/_links.html.erb +5 -0
- data/app/views/barkest_core/testsub/page1.html.erb +3 -0
- data/app/views/barkest_core/testsub/page2.html.erb +2 -0
- data/app/views/barkest_core/testsub/page3.html.erb +2 -0
- data/app/views/barkest_core/user_mailer/account_activation.html.erb +7 -0
- data/app/views/barkest_core/user_mailer/account_activation.text.erb +6 -0
- data/app/views/barkest_core/user_mailer/invalid_password_reset.html.erb +3 -0
- data/app/views/barkest_core/user_mailer/invalid_password_reset.text.erb +5 -0
- data/app/views/barkest_core/user_mailer/password_reset.html.erb +8 -0
- data/app/views/barkest_core/user_mailer/password_reset.text.erb +7 -0
- data/app/views/contact/index.html.erb +24 -0
- data/app/views/layouts/_footer_copyright.html.erb +1 -0
- data/app/views/layouts/_menu_admin.html.erb +5 -0
- data/app/views/layouts/_menu_anon.html.erb +0 -0
- data/app/views/layouts/_menu_auth.html.erb +3 -0
- data/app/views/layouts/_menu_footer.html.erb +1 -0
- data/app/views/layouts/_nav_logo.html.erb +1 -0
- data/app/views/layouts/application.html.erb +2 -0
- data/app/views/layouts/barkest_core/_application.html.erb +24 -0
- data/app/views/layouts/barkest_core/_footer.html.erb +18 -0
- data/app/views/layouts/barkest_core/_header.html.erb +38 -0
- data/app/views/layouts/barkest_core/_html_mailer.html.erb +11 -0
- data/app/views/layouts/barkest_core/_menu_account.html.erb +14 -0
- data/app/views/layouts/barkest_core/_menu_sample.html.erb +1 -0
- data/app/views/layouts/barkest_core/_messages.html.erb +4 -0
- data/app/views/layouts/barkest_core/_shim.html.erb +4 -0
- data/app/views/layouts/barkest_core/_subheader.html.erb +1 -0
- data/app/views/layouts/barkest_core/_text_mailer.text.erb +4 -0
- data/app/views/layouts/mailer.html.erb +1 -0
- data/app/views/layouts/mailer.text.erb +1 -0
- data/app/views/log_view/index.html.erb +100 -0
- data/app/views/password_resets/edit.html.erb +20 -0
- data/app/views/password_resets/new.html.erb +14 -0
- data/app/views/sessions/new.html.erb +27 -0
- data/app/views/shared/_error_messages.html.erb +29 -0
- data/app/views/shared/_generic_user_alert.html.erb +4 -0
- data/app/views/status/current.html.erb +34 -0
- data/app/views/status/test.html.erb +50 -0
- data/app/views/system_config/index.html.erb +25 -0
- data/app/views/system_config/show_auth.html.erb +28 -0
- data/app/views/system_config/show_database.html.erb +36 -0
- data/app/views/system_config/show_email.html.erb +21 -0
- data/app/views/system_config/show_self_update.html.erb +13 -0
- data/app/views/system_update/index.html.erb +31 -0
- data/app/views/system_update/new.html.erb +2 -0
- data/app/views/test_access/allow_anon.html.erb +2 -0
- data/app/views/test_access/require_admin.html.erb +2 -0
- data/app/views/test_access/require_group_x.html.erb +2 -0
- data/app/views/test_access/require_user.html.erb +2 -0
- data/app/views/test_report/index.csv.csvrb +23 -0
- data/app/views/test_report/index.html.erb +6 -0
- data/app/views/test_report/index.pdf.prawn +50 -0
- data/app/views/test_report/index.xlsx.axlsx +28 -0
- data/app/views/users/_user.html.erb +57 -0
- data/app/views/users/_user_details.html.erb +15 -0
- data/app/views/users/_user_details_for_list.html.erb +1 -0
- data/app/views/users/_user_form.html.erb +13 -0
- data/app/views/users/disable_confirm.html.erb +19 -0
- data/app/views/users/edit.html.erb +15 -0
- data/app/views/users/index.html.erb +9 -0
- data/app/views/users/new.html.erb +10 -0
- data/app/views/users/show.html.erb +46 -0
- data/bin/rails +12 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20160617172539_create_access_groups.rb +10 -0
- data/db/migrate/20160617172725_create_users.rb +26 -0
- data/db/migrate/20160617172833_create_user_login_histories.rb +12 -0
- data/db/migrate/20160622151720_create_access_group_user_members.rb +9 -0
- data/db/migrate/20160622151925_create_access_group_group_members.rb +9 -0
- data/db/migrate/20160701005706_create_ldap_access_groups.rb +11 -0
- data/db/migrate/20161108155029_create_system_configs.rb +11 -0
- data/db/seeds/barkest_core_01_create_users.rb +42 -0
- data/db/seeds.rb +53 -0
- data/lib/barkest_core/concerns/association_with_defaults.rb +55 -0
- data/lib/barkest_core/concerns/boolean_parser.rb +88 -0
- data/lib/barkest_core/concerns/date_parser.rb +181 -0
- data/lib/barkest_core/concerns/email_tester.rb +55 -0
- data/lib/barkest_core/concerns/encrypted_fields.rb +156 -0
- data/lib/barkest_core/concerns/named_model.rb +73 -0
- data/lib/barkest_core/concerns/number_parser.rb +145 -0
- data/lib/barkest_core/concerns/utc_conversion.rb +60 -0
- data/lib/barkest_core/engine.rb +105 -0
- data/lib/barkest_core/extensions/active_record_extensions.rb +120 -0
- data/lib/barkest_core/extensions/application_configuration_extensions.rb +38 -0
- data/lib/barkest_core/extensions/application_extensions.rb +50 -0
- data/lib/barkest_core/extensions/axlsx_extenstions.rb +157 -0
- data/lib/barkest_core/extensions/fixture_set_extensions.rb +107 -0
- data/lib/barkest_core/extensions/generator_extensions.rb +271 -0
- data/lib/barkest_core/extensions/main_app_extensions.rb +35 -0
- data/lib/barkest_core/extensions/prawn_document_extensions.rb +367 -0
- data/lib/barkest_core/extensions/prawn_table_extensions.rb +131 -0
- data/lib/barkest_core/extensions/router_extensions.rb +106 -0
- data/lib/barkest_core/extensions/simple_formatter_extensions.rb +66 -0
- data/lib/barkest_core/extensions/test_case_extensions.rb +348 -0
- data/lib/barkest_core/extensions/time_extensions.rb +164 -0
- data/lib/barkest_core/handlers/csv_handler.rb +30 -0
- data/lib/barkest_core/version.rb +3 -0
- data/lib/barkest_core.rb +324 -0
- data/lib/generators/barkest/install_generator.rb +102 -0
- data/lib/generators/barkest_core/actions/01_patch_application_controller.rb +55 -0
- data/lib/generators/barkest_core/actions/02_patch_application_mailer.rb +56 -0
- data/lib/generators/barkest_core/actions/03_patch_assets.rb +62 -0
- data/lib/generators/barkest_core/actions/04_patch_layouts.rb +36 -0
- data/lib/generators/barkest_core/actions/05_patch_routes.rb +93 -0
- data/lib/generators/barkest_core/actions/06_patch_seeds.rb +60 -0
- data/lib/generators/barkest_core/actions/07_copy_migrations.rb +51 -0
- data/lib/generators/barkest_core/actions/08_configure_database.rb +52 -0
- data/lib/generators/barkest_core/actions/09_configure_secrets.rb +29 -0
- data/lib/generators/barkest_core/actions/99_patch_gitignore.rb +57 -0
- data/lib/generators/barkest_core/install_generator.rb +17 -0
- data/test/barkest_core_test.rb +83 -0
- data/test/controllers/access_groups_controller_test.rb +53 -0
- data/test/controllers/contact_controller_test.rb +10 -0
- data/test/controllers/sessions_controller_test.rb +10 -0
- data/test/controllers/users_controller_test.rb +10 -0
- data/test/dummy/.gitignore +10 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +14 -0
- data/test/dummy/app/assets/stylesheets/application.css +16 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/mailers/application_mailer.rb +3 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +1 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +1 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/app/views/system_config/show_fake.html.erb +3 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config/application.rb +27 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +47 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +44 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/db_updater_ext.rb +33 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/sys_config_ext.rb +12 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +60 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/schema.rb +95 -0
- data/test/dummy/db/seeds/barkest_core_01_create_users.rb +42 -0
- data/test/dummy/db/seeds.rb +51 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/sql/my_test_view.sql +3 -0
- data/test/fixtures/access_groups.yml +21 -0
- data/test/fixtures/users.yml +71 -0
- data/test/helpers/barkest_core/sessions_helper_test.rb +22 -0
- data/test/integration/access_group_mgmt_test.rb +33 -0
- data/test/integration/access_test.rb +24 -0
- data/test/integration/account_activations_access_test.rb +12 -0
- data/test/integration/contact_test.rb +98 -0
- data/test/integration/extra_partial_test.rb +41 -0
- data/test/integration/log_view_access_test.rb +12 -0
- data/test/integration/password_resets_test.rb +101 -0
- data/test/integration/reports_test.rb +53 -0
- data/test/integration/status_access_test.rb +27 -0
- data/test/integration/system_config_access_test.rb +24 -0
- data/test/integration/system_update_access_test.rb +19 -0
- data/test/integration/users_access_test.rb +34 -0
- data/test/integration/users_edit_test.rb +178 -0
- data/test/integration/users_index_test.rb +62 -0
- data/test/integration/users_login_test.rb +67 -0
- data/test/integration/users_signup_test.rb +54 -0
- data/test/mailers/.keep +0 -0
- data/test/mailers/barkest_core/contact_form_test.rb +28 -0
- data/test/mailers/barkest_core/user_mailer_test.rb +43 -0
- data/test/mailers/previews/barkest_core/contact_form_preview.rb +17 -0
- data/test/mailers/previews/barkest_core/user_mailer_preview.rb +26 -0
- data/test/models/access_group_group_member_test.rb +28 -0
- data/test/models/access_group_test.rb +114 -0
- data/test/models/access_group_user_member_test.rb +28 -0
- data/test/models/barkest_core/auth_config_test.rb +57 -0
- data/test/models/barkest_core/bool_parser_test.rb +28 -0
- data/test/models/barkest_core/contact_message_test.rb +61 -0
- data/test/models/barkest_core/database_config_test.rb +33 -0
- data/test/models/barkest_core/date_parser_test.rb +110 -0
- data/test/models/barkest_core/email_config_test.rb +57 -0
- data/test/models/barkest_core/global_status_test.rb +50 -0
- data/test/models/barkest_core/ms_sql_db_updater_test.rb +115 -0
- data/test/models/barkest_core/ms_sql_definition_test.rb +102 -0
- data/test/models/barkest_core/ms_sql_function_test.rb +131 -0
- data/test/models/barkest_core/number_parser_test.rb +29 -0
- data/test/models/barkest_core/self_update_config_test.rb +29 -0
- data/test/models/barkest_core/user_alert_test.rb +19 -0
- data/test/models/barkest_core/user_manager_test.rb +34 -0
- data/test/models/barkest_core/work_path_test.rb +26 -0
- data/test/models/disable_user_test.rb +27 -0
- data/test/models/generic_time_test.rb +66 -0
- data/test/models/ldap_access_group_test.rb +31 -0
- data/test/models/pdf_table_builder_test.rb +6 -0
- data/test/models/system_config_test.rb +78 -0
- data/test/models/user_login_history_test.rb +37 -0
- data/test/models/user_test.rb +130 -0
- data/test/test_helper.rb +63 -0
- metadata +798 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Time is much easier to work with when you discard the time zones.
|
|
2
|
+
# The only place the local time matters at all is when displaying to the user on reports.
|
|
3
|
+
# Everywhere else, use UTC. The default behavior should be UTC.
|
|
4
|
+
|
|
5
|
+
require 'time'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Time.class_eval do
|
|
9
|
+
|
|
10
|
+
##
|
|
11
|
+
# Parses a time string into UTC time.
|
|
12
|
+
#
|
|
13
|
+
# Supports either M/D/Y H:M:S or Y-M-D H:M:S format.
|
|
14
|
+
#
|
|
15
|
+
# If a timezone is provided, it will be taken into account and the UTC equivalent will be returned.
|
|
16
|
+
def self.utc_parse(s)
|
|
17
|
+
raise ArgumentError, 'expected a time value to be provided' if s.blank?
|
|
18
|
+
|
|
19
|
+
# If it's already a time, return the UTC variant.
|
|
20
|
+
return s.utc if s.is_a?(Time)
|
|
21
|
+
# If it can be converted to a time, and is not a string, convert and return the UTC variant.
|
|
22
|
+
return s.to_time.utc if s.respond_to?(:to_time) && !s.is_a?(String)
|
|
23
|
+
# If it is not a string, turn it into a string and parse that.
|
|
24
|
+
return utc_parse(s.to_s) unless s.is_a?(String)
|
|
25
|
+
|
|
26
|
+
dt,tm,tz,ex = s.split(' ')
|
|
27
|
+
|
|
28
|
+
# Time only?
|
|
29
|
+
if dt.include?(':')
|
|
30
|
+
ex = tz
|
|
31
|
+
tz = tm
|
|
32
|
+
tm = dt
|
|
33
|
+
dt = '1900-01-01'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
yr,mon,day =
|
|
37
|
+
if dt.include?('/')
|
|
38
|
+
# M/D/Y
|
|
39
|
+
_m,_d,_y = dt.split('/')
|
|
40
|
+
_y ||= Time.now.utc.year
|
|
41
|
+
[ _y, _m, _d ]
|
|
42
|
+
elsif dt.include?('-')
|
|
43
|
+
# Y-M-D
|
|
44
|
+
dt.split('-')
|
|
45
|
+
|
|
46
|
+
# Because we may be interacting with Spectrum users, accept these formats as well.
|
|
47
|
+
elsif (/^\d{4}$/).match(dt)
|
|
48
|
+
# MMDD
|
|
49
|
+
[ Time.now.utc.year, dt[0...2], dt[2...4] ]
|
|
50
|
+
elsif (/^\d{6}(\d{2})?$/).match(dt)
|
|
51
|
+
# MMDDYY(YY)
|
|
52
|
+
[ dt[4..-1], dt[0...2], dt[2...4] ]
|
|
53
|
+
|
|
54
|
+
elsif (/^\d+(am|pm)?$/i).match(dt) && (0..24).include?(dt.to_i)
|
|
55
|
+
# a single integer parsing to a valid hour, possibly with an AM/PM specifier
|
|
56
|
+
ex = tz
|
|
57
|
+
tz = tm
|
|
58
|
+
tm = dt
|
|
59
|
+
[ 1900, 1, 1 ]
|
|
60
|
+
|
|
61
|
+
else
|
|
62
|
+
# Unsupported format.
|
|
63
|
+
[]
|
|
64
|
+
end.map { |i| i.to_i }
|
|
65
|
+
|
|
66
|
+
raise ArgumentError, 'year is missing' unless yr
|
|
67
|
+
raise ArgumentError, 'month is missing' unless mon
|
|
68
|
+
raise ArgumentError, 'day is missing' unless day
|
|
69
|
+
|
|
70
|
+
yr += 2000 if yr < 40
|
|
71
|
+
yr += 1900 if yr < 100
|
|
72
|
+
|
|
73
|
+
mon = 1 unless mon
|
|
74
|
+
day = 1 unless day
|
|
75
|
+
|
|
76
|
+
if tm
|
|
77
|
+
# allow AM/PM specifier to be attached to time.
|
|
78
|
+
if %w(AM PM).include?(tm[-2..-1].to_s.upcase)
|
|
79
|
+
ex = tz
|
|
80
|
+
tz = tm[-2..-1]
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
hr,min,sec = tm ? tm.split(':') : []
|
|
85
|
+
hr = hr ? hr.to_i : 0
|
|
86
|
+
min = min ? min.to_i : 0
|
|
87
|
+
sec = sec ? sec.to_f : 0.0
|
|
88
|
+
|
|
89
|
+
if %w(AM PM).include?(tz.to_s.upcase)
|
|
90
|
+
raise ArgumentError, 'hour must be between 1 and 12 for 12-hour formats' unless (1..12).include?(hr)
|
|
91
|
+
|
|
92
|
+
tz = tz.to_s.upcase
|
|
93
|
+
|
|
94
|
+
if tz == 'AM'
|
|
95
|
+
hr = 0 if hr == 12 # only need to modify midnight.
|
|
96
|
+
else
|
|
97
|
+
hr += 12 unless hr == 12 # modify everything except noon.
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# grab the next item from the original string.
|
|
101
|
+
tz = ex
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
if hr == 24 && min == 0 && sec == 0
|
|
105
|
+
tmp_date = Time.utc(yr,mon,day)
|
|
106
|
+
raise ArgumentError, 'time component overflow' unless tmp_date.year == yr && tmp_date.month == mon && tmp_date.day == day
|
|
107
|
+
tmp_date = (tmp_date + 1.day).to_time.utc
|
|
108
|
+
yr = tmp_date.year
|
|
109
|
+
mon = tmp_date.month
|
|
110
|
+
day = tmp_date.day
|
|
111
|
+
hr = 0
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
tz = nil if %w(UTC).include?(tz.to_s.upcase)
|
|
115
|
+
|
|
116
|
+
result =
|
|
117
|
+
if tz
|
|
118
|
+
bits = (/^([+-])(\d{1,2}):?(\d{2})$/).match(tz)
|
|
119
|
+
raise ArgumentError, '"+HH:MM" or "-HH:MM" expected for utc_offset' unless bits
|
|
120
|
+
tz = "#{bits[1]}#{bits[2].rjust(2,'0')}:#{bits[3]}"
|
|
121
|
+
Time.new(yr, mon, day, hr, min, sec, tz)
|
|
122
|
+
else
|
|
123
|
+
Time.utc(yr, mon, day, hr, min, sec)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
raise ArgumentError, 'time component overflow' unless result.year == yr && result.month == mon && result.day == day && result.hour == hr && result.min == min && result.sec.to_i == sec.to_i
|
|
127
|
+
|
|
128
|
+
result.utc
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
##
|
|
133
|
+
# Gets the date component of the time.
|
|
134
|
+
def date
|
|
135
|
+
return utc.date unless utc?
|
|
136
|
+
Time.utc(year, month, day)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
##
|
|
140
|
+
# Discards time zone information and makes
|
|
141
|
+
#
|
|
142
|
+
# The current time zone offset is discarded.
|
|
143
|
+
# For instance, '2016-12-19 19:00:00 -05:00' becomes '2016-12-19 19:00:00 +00:00'
|
|
144
|
+
def as_utc
|
|
145
|
+
Time.utc(year, month, day, hour, min, sec)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
Date.class_eval do
|
|
151
|
+
# :nodoc:
|
|
152
|
+
alias :barkest_core_original_to_time :to_time
|
|
153
|
+
|
|
154
|
+
##
|
|
155
|
+
# Returns the date in UTC format.
|
|
156
|
+
#
|
|
157
|
+
# Time portion will always be 00:00:00 UTC.
|
|
158
|
+
# Dates shouldn't be TZ specific.
|
|
159
|
+
def to_time
|
|
160
|
+
Time.utc(year, month, day)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
end
|
|
164
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'csv'
|
|
2
|
+
|
|
3
|
+
module BarkestCore
|
|
4
|
+
|
|
5
|
+
##
|
|
6
|
+
# Handles CSV views.
|
|
7
|
+
module CsvHandler
|
|
8
|
+
# :enddoc:
|
|
9
|
+
|
|
10
|
+
class CsvGenerator
|
|
11
|
+
def self.generate
|
|
12
|
+
file = CSV.generate do |csv|
|
|
13
|
+
yield csv
|
|
14
|
+
end
|
|
15
|
+
file.html_safe
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class Handler
|
|
20
|
+
def self.call (template)
|
|
21
|
+
%{
|
|
22
|
+
BarkestCore::CsvHandler::CsvGenerator.generate do |csv|
|
|
23
|
+
#{template.source}
|
|
24
|
+
end
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
data/lib/barkest_core.rb
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
require 'barkest_core/engine'
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
require 'time'
|
|
4
|
+
|
|
5
|
+
module BarkestCore
|
|
6
|
+
|
|
7
|
+
##
|
|
8
|
+
# Cache of the application root path for use within the engine.
|
|
9
|
+
mattr_accessor :app_root
|
|
10
|
+
|
|
11
|
+
##
|
|
12
|
+
# Determines the accessibility of /users (index) and /users/1 (show) actions.
|
|
13
|
+
#
|
|
14
|
+
# Set to true to deny access to the users' list and user profiles for non-admin users.
|
|
15
|
+
# Set to false to allow access to the users' list for all logged-in users.
|
|
16
|
+
mattr_accessor :lock_down_users
|
|
17
|
+
|
|
18
|
+
##
|
|
19
|
+
# Gets the database configuration for the auth models.
|
|
20
|
+
#
|
|
21
|
+
# The +barkest_core+ database must be defined in +database.yml+.
|
|
22
|
+
# This will either be an explicit +barkest_core+ section or a normal environment section (ie - +production+).
|
|
23
|
+
# However other databases can be defined via the SystemConfig model.
|
|
24
|
+
#
|
|
25
|
+
# The +database.yml+ file is checked first, followed by SystemConfig.
|
|
26
|
+
# If neither of those defines the specific database, then we fall back on +database.yml+ to load
|
|
27
|
+
# the global configuration for the environment.
|
|
28
|
+
#
|
|
29
|
+
# For instance, if you want the configuration for :mydb in the :development environment:
|
|
30
|
+
# * Check in +database.yml+ for "mydb_development".
|
|
31
|
+
# * Check in +database.yml+ for "mydb".
|
|
32
|
+
# * Check in SystemConfig for "mydb" (unless "mydb" == "barkest_core").
|
|
33
|
+
# * Check in +database.yml+ for "development".
|
|
34
|
+
# * Fall back on default connection used by ActiveRecord::Base.
|
|
35
|
+
#
|
|
36
|
+
# Returned hash will have symbol keys.
|
|
37
|
+
def self.db_config(other = nil, env = nil, convert_extra = true)
|
|
38
|
+
if other
|
|
39
|
+
@db_configs ||= {}
|
|
40
|
+
|
|
41
|
+
other = other.to_sym
|
|
42
|
+
env = (env || Rails.env).to_sym
|
|
43
|
+
key = :"#{other}_#{env}"
|
|
44
|
+
|
|
45
|
+
@db_configs[key] ||=
|
|
46
|
+
begin
|
|
47
|
+
avail = avail_db_configs
|
|
48
|
+
|
|
49
|
+
# for any db connection other than the core connection, check
|
|
50
|
+
# in the system config table as well.
|
|
51
|
+
syscfg = (other == :barkest_core) ? nil : SystemConfig.get(other)
|
|
52
|
+
defcfg = (other == :barkest_core) ? avail[env] : db_config_defaults(other)
|
|
53
|
+
|
|
54
|
+
# Preference
|
|
55
|
+
(
|
|
56
|
+
avail[key] || # 1: barkest_core_development
|
|
57
|
+
avail[other] || # 2: barkest_core
|
|
58
|
+
syscfg || # 3: SystemConfig: barkest_core
|
|
59
|
+
defcfg || # 4: YAML[env] or defaults depending on db name
|
|
60
|
+
ActiveRecord::Base.connection_config # 5: default connection (hopefully never gets used)
|
|
61
|
+
).merge(defcfg.select do |k,_|
|
|
62
|
+
[ # reset name, type, and label for extra values.
|
|
63
|
+
:extra_1_name, :extra_1_type, :extra_1_label,
|
|
64
|
+
:extra_2_name, :extra_2_type, :extra_2_label,
|
|
65
|
+
:extra_3_name, :extra_3_type, :extra_3_label,
|
|
66
|
+
:extra_4_name, :extra_4_type, :extra_4_label,
|
|
67
|
+
:extra_5_name, :extra_5_type, :extra_5_label
|
|
68
|
+
].include?(k)
|
|
69
|
+
end)
|
|
70
|
+
end
|
|
71
|
+
.symbolize_keys
|
|
72
|
+
|
|
73
|
+
if convert_extra
|
|
74
|
+
@db_configs[:"#{key}_converted"] ||= BarkestCore::DatabaseConfig.new(@db_configs[key]).to_h(true)
|
|
75
|
+
else
|
|
76
|
+
@db_configs[key]
|
|
77
|
+
end
|
|
78
|
+
elsif env
|
|
79
|
+
db_config(:barkest_core, env, convert_extra)
|
|
80
|
+
else
|
|
81
|
+
@db_config ||= db_config(:barkest_core, Rails.env, false)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
##
|
|
86
|
+
# Determines if the configuration for the specified database is stored in the global configuration file.
|
|
87
|
+
def self.db_config_is_file_based?(db_name)
|
|
88
|
+
avail = avail_db_configs.keys
|
|
89
|
+
avail.include?(:"#{db_name}_#{Rails.env}") || avail.include?(:"#{db_name}")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
##
|
|
93
|
+
# Sets the defaults for a database configuration.
|
|
94
|
+
def self.register_db_config_defaults(db_name, defaults)
|
|
95
|
+
# reset the config cache.
|
|
96
|
+
@db_configs = nil
|
|
97
|
+
|
|
98
|
+
db_name = db_name.to_s
|
|
99
|
+
return false if db_name.blank?
|
|
100
|
+
return false if db_name == 'barkest_core'
|
|
101
|
+
|
|
102
|
+
# set the defaults.
|
|
103
|
+
@db_config_defaults ||= {}
|
|
104
|
+
@db_config_defaults[db_name.to_sym] = defaults
|
|
105
|
+
|
|
106
|
+
true
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
##
|
|
110
|
+
# Gets the email configuration for the application.
|
|
111
|
+
#
|
|
112
|
+
# Email settings are stored under the :email key within SystemConfig.
|
|
113
|
+
#
|
|
114
|
+
# Returned keys will be symbols.
|
|
115
|
+
def self.email_config
|
|
116
|
+
@email_config ||= email_config_defaults(nil).merge( (SystemConfig.get(:email) || {}).symbolize_keys )
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
##
|
|
120
|
+
# Provides the defaults to be returned by email_config when settings are missing.
|
|
121
|
+
def self.email_config_defaults(new_defaults = {})
|
|
122
|
+
@email_config_defaults = nil if new_defaults
|
|
123
|
+
@email_config_defaults ||=
|
|
124
|
+
{
|
|
125
|
+
config_mode: :none,
|
|
126
|
+
default_sender: 'support@barkerest.com',
|
|
127
|
+
default_recipient: 'support@barkerest.com',
|
|
128
|
+
default_hostname: 'localhost',
|
|
129
|
+
}.merge((new_defaults || {}).symbolize_keys)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
##
|
|
133
|
+
# Gets the authorization configuration.
|
|
134
|
+
#
|
|
135
|
+
# Basically this does two things.
|
|
136
|
+
# 1) It will enable/disable internal database authentication.
|
|
137
|
+
# 2) It will enable/disable ldap authentication.
|
|
138
|
+
#
|
|
139
|
+
# If ldap authentication is not configured then internal database authentication
|
|
140
|
+
# is forcibly enabled. Both modes can be active simultaneously.
|
|
141
|
+
#
|
|
142
|
+
# Auth settings are stored under the :auth key within SystemConfig.
|
|
143
|
+
#
|
|
144
|
+
# Returned keys will be symbols.
|
|
145
|
+
def self.auth_config
|
|
146
|
+
@auth_config ||=
|
|
147
|
+
begin
|
|
148
|
+
cfg = auth_config_defaults(nil).symbolize_keys.merge( (SystemConfig.get(:auth) || {}).symbolize_keys )
|
|
149
|
+
|
|
150
|
+
cfg[:enable_db_auth] = true unless cfg[:enable_ldap_auth]
|
|
151
|
+
|
|
152
|
+
cfg
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
##
|
|
157
|
+
# Provides the defaults to be provided by auth_config when settings are missing.
|
|
158
|
+
def self.auth_config_defaults(new_defaults = {})
|
|
159
|
+
@auth_config_defaults = nil if new_defaults
|
|
160
|
+
@auth_config_defaults ||=
|
|
161
|
+
{
|
|
162
|
+
enable_db_auth: true,
|
|
163
|
+
enable_ldap_auth: false,
|
|
164
|
+
}.merge((new_defaults || {}).symbolize_keys)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# :nodoc:
|
|
168
|
+
def self.config
|
|
169
|
+
BarkestCore::Engine.config
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
##
|
|
173
|
+
# Tells the hosting service (Passenger) that we want to restart the application.
|
|
174
|
+
def self.request_restart
|
|
175
|
+
FileUtils.touch restart_file
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
##
|
|
179
|
+
# Determines if the application is still waiting on a restart to take place.
|
|
180
|
+
def self.restart_pending?
|
|
181
|
+
return false unless File.exist?(restart_file)
|
|
182
|
+
|
|
183
|
+
request_time = File.mtime(restart_file)
|
|
184
|
+
|
|
185
|
+
request_time > start_time
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
##
|
|
189
|
+
# Gets a list of key gems with their versions.
|
|
190
|
+
#
|
|
191
|
+
# This is useful for informational displays such as brief application version diplays.
|
|
192
|
+
#
|
|
193
|
+
# Supply one or more patterns for gem names. If you supply none, then the default
|
|
194
|
+
# pattern list is used.
|
|
195
|
+
def self.gem_list(*patterns)
|
|
196
|
+
ret = []
|
|
197
|
+
|
|
198
|
+
if patterns.blank?
|
|
199
|
+
patterns = key_gem_patterns
|
|
200
|
+
elsif patterns.first.is_a?(TrueClass)
|
|
201
|
+
patterns = key_gem_patterns + patterns[1..-1]
|
|
202
|
+
elsif patterns.last.is_a?(TrueClass)
|
|
203
|
+
patterns = patterns[0...-1] + key_gem_patterns
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
patterns = patterns.flatten.inject([]) { |memo,v| memo << v unless memo.include?(v); memo }
|
|
207
|
+
|
|
208
|
+
Gem::Specification.to_a.sort{|a,b| a.name <=> b.name}.each do |gem|
|
|
209
|
+
patterns.each do |pat|
|
|
210
|
+
if pat.is_a?(String) && gem.name == pat
|
|
211
|
+
ret << [ gem.name, gem.version.to_s ]
|
|
212
|
+
elsif pat.is_a?(Regexp) && pat.match(gem.name)
|
|
213
|
+
ret << [ gem.name, gem.version.to_s ]
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
ret
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
##
|
|
222
|
+
# Adds a key gem pattern to the default gem_list results.
|
|
223
|
+
def self.add_key_gem_pattern(pattern)
|
|
224
|
+
pattern = pattern.to_s.downcase
|
|
225
|
+
unless pattern.blank?
|
|
226
|
+
key_gem_patterns << pattern unless key_gem_patterns.include?(pattern)
|
|
227
|
+
end
|
|
228
|
+
key_gem_patterns.include? pattern
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
##
|
|
232
|
+
# Registers a partial view to build up the anonymous header menu.
|
|
233
|
+
def self.register_anon_menu(partial_path)
|
|
234
|
+
unless partial_path.blank?
|
|
235
|
+
anon_menu_registry << partial_path unless anon_menu_registry.include?(partial_path)
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
##
|
|
240
|
+
# Registers a partial view to build up the authenticated header menu.
|
|
241
|
+
def self.register_auth_menu(partial_path)
|
|
242
|
+
unless partial_path.blank?
|
|
243
|
+
auth_menu_registry << partial_path unless auth_menu_registry.include?(partial_path)
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
##
|
|
248
|
+
# Registers a partial view to build up the footer menu.
|
|
249
|
+
def self.register_footer_menu(partial_path)
|
|
250
|
+
unless partial_path.blank?
|
|
251
|
+
footer_menu_registry << partial_path unless footer_menu_registry.include?(partial_path)
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
##
|
|
256
|
+
# Registers a path to be processed by the custom seeds.rb file.
|
|
257
|
+
def self.register_db_seed_path(seed_path)
|
|
258
|
+
unless seed_path.blank?
|
|
259
|
+
db_seed_path_registry << partial_path unless db_seed_path_registry.include?(seed_path)
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
##
|
|
264
|
+
# Gets the root path of the BarkestCore gem.
|
|
265
|
+
def self.gem_root_path
|
|
266
|
+
@gem_root_path ||= File.expand_path('../..', __FILE__)
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
private
|
|
270
|
+
|
|
271
|
+
def self.anon_menu_registry
|
|
272
|
+
@anon_menu_registry ||= [ 'layouts/menu_anon' ]
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def self.auth_menu_registry
|
|
276
|
+
@auth_menu_registry ||= [ 'layouts/menu_auth' ]
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def self.footer_menu_registry
|
|
280
|
+
@footer_menu_registry ||= [ 'layouts/menu_footer' ]
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
def self.db_seed_path_registry
|
|
284
|
+
@db_seed_path_registry ||= [ 'db/seeds/*.rb' ]
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def self.key_gem_patterns
|
|
288
|
+
@key_gem_patterns ||= [ 'rails', /^barkest/ ]
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
def self.db_config_defaults(db_name)
|
|
292
|
+
@db_config_defaults ||= {}
|
|
293
|
+
@db_config_defaults[db_name.to_sym] || {}
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def self.avail_db_configs
|
|
297
|
+
@avail_db_configs ||=
|
|
298
|
+
begin
|
|
299
|
+
db_yml = "#{self.app_root}/config/database.yml"
|
|
300
|
+
if File.exist?(db_yml)
|
|
301
|
+
YAML.load_file(db_yml).symbolize_keys
|
|
302
|
+
else
|
|
303
|
+
ActiveRecord::Base.configurations.to_h.symbolize_keys
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
def self.restart_file
|
|
309
|
+
@restart_file ||= "#{self.app_root}/tmp/restart.txt"
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
def self.start_time
|
|
313
|
+
@start_time ||= Time.now
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
# make sure @start_time gets set...
|
|
317
|
+
start_time
|
|
318
|
+
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
# Preload the concerns and process the extensions.
|
|
322
|
+
Dir.glob(File.expand_path('../barkest_core/{concerns,extensions,handlers}/*.rb', __FILE__)).each do |lib_code|
|
|
323
|
+
require lib_code
|
|
324
|
+
end
|