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.
Files changed (308) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/Gemfile +22 -0
  4. data/Gemfile.lock +254 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +364 -0
  7. data/Rakefile +37 -0
  8. data/app/assets/fonts/barkest_core/ArchivoNarrow-Bold.ttf +0 -0
  9. data/app/assets/fonts/barkest_core/ArchivoNarrow-BoldItalic.ttf +0 -0
  10. data/app/assets/fonts/barkest_core/ArchivoNarrow-Italic.ttf +0 -0
  11. data/app/assets/fonts/barkest_core/ArchivoNarrow-Regular.ttf +0 -0
  12. data/app/assets/images/barkest_core/.keep +0 -0
  13. data/app/assets/images/barkest_core/barcode-B.svg +181 -0
  14. data/app/assets/javascripts/barkest_core/.keep +0 -0
  15. data/app/assets/javascripts/barkest_core/application.js +22 -0
  16. data/app/assets/javascripts/barkest_core/bootstrap-datepicker.js +1800 -0
  17. data/app/assets/javascripts/barkest_core/field_init.js +7 -0
  18. data/app/assets/javascripts/barkest_core/jquery.doubleScroll.js +112 -0
  19. data/app/assets/javascripts/barkest_core/masked_edit.js +25 -0
  20. data/app/assets/javascripts/barkest_core/system_status.js.erb +201 -0
  21. data/app/assets/stylesheets/barkest_core/.keep +0 -0
  22. data/app/assets/stylesheets/barkest_core/application.css +17 -0
  23. data/app/assets/stylesheets/barkest_core/custom.css.scss +264 -0
  24. data/app/assets/stylesheets/barkest_core/datepicker3.css +790 -0
  25. data/app/controllers/.keep +0 -0
  26. data/app/controllers/access_groups_controller.rb +74 -0
  27. data/app/controllers/account_activations_controller.rb +29 -0
  28. data/app/controllers/application_controller.rb +5 -0
  29. data/app/controllers/barkest_core/application_controller_base.rb +113 -0
  30. data/app/controllers/barkest_core/engine_controller_base.rb +15 -0
  31. data/app/controllers/barkest_core/testsub_controller.rb +21 -0
  32. data/app/controllers/contact_controller.rb +32 -0
  33. data/app/controllers/log_view_controller.rb +31 -0
  34. data/app/controllers/password_resets_controller.rb +126 -0
  35. data/app/controllers/sessions_controller.rb +64 -0
  36. data/app/controllers/status_controller.rb +150 -0
  37. data/app/controllers/system_config_controller.rb +238 -0
  38. data/app/controllers/system_update_controller.rb +164 -0
  39. data/app/controllers/test_access_controller.rb +44 -0
  40. data/app/controllers/test_report_controller.rb +75 -0
  41. data/app/controllers/users_controller.rb +218 -0
  42. data/app/helpers/.keep +0 -0
  43. data/app/helpers/barkest_core/application_helper.rb +134 -0
  44. data/app/helpers/barkest_core/form_helper.rb +469 -0
  45. data/app/helpers/barkest_core/html_helper.rb +70 -0
  46. data/app/helpers/barkest_core/misc_helper.rb +68 -0
  47. data/app/helpers/barkest_core/pdf_helper.rb +180 -0
  48. data/app/helpers/barkest_core/recaptcha_helper.rb +115 -0
  49. data/app/helpers/barkest_core/sessions_helper.rb +94 -0
  50. data/app/helpers/barkest_core/status_helper.rb +118 -0
  51. data/app/helpers/barkest_core/users_helper.rb +32 -0
  52. data/app/mailers/.keep +0 -0
  53. data/app/mailers/application_mailer.rb +5 -0
  54. data/app/mailers/barkest_core/application_mailer_base.rb +30 -0
  55. data/app/mailers/barkest_core/contact_form.rb +20 -0
  56. data/app/mailers/barkest_core/user_mailer.rb +44 -0
  57. data/app/models/.keep +0 -0
  58. data/app/models/access_group.rb +121 -0
  59. data/app/models/access_group_group_member.rb +13 -0
  60. data/app/models/access_group_user_member.rb +11 -0
  61. data/app/models/barkest_core/auth_config.rb +95 -0
  62. data/app/models/barkest_core/authorize_failure.rb +7 -0
  63. data/app/models/barkest_core/contact_message.rb +37 -0
  64. data/app/models/barkest_core/database_config.rb +223 -0
  65. data/app/models/barkest_core/db_table.rb +21 -0
  66. data/app/models/barkest_core/email_config.rb +132 -0
  67. data/app/models/barkest_core/global_status.rb +267 -0
  68. data/app/models/barkest_core/log_entry.rb +101 -0
  69. data/app/models/barkest_core/log_view_options.rb +51 -0
  70. data/app/models/barkest_core/ms_sql_db_definition.rb +441 -0
  71. data/app/models/barkest_core/ms_sql_definition.rb +221 -0
  72. data/app/models/barkest_core/ms_sql_function.rb +423 -0
  73. data/app/models/barkest_core/not_logged_in.rb +7 -0
  74. data/app/models/barkest_core/pdf_table_builder.rb +407 -0
  75. data/app/models/barkest_core/self_update_config.rb +37 -0
  76. data/app/models/barkest_core/user_alert.rb +29 -0
  77. data/app/models/barkest_core/user_alert_generators.rb +58 -0
  78. data/app/models/barkest_core/user_manager.rb +404 -0
  79. data/app/models/barkest_core/work_path.rb +74 -0
  80. data/app/models/disable_user.rb +18 -0
  81. data/app/models/ldap_access_group.rb +15 -0
  82. data/app/models/system_config.rb +99 -0
  83. data/app/models/user.rb +405 -0
  84. data/app/models/user_login_history.rb +11 -0
  85. data/app/views/.keep +0 -0
  86. data/app/views/access_groups/_form.html.erb +19 -0
  87. data/app/views/access_groups/edit.html.erb +2 -0
  88. data/app/views/access_groups/index.html.erb +32 -0
  89. data/app/views/access_groups/new.html.erb +2 -0
  90. data/app/views/access_groups/show.html.erb +4 -0
  91. data/app/views/barkest_core/contact_form/contact.html.erb +16 -0
  92. data/app/views/barkest_core/contact_form/contact.text.erb +13 -0
  93. data/app/views/barkest_core/testsub/_links.html.erb +5 -0
  94. data/app/views/barkest_core/testsub/page1.html.erb +3 -0
  95. data/app/views/barkest_core/testsub/page2.html.erb +2 -0
  96. data/app/views/barkest_core/testsub/page3.html.erb +2 -0
  97. data/app/views/barkest_core/user_mailer/account_activation.html.erb +7 -0
  98. data/app/views/barkest_core/user_mailer/account_activation.text.erb +6 -0
  99. data/app/views/barkest_core/user_mailer/invalid_password_reset.html.erb +3 -0
  100. data/app/views/barkest_core/user_mailer/invalid_password_reset.text.erb +5 -0
  101. data/app/views/barkest_core/user_mailer/password_reset.html.erb +8 -0
  102. data/app/views/barkest_core/user_mailer/password_reset.text.erb +7 -0
  103. data/app/views/contact/index.html.erb +24 -0
  104. data/app/views/layouts/_footer_copyright.html.erb +1 -0
  105. data/app/views/layouts/_menu_admin.html.erb +5 -0
  106. data/app/views/layouts/_menu_anon.html.erb +0 -0
  107. data/app/views/layouts/_menu_auth.html.erb +3 -0
  108. data/app/views/layouts/_menu_footer.html.erb +1 -0
  109. data/app/views/layouts/_nav_logo.html.erb +1 -0
  110. data/app/views/layouts/application.html.erb +2 -0
  111. data/app/views/layouts/barkest_core/_application.html.erb +24 -0
  112. data/app/views/layouts/barkest_core/_footer.html.erb +18 -0
  113. data/app/views/layouts/barkest_core/_header.html.erb +38 -0
  114. data/app/views/layouts/barkest_core/_html_mailer.html.erb +11 -0
  115. data/app/views/layouts/barkest_core/_menu_account.html.erb +14 -0
  116. data/app/views/layouts/barkest_core/_menu_sample.html.erb +1 -0
  117. data/app/views/layouts/barkest_core/_messages.html.erb +4 -0
  118. data/app/views/layouts/barkest_core/_shim.html.erb +4 -0
  119. data/app/views/layouts/barkest_core/_subheader.html.erb +1 -0
  120. data/app/views/layouts/barkest_core/_text_mailer.text.erb +4 -0
  121. data/app/views/layouts/mailer.html.erb +1 -0
  122. data/app/views/layouts/mailer.text.erb +1 -0
  123. data/app/views/log_view/index.html.erb +100 -0
  124. data/app/views/password_resets/edit.html.erb +20 -0
  125. data/app/views/password_resets/new.html.erb +14 -0
  126. data/app/views/sessions/new.html.erb +27 -0
  127. data/app/views/shared/_error_messages.html.erb +29 -0
  128. data/app/views/shared/_generic_user_alert.html.erb +4 -0
  129. data/app/views/status/current.html.erb +34 -0
  130. data/app/views/status/test.html.erb +50 -0
  131. data/app/views/system_config/index.html.erb +25 -0
  132. data/app/views/system_config/show_auth.html.erb +28 -0
  133. data/app/views/system_config/show_database.html.erb +36 -0
  134. data/app/views/system_config/show_email.html.erb +21 -0
  135. data/app/views/system_config/show_self_update.html.erb +13 -0
  136. data/app/views/system_update/index.html.erb +31 -0
  137. data/app/views/system_update/new.html.erb +2 -0
  138. data/app/views/test_access/allow_anon.html.erb +2 -0
  139. data/app/views/test_access/require_admin.html.erb +2 -0
  140. data/app/views/test_access/require_group_x.html.erb +2 -0
  141. data/app/views/test_access/require_user.html.erb +2 -0
  142. data/app/views/test_report/index.csv.csvrb +23 -0
  143. data/app/views/test_report/index.html.erb +6 -0
  144. data/app/views/test_report/index.pdf.prawn +50 -0
  145. data/app/views/test_report/index.xlsx.axlsx +28 -0
  146. data/app/views/users/_user.html.erb +57 -0
  147. data/app/views/users/_user_details.html.erb +15 -0
  148. data/app/views/users/_user_details_for_list.html.erb +1 -0
  149. data/app/views/users/_user_form.html.erb +13 -0
  150. data/app/views/users/disable_confirm.html.erb +19 -0
  151. data/app/views/users/edit.html.erb +15 -0
  152. data/app/views/users/index.html.erb +9 -0
  153. data/app/views/users/new.html.erb +10 -0
  154. data/app/views/users/show.html.erb +46 -0
  155. data/bin/rails +12 -0
  156. data/config/routes.rb +3 -0
  157. data/db/migrate/20160617172539_create_access_groups.rb +10 -0
  158. data/db/migrate/20160617172725_create_users.rb +26 -0
  159. data/db/migrate/20160617172833_create_user_login_histories.rb +12 -0
  160. data/db/migrate/20160622151720_create_access_group_user_members.rb +9 -0
  161. data/db/migrate/20160622151925_create_access_group_group_members.rb +9 -0
  162. data/db/migrate/20160701005706_create_ldap_access_groups.rb +11 -0
  163. data/db/migrate/20161108155029_create_system_configs.rb +11 -0
  164. data/db/seeds/barkest_core_01_create_users.rb +42 -0
  165. data/db/seeds.rb +53 -0
  166. data/lib/barkest_core/concerns/association_with_defaults.rb +55 -0
  167. data/lib/barkest_core/concerns/boolean_parser.rb +88 -0
  168. data/lib/barkest_core/concerns/date_parser.rb +181 -0
  169. data/lib/barkest_core/concerns/email_tester.rb +55 -0
  170. data/lib/barkest_core/concerns/encrypted_fields.rb +156 -0
  171. data/lib/barkest_core/concerns/named_model.rb +73 -0
  172. data/lib/barkest_core/concerns/number_parser.rb +145 -0
  173. data/lib/barkest_core/concerns/utc_conversion.rb +60 -0
  174. data/lib/barkest_core/engine.rb +105 -0
  175. data/lib/barkest_core/extensions/active_record_extensions.rb +120 -0
  176. data/lib/barkest_core/extensions/application_configuration_extensions.rb +38 -0
  177. data/lib/barkest_core/extensions/application_extensions.rb +50 -0
  178. data/lib/barkest_core/extensions/axlsx_extenstions.rb +157 -0
  179. data/lib/barkest_core/extensions/fixture_set_extensions.rb +107 -0
  180. data/lib/barkest_core/extensions/generator_extensions.rb +271 -0
  181. data/lib/barkest_core/extensions/main_app_extensions.rb +35 -0
  182. data/lib/barkest_core/extensions/prawn_document_extensions.rb +367 -0
  183. data/lib/barkest_core/extensions/prawn_table_extensions.rb +131 -0
  184. data/lib/barkest_core/extensions/router_extensions.rb +106 -0
  185. data/lib/barkest_core/extensions/simple_formatter_extensions.rb +66 -0
  186. data/lib/barkest_core/extensions/test_case_extensions.rb +348 -0
  187. data/lib/barkest_core/extensions/time_extensions.rb +164 -0
  188. data/lib/barkest_core/handlers/csv_handler.rb +30 -0
  189. data/lib/barkest_core/version.rb +3 -0
  190. data/lib/barkest_core.rb +324 -0
  191. data/lib/generators/barkest/install_generator.rb +102 -0
  192. data/lib/generators/barkest_core/actions/01_patch_application_controller.rb +55 -0
  193. data/lib/generators/barkest_core/actions/02_patch_application_mailer.rb +56 -0
  194. data/lib/generators/barkest_core/actions/03_patch_assets.rb +62 -0
  195. data/lib/generators/barkest_core/actions/04_patch_layouts.rb +36 -0
  196. data/lib/generators/barkest_core/actions/05_patch_routes.rb +93 -0
  197. data/lib/generators/barkest_core/actions/06_patch_seeds.rb +60 -0
  198. data/lib/generators/barkest_core/actions/07_copy_migrations.rb +51 -0
  199. data/lib/generators/barkest_core/actions/08_configure_database.rb +52 -0
  200. data/lib/generators/barkest_core/actions/09_configure_secrets.rb +29 -0
  201. data/lib/generators/barkest_core/actions/99_patch_gitignore.rb +57 -0
  202. data/lib/generators/barkest_core/install_generator.rb +17 -0
  203. data/test/barkest_core_test.rb +83 -0
  204. data/test/controllers/access_groups_controller_test.rb +53 -0
  205. data/test/controllers/contact_controller_test.rb +10 -0
  206. data/test/controllers/sessions_controller_test.rb +10 -0
  207. data/test/controllers/users_controller_test.rb +10 -0
  208. data/test/dummy/.gitignore +10 -0
  209. data/test/dummy/README.rdoc +28 -0
  210. data/test/dummy/Rakefile +6 -0
  211. data/test/dummy/app/assets/images/.keep +0 -0
  212. data/test/dummy/app/assets/javascripts/application.js +14 -0
  213. data/test/dummy/app/assets/stylesheets/application.css +16 -0
  214. data/test/dummy/app/controllers/application_controller.rb +5 -0
  215. data/test/dummy/app/controllers/concerns/.keep +0 -0
  216. data/test/dummy/app/helpers/application_helper.rb +2 -0
  217. data/test/dummy/app/mailers/.keep +0 -0
  218. data/test/dummy/app/mailers/application_mailer.rb +3 -0
  219. data/test/dummy/app/models/.keep +0 -0
  220. data/test/dummy/app/models/concerns/.keep +0 -0
  221. data/test/dummy/app/views/layouts/application.html.erb +1 -0
  222. data/test/dummy/app/views/layouts/mailer.html.erb +1 -0
  223. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  224. data/test/dummy/app/views/system_config/show_fake.html.erb +3 -0
  225. data/test/dummy/bin/bundle +3 -0
  226. data/test/dummy/bin/rails +4 -0
  227. data/test/dummy/bin/rake +4 -0
  228. data/test/dummy/bin/setup +29 -0
  229. data/test/dummy/config/application.rb +27 -0
  230. data/test/dummy/config/boot.rb +5 -0
  231. data/test/dummy/config/environment.rb +5 -0
  232. data/test/dummy/config/environments/development.rb +47 -0
  233. data/test/dummy/config/environments/production.rb +79 -0
  234. data/test/dummy/config/environments/test.rb +44 -0
  235. data/test/dummy/config/initializers/assets.rb +11 -0
  236. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  237. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  238. data/test/dummy/config/initializers/db_updater_ext.rb +33 -0
  239. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  240. data/test/dummy/config/initializers/inflections.rb +16 -0
  241. data/test/dummy/config/initializers/mime_types.rb +4 -0
  242. data/test/dummy/config/initializers/session_store.rb +3 -0
  243. data/test/dummy/config/initializers/sys_config_ext.rb +12 -0
  244. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  245. data/test/dummy/config/locales/en.yml +23 -0
  246. data/test/dummy/config/routes.rb +60 -0
  247. data/test/dummy/config.ru +4 -0
  248. data/test/dummy/db/schema.rb +95 -0
  249. data/test/dummy/db/seeds/barkest_core_01_create_users.rb +42 -0
  250. data/test/dummy/db/seeds.rb +51 -0
  251. data/test/dummy/lib/assets/.keep +0 -0
  252. data/test/dummy/log/.keep +0 -0
  253. data/test/dummy/public/404.html +67 -0
  254. data/test/dummy/public/422.html +67 -0
  255. data/test/dummy/public/500.html +66 -0
  256. data/test/dummy/public/favicon.ico +0 -0
  257. data/test/dummy/sql/my_test_view.sql +3 -0
  258. data/test/fixtures/access_groups.yml +21 -0
  259. data/test/fixtures/users.yml +71 -0
  260. data/test/helpers/barkest_core/sessions_helper_test.rb +22 -0
  261. data/test/integration/access_group_mgmt_test.rb +33 -0
  262. data/test/integration/access_test.rb +24 -0
  263. data/test/integration/account_activations_access_test.rb +12 -0
  264. data/test/integration/contact_test.rb +98 -0
  265. data/test/integration/extra_partial_test.rb +41 -0
  266. data/test/integration/log_view_access_test.rb +12 -0
  267. data/test/integration/password_resets_test.rb +101 -0
  268. data/test/integration/reports_test.rb +53 -0
  269. data/test/integration/status_access_test.rb +27 -0
  270. data/test/integration/system_config_access_test.rb +24 -0
  271. data/test/integration/system_update_access_test.rb +19 -0
  272. data/test/integration/users_access_test.rb +34 -0
  273. data/test/integration/users_edit_test.rb +178 -0
  274. data/test/integration/users_index_test.rb +62 -0
  275. data/test/integration/users_login_test.rb +67 -0
  276. data/test/integration/users_signup_test.rb +54 -0
  277. data/test/mailers/.keep +0 -0
  278. data/test/mailers/barkest_core/contact_form_test.rb +28 -0
  279. data/test/mailers/barkest_core/user_mailer_test.rb +43 -0
  280. data/test/mailers/previews/barkest_core/contact_form_preview.rb +17 -0
  281. data/test/mailers/previews/barkest_core/user_mailer_preview.rb +26 -0
  282. data/test/models/access_group_group_member_test.rb +28 -0
  283. data/test/models/access_group_test.rb +114 -0
  284. data/test/models/access_group_user_member_test.rb +28 -0
  285. data/test/models/barkest_core/auth_config_test.rb +57 -0
  286. data/test/models/barkest_core/bool_parser_test.rb +28 -0
  287. data/test/models/barkest_core/contact_message_test.rb +61 -0
  288. data/test/models/barkest_core/database_config_test.rb +33 -0
  289. data/test/models/barkest_core/date_parser_test.rb +110 -0
  290. data/test/models/barkest_core/email_config_test.rb +57 -0
  291. data/test/models/barkest_core/global_status_test.rb +50 -0
  292. data/test/models/barkest_core/ms_sql_db_updater_test.rb +115 -0
  293. data/test/models/barkest_core/ms_sql_definition_test.rb +102 -0
  294. data/test/models/barkest_core/ms_sql_function_test.rb +131 -0
  295. data/test/models/barkest_core/number_parser_test.rb +29 -0
  296. data/test/models/barkest_core/self_update_config_test.rb +29 -0
  297. data/test/models/barkest_core/user_alert_test.rb +19 -0
  298. data/test/models/barkest_core/user_manager_test.rb +34 -0
  299. data/test/models/barkest_core/work_path_test.rb +26 -0
  300. data/test/models/disable_user_test.rb +27 -0
  301. data/test/models/generic_time_test.rb +66 -0
  302. data/test/models/ldap_access_group_test.rb +31 -0
  303. data/test/models/pdf_table_builder_test.rb +6 -0
  304. data/test/models/system_config_test.rb +78 -0
  305. data/test/models/user_login_history_test.rb +37 -0
  306. data/test/models/user_test.rb +130 -0
  307. data/test/test_helper.rb +63 -0
  308. 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,5 @@
1
+ ##
2
+ # Default application controller. Easy to override in child apps.
3
+ class ApplicationController < ::BarkestCore::ApplicationControllerBase
4
+
5
+ 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