biovision 0.1.210414.0 → 0.12.211128.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +50 -40
  3. data/app/assets/stylesheets/biovision/admin/components/users.scss +4 -0
  4. data/app/assets/stylesheets/biovision/admin/components.scss +10 -0
  5. data/app/assets/stylesheets/biovision/admin/layout.scss +34 -8
  6. data/app/assets/stylesheets/biovision/biovision.scss +64 -26
  7. data/app/assets/stylesheets/biovision/components/carousel.scss +24 -24
  8. data/app/assets/stylesheets/biovision/components/filters.scss +39 -0
  9. data/app/assets/stylesheets/biovision/components/forms.scss +56 -10
  10. data/app/assets/stylesheets/biovision/components/quick_search.scss +24 -0
  11. data/app/assets/stylesheets/biovision/components.scss +1 -0
  12. data/app/assets/stylesheets/biovision/default.scss +4 -4
  13. data/app/assets/stylesheets/biovision/themes/default_theme/components/users/dashboard.scss +4 -0
  14. data/app/assets/stylesheets/biovision/themes/default_theme/components/users.scss +1 -0
  15. data/app/assets/stylesheets/biovision/themes/default_theme/layout/footer.scss +3 -0
  16. data/app/assets/stylesheets/biovision/themes/default_theme/layout/header.scss +12 -0
  17. data/app/assets/stylesheets/biovision/themes/default_theme/layout.scss +6 -3
  18. data/app/assets/stylesheets/biovision/themes/default_theme.scss +0 -1
  19. data/app/assets/stylesheets/biovision/vars.scss +5 -0
  20. data/app/controllers/admin/biovision_components_controller.rb +10 -0
  21. data/app/controllers/admin/components_controller.rb +33 -83
  22. data/app/controllers/admin/dynamic_pages_controller.rb +1 -1
  23. data/app/controllers/admin/index_controller.rb +8 -2
  24. data/app/controllers/admin/navigation_groups_controller.rb +31 -0
  25. data/app/controllers/admin/tokens_controller.rb +15 -0
  26. data/app/controllers/admin/users_controller.rb +35 -4
  27. data/app/controllers/admin_controller.rb +2 -9
  28. data/app/controllers/concerns/component_stories.rb +22 -0
  29. data/app/controllers/concerns/crud_entities.rb +23 -15
  30. data/app/controllers/concerns/my_crud_entities.rb +146 -0
  31. data/app/controllers/concerns/processed_forms.rb +28 -0
  32. data/app/controllers/concerns/restricted_access.rb +37 -0
  33. data/app/controllers/contact_controller.rb +1 -1
  34. data/app/controllers/errors_controller.rb +37 -0
  35. data/app/controllers/my/components_controller.rb +21 -0
  36. data/app/controllers/my/index_controller.rb +1 -3
  37. data/app/controllers/my/profiles_controller.rb +2 -0
  38. data/app/controllers/oembed_controller.rb +12 -0
  39. data/app/controllers/profile_controller.rb +2 -0
  40. data/app/controllers/users_controller.rb +2 -0
  41. data/app/helpers/biovision_components_helper.rb +7 -3
  42. data/app/helpers/biovision_helper.rb +33 -34
  43. data/app/helpers/entity_helper.rb +77 -0
  44. data/app/helpers/my_helper.rb +34 -0
  45. data/app/lib/biovision/components/base/component_parameters.rb +13 -2
  46. data/app/lib/biovision/components/base/component_privileges.rb +28 -18
  47. data/app/lib/biovision/components/base/component_settings.rb +8 -0
  48. data/app/lib/biovision/components/base/component_stories.rb +30 -0
  49. data/app/lib/biovision/components/base/entity_links.rb +38 -0
  50. data/app/lib/biovision/components/base/image_handling.rb +33 -0
  51. data/app/lib/biovision/components/base_component.rb +20 -49
  52. data/app/lib/biovision/components/contact_component.rb +5 -1
  53. data/app/lib/biovision/components/content/oembed/receiver.rb +98 -0
  54. data/app/lib/biovision/components/content/oembed/twitter_receiver.rb +20 -0
  55. data/app/lib/biovision/components/content/oembed/vimeo_receiver.rb +20 -0
  56. data/app/lib/biovision/components/content/oembed/youtube_receiver.rb +20 -0
  57. data/app/lib/biovision/components/content_component.rb +46 -9
  58. data/app/lib/biovision/components/track_component.rb +1 -1
  59. data/app/lib/biovision/components/users_component.rb +34 -2
  60. data/app/lib/biovision/helpers/data_helper.rb +70 -0
  61. data/app/lib/biovision/helpers/export_helper.rb +97 -0
  62. data/app/lib/biovision/migrations/component_migration.rb +56 -0
  63. data/app/lib/biovision/stories/component_story.rb +55 -0
  64. data/app/mailers/feedback_mailer.rb +14 -0
  65. data/app/models/biovision_component.rb +17 -1
  66. data/app/models/browser.rb +1 -1
  67. data/app/models/code.rb +5 -5
  68. data/app/models/concerns/checkable.rb +2 -1
  69. data/app/models/concerns/has_uploaded_file.rb +26 -0
  70. data/app/models/concerns/simple_tag.rb +30 -0
  71. data/app/models/concerns/toggleable.rb +2 -1
  72. data/app/models/concerns/tree_structure.rb +4 -1
  73. data/app/models/contact_method.rb +1 -1
  74. data/app/models/contact_type.rb +1 -1
  75. data/app/models/dynamic_block.rb +1 -1
  76. data/app/models/dynamic_page.rb +3 -1
  77. data/app/models/feedback_message.rb +7 -1
  78. data/app/models/feedback_response.rb +2 -2
  79. data/app/models/metric.rb +4 -0
  80. data/app/models/navigation_group.rb +11 -1
  81. data/app/models/oembed_domain.rb +25 -0
  82. data/app/models/oembed_link.rb +19 -0
  83. data/app/models/oembed_receiver.rb +15 -0
  84. data/app/models/role.rb +42 -12
  85. data/app/models/simple_image.rb +30 -3
  86. data/app/models/simple_image_tag.rb +1 -16
  87. data/app/models/token.rb +6 -2
  88. data/app/models/uploaded_file.rb +62 -0
  89. data/app/models/uploaded_file_tag.rb +15 -0
  90. data/app/models/uploaded_file_tag_file.rb +13 -0
  91. data/app/models/user.rb +35 -10
  92. data/app/models/user_role.rb +0 -1
  93. data/app/uploaders/simple_file_uploader.rb +2 -6
  94. data/app/uploaders/simple_image_uploader.rb +10 -21
  95. data/app/uploaders/uploaders/path_slug.rb +22 -0
  96. data/app/views/admin/agents/index.html.erb +1 -1
  97. data/app/views/admin/biovision_components/_nav_item.html.erb +6 -0
  98. data/app/views/admin/biovision_components/entity/_in_list.html.erb +12 -0
  99. data/app/views/admin/biovision_components/index.html.erb +11 -0
  100. data/app/views/admin/components/_list.html.erb +1 -1
  101. data/app/views/admin/components/entity/_links.html.erb +31 -21
  102. data/app/views/admin/components/links/_base.html.erb +1 -0
  103. data/app/views/admin/components/settings/_settings.html.erb +3 -3
  104. data/app/views/admin/components/settings.html.erb +2 -1
  105. data/app/views/admin/dynamic_blocks/_form.html.erb +1 -1
  106. data/app/views/admin/dynamic_blocks/entity/_in_list.html.erb +8 -6
  107. data/app/views/admin/dynamic_blocks/index.html.erb +6 -4
  108. data/app/views/admin/dynamic_blocks/show.html.erb +9 -7
  109. data/app/views/admin/dynamic_pages/_dynamic_page.jbuilder +18 -0
  110. data/app/views/admin/dynamic_pages/entity/_in_list.html.erb +6 -4
  111. data/app/views/admin/dynamic_pages/entity/_in_search.html.erb +7 -0
  112. data/app/views/admin/dynamic_pages/index.html.erb +6 -4
  113. data/app/views/admin/dynamic_pages/search.jbuilder +4 -0
  114. data/app/views/admin/dynamic_pages/show.html.erb +2 -2
  115. data/app/views/admin/index/index.html.erb +7 -5
  116. data/app/views/admin/ip_addresses/index.html.erb +2 -2
  117. data/app/views/admin/navigation_group_pages/entity/_in_list.html.erb +26 -0
  118. data/app/views/admin/navigation_groups/entity/_dynamic_pages.html.erb +38 -0
  119. data/app/views/admin/navigation_groups/entity/_in_list.html.erb +7 -5
  120. data/app/views/admin/navigation_groups/index.html.erb +6 -4
  121. data/app/views/admin/navigation_groups/show.html.erb +16 -3
  122. data/app/views/admin/tokens/_form.html.erb +31 -0
  123. data/app/views/admin/tokens/_nav_item.html.erb +6 -0
  124. data/app/views/admin/tokens/entity/_in_list.html.erb +27 -0
  125. data/app/views/admin/tokens/index.html.erb +11 -0
  126. data/app/views/admin/tokens/show.html.erb +26 -0
  127. data/app/views/admin/users/_user.jbuilder +18 -0
  128. data/app/views/admin/users/entity/_fields.html.erb +1 -1
  129. data/app/views/admin/users/entity/_in_list.html.erb +3 -3
  130. data/app/views/admin/users/entity/_in_search.html.erb +18 -0
  131. data/app/views/admin/users/index.html.erb +13 -4
  132. data/app/views/admin/users/roles/_component.html.erb +22 -0
  133. data/app/views/admin/users/roles.html.erb +23 -0
  134. data/app/views/admin/users/search.jbuilder +4 -0
  135. data/app/views/admin/users/show.html.erb +28 -10
  136. data/app/views/admin/widgets/_filters.html.erb +20 -0
  137. data/app/views/admin/widgets/_quick_search.html.erb +13 -0
  138. data/app/views/admin/widgets/filters/_flag.html.erb +15 -0
  139. data/app/views/admin/widgets/filters/_text.html.erb +7 -0
  140. data/app/views/application/unauthorized.html.erb +4 -1
  141. data/app/views/components/content/_dynamic_page.html.erb +6 -10
  142. data/app/views/components/content/_dynamic_page_content.html.erb +14 -0
  143. data/app/views/components/users/_login_form.html.erb +1 -0
  144. data/app/views/contact/_form.html.erb +1 -1
  145. data/app/views/errors/error.html.erb +1 -0
  146. data/app/views/feedback_mailer/new_feedback_request.html.erb +11 -0
  147. data/app/views/feedback_mailer/new_feedback_request.text.erb +6 -0
  148. data/app/views/index/index.html.erb +14 -0
  149. data/app/views/layouts/admin/_header.html.erb +7 -2
  150. data/app/views/layouts/admin.html.erb +0 -1
  151. data/app/views/layouts/application/_footer.html.erb +1 -1
  152. data/app/views/layouts/application/header/_authentication.html.erb +4 -1
  153. data/app/views/my/components/index.html.erb +25 -0
  154. data/app/views/my/components/show.html.erb +21 -0
  155. data/app/views/my/index/_cards.html.erb +15 -0
  156. data/app/views/my/index/_email.html.erb +14 -0
  157. data/app/views/my/index/_navigation.html.erb +33 -0
  158. data/app/views/my/index/index.html.erb +7 -26
  159. data/app/views/my/profiles/show.html.erb +13 -0
  160. data/app/views/{admin/components/links/extra/_content.html.erb → my/recoveries/show.html.erb} +0 -0
  161. data/app/views/shared/admin/_list.html.erb +10 -19
  162. data/app/views/shared/admin/_list_with_priority.html.erb +10 -19
  163. data/app/views/shared/admin/_priority.html.erb +6 -5
  164. data/app/views/shared/admin/_toggle.html.erb +5 -10
  165. data/app/views/shared/entity/_date_field.html.erb +6 -0
  166. data/app/views/shared/entity/_linked_entity.html.erb +2 -2
  167. data/app/views/shared/entity/_list.html.erb +22 -0
  168. data/app/views/shared/entity/_list_with_priority.html.erb +22 -0
  169. data/app/views/shared/entity/_parent.html.erb +1 -1
  170. data/app/views/shared/entity/_priority_icons.html.erb +8 -0
  171. data/app/views/shared/entity/_time_field.html.erb +6 -0
  172. data/app/views/shared/entity/_toggle.html.erb +12 -0
  173. data/app/views/shared/entity/_track.html.erb +12 -0
  174. data/app/views/shared/entity/_tree_caches.html.erb +8 -1
  175. data/app/views/shared/entity/edit.html.erb +10 -6
  176. data/app/views/shared/entity/new.html.erb +4 -2
  177. data/app/views/shared/forms/_field.html.erb +6 -2
  178. data/app/views/shared/forms/_field_with_search.html.erb +17 -0
  179. data/app/views/shared/forms/_meta_texts.html.erb +1 -1
  180. data/app/views/shared/forms/_simple_entity_link.html.erb +14 -0
  181. data/app/views/shared/forms/_simple_image.html.erb +12 -4
  182. data/app/views/shared/forms/_text_area.html.erb +1 -1
  183. data/app/views/shared/forms/_text_field.html.erb +1 -1
  184. data/app/views/shared/my/_list.html.erb +10 -19
  185. data/app/views/shared/my/_list_with_priority.html.erb +10 -19
  186. data/app/views/shared/my/entity/edit.html.erb +25 -0
  187. data/app/views/shared/my/entity/new.html.erb +18 -0
  188. data/app/views/simple_images/_simple_image.jbuilder +13 -0
  189. data/config/locales/biovision-ru.yml +18 -1
  190. data/config/locales/components-ru.yml +27 -4
  191. data/config/locales/contact-ru.yml +4 -0
  192. data/config/locales/content-ru.yml +12 -0
  193. data/config/locales/users-ru.yml +31 -6
  194. data/config/routes.rb +35 -4
  195. data/db/migrate/20191228000000_create_biovision_components.rb +2 -0
  196. data/db/migrate/20200224000000_create_track_component.rb +8 -12
  197. data/db/migrate/20200224000010_create_users_component.rb +8 -49
  198. data/db/migrate/20200404000000_create_simple_images.rb +1 -0
  199. data/db/migrate/20210405000000_create_acl.rb +15 -1
  200. data/db/migrate/{20200529000000_create_content_component.rb → 20210421000000_create_content_component.rb} +24 -18
  201. data/db/migrate/{20210401000000_create_contact_component.rb → 20210421000010_create_contact_component.rb} +1 -22
  202. data/db/migrate/20210616000000_create_uploaded_files.rb +52 -0
  203. data/db/migrate/amends/20210816060606_create_oembed_receivers.rb +21 -0
  204. data/db/migrate/amends/20210907070707_add_checksum_to_simple_images.rb +13 -0
  205. data/lib/biovision/base_methods.rb +8 -28
  206. data/lib/biovision/version.rb +1 -1
  207. data/lib/tasks/components.rake +51 -0
  208. metadata +90 -17
  209. data/app/lib/biovision/components/base/privilege_handler.rb +0 -79
  210. data/app/models/biovision_component_user.rb +0 -21
  211. data/app/views/admin/components/links/_content.html.erb +0 -9
  212. data/app/views/admin/components/links/_track.html.erb +0 -2
  213. data/app/views/admin/components/links/_users.html.erb +0 -4
  214. data/app/views/admin/components/privileges/_component_user.html.erb +0 -17
  215. data/app/views/admin/components/privileges/_links.html.erb +0 -17
  216. data/app/views/admin/components/privileges/_users.html.erb +0 -23
  217. data/app/views/admin/components/privileges.html.erb +0 -20
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Adds methods for CRUD in My namespace
4
+ module MyCrudEntities
5
+ extend ActiveSupport::Concern
6
+ included ProcessedForms
7
+
8
+ # get [scope]/[table_name]/search?q=
9
+ def search
10
+ q = param_from_request(:q)
11
+ @collection = model_class.search(q).list_for_owner(current_user).page(current_page)
12
+ end
13
+
14
+ # get [scope]/[table_name]
15
+ def index
16
+ @filter = params[:filter]&.permit!.to_h
17
+ data_helper = Biovision::Helpers::DataHelper.new(model_class, @filter)
18
+ @collection = data_helper.personal_collection(current_user, current_page)
19
+ end
20
+
21
+ # get [scope]/[table_name]/:id
22
+ def show
23
+ end
24
+
25
+ # post [scope]/[table_name]/check
26
+ def check
27
+ @entity = model_class.instance_for_check(params[:entity_id], entity_parameters)
28
+
29
+ render 'shared/forms/check'
30
+ end
31
+
32
+ # get [scope]/[table_name]/new
33
+ def new
34
+ @entity = model_class.new
35
+ render view_for_new
36
+ end
37
+
38
+ # post [scope]/[table_name]
39
+ def create
40
+ @entity = component_handler.new_entity(model_class, creation_parameters)
41
+ apply_meta if @entity.respond_to?(:meta=)
42
+ if @entity.save
43
+ form_processed_ok(path_after_save)
44
+ else
45
+ form_processed_with_error(view_for_new)
46
+ end
47
+ end
48
+
49
+ # get [scope]/[table_name]/:id/edit
50
+ def edit
51
+ render view_for_edit
52
+ end
53
+
54
+ # patch [scope]/[table_name]/:id
55
+ def update
56
+ apply_meta if @entity.respond_to?(:meta=)
57
+
58
+ if component_handler.update_entity(@entity, entity_parameters)
59
+ form_processed_ok(path_after_save)
60
+ else
61
+ form_processed_with_error(view_for_edit)
62
+ end
63
+ end
64
+
65
+ # delete [scope]/[table_name]/:id
66
+ def destroy
67
+ flash[:notice] = t('.success') if @entity.destroy
68
+ redirect_to path_after_destroy
69
+ end
70
+
71
+ private
72
+
73
+ def view_for_new
74
+ default_view = "#{controller_path}/new"
75
+ lookup_context.exists?(default_view) ? default_view : 'shared/my/entity/new'
76
+ end
77
+
78
+ def view_for_edit
79
+ default_view = "#{controller_path}/edit"
80
+ lookup_context.exists?(default_view) ? default_view : 'shared/my/entity/edit'
81
+ end
82
+
83
+ def model_class
84
+ @model_class ||= controller_name.classify.constantize
85
+ end
86
+
87
+ def model_key
88
+ model_class.model_name.to_s.underscore
89
+ end
90
+
91
+ def path_after_save
92
+ if @entity.respond_to?(:my_url)
93
+ @entity.my_url
94
+ else
95
+ scope = self.class.module_parent.to_s.downcase
96
+ prefix = scope.blank? ? '' : "/#{scope}"
97
+ key = model_class.column_names.include?('uuid') ? @entity.uuid : @entity.id
98
+ "#{prefix}/#{model_class.table_name}/#{key}"
99
+ end
100
+ end
101
+
102
+ def path_after_destroy
103
+ scope = self.class.module_parent.to_s.downcase
104
+ prefix = scope.blank? ? '' : "/#{scope}"
105
+ "#{prefix}/#{model_class.table_name}"
106
+ end
107
+
108
+ def set_entity
109
+ id = params[:id].to_s
110
+ has_uuid = model_class.column_names.include?('uuid')
111
+ key = id.include?('-') && has_uuid ? :uuid : :id
112
+ @entity = model_class.owned_by(current_user).find_by(key => params[:id])
113
+ handle_http_404("Cannot find #{model_class.model_name}") if @entity.nil?
114
+ end
115
+
116
+ def creation_parameters
117
+ if model_class.respond_to?(:creation_parameters)
118
+ explicit_creation_parameters
119
+ else
120
+ implicit_creation_parameters
121
+ end
122
+ end
123
+
124
+ def explicit_creation_parameters
125
+ permitted = model_class.creation_parameters
126
+ parameters = params.require(model_key).permit(permitted)
127
+ parameters.merge!(tracking_for_entity) if model_class.include?(HasTrack)
128
+ parameters.merge(owner_for_entity)
129
+ end
130
+
131
+ def implicit_creation_parameters
132
+ parameters = entity_parameters
133
+ parameters.merge!(tracking_for_entity) if model_class.include?(HasTrack)
134
+ parameters.merge(owner_for_entity)
135
+ end
136
+
137
+ def entity_parameters
138
+ permitted = model_class.entity_parameters
139
+ params.require(model_key).permit(permitted)
140
+ end
141
+
142
+ def apply_meta
143
+ new_data = params[:meta].permit!
144
+ @entity.meta = new_data
145
+ end
146
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Adds method for redirects after processed forms
4
+ module ProcessedForms
5
+ extend ActiveSupport::Concern
6
+
7
+ private
8
+
9
+ # @param [String] next_page
10
+ def form_processed_ok(next_page)
11
+ respond_to do |format|
12
+ format.js { render(js: "document.location.href = '#{next_page}'") }
13
+ format.json { render(json: { links: { next: next_page } }) }
14
+ format.html { redirect_to(next_page) }
15
+ end
16
+ end
17
+
18
+ # @param [Symbol|String] view_to_render
19
+ # @param [Array] errors
20
+ def form_processed_with_error(view_to_render, errors = [])
21
+ @errors = errors
22
+ respond_to do |format|
23
+ format.js { render('shared/forms/errors', status: :bad_request) }
24
+ format.json { render('shared/forms/errors', status: :bad_request) }
25
+ format.html { render(view_to_render, status: :bad_request) }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Adds method for restricting access
4
+ module RestrictedAccess
5
+ extend ActiveSupport::Concern
6
+
7
+ private
8
+
9
+ # Restrict access for anonymous users
10
+ def restrict_anonymous_access
11
+ return unless current_user.nil?
12
+
13
+ handle_http_401(t('application.errors.restricted_access'))
14
+ end
15
+
16
+ def restrict_access
17
+ user_action = role_end_from_action
18
+ role_name = "#{component_handler.slug}.#{user_action}"
19
+ error = t('admin.errors.unauthorized.missing_role', role: role_name)
20
+
21
+ handle_http_401(error) unless component_handler.permit?(user_action)
22
+ end
23
+
24
+ def role_end_from_action
25
+ role = action_to_role_map.select { |k| k.include?(action_name) }.values.last
26
+ role || 'default'
27
+ end
28
+
29
+ def action_to_role_map
30
+ view = %w[index show search]
31
+ edit = %w[create destroy edit new priority toggle update]
32
+ {
33
+ view => "#{controller_name}.view",
34
+ edit => "#{controller_name}.edit"
35
+ }
36
+ end
37
+ end
@@ -27,7 +27,7 @@ class ContactController < ApplicationController
27
27
  def save_entity
