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
|
File without changes
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
##
|
|
2
|
+
# This is the controller that allows managing the access groups used for authorizing access to resources.
|
|
3
|
+
#
|
|
4
|
+
class AccessGroupsController < ApplicationController
|
|
5
|
+
before_action :validate_user
|
|
6
|
+
before_action :set_access_group, only: [:show, :edit, :update, :destroy]
|
|
7
|
+
|
|
8
|
+
##
|
|
9
|
+
# GET /access_groups
|
|
10
|
+
def index
|
|
11
|
+
@access_groups = AccessGroup.all.sorted
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
##
|
|
15
|
+
# GET /access_groups/1
|
|
16
|
+
def show
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
##
|
|
20
|
+
# GET /access_groups/new
|
|
21
|
+
def new
|
|
22
|
+
@access_group = AccessGroup.new
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
##
|
|
26
|
+
# GET /access_groups/1/edit
|
|
27
|
+
def edit
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
##
|
|
31
|
+
# POST /access_groups
|
|
32
|
+
def create
|
|
33
|
+
@access_group = AccessGroup.new(access_group_params)
|
|
34
|
+
|
|
35
|
+
if @access_group.save
|
|
36
|
+
redirect_to access_groups_url, notice: 'Access group was successfully created.'
|
|
37
|
+
else
|
|
38
|
+
render :new
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
##
|
|
43
|
+
# PATCH/PUT /access_groups/1
|
|
44
|
+
def update
|
|
45
|
+
if @access_group.update(access_group_params)
|
|
46
|
+
redirect_to access_groups_url, notice: 'Access group was successfully updated.'
|
|
47
|
+
else
|
|
48
|
+
render :edit
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
##
|
|
53
|
+
# DELETE /access_groups/1
|
|
54
|
+
def destroy
|
|
55
|
+
@access_group.destroy
|
|
56
|
+
redirect_to access_groups_url, notice: 'Access group was successfully destroyed.'
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def validate_user
|
|
62
|
+
authorize! true
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
66
|
+
def set_access_group
|
|
67
|
+
@access_group = AccessGroup.find(params[:id])
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Only allow a trusted parameter "white list" through.
|
|
71
|
+
def access_group_params
|
|
72
|
+
params.require(:access_group).permit(:name, :ldap_group_list)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
##
|
|
2
|
+
# This is a simple controller that handles account activation requests.
|
|
3
|
+
#
|
|
4
|
+
class AccountActivationsController < ApplicationController
|
|
5
|
+
|
|
6
|
+
##
|
|
7
|
+
# Takes in the user's email address and activation token as parameters.
|
|
8
|
+
#
|
|
9
|
+
# If the activation token is correct for the email, then the account is activated.
|
|
10
|
+
# If a user is logged in, then the user must be activated already, so alert them that reactivation is not allowed.
|
|
11
|
+
def edit
|
|
12
|
+
if logged_in?
|
|
13
|
+
flash[:danger] = 'You cannot reactivate your account.'
|
|
14
|
+
redirect_to root_url
|
|
15
|
+
else
|
|
16
|
+
user = User.find_by(email: params[:email].downcase)
|
|
17
|
+
if user && !user.activated? && user.authenticated?(:activation, params[:id])
|
|
18
|
+
user.activate
|
|
19
|
+
log_in user
|
|
20
|
+
flash[:success] = 'Your account has been activated.'
|
|
21
|
+
redirect_to user
|
|
22
|
+
else
|
|
23
|
+
flash[:danger] = 'Invalid activation link'
|
|
24
|
+
redirect_to root_url
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
module BarkestCore
|
|
2
|
+
##
|
|
3
|
+
# This is the default application controller for the Barkest library.
|
|
4
|
+
# The application's ApplicationController should inherit from this.
|
|
5
|
+
class ApplicationControllerBase < ActionController::Base
|
|
6
|
+
|
|
7
|
+
include BarkestCore::SessionsHelper
|
|
8
|
+
include BarkestCore::RecaptchaHelper
|
|
9
|
+
include BarkestCore::StatusHelper
|
|
10
|
+
|
|
11
|
+
protect_from_forgery with: :exception
|
|
12
|
+
layout 'layouts/application'
|
|
13
|
+
helper BarkestCore::Engine.helpers
|
|
14
|
+
|
|
15
|
+
##
|
|
16
|
+
# Should we show the denial reason when a user cannot access an action?
|
|
17
|
+
#
|
|
18
|
+
# Override this for any controller you want to show the denial reasons on.
|
|
19
|
+
def show_denial_reason?
|
|
20
|
+
false
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
##
|
|
24
|
+
# Authorize the current action.
|
|
25
|
+
#
|
|
26
|
+
# * If +group_list+ is not provided or only contains +false+ then any authenticated user will be authorized.
|
|
27
|
+
# * If +group_list+ contains +true+ then only system administrators will be authorized.
|
|
28
|
+
# * Otherwise the +group_list+ contains a list of accepted groups that will be authorized.
|
|
29
|
+
# Any user with one or more groups from the list will be granted access.
|
|
30
|
+
def authorize!(*group_list)
|
|
31
|
+
begin
|
|
32
|
+
|
|
33
|
+
# an authenticated user must exist.
|
|
34
|
+
unless logged_in?
|
|
35
|
+
store_location
|
|
36
|
+
|
|
37
|
+
raise_not_logged_in "You need to login to access '#{request.fullpath}'.",
|
|
38
|
+
'nobody is logged in'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# clean up the group list.
|
|
42
|
+
group_list ||= []
|
|
43
|
+
group_list.delete false
|
|
44
|
+
group_list.delete ''
|
|
45
|
+
|
|
46
|
+
if group_list.include?(true)
|
|
47
|
+
# group_list contains "true" so only a system admin may continue.
|
|
48
|
+
unless system_admin?
|
|
49
|
+
if show_denial_reason?
|
|
50
|
+
flash[:info] = 'The requested path is only available to system administrators.'
|
|
51
|
+
end
|
|
52
|
+
raise_authorize_failure "Your are not authorized to access '#{request.fullpath}'.",
|
|
53
|
+
'requires system administrator'
|
|
54
|
+
end
|
|
55
|
+
log_authorize_success 'user is system admin'
|
|
56
|
+
|
|
57
|
+
elsif group_list.blank?
|
|
58
|
+
# group_list is empty or contained nothing but empty strings and boolean false.
|
|
59
|
+
# everyone can continue.
|
|
60
|
+
log_authorize_success 'only requires authenticated user'
|
|
61
|
+
|
|
62
|
+
else
|
|
63
|
+
# the group list contains one or more authorized groups.
|
|
64
|
+
# we want them to all be uppercase strings.
|
|
65
|
+
group_list = group_list.map{|v| v.to_s.upcase}.sort
|
|
66
|
+
result = current_user.has_any_group?(*group_list)
|
|
67
|
+
unless result
|
|
68
|
+
message = group_list.join(', ')
|
|
69
|
+
if show_denial_reason?
|
|
70
|
+
flash[:info] = "The requested path requires one of these groups: #{message}"
|
|
71
|
+
end
|
|
72
|
+
raise_authorize_failure "You are not authorized to access '#{request.fullpath}'.",
|
|
73
|
+
"requires one of: #{message}"
|
|
74
|
+
end
|
|
75
|
+
log_authorize_success "user has '#{result}' group"
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
rescue BarkestCore::AuthorizeFailure => err
|
|
79
|
+
flash[:danger] = err.message
|
|
80
|
+
redirect_to root_url and return false
|
|
81
|
+
end
|
|
82
|
+
true
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
rescue_from NotLoggedIn do |exception|
|
|
86
|
+
flash[:info] = exception.message
|
|
87
|
+
redirect_to login_url
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
private
|
|
92
|
+
|
|
93
|
+
def raise_authorize_failure(message, log_message = nil)
|
|
94
|
+
log_authorize_failure message, log_message
|
|
95
|
+
raise BarkestCore::AuthorizeFailure.new(message)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def raise_not_logged_in(message, log_message = nil)
|
|
99
|
+
log_authorize_failure message, log_message
|
|
100
|
+
raise BarkestCore::NotLoggedIn.new(message)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def log_authorize_failure(message, log_message = nil)
|
|
104
|
+
log_message ||= message
|
|
105
|
+
Rails.logger.info "AUTH(FAILURE): #{request.fullpath}, #{current_user}, #{message}"
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def log_authorize_success(message)
|
|
109
|
+
Rails.logger.debug "AUTH(SUCCESS): #{request.fullpath}, #{current_user}, #{message}"
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module BarkestCore
|
|
2
|
+
##
|
|
3
|
+
# An application controller base with a few modifications making it ideal for the parent class to engine controllers.
|
|
4
|
+
class EngineControllerBase < ApplicationControllerBase
|
|
5
|
+
|
|
6
|
+
# As an engine, we need to make sure the NotLoggedIn exception flows properly.
|
|
7
|
+
# If we let this fall through, it looks for the route inside our engine.
|
|
8
|
+
# We need to tell it to look at the main app instead.
|
|
9
|
+
rescue_from NotLoggedIn do |exception|
|
|
10
|
+
flash[:info] = exception.message
|
|
11
|
+
redirect_to main_app.login_url
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
module BarkestCore
|
|
3
|
+
|
|
4
|
+
##
|
|
5
|
+
# A namespaced controller just for testing the submenu.
|
|
6
|
+
class TestsubController < ApplicationController
|
|
7
|
+
|
|
8
|
+
def page1
|
|
9
|
+
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def page2
|
|
13
|
+
flash.now[:success] = 'The subheader should be above this message.'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def page3
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
##
|
|
2
|
+
# This controller provides the basic contact form.
|
|
3
|
+
#
|
|
4
|
+
class ContactController < ApplicationController
|
|
5
|
+
|
|
6
|
+
##
|
|
7
|
+
# GET /contact
|
|
8
|
+
def index
|
|
9
|
+
@msg = BarkestCore::ContactMessage.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
##
|
|
13
|
+
# POST /contact
|
|
14
|
+
def create
|
|
15
|
+
@msg = get_message
|
|
16
|
+
if @msg.valid? && verify_recaptcha_challenge(@msg)
|
|
17
|
+
@msg.remote_ip = request.remote_ip
|
|
18
|
+
@msg.send_message
|
|
19
|
+
flash[:success] = 'Your message has been sent.'
|
|
20
|
+
redirect_to root_url
|
|
21
|
+
else
|
|
22
|
+
render 'index'
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def get_message
|
|
29
|
+
BarkestCore::ContactMessage.new(params.require(:barkest_core_contact_message).permit(:your_name, :your_email, :related_to, :subject, :body))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'time'
|
|
2
|
+
|
|
3
|
+
class LogViewController < ApplicationController
|
|
4
|
+
|
|
5
|
+
before_action :valid_user
|
|
6
|
+
before_action :load_options
|
|
7
|
+
before_action :load_log
|
|
8
|
+
|
|
9
|
+
def index
|
|
10
|
+
@options.max_records = 50
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def valid_user
|
|
16
|
+
authorize! true
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def load_options
|
|
20
|
+
@options = BarkestCore::LogViewOptions.new(
|
|
21
|
+
params.include?(:barkest_core_log_view_options) ?
|
|
22
|
+
params.require(:barkest_core_log_view_options).permit(:min_severity, :start_time, :end_time, :search) :
|
|
23
|
+
{ start_time: 7.days.ago }
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def load_log
|
|
28
|
+
# load, filter, and reverse sort.
|
|
29
|
+
@log = BarkestCore::LogEntry.read_log.keep_if{ |r| @options.keep_log_entry? r }.sort{ |a,b| b <=> a }
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
##
|
|
2
|
+
# This is a simple controller that processes user password reset requests.
|
|
3
|
+
#
|
|
4
|
+
class PasswordResetsController < ApplicationController
|
|
5
|
+
before_action :not_logged_in
|
|
6
|
+
before_action :load_user, only: [:edit, :update]
|
|
7
|
+
before_action :valid_user, only: [:edit, :update]
|
|
8
|
+
before_action :check_expiration, only: [:edit, :update]
|
|
9
|
+
|
|
10
|
+
##
|
|
11
|
+
# Shows the form allowing the user to enter their email address and confirm their non-robot status.
|
|
12
|
+
#
|
|
13
|
+
def new
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
##
|
|
18
|
+
# Verifies that the user is not a robot via recaptcha, once that is complete the submitted
|
|
19
|
+
# email address is looked up. Depending on the status of the user account looked up, one
|
|
20
|
+
# of four actions will occur.
|
|
21
|
+
#
|
|
22
|
+
# 1. The user account is active and valid, a reset email is sent.
|
|
23
|
+
# 2. The user account is disabled, a disabled account message is sent.
|
|
24
|
+
# 3. The user account has not been activated, an inactive account message is sent.
|
|
25
|
+
# 4. The user account doesn't exist, a non-existent account message is sent.
|
|
26
|
+
#
|
|
27
|
+
# Because a message is always sent, the caller cannot determine if the email address
|
|
28
|
+
# is a valid user account. If it is a valid attempt on a non-existent account,
|
|
29
|
+
# only the recipient will know that the email address is not associated with an account
|
|
30
|
+
# and will be able to work from there to create a new account.
|
|
31
|
+
#
|
|
32
|
+
def create
|
|
33
|
+
unless verify_recaptcha_challenge
|
|
34
|
+
flash.now[:danger] = 'You must complete the recaptcha challenge to reset your password.'
|
|
35
|
+
render 'new' and return
|
|
36
|
+
end
|
|
37
|
+
email = params[:password_reset][:email].downcase
|
|
38
|
+
unless email && User::VALID_EMAIL_REGEX.match(email)
|
|
39
|
+
flash.now[:danger] = 'You must provide a valid email address to reset your password.'
|
|
40
|
+
render 'new' and return
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
@user = User.find_by(email: email)
|
|
44
|
+
if @user && @user.ldap?
|
|
45
|
+
User.send_ldap_reset_email(email, request.remote_ip)
|
|
46
|
+
elsif @user && @user.enabled? && @user.activated?
|
|
47
|
+
@user.create_reset_digest
|
|
48
|
+
@user.send_password_reset_email request.remote_ip
|
|
49
|
+
elsif @user
|
|
50
|
+
if !@user.enabled?
|
|
51
|
+
User.send_disabled_reset_email(email, request.remote_ip)
|
|
52
|
+
elsif !@user.active?
|
|
53
|
+
User.send_inactive_reset_email(email, request.remote_ip)
|
|
54
|
+
else
|
|
55
|
+
User.send_missing_reset_email(email, request.remote_ip)
|
|
56
|
+
end
|
|
57
|
+
else
|
|
58
|
+
User.send_missing_reset_email(email, request.remote_ip)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
flash[:info] = 'An email with password reset information has been sent to you.'
|
|
62
|
+
redirect_to root_url
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
##
|
|
66
|
+
# Shows a form allowing the user to specify a new password for their account.
|
|
67
|
+
# This is of course after verifying that the email address is correct and the
|
|
68
|
+
# password reset token for the email address is correct.
|
|
69
|
+
#
|
|
70
|
+
def edit
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
##
|
|
75
|
+
# Resets the user's password. This is only done once the email address is
|
|
76
|
+
# confirmed as being associated with a valid account, and the password reset
|
|
77
|
+
# token provided matches that account. The user must also complete a
|
|
78
|
+
# recaptcha challenge to prevent robotic submissions, and the user's password
|
|
79
|
+
# must not be blank.
|
|
80
|
+
#
|
|
81
|
+
def update
|
|
82
|
+
if params[:user][:password].blank?
|
|
83
|
+
@user.errors.add(:password, 'can\'t be blank')
|
|
84
|
+
render 'edit'
|
|
85
|
+
elsif !verify_recaptcha_challenge(@user)
|
|
86
|
+
render 'edit'
|
|
87
|
+
elsif @user.update_attributes(user_params)
|
|
88
|
+
log_in @user
|
|
89
|
+
flash[:success] = 'Password has been reset.'
|
|
90
|
+
redirect_to @user
|
|
91
|
+
else
|
|
92
|
+
render 'edit'
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
private
|
|
97
|
+
|
|
98
|
+
def not_logged_in
|
|
99
|
+
if logged_in?
|
|
100
|
+
flash[:danger] = 'A logged in user cannot request a password reset.'
|
|
101
|
+
redirect_to root_url
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def user_params
|
|
106
|
+
params.require(:user).permit(:password, :password_confirmation)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def load_user
|
|
110
|
+
@user = User.find_by(email: params[:email])
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def valid_user
|
|
114
|
+
unless @user && !@user.ldap? && @user.enabled? && @user.activated? && @user.authenticated?(:reset, params[:id])
|
|
115
|
+
redirect_to root_url
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def check_expiration
|
|
120
|
+
if @user.password_reset_expired?
|
|
121
|
+
flash[:danger] = 'Password reset request has expired.'
|
|
122
|
+
redirect_to new_password_reset_url
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
end
|