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.
- checksums.yaml +4 -4
- data/README.md +60 -18
- data/app/assets/images/biovision/icons/back.svg +19 -0
- data/app/assets/images/biovision/icons/create.svg +19 -0
- data/app/assets/images/biovision/icons/destroy.svg +12 -0
- data/app/assets/images/biovision/icons/dropdown.svg +3 -0
- data/app/assets/images/biovision/icons/edit.svg +22 -0
- data/app/assets/images/biovision/icons/gear.svg +11 -0
- data/app/assets/images/biovision/icons/return.svg +25 -0
- data/app/assets/images/biovision/icons/world.svg +11 -0
- data/app/assets/stylesheets/biovision/admin/components.scss +3 -1
- data/app/assets/stylesheets/biovision/admin/components/users.scss +16 -0
- data/app/assets/stylesheets/biovision/admin/layout.scss +6 -17
- data/app/assets/stylesheets/biovision/biovision.scss +42 -1
- data/app/assets/stylesheets/biovision/components.scss +6 -0
- data/app/assets/stylesheets/biovision/components/breadcrumbs.scss +13 -0
- data/app/assets/stylesheets/biovision/components/buttons.scss +130 -0
- data/app/assets/stylesheets/biovision/components/forms.scss +162 -1
- data/app/assets/stylesheets/biovision/components/lists.scss +6 -7
- data/app/assets/stylesheets/biovision/{biovision → components}/messages.scss +9 -0
- data/app/assets/stylesheets/biovision/components/pagination.scss +34 -0
- data/app/assets/stylesheets/biovision/components/simple_image.scss +112 -0
- data/app/assets/stylesheets/biovision/components/toggleable.scss +71 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components.scss +2 -3
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users.scss +2 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users/form_tabs.scss +101 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users/profile.scss +77 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/layout.scss +2 -16
- data/app/controllers/admin/components_controller.rb +9 -19
- data/app/controllers/admin/dynamic_blocks_controller.rb +15 -0
- data/app/controllers/admin/dynamic_pages_controller.rb +15 -0
- data/app/controllers/admin/navigation_groups_controller.rb +14 -0
- data/app/controllers/admin/users_controller.rb +70 -0
- data/app/controllers/admin_controller.rb +3 -2
- data/app/controllers/authentication_controller.rb +6 -34
- data/app/controllers/concerns/authentication.rb +12 -12
- data/app/controllers/concerns/crud_entities.rb +132 -0
- data/app/controllers/concerns/entity_priority.rb +10 -0
- data/app/controllers/concerns/toggleable_entity.rb +31 -0
- data/app/controllers/contact_controller.rb +49 -0
- data/app/controllers/fallback_controller.rb +12 -0
- data/app/controllers/index_controller.rb +1 -0
- data/app/controllers/legal_controller.rb +14 -0
- data/app/controllers/my/components_controller.rb +5 -0
- data/app/controllers/my/confirmations_controller.rb +44 -0
- data/app/controllers/my/index_controller.rb +8 -0
- data/app/controllers/my/profiles_controller.rb +31 -16
- data/app/controllers/profile_controller.rb +12 -0
- data/app/controllers/users_controller.rb +61 -0
- data/app/helpers/biovision_helper.rb +171 -0
- data/app/helpers/simple_image_helper.rb +125 -0
- data/app/jobs/application_job.rb +7 -0
- data/app/jobs/send_phone_confirmation_job.rb +16 -0
- data/app/lib/biovision/components/base/component_parameters.rb +44 -0
- data/app/lib/biovision/components/base/component_privileges.rb +65 -0
- data/app/lib/biovision/components/base/component_settings.rb +32 -0
- data/app/lib/biovision/components/base/privilege_handler.rb +79 -0
- data/app/lib/biovision/components/base_component.rb +51 -54
- data/app/lib/biovision/components/contact_component.rb +22 -0
- data/app/lib/biovision/components/content_component.rb +28 -0
- data/app/lib/biovision/components/track_component.rb +3 -0
- data/app/lib/biovision/components/users/authentication.rb +15 -7
- data/app/lib/biovision/components/users/codes.rb +104 -0
- data/app/lib/biovision/components/users/flag_helpers.rb +72 -0
- data/app/lib/biovision/components/users/profile_handler.rb +111 -1
- data/app/lib/biovision/components/users/registration_handler.rb +40 -52
- data/app/lib/biovision/components/users/validation.rb +83 -0
- data/app/lib/biovision/components/users_component.rb +82 -19
- data/app/lib/biovision/notifiers/base_notifier.rb +2 -2
- data/app/lib/biovision/notifiers/contact_notifier.rb +15 -0
- data/app/lib/canonizer.rb +38 -0
- data/app/lib/carrier_wave/image_optim.rb +32 -0
- data/app/mailers/code_sender.rb +29 -0
- data/app/models/agent.rb +4 -0
- data/app/models/biovision_component.rb +22 -2
- data/app/models/browser.rb +1 -1
- data/app/models/code.rb +32 -9
- data/app/models/concerns/has_simple_image.rb +9 -0
- data/app/models/concerns/meta_texts.rb +25 -5
- data/app/models/concerns/tree_structure.rb +72 -0
- data/app/models/contact_method.rb +47 -0
- data/app/models/contact_type.rb +27 -0
- data/app/models/dynamic_block.rb +43 -0
- data/app/models/dynamic_page.rb +71 -0
- data/app/models/feedback_message.rb +59 -0
- data/app/models/feedback_response.rb +50 -0
- data/app/models/group.rb +48 -0
- data/app/models/language.rb +4 -0
- data/app/models/navigation_group.rb +33 -0
- data/app/models/navigation_group_page.rb +23 -0
- data/app/models/role.rb +56 -0
- data/app/models/role_group.rb +13 -0
- data/app/models/simple_image.rb +22 -8
- data/app/models/simple_image_tag.rb +1 -1
- data/app/models/token.rb +4 -4
- data/app/models/user.rb +94 -26
- data/app/models/user_group.rb +20 -0
- data/app/models/user_role.rb +19 -0
- data/app/uploaders/simple_file_uploader.rb +27 -0
- data/app/uploaders/simple_image_uploader.rb +20 -0
- data/app/views/admin/agents/index.html.erb +0 -2
- data/app/views/admin/components/_image.jbuilder +18 -0
- data/app/views/admin/components/_list.html.erb +1 -1
- data/app/views/admin/components/entity/_links.html.erb +1 -1
- data/app/views/admin/components/image.jbuilder +1 -0
- data/app/views/admin/components/images.jbuilder +4 -0
- data/app/views/admin/components/links/_content.html.erb +9 -0
- data/app/views/admin/components/links/_users.html.erb +1 -8
- data/app/views/admin/components/links/extra/_content.html.erb +0 -0
- data/app/views/admin/components/privileges/_links.html.erb +0 -18
- data/app/views/admin/components/settings/_new_parameter.html.erb +4 -2
- data/app/views/admin/components/settings/_parameters.html.erb +8 -2
- data/app/views/admin/components/settings/_settings.html.erb +1 -1
- data/app/views/admin/components/update_privileges.jbuilder +21 -0
- data/app/views/admin/dynamic_blocks/_form.html.erb +16 -0
- data/app/views/admin/dynamic_blocks/_nav_item.html.erb +6 -0
- data/app/views/admin/dynamic_blocks/entity/_in_list.html.erb +10 -0
- data/app/views/admin/dynamic_blocks/index.html.erb +15 -0
- data/app/views/admin/dynamic_blocks/show.html.erb +23 -0
- data/app/views/admin/dynamic_pages/_form.html.erb +21 -0
- data/app/views/admin/dynamic_pages/_nav_item.html.erb +6 -0
- data/app/views/admin/dynamic_pages/entity/_in_list.html.erb +15 -0
- data/app/views/admin/dynamic_pages/index.html.erb +15 -0
- data/app/views/admin/dynamic_pages/show.html.erb +28 -0
- data/app/views/admin/ip_addresses/index.html.erb +0 -2
- data/app/views/admin/navigation_groups/_form.html.erb +15 -0
- data/app/views/admin/navigation_groups/_nav_item.html.erb +6 -0
- data/app/views/admin/navigation_groups/entity/_in_list.html.erb +12 -0
- data/app/views/admin/navigation_groups/index.html.erb +15 -0
- data/app/views/admin/navigation_groups/show.html.erb +20 -0
- data/app/views/admin/unauthorized.html.erb +2 -5
- data/app/views/admin/users/_form.html.erb +81 -0
- data/app/views/admin/users/_nav_item.html.erb +6 -0
- data/app/views/admin/users/entity/_fields.html.erb +53 -0
- data/app/views/admin/users/entity/_in_list.html.erb +38 -0
- data/app/views/admin/users/entity/_profile.html.erb +26 -0
- data/app/views/admin/users/entity/in_list/_additional_data.html.erb +0 -0
- data/app/views/admin/users/index.html.erb +15 -0
- data/app/views/admin/users/show.html.erb +44 -0
- data/app/views/application/forbidden.html.erb +9 -0
- data/app/views/application/forbidden.jbuilder +4 -0
- data/app/views/application/not_found.html.erb +9 -0
- data/app/views/application/not_found.jbuilder +4 -0
- data/app/views/application/unauthorized.html.erb +16 -0
- data/app/views/application/unauthorized.jbuilder +4 -0
- data/app/views/authentication/new.html.erb +2 -8
- data/app/views/components/content/_dynamic_page.html.erb +21 -0
- data/app/views/components/users/_form_tabs.html.erb +31 -0
- data/app/views/components/users/_join_form.html.erb +192 -0
- data/app/views/components/users/_login_form.html.erb +45 -0
- data/app/views/components/users/form/_image.html.erb +17 -0
- data/app/views/components/users/form/_profile_data.html.erb +54 -0
- data/app/views/contact/_form.html.erb +108 -0
- data/app/views/contact/create_feedback_message.js.erb +1 -0
- data/app/views/contact/feedback.html.erb +13 -0
- data/app/views/contact/index.html.erb +16 -0
- data/app/views/fallback/show.html.erb +6 -0
- data/app/views/layouts/admin.html.erb +1 -1
- data/app/views/layouts/admin/_footer.html.erb +1 -1
- data/app/views/layouts/application/header/_authentication.html.erb +1 -1
- data/app/views/legal/privacy.html.erb +5 -0
- data/app/views/legal/tos.html.erb +5 -0
- data/app/views/my/confirmations/show.html.erb +62 -0
- data/app/views/my/index/index.html.erb +33 -0
- data/app/views/my/profiles/_form.html.erb +10 -0
- data/app/views/my/profiles/check.jbuilder +4 -0
- data/app/views/my/profiles/edit.html.erb +14 -0
- data/app/views/my/profiles/form/_basic_parameters.html.erb +9 -0
- data/app/views/my/profiles/form/_sensitive_parameters.html.erb +68 -0
- data/app/views/my/profiles/new.html.erb +6 -8
- data/app/views/my/profiles/show.html.erb +23 -0
- data/app/views/shared/_flash_messages.html.erb +1 -1
- data/app/views/shared/_list_of_errors.html.erb +7 -0
- data/app/views/shared/admin/_breadcrumbs.html.erb +8 -0
- data/app/views/shared/admin/_list.html.erb +4 -4
- data/app/views/shared/admin/_list_with_priority.html.erb +4 -4
- data/app/views/shared/admin/_priority.html.erb +5 -0
- data/app/views/shared/admin/_toggle.html.erb +11 -0
- data/app/views/shared/entity/_formatted_text_field.html.erb +10 -0
- data/app/views/shared/entity/_image.html.erb +31 -0
- data/app/views/shared/entity/_language.html.erb +6 -0
- data/app/views/shared/entity/_linked_entity.html.erb +6 -0
- data/app/views/shared/entity/_meta_texts.html.erb +16 -0
- data/app/views/shared/entity/_metadata.html.erb +18 -0
- data/app/views/shared/entity/_parent.html.erb +6 -0
- data/app/views/shared/entity/_priority.html.erb +4 -0
- data/app/views/shared/entity/_raw_text_field.html.erb +10 -0
- data/app/views/shared/entity/_simple_image.html.erb +10 -0
- data/app/views/shared/entity/_slug.html.erb +6 -0
- data/app/views/shared/entity/_text_field.html.erb +6 -0
- data/app/views/shared/entity/_text_fields.html.erb +9 -0
- data/app/views/shared/entity/_timestamps.html.erb +13 -0
- data/app/views/shared/entity/_tree_caches.html.erb +12 -0
- data/app/views/shared/entity/_uuid.html.erb +4 -0
- data/app/views/shared/entity/edit.html.erb +21 -0
- data/app/views/shared/entity/new.html.erb +16 -0
- data/app/views/shared/forms/_entity_flags.html.erb +15 -0
- data/app/views/shared/forms/_field.html.erb +46 -0
- data/app/views/shared/forms/_fields.html.erb +3 -0
- data/app/views/shared/forms/_language.html.erb +40 -0
- data/app/views/shared/forms/_meta_texts.html.erb +27 -0
- data/app/views/shared/forms/_priority.html.erb +13 -0
- data/app/views/shared/forms/_simple_image.html.erb +39 -0
- data/app/views/shared/forms/_state_container.html.erb +7 -0
- data/app/views/shared/forms/_text_area.html.erb +25 -0
- data/app/views/shared/forms/_text_field.html.erb +24 -0
- data/app/views/shared/forms/_text_fields.html.erb +3 -0
- data/app/views/shared/forms/check.jbuilder +4 -0
- data/app/views/shared/forms/errors.jbuilder +3 -0
- data/app/views/shared/forms/simple_image/_browse.html.erb +14 -0
- data/app/views/shared/forms/simple_image/_load_image.html.erb +38 -0
- data/app/views/shared/my/_list.html.erb +19 -0
- data/app/views/shared/my/_list_with_priority.html.erb +19 -0
- data/app/views/users/_profile.html.erb +30 -0
- data/app/views/users/profile/_data.html.erb +20 -0
- data/app/views/users/show.html.erb +21 -0
- data/config/locales/biovision-ru.yml +58 -0
- data/config/locales/components-ru.yml +30 -2
- data/config/locales/contact-ru.yml +106 -0
- data/config/locales/content-ru.yml +103 -0
- data/config/locales/users-ru.yml +117 -3
- data/config/routes.rb +70 -50
- data/db/migrate/20191228000000_create_biovision_components.rb +4 -5
- data/db/migrate/20200224000000_create_track_component.rb +7 -8
- data/db/migrate/20200224000010_create_users_component.rb +15 -43
- data/db/migrate/20200404000000_create_simple_images.rb +3 -3
- data/db/migrate/20200529000000_create_content_component.rb +74 -0
- data/db/migrate/20210401000000_create_contact_component.rb +95 -0
- data/db/migrate/20210405000000_create_acl.rb +74 -0
- data/lib/biovision/base_methods.rb +18 -10
- data/lib/biovision/engine.rb +8 -13
- data/lib/biovision/version.rb +1 -1
- metadata +186 -20
- data/app/assets/images/biovision/placeholders/user.svg +0 -15
- data/app/helpers/users_helper.rb +0 -11
- data/app/lib/biovision/components/component_settings.rb +0 -30
- data/app/lib/biovision/components/privilege_handler.rb +0 -77
- data/app/lib/biovision/components/users/code_handler.rb +0 -23
- data/app/models/foreign_site.rb +0 -34
- data/app/models/foreign_user.rb +0 -21
- data/app/uploaders/user_image_uploader.rb +0 -58
- data/app/views/admin/components/privileges/_privilege_flag.html.erb +0 -28
- data/app/views/authentication/_form.html.erb +0 -40
- data/app/views/authentication/failed.js.erb +0 -3
- data/app/views/my/profiles/new/_form.html.erb +0 -147
- data/app/views/shared/admin/_toggleable.html.erb +0 -8
@@ -0,0 +1,7 @@
|
|
1
|
+
class ApplicationJob < ActiveJob::Base
|
2
|
+
# Automatically retry jobs that encountered a deadlock
|
3
|
+
# retry_on ActiveRecord::Deadlocked
|
4
|
+
|
5
|
+
# Most jobs are safe to ignore if the underlying records are no longer available
|
6
|
+
# discard_on ActiveJob::DeserializationError
|
7
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Send phone confirmation code via SMS gateway
|
4
|
+
class SendPhoneConfirmationJob < ApplicationJob
|
5
|
+
queue_as :default
|
6
|
+
|
7
|
+
# @param [Integer] id
|
8
|
+
def perform(id)
|
9
|
+
code = Code.find_by(id: id)
|
10
|
+
|
11
|
+
return if code.nil?
|
12
|
+
|
13
|
+
# To be implemented: use actual gateway
|
14
|
+
code.user.phone
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
module Base
|
6
|
+
# Getting and setting component parameters
|
7
|
+
module ComponentParameters
|
8
|
+
def use_parameters?
|
9
|
+
false
|
10
|
+
end
|
11
|
+
|
12
|
+
# Receive parameter value with default
|
13
|
+
#
|
14
|
+
# Returns value of component's parameter or default value
|
15
|
+
# when it's not found
|
16
|
+
#
|
17
|
+
# @param [String] key
|
18
|
+
# @param [String] default
|
19
|
+
# @return [String]
|
20
|
+
def receive(key, default = '')
|
21
|
+
@component.get(key, default)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Receive parameter value or nil
|
25
|
+
#
|
26
|
+
# Returns value of component's parameter of nil when it's not found
|
27
|
+
#
|
28
|
+
# @param [String] key
|
29
|
+
# @return [String]
|
30
|
+
def [](key)
|
31
|
+
@component.get(key)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Set parameter
|
35
|
+
#
|
36
|
+
# @param [String] key
|
37
|
+
# @param [String] value
|
38
|
+
def []=(key, value)
|
39
|
+
@component[key] = value unless key.blank?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
module Base
|
6
|
+
# Handling component privileges
|
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
|
+
# @param [String] action
|
15
|
+
# @param [Object] context
|
16
|
+
def permit?(action = 'default', context = nil)
|
17
|
+
return false if user.nil?
|
18
|
+
|
19
|
+
parts = []
|
20
|
+
model = model_from_context(context)
|
21
|
+
parts << model.table_name if model.respond_to?(:table_name)
|
22
|
+
parts << action
|
23
|
+
owner?(context) || role?(parts.join('.'))
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param [ApplicationRecord|nil] entity
|
27
|
+
def owner?(entity)
|
28
|
+
return false unless entity.respond_to?(:owned_by?)
|
29
|
+
|
30
|
+
entity.owned_by?(user)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param [String] role_name
|
34
|
+
def role?(role_name)
|
35
|
+
return false if user.nil?
|
36
|
+
return true if user.super_user? || administrator?
|
37
|
+
|
38
|
+
role = Role[role_name]
|
39
|
+
return false if role.nil?
|
40
|
+
|
41
|
+
Array(user.data['role_cache']).include?(role.id)
|
42
|
+
end
|
43
|
+
|
44
|
+
# @param [Class|Object] context
|
45
|
+
# @return Class
|
46
|
+
def model_from_context(context)
|
47
|
+
context.is_a?(Class) ? context : context.class
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_roles
|
51
|
+
slugs = %w[view edit]
|
52
|
+
model_roles = %w[list view create edit destroy]
|
53
|
+
model_roles.each { |role| slugs << "simple_images.#{role}" }
|
54
|
+
self.class.dependent_models.each do |model|
|
55
|
+
model_roles.each { |role| slugs << "#{model.table_name}.#{role}" }
|
56
|
+
end
|
57
|
+
|
58
|
+
slugs.each do |slug|
|
59
|
+
Role.create(biovision_component: component, slug: slug)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
module Base
|
6
|
+
# Normalizing component settings
|
7
|
+
module ComponentSettings
|
8
|
+
def settings_flags
|
9
|
+
[]
|
10
|
+
end
|
11
|
+
|
12
|
+
def settings_numbers
|
13
|
+
[]
|
14
|
+
end
|
15
|
+
|
16
|
+
def settings_strings
|
17
|
+
[]
|
18
|
+
end
|
19
|
+
|
20
|
+
# @param [Hash] data
|
21
|
+
def normalize_settings(data)
|
22
|
+
result = {}
|
23
|
+
settings_flags.each { |f| result[f] = data[f].to_i == 1 }
|
24
|
+
settings_numbers.each { |n| result[n] = data[n].to_i }
|
25
|
+
settings_strings.each { |s| result[s] = data[s].to_s }
|
26
|
+
|
27
|
+
result
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
module Base
|
6
|
+
# Handling user privileges in component
|
7
|
+
class PrivilegeHandler
|
8
|
+
attr_accessor :component
|
9
|
+
|
10
|
+
# @param [BaseComponent] component
|
11
|
+
def initialize(component)
|
12
|
+
@component = component
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param [String|Symbol]
|
16
|
+
def privilege?(slug)
|
17
|
+
return false if @component.user_link.nil?
|
18
|
+
|
19
|
+
privileges = Array(@component.user_link.data['privileges'])
|
20
|
+
privileges.include?(slug)
|
21
|
+
end
|
22
|
+
|
23
|
+
def administrator!
|
24
|
+
return if @component.user.nil?
|
25
|
+
|
26
|
+
link = @component.user_link!
|
27
|
+
link.administrator = true
|
28
|
+
link.save
|
29
|
+
end
|
30
|
+
|
31
|
+
def not_administrator!
|
32
|
+
return if @component.user.nil? || @component.user_link.nil?
|
33
|
+
|
34
|
+
@component.user_link.update(administrator: false)
|
35
|
+
end
|
36
|
+
|
37
|
+
# @param [Array] new_privileges
|
38
|
+
def privileges=(new_privileges)
|
39
|
+
return if @component.user.nil?
|
40
|
+
|
41
|
+
link = @component.user_link!
|
42
|
+
link.data['privileges'] = Array(new_privileges).uniq
|
43
|
+
link.save
|
44
|
+
end
|
45
|
+
|
46
|
+
# @param [Hash] new_settings
|
47
|
+
def settings=(new_settings)
|
48
|
+
return if @component.user.nil?
|
49
|
+
|
50
|
+
link = @component.user_link!
|
51
|
+
link.data['settings'] = new_settings
|
52
|
+
link.save
|
53
|
+
end
|
54
|
+
|
55
|
+
# @param [String] slug
|
56
|
+
def add_privilege(slug)
|
57
|
+
return if @component.user.nil?
|
58
|
+
|
59
|
+
link = @component.user_link!
|
60
|
+
link.data['privileges'] ||= []
|
61
|
+
link.data['privileges'] += [slug.to_s]
|
62
|
+
link.data['privileges'].uniq!
|
63
|
+
link.save
|
64
|
+
end
|
65
|
+
|
66
|
+
# @param [String] slug
|
67
|
+
def remove_privilege(slug)
|
68
|
+
link = @component.user_link
|
69
|
+
|
70
|
+
return if link.nil?
|
71
|
+
|
72
|
+
link.data['privileges'] ||= []
|
73
|
+
link.data['privileges'] -= [slug.to_s]
|
74
|
+
link.save
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -4,12 +4,14 @@ module Biovision
|
|
4
4
|
module Components
|
5
5
|
# Base biovision component
|
6
6
|
class BaseComponent
|
7
|
-
extend ComponentSettings
|
7
|
+
extend Base::ComponentSettings
|
8
|
+
include Base::ComponentPrivileges
|
9
|
+
include Base::ComponentParameters
|
8
10
|
|
9
11
|
attr_reader :component, :slug, :name, :user, :user_link
|
10
12
|
|
11
13
|
# @param [BiovisionComponent] component
|
12
|
-
# @param [User] user
|
14
|
+
# @param [User|nil] user
|
13
15
|
def initialize(component, user = nil)
|
14
16
|
@component = component
|
15
17
|
@slug = component&.slug || 'base'
|
@@ -29,7 +31,11 @@ module Biovision
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def self.slug
|
32
|
-
to_s.demodulize.underscore.gsub('_component', '')
|
34
|
+
to_s.demodulize.to_s.underscore.gsub('_component', '')
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.active?
|
38
|
+
BiovisionComponent[slug]&.active?
|
33
39
|
end
|
34
40
|
|
35
41
|
# Receive component-specific handler by class name for component.
|
@@ -48,10 +54,16 @@ module Biovision
|
|
48
54
|
end
|
49
55
|
|
50
56
|
# Privilege names for using in biovision_component_user.data
|
57
|
+
# @deprecated use roles instead
|
51
58
|
def self.privilege_names
|
52
59
|
[]
|
53
60
|
end
|
54
61
|
|
62
|
+
# Model list for automatic role creation
|
63
|
+
def self.dependent_models
|
64
|
+
[]
|
65
|
+
end
|
66
|
+
|
55
67
|
# @param [User] user
|
56
68
|
def self.privileged?(user)
|
57
69
|
return false if user.nil? || user.banned?
|
@@ -64,6 +76,19 @@ module Biovision
|
|
64
76
|
false
|
65
77
|
end
|
66
78
|
|
79
|
+
# @param [ApplicationRecord] entity
|
80
|
+
# @param [Symbol|nil] scope
|
81
|
+
# @param [Hash] options
|
82
|
+
def self.form_options(entity, scope = :admin, options = {})
|
83
|
+
table_name = entity.class.table_name
|
84
|
+
prefix = scope.nil? ? '' : "/#{scope}"
|
85
|
+
{
|
86
|
+
model: scope.nil? ? entity : [scope, entity],
|
87
|
+
id: "#{entity.class.to_s.underscore}-form",
|
88
|
+
data: { check_url: "#{prefix}/#{table_name}/check" }
|
89
|
+
}.merge(options)
|
90
|
+
end
|
91
|
+
|
67
92
|
# @param [User] user
|
68
93
|
def user=(user)
|
69
94
|
@user = user
|
@@ -83,10 +108,6 @@ module Biovision
|
|
83
108
|
@user_link
|
84
109
|
end
|
85
110
|
|
86
|
-
def use_parameters?
|
87
|
-
false
|
88
|
-
end
|
89
|
-
|
90
111
|
def use_settings?
|
91
112
|
use_parameters? || @component.settings.any?
|
92
113
|
end
|
@@ -97,22 +118,6 @@ module Biovision
|
|
97
118
|
user.super_user? || @user_link&.administrator?
|
98
119
|
end
|
99
120
|
|
100
|
-
# @param [String|Array] privileges
|
101
|
-
def allow?(*privileges)
|
102
|
-
return false if user.nil?
|
103
|
-
return true if administrator? || (component.nil? && privileges.blank?)
|
104
|
-
return false if @user_link.nil?
|
105
|
-
|
106
|
-
result = privileges.blank?
|
107
|
-
privileges.flatten.each { |slug| result |= privilege?(slug) }
|
108
|
-
result
|
109
|
-
end
|
110
|
-
|
111
|
-
# @param [String] privilege_name
|
112
|
-
def privilege?(privilege_name)
|
113
|
-
privilege_handler.privilege?(privilege_name)
|
114
|
-
end
|
115
|
-
|
116
121
|
# @param [Hash] data
|
117
122
|
def settings=(data)
|
118
123
|
@component.settings.merge!(self.class.normalize_settings(data))
|
@@ -123,36 +128,6 @@ module Biovision
|
|
123
128
|
@component.settings
|
124
129
|
end
|
125
130
|
|
126
|
-
# Receive parameter value with default
|
127
|
-
#
|
128
|
-
# Returns value of component's parameter or default value
|
129
|
-
# when it's not found
|
130
|
-
#
|
131
|
-
# @param [String] key
|
132
|
-
# @param [String] default
|
133
|
-
# @return [String]
|
134
|
-
def receive(key, default = '')
|
135
|
-
@component.get(key, default)
|
136
|
-
end
|
137
|
-
|
138
|
-
# Receive parameter value or nil
|
139
|
-
#
|
140
|
-
# Returns value of component's parameter of nil when it's not found
|
141
|
-
#
|
142
|
-
# @param [String] key
|
143
|
-
# @return [String]
|
144
|
-
def [](key)
|
145
|
-
@component.get(key)
|
146
|
-
end
|
147
|
-
|
148
|
-
# Set parameter
|
149
|
-
#
|
150
|
-
# @param [String] key
|
151
|
-
# @param [String] value
|
152
|
-
def []=(key, value)
|
153
|
-
@component[key] = value unless key.blank?
|
154
|
-
end
|
155
|
-
|
156
131
|
# @param [String] name
|
157
132
|
# @param [Integer] quantity
|
158
133
|
def register_metric(name, quantity = 1)
|
@@ -170,7 +145,29 @@ module Biovision
|
|
170
145
|
end
|
171
146
|
|
172
147
|
def privilege_handler
|
173
|
-
@privilege_handler ||= PrivilegeHandler.new(self)
|
148
|
+
@privilege_handler ||= Base::PrivilegeHandler.new(self)
|
149
|
+
end
|
150
|
+
|
151
|
+
# @param [User] user
|
152
|
+
# @param [String] code_type
|
153
|
+
# @param [Integer] quantity
|
154
|
+
def find_or_create_code(user, code_type, quantity = 1)
|
155
|
+
@component.find_or_create_code(user, code_type, quantity)
|
156
|
+
end
|
157
|
+
|
158
|
+
# @param [String|Symbol] key
|
159
|
+
# @param default_value
|
160
|
+
def data_value(key, default_value = '')
|
161
|
+
data = user.component_data(slug)
|
162
|
+
data.key?(key.to_s) ? data[key.to_s] : default_value
|
163
|
+
end
|
164
|
+
|
165
|
+
# @param [String|Symbol] key
|
166
|
+
# @param new_value
|
167
|
+
def update_data_value(key, new_value)
|
168
|
+
data = user.component_data(slug)
|
169
|
+
data[key.to_s] = new_value
|
170
|
+
user.new_component_data(data)
|
174
171
|
end
|
175
172
|
end
|
176
173
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
# Contact and feedback
|
6
|
+
class ContactComponent < BaseComponent
|
7
|
+
SETTING_FEEDBACK_MAIL = 'feedback_email'
|
8
|
+
|
9
|
+
def self.settings_strings
|
10
|
+
[SETTING_FEEDBACK_MAIL]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.dependent_models
|
14
|
+
[ContactMethod, ContactType, FeedbackResponse, FeedbackMessage]
|
15
|
+
end
|
16
|
+
|
17
|
+
def use_parameters?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
# Content
|
6
|
+
class ContentComponent < BaseComponent
|
7
|
+
def self.privilege_names
|
8
|
+
%w[content_manager]
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.dependent_models
|
12
|
+
[DynamicBlock, NavigationGroupPage, NavigationGroup, DynamicPage]
|
13
|
+
end
|
14
|
+
|
15
|
+
def use_parameters?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param [ApplicationRecord] entity
|
20
|
+
# @deprecated use #permit?
|
21
|
+
def editable?(entity)
|
22
|
+
return false if entity.nil?
|
23
|
+
|
24
|
+
permit?('edit', entity)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|