biovision 0.0.200518.1 → 0.12.211124.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (345) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +105 -52
  3. data/app/assets/images/biovision/icons/back.svg +19 -0
  4. data/app/assets/images/biovision/icons/create.svg +19 -0
  5. data/app/assets/images/biovision/icons/destroy.svg +12 -0
  6. data/app/assets/images/biovision/icons/dropdown.svg +3 -0
  7. data/app/assets/images/biovision/icons/edit.svg +22 -0
  8. data/app/assets/images/biovision/icons/gear.svg +11 -0
  9. data/app/assets/images/biovision/icons/return.svg +25 -0
  10. data/app/assets/images/biovision/icons/world.svg +11 -0
  11. data/app/assets/stylesheets/biovision/admin/components/users.scss +20 -0
  12. data/app/assets/stylesheets/biovision/admin/components.scss +13 -1
  13. data/app/assets/stylesheets/biovision/admin/layout.scss +27 -12
  14. data/app/assets/stylesheets/biovision/biovision.scss +105 -26
  15. data/app/assets/stylesheets/biovision/components/breadcrumbs.scss +13 -0
  16. data/app/assets/stylesheets/biovision/components/buttons.scss +130 -0
  17. data/app/assets/stylesheets/biovision/components/filters.scss +39 -0
  18. data/app/assets/stylesheets/biovision/components/forms.scss +208 -1
  19. data/app/assets/stylesheets/biovision/components/lists.scss +6 -7
  20. data/app/assets/stylesheets/biovision/{biovision → components}/messages.scss +9 -0
  21. data/app/assets/stylesheets/biovision/components/pagination.scss +34 -0
  22. data/app/assets/stylesheets/biovision/components/quick_search.scss +24 -0
  23. data/app/assets/stylesheets/biovision/components/simple_image.scss +112 -0
  24. data/app/assets/stylesheets/biovision/components/toggleable.scss +71 -0
  25. data/app/assets/stylesheets/biovision/components.scss +7 -0
  26. data/app/assets/stylesheets/biovision/default.scss +4 -4
  27. data/app/assets/stylesheets/biovision/themes/default_theme/components/users/dashboard.scss +4 -0
  28. data/app/assets/stylesheets/biovision/themes/default_theme/components/users/form_tabs.scss +101 -0
  29. data/app/assets/stylesheets/biovision/themes/default_theme/components/users/profile.scss +77 -0
  30. data/app/assets/stylesheets/biovision/themes/default_theme/components/users.scss +3 -0
  31. data/app/assets/stylesheets/biovision/themes/default_theme/components.scss +2 -3
  32. data/app/assets/stylesheets/biovision/themes/default_theme/layout/footer.scss +3 -0
  33. data/app/assets/stylesheets/biovision/themes/default_theme/layout/header.scss +12 -0
  34. data/app/assets/stylesheets/biovision/themes/default_theme/layout.scss +8 -19
  35. data/app/assets/stylesheets/biovision/themes/default_theme.scss +0 -1
  36. data/app/assets/stylesheets/biovision/vars.scss +5 -0
  37. data/app/controllers/admin/biovision_components_controller.rb +10 -0
  38. data/app/controllers/admin/components_controller.rb +37 -97
  39. data/app/controllers/admin/dynamic_blocks_controller.rb +15 -0
  40. data/app/controllers/admin/dynamic_pages_controller.rb +15 -0
  41. data/app/controllers/admin/index_controller.rb +8 -2
  42. data/app/controllers/admin/navigation_groups_controller.rb +45 -0
  43. data/app/controllers/admin/tokens_controller.rb +15 -0
  44. data/app/controllers/admin/users_controller.rb +101 -0
  45. data/app/controllers/admin_controller.rb +2 -8
  46. data/app/controllers/authentication_controller.rb +6 -34
  47. data/app/controllers/concerns/authentication.rb +12 -12
  48. data/app/controllers/concerns/component_stories.rb +22 -0
  49. data/app/controllers/concerns/crud_entities.rb +140 -0
  50. data/app/controllers/concerns/entity_priority.rb +10 -0
  51. data/app/controllers/concerns/my_crud_entities.rb +146 -0
  52. data/app/controllers/concerns/processed_forms.rb +28 -0
  53. data/app/controllers/concerns/restricted_access.rb +37 -0
  54. data/app/controllers/concerns/toggleable_entity.rb +31 -0
  55. data/app/controllers/contact_controller.rb +49 -0
  56. data/app/controllers/errors_controller.rb +37 -0
  57. data/app/controllers/fallback_controller.rb +12 -0
  58. data/app/controllers/index_controller.rb +1 -0
  59. data/app/controllers/legal_controller.rb +14 -0
  60. data/app/controllers/my/components_controller.rb +26 -0
  61. data/app/controllers/my/confirmations_controller.rb +44 -0
  62. data/app/controllers/my/index_controller.rb +7 -1
  63. data/app/controllers/my/profiles_controller.rb +33 -16
  64. data/app/controllers/oembed_controller.rb +12 -0
  65. data/app/controllers/profile_controller.rb +14 -0
  66. data/app/controllers/users_controller.rb +63 -0
  67. data/app/helpers/biovision_components_helper.rb +7 -3
  68. data/app/helpers/biovision_helper.rb +170 -0
  69. data/app/helpers/entity_helper.rb +77 -0
  70. data/app/helpers/my_helper.rb +34 -0
  71. data/app/helpers/simple_image_helper.rb +125 -0
  72. data/app/jobs/application_job.rb +7 -0
  73. data/app/jobs/send_phone_confirmation_job.rb +16 -0
  74. data/app/lib/biovision/components/base/component_parameters.rb +55 -0
  75. data/app/lib/biovision/components/base/component_privileges.rb +75 -0
  76. data/app/lib/biovision/components/base/component_settings.rb +40 -0
  77. data/app/lib/biovision/components/base/component_stories.rb +30 -0
  78. data/app/lib/biovision/components/base/entity_links.rb +38 -0
  79. data/app/lib/biovision/components/base/image_handling.rb +33 -0
  80. data/app/lib/biovision/components/base_component.rb +63 -95
  81. data/app/lib/biovision/components/contact_component.rb +26 -0
  82. data/app/lib/biovision/components/content/oembed/receiver.rb +98 -0
  83. data/app/lib/biovision/components/content/oembed/twitter_receiver.rb +20 -0
  84. data/app/lib/biovision/components/content/oembed/vimeo_receiver.rb +20 -0
  85. data/app/lib/biovision/components/content/oembed/youtube_receiver.rb +20 -0
  86. data/app/lib/biovision/components/content_component.rb +65 -0
  87. data/app/lib/biovision/components/track_component.rb +3 -0
  88. data/app/lib/biovision/components/users/authentication.rb +15 -7
  89. data/app/lib/biovision/components/users/codes.rb +104 -0
  90. data/app/lib/biovision/components/users/flag_helpers.rb +72 -0
  91. data/app/lib/biovision/components/users/profile_handler.rb +111 -1
  92. data/app/lib/biovision/components/users/registration_handler.rb +40 -52
  93. data/app/lib/biovision/components/users/validation.rb +83 -0
  94. data/app/lib/biovision/components/users_component.rb +114 -19
  95. data/app/lib/biovision/helpers/data_helper.rb +70 -0
  96. data/app/lib/biovision/helpers/export_helper.rb +97 -0
  97. data/app/lib/biovision/migrations/component_migration.rb +56 -0
  98. data/app/lib/biovision/notifiers/base_notifier.rb +2 -2
  99. data/app/lib/biovision/notifiers/contact_notifier.rb +15 -0
  100. data/app/lib/biovision/stories/component_story.rb +55 -0
  101. data/app/lib/canonizer.rb +38 -0
  102. data/app/lib/carrier_wave/image_optim.rb +32 -0
  103. data/app/mailers/code_sender.rb +29 -0
  104. data/app/mailers/feedback_mailer.rb +14 -0
  105. data/app/models/agent.rb +4 -0
  106. data/app/models/biovision_component.rb +39 -3
  107. data/app/models/code.rb +31 -8
  108. data/app/models/concerns/checkable.rb +2 -1
  109. data/app/models/concerns/has_simple_image.rb +9 -0
  110. data/app/models/concerns/has_uploaded_file.rb +26 -0
  111. data/app/models/concerns/meta_texts.rb +25 -5
  112. data/app/models/concerns/simple_tag.rb +30 -0
  113. data/app/models/concerns/toggleable.rb +2 -1
  114. data/app/models/concerns/tree_structure.rb +75 -0
  115. data/app/models/contact_method.rb +47 -0
  116. data/app/models/contact_type.rb +27 -0
  117. data/app/models/dynamic_block.rb +43 -0
  118. data/app/models/dynamic_page.rb +73 -0
  119. data/app/models/feedback_message.rb +65 -0
  120. data/app/models/feedback_response.rb +50 -0
  121. data/app/models/group.rb +48 -0
  122. data/app/models/language.rb +4 -0
  123. data/app/models/metric.rb +4 -0
  124. data/app/models/navigation_group.rb +43 -0
  125. data/app/models/navigation_group_page.rb +23 -0
  126. data/app/models/oembed_domain.rb +25 -0
  127. data/app/models/oembed_link.rb +19 -0
  128. data/app/models/oembed_receiver.rb +15 -0
  129. data/app/models/role.rb +86 -0
  130. data/app/models/role_group.rb +13 -0
  131. data/app/models/simple_image.rb +49 -8
  132. data/app/models/simple_image_tag.rb +1 -16
  133. data/app/models/token.rb +6 -2
  134. data/app/models/uploaded_file.rb +62 -0
  135. data/app/models/uploaded_file_tag.rb +15 -0
  136. data/app/models/uploaded_file_tag_file.rb +13 -0
  137. data/app/models/user.rb +122 -29
  138. data/app/models/user_group.rb +20 -0
  139. data/app/models/user_role.rb +18 -0
  140. data/app/uploaders/simple_file_uploader.rb +23 -0
  141. data/app/uploaders/simple_image_uploader.rb +29 -20
  142. data/app/uploaders/uploaders/path_slug.rb +22 -0
  143. data/app/views/admin/agents/index.html.erb +1 -3
  144. data/app/views/admin/biovision_components/_nav_item.html.erb +6 -0
  145. data/app/views/admin/biovision_components/entity/_in_list.html.erb +12 -0
  146. data/app/views/admin/biovision_components/index.html.erb +11 -0
  147. data/app/views/admin/components/_image.jbuilder +18 -0
  148. data/app/views/admin/components/_list.html.erb +1 -1
  149. data/app/views/admin/components/entity/_links.html.erb +31 -21
  150. data/app/views/admin/components/image.jbuilder +1 -0
  151. data/app/views/admin/components/images.jbuilder +4 -0
  152. data/app/views/admin/components/links/_base.html.erb +1 -0
  153. data/app/views/admin/components/settings/_new_parameter.html.erb +4 -2
  154. data/app/views/admin/components/settings/_parameters.html.erb +8 -2
  155. data/app/views/admin/components/settings/_settings.html.erb +4 -4
  156. data/app/views/admin/components/settings.html.erb +2 -1
  157. data/app/views/admin/components/update_privileges.jbuilder +21 -0
  158. data/app/views/admin/dynamic_blocks/_form.html.erb +16 -0
  159. data/app/views/admin/dynamic_blocks/_nav_item.html.erb +6 -0
  160. data/app/views/admin/dynamic_blocks/entity/_in_list.html.erb +12 -0
  161. data/app/views/admin/dynamic_blocks/index.html.erb +17 -0
  162. data/app/views/admin/dynamic_blocks/show.html.erb +25 -0
  163. data/app/views/admin/dynamic_pages/_dynamic_page.jbuilder +18 -0
  164. data/app/views/admin/dynamic_pages/_form.html.erb +21 -0
  165. data/app/views/admin/dynamic_pages/_nav_item.html.erb +6 -0
  166. data/app/views/admin/dynamic_pages/entity/_in_list.html.erb +17 -0
  167. data/app/views/admin/dynamic_pages/entity/_in_search.html.erb +7 -0
  168. data/app/views/admin/dynamic_pages/index.html.erb +17 -0
  169. data/app/views/admin/dynamic_pages/search.jbuilder +4 -0
  170. data/app/views/admin/dynamic_pages/show.html.erb +28 -0
  171. data/app/views/admin/index/index.html.erb +7 -5
  172. data/app/views/admin/ip_addresses/index.html.erb +2 -4
  173. data/app/views/admin/navigation_group_pages/entity/_in_list.html.erb +26 -0
  174. data/app/views/admin/navigation_groups/_form.html.erb +15 -0
  175. data/app/views/admin/navigation_groups/_nav_item.html.erb +6 -0
  176. data/app/views/admin/navigation_groups/entity/_dynamic_pages.html.erb +38 -0
  177. data/app/views/admin/navigation_groups/entity/_in_list.html.erb +14 -0
  178. data/app/views/admin/navigation_groups/index.html.erb +17 -0
  179. data/app/views/admin/navigation_groups/show.html.erb +33 -0
  180. data/app/views/admin/tokens/_form.html.erb +31 -0
  181. data/app/views/admin/tokens/_nav_item.html.erb +6 -0
  182. data/app/views/admin/tokens/entity/_in_list.html.erb +27 -0
  183. data/app/views/admin/tokens/index.html.erb +11 -0
  184. data/app/views/admin/tokens/show.html.erb +26 -0
  185. data/app/views/admin/unauthorized.html.erb +2 -5
  186. data/app/views/admin/users/_form.html.erb +81 -0
  187. data/app/views/admin/users/_nav_item.html.erb +6 -0
  188. data/app/views/admin/users/_user.jbuilder +18 -0
  189. data/app/views/admin/users/entity/_fields.html.erb +53 -0
  190. data/app/views/admin/users/entity/_in_list.html.erb +38 -0
  191. data/app/views/admin/users/entity/_in_search.html.erb +18 -0
  192. data/app/views/admin/users/entity/_profile.html.erb +26 -0
  193. data/app/views/admin/users/entity/in_list/_additional_data.html.erb +0 -0
  194. data/app/views/admin/users/index.html.erb +24 -0
  195. data/app/views/admin/users/roles/_component.html.erb +22 -0
  196. data/app/views/admin/users/roles.html.erb +23 -0
  197. data/app/views/admin/users/search.jbuilder +4 -0
  198. data/app/views/admin/users/show.html.erb +62 -0
  199. data/app/views/admin/widgets/_filters.html.erb +20 -0
  200. data/app/views/admin/widgets/_quick_search.html.erb +13 -0
  201. data/app/views/admin/widgets/filters/_flag.html.erb +15 -0
  202. data/app/views/admin/widgets/filters/_text.html.erb +7 -0
  203. data/app/views/application/forbidden.html.erb +9 -0
  204. data/app/views/application/forbidden.jbuilder +4 -0
  205. data/app/views/application/not_found.html.erb +9 -0
  206. data/app/views/application/not_found.jbuilder +4 -0
  207. data/app/views/application/unauthorized.html.erb +19 -0
  208. data/app/views/application/unauthorized.jbuilder +4 -0
  209. data/app/views/authentication/new.html.erb +2 -8
  210. data/app/views/components/content/_dynamic_page.html.erb +17 -0
  211. data/app/views/components/content/_dynamic_page_content.html.erb +14 -0
  212. data/app/views/components/users/_form_tabs.html.erb +31 -0
  213. data/app/views/components/users/_join_form.html.erb +192 -0
  214. data/app/views/components/users/_login_form.html.erb +46 -0
  215. data/app/views/components/users/form/_image.html.erb +17 -0
  216. data/app/views/components/users/form/_profile_data.html.erb +54 -0
  217. data/app/views/contact/_form.html.erb +108 -0
  218. data/app/views/contact/create_feedback_message.js.erb +1 -0
  219. data/app/views/contact/feedback.html.erb +13 -0
  220. data/app/views/contact/index.html.erb +16 -0
  221. data/app/views/errors/error.html.erb +1 -0
  222. data/app/views/fallback/show.html.erb +6 -0
  223. data/app/views/feedback_mailer/new_feedback_request.html.erb +11 -0
  224. data/app/views/feedback_mailer/new_feedback_request.text.erb +6 -0
  225. data/app/views/index/index.html.erb +14 -0
  226. data/app/views/layouts/admin/_footer.html.erb +1 -1
  227. data/app/views/layouts/admin/_header.html.erb +7 -2
  228. data/app/views/layouts/admin.html.erb +0 -1
  229. data/app/views/layouts/application/_footer.html.erb +1 -1
  230. data/app/views/layouts/application/header/_authentication.html.erb +4 -1
  231. data/app/views/legal/privacy.html.erb +5 -0
  232. data/app/views/legal/tos.html.erb +5 -0
  233. data/app/views/my/components/index.html.erb +25 -0
  234. data/app/views/my/components/show.html.erb +21 -0
  235. data/app/views/my/confirmations/show.html.erb +62 -0
  236. data/app/views/my/index/_cards.html.erb +15 -0
  237. data/app/views/my/index/_email.html.erb +14 -0
  238. data/app/views/my/index/_navigation.html.erb +33 -0
  239. data/app/views/my/index/index.html.erb +12 -0
  240. data/app/views/my/profiles/_form.html.erb +10 -0
  241. data/app/views/my/profiles/check.jbuilder +4 -0
  242. data/app/views/my/profiles/edit.html.erb +14 -0
  243. data/app/views/my/profiles/form/_basic_parameters.html.erb +9 -0
  244. data/app/views/my/profiles/form/_sensitive_parameters.html.erb +68 -0
  245. data/app/views/my/profiles/new.html.erb +6 -8
  246. data/app/views/my/profiles/show.html.erb +36 -0
  247. data/app/views/my/recoveries/show.html.erb +0 -0
  248. data/app/views/shared/_flash_messages.html.erb +1 -1
  249. data/app/views/shared/_list_of_errors.html.erb +7 -0
  250. data/app/views/shared/admin/_breadcrumbs.html.erb +8 -0
  251. data/app/views/shared/admin/_list.html.erb +10 -19
  252. data/app/views/shared/admin/_list_with_priority.html.erb +10 -19
  253. data/app/views/shared/admin/_priority.html.erb +6 -0
  254. data/app/views/shared/admin/_toggle.html.erb +6 -0
  255. data/app/views/shared/entity/_date_field.html.erb +6 -0
  256. data/app/views/shared/entity/_formatted_text_field.html.erb +10 -0
  257. data/app/views/shared/entity/_image.html.erb +31 -0
  258. data/app/views/shared/entity/_language.html.erb +6 -0
  259. data/app/views/shared/entity/_linked_entity.html.erb +6 -0
  260. data/app/views/shared/entity/_list.html.erb +22 -0
  261. data/app/views/shared/entity/_list_with_priority.html.erb +22 -0
  262. data/app/views/shared/entity/_meta_texts.html.erb +16 -0
  263. data/app/views/shared/entity/_metadata.html.erb +18 -0
  264. data/app/views/shared/entity/_parent.html.erb +6 -0
  265. data/app/views/shared/entity/_priority.html.erb +4 -0
  266. data/app/views/shared/entity/_priority_icons.html.erb +8 -0
  267. data/app/views/shared/entity/_raw_text_field.html.erb +10 -0
  268. data/app/views/shared/entity/_simple_image.html.erb +10 -0
  269. data/app/views/shared/entity/_slug.html.erb +6 -0
  270. data/app/views/shared/entity/_text_field.html.erb +6 -0
  271. data/app/views/shared/entity/_text_fields.html.erb +9 -0
  272. data/app/views/shared/entity/_time_field.html.erb +6 -0
  273. data/app/views/shared/entity/_timestamps.html.erb +13 -0
  274. data/app/views/shared/entity/_toggle.html.erb +12 -0
  275. data/app/views/shared/entity/_track.html.erb +12 -0
  276. data/app/views/shared/entity/_tree_caches.html.erb +19 -0
  277. data/app/views/shared/entity/_uuid.html.erb +4 -0
  278. data/app/views/shared/entity/edit.html.erb +23 -0
  279. data/app/views/shared/entity/new.html.erb +16 -0
  280. data/app/views/shared/forms/_entity_flags.html.erb +15 -0
  281. data/app/views/shared/forms/_field.html.erb +50 -0
  282. data/app/views/shared/forms/_field_with_search.html.erb +17 -0
  283. data/app/views/shared/forms/_fields.html.erb +3 -0
  284. data/app/views/shared/forms/_language.html.erb +40 -0
  285. data/app/views/shared/forms/_meta_texts.html.erb +27 -0
  286. data/app/views/shared/forms/_priority.html.erb +13 -0
  287. data/app/views/shared/forms/_simple_entity_link.html.erb +14 -0
  288. data/app/views/shared/forms/_simple_image.html.erb +47 -0
  289. data/app/views/shared/forms/_state_container.html.erb +7 -0
  290. data/app/views/shared/forms/_text_area.html.erb +25 -0
  291. data/app/views/shared/forms/_text_field.html.erb +24 -0
  292. data/app/views/shared/forms/_text_fields.html.erb +3 -0
  293. data/app/views/shared/forms/check.jbuilder +4 -0
  294. data/app/views/shared/forms/errors.jbuilder +3 -0
  295. data/app/views/shared/forms/simple_image/_browse.html.erb +14 -0
  296. data/app/views/shared/forms/simple_image/_load_image.html.erb +38 -0
  297. data/app/views/shared/my/_list.html.erb +10 -0
  298. data/app/views/shared/my/_list_with_priority.html.erb +10 -0
  299. data/app/views/shared/my/entity/edit.html.erb +25 -0
  300. data/app/views/shared/my/entity/new.html.erb +18 -0
  301. data/app/views/simple_images/_simple_image.jbuilder +13 -0
  302. data/app/views/users/_profile.html.erb +30 -0
  303. data/app/views/users/profile/_data.html.erb +20 -0
  304. data/app/views/users/show.html.erb +21 -0
  305. data/config/locales/biovision-ru.yml +76 -1
  306. data/config/locales/components-ru.yml +55 -4
  307. data/config/locales/contact-ru.yml +110 -0
  308. data/config/locales/content-ru.yml +115 -0
  309. data/config/locales/users-ru.yml +142 -3
  310. data/config/routes.rb +99 -48
  311. data/db/migrate/20191228000000_create_biovision_components.rb +6 -5
  312. data/db/migrate/20200224000000_create_track_component.rb +9 -14
  313. data/db/migrate/20200224000010_create_users_component.rb +14 -83
  314. data/db/migrate/20200404000000_create_simple_images.rb +4 -3
  315. data/db/migrate/20210405000000_create_acl.rb +88 -0
  316. data/db/migrate/20210421000000_create_content_component.rb +80 -0
  317. data/db/migrate/20210421000010_create_contact_component.rb +74 -0
  318. data/db/migrate/20210616000000_create_uploaded_files.rb +52 -0
  319. data/db/migrate/amends/20210816060606_create_oembed_receivers.rb +21 -0
  320. data/db/migrate/amends/20210907070707_add_checksum_to_simple_images.rb +13 -0
  321. data/lib/biovision/base_methods.rb +17 -29
  322. data/lib/biovision/engine.rb +8 -13
  323. data/lib/biovision/version.rb +1 -1
  324. data/lib/tasks/components.rake +51 -0
  325. metadata +266 -27
  326. data/app/assets/images/biovision/placeholders/user.svg +0 -15
  327. data/app/helpers/users_helper.rb +0 -11
  328. data/app/lib/biovision/components/component_settings.rb +0 -30
  329. data/app/lib/biovision/components/privilege_handler.rb +0 -77
  330. data/app/lib/biovision/components/users/code_handler.rb +0 -23
  331. data/app/models/biovision_component_user.rb +0 -21
  332. data/app/models/foreign_site.rb +0 -34
  333. data/app/models/foreign_user.rb +0 -21
  334. data/app/uploaders/user_image_uploader.rb +0 -58
  335. data/app/views/admin/components/links/_track.html.erb +0 -2
  336. data/app/views/admin/components/links/_users.html.erb +0 -11
  337. data/app/views/admin/components/privileges/_component_user.html.erb +0 -17
  338. data/app/views/admin/components/privileges/_links.html.erb +0 -35
  339. data/app/views/admin/components/privileges/_privilege_flag.html.erb +0 -28
  340. data/app/views/admin/components/privileges/_users.html.erb +0 -23
  341. data/app/views/admin/components/privileges.html.erb +0 -20
  342. data/app/views/authentication/_form.html.erb +0 -40
  343. data/app/views/authentication/failed.js.erb +0 -3
  344. data/app/views/my/profiles/new/_form.html.erb +0 -147
  345. data/app/views/shared/admin/_toggleable.html.erb +0 -8
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Biovision
4
+ module Migrations
5
+ # Mix-ins for repeated component migration parts
6
+ module ComponentMigration
7
+ # Component class
8
+ def component
9
+ @component ||= find_component
10
+ end
11
+
12
+ # Create component tables and roles
13
+ #
14
+ # Creates new BiovisionComponent
15
+ # For each dependent model, calls "create_<table_name>" method
16
+ # Creates roles for new component
17
+ def up
18
+ component.create
19
+ component.dependent_models.each do |model|
20
+ next if model.table_exists?
21
+
22
+ message = "create_#{model.table_name}".to_sym
23
+ send(message) if respond_to?(message, true)
24
+ end
25
+ handler = component[nil]
26
+ handler.create_roles
27
+ handler.seed if handler.respond_to?(:seed)
28
+ end
29
+
30
+ # Drops tables for each dependent model
31
+ # Removes BiovisionComponent
32
+ def down
33
+ component.dependent_models.reverse.each do |model|
34
+ drop_table model.table_name if model.table_exists?
35
+ end
36
+ BiovisionComponent[component]&.destroy
37
+ end
38
+
39
+ private
40
+
41
+ # Find component class by migration name
42
+ #
43
+ # Method relies on naming like Create<:CamelCaseSlug>Component
44
+ #
45
+ # Example:
46
+ # - Migration class is named CreateFooBarComponent
47
+ # - Component slug is "foo_bar"
48
+ # - Use base component handler to get "FooBarComponent" class
49
+ def find_component
50
+ migration = name.to_s.demodulize.to_s.underscore
51
+ slug = migration.gsub(/\Acreate_/, '').gsub(/_component\z/, '')
52
+ Biovision::Components::BaseComponent.handler_class(slug)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -20,7 +20,7 @@ module Biovision
20
20
  end
