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,118 @@
|
|
|
1
|
+
require 'spawnling'
|
|
2
|
+
|
|
3
|
+
module BarkestCore
|
|
4
|
+
##
|
|
5
|
+
# This module contains helper methods related to status reporting.
|
|
6
|
+
#
|
|
7
|
+
module StatusHelper
|
|
8
|
+
|
|
9
|
+
##
|
|
10
|
+
# Shows the system status while optionally performing a long running code block.
|
|
11
|
+
#
|
|
12
|
+
# Accepted options:
|
|
13
|
+
#
|
|
14
|
+
# url_on_completion::
|
|
15
|
+
# This is the URL you want to redirect to when the long running code completes.
|
|
16
|
+
# If not set, then the completion button will have an empty HREF which means it will simply reload the status page.
|
|
17
|
+
# It is therefore highly recommended that you provide this value when using this method.
|
|
18
|
+
#
|
|
19
|
+
# completion_button::
|
|
20
|
+
# This is the label for the button that becomes visible when the long running code completes.
|
|
21
|
+
# Defaults to 'Continue'.
|
|
22
|
+
#
|
|
23
|
+
# main_status::
|
|
24
|
+
# This is the initial status to report for the system when a long running code block is provided.
|
|
25
|
+
#
|
|
26
|
+
# If a code block is provided, this will reset the system status and spawn a thread to run the code block.
|
|
27
|
+
# Before running the code block, it will acquire a GlobalStatus lock and set the initial status.
|
|
28
|
+
# When the code block exits, either through error or normal behavior, the GlobalStatus lock will be released.
|
|
29
|
+
#
|
|
30
|
+
# It will yield the +status+ object to the code block on a successful lock, or it will yield false to the code
|
|
31
|
+
# block to let it know that a lock could not be acquired. You should check for this in your code block and
|
|
32
|
+
# handle the error as appropriate.
|
|
33
|
+
#
|
|
34
|
+
# Example 1:
|
|
35
|
+
# def my_action
|
|
36
|
+
# Spawling.new do
|
|
37
|
+
# GlobalStatus.lock_for do |status|
|
|
38
|
+
# if status
|
|
39
|
+
# clear_system_status # reset the log file.
|
|
40
|
+
# # Do something that takes a long time.
|
|
41
|
+
# ...
|
|
42
|
+
# end
|
|
43
|
+
# end
|
|
44
|
+
# end
|
|
45
|
+
# show_system_status(:url_on_completion => my_target_url)
|
|
46
|
+
# end
|
|
47
|
+
#
|
|
48
|
+
# Example 2:
|
|
49
|
+
# def my_action
|
|
50
|
+
# show_system_status(:url_on_completion => my_target_url) do |status|
|
|
51
|
+
# if status
|
|
52
|
+
# # Do something that takes a long time.
|
|
53
|
+
# ...
|
|
54
|
+
# end
|
|
55
|
+
# end
|
|
56
|
+
# end
|
|
57
|
+
#
|
|
58
|
+
# The benefits of Example 2 is that it handles the thread spawning and status locking for you.
|
|
59
|
+
#
|
|
60
|
+
def show_system_status(options = {})
|
|
61
|
+
options = {
|
|
62
|
+
url_on_completion: nil,
|
|
63
|
+
completion_button: 'Continue',
|
|
64
|
+
main_status: 'System is busy'
|
|
65
|
+
}.merge(options || {})
|
|
66
|
+
|
|
67
|
+
if block_given?
|
|
68
|
+
clear_system_status
|
|
69
|
+
Spawnling.new do
|
|
70
|
+
status = BarkestCore::GlobalStatus.new
|
|
71
|
+
if status.acquire_lock
|
|
72
|
+
status.set_message options[:main_status]
|
|
73
|
+
begin
|
|
74
|
+
yield status
|
|
75
|
+
ensure
|
|
76
|
+
status.release_lock
|
|
77
|
+
end
|
|
78
|
+
else
|
|
79
|
+
yield false
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
session[:status_comp_url] = options[:url_on_completion]
|
|
85
|
+
session[:status_comp_lbl] = options[:completion_button]
|
|
86
|
+
|
|
87
|
+
redirect_to status_current_url
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
##
|
|
91
|
+
# Clears the system status log file.
|
|
92
|
+
#
|
|
93
|
+
# If the file does not exist, it is created as a zero byte file.
|
|
94
|
+
# This is important for the status checking, since if there is no log file it will report an error.
|
|
95
|
+
#
|
|
96
|
+
def clear_system_status
|
|
97
|
+
unless BarkestCore::GlobalStatus.locked?
|
|
98
|
+
# open, truncate, and close.
|
|
99
|
+
File.open(BarkestCore::WorkPath.system_status_file,'w').close
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
##
|
|
104
|
+
# Gets the URL to redirect to when the long running process completes.
|
|
105
|
+
#
|
|
106
|
+
def status_redirect_url
|
|
107
|
+
session[:status_comp_url].to_s
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
##
|
|
111
|
+
# Gets the label for the button to show when the long running process completes.
|
|
112
|
+
#
|
|
113
|
+
def status_button_label
|
|
114
|
+
session[:status_comp_lbl].to_s
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module BarkestCore
|
|
2
|
+
##
|
|
3
|
+
# This module adds helper methods related to users in general (not just the current user).
|
|
4
|
+
#
|
|
5
|
+
# Based on the tutorial from [www.railstutorial.org](www.railstutorial.org).
|
|
6
|
+
#
|
|
7
|
+
module UsersHelper
|
|
8
|
+
|
|
9
|
+
##
|
|
10
|
+
# Returns the Gravatar for the given user.
|
|
11
|
+
#
|
|
12
|
+
# Based on the tutorial from [www.railstutorial.org](www.railstutorial.org).
|
|
13
|
+
#
|
|
14
|
+
# The +user+ is the user you want to get the gravatar for.
|
|
15
|
+
#
|
|
16
|
+
# Valid options:
|
|
17
|
+
# * +size+ The size (in pixels) for the returned gravatar. The gravatar will be a square image using this
|
|
18
|
+
# value as both the width and height. The default is 80 pixels.
|
|
19
|
+
# * +default+ The default image to return when no image is set. This can be nil, :mm, :identicon, :monsterid,
|
|
20
|
+
# :wavatar, or :retro. The default is :identicon.
|
|
21
|
+
def gravatar_for(user, options = {})
|
|
22
|
+
options = { size: 80, default: :identicon }.merge(options || {})
|
|
23
|
+
options[:default] = options[:default].to_s.to_sym unless options[:default].nil? || options[:default].is_a?(Symbol)
|
|
24
|
+
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
|
|
25
|
+
size = options[:size]
|
|
26
|
+
default = [:mm, :identicon, :monsterid, :wavatar, :retro].include?(options[:default]) ? "&d=#{options[:default]}" : ''
|
|
27
|
+
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}#{default}"
|
|
28
|
+
image_tag(gravatar_url, alt: user.name, class: 'gravatar', style: "width: #{size}px, height: #{size}px")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
data/app/mailers/.keep
ADDED
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module BarkestCore
|
|
2
|
+
##
|
|
3
|
+
# This class defines the default behavior for mailers in this application.
|
|
4
|
+
#
|
|
5
|
+
class ApplicationMailerBase < ActionMailer::Base
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
##
|
|
9
|
+
# Gets the default hostname for messages.
|
|
10
|
+
def self.default_hostname
|
|
11
|
+
@default_hostname ||= BarkestCore.email_config[:default_hostname]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
##
|
|
15
|
+
# Gets the default sender for messages.
|
|
16
|
+
def self.default_sender
|
|
17
|
+
@default_sender ||= BarkestCore.email_config[:default_sender]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
##
|
|
21
|
+
# Gets the default recipient for messages.
|
|
22
|
+
def self.default_recipient
|
|
23
|
+
@default_recipient ||= BarkestCore.email_config[:default_recipient]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
default from: ApplicationMailerBase.default_sender, to: ApplicationMailerBase.default_recipient
|
|
27
|
+
layout 'mailer'
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require_dependency 'barkest_core/application_mailer_base.rb'
|
|
2
|
+
|
|
3
|
+
module BarkestCore
|
|
4
|
+
##
|
|
5
|
+
# This mailer is used for the generic contact form.
|
|
6
|
+
class ContactForm < ::BarkestCore::ApplicationMailerBase
|
|
7
|
+
|
|
8
|
+
##
|
|
9
|
+
# Sends the message from the contact form.
|
|
10
|
+
def contact(msg)
|
|
11
|
+
@data = {
|
|
12
|
+
msg: msg,
|
|
13
|
+
client_ip: msg.remote_ip,
|
|
14
|
+
gems: BarkestCore.gem_list(Rails.application.class.parent_name.underscore, 'rails', 'barkest*'),
|
|
15
|
+
}
|
|
16
|
+
mail subject: msg.full_subject, reply_to: msg.your_email
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require_dependency 'barkest_core/application_mailer_base.rb'
|
|
2
|
+
|
|
3
|
+
module BarkestCore
|
|
4
|
+
##
|
|
5
|
+
# This mailer is used for the account activation, password reset, and invalid password reset messages.
|
|
6
|
+
#
|
|
7
|
+
class UserMailer < ::BarkestCore::ApplicationMailerBase
|
|
8
|
+
|
|
9
|
+
##
|
|
10
|
+
# Sends the activation email to a new user.
|
|
11
|
+
def account_activation(data = {})
|
|
12
|
+
@data = {
|
|
13
|
+
user: nil,
|
|
14
|
+
client_ip: '0.0.0.0'
|
|
15
|
+
}.merge(data || {})
|
|
16
|
+
raise unless data[:user]
|
|
17
|
+
mail to: data[:user].email, subject: 'Account activation'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
##
|
|
21
|
+
# Sends the password reset email to an existing user.
|
|
22
|
+
def password_reset(data = {})
|
|
23
|
+
@data = {
|
|
24
|
+
user: nil,
|
|
25
|
+
client_ip: '0.0.0.0'
|
|
26
|
+
}.merge(data || {})
|
|
27
|
+
raise unless data[:user]
|
|
28
|
+
mail to: data[:user].email, subject: 'Password reset request'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
##
|
|
32
|
+
# Sends an invalid password reset attempt message to a user whether they exist or not.
|
|
33
|
+
def invalid_password_reset(data = {})
|
|
34
|
+
@data = {
|
|
35
|
+
email: nil,
|
|
36
|
+
message: 'This email address is not associated with an existing account.',
|
|
37
|
+
client_ip: '0.0.0.0'
|
|
38
|
+
}.merge(data || {})
|
|
39
|
+
raise unless data[:email]
|
|
40
|
+
mail to: data[:email], subject: 'Password reset request'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
end
|
data/app/models/.keep
ADDED
|
File without changes
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
##
|
|
2
|
+
# Defines the authorization mechanism for the system.
|
|
3
|
+
#
|
|
4
|
+
# Access Groups can contain users and other access groups. Any member gains access to
|
|
5
|
+
# any resource that allows the parent access group.
|
|
6
|
+
class AccessGroup < ::BarkestCore::DbTable
|
|
7
|
+
|
|
8
|
+
include BarkestCore::NamedModel
|
|
9
|
+
|
|
10
|
+
# hide the Groups<=>Users relationship association
|
|
11
|
+
has_many :access_group_user_members, class_name: 'AccessGroupUserMember', foreign_key: 'group_id', dependent: :delete_all
|
|
12
|
+
private :access_group_user_members, :access_group_user_members=
|
|
13
|
+
|
|
14
|
+
# and expose the Users relationship instead.
|
|
15
|
+
has_many :users, class_name: 'User', through: :access_group_user_members, source: :member
|
|
16
|
+
|
|
17
|
+
# hide the Groups<=>Groups relationship association
|
|
18
|
+
has_many :access_group_group_members, class_name: 'AccessGroupGroupMember', foreign_key: 'group_id', dependent: :delete_all
|
|
19
|
+
private :access_group_group_members, :access_group_group_members=
|
|
20
|
+
|
|
21
|
+
# and expose the group members.
|
|
22
|
+
has_many :members, class_name: 'AccessGroup', through: :access_group_group_members, source: :member
|
|
23
|
+
|
|
24
|
+
##
|
|
25
|
+
# Gets a list of memberships for this group. (Read-only)
|
|
26
|
+
def memberships(refresh = false)
|
|
27
|
+
@memberships = nil if refresh
|
|
28
|
+
@memberships ||= AccessGroupGroupMember.where(member_id: id).includes(:group).map{|v| v.group}.to_a.freeze
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
has_many :ldap_groups, class_name: 'LdapAccessGroup', foreign_key: 'group_id', dependent: :delete_all
|
|
32
|
+
|
|
33
|
+
validates :name,
|
|
34
|
+
presence: true,
|
|
35
|
+
length: { maximum: 100 },
|
|
36
|
+
uniqueness: { case_sensitive: false }
|
|
37
|
+
|
|
38
|
+
scope :sorted, ->{ order(:name) }
|
|
39
|
+
|
|
40
|
+
##
|
|
41
|
+
# Gets the LDAP group list as a newline separated string.
|
|
42
|
+
#
|
|
43
|
+
# Specify +refresh+ to force the list to be reloaded.
|
|
44
|
+
#
|
|
45
|
+
# Specify a +separator+ if your would like to use something other than a newline.
|
|
46
|
+
def ldap_group_list(refresh = false, separator = "\n")
|
|
47
|
+
@ldap_group_list = nil if refresh
|
|
48
|
+
@ldap_group_list ||= ldap_groups(refresh).map{|v| v.name.upcase}.join(separator)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
##
|
|
52
|
+
# Splits a newline separated string into LDAP groups for this group.
|
|
53
|
+
#
|
|
54
|
+
# +value+ can be either a newline separated string or an array of strings.
|
|
55
|
+
def ldap_group_list=(value)
|
|
56
|
+
# convert string into array.
|
|
57
|
+
value = value.split("\n") if value.is_a?(String)
|
|
58
|
+
|
|
59
|
+
@ldap_group_list = nil
|
|
60
|
+
|
|
61
|
+
if value.is_a?(Array) && value.count > 0
|
|
62
|
+
|
|
63
|
+
value = value.map{|v| v.to_s.upcase}.uniq
|
|
64
|
+
|
|
65
|
+
# remove those missing from the new list.
|
|
66
|
+
ldap_groups.where.not(name: value).delete_all
|
|
67
|
+
|
|
68
|
+
# remove items already existing in the current list.
|
|
69
|
+
value.delete_if {|v| ldap_groups.where(name: v).count != 0 }
|
|
70
|
+
|
|
71
|
+
# add items missing from the current list.
|
|
72
|
+
value.each do |new_group|
|
|
73
|
+
ldap_groups << LdapAccessGroup.new(group: self, name: new_group)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
else
|
|
77
|
+
|
|
78
|
+
# clear the list.
|
|
79
|
+
ldap_groups.delete_all
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
ldap_groups true
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
##
|
|
86
|
+
# Determines if this group belongs to the specified group.
|
|
87
|
+
def belongs_to?(group)
|
|
88
|
+
group = AccessGroup.get(group) unless group.is_a?(AccessGroup)
|
|
89
|
+
return false unless group
|
|
90
|
+
safe_belongs_to?(group)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
##
|
|
94
|
+
# Gets a list of all the groups this group provides effective membership to.
|
|
95
|
+
def effective_groups
|
|
96
|
+
ret = [ self ]
|
|
97
|
+
memberships.each do |m|
|
|
98
|
+
unless ret.include?(m) # prevent infinite recursion
|
|
99
|
+
tmp = m.effective_groups
|
|
100
|
+
tmp.each do |g|
|
|
101
|
+
ret << g unless ret.include?(g)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
ret
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
protected
|
|
109
|
+
|
|
110
|
+
def safe_belongs_to?(group, already_tried = [])
|
|
111
|
+
return true if self == group
|
|
112
|
+
already_tried << self
|
|
113
|
+
memberships.each do |parent|
|
|
114
|
+
unless already_tried.include?(parent)
|
|
115
|
+
return true if parent.safe_belongs_to?(group, already_tried)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
false
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
##
|
|
2
|
+
# Defines an access group that belongs to another access group.
|
|
3
|
+
class AccessGroupGroupMember < ::BarkestCore::DbTable
|
|
4
|
+
belongs_to :group, class_name: 'AccessGroup'
|
|
5
|
+
belongs_to :member, class_name: 'AccessGroup'
|
|
6
|
+
|
|
7
|
+
validates :group_id, presence: true
|
|
8
|
+
validates :member_id, presence: true, uniqueness: { scope: :group_id }
|
|
9
|
+
|
|
10
|
+
# member_id should not equal group_id or cause infinite recursion.
|
|
11
|
+
# these two issues are addressed in the AccessGroup model.
|
|
12
|
+
|
|
13
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
##
|
|
2
|
+
# Defines a user that belongs to an access group.
|
|
3
|
+
class AccessGroupUserMember < ::BarkestCore::DbTable
|
|
4
|
+
|
|
5
|
+
belongs_to :group, class_name: 'AccessGroup'
|
|
6
|
+
belongs_to :member, class_name: 'User'
|
|
7
|
+
|
|
8
|
+
validates :group_id, presence: true
|
|
9
|
+
validates :member_id, presence: true, uniqueness: { scope: :group_id }
|
|
10
|
+
|
|
11
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
module BarkestCore
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# Defines the authentication configuration for the system.
|
|
5
|
+
class AuthConfig
|
|
6
|
+
include ActiveModel::Model
|
|
7
|
+
include ActiveModel::Validations
|
|
8
|
+
|
|
9
|
+
attr_accessor :enable_db_auth, :enable_ldap_auth, :ldap_host, :ldap_port, :ldap_base_dn, :ldap_ssl,
|
|
10
|
+
:ldap_browse_user, :ldap_browse_password, :ldap_auto_activate, :ldap_system_admin_groups
|
|
11
|
+
|
|
12
|
+
validate do
|
|
13
|
+
errors.add :enable_db_auth, 'must be selected if enable_ldap_auth is not selected' unless enable_ldap_auth? || enable_db_auth?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
with_options if: :enable_ldap_auth?, presence: true do |cfg|
|
|
17
|
+
cfg.validates :ldap_host
|
|
18
|
+
cfg.validates :ldap_port
|
|
19
|
+
cfg.validates :ldap_base_dn
|
|
20
|
+
cfg.validates :ldap_browse_user
|
|
21
|
+
cfg.validates :ldap_browse_password
|
|
22
|
+
cfg.validates :ldap_system_admin_groups
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
##
|
|
26
|
+
# Creates the configuration.
|
|
27
|
+
def initialize(*args)
|
|
28
|
+
args.each do |arg|
|
|
29
|
+
if arg.is_a?(Hash)
|
|
30
|
+
arg.each do |k,v|
|
|
31
|
+
if respond_to?(:"#{k}?")
|
|
32
|
+
send :"#{k}=", ((v === true || v === '1') ? '1' : '0')
|
|
33
|
+
elsif respond_to?(k)
|
|
34
|
+
send :"#{k}=", v.to_s
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
##
|
|
42
|
+
# Is DB authentication enabled?
|
|
43
|
+
def enable_db_auth?
|
|
44
|
+
enable_db_auth.to_s.to_i != 0
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
##
|
|
48
|
+
# Is LDAP authentication enabled?
|
|
49
|
+
def enable_ldap_auth?
|
|
50
|
+
enable_ldap_auth.to_s.to_i != 0
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
##
|
|
54
|
+
# Is SSL enabled for LDAP authentication?
|
|
55
|
+
def ldap_ssl?
|
|
56
|
+
ldap_ssl.to_s.to_i != 0
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
##
|
|
60
|
+
# Is automatic activation enabled for LDAP authenticated users?
|
|
61
|
+
def ldap_auto_activate?
|
|
62
|
+
ldap_auto_activate.to_s.to_i != 0
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
##
|
|
66
|
+
# Converts the configuration to a hash.
|
|
67
|
+
def to_h
|
|
68
|
+
{
|
|
69
|
+
enable_db_auth: enable_db_auth?,
|
|
70
|
+
enable_ldap_auth: enable_ldap_auth?,
|
|
71
|
+
ldap_host: ldap_host.to_s,
|
|
72
|
+
ldap_port: ldap_port.to_s.to_i,
|
|
73
|
+
ldap_ssl: ldap_ssl?,
|
|
74
|
+
ldap_base_dn: ldap_base_dn.to_s,
|
|
75
|
+
ldap_browse_user: ldap_browse_user.to_s,
|
|
76
|
+
ldap_browse_password: ldap_browse_password.to_s,
|
|
77
|
+
ldap_auto_activate: ldap_auto_activate?,
|
|
78
|
+
ldap_system_admin_groups: ldap_system_admin_groups.to_s,
|
|
79
|
+
}
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
##
|
|
83
|
+
# Saves the configuration (encrypted) to the SystemConfig.
|
|
84
|
+
def save
|
|
85
|
+
SystemConfig.set :auth, to_h, true
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
##
|
|
89
|
+
# Loads the configuration from the SystemConfig.
|
|
90
|
+
def AuthConfig.load
|
|
91
|
+
AuthConfig.new(SystemConfig.get(:auth) || {})
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
|
95
|
+
end
|