28
28
  if @entity.save
29
29
  show_result
30
- # FeedbackMailer.new_feedback_request(@entity.id).deliver_later
30
+ FeedbackMailer.new_feedback_request(@entity.id).deliver_later
31
31
  else
32
32
  redirect_to root_path
33
33
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Errors
4
+ class ErrorsController < ApplicationController
5
+ before_action :set_message
6
+
7
+ # get /400
8
+ def bad_request
9
+ render :error
10
+ end
11
+
12
+ # get /401
13
+ def unauthorized
14
+ render :error
15
+ end
16
+
17
+ # get /403
18
+ def forbidden
19
+ render :error
20
+ end
21
+
22
+ # get /422
23
+ def unprocessable_entity
24
+ render :error
25
+ end
26
+
27
+ # get /500
28
+ def internal_server_error
29
+ render :error
30
+ end
31
+
32
+ private
33
+
34
+ def set_message
35
+ @message = t("application.errors.#{action_name}")
36
+ end
37
+ end
@@ -2,4 +2,25 @@
2
2
 
3
3
  # User-side component handling
4
4
  class My::ComponentsController < ProfileController
5
+ before_action :restrict_component_access, except: :index
6
+
7
+ # get /my/components
8
+ def index
9
+ @collection = BiovisionComponent.list_for_user
10
+ end
11
+
12
+ # get /my/components/:slug
13
+ def show
14
+ end
15
+
16
+ private
17
+
18
+ def restrict_component_access
19
+ slug = params[:slug]
20
+ @handler = Biovision::Components::BaseComponent.handler(slug, current_user)
21
+ role_name = "#{@handler.slug}.default"
22
+ error = t('admin.errors.unauthorized.missing_role', role: role_name)
23
+
24
+ handle_http_401(error) unless @handler.permit?(role_name)
25
+ end
5
26
  end
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Main page for user
4
- class My::IndexController < ApplicationController
5
- before_action :restrict_anonymous_access
6
-
4
+ class My::IndexController < ProfileController
7
5
  # get /my