21
21
 
22
22
  def self.slug
23
- to_s.demodulize.underscore.gsub('_notifier', '')
23
+ to_s.demodulize.to_s.underscore.gsub('_notifier', '')
24
24
  end
25
25
 
26
26
  # @param [String] slug
@@ -56,7 +56,7 @@ module Biovision
56
56
  def check_and_notify(id, type)
57
57
  return if check_chain(id, type).exists?
58
58
 
59
- notify({id: id, type: type})
59
+ notify({ id: id, type: type })
60
60
  end
61
61
 
62
62
  # @param [Integer] id
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Biovision
4
+ module Notifiers
5
+ # Notification mapper for contact component
6
+ class ContactNotifier < BaseNotifier
7
+ TYPE_FEEDBACK_MESSAGE = 'feedback_message'
8
+
9
+ # @param [Integer] message_id
10
+ def new_feedback_message(message_id)
11
+ check_and_notify(message_id, TYPE_FEEDBACK_MESSAGE)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Biovision
4
+ module Stories
5
+ # Base component story
6
+ class ComponentStory
7
+ attr_accessor :component_handler, :entity
8
+
9
+ # @param [Biovision::Components::BaseComponent] handler
10
+ # @param [ApplicationRecord|String|nil] entity
11
+ def initialize(handler, entity = nil)
12
+ self.component_handler = handler
13
+ return if entity.blank?
14
+
15
+ if entity.is_a?(ApplicationRecord)
16
+ self.entity = entity
17
+ else
18
+ self.entity_id = entity.to_s
19
+ end
20
+ end
21
+
22
+ # Get associated model class
23
+ #
24
+ # This method should be implemented in children if story name
25
+ # does not match model name.
26
+ # The result is used in #entity_id=
27
+ def model_class
28
+ model_name = to_s.demodulize.to_s.underscore.gsub('_story', '')
29
+ model_name.classify.safe_constantize
30
+ end
31
+
32
+ # @param [Hash] parameters
33
+ def perform(parameters)
34
+ @parameters = parameters
35
+ # implement in children and return hash
36
+ { result: 'Nothing was processed.' }
37
+ end
38
+
39
+ # Set entity identified by value
40
+ #
41
+ # This method can be implemented in child classes
42
+ #
43
+ # @param [String] value
44
+ def entity_id=(value)
45
+ return if model_class.nil?
46
+
47
+ if model_class.respond_to?(:[])
48
+ self.entity = model_class[value]
49
+ elsif model_class.respond_to?(:find_by)
50
+ self.entity = model_class.find_by(id: value)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Helper for canonizing and transliterating strings
4
+ class Canonizer
5
+ # Keys are not latin letters
6
+ TRANSLITERATION_MAP = {
7
+ 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e',
8
+ 'ё' => 'yo', 'ж' => 'zh', 'з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k',
9
+ 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r',
10
+ 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'kh', 'ц' => 'c',
11
+ 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'shh', 'ъ' => '', 'ы' => 'y', 'ь' => '',
12
+ 'э' => 'e', 'ю' => 'yu', 'я' => 'ya',
13
+ 'å' => 'ao', 'ä' => 'ae', 'ö' => 'oe', 'é' => 'e'
14
+ }.freeze
15
+
16
+ # @param [String] text
17
+ def self.transliterate(text)
18
+ pattern = Regexp.new "[#{TRANSLITERATION_MAP.keys.join}]"
19
+ result = text.to_s.downcase.gsub(pattern, TRANSLITERATION_MAP)
20
+
21
+ a = /[^-a-z0-9_]/ # non-allowed characters will be replaced with dash
22
+ b = /\A[-_]*([-a-z0-9_]*[a-z0-9]+)[-_]*\z/ # chop leading and trailing dash
23
+ result.gsub(a, '-').gsub(b, '\1').gsub(/--+/, '-').gsub(/-+\z/, '')
24
+ end
25
+
26
+ # @param [String] input
27
+ def self.canonize(input)
28
+ lowered = input.to_s.downcase.strip
29
+ canonized = lowered.gsub(/[^a-zа-я0-9ё]/, '')
30
+ canonized.empty? ? lowered : canonized
31
+ end
32
+
33
+ # @param [String] input
34
+ def self.urlize(input)
35
+ lowered = input.to_s.downcase.squish
36
+ lowered.gsub(/[^a-zа-я0-9ё]/, '-').gsub(/-+\z/, '')
37
+ end
38
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CarrierWave
4
+ # Optimizing uploaded images
5
+ module ImageOptim
6
+ DEFAULT_OPTIONS = {
7
+ skip_missing_workers: true,
8
+ advpng: false,
9
+ gifsicle: false,
10
+ jhead: false,
11
+ jpegrecompress: false,
12
+ jpegtran: false,
13
+ pngcrush: false,
14
+ pngout: false,
15
+ pngquant: false,
16
+ svgo: false,
17
+ jpegoptim: { max_quality: 75 },
18
+ optipng: { level: 4 }
19
+ }.freeze
20
+
21
+ def optimize(options = {})
22
+ image_optim = ::ImageOptim.new(optimizer_options(options))
23
+ image_optim.optimize_image!(current_path)
24
+ end
25
+
26
+ private
27
+
28
+ def optimizer_options(options)
29
+ DEFAULT_OPTIONS.deep_merge(options)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Mailer for sending codes to users
4
+ class CodeSender < ApplicationMailer
5
+ # Email confirmation code
6
+ #
7
+ # @param [Integer] code_id
8
+ def email(code_id)
9
+ @code = Code.find_by(id: code_id)
10
+ return if @code.nil?
11
+
12
+ user = @code.user
13
+
14
+ return if user.email.blank? || user.email_confirmed?
15
+
16
+ mail to: user.email
17
+ end
18
+
19
+ # Password reset code
20
+ #
21
+ # @param [Integer] code_id
22
+ def password(code_id)
23
+ @code = Code.find_by(id: code_id)
24
+
25
+ return if @code.nil? || @code.user.email.blank?
26
+
27
+ mail to: @code.user.email
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Mailer for sending feedback requests
4
+ class FeedbackMailer < ApplicationMailer
5
+ # @param [Integer] id
6
+ def new_feedback_request(id)
7
+ @entity = FeedbackMessage.find_by(id: id)
8
+
9
+ key = Biovision::Components::ContactComponent::SETTING_FEEDBACK_MAIL
10
+ receiver = Biovision::Components::ContactComponent[nil].settings[key]
11
+
12
+ mail to: receiver unless @entity.nil? || receiver.blank?
13
+ end
14
+ end
data/app/models/agent.rb CHANGED
@@ -32,4 +32,8 @@ class Agent < ApplicationRecord
32
32
 
