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,106 @@
|
|
|
1
|
+
|
|
2
|
+
# Add some extensions to the route mapper.
|
|
3
|
+
ActionDispatch::Routing::Mapper.class_eval do
|
|
4
|
+
|
|
5
|
+
##
|
|
6
|
+
# Installs all known Barkest routes.
|
|
7
|
+
#
|
|
8
|
+
# Basically every Barkest plugin should define a 'barkest_' helper in the routing mapper class,
|
|
9
|
+
# so this method simply finds and executes those helpers.
|
|
10
|
+
def barkest(options = {})
|
|
11
|
+
self.methods.each do |method|
|
|
12
|
+
if method.to_s.index('barkest_') == 0
|
|
13
|
+
send method, options
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
##
|
|
19
|
+
# Installs the BarkestCore routes.
|
|
20
|
+
def barkest_core(options = {})
|
|
21
|
+
options = { path: options } if options.is_a?(String)
|
|
22
|
+
options = (options || {}).symbolize_keys
|
|
23
|
+
|
|
24
|
+
path = options[:path].blank? ? '/' : options[:path].to_s
|
|
25
|
+
path = '/' + path unless path[0] == '/'
|
|
26
|
+
|
|
27
|
+
scope path: path do
|
|
28
|
+
if Rails.env.test? || Rails.env.development?
|
|
29
|
+
scope as: :barkest_core do
|
|
30
|
+
# test routes
|
|
31
|
+
get 'test_access/allow_anon'
|
|
32
|
+
get 'test_access/require_user'
|
|
33
|
+
get 'test_access/require_admin'
|
|
34
|
+
get 'test_access/require_group_x'
|
|
35
|
+
get 'test_report' => 'test_report#index'
|
|
36
|
+
|
|
37
|
+
# namespaced tests (these should have the subheader in place).
|
|
38
|
+
get 'test_sub' => 'barkest_core/testsub#page1', as: :testsub_page1
|
|
39
|
+
get 'test_sub/page2' => 'barkest_core/testsub#page2', as: :testsub_page2
|
|
40
|
+
get 'test_sub/page3' => 'barkest_core/testsub#page3', as: :testsub_page3
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# contact form
|
|
45
|
+
get 'contact' => 'contact#index'
|
|
46
|
+
post 'contact' => 'contact#create'
|
|
47
|
+
|
|
48
|
+
# login/logout
|
|
49
|
+
get 'login' => 'sessions#new', as: :login
|
|
50
|
+
post 'login' => 'sessions#create'
|
|
51
|
+
delete 'logout' => 'sessions#destroy', as: :logout
|
|
52
|
+
|
|
53
|
+
# user management
|
|
54
|
+
get 'signup' => 'users#new', as: :signup
|
|
55
|
+
post 'signup' => 'users#create'
|
|
56
|
+
resources :users do
|
|
57
|
+
member do
|
|
58
|
+
get 'disable', action: :disable_confirm
|
|
59
|
+
patch 'disable', action: :disable
|
|
60
|
+
put 'disable', action: :disable
|
|
61
|
+
patch 'enable', action: :enable
|
|
62
|
+
put 'enable', action: :enable
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# account activation route.
|
|
67
|
+
get 'account_activation/:id' => 'account_activations#edit', as: 'edit_account_activation'
|
|
68
|
+
|
|
69
|
+
# password reset routes.
|
|
70
|
+
resources :password_resets, only: [:new, :create, :edit, :update]
|
|
71
|
+
|
|
72
|
+
# group management
|
|
73
|
+
resources :access_groups
|
|
74
|
+
|
|
75
|
+
# status paths
|
|
76
|
+
get 'status/current' => 'status#current'
|
|
77
|
+
get 'status/first' => 'status#first'
|
|
78
|
+
get 'status/more' => 'status#more'
|
|
79
|
+
get 'status/test(/:flag)' => 'status#test', as: :status_test
|
|
80
|
+
|
|
81
|
+
# system update paths
|
|
82
|
+
get 'system_update/new'
|
|
83
|
+
get 'system_update' => 'system_update#index', as: :system_update
|
|
84
|
+
|
|
85
|
+
# system configuration paths
|
|
86
|
+
get 'system_config' => 'system_config#index', as: :system_config
|
|
87
|
+
post 'system_config/restart' => 'system_config#restart', as: :system_config_restart
|
|
88
|
+
SystemConfigController.get_config_items.sort.each do |(item_name, attrib)|
|
|
89
|
+
if attrib[:require_id]
|
|
90
|
+
get "system_config/#{item_name}/:id" => "system_config#show_#{item_name}", as: attrib[:route_name]
|
|
91
|
+
post "system_config/#{item_name}/:id" => "system_config#update_#{item_name}"
|
|
92
|
+
else
|
|
93
|
+
get "system_config/#{item_name}" => "system_config#show_#{item_name}", as: attrib[:route_name]
|
|
94
|
+
post "system_config/#{item_name}" => "system_config#update_#{item_name}"
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# log view paths
|
|
99
|
+
get 'system_log' => 'log_view#index', as: :system_log
|
|
100
|
+
post 'system_log' => 'log_view#index'
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
# :enddoc:
|
|
3
|
+
|
|
4
|
+
# The simple formatter is too simple.
|
|
5
|
+
# We'll clean things up and log using JSON.
|
|
6
|
+
|
|
7
|
+
ActiveSupport::Logger::SimpleFormatter.class_eval do
|
|
8
|
+
|
|
9
|
+
alias :barkest_core_original_call :call
|
|
10
|
+
|
|
11
|
+
def call(sev, time, _, msg)
|
|
12
|
+
level = ({
|
|
13
|
+
Logger::DEBUG => 'DEBUG',
|
|
14
|
+
Logger::INFO => 'INFO',
|
|
15
|
+
Logger::WARN => 'WARN',
|
|
16
|
+
Logger::ERROR => 'ERROR',
|
|
17
|
+
Logger::FATAL => 'FATAL',
|
|
18
|
+
}[sev] || sev.to_s).upcase
|
|
19
|
+
|
|
20
|
+
if msg.present? && msg.exclude?('Started GET "/assets')
|
|
21
|
+
|
|
22
|
+
# And we'll exapnd exceptions so we get as much info as possible.
|
|
23
|
+
# If you just want the message, make sure you just pass the message.
|
|
24
|
+
if msg.is_a?(Exception)
|
|
25
|
+
msg = "#{msg.message} (#{msg.class})\n#{(msg.backtrace || []).join("\n")}"
|
|
26
|
+
elsif !msg.is_a?(String)
|
|
27
|
+
msg = msg.inspect
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
msg = rm_fmt msg
|
|
31
|
+
|
|
32
|
+
if (/^rendered\s/i).match msg
|
|
33
|
+
return '' if Rails.logger.level > 0
|
|
34
|
+
level = 'DEBUG'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
{
|
|
38
|
+
level: level,
|
|
39
|
+
time: time.strftime('%Y-%m-%d %H:%M:%S'),
|
|
40
|
+
message: msg,
|
|
41
|
+
app_name: Rails.application.app_name,
|
|
42
|
+
app_version: Rails.application.app_version,
|
|
43
|
+
process_id: Process.pid,
|
|
44
|
+
}.to_json + "\r\n"
|
|
45
|
+
else
|
|
46
|
+
''
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def rm_fmt(msg)
|
|
53
|
+
msg
|
|
54
|
+
.gsub(/\e\[(\d+;?)*[ABCDEFGHfu]/, "\n") # any of the "set cursor position" CSI commands.
|
|
55
|
+
.gsub(/\e\[=?(\d+;?)*[A-Za-z]/,'') # \e[#;#;#A or \e[=#;#;#A basically all the CSI commands except ...
|
|
56
|
+
.gsub(/\e\[(\d+;"[^"]+";?)+p/, '') # \e[#;"A"p
|
|
57
|
+
.gsub(/\e[NOc]./,'?') # any of the alternate character set commands.
|
|
58
|
+
.gsub(/\e[P_\]^X][^\e\a]*(\a|(\e\\))/,'') # any string command
|
|
59
|
+
.gsub(/[\x00\x08\x0B\x0C\x0E-\x1F]/, '') # any non-printable characters (notice \x0A (LF) and \x0D (CR) are left as is).
|
|
60
|
+
.gsub("\t", ' ') # turn tabs into spaces.
|
|
61
|
+
.gsub("\r\n", "\n") # all CRLF to LF
|
|
62
|
+
.gsub("\r", "\n") # all CR to LF
|
|
63
|
+
.strip # remove trailing and leading whitespace
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
require File.expand_path('../../../../app/helpers/barkest_core/application_helper', __FILE__)
|
|
2
|
+
require File.expand_path('../../../../app/helpers/barkest_core/sessions_helper', __FILE__)
|
|
3
|
+
|
|
4
|
+
# include all the standard application helpers.
|
|
5
|
+
ActiveSupport::TestCase.include BarkestCore::ApplicationHelper
|
|
6
|
+
ActiveSupport::TestCase.include BarkestCore::SessionsHelper
|
|
7
|
+
|
|
8
|
+
# add a few simple extensions for testing.
|
|
9
|
+
ActiveSupport::TestCase.class_eval do
|
|
10
|
+
|
|
11
|
+
##
|
|
12
|
+
# Tests a specific field for presence validation.
|
|
13
|
+
#
|
|
14
|
+
# +model+ must respond to _attribute_ and _attribute=_ as well as _valid?_.
|
|
15
|
+
#
|
|
16
|
+
# +attribute+ must provide the name of a valid attribute in the model.
|
|
17
|
+
#
|
|
18
|
+
# +message+ is optional, but if provided it will be postfixed with the failure reason.
|
|
19
|
+
def assert_required(model, attribute, message = nil)
|
|
20
|
+
original_value = model.send(attribute)
|
|
21
|
+
original_valid = model.valid?
|
|
22
|
+
is_string = original_value.is_a?(String)
|
|
23
|
+
setter = :"#{attribute}="
|
|
24
|
+
model.send setter, nil
|
|
25
|
+
assert_not model.valid?, message ? (message + ': (nil)') : "Should not allow #{attribute} to be set to nil."
|
|
26
|
+
if is_string
|
|
27
|
+
model.send setter, ''
|
|
28
|
+
assert_not model.valid?, message ? (message + ": ('')") : "Should not allow #{attribute} to be set to empty string."
|
|
29
|
+
model.send setter, ' '
|
|
30
|
+
assert_not model.valid?, message ? (message + ": (' ')") : "Should not allow #{attribute} to be set to blank string."
|
|
31
|
+
end
|
|
32
|
+
model.send setter, original_value
|
|
33
|
+
if original_valid
|
|
34
|
+
assert model.valid?, message ? (message + ": !(#{original_value.inspect})") : "Should allow #{attribute} to be set back to '#{original_value.inspect}'."
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
##
|
|
39
|
+
# Tests a specific field for maximum length restriction.
|
|
40
|
+
#
|
|
41
|
+
# +model+ must respond to _attribute_ and _attribute=_ as well as _valid?_.
|
|
42
|
+
#
|
|
43
|
+
# +attribute+ must provide the name of a valid attribute in the model.
|
|
44
|
+
#
|
|
45
|
+
# +max_length+ is the maximum valid length for the field.
|
|
46
|
+
#
|
|
47
|
+
# +message+ is optional, but if provided it will be postfixed with the failure reason.
|
|
48
|
+
def assert_max_length(model, attribute, max_length, message = nil, options = {})
|
|
49
|
+
original_value = model.send(attribute)
|
|
50
|
+
original_valid = model.valid?
|
|
51
|
+
setter = :"#{attribute}="
|
|
52
|
+
|
|
53
|
+
if message.is_a?(Hash)
|
|
54
|
+
options = message.merge(options || {})
|
|
55
|
+
message = nil
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
pre = options[:start].to_s
|
|
59
|
+
post = options[:end].to_s
|
|
60
|
+
len = max_length - pre.length - post.length
|
|
61
|
+
|
|
62
|
+
# try with maximum valid length.
|
|
63
|
+
value = pre + ('a' * len) + post
|
|
64
|
+
model.send setter, value
|
|
65
|
+
assert model.valid?, message ? (message + ": !(#{value.length})") : "Should allow a string of #{value.length} characters."
|
|
66
|
+
|
|
67
|
+
# try with one extra character.
|
|
68
|
+
value = pre + ('a' * (len + 1)) + post
|
|
69
|
+
model.send setter, value
|
|
70
|
+
assert_not model.valid?, message ? (message + ": (#{value.length})") : "Should not allow a string of #{value.length} characters."
|
|
71
|
+
|
|
72
|
+
model.send setter, original_value
|
|
73
|
+
if original_valid
|
|
74
|
+
assert model.valid?, message ? (message + ": !(#{original_value.inspect})") : "Should allow #{attribute} to be set back to '#{original_value.inspect}'."
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
##
|
|
79
|
+
# Tests a specific field for maximum length restriction.
|
|
80
|
+
#
|
|
81
|
+
# +model+ must respond to _attribute_ and _attribute=_ as well as _valid?_.
|
|
82
|
+
#
|
|
83
|
+
# +attribute+ must provide the name of a valid attribute in the model.
|
|
84
|
+
#
|
|
85
|
+
# +max_length+ is the maximum valid length for the field.
|
|
86
|
+
#
|
|
87
|
+
# +message+ is optional, but if provided it will be postfixed with the failure reason.
|
|
88
|
+
def assert_min_length(model, attribute, min_length, message = nil, options = {})
|
|
89
|
+
original_value = model.send(attribute)
|
|
90
|
+
original_valid = model.valid?
|
|
91
|
+
setter = :"#{attribute}="
|
|
92
|
+
|
|
93
|
+
if message.is_a?(Hash)
|
|
94
|
+
options = message.merge(options || {})
|
|
95
|
+
message = nil
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
pre = options[:start].to_s
|
|
99
|
+
post = options[:end].to_s
|
|
100
|
+
len = max_length - pre.length - post.length
|
|
101
|
+
|
|
102
|
+
# try with minimum valid length.
|
|
103
|
+
value = pre + ('a' * len) + post
|
|
104
|
+
model.send setter, value
|
|
105
|
+
assert model.valid?, message ? (message + ": !(#{value.length})") : "Should allow a string of #{value.length} characters."
|
|
106
|
+
|
|
107
|
+
# try with one extra character.
|
|
108
|
+
value = pre + ('a' * (len - 1)) + post
|
|
109
|
+
model.send setter, value
|
|
110
|
+
assert_not model.valid?, message ? (message + ": (#{value.length})") : "Should not allow a string of #{value.length} characters."
|
|
111
|
+
|
|
112
|
+
model.send setter, original_value
|
|
113
|
+
if original_valid
|
|
114
|
+
assert model.valid?, message ? (message + ": !(#{original_value.inspect})") : "Should allow #{attribute} to be set back to '#{original_value.inspect}'."
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
##
|
|
119
|
+
# Tests a specific field for uniqueness.
|
|
120
|
+
#
|
|
121
|
+
# +model+ must respond to _attribute_ and _attribute=_ as well as _valid?_.
|
|
122
|
+
# The model will be saved to perform uniqueness testing.
|
|
123
|
+
#
|
|
124
|
+
# +attribute+ must provide the name of a valid attribute in the model.
|
|
125
|
+
#
|
|
126
|
+
# +case_sensitive+ determines if changing case should change validation.
|
|
127
|
+
#
|
|
128
|
+
# +message+ is optional, but if provided it will be postfixed with the failure reason.
|
|
129
|
+
#
|
|
130
|
+
# +alternate_scopes+ is also optional. If provided the keys of the hash will be used to
|
|
131
|
+
# set additional attributes on the model. When these attributes are changed to the alternate
|
|
132
|
+
# values, the model should once again be valid.
|
|
133
|
+
def assert_uniqueness(model, attribute, case_sensitive = false, message = nil, alternate_scopes = {})
|
|
134
|
+
setter = :"#{attribute}="
|
|
135
|
+
original_value = model.send(attribute)
|
|
136
|
+
|
|
137
|
+
if case_sensitive.is_a?(Hash)
|
|
138
|
+
alternate_scopes = case_sensitive.merge(alternate_scopes || {})
|
|
139
|
+
case_sensitive = false
|
|
140
|
+
end
|
|
141
|
+
if message.is_a?(Hash)
|
|
142
|
+
alternate_scopes = message.merge(alternate_scopes || {})
|
|
143
|
+
message = nil
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
copy = model.dup
|
|
147
|
+
model.save!
|
|
148
|
+
|
|
149
|
+
assert_not copy.valid?, message ? (message + ": (#{copy.send(attribute).inspect})") : "Duplicate model with #{attribute}=#{copy.send(attribute).inspect} should not be valid."
|
|
150
|
+
unless case_sensitive
|
|
151
|
+
copy.send(setter, original_value.to_s.upcase)
|
|
152
|
+
assert_not copy.valid?, message ? (message + ": (#{copy.send(attribute).inspect})") : "Duplicate model with #{attribute}=#{copy.send(attribute).inspect} should not be valid."
|
|
153
|
+
copy.send(setter, original_value.to_s.downcase)
|
|
154
|
+
assert_not copy.valid?, message ? (message + ": (#{copy.send(attribute).inspect})") : "Duplicate model with #{attribute}=#{copy.send(attribute).inspect} should not be valid."
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
unless alternate_scopes.blank?
|
|
158
|
+
copy.send(setter, original_value)
|
|
159
|
+
assert_not copy.valid?, message ? (message + ": (#{copy.send(attribute).inspect})") : "Duplicate model with #{attribute}=#{copy.send(attribute).inspect} should not be valid."
|
|
160
|
+
alternate_scopes.each do |k,v|
|
|
161
|
+
kset = :"#{k}="
|
|
162
|
+
vorig = copy.send(k)
|
|
163
|
+
copy.send(kset, v)
|
|
164
|
+
assert copy.valid?, message ? (message + ": !#{k}(#{v})") : "Duplicate model with #{k}=#{v.inspect} should be valid with #{attribute}=#{copy.send(attribute).inspect}."
|
|
165
|
+
copy.send(kset, vorig)
|
|
166
|
+
assert_not copy.valid?, message ? (message + ": (#{copy.send(attribute).inspect})") : "Duplicate model with #{attribute}=#{copy.send(attribute).inspect} should not be valid." end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
##
|
|
171
|
+
# Tests access permissions for a specific action.
|
|
172
|
+
#
|
|
173
|
+
# Options:
|
|
174
|
+
# * +controller+ is the string name of the controller. If not supplied, the controller is inferred from the class name.
|
|
175
|
+
# * +url_helper+ is a string to generate the url. If not supplied, the helper is inferred from the controller and action names.
|
|
176
|
+
# * +fixture_helper+ is a string defining the fixture helper to use. If not supplied the controller name will be used.
|
|
177
|
+
# * +fixture_key+ is the fixture key to use. Defaults to :one.
|
|
178
|
+
# * +allow_anon+ determines if anonymous users should be able to access the action. Default is false.
|
|
179
|
+
# * +allow_any_user+ determines if any logged in user should be able to access the action. Default is false.
|
|
180
|
+
# * +allow_groups+ determines if a specific set of groups can access the action. Default is nil.
|
|
181
|
+
# * +deny_groups+ determines if a specific set of groups should not be able to access the action. Default is nil.
|
|
182
|
+
# * +allow_admin+ determines if system admins can access the action. Default is true.
|
|
183
|
+
# * +method+ determines the method to process the action with. Default is 'get'.
|
|
184
|
+
# * +success+ determines the result on success. Defaults to :success for 'get' requests, otherwise the pluralized controller helper path.
|
|
185
|
+
# * +failure+ determines the result on failure for non-anon tests. Defaults to 'root_url'.
|
|
186
|
+
# * +anon_failure+ determines the result on failure for anon tests. Defaults to 'login_url'.
|
|
187
|
+
#
|
|
188
|
+
def self.access_tests_for(action, options = {})
|
|
189
|
+
|
|
190
|
+
if action.respond_to?(:each)
|
|
191
|
+
action.each do |act|
|
|
192
|
+
access_tests_for(act, options.dup)
|
|
193
|
+
end
|
|
194
|
+
return
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
options = {
|
|
198
|
+
allow_anon: false,
|
|
199
|
+
allow_any_user: false,
|
|
200
|
+
allow_groups: nil,
|
|
201
|
+
allow_admin: true,
|
|
202
|
+
fixture_key: :one,
|
|
203
|
+
failure: 'root_url',
|
|
204
|
+
anon_failure: 'login_url'
|
|
205
|
+
}.merge(options || {})
|
|
206
|
+
|
|
207
|
+
action = action.to_sym
|
|
208
|
+
params = options[:"#{action}_params"]
|
|
209
|
+
params = nil unless params.is_a?(Hash)
|
|
210
|
+
|
|
211
|
+
if options[:method].blank?
|
|
212
|
+
options[:method] =
|
|
213
|
+
if action == :destroy
|
|
214
|
+
'delete'
|
|
215
|
+
elsif action == :update
|
|
216
|
+
'patch'
|
|
217
|
+
elsif action == :create
|
|
218
|
+
'post'
|
|
219
|
+
else
|
|
220
|
+
'get'
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
if options[:controller].blank?
|
|
225
|
+
options[:controller] = self.name.underscore.rpartition('_')[0]
|
|
226
|
+
else
|
|
227
|
+
options[:controller] = options[:controller].to_s.underscore
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
if options[:controller][-11..-1] == '_controller'
|
|
231
|
+
options[:controller] = options[:controller].rpartition('_')[0]
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
if options[:fixture_helper].blank?
|
|
235
|
+
options[:fixture_helper] = options[:controller]
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
options[:method] = options[:method].to_sym
|
|
239
|
+
|
|
240
|
+
if options[:url_helper].blank?
|
|
241
|
+
fix_val = "#{options[:fixture_helper].pluralize}(#{options[:fixture_key].inspect})"
|
|
242
|
+
options[:url_helper] =
|
|
243
|
+
case action
|
|
244
|
+
when :show, :update, :destroy then "#{options[:controller].singularize}_path(#{fix_val})"
|
|
245
|
+
when :edit then "edit_#{options[:controller].singularize}_path(#{fix_val})"
|
|
246
|
+
when :new then "new_#{options[:controller].singularize}_path"
|
|
247
|
+
else "#{options[:controller].pluralize}_path"
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
if options[:success].blank?
|
|
252
|
+
if options[:method] == :get
|
|
253
|
+
options[:success] = :success
|
|
254
|
+
else
|
|
255
|
+
options[:success] = "#{options[:controller].pluralize}_path"
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
method = options[:method]
|
|
261
|
+
url_helper = options[:url_helper]
|
|
262
|
+
|
|
263
|
+
tests = [
|
|
264
|
+
[ 'anonymous', options[:allow_anon], nil, nil, nil, options[:anon_failure] ],
|
|
265
|
+
[ 'any user', options[:allow_any_user], :basic ],
|
|
266
|
+
[ 'admin user', options[:allow_admin], :admin ]
|
|
267
|
+
]
|
|
268
|
+
|
|
269
|
+
unless options[:allow_groups].blank?
|
|
270
|
+
if options[:allow_groups].is_a?(String)
|
|
271
|
+
options[:allow_groups] = options[:allow_groups].gsub(',', ';').split(';').map{|v| v.strip}
|
|
272
|
+
end
|
|
273
|
+
options[:allow_groups].each do |group|
|
|
274
|
+
tests << [ "#{group} member", true, :basic, group ]
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
unless options[:deny_groups].blank?
|
|
279
|
+
if options[:deny_groups].is_a?(String)
|
|
280
|
+
options[:deny_groups] = options[:deny_groups].gsub(',', ';').split(';').map{|v| v.strip}
|
|
281
|
+
end
|
|
282
|
+
options[:deny_groups].each do |group|
|
|
283
|
+
tests << [ "#{group} member", false, :basic, group ]
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
tests.each do |(label, result, user, group, success_override, failure_override)|
|
|
288
|
+
expected_result = result ? (success_override || options[:success]) : (failure_override || options[:failure])
|
|
289
|
+
|
|
290
|
+
test_code = "test \"should #{result ? '' : 'not '}allow access to #{action} for #{label}\" do\n"
|
|
291
|
+
|
|
292
|
+
if user
|
|
293
|
+
test_code += "user = users(#{user.inspect})\n"
|
|
294
|
+
if group
|
|
295
|
+
test_code += "group = AccessGroup.get(#{group.inspect}) || AccessGroup.create(name: #{group.inspect})\n"
|
|
296
|
+
test_code += "user.groups << group\n"
|
|
297
|
+
end
|
|
298
|
+
test_code += "log_in_as user\n"
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
test_code += "path = #{url_helper}\n"
|
|
302
|
+
|
|
303
|
+
if params.blank?
|
|
304
|
+
test_code += "#{method} path\n"
|
|
305
|
+
else
|
|
306
|
+
test_code += "#{method} path, #{params.inspect[1...-1]}\n"
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
if expected_result.is_a?(Symbol)
|
|
310
|
+
test_code += "assert_response #{expected_result.inspect}\n"
|
|
311
|
+
else
|
|
312
|
+
test_code += "assert_redirected_to #{expected_result}\n"
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
test_code += "end\n"
|
|
316
|
+
|
|
317
|
+
eval test_code
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
##
|
|
323
|
+
# Is a user currently logged in?
|
|
324
|
+
def is_logged_in?
|
|
325
|
+
!session[:user_id].nil?
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
##
|
|
329
|
+
# Logs in as the specified user.
|
|
330
|
+
def log_in_as(user, options = {})
|
|
331
|
+
password = options[:password] || 'password'
|
|
332
|
+
remember_me = options[:remember_me] || '1'
|
|
333
|
+
if integration_test?
|
|
334
|
+
post login_path, session: { email: user.email, password: password, remember_me: remember_me }
|
|
335
|
+
else
|
|
336
|
+
session[:user_id] = user.id
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
##
|
|
341
|
+
# Are we running an integration test?
|
|
342
|
+
def integration_test?
|
|
343
|
+
defined?(post_via_redirect)
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
|