8
6
  def index
9
7
  end
@@ -3,6 +3,8 @@
3
3
  # Managing profile for current user
4
4
  class My::ProfilesController < ApplicationController
5
5
  include Authentication
6
+ include ProcessedForms
7
+ include RestrictedAccess
6
8
 
7
9
  before_action :redirect_authorized_user, only: %i[new create]
8
10
  before_action :restrict_anonymous_access, except: %i[check new create]
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Receiving oembed data by URLs
4
+ class OembedController < ApplicationController
5
+ # get /oembed?url=
6
+ def code
7
+ url = param_from_request(:url)
8
+ receiver = Biovision::Components::Content::Oembed::Receiver[url]
9
+
10
+ render json: { meta: { code: receiver.code } }
11
+ end
12
+ end
@@ -2,6 +2,8 @@
2
2
 
3
3
  # Controllers for logged-in users only
4
4
  class ProfileController < ApplicationController
5
+ include RestrictedAccess
6
+
5
7
  before_action :restrict_access
6
8
 
7
9
  protected
@@ -2,6 +2,8 @@
2
2
 
3
3
  # Users for visitors
4
4
  class UsersController < ApplicationController
5
+ include RestrictedAccess
6
+
5
7
  before_action :restrict_anonymous_access, only: %i[ban follow unban unfollow]