33
33
  find_or_create_by(name: name[0..254])
34
34
  end
35
+
36
+ def bot?
37
+ name.downcase.include?('bot')
38
+ end
35
39
  end
@@ -13,17 +13,28 @@
13
13
  class BiovisionComponent < ApplicationRecord
14
14
  include FlatPriority
15
15
  include RequiredUniqueSlug
16
+ include Toggleable
17
+
18
+ SLUG_LIMIT = 250
19
+ SLUG_PATTERN_HTML = '^[a-zA-Z][-a-zA-Z0-9_]+[a-zA-Z0-9]$'
20
+
21
+ toggleable :active
16
22
 
17
- has_many :biovision_component_users, dependent: :delete_all
18
23
  has_many :simple_images, dependent: :destroy
24
+ has_many :uploaded_files, dependent: :destroy
25
+ has_many :codes, dependent: :delete_all
26
+ has_many :roles, dependent: :destroy
27
+ has_many :groups, dependent: :destroy
19
28
 
29
+ scope :active, -> { where(active: true) }
20
30
  scope :list_for_administration, -> { ordered_by_priority }
31
+ scope :list_for_user, -> { active.ordered_by_priority }
21
32
 
22
33
  # Find component by slug
23
34
  #
24
- # @param [String] slug
35
+ # @param [String|Class] slug
25
36
  def self.[](slug)
