biovision 0.0.200518.1 → 0.1.210414.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +60 -18
  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.scss +3 -1
  12. data/app/assets/stylesheets/biovision/admin/components/users.scss +16 -0
  13. data/app/assets/stylesheets/biovision/admin/layout.scss +6 -17
  14. data/app/assets/stylesheets/biovision/biovision.scss +42 -1
  15. data/app/assets/stylesheets/biovision/components.scss +6 -0
  16. data/app/assets/stylesheets/biovision/components/breadcrumbs.scss +13 -0
  17. data/app/assets/stylesheets/biovision/components/buttons.scss +130 -0
  18. data/app/assets/stylesheets/biovision/components/forms.scss +162 -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/simple_image.scss +112 -0
  23. data/app/assets/stylesheets/biovision/components/toggleable.scss +71 -0
  24. data/app/assets/stylesheets/biovision/themes/default_theme/components.scss +2 -3
  25. data/app/assets/stylesheets/biovision/themes/default_theme/components/users.scss +2 -0
  26. data/app/assets/stylesheets/biovision/themes/default_theme/components/users/form_tabs.scss +101 -0
  27. data/app/assets/stylesheets/biovision/themes/default_theme/components/users/profile.scss +77 -0
  28. data/app/assets/stylesheets/biovision/themes/default_theme/layout.scss +2 -16
  29. data/app/controllers/admin/components_controller.rb +9 -19
  30. data/app/controllers/admin/dynamic_blocks_controller.rb +15 -0
  31. data/app/controllers/admin/dynamic_pages_controller.rb +15 -0
  32. data/app/controllers/admin/navigation_groups_controller.rb +14 -0
  33. data/app/controllers/admin/users_controller.rb +70 -0
  34. data/app/controllers/admin_controller.rb +3 -2
  35. data/app/controllers/authentication_controller.rb +6 -34
  36. data/app/controllers/concerns/authentication.rb +12 -12
  37. data/app/controllers/concerns/crud_entities.rb +132 -0
  38. data/app/controllers/concerns/entity_priority.rb +10 -0
  39. data/app/controllers/concerns/toggleable_entity.rb +31 -0
  40. data/app/controllers/contact_controller.rb +49 -0
  41. data/app/controllers/fallback_controller.rb +12 -0
  42. data/app/controllers/index_controller.rb +1 -0
  43. data/app/controllers/legal_controller.rb +14 -0
  44. data/app/controllers/my/components_controller.rb +5 -0
  45. data/app/controllers/my/confirmations_controller.rb +44 -0
  46. data/app/controllers/my/index_controller.rb +8 -0
  47. data/app/controllers/my/profiles_controller.rb +31 -16
  48. data/app/controllers/profile_controller.rb +12 -0
  49. data/app/controllers/users_controller.rb +61 -0
  50. data/app/helpers/biovision_helper.rb +171 -0
  51. data/app/helpers/simple_image_helper.rb +125 -0
  52. data/app/jobs/application_job.rb +7 -0
  53. data/app/jobs/send_phone_confirmation_job.rb +16 -0
  54. data/app/lib/biovision/components/base/component_parameters.rb +44 -0
  55. data/app/lib/biovision/components/base/component_privileges.rb +65 -0
  56. data/app/lib/biovision/components/base/component_settings.rb +32 -0
  57. data/app/lib/biovision/components/base/privilege_handler.rb +79 -0
  58. data/app/lib/biovision/components/base_component.rb +51 -54
  59. data/app/lib/biovision/components/contact_component.rb +22 -0
  60. data/app/lib/biovision/components/content_component.rb +28 -0
  61. data/app/lib/biovision/components/track_component.rb +3 -0
  62. data/app/lib/biovision/components/users/authentication.rb +15 -7
  63. data/app/lib/biovision/components/users/codes.rb +104 -0
  64. data/app/lib/biovision/components/users/flag_helpers.rb +72 -0
  65. data/app/lib/biovision/components/users/profile_handler.rb +111 -1
  66. data/app/lib/biovision/components/users/registration_handler.rb +40 -52
  67. data/app/lib/biovision/components/users/validation.rb +83 -0
  68. data/app/lib/biovision/components/users_component.rb +82 -19
  69. data/app/lib/biovision/notifiers/base_notifier.rb +2 -2
  70. data/app/lib/biovision/notifiers/contact_notifier.rb +15 -0
  71. data/app/lib/canonizer.rb +38 -0
  72. data/app/lib/carrier_wave/image_optim.rb +32 -0
  73. data/app/mailers/code_sender.rb +29 -0
  74. data/app/models/agent.rb +4 -0
  75. data/app/models/biovision_component.rb +22 -2
  76. data/app/models/browser.rb +1 -1
  77. data/app/models/code.rb +32 -9
  78. data/app/models/concerns/has_simple_image.rb +9 -0
  79. data/app/models/concerns/meta_texts.rb +25 -5
  80. data/app/models/concerns/tree_structure.rb +72 -0
  81. data/app/models/contact_method.rb +47 -0
  82. data/app/models/contact_type.rb +27 -0
  83. data/app/models/dynamic_block.rb +43 -0
  84. data/app/models/dynamic_page.rb +71 -0
  85. data/app/models/feedback_message.rb +59 -0
  86. data/app/models/feedback_response.rb +50 -0
  87. data/app/models/group.rb +48 -0
  88. data/app/models/language.rb +4 -0
  89. data/app/models/navigation_group.rb +33 -0
  90. data/app/models/navigation_group_page.rb +23 -0
  91. data/app/models/role.rb +56 -0
  92. data/app/models/role_group.rb +13 -0
  93. data/app/models/simple_image.rb +22 -8
  94. data/app/models/simple_image_tag.rb +1 -1
  95. data/app/models/token.rb +4 -4
  96. data/app/models/user.rb +94 -26
  97. data/app/models/user_group.rb +20 -0
  98. data/app/models/user_role.rb +19 -0
  99. data/app/uploaders/simple_file_uploader.rb +27 -0
  100. data/app/uploaders/simple_image_uploader.rb +20 -0
  101. data/app/views/admin/agents/index.html.erb +0 -2
  102. data/app/views/admin/components/_image.jbuilder +18 -0
  103. data/app/views/admin/components/_list.html.erb +1 -1
  104. data/app/views/admin/components/entity/_links.html.erb +1 -1
  105. data/app/views/admin/components/image.jbuilder +1 -0
  106. data/app/views/admin/components/images.jbuilder +4 -0
  107. data/app/views/admin/components/links/_content.html.erb +9 -0
  108. data/app/views/admin/components/links/_users.html.erb +1 -8
  109. data/app/views/admin/components/links/extra/_content.html.erb +0 -0
  110. data/app/views/admin/components/privileges/_links.html.erb +0 -18
  111. data/app/views/admin/components/settings/_new_parameter.html.erb +4 -2
  112. data/app/views/admin/components/settings/_parameters.html.erb +8 -2
  113. data/app/views/admin/components/settings/_settings.html.erb +1 -1
  114. data/app/views/admin/components/update_privileges.jbuilder +21 -0
  115. data/app/views/admin/dynamic_blocks/_form.html.erb +16 -0
  116. data/app/views/admin/dynamic_blocks/_nav_item.html.erb +6 -0
  117. data/app/views/admin/dynamic_blocks/entity/_in_list.html.erb +10 -0
  118. data/app/views/admin/dynamic_blocks/index.html.erb +15 -0
  119. data/app/views/admin/dynamic_blocks/show.html.erb +23 -0
  120. data/app/views/admin/dynamic_pages/_form.html.erb +21 -0
  121. data/app/views/admin/dynamic_pages/_nav_item.html.erb +6 -0
  122. data/app/views/admin/dynamic_pages/entity/_in_list.html.erb +15 -0
  123. data/app/views/admin/dynamic_pages/index.html.erb +15 -0
  124. data/app/views/admin/dynamic_pages/show.html.erb +28 -0
  125. data/app/views/admin/ip_addresses/index.html.erb +0 -2
  126. data/app/views/admin/navigation_groups/_form.html.erb +15 -0
  127. data/app/views/admin/navigation_groups/_nav_item.html.erb +6 -0
  128. data/app/views/admin/navigation_groups/entity/_in_list.html.erb +12 -0
  129. data/app/views/admin/navigation_groups/index.html.erb +15 -0
  130. data/app/views/admin/navigation_groups/show.html.erb +20 -0
  131. data/app/views/admin/unauthorized.html.erb +2 -5
  132. data/app/views/admin/users/_form.html.erb +81 -0
  133. data/app/views/admin/users/_nav_item.html.erb +6 -0
  134. data/app/views/admin/users/entity/_fields.html.erb +53 -0
  135. data/app/views/admin/users/entity/_in_list.html.erb +38 -0
  136. data/app/views/admin/users/entity/_profile.html.erb +26 -0
  137. data/app/views/admin/users/entity/in_list/_additional_data.html.erb +0 -0
  138. data/app/views/admin/users/index.html.erb +15 -0
  139. data/app/views/admin/users/show.html.erb +44 -0
  140. data/app/views/application/forbidden.html.erb +9 -0
  141. data/app/views/application/forbidden.jbuilder +4 -0
  142. data/app/views/application/not_found.html.erb +9 -0
  143. data/app/views/application/not_found.jbuilder +4 -0
  144. data/app/views/application/unauthorized.html.erb +16 -0
  145. data/app/views/application/unauthorized.jbuilder +4 -0
  146. data/app/views/authentication/new.html.erb +2 -8
  147. data/app/views/components/content/_dynamic_page.html.erb +21 -0
  148. data/app/views/components/users/_form_tabs.html.erb +31 -0
  149. data/app/views/components/users/_join_form.html.erb +192 -0
  150. data/app/views/components/users/_login_form.html.erb +45 -0
  151. data/app/views/components/users/form/_image.html.erb +17 -0
  152. data/app/views/components/users/form/_profile_data.html.erb +54 -0
  153. data/app/views/contact/_form.html.erb +108 -0
  154. data/app/views/contact/create_feedback_message.js.erb +1 -0
  155. data/app/views/contact/feedback.html.erb +13 -0
  156. data/app/views/contact/index.html.erb +16 -0
  157. data/app/views/fallback/show.html.erb +6 -0
  158. data/app/views/layouts/admin.html.erb +1 -1
  159. data/app/views/layouts/admin/_footer.html.erb +1 -1
  160. data/app/views/layouts/application/header/_authentication.html.erb +1 -1
  161. data/app/views/legal/privacy.html.erb +5 -0
  162. data/app/views/legal/tos.html.erb +5 -0
  163. data/app/views/my/confirmations/show.html.erb +62 -0
  164. data/app/views/my/index/index.html.erb +33 -0
  165. data/app/views/my/profiles/_form.html.erb +10 -0
  166. data/app/views/my/profiles/check.jbuilder +4 -0
  167. data/app/views/my/profiles/edit.html.erb +14 -0
  168. data/app/views/my/profiles/form/_basic_parameters.html.erb +9 -0
  169. data/app/views/my/profiles/form/_sensitive_parameters.html.erb +68 -0
  170. data/app/views/my/profiles/new.html.erb +6 -8
  171. data/app/views/my/profiles/show.html.erb +23 -0
  172. data/app/views/shared/_flash_messages.html.erb +1 -1
  173. data/app/views/shared/_list_of_errors.html.erb +7 -0
  174. data/app/views/shared/admin/_breadcrumbs.html.erb +8 -0
  175. data/app/views/shared/admin/_list.html.erb +4 -4
  176. data/app/views/shared/admin/_list_with_priority.html.erb +4 -4
  177. data/app/views/shared/admin/_priority.html.erb +5 -0
  178. data/app/views/shared/admin/_toggle.html.erb +11 -0
  179. data/app/views/shared/entity/_formatted_text_field.html.erb +10 -0
  180. data/app/views/shared/entity/_image.html.erb +31 -0
  181. data/app/views/shared/entity/_language.html.erb +6 -0
  182. data/app/views/shared/entity/_linked_entity.html.erb +6 -0
  183. data/app/views/shared/entity/_meta_texts.html.erb +16 -0
  184. data/app/views/shared/entity/_metadata.html.erb +18 -0
  185. data/app/views/shared/entity/_parent.html.erb +6 -0
  186. data/app/views/shared/entity/_priority.html.erb +4 -0
  187. data/app/views/shared/entity/_raw_text_field.html.erb +10 -0
  188. data/app/views/shared/entity/_simple_image.html.erb +10 -0
  189. data/app/views/shared/entity/_slug.html.erb +6 -0
  190. data/app/views/shared/entity/_text_field.html.erb +6 -0
  191. data/app/views/shared/entity/_text_fields.html.erb +9 -0
  192. data/app/views/shared/entity/_timestamps.html.erb +13 -0
  193. data/app/views/shared/entity/_tree_caches.html.erb +12 -0
  194. data/app/views/shared/entity/_uuid.html.erb +4 -0
  195. data/app/views/shared/entity/edit.html.erb +21 -0
  196. data/app/views/shared/entity/new.html.erb +16 -0
  197. data/app/views/shared/forms/_entity_flags.html.erb +15 -0
  198. data/app/views/shared/forms/_field.html.erb +46 -0
  199. data/app/views/shared/forms/_fields.html.erb +3 -0
  200. data/app/views/shared/forms/_language.html.erb +40 -0
  201. data/app/views/shared/forms/_meta_texts.html.erb +27 -0
  202. data/app/views/shared/forms/_priority.html.erb +13 -0
  203. data/app/views/shared/forms/_simple_image.html.erb +39 -0
  204. data/app/views/shared/forms/_state_container.html.erb +7 -0
  205. data/app/views/shared/forms/_text_area.html.erb +25 -0
  206. data/app/views/shared/forms/_text_field.html.erb +24 -0
  207. data/app/views/shared/forms/_text_fields.html.erb +3 -0
  208. data/app/views/shared/forms/check.jbuilder +4 -0
  209. data/app/views/shared/forms/errors.jbuilder +3 -0
  210. data/app/views/shared/forms/simple_image/_browse.html.erb +14 -0
  211. data/app/views/shared/forms/simple_image/_load_image.html.erb +38 -0
  212. data/app/views/shared/my/_list.html.erb +19 -0
  213. data/app/views/shared/my/_list_with_priority.html.erb +19 -0
  214. data/app/views/users/_profile.html.erb +30 -0
  215. data/app/views/users/profile/_data.html.erb +20 -0
  216. data/app/views/users/show.html.erb +21 -0
  217. data/config/locales/biovision-ru.yml +58 -0
  218. data/config/locales/components-ru.yml +30 -2
  219. data/config/locales/contact-ru.yml +106 -0
  220. data/config/locales/content-ru.yml +103 -0
  221. data/config/locales/users-ru.yml +117 -3
  222. data/config/routes.rb +70 -50
  223. data/db/migrate/20191228000000_create_biovision_components.rb +4 -5
  224. data/db/migrate/20200224000000_create_track_component.rb +7 -8
  225. data/db/migrate/20200224000010_create_users_component.rb +15 -43
  226. data/db/migrate/20200404000000_create_simple_images.rb +3 -3
  227. data/db/migrate/20200529000000_create_content_component.rb +74 -0
  228. data/db/migrate/20210401000000_create_contact_component.rb +95 -0
  229. data/db/migrate/20210405000000_create_acl.rb +74 -0
  230. data/lib/biovision/base_methods.rb +18 -10
  231. data/lib/biovision/engine.rb +8 -13
  232. data/lib/biovision/version.rb +1 -1
  233. metadata +186 -20
  234. data/app/assets/images/biovision/placeholders/user.svg +0 -15
  235. data/app/helpers/users_helper.rb +0 -11
  236. data/app/lib/biovision/components/component_settings.rb +0 -30
  237. data/app/lib/biovision/components/privilege_handler.rb +0 -77
  238. data/app/lib/biovision/components/users/code_handler.rb +0 -23
  239. data/app/models/foreign_site.rb +0 -34
  240. data/app/models/foreign_user.rb +0 -21
  241. data/app/uploaders/user_image_uploader.rb +0 -58
  242. data/app/views/admin/components/privileges/_privilege_flag.html.erb +0 -28
  243. data/app/views/authentication/_form.html.erb +0 -40
  244. data/app/views/authentication/failed.js.erb +0 -3
  245. data/app/views/my/profiles/new/_form.html.erb +0 -147
  246. data/app/views/shared/admin/_toggleable.html.erb +0 -8