6
8
  before_action :set_socialization, only: %i[ban follow unban unfollow]
7
9
  before_action :set_entity
@@ -6,9 +6,13 @@ module BiovisionComponentsHelper
6
6
  # @param [String] text
7
7
  # @param [Hash] options
8
8
  def admin_biovision_component_link(entity, text = nil, options = {})
9
- if text.nil?
10
- text = t("biovision.components.#{entity.slug}.name", default: entity.slug)
11
- end
9
+ text ||= component_name(entity.slug)
12
10
  link_to(text, admin_component_path(slug: entity.slug), options)
13
11
  end
12
+
13
+ # @param [String|BiovisionComponent] slug
14
+ def component_name(slug)
15
+ slug = slug.respond_to?(:slug) ? slug.slug : slug
16
+ t("biovision.components.#{slug}.name", default: slug)
17
+ end
14
18
  end
@@ -3,58 +3,43 @@
3
3
  # Helper methods for common cases
4
4
  module BiovisionHelper
5
5
  # @param [ApplicationRecord] entity
6
- # @param [String] text
6
+ # @param [Biovision::Components::BaseComponent] handler
7
7
  # @param [Hash] options
8
- def admin_entity_link(entity, text = nil, options = {})
8
+ def admin_entity_link(entity, handler: nil, **options)
9
9
  return '∅' if entity.nil?