26
- find_by(slug: slug)
37
+ find_by(slug: slug.respond_to?(:slug) ? slug.slug : slug)
27
38
  end
28
39
 
29
40
  # @param [String] slug
@@ -34,6 +45,8 @@ class BiovisionComponent < ApplicationRecord
34
45
 
35
46
  # @param [String] slug
36
47
  # @param value
48
+ #
49
+ # @deprecated use parameters[slug.to_s] = value
37
50
  def []=(slug, value)
38
51
  parameters[slug.to_s] = value
39
52
  save!
@@ -42,4 +55,27 @@ class BiovisionComponent < ApplicationRecord
42
55
  def privileges
43
56
  biovision_component_users.recent
44
57
  end
58
+
59
+ # @param [User] user
60
+ # @param [String] type
61
+ # @param [Integer] quantity
62
+ def find_or_create_code(user, type, quantity = 1)
63
+ code = codes.owned_by(user).with_type(type).active.first
64
+
65
+ if code.nil?
66
+ code = codes.new(user: user, quantity: quantity)
67
+ code.code_type = type
68
+ code.save
69
+ end
70
+
71
+ code
72
+ end
73
+
74
+ def text_for_link
75
+ I18n.t("biovision.components.#{slug}.name", default: slug)
76
+ end
77
+
78
+ def admin_url
79
+ "/admin/components/#{slug}"
80
+ end
45
81
  end
