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.
- checksums.yaml +4 -4
- data/README.md +50 -40
- data/app/assets/stylesheets/biovision/admin/components/users.scss +4 -0
- data/app/assets/stylesheets/biovision/admin/components.scss +10 -0
- data/app/assets/stylesheets/biovision/admin/layout.scss +34 -8
- data/app/assets/stylesheets/biovision/biovision.scss +64 -26
- data/app/assets/stylesheets/biovision/components/carousel.scss +24 -24
- data/app/assets/stylesheets/biovision/components/filters.scss +39 -0
- data/app/assets/stylesheets/biovision/components/forms.scss +56 -10
- data/app/assets/stylesheets/biovision/components/quick_search.scss +24 -0
- data/app/assets/stylesheets/biovision/components.scss +1 -0
- data/app/assets/stylesheets/biovision/default.scss +4 -4
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users/dashboard.scss +4 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users.scss +1 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/layout/footer.scss +3 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/layout/header.scss +12 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/layout.scss +6 -3
- data/app/assets/stylesheets/biovision/themes/default_theme.scss +0 -1
- data/app/assets/stylesheets/biovision/vars.scss +5 -0
- data/app/controllers/admin/biovision_components_controller.rb +10 -0
- data/app/controllers/admin/components_controller.rb +33 -83
- data/app/controllers/admin/dynamic_pages_controller.rb +1 -1
- data/app/controllers/admin/index_controller.rb +8 -2
- data/app/controllers/admin/navigation_groups_controller.rb +31 -0
- data/app/controllers/admin/tokens_controller.rb +15 -0
- data/app/controllers/admin/users_controller.rb +35 -4
- data/app/controllers/admin_controller.rb +2 -9
- data/app/controllers/concerns/component_stories.rb +22 -0
- data/app/controllers/concerns/crud_entities.rb +23 -15
- data/app/controllers/concerns/my_crud_entities.rb +146 -0
- data/app/controllers/concerns/processed_forms.rb +28 -0
- data/app/controllers/concerns/restricted_access.rb +37 -0
- data/app/controllers/contact_controller.rb +1 -1
- data/app/controllers/errors_controller.rb +37 -0
- data/app/controllers/my/components_controller.rb +21 -0
- data/app/controllers/my/index_controller.rb +1 -3
- data/app/controllers/my/profiles_controller.rb +2 -0
- data/app/controllers/oembed_controller.rb +12 -0
- data/app/controllers/profile_controller.rb +2 -0
- data/app/controllers/users_controller.rb +2 -0
- data/app/helpers/biovision_components_helper.rb +7 -3
- data/app/helpers/biovision_helper.rb +33 -34
- data/app/helpers/entity_helper.rb +77 -0
- data/app/helpers/my_helper.rb +34 -0
- data/app/lib/biovision/components/base/component_parameters.rb +13 -2
- data/app/lib/biovision/components/base/component_privileges.rb +28 -18
- data/app/lib/biovision/components/base/component_settings.rb +8 -0
- data/app/lib/biovision/components/base/component_stories.rb +30 -0
- data/app/lib/biovision/components/base/entity_links.rb +38 -0
- data/app/lib/biovision/components/base/image_handling.rb +33 -0
- data/app/lib/biovision/components/base_component.rb +20 -49
- data/app/lib/biovision/components/contact_component.rb +5 -1
- data/app/lib/biovision/components/content/oembed/receiver.rb +98 -0
- data/app/lib/biovision/components/content/oembed/twitter_receiver.rb +20 -0
- data/app/lib/biovision/components/content/oembed/vimeo_receiver.rb +20 -0
- data/app/lib/biovision/components/content/oembed/youtube_receiver.rb +20 -0
- data/app/lib/biovision/components/content_component.rb +46 -9
- data/app/lib/biovision/components/track_component.rb +1 -1
- data/app/lib/biovision/components/users_component.rb +34 -2
- data/app/lib/biovision/helpers/data_helper.rb +70 -0
- data/app/lib/biovision/helpers/export_helper.rb +97 -0
- data/app/lib/biovision/migrations/component_migration.rb +56 -0
- data/app/lib/biovision/stories/component_story.rb +55 -0
- data/app/mailers/feedback_mailer.rb +14 -0
- data/app/models/biovision_component.rb +17 -1
- data/app/models/browser.rb +1 -1
- data/app/models/code.rb +5 -5
- data/app/models/concerns/checkable.rb +2 -1
- data/app/models/concerns/has_uploaded_file.rb +26 -0
- data/app/models/concerns/simple_tag.rb +30 -0
- data/app/models/concerns/toggleable.rb +2 -1
- data/app/models/concerns/tree_structure.rb +4 -1
- data/app/models/contact_method.rb +1 -1
- data/app/models/contact_type.rb +1 -1
- data/app/models/dynamic_block.rb +1 -1
- data/app/models/dynamic_page.rb +3 -1
- data/app/models/feedback_message.rb +7 -1
- data/app/models/feedback_response.rb +2 -2
- data/app/models/metric.rb +4 -0
- data/app/models/navigation_group.rb +11 -1
- data/app/models/oembed_domain.rb +25 -0
- data/app/models/oembed_link.rb +19 -0
- data/app/models/oembed_receiver.rb +15 -0
- data/app/models/role.rb +42 -12
- data/app/models/simple_image.rb +30 -3
- data/app/models/simple_image_tag.rb +1 -16
- data/app/models/token.rb +6 -2
- data/app/models/uploaded_file.rb +62 -0
- data/app/models/uploaded_file_tag.rb +15 -0
- data/app/models/uploaded_file_tag_file.rb +13 -0
- data/app/models/user.rb +35 -10
- data/app/models/user_role.rb +0 -1
- data/app/uploaders/simple_file_uploader.rb +2 -6
- data/app/uploaders/simple_image_uploader.rb +10 -21
- data/app/uploaders/uploaders/path_slug.rb +22 -0
- data/app/views/admin/agents/index.html.erb +1 -1
- data/app/views/admin/biovision_components/_nav_item.html.erb +6 -0
- data/app/views/admin/biovision_components/entity/_in_list.html.erb +12 -0
- data/app/views/admin/biovision_components/index.html.erb +11 -0
- data/app/views/admin/components/_list.html.erb +1 -1
- data/app/views/admin/components/entity/_links.html.erb +31 -21
- data/app/views/admin/components/links/_base.html.erb +1 -0
- data/app/views/admin/components/settings/_settings.html.erb +3 -3
- data/app/views/admin/components/settings.html.erb +2 -1
- data/app/views/admin/dynamic_blocks/_form.html.erb +1 -1
- data/app/views/admin/dynamic_blocks/entity/_in_list.html.erb +8 -6
- data/app/views/admin/dynamic_blocks/index.html.erb +6 -4
- data/app/views/admin/dynamic_blocks/show.html.erb +9 -7
- data/app/views/admin/dynamic_pages/_dynamic_page.jbuilder +18 -0
- data/app/views/admin/dynamic_pages/entity/_in_list.html.erb +6 -4
- data/app/views/admin/dynamic_pages/entity/_in_search.html.erb +7 -0
- data/app/views/admin/dynamic_pages/index.html.erb +6 -4
- data/app/views/admin/dynamic_pages/search.jbuilder +4 -0
- data/app/views/admin/dynamic_pages/show.html.erb +2 -2
- data/app/views/admin/index/index.html.erb +7 -5
- data/app/views/admin/ip_addresses/index.html.erb +2 -2
- data/app/views/admin/navigation_group_pages/entity/_in_list.html.erb +26 -0
- data/app/views/admin/navigation_groups/entity/_dynamic_pages.html.erb +38 -0
- data/app/views/admin/navigation_groups/entity/_in_list.html.erb +7 -5
- data/app/views/admin/navigation_groups/index.html.erb +6 -4
- data/app/views/admin/navigation_groups/show.html.erb +16 -3
- data/app/views/admin/tokens/_form.html.erb +31 -0
- data/app/views/admin/tokens/_nav_item.html.erb +6 -0
- data/app/views/admin/tokens/entity/_in_list.html.erb +27 -0
- data/app/views/admin/tokens/index.html.erb +11 -0
- data/app/views/admin/tokens/show.html.erb +26 -0
- data/app/views/admin/users/_user.jbuilder +18 -0
- data/app/views/admin/users/entity/_fields.html.erb +1 -1
- data/app/views/admin/users/entity/_in_list.html.erb +3 -3
- data/app/views/admin/users/entity/_in_search.html.erb +18 -0
- data/app/views/admin/users/index.html.erb +13 -4
- data/app/views/admin/users/roles/_component.html.erb +22 -0
- data/app/views/admin/users/roles.html.erb +23 -0
- data/app/views/admin/users/search.jbuilder +4 -0
- data/app/views/admin/users/show.html.erb +28 -10
- data/app/views/admin/widgets/_filters.html.erb +20 -0
- data/app/views/admin/widgets/_quick_search.html.erb +13 -0
- data/app/views/admin/widgets/filters/_flag.html.erb +15 -0
- data/app/views/admin/widgets/filters/_text.html.erb +7 -0
- data/app/views/application/unauthorized.html.erb +4 -1
- data/app/views/components/content/_dynamic_page.html.erb +6 -10
- data/app/views/components/content/_dynamic_page_content.html.erb +14 -0
- data/app/views/components/users/_login_form.html.erb +1 -0
- data/app/views/contact/_form.html.erb +1 -1
- data/app/views/errors/error.html.erb +1 -0
- data/app/views/feedback_mailer/new_feedback_request.html.erb +11 -0
- data/app/views/feedback_mailer/new_feedback_request.text.erb +6 -0
- data/app/views/index/index.html.erb +14 -0
- data/app/views/layouts/admin/_header.html.erb +7 -2
- data/app/views/layouts/admin.html.erb +0 -1
- data/app/views/layouts/application/_footer.html.erb +1 -1
- data/app/views/layouts/application/header/_authentication.html.erb +4 -1
- data/app/views/my/components/index.html.erb +25 -0
- data/app/views/my/components/show.html.erb +21 -0
- data/app/views/my/index/_cards.html.erb +15 -0
- data/app/views/my/index/_email.html.erb +14 -0
- data/app/views/my/index/_navigation.html.erb +33 -0
- data/app/views/my/index/index.html.erb +7 -26
- data/app/views/my/profiles/show.html.erb +13 -0
- data/app/views/{admin/components/links/extra/_content.html.erb → my/recoveries/show.html.erb} +0 -0
- data/app/views/shared/admin/_list.html.erb +10 -19
- data/app/views/shared/admin/_list_with_priority.html.erb +10 -19
- data/app/views/shared/admin/_priority.html.erb +6 -5
- data/app/views/shared/admin/_toggle.html.erb +5 -10
- data/app/views/shared/entity/_date_field.html.erb +6 -0
- data/app/views/shared/entity/_linked_entity.html.erb +2 -2
- data/app/views/shared/entity/_list.html.erb +22 -0
- data/app/views/shared/entity/_list_with_priority.html.erb +22 -0
- data/app/views/shared/entity/_parent.html.erb +1 -1
- data/app/views/shared/entity/_priority_icons.html.erb +8 -0
- data/app/views/shared/entity/_time_field.html.erb +6 -0
- data/app/views/shared/entity/_toggle.html.erb +12 -0
- data/app/views/shared/entity/_track.html.erb +12 -0
- data/app/views/shared/entity/_tree_caches.html.erb +8 -1
- data/app/views/shared/entity/edit.html.erb +10 -6
- data/app/views/shared/entity/new.html.erb +4 -2
- data/app/views/shared/forms/_field.html.erb +6 -2
- data/app/views/shared/forms/_field_with_search.html.erb +17 -0
- data/app/views/shared/forms/_meta_texts.html.erb +1 -1
- data/app/views/shared/forms/_simple_entity_link.html.erb +14 -0
- data/app/views/shared/forms/_simple_image.html.erb +12 -4
- data/app/views/shared/forms/_text_area.html.erb +1 -1
- data/app/views/shared/forms/_text_field.html.erb +1 -1
- data/app/views/shared/my/_list.html.erb +10 -19
- data/app/views/shared/my/_list_with_priority.html.erb +10 -19
- data/app/views/shared/my/entity/edit.html.erb +25 -0
- data/app/views/shared/my/entity/new.html.erb +18 -0
- data/app/views/simple_images/_simple_image.jbuilder +13 -0
- data/config/locales/biovision-ru.yml +18 -1
- data/config/locales/components-ru.yml +27 -4
- data/config/locales/contact-ru.yml +4 -0
- data/config/locales/content-ru.yml +12 -0
- data/config/locales/users-ru.yml +31 -6
- data/config/routes.rb +35 -4
- data/db/migrate/20191228000000_create_biovision_components.rb +2 -0
- data/db/migrate/20200224000000_create_track_component.rb +8 -12
- data/db/migrate/20200224000010_create_users_component.rb +8 -49
- data/db/migrate/20200404000000_create_simple_images.rb +1 -0
- data/db/migrate/20210405000000_create_acl.rb +15 -1
- data/db/migrate/{20200529000000_create_content_component.rb → 20210421000000_create_content_component.rb} +24 -18
- data/db/migrate/{20210401000000_create_contact_component.rb → 20210421000010_create_contact_component.rb} +1 -22
- data/db/migrate/20210616000000_create_uploaded_files.rb +52 -0
- data/db/migrate/amends/20210816060606_create_oembed_receivers.rb +21 -0
- data/db/migrate/amends/20210907070707_add_checksum_to_simple_images.rb +13 -0
- data/lib/biovision/base_methods.rb +8 -28
- data/lib/biovision/version.rb +1 -1
- data/lib/tasks/components.rake +51 -0
- metadata +90 -17
- data/app/lib/biovision/components/base/privilege_handler.rb +0 -79
- data/app/models/biovision_component_user.rb +0 -21
- data/app/views/admin/components/links/_content.html.erb +0 -9
- data/app/views/admin/components/links/_track.html.erb +0 -2
- data/app/views/admin/components/links/_users.html.erb +0 -4
- data/app/views/admin/components/privileges/_component_user.html.erb +0 -17
- data/app/views/admin/components/privileges/_links.html.erb +0 -17
- data/app/views/admin/components/privileges/_users.html.erb +0 -23
- data/app/views/admin/components/privileges.html.erb +0 -20
@@ -5,22 +5,16 @@ module Biovision
|
|
5
5
|
module Base
|
6
6
|
# Handling component privileges
|
7
7
|
module ComponentPrivileges
|
8
|
-
# @param [String|Array] privileges
|
9
|
-
# @deprecated use #role? or #permit?
|
10
|
-
def allow?(*privileges)
|
11
|
-
permit?(*privileges)
|
12
|
-
end
|
13
|
-
|
14
8
|
# @param [String] action
|
15
9
|
# @param [Object] context
|
16
10
|
def permit?(action = 'default', context = nil)
|
17
11
|
return false if user.nil?
|
18
12
|
|
19
|
-
parts = []
|
13
|
+
parts = [slug]
|
20
14
|
model = model_from_context(context)
|
21
15
|
parts << model.table_name if model.respond_to?(:table_name)
|
22
16
|
parts << action
|
23
|
-
owner?(context) || role?(parts.join('.'))
|
17
|
+
owner?(context) || role?(parts.join('.')) || role?("#{slug}.all")
|
24
18
|
end
|
25
19
|
|
26
20
|
# @param [ApplicationRecord|nil] entity
|
@@ -33,12 +27,12 @@ module Biovision
|
|
33
27
|
# @param [String] role_name
|
34
28
|
def role?(role_name)
|
35
29
|
return false if user.nil?
|
36
|
-
return true if user.super_user?
|
30
|
+
return true if user.super_user?
|
37
31
|
|
38
32
|
role = Role[role_name]
|
39
33
|
return false if role.nil?
|
40
34
|
|
41
|
-
|
35
|
+
user.role_ids.include?(role.id)
|
42
36
|
end
|
43
37
|
|
44
38
|
# @param [Class|Object] context
|
@@ -47,18 +41,34 @@ module Biovision
|
|
47
41
|
context.is_a?(Class) ? context : context.class
|
48
42
|
end
|
49
43
|
|
50
|
-
def
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
44
|
+
def crud_table_names
|
45
|
+
tables = administrative_parts
|
46
|
+
tables << 'simple_images' if use_images?
|
47
|
+
tables << 'uploaded_files' if use_files?
|
48
|
+
tables
|
49
|
+
end
|
50
|
+
|
51
|
+
def role_tree
|
52
|
+
tree = { nil => %w[all default view] }
|
53
|
+
tree['settings'] = %w[view edit] if use_settings?
|
54
|
+
crud_table_names.each do |table_name|
|
55
|
+
tree[table_name] = %w[view edit]
|
56
56
|
end
|
57
|
+
tree
|
58
|
+
end
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
+
def create_roles
|
61
|
+
role_tree.each do |prefix, postfixes|
|
62
|
+
postfixes.each do |postfix|
|
63
|
+
slug = prefix.blank? ? postfix : "#{prefix}.#{postfix}"
|
64
|
+
Role.create(biovision_component: component, slug: slug)
|
65
|
+
end
|
60
66
|
end
|
61
67
|
end
|
68
|
+
|
69
|
+
def administrative_parts
|
70
|
+
self.class.dependent_models.map(&:table_name)
|
71
|
+
end
|
62
72
|
end
|
63
73
|
end
|
64
74
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
module Base
|
6
|
+
# Methods for handling component stories
|
7
|
+
module ComponentStories
|
8
|
+
# @param [String] story_slug
|
9
|
+
def story_class(story_slug)
|
10
|
+
namespace = "biovision/components/#{self.class.slug}"
|
11
|
+
handler_name = "#{namespace}/stories/#{story_slug}_story".classify
|
12
|
+
handler_name.safe_constantize || Biovision::Stories::ComponentStory
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param [String] story_slug
|
16
|
+
# @param [ApplicationRecord|nil] entity
|
17
|
+
def story(story_slug, entity = nil)
|
18
|
+
story_class(story_slug).new(self, entity)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param [String] story_slug
|
22
|
+
# @param [Hash] story_parameters
|
23
|
+
# @param [ApplicationRecord|String|nli] entity
|
24
|
+
def perform_story(story_slug, story_parameters, entity = nil)
|
25
|
+
story(story_slug, entity).perform(story_parameters)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
module Base
|
6
|
+
# Links for entities in context of current user
|
7
|
+
module EntityLinks
|
8
|
+
# @param [ApplicationRecord] entity
|
9
|
+
def text_for_link(entity)
|
10
|
+
entity.respond_to?(:text_for_link) ? entity.text_for_link : entity.id
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param [ApplicationRecord] entity
|
14
|
+
# @param [Symbol|String] scope
|
15
|
+
def entity_link(entity, scope = '')
|
16
|
+
prefix = %i[admin my].include?(scope.to_sym) ? scope : 'world'
|
17
|
+
message = "#{prefix}_url".to_sym
|
18
|
+
if entity.respond_to?(message)
|
19
|
+
entity.send(message)
|
20
|
+
else
|
21
|
+
rest_entity_link(entity, scope.to_sym)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param [ApplicationRecord] entity
|
26
|
+
# @param [Symbol] scope
|
27
|
+
def rest_entity_link(entity, scope)
|
28
|
+
collection = "/#{scope}/#{entity.class.table_name}".gsub('//', '/')
|
29
|
+
if entity.attributes.key?('uuid') && scope != :admin
|
30
|
+
"#{collection}/#{entity.uuid}"
|
31
|
+
else
|
32
|
+
"#{collection}/#{entity.id}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
module Base
|
6
|
+
# Handling simple images
|
7
|
+
module ImageHandling
|
8
|
+
def use_images?
|
9
|
+
false
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param [Hash] parameters
|
13
|
+
def upload_image(parameters)
|
14
|
+
return if parameters[:image].blank?
|
15
|
+
|
16
|
+
checksum = Digest::SHA256.file(parameters[:image].path).hexdigest
|
17
|
+
SimpleImage[checksum] || create_image(parameters, checksum)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# @param [Hash] parameters
|
23
|
+
# @param [String] checksum
|
24
|
+
def create_image(parameters, checksum)
|
25
|
+
image = component.simple_images.new(parameters)
|
26
|
+
image.data[SimpleImage::ORIGINAL_CHECKSUM] = checksum
|
27
|
+
image.save
|
28
|
+
image
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -7,8 +7,11 @@ module Biovision
|
|
7
7
|
extend Base::ComponentSettings
|
8
8
|
include Base::ComponentPrivileges
|
9
9
|
include Base::ComponentParameters
|
10
|
+
include Base::EntityLinks
|
11
|
+
include Base::ImageHandling
|
10
12
|
|
11
|
-
attr_reader :component, :slug, :name
|
13
|
+
attr_reader :component, :slug, :name
|
14
|
+
attr_accessor :user
|
12
15
|
|
13
16
|
# @param [BiovisionComponent] component
|
14
17
|
# @param [User|nil] user
|
@@ -16,8 +19,7 @@ module Biovision
|
|
16
19
|
@component = component
|
17
20
|
@slug = component&.slug || 'base'
|
18
21
|
self.user = user
|
19
|
-
|
20
|
-
@name = I18n.t("biovision.components.#{@slug}.name", default: @slug)
|
22
|
+
@name = I18n.t("biovision.components.#{slug}.name", default: slug)
|
21
23
|
end
|
22
24
|
|
23
25
|
# Receive component-specific handler by component slug
|
@@ -53,27 +55,13 @@ module Biovision
|
|
53
55
|
handler_name.safe_constantize || BaseComponent
|
54
56
|
end
|
55
57
|
|
56
|
-
# Privilege names for using in biovision_component_user.data
|
57
|
-
# @deprecated use roles instead
|
58
|
-
def self.privilege_names
|
59
|
-
[]
|
60
|
-
end
|
61
|
-
|
62
58
|
# Model list for automatic role creation
|
63
59
|
def self.dependent_models
|
64
60
|
[]
|
65
61
|
end
|
66
62
|
|
67
|
-
|
68
|
-
|
69
|
-
return false if user.nil? || user.banned?
|
70
|
-
return true if user.super_user?
|
71
|
-
|
72
|
-
BiovisionComponentUser.owned_by(user).each do |link|
|
73
|
-
return true if link.administrator? || !link.data['privileges'].blank?
|
74
|
-
end
|
75
|
-
|
76
|
-
false
|
63
|
+
def self.create
|
64
|
+
BiovisionComponent.create(slug: slug, settings: default_settings)
|
77
65
|
end
|
78
66
|
|
79
67
|
# @param [ApplicationRecord] entity
|
@@ -89,35 +77,10 @@ module Biovision
|
|
89
77
|
}.merge(options)
|
90
78
|
end
|
91
79
|
|
92
|
-
# @param [User] user
|
93
|
-
def user=(user)
|
94
|
-
@user = user
|
95
|
-
|
96
|
-
criteria = { biovision_component: @component, user: user }
|
97
|
-
|
98
|
-
@user_link = BiovisionComponentUser.find_by(criteria)
|
99
|
-
end
|
100
|
-
|
101
|
-
def user_link!(force_create = false)
|
102
|
-
if @user_link.nil?
|
103
|
-
criteria = { biovision_component: @component, user: user }
|
104
|
-
@user_link = BiovisionComponentUser.new(criteria)
|
105
|
-
@user_link.save if force_create
|
106
|
-
end
|
107
|
-
|
108
|
-
@user_link
|
109
|
-
end
|
110
|
-
|
111
80
|
def use_settings?
|
112
81
|
use_parameters? || @component.settings.any?
|
113
82
|
end
|
114
83
|
|
115
|
-
def administrator?
|
116
|
-
return false if user.nil?
|
117
|
-
|
118
|
-
user.super_user? || @user_link&.administrator?
|
119
|
-
end
|
120
|
-
|
121
84
|
# @param [Hash] data
|
122
85
|
def settings=(data)
|
123
86
|
@component.settings.merge!(self.class.normalize_settings(data))
|
@@ -131,7 +94,7 @@ module Biovision
|
|
131
94
|
# @param [String] name
|
132
95
|
# @param [Integer] quantity
|
133
96
|
def register_metric(name, quantity = 1)
|
134
|
-
metric = Metric
|
97
|
+
metric = Metric[name]
|
135
98
|
if metric.nil?
|
136
99
|
attributes = {
|
137
100
|
biovision_component: @component,
|
@@ -144,10 +107,6 @@ module Biovision
|
|
144
107
|
metric << quantity
|
145
108
|
end
|
146
109
|
|
147
|
-
def privilege_handler
|
148
|
-
@privilege_handler ||= Base::PrivilegeHandler.new(self)
|
149
|
-
end
|
150
|
-
|
151
110
|
# @param [User] user
|
152
111
|
# @param [String] code_type
|
153
112
|
# @param [Integer] quantity
|
@@ -169,6 +128,18 @@ module Biovision
|
|
169
128
|
data[key.to_s] = new_value
|
170
129
|
user.new_component_data(data)
|
171
130
|
end
|
131
|
+
|
132
|
+
# @param [ApplicationRecord] entity
|
133
|
+
# @param [Hash] new_attributes
|
134
|
+
def update_entity(entity, new_attributes)
|
135
|
+
entity.update(new_attributes)
|
136
|
+
end
|
137
|
+
|
138
|
+
# @param [Class] model_class
|
139
|
+
# @param [Hash] parameters
|
140
|
+
def new_entity(model_class, parameters)
|
141
|
+
model_class.new(parameters)
|
142
|
+
end
|
172
143
|
end
|
173
144
|
end
|
174
145
|
end
|
@@ -10,8 +10,12 @@ module Biovision
|
|
10
10
|
[SETTING_FEEDBACK_MAIL]
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.default_settings
|
14
|
+
{ SETTING_FEEDBACK_MAIL => '' }
|
15
|
+
end
|
16
|
+
|
13
17
|
def self.dependent_models
|
14
|
-
[
|
18
|
+
[FeedbackMessage, FeedbackResponse, ContactType, ContactMethod]
|
15
19
|
end
|
16
20
|
|
17
21
|
def use_parameters?
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Receiver for OEmbed-wrapped content
|
4
|
+
module Biovision
|
5
|
+
module Components
|
6
|
+
module Content
|
7
|
+
module Oembed
|
8
|
+
# Default receiver for embedded media
|
9
|
+
class Receiver
|
10
|
+
PATTERN = %r{<oembed url="([^"]+)"></oembed>}
|
11
|
+
|
12
|
+
# @param [String] url
|
13
|
+
def initialize(url = '')
|
14
|
+
@url = url
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param [String] url
|
18
|
+
def self.[](url)
|
19
|
+
host = URI.parse(url).host
|
20
|
+
slug = OembedDomain[host]&.receiver_slug
|
21
|
+
receiver_path = "biovision/components/content/oembed/#{slug}_receiver"
|
22
|
+
receiver_class = receiver_path.classify.safe_constantize
|
23
|
+
|
24
|
+
receiver_class.nil? ? new(url) : receiver_class.new(url)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param [String] text
|
28
|
+
def self.convert(text)
|
29
|
+
text.gsub(PATTERN) do |fragment|
|
30
|
+
url = fragment.match(PATTERN)[1].to_s
|
31
|
+
return '' if url.blank?
|
32
|
+
|
33
|
+
receiver = self[url]
|
34
|
+
receiver.code
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.slug
|
39
|
+
to_s.demodulize.to_s.underscore.gsub('_receiver', '')
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.domains
|
43
|
+
%w[]
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.seed
|
47
|
+
receiver_entity = OembedReceiver.find_or_create_by(slug: slug)
|
48
|
+
domains.each do |domain|
|
49
|
+
receiver_entity.oembed_domains.create(name: domain)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def code
|
54
|
+
@link = OembedLink[@url]
|
55
|
+
@link.code || receive_and_update
|
56
|
+
end
|
57
|
+
|
58
|
+
def fallback
|
59
|
+
attributes = %(rel="external nofollow noreferrer" target="_blank")
|
60
|
+
%(<a href="#{@url}" #{attributes}>#{URI.parse(@url).host}</a>)
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def receive_and_update
|
66
|
+
code = receive(code_url)
|
67
|
+
@link.code = code
|
68
|
+
@link.save
|
69
|
+
|
70
|
+
code
|
71
|
+
end
|
72
|
+
|
73
|
+
# @param [String] embed_url
|
74
|
+
def receive(embed_url)
|
75
|
+
response = RestClient.get(embed_url)
|
76
|
+
parse(response.body)
|
77
|
+
rescue RestClient::Exception => e
|
78
|
+
Rails.logger.warn("Cannot receive data for #{embed_url}: #{e}")
|
79
|
+
fallback
|
80
|
+
end
|
81
|
+
|
82
|
+
# @param [String] response
|
83
|
+
def parse(response)
|
84
|
+
json = JSON.parse(response)
|
85
|
+
json['html'] || fallback
|
86
|
+
rescue JSON::ParserError => e
|
87
|
+
Rails.logger.warn("Cannot parse response #{response}: #{e}")
|
88
|
+
fallback
|
89
|
+
end
|
90
|
+
|
91
|
+
def code_url
|
92
|
+
"https://#{@host}/oembed?url=#{CGI.escape(@url)}&format=json"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
module Content
|
6
|
+
module Oembed
|
7
|
+
# OEmbed receiver for Twitter
|
8
|
+
class TwitterReceiver < Receiver
|
9
|
+
def code_url
|
10
|
+
"https://publish.twitter.com/oembed?url=#{CGI.escape(@url)}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.domains
|
14
|
+
%w[twitter.com www.twitter.com]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
module Content
|
6
|
+
module Oembed
|
7
|
+
# OEmbed receiver for vimeo.com
|
8
|
+
class VimeoReceiver < Receiver
|
9
|
+
def code_url
|
10
|
+
"https://vimeo.com/api/oembed.json?url=#{CGI.escape(@url)}&responsive=true"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.domains
|
14
|
+
%w[www.vimeo.com vimeo.com]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
module Content
|
6
|
+
module Oembed
|
7
|
+
# OEmbed receiver for YouTube
|
8
|
+
class YoutubeReceiver < Receiver
|
9
|
+
def code_url
|
10
|
+
"https://www.youtube.com/oembed?url=#{CGI.escape(@url)}&format=json"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.domains
|
14
|
+
%w[www.youtube.com youtube.com youtu.be]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -4,24 +4,61 @@ module Biovision
|
|
4
4
|
module Components
|
5
5
|
# Content
|
6
6
|
class ContentComponent < BaseComponent
|
7
|
-
def self.
|
8
|
-
|
7
|
+
def self.dependent_models
|
8
|
+
[
|
9
|
+
DynamicPage, NavigationGroup, NavigationGroupPage, DynamicBlock,
|
10
|
+
OembedReceiver, OembedDomain, OembedLink
|
11
|
+
]
|
9
12
|
end
|
10
13
|
|
11
|
-
def self.
|
12
|
-
[
|
14
|
+
def self.seed
|
15
|
+
[
|
16
|
+
Biovision::Components::Content::Oembed::VimeoReceiver,
|
17
|
+
Biovision::Components::Content::Oembed::YoutubeReceiver,
|
18
|
+
Biovision::Components::Content::Oembed::TwitterReceiver
|
19
|
+
].each(&:seed)
|
13
20
|
end
|
14
21
|
|
15
22
|
def use_parameters?
|
16
23
|
true
|
17
24
|
end
|
18
25
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
26
|
+
def use_images?
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def crud_table_names
|
31
|
+
super - %w[navigation_group_pages oembed_receivers oembed_domains]
|
32
|
+
end
|
33
|
+
|
34
|
+
def administrative_parts
|
35
|
+
%w[navigation_groups dynamic_blocks dynamic_pages oembed_links]
|
36
|
+
end
|
37
|
+
|
38
|
+
def navigation
|
39
|
+
@navigation ||= prepare_navigation
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def prepare_navigation
|
45
|
+
result = {}
|
46
|
+
NavigationGroup.connection.execute(grouped_links_query).each do |row|
|
47
|
+
result[row['slug']] = [] unless result.key?(row['slug'])
|
48
|
+
result[row['slug']] << { text: row['name'], url: row['url'] }
|
49
|
+
end
|
50
|
+
result
|
51
|
+
end
|
23
52
|
|
24
|
-
|
53
|
+
def grouped_links_query
|
54
|
+
<<~SQL
|
55
|
+
select g.slug, p.name, p.url
|
56
|
+
from "#{NavigationGroupPage.table_name}" gp
|
57
|
+
join "#{NavigationGroup.table_name}" g on gp.navigation_group_id = g.id
|
58
|
+
join "#{DynamicPage.table_name}" p on gp.dynamic_page_id = p.id
|
59
|
+
where p.visible = true
|
60
|
+
order by g.slug asc, gp.priority asc
|
61
|
+
SQL
|
25
62
|
end
|
26
63
|
end
|
27
64
|
end
|
@@ -33,8 +33,8 @@ module Biovision
|
|
33
33
|
|
34
34
|
def self.dependent_models
|
35
35
|
[
|
36
|
-
|
37
|
-
|
36
|
+
User, Token, LoginAttempt, UserLanguage, BiovisionComponentUser, Code,
|
37
|
+
Notification
|
38
38
|
]
|
39
39
|
end
|
40
40
|
|
@@ -51,6 +51,24 @@ module Biovision
|
|
51
51
|
[SETTING_INVITE_COUNT, SETTING_BOUNCE_COUNT, SETTING_BOUNCE_TIMEOUT]
|
52
52
|
end
|
53
53
|
|
54
|
+
def self.default_settings
|
55
|
+
{
|
56
|
+
SETTING_OPEN => true,
|
57
|
+
SETTING_EMAIL_AS_LOGIN => false,
|
58
|
+
SETTING_PHONE_AS_LOGIN => false,
|
59
|
+
SETTING_CONFIRM_EMAIL => false,
|
60
|
+
SETTING_REQUIRE_EMAIL => false,
|
61
|
+
SETTING_USE_PHONE => false,
|
62
|
+
SETTING_REQUIRE_PHONE => false,
|
63
|
+
SETTING_CONFIRM_PHONE => false,
|
64
|
+
SETTING_INVITE_ONLY => false,
|
65
|
+
SETTING_USE_INVITES => false,
|
66
|
+
SETTING_INVITE_COUNT => 5,
|
67
|
+
SETTING_BOUNCE_COUNT => 10,
|
68
|
+
SETTING_BOUNCE_TIMEOUT => 3,
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
54
72
|
# @param [User] user
|
55
73
|
def self.created_user(user)
|
56
74
|
BiovisionComponent.active.pluck(:slug).each do |slug|
|
@@ -105,6 +123,20 @@ module Biovision
|
|
105
123
|
|
106
124
|
user.attributes[attribute_name.to_s]
|
107
125
|
end
|
126
|
+
|
127
|
+
def role_tree
|
128
|
+
result = super
|
129
|
+
result['users'] << 'log_in'
|
130
|
+
result
|
131
|
+
end
|
132
|
+
|
133
|
+
def crud_table_names
|
134
|
+
super - %w[user_languages biovision_component_users]
|
135
|
+
end
|
136
|
+
|
137
|
+
def administrative_parts
|
138
|
+
%w[users tokens login_attempts codes notifications]
|
139
|
+
end
|
108
140
|
end
|
109
141
|
end
|
110
142
|
end
|