10
10
 
11
- if text.nil?
12
- text = entity.respond_to?(:text_for_link) ? entity.text_for_link : entity.id
13
- end
14
-
15
- href = if entity.respond_to?(:admin_url)
16
- entity.admin_url
17
- else
18
- "/admin/#{entity.class.table_name}/#{entity.id}"
19
- end
11
+ component = (handler || component_handler)
12
+ text = options.delete(:text) { component.text_for_link(entity) }
20
13
 
21
- link_to(text, href, options)
14
+ if handler.nil? || handler.permit?('view', entity)
15
+ href = component.entity_link(entity, :admin)
16
+ link_to(text, href, options)
17
+ else
18
+ text
19
+ end
22
20
  end
23
21
 
24
22
  # @param [ApplicationRecord] entity
25
- # @param [String] text
26
23
  # @param [Hash] options
27
- def my_entity_link(entity, text = nil, options = {})
24
+ def my_entity_link(entity, **options)
28
25
  return '∅' if entity.nil?
29
26
 
30
- if text.nil?
31
- text = entity.respond_to?(:text_for_link) ? entity.text_for_link : entity.id
32
- end
33
-
34
- href = if entity.respond_to?(:my_url)
35
- entity.my_url
36
- else
37
- "/my/#{entity.class.table_name}/#{entity.id}"
38
- end
27
+ handler = Biovision::Components::BaseComponent[]
28
+ text = options.delete(:text) { handler.text_for_link(entity) }
29
+ href = handler.entity_link(entity, :my)
39
30
 
40
31
  link_to(text, href, options)
41
32
  end
42
33
 
43
34
  # @param [ApplicationRecord] entity
44
- # @param [String] text
45
35
  # @param [Hash] options
46
- def entity_link(entity, text = nil, options = {})
36
+ def entity_link(entity, **options)
47
37
  return '' if entity.nil?
38
+ return '' if entity.respond_to?(:visible?) && !entity.visible?
48
39
 
49
- if text.nil?
50
- text = entity.respond_to?(:text_for_link) ? entity.text_for_link : entity.id
51
- end
52
-
53
- href = if entity.respond_to?(:world_url)
54
- entity.world_url
55
- else
56
- "/#{entity.class.table_name}/#{entity.id}"
57
- end
40
+ handler = Biovision::Components::BaseComponent[]
41
+ text = options.delete(:text) { handler.text_for_link(entity) }
42
+ href = handler.entity_link(entity)
58
43
 
59
44
  link_to(text, href, options)
60
45
  end
@@ -69,6 +54,8 @@ module BiovisionHelper
69
54
  # @param [Hash] options
70
55
  def world_icon(path, title = t(:view_as_visitor), options = {})
71
56
  if path.is_a? ApplicationRecord
57
+ return '' if path.respond_to?(:visible?) && !path.visible?
58
+
72
59
  table_name = path.class.table_name
73
60
  path = path.respond_to?(:world_url) ? path.world_url : "/#{table_name}/#{path.id}"
74
61
  end
@@ -168,4 +155,16 @@ module BiovisionHelper
168
155
  def email_link(email, options = {})
169
156
  link_to(email, "mailto:#{email}", options)
170
157
  end
158
+
159
+ # @param [ApplicationRecord] entity
160
+ # @deprecated use #entity_priority_icons
161
+ def admin_priority_icons(entity)
162
+ render(partial: 'shared/admin/priority', locals: { entity: entity })
163
+ end
164
+
165
+ # @param [ApplicationRecord] entity
166
+ # @deprecated use #entity_toggle
167
+ def admin_toggle_block(entity)
168
+ render(partial: 'shared/admin/toggle', locals: { entity: entity })
169
+ end
171
170
  end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Helpers for displaying common entity-related blocks
4
+ module EntityHelper
5
+ # @param [Enumerable] collection
6
+ # @param [Symbol|String|nil] scope
7
+ # @param [Biovision::Components::BaseComponent|nil] handler
8
+ # @param [TrueClass|FalseClass] with_priority
9
+ def entity_list(collection, scope: nil, handler: component_handler, with_priority: false)
10
+ scope = controller.class.module_parent_name.to_s.downcase if scope.nil?
11
+ suffix = with_priority ? '_with_priority' : ''
12
+
13
+ render(
14
+ partial: "shared/entity/list#{suffix}",
15
+ locals: { collection: collection, handler: handler, scope: scope.to_sym }
16
+ )
17
+ end
18
+
19
+ # @param [ApplicationRecord] entity
20
+ # @param [Symbol|String|nil] scope
21
+ def entity_toggle(entity, scope: nil)
22
+ scope = controller.class.module_parent_name.to_s.downcase if scope.nil?
23
+
24
+ render(
25
+ partial: 'shared/entity/toggle',
26
+ locals: { entity: entity, scope: scope.to_sym }
27
+ )
28
+ end
29
+
30
+ # @param [ApplicationRecord] entity
31
+ # @param [Symbol|String|nil] scope
32
+ def entity_priority_icons(entity, scope: nil)
33
+ scope = controller.class.module_parent_name.to_s.downcase if scope.nil?
34
+
35
+ render(
36
+ partial: 'shared/entity/priority_icons',
37
+ locals: { entity: entity, scope: scope.to_sym }
38
+ )
39
+ end
40
+
41
+ # @param [ApplicationRecord] entity
42
+ # @param [String] text
43
+ def linked_entity_block(entity, text: nil)
44
+ return '' if entity.blank?
45
+
46
+ render(
47
+ partial: 'shared/entity/linked_entity',
48
+ locals: { entity: entity, text: text }
49
+ )
50
+ end
51
+
52
+ # @param [ApplicationRecord] entity
53
+ # @param [String|Symbol] types
54
+ def entity_partial_block(entity, *types)
55
+ permitted = %i[
56
+ priority uuid slug timestamps language simple_image meta_texts track
57
+ ]
58
+
59
+ buffer = ''
60
+ types.select { |i| permitted.include?(i.to_sym)}.each do |type|
61
+ buffer += render(partial: "shared/entity/#{type}", locals: { entity: entity })
62
+ end
63
+
64
+ raw buffer
65
+ end
66
+
67
+ def entity_form_block(f, *types)
68
+ permitted = %i[priority entity_flags simple_image]
69
+
70
+ buffer = ''
71
+ types.select { |i| permitted.include?(i.to_sym)}.each do |type|
72
+ buffer += render partial: "shared/forms/#{type}", locals: { f: f }
73
+ end
74
+
75
+ raw buffer
76
+ end
77
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Helper methods for user context
4
+ module MyHelper
5
+ # @param [ApplicationRecord] entity
6
+ # @param [Hash] options
7
+ def my_edit_icon(entity, options = {})
8
+ title = options.delete(:title) { t(:edit) }
9
+ key = entity.respond_to?(:uuid) ? entity.uuid : entity.id
10
+ path = "/my/#{entity.class.table_name}/#{key}/edit"
11
+ my_icon_with_link('biovision/icons/edit.svg', path, title.to_s, options)
12
+ end
13
+
14
+ # @param [ApplicationRecord] entity
15
+ # @param [Hash] options
16
+ def my_destroy_icon(entity, options = {})
17
+ title = options.delete(:title) { t(:edit) }
18
+ key = entity.respond_to?(:uuid) ? entity.uuid : entity.id
19
+ path = "/my/#{entity.class.table_name}/#{key}"
20
+ default = {
21
+ class: 'danger',
22
+ data: { confirm: t(:are_you_sure) },
23
+ method: :delete,
24
+ }
25
+ my_icon_with_link('biovision/icons/destroy.svg', path, title.to_s, default.merge(options))
26
+ end
27
+
28
+ # @param [String|ApplicationRecord] path
29
+ # @param [String] title
30
+ # @param [Hash] options
31
+ def my_icon_with_link(source, path, title = '', options = {})
32
+ link_to(image_tag(source, alt: title), path, options)
33
+ end
34
+ end
@@ -9,6 +9,14 @@ module Biovision
9
9
  false
10
10
  end
11
11
 
12
+ def use_files?
13
+ false
14
+ end
15
+
16
+ def manage_settings?
17
+ use_parameters? || component.settings.any?
18
+ end
19
+
12
20
  # Receive parameter value with default
13
21
  #
14
22
  # Returns value of component's parameter or default value
@@ -28,7 +36,7 @@ module Biovision
28
36
  # @param [String] key
29
37
  # @return [String]
30
38
  def [](key)
31
- @component.get(key)
39
+ @component.get(key, nil)
32
40
  end
33
41
 
34
42
  # Set parameter
@@ -36,7 +44,10 @@ module Biovision
36
44
  # @param [String] key
37
45
  # @param [String] value
38
46
  def []=(key, value)
39
- @component[key] = value unless key.blank?
47
+ return if key.blank?
48
+
49
+ @component.parameters[key.to_s] = value
50
+ @component.save!
40
51
  end
41
52
  end
42
53
  end