data/app/models/code.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Code for users
4
- #
4
+ #
5
5
  # Attributes:
6
6
  # agent_id [Agent], optional
7
7
  # biovision_component_id [BiovisionComponent]
@@ -17,21 +17,22 @@ class Code < ApplicationRecord
17
17
  include HasTrack
18
18
 
19
19
  BODY_LIMIT = 50
20
- QUANTITY_RANGE = (0..32_767).freeze
20
+ QUANTITY_RANGE = (0..32_767)
21
21
 
22
22
  belongs_to :biovision_component
23
- belongs_to :user
23
+ belongs_to :user, optional: true
24
24
 
25
25
  after_initialize :generate_body
26
26
 
27
27
  before_validation :sanitize_quantity
28
28
 
29
29
  validates_presence_of :body
30
- validates_uniqueness_of :body
30
+ validates_uniqueness_of :body, unless: :phone?
31
31
  validates_length_of :body, maximum: BODY_LIMIT
32
32
 
33
33
  scope :recent, -> { order('id desc') }
34
34
  scope :active, -> { where('quantity > 0') }
35
+ scope :with_type, ->(v) { where("data->>'type' = ?", v) unless v.blank? }
35
36
  scope :list_for_administration, -> { recent }
36
37
 
37
38
  # @param [Integer] page