@@ -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
@@ -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,72 @@
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_save { parent&.cache_children! }
14
+
15
+ def self.tree(collection)
16
+ result = {}
17
+
18
+ collection.each do |entity|
19
+ result[entity.id] = {
20
+ parent_id: entity.parent_id,
21
+ entity: entity,
22
+ }
23
+ end
24
+
25
+ result
26
+ end
27
+
28
+ def depth
29
+ parent_ids.count
30
+ end
31
+
32
+ def parent_ids
33
+ parents_cache.split(',').compact
34
+ end
35
+
36
+ # @return [Array<Integer>]
37
+ def branch_ids
38
+ parents_cache.split(',').map(&:to_i).reject { |i| i < 1 }.uniq + [id]
39
+ end
40
+
41
+ # @return [Array<Integer>]
42
+ def subbranch_ids
43
+ [id] + children_cache
44
+ end
45
+
46
+ def parents
47
+ return [] if parents_cache.blank?
48
+
49
+ self.class.where(id: parent_ids).order('id asc')
50
+ end
51
+
52
+ def cache_parents!
53
+ return if parent.nil?
54
+
55
+ self.parents_cache = "#{parent.parents_cache},#{parent_id}".gsub(/\A,/, '')
56
+ save!
57
+ end
58
+
59
+ # @param [Array] new_cache
60
+ def cache_children!(new_cache = [])
61
+ if new_cache.blank?
62
+ new_cache = child_items.order('id asc').pluck(:id, :children_cache)
63
+ end
64
+
65
+ self.children_cache += new_cache.flatten
66
+ self.children_cache.uniq!
67
+
68
+ save!
69
+ parent&.cache_children!([id] + children_cache)
70
+ end
71
+ end
72
+ 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
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Type of contact
4
+ #
5
+ # Attributes:
6
+ # slug [String]
7
+ class ContactType < ApplicationRecord
8
+ include Checkable
9
+ include RequiredUniqueSlug
10
+
11
+ SLUG_PATTERN = /\A[a-z][_a-z]{,16}[a-z]\z/.freeze
12
+
13
+ has_many :contact_methods, dependent: :delete_all
14
+
15
+ validates_format_of :slug, with: SLUG_PATTERN
16
+
17
+ scope :list_for_administration, -> { ordered_by_slug }
18
+
19
+ # @param [String] slug
20
+ def self.[](slug)
21
+ find_by(slug: slug)
22
+ end
23
+
24
+ def self.entity_parameters(*)
25
+ %i[slug]
26
+ end
27
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Dynamic block
4
+ #
5
+ # Attributes:
6
+ # body [Text], optional
7
+ # created_at [DateTime]
8
+ # data [JSON]
9
+ # slug [String]
10
+ # updated_at [DateTime]
11
+ # visible [Boolean]
12
+ class DynamicBlock < ApplicationRecord
13
+ include Checkable
14
+ include RequiredUniqueSlug
15
+ include Toggleable
16
+
17
+ SLUG_LIMIT = 100
18
+
19
+ toggleable :visible
20
+
21
+ validates_length_of :slug, maximum: SLUG_LIMIT
22
+
23
+ scope :visible, -> { where(visible: true) }
24
+ scope :list_for_administration, -> { ordered_by_slug }
25
+
26
+ # Get body of visible block with given slug or empty string
27
+ #
28
+ # Can be used in views for quick output
29
+ #
30
+ # @param [String] slug
31
+ # @return [String]
32
+ def self.[](slug)
33
+ visible.find_by(slug: slug)&.body.to_s
34
+ end
35
+
36
+ def self.entity_parameters(*)
37
+ %i[body slug visible]
38
+ end
39
+
40
+ def text_for_link
41
+ slug
42
+ end
43
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Dynamic page
4
+ #
5
+ # Attributes:
6
+ # body [text]
7
+ # created_at [DateTime]
8
+ # data [jsonb]
9
+ # language_id [Language], optional
10
+ # name [string]
11
+ # simple_image_id [SimpleImage], optional
12
+ # slug [string]
13
+ # updated_at [DateTime]
14
+ # url [string], optional
15
+ # uuid [uuid]
16
+ # visible [boolean]
17
+ class DynamicPage < ApplicationRecord
18
+ include Checkable
19
+ include HasLanguage
20
+ include HasSimpleImage
21
+ include HasUuid
22
+ include MetaTexts
23
+ include Toggleable
24
+
25
+ NAME_LIMIT = 100
26
+ SLUG_LIMIT = 100
27
+ URL_LIMIT = 100
28
+
29
+ toggleable :visible
30
+
31
+ has_many :navigation_group_pages, dependent: :destroy
32
+
33
+ validates_presence_of :slug
34
+ validates_uniqueness_of :slug, scope: :language_id
35
+ validates_length_of :name, maximum: NAME_LIMIT
36
+ validates_length_of :slug, maximum: SLUG_LIMIT
37
+ validates_length_of :url, maximum: URL_LIMIT
38
+
39
+ scope :list_for_administration, -> { included_image.order('slug asc, language_id asc nulls first') }
40
+
41
+ # @param [String] slug
42
+ def self.[](slug)
43
+ find_by(slug: slug)
44
+ end
45
+
46
+ def self.entity_parameters(*)
47
+ %i[body language_id name simple_image_id slug url visible]
48
+ end
49
+
50
+ def long_slug
51
+ language.nil? ? slug : "#{slug} (#{language.code})"
52
+ end
53
+
54
+ def text_for_link
55
+ long_slug
56
+ end
57
+
58
+ def world_url
59
+ url.blank? ? '/' : url
60
+ end
61
+
62
+ def meta_title
63
+ title = data.dig('meta', 'title')
64
+ title.blank? ? name : title
65
+ end
66
+
67
+ def meta_heading
68
+ heading = data.dig('meta', 'heading')
69
+ heading.blank? ? name : heading
70
+ end
71
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Message from visitor
4
+ #
5
+ # Attributes:
6
+ # agent_id [Agent], optional
7
+ # attachment [SimpleFileUploader], optional
8
+ # comment [text], optional
9
+ # created_at [DateTime]
10
+ # data [jsonb]
11
+ # email [string], optional
12
+ # ip_address_id [IpAddress], optional
13
+ # language_id [Language], optional
14
+ # name [string], optional
15
+ # phone [string], optional
16
+ # processed [boolean]
17
+ # updated_at [DateTime]
18
+ # user_id [User], optional
19
+ # uuid [uuid]
20
+ class FeedbackMessage < ApplicationRecord
21
+ include Checkable
22
+ include HasLanguage
23
+ include HasOwner
24
+ include HasTrack
25
+ include HasUuid
26
+ include Toggleable
27
+
28
+ COMMENT_LIMIT = 5000
29
+ EMAIL_LIMIT = 250
30
+ EMAIL_PATTERN = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z0-9][-a-z0-9]+)\z/i.freeze
31
+ NAME_LIMIT = 100
32
+ PHONE_LIMIT = 30
33
+
34
+ toggleable :processed
35
+
36
+ mount_uploader :attachment, SimpleFileUploader
37
+
38
+ belongs_to :user, optional: true
39
+ has_many :feedback_responses, dependent: :delete_all
40
+
41
+ validates_format_of :email, with: EMAIL_PATTERN, allow_blank: true
42
+ validates_length_of :comment, maximum: COMMENT_LIMIT
43
+ validates_length_of :email, maximum: EMAIL_LIMIT
44
+ validates_length_of :name, maximum: NAME_LIMIT
45
+ validates_length_of :phone, maximum: PHONE_LIMIT
46
+
47
+ scope :recent, -> { order('id desc') }
48
+ scope :unprocessed, -> { where(processed: false) }
49
+ scope :list_for_administration, -> { recent }
50
+
51
+ # @param [Integer] page
52
+ def self.page_for_administration(page = 1)
53
+ list_for_administration.page(page)
54
+ end
55
+
56
+ def self.entity_parameters(*)
57
+ %i[attachment comment email language_id name phone]
58
+ end
59
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Response to feedback message
4
+ #
5
+ # Attributes:
6
+ # agent_id [Agent], optional
7
+ # body [text]
8
+ # created_at [DateTime]
9
+ # data [jsonb]
10
+ # feedback_message_id [FeedbackMessage]
11
+ # ip_address_id [IpAddress], optional
12
+ # updated_at [DateTime]
13
+ # user_id [User], optional
14
+ # uuid [uuid]
15
+ # visible [boolean]
16
+ class FeedbackResponse < ApplicationRecord
17
+ include Checkable
18
+ include HasOwner
19
+ include HasTrack
20
+ include HasUuid
21
+ include Toggleable
22
+
23
+ BODY_LIMIT = 5000
24
+
25
+ toggleable :visible
26
+
27
+ belongs_to :feedback_message
28
+ belongs_to :user, optional: true
29
+
30
+ validates_presence_of :body
31
+ validates_length_of :body, maximum: BODY_LIMIT
32
+
33
+ scope :recent, -> { order('id desc') }
34
+ scope :visible, -> { where(visible: true) }
35
+ scope :list_for_administration, -> { recent }
36
+ scope :list_for_visitors, -> { visible.recent }
37
+
38
+ # @param [Integer] page
39
+ def self.page_for_administration(page = 1)
40
+ list_for_administration.page(page)
41
+ end
42
+
43
+ def self.entity_parameters(*)
44
+ %i[body]
45
+ end
46
+
47
+ def self.creation_parameters(*)
48
+ entity_parameters + %i[feedback_message_id]
49
+ end
50
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ACL group
4
+ #
5
+ # Attributes:
6
+ # biovision_component_id [BiovisionComponent]
7
+ # data [jsonb]
8
+ # children_cache [Array<integer>]
9
+ # parent_id [Group], optional
10
+ # parents_cache [string]
11
+ # slug [string]
12
+ # user_count [Integer]
13
+ # uuid [uuid]
14
+ class Group < ApplicationRecord
15
+ include Checkable
16
+ include HasUuid
17
+ include TreeStructure
18
+
19
+ SLUG_LIMIT = 50
20
+ SLUG_PATTERN = /\A[a-z][_a-z]*[a-z]\z/.freeze
21
+
22
+ belongs_to :biovision_component
23
+ has_many :user_groups, dependent: :delete_all
24
+ has_many :role_groups, dependent: :destroy
25
+
26
+ before_validation { self.slug = slug.to_s.downcase }
27
+
28
+ validates_presence_of :slug
29
+ validates_uniqueness_of :slug, scope: :biovision_component_id
30
+ validates_format_of :slug, with: SLUG_PATTERN
31
+
32
+ def roles
33
+ Role.where(id: role_groups.where(group_id: branch_ids).pluck(:role_id).uniq)
34
+ end
35
+
36
+ def users
37
+ User.where(id: user_ids)
38
+ end
39
+
40
+ def user_ids
41
+ # user_groups.where(group_id: branch_ids).pluck(:user_id).uniq
42
+ []
43
+ end
44
+
45
+ def users_changed!
46
+ roles.each(&:count_users!)
47
+ end
48
+ end