@@ -40,11 +41,11 @@ class Code < ApplicationRecord
40
41
  end
41
42
 
42
43
  def self.entity_parameters
43
- %i[body payload quantity]
44
+ %i[body quantity]
44
45
  end
45
46
 
46
47
  def self.creation_parameters
47
- entity_parameters + %i[user_id code_type_id]
48
+ entity_parameters + %i[user_id biovision_component_id]
48
49
  end
49
50
 
50
51
  def activated?
@@ -55,13 +56,35 @@ class Code < ApplicationRecord
55
56
  quantity.positive?
56
57
  end
57
58
 
59
+ # @param [String] type_name
60
+ def type?(type_name)
61
+ code_type == type_name.to_s
62
+ end
63
+
64
+ def code_type
65
+ data['type'].to_s
66
+ end
67
+
68
+ # @param [String] new_type
69
+ def code_type=(new_type)
70
+ data['type'] = new_type.to_s
71
+ end
72
+
73
+ def phone?
74
+ type?(Biovision::Components::UsersComponent::CODE_PHONE_CONFIRMATION)
75
+ end
76
+
58
77
  private
59
78
 
60
79
  def generate_body
61
80
  return unless body.nil?
62
81
 
63
- number = SecureRandom.random_number(0xffff_ffff_ffff_ffff)
64
- self.body = number.to_s(36).scan(/.{4}/).join('-').upcase
82
+ if phone?
83
+ self.body = SecureRandom.random_number(1_000_000).to_s.rjust(6, '0')
84
+ else
85
+ number = SecureRandom.random_number(0xffff_ffff_ffff_ffff)
86
+ self.body = number.to_s(36).scan(/.{4}/).join('-').upcase
87
+ end
65
88
  end
66
89
 
67
90
  def sanitize_quantity
@@ -13,7 +13,8 @@ module Checkable
13
13
  if id.blank?
14
14
  entity = new(parameters)
15
15
  else
16
- entity = find_by(id: id)
16
+ key = column_names.include?('uuid') && id.include?('-') ? :uuid : :id
17
+ entity = find_by(key => id)
17
18
  entity.assign_attributes(parameters)
18
19
  end
19
20
  entity
@@ -6,6 +6,15 @@ module HasSimpleImage
6
6
 
7
7
  included do
8
8
  belongs_to :simple_image, optional: true, counter_cache: :object_count
9
+
10
+ scope :included_image, -> { includes(:simple_image) }
11
+
12
+ def image_metadata
13
+ {
14
+ url: simple_image&.image&.url,
15
+ alt: simple_image&.image_alt_text
16
+ }
17
+ end
9
18
  end
10
19
 
11
20
  def image
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Model references to uploaded file
4
+ module HasUploadedFile
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ belongs_to :uploaded_file, optional: true, counter_cache: :object_count
9
+
10
+ scope :included_file, -> { includes(:uploaded_file) }
11
+ end
12
+
13
+ def attachment_name
14
+ uploaded_file&.name
15
+ end
16
+
17
+ def attachment_size
18
+ uploaded_file&.file_size
19
+ end
20
+
21
+ def attachment_url
22
+ return if uploaded_file&.attachment.blank?
23
+
24
+ uploaded_file.attachment.url
25
+ end
26
+ end
@@ -5,12 +5,32 @@ module MetaTexts
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
- validates_length_of :meta_description, maximum: 500
9
- validates_length_of :meta_keywords, maximum: 250
10
- validates_length_of :meta_title, maximum: 250
8
+ def self.meta_keys
9
+ %w[title keywords description heading]
10
+ end
11
+
12
+ # @param [String] key
13
+ # @param [String] default
14
+ def meta(key, default = '')
15
+ message = "meta_#{key}".to_sym
16
+ if respond_to?(message)
17
+ send(message)
18
+ else
19
+ data.dig('meta', key.to_s) || default
20
+ end
21
+ end
22
+
23
+ def meta!
24
+ data['meta'].to_h
25
+ end
26
+
27
+ # @param [Hash] new_data
28
+ def meta=(new_data)
29
+ data['meta'] = {}
11
30
 
12
- def self.meta_text_fields
13
- %i[meta_description meta_keywords meta_title]
31
+ self.class.meta_keys.each do |key|
32
+ data['meta'][key] = new_data[key]
33
+ end
14
34
  end
15
35
  end
16
36
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Adds list of toggleable attributes to model
4
+ #
5
+ # @author Maxim Khan-Magomedov <maxim.km@gmail.com>
6
+ module SimpleTag
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+
11
+ before_validation :normalize_name
12
+ validates_uniqueness_of :name, case_sensitive: false
13
+
14
+ scope :list_for_administration, -> { order(:name) }
15
+
16
+ def self.entity_parameters
17
+ %i[name]
18
+ end
19
+
20
+ def self.name_limit
21
+ 100
22
+ end
23
+
24
+ private
25
+
26
+ def normalize_name
27
+ self.name = name.to_s[0..name_limit]
28
+ end
29
+ end
30
+ end
@@ -14,7 +14,8 @@ module Toggleable
14
14
  def toggle_parameter(attribute)
15
15
  return unless toggleable_attributes.include? attribute.to_sym
16
16
 
17
- toggle! attribute
17
+ assign_attributes(attribute => !attributes[attribute.to_s])
18
+ save!
18
19
  { attribute => self[attribute] }
19
20
  end
20
21
  end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Model has parent and children
4
+ module TreeStructure
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ belongs_to :parent, class_name: name, optional: true
9
+ has_many :child_items, class_name: name, foreign_key: :parent_id, dependent: :destroy
10
+
11
+ before_save { children_cache.uniq! }
12
+ after_create :cache_parents!
13
+ after_destroy { parent&.cache_children! unless ENV['SKIP_CHILDREN_CACHE'] }
14
+ after_save { parent&.cache_children! unless ENV['SKIP_CHILDREN_CACHE'] }
15
+
16
+ scope :with_parent_id, ->(v) { where(parent_id: v) }
17
+
18
+ def self.tree(collection)
19
+ result = {}
20
+
21
+ collection.each do |entity|
22
+ result[entity.id] = {
23
+ parent_id: entity.parent_id,
24
+ entity: entity,
25
+ }
26
+ end
27
+
28
+ result
29
+ end
30
+
31
+ def depth
32
+ parent_ids.count
33
+ end
34
+
35
+ def parent_ids
36
+ parents_cache.split(',').compact
37
+ end
38
+
39
+ # @return [Array<Integer>]
40
+ def branch_ids
41
+ parents_cache.split(',').map(&:to_i).reject { |i| i < 1 }.uniq + [id]
42
+ end
43
+
44
+ # @return [Array<Integer>]
45
+ def subbranch_ids
46
+ [id] + children_cache
47
+ end
48
+
49
+ def parents
50
+ return [] if parents_cache.blank?
51
+
52
+ self.class.where(id: parent_ids).order('id asc')
53
+ end
54
+
55
+ def cache_parents!
56
+ return if parent.nil?
57
+
58
+ self.parents_cache = "#{parent.parents_cache},#{parent_id}".gsub(/\A,/, '')
59
+ save!
60
+ end
61
+
62
+ # @param [Array] new_cache
63
+ def cache_children!(new_cache = [])
64
+ if new_cache.blank?
65
+ new_cache = child_items.order('id asc').pluck(:id, :children_cache)
66
+ end
67
+
68
+ self.children_cache += new_cache.flatten
69
+ self.children_cache.uniq!
70
+
71
+ save!
72
+ parent&.cache_children!([id] + children_cache)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Contact method
4
+ #
5
+ # Attributes:
6
+ # contact_type_id [ContactType]
7
+ # created_at [DateTime]
8
+ # data [jsonb]
9
+ # language_id [Language], optional
10
+ # name [string], optional
11
+ # priority [integer]
12
+ # updated_at [DateTime]
13
+ # uuid [uuid]
14
+ # value [string]
15
+ # visible [boolean]
16
+ class ContactMethod < ApplicationRecord
17
+ include Checkable
18
+ include FlatPriority
19
+ include HasLanguage
20
+ include HasUuid
21
+ include Toggleable
22
+
23
+ NAME_LIMIT = 50
24
+ VALUE_LIMIT = 255
25
+
26
+ toggleable :visible
27
+
28
+ belongs_to :language, optional: true
29
+ belongs_to :contact_type
30
+
31
+ validates_presence_of :value
32
+ validates_length_of :name, maximum: NAME_LIMIT
33
+ validates_length_of :value, maximum: VALUE_LIMIT
34
+
35
+ scope :visible, -> { where(visible: true) }
36
+ scope :list_for_administration, -> { ordered_by_priority }
37
+ scope :list_for_visitors, -> { visible.ordered_by_priority }
38
+
39
+ # @param [String] slug
40
+ def self.[](slug)
41
+ ContactType[slug]&.contact_methods&.list_for_visitors
42
+ end
43
+
44
+ def self.entity_parameters
45
+ %i[contact_type_id language_id name priority value visible]
46
+ end
47
+ end