biovision 0.4.210512.0 → 0.12.211124.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 +7 -5
- data/app/assets/stylesheets/biovision/admin/layout.scss +34 -0
- data/app/assets/stylesheets/biovision/biovision.scss +56 -26
- data/app/assets/stylesheets/biovision/components/filters.scss +0 -2
- data/app/assets/stylesheets/biovision/components/forms.scss +40 -10
- data/app/assets/stylesheets/biovision/themes/default_theme/layout/header.scss +10 -0
- data/app/controllers/admin/biovision_components_controller.rb +10 -0
- data/app/controllers/admin/components_controller.rb +9 -5
- data/app/controllers/admin/users_controller.rb +2 -1
- data/app/controllers/admin_controller.rb +2 -22
- data/app/controllers/concerns/component_stories.rb +22 -0
- data/app/controllers/concerns/crud_entities.rb +12 -4
- 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/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_helper.rb +16 -1
- 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 +6 -3
- data/app/lib/biovision/components/base/component_privileges.rb +4 -3
- data/app/lib/biovision/components/base/component_stories.rb +30 -0
- data/app/lib/biovision/components/base/entity_links.rb +16 -2
- data/app/lib/biovision/components/base/image_handling.rb +33 -0
- data/app/lib/biovision/components/base_component.rb +6 -27
- 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 +14 -3
- data/app/lib/biovision/components/users_component.rb +6 -0
- data/app/lib/biovision/helpers/data_helper.rb +31 -4
- data/app/lib/biovision/helpers/export_helper.rb +97 -0
- data/app/lib/biovision/migrations/component_migration.rb +3 -1
- data/app/lib/biovision/stories/component_story.rb +55 -0
- data/app/models/biovision_component.rb +14 -1
- data/app/models/code.rb +3 -3
- 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 +2 -0
- data/app/models/metric.rb +4 -0
- 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 +4 -12
- data/app/models/simple_image.rb +29 -2
- data/app/models/simple_image_tag.rb +1 -16
- 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 +10 -0
- data/app/models/user_role.rb +0 -1
- data/app/uploaders/simple_file_uploader.rb +2 -6
- data/app/uploaders/simple_image_uploader.rb +3 -20
- 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/links/_base.html.erb +1 -1
- data/app/views/admin/dynamic_blocks/_form.html.erb +1 -1
- data/app/views/admin/dynamic_blocks/entity/_in_list.html.erb +1 -1
- data/app/views/admin/dynamic_blocks/index.html.erb +1 -1
- data/app/views/admin/dynamic_blocks/show.html.erb +3 -3
- data/app/views/admin/dynamic_pages/entity/_in_list.html.erb +1 -1
- data/app/views/admin/dynamic_pages/index.html.erb +1 -6
- data/app/views/admin/dynamic_pages/show.html.erb +1 -1
- data/app/views/admin/index/index.html.erb +1 -1
- data/app/views/admin/ip_addresses/index.html.erb +2 -2
- data/app/views/admin/navigation_groups/index.html.erb +1 -6
- data/app/views/admin/tokens/entity/_in_list.html.erb +1 -1
- data/app/views/admin/tokens/index.html.erb +1 -6
- data/app/views/admin/tokens/show.html.erb +1 -1
- data/app/views/admin/users/entity/_in_list.html.erb +2 -4
- data/app/views/admin/users/index.html.erb +1 -1
- data/app/views/admin/users/show.html.erb +18 -12
- data/app/views/admin/widgets/_filters.html.erb +7 -2
- data/app/views/admin/widgets/filters/_text.html.erb +7 -0
- data/app/views/errors/error.html.erb +1 -0
- data/app/views/layouts/admin/_header.html.erb +7 -2
- 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 +3 -50
- data/app/views/my/profiles/show.html.erb +13 -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 +1 -1
- 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/_priority_icons.html.erb +8 -0
- data/app/views/shared/entity/_toggle.html.erb +12 -0
- data/app/views/shared/forms/_field.html.erb +5 -1
- 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/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 +4 -0
- data/config/locales/components-ru.yml +23 -2
- data/config/locales/content-ru.yml +8 -0
- data/config/locales/users-ru.yml +4 -1
- data/config/routes.rb +21 -0
- data/db/migrate/20200224000010_create_users_component.rb +0 -11
- data/db/migrate/20200404000000_create_simple_images.rb +1 -0
- data/db/migrate/20210405000000_create_acl.rb +0 -1
- data/db/migrate/20210421000000_create_content_component.rb +21 -0
- 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 +0 -27
- data/lib/biovision/version.rb +1 -1
- data/lib/tasks/components.rake +51 -0
- metadata +53 -4
- data/app/models/biovision_component_user.rb +0 -21
@@ -5,7 +5,18 @@ module Biovision
|
|
5
5
|
# Content
|
6
6
|
class ContentComponent < BaseComponent
|
7
7
|
def self.dependent_models
|
8
|
-
[
|
8
|
+
[
|
9
|
+
DynamicPage, NavigationGroup, NavigationGroupPage, DynamicBlock,
|
10
|
+
OembedReceiver, OembedDomain, OembedLink
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
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)
|
9
20
|
end
|
10
21
|
|
11
22
|
def use_parameters?
|
@@ -17,11 +28,11 @@ module Biovision
|
|
17
28
|
end
|
18
29
|
|
19
30
|
def crud_table_names
|
20
|
-
super - %w[navigation_group_pages]
|
31
|
+
super - %w[navigation_group_pages oembed_receivers oembed_domains]
|
21
32
|
end
|
22
33
|
|
23
34
|
def administrative_parts
|
24
|
-
%w[navigation_groups dynamic_blocks dynamic_pages]
|
35
|
+
%w[navigation_groups dynamic_blocks dynamic_pages oembed_links]
|
25
36
|
end
|
26
37
|
|
27
38
|
def navigation
|
@@ -124,6 +124,12 @@ module Biovision
|
|
124
124
|
user.attributes[attribute_name.to_s]
|
125
125
|
end
|
126
126
|
|
127
|
+
def role_tree
|
128
|
+
result = super
|
129
|
+
result['users'] << 'log_in'
|
130
|
+
result
|
131
|
+
end
|
132
|
+
|
127
133
|
def crud_table_names
|
128
134
|
super - %w[user_languages biovision_component_users]
|
129
135
|
end
|
@@ -7,18 +7,25 @@ module Biovision
|
|
7
7
|
attr_reader :model_class
|
8
8
|
|
9
9
|
# @param [ApplicationRecord] model_class
|
10
|
-
|
10
|
+
# @param [Hash] filters
|
11
|
+
def initialize(model_class, filters = {})
|
11
12
|
@model_class = model_class
|
13
|
+
@filters = filters
|
12
14
|
end
|
13
15
|
|
14
16
|
# @param [Integer] page
|
15
|
-
|
16
|
-
def administrative_collection(page = 1, filters = {})
|
17
|
-
@filters = filters
|
17
|
+
def administrative_collection(page = 1)
|
18
18
|
paginates = model_class.respond_to?(:page_for_administration)
|
19
19
|
paginates ? administrative_page(page) : administrative_list
|
20
20
|
end
|
21
21
|
|
22
|
+
# @param [User] user
|
23
|
+
# @param [Integer] page
|
24
|
+
def personal_collection(user, page = 1)
|
25
|
+
paginates = model_class.respond_to?(:page_for_owner)
|
26
|
+
paginates ? personal_page(user, page) : personal_list(user)
|
27
|
+
end
|
28
|
+
|
22
29
|
private
|
23
30
|
|
24
31
|
def administrative_list
|
@@ -38,6 +45,26 @@ module Biovision
|
|
38
45
|
model_class.page_for_administration(page)
|
39
46
|
end
|
40
47
|
end
|
48
|
+
|
49
|
+
# @param [User] user
|
50
|
+
def personal_list(user)
|
51
|
+
if model_class.respond_to?(:filtered)
|
52
|
+
model_class.filtered(@filters).list_for_owner(user)
|
53
|
+
else
|
54
|
+
model_class.list_for_owner(user)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# @param [User] user
|
59
|
+
# @param [Integer] page
|
60
|
+
def personal_page(user, page)
|
61
|
+
reflection = model_class.singleton_method(:page_for_owner)
|
62
|
+
if reflection.parameters.include?(%i[key filters])
|
63
|
+
model_class.page_for_owner(user, page, filters: @filters)
|
64
|
+
else
|
65
|
+
model_class.page_for_owner(user, page)
|
66
|
+
end
|
67
|
+
end
|
41
68
|
end
|
42
69
|
end
|
43
70
|
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Helpers
|
5
|
+
# Helper for exporting model data
|
6
|
+
class ExportHelper
|
7
|
+
EXPORT_DIR = "#{Rails.root}/tmp/export"
|
8
|
+
SPECIAL_FIELDS = %w[id agent_id ip_address_id image attachment].freeze
|
9
|
+
|
10
|
+
# @param [Class] model
|
11
|
+
def export_model(model)
|
12
|
+
puts "Exporting model #{model}..."
|
13
|
+
FileUtils.mkdir_p(EXPORT_DIR) unless Dir.exist?(EXPORT_DIR)
|
14
|
+
file_name = "#{EXPORT_DIR}/#{model.table_name}.yml"
|
15
|
+
File.open(file_name, 'wb') do |file|
|
16
|
+
@file = file
|
17
|
+
model.order(:id).each do |entity|
|
18
|
+
@entity = entity
|
19
|
+
export_entity
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def export_entity
|
27
|
+
print "\r#{@entity.id} "
|
28
|
+
@file.puts "#{@entity.id}:"
|
29
|
+
export_attributes
|
30
|
+
end
|
31
|
+
|
32
|
+
def export_attributes
|
33
|
+
filtered = @entity.attributes.reject { |a, v| ignored?(a) || v.nil? }
|
34
|
+
filtered.each do |attribute, value|
|
35
|
+
export_attribute(attribute, value)
|
36
|
+
end
|
37
|
+
export_track
|
38
|
+
export_media('image') if @entity.attributes.key?('image')
|
39
|
+
export_media('attachment') if @entity.attributes.key?('attachment')
|
40
|
+
end
|
41
|
+
|
42
|
+
# @param [String] attribute
|
43
|
+
# @param value
|
44
|
+
def export_attribute(attribute, value)
|
45
|
+
@file.print " #{attribute}: "
|
46
|
+
if value.is_a?(Hash)
|
47
|
+
if value.blank?
|
48
|
+
@file.puts '{}'
|
49
|
+
else
|
50
|
+
@file.puts value.to_yaml.gsub(/\A---|\n\z/, '').gsub("\n", "\n ")
|
51
|
+
end
|
52
|
+
else
|
53
|
+
@file.puts value.inspect
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def export_track
|
58
|
+
return unless @entity.is_a?(HasTrack)
|
59
|
+
|
60
|
+
unless @entity.ip_address.nil?
|
61
|
+
@file.puts " ip_address: #{@entity.ip_address.ip.to_s.inspect}"
|
62
|
+
end
|
63
|
+
|
64
|
+
return if @entity.agent.blank?
|
65
|
+
|
66
|
+
@file.puts " agent: #{@entity.agent.name.inspect}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def media_dir
|
70
|
+
"#{EXPORT_DIR}/#{@entity.class.table_name}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def export_media(type)
|
74
|
+
media = @entity.send(type.to_sym)
|
75
|
+
|
76
|
+
return if media.blank?
|
77
|
+
|
78
|
+
media_name = File.basename(media.path)
|
79
|
+
dir_name = "#{media_dir}/#{@entity.id}"
|
80
|
+
FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
|
81
|
+
FileUtils.copy(media.path, "#{dir_name}/#{media_name}")
|
82
|
+
@file.puts " #{type}: #{media_name.inspect}"
|
83
|
+
end
|
84
|
+
|
85
|
+
# @param [String] attribute
|
86
|
+
def ignored?(attribute)
|
87
|
+
return true if SPECIAL_FIELDS.include?(attribute)
|
88
|
+
|
89
|
+
%w[count cache].each do |ending|
|
90
|
+
return true if attribute.end_with?("_#{ending}")
|
91
|
+
end
|
92
|
+
|
93
|
+
false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -22,7 +22,9 @@ module Biovision
|
|
22
22
|
message = "create_#{model.table_name}".to_sym
|
23
23
|
send(message) if respond_to?(message, true)
|
24
24
|
end
|
25
|
-
component[nil]
|
25
|
+
handler = component[nil]
|
26
|
+
handler.create_roles
|
27
|
+
handler.seed if handler.respond_to?(:seed)
|
26
28
|
end
|
27
29
|
|
28
30
|
# Drops tables for each dependent model
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Stories
|
5
|
+
# Base component story
|
6
|
+
class ComponentStory
|
7
|
+
attr_accessor :component_handler, :entity
|
8
|
+
|
9
|
+
# @param [Biovision::Components::BaseComponent] handler
|
10
|
+
# @param [ApplicationRecord|String|nil] entity
|
11
|
+
def initialize(handler, entity = nil)
|
12
|
+
self.component_handler = handler
|
13
|
+
return if entity.blank?
|
14
|
+
|
15
|
+
if entity.is_a?(ApplicationRecord)
|
16
|
+
self.entity = entity
|
17
|
+
else
|
18
|
+
self.entity_id = entity.to_s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Get associated model class
|
23
|
+
#
|
24
|
+
# This method should be implemented in children if story name
|
25
|
+
# does not match model name.
|
26
|
+
# The result is used in #entity_id=
|
27
|
+
def model_class
|
28
|
+
model_name = to_s.demodulize.to_s.underscore.gsub('_story', '')
|
29
|
+
model_name.classify.safe_constantize
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param [Hash] parameters
|
33
|
+
def perform(parameters)
|
34
|
+
@parameters = parameters
|
35
|
+
# implement in children and return hash
|
36
|
+
{ result: 'Nothing was processed.' }
|
37
|
+
end
|
38
|
+
|
39
|
+
# Set entity identified by value
|
40
|
+
#
|
41
|
+
# This method can be implemented in child classes
|
42
|
+
#
|
43
|
+
# @param [String] value
|
44
|
+
def entity_id=(value)
|
45
|
+
return if model_class.nil?
|
46
|
+
|
47
|
+
if model_class.respond_to?(:[])
|
48
|
+
self.entity = model_class[value]
|
49
|
+
elsif model_class.respond_to?(:find_by)
|
50
|
+
self.entity = model_class.find_by(id: value)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -13,12 +13,15 @@
|
|
13
13
|
class BiovisionComponent < ApplicationRecord
|
14
14
|
include FlatPriority
|
15
15
|
include RequiredUniqueSlug
|
16
|
+
include Toggleable
|
16
17
|
|
17
18
|
SLUG_LIMIT = 250
|
18
19
|
SLUG_PATTERN_HTML = '^[a-zA-Z][-a-zA-Z0-9_]+[a-zA-Z0-9]$'
|
19
20
|
|
20
|
-
|
21
|
+
toggleable :active
|
22
|
+
|
21
23
|
has_many :simple_images, dependent: :destroy
|
24
|
+
has_many :uploaded_files, dependent: :destroy
|
22
25
|
has_many :codes, dependent: :delete_all
|
23
26
|
has_many :roles, dependent: :destroy
|
24
27
|
has_many :groups, dependent: :destroy
|
@@ -42,6 +45,8 @@ class BiovisionComponent < ApplicationRecord
|
|
42
45
|
|
43
46
|
# @param [String] slug
|
44
47
|
# @param value
|
48
|
+
#
|
49
|
+
# @deprecated use parameters[slug.to_s] = value
|
45
50
|
def []=(slug, value)
|
46
51
|
parameters[slug.to_s] = value
|
47
52
|
save!
|
@@ -65,4 +70,12 @@ class BiovisionComponent < ApplicationRecord
|
|
65
70
|
|
66
71
|
code
|
67
72
|
end
|
73
|
+
|
74
|
+
def text_for_link
|
75
|
+
I18n.t("biovision.components.#{slug}.name", default: slug)
|
76
|
+
end
|
77
|
+
|
78
|
+
def admin_url
|
79
|
+
"/admin/components/#{slug}"
|
80
|
+
end
|
68
81
|
end
|
data/app/models/code.rb
CHANGED
@@ -17,7 +17,7 @@ class Code < ApplicationRecord
|
|
17
17
|
include HasTrack
|
18
18
|
|
19
19
|
BODY_LIMIT = 50
|
20
|
-
QUANTITY_RANGE = (0..32_767)
|
20
|
+
QUANTITY_RANGE = (0..32_767)
|
21
21
|
|
22
22
|
belongs_to :biovision_component
|
23
23
|
belongs_to :user, optional: true
|
@@ -80,10 +80,10 @@ class Code < ApplicationRecord
|
|
80
80
|
return unless body.nil?
|
81
81
|
|
82
82
|
if phone?
|
83
|
+
self.body = SecureRandom.random_number(1_000_000).to_s.rjust(6, '0')
|
84
|
+
else
|
83
85
|
number = SecureRandom.random_number(0xffff_ffff_ffff_ffff)
|
84
86
|
self.body = number.to_s(36).scan(/.{4}/).join('-').upcase
|
85
|
-
else
|
86
|
-
self.body = SecureRandom.random_number(1_000_000).to_s.rjust(6, '0')
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Model references to uploaded file
|
4
|
+
module HasUploadedFile
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
belongs_to :uploaded_file, optional: true, counter_cache: :object_count
|
9
|
+
|
10
|
+
scope :included_file, -> { includes(:uploaded_file) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def attachment_name
|
14
|
+
uploaded_file&.name
|
15
|
+
end
|
16
|
+
|
17
|
+
def attachment_size
|
18
|
+
uploaded_file&.file_size
|
19
|
+
end
|
20
|
+
|
21
|
+
def attachment_url
|
22
|
+
return if uploaded_file&.attachment.blank?
|
23
|
+
|
24
|
+
uploaded_file.attachment.url
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Adds list of toggleable attributes to model
|
4
|
+
#
|
5
|
+
# @author Maxim Khan-Magomedov <maxim.km@gmail.com>
|
6
|
+
module SimpleTag
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
|
11
|
+
before_validation :normalize_name
|
12
|
+
validates_uniqueness_of :name, case_sensitive: false
|
13
|
+
|
14
|
+
scope :list_for_administration, -> { order(:name) }
|
15
|
+
|
16
|
+
def self.entity_parameters
|
17
|
+
%i[name]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.name_limit
|
21
|
+
100
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def normalize_name
|
27
|
+
self.name = name.to_s[0..name_limit]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -14,7 +14,8 @@ module Toggleable
|
|
14
14
|
def toggle_parameter(attribute)
|
15
15
|
return unless toggleable_attributes.include? attribute.to_sym
|
16
16
|
|
17
|
-
|
17
|
+
assign_attributes(attribute => !attributes[attribute.to_s])
|
18
|
+
save!
|
18
19
|
{ attribute => self[attribute] }
|
19
20
|
end
|
20
21
|
end
|
@@ -13,6 +13,8 @@ module TreeStructure
|
|
13
13
|
after_destroy { parent&.cache_children! unless ENV['SKIP_CHILDREN_CACHE'] }
|
14
14
|
after_save { parent&.cache_children! unless ENV['SKIP_CHILDREN_CACHE'] }
|
15
15
|
|
16
|
+
scope :with_parent_id, ->(v) { where(parent_id: v) }
|
17
|
+
|
16
18
|
def self.tree(collection)
|
17
19
|
result = {}
|
18
20
|
|
data/app/models/metric.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Domain for OEmbed receiver
|
4
|
+
#
|
5
|
+
# Attributes:
|
6
|
+
# name [String]
|
7
|
+
# oembed_receiver_id [OembedReceiver]
|
8
|
+
class OembedDomain < ApplicationRecord
|
9
|
+
include RequiredUniqueName
|
10
|
+
|
11
|
+
NAME_LIMIT = 255
|
12
|
+
|
13
|
+
belongs_to :oembed_receiver
|
14
|
+
|
15
|
+
validates_length_of :name, maximum: NAME_LIMIT
|
16
|
+
|
17
|
+
# @param [String] name
|
18
|
+
def self.[](name)
|
19
|
+
find_by(name: name.to_s.downcase)
|
20
|
+
end
|
21
|
+
|
22
|
+
def receiver_slug
|
23
|
+
oembed_receiver&.slug
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Link from oembed tag
|
4
|
+
#
|
5
|
+
# Attributes:
|
6
|
+
# code [Text], optional
|
7
|
+
# created_at [DateTime]
|
8
|
+
# updated_at [DateTime]
|
9
|
+
# url [String]
|
10
|
+
class OembedLink < ApplicationRecord
|
11
|
+
URL_LIMIT = 255
|
12
|
+
|
13
|
+
validates_presence_of :url
|
14
|
+
before_save { self.url = url.to_s[0..(URL_LIMIT - 1)] }
|
15
|
+
|
16
|
+
def self.[](url)
|
17
|
+
find_or_initialize_by(url: url)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Receiver for OEmbed links
|
4
|
+
#
|
5
|
+
# Attributes:
|
6
|
+
# slug [String]
|
7
|
+
class OembedReceiver < ApplicationRecord
|
8
|
+
include RequiredUniqueSlug
|
9
|
+
|
10
|
+
SLUG_PATTERN = /\A[a-z]+(_?[a-z]+){2,49}\z/
|
11
|
+
|
12
|
+
has_many :oembed_domains, dependent: :delete_all
|
13
|
+
|
14
|
+
validates_format_of :slug, with: SLUG_PATTERN
|
15
|
+
end
|
data/app/models/role.rb
CHANGED
@@ -44,12 +44,7 @@ class Role < ApplicationRecord
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def user_ids
|
47
|
-
|
48
|
-
# direct_exclusive = user_roles.where(inclusive: false).pluck(:user_id).uniq
|
49
|
-
# group_inclusive = groups.map(&:user_ids).flatten
|
50
|
-
#
|
51
|
-
# group_inclusive + direct_inclusive - direct_exclusive
|
52
|
-
[]
|
47
|
+
(user_roles.pluck(:user_id).uniq + groups.map(&:user_ids).flatten).uniq
|
53
48
|
end
|
54
49
|
|
55
50
|
def count_users!
|
@@ -76,12 +71,9 @@ class Role < ApplicationRecord
|
|
76
71
|
end
|
77
72
|
|
78
73
|
# @param [User] user
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
user_roles.create(user: user, inclusive: inclusive)
|
84
|
-
inclusive ? add_to_cache!(user) : remove_from_cache!(user)
|
74
|
+
def add_user(user)
|
75
|
+
user_roles.create(user: user)
|
76
|
+
add_to_cache!(user)
|
85
77
|
end
|
86
78
|
|
87
79
|
# @param [User] user
|
data/app/models/simple_image.rb
CHANGED
@@ -6,7 +6,9 @@
|
|
6
6
|
# agent_id [Agent], optional
|
7
7
|
# biovision_component_id [BiovisionComponent]
|
8
8
|
# caption [string], optional
|
9
|
+
# checksum [String], optional
|
9
10
|
# created_at [DateTime]
|
11
|
+
# data [jsonb]
|
10
12
|
# image [SimpleImageUploader]
|
11
13
|
# image_alt_text [string]
|
12
14
|
# ip_address_id [IpAddress], optional
|
@@ -16,7 +18,6 @@
|
|
16
18
|
# updated_at [DateTime]
|
17
19
|
# user_id [User], optional
|
18
20
|
# uuid [uuid]
|
19
|
-
# data [jsonb]
|
20
21
|
class SimpleImage < ApplicationRecord
|
21
22
|
include Checkable
|
22
23
|
include HasOwner
|
@@ -24,6 +25,7 @@ class SimpleImage < ApplicationRecord
|
|
24
25
|
include HasUuid
|
25
26
|
|
26
27
|
META_LIMIT = 255
|
28
|
+
ORIGINAL_CHECKSUM = 'original_checksum'
|
27
29
|
|
28
30
|
mount_uploader :image, SimpleImageUploader
|
29
31
|
|
@@ -33,6 +35,8 @@ class SimpleImage < ApplicationRecord
|
|
33
35
|
has_many :simple_image_tag_images, dependent: :destroy
|
34
36
|
has_many :simple_image_tags, through: :simple_image_tag_images
|
35
37
|
|
38
|
+
before_save :calculate_checksum
|
39
|
+
|
36
40
|
validates_presence_of :image
|
37
41
|
validates_length_of :caption, maximum: META_LIMIT
|
38
42
|
validates_length_of :image_alt_text, maximum: META_LIMIT
|
@@ -41,12 +45,27 @@ class SimpleImage < ApplicationRecord
|
|
41
45
|
|
42
46
|
scope :in_component, ->(v) { where(biovision_component: v) }
|
43
47
|
scope :filtered, ->(v) { where('image ilike ? or caption ilike ?', "%#{v}%", "%#{v}%") unless v.blank? }
|
44
|
-
scope :list_for_administration, -> { order(
|
48
|
+
scope :list_for_administration, -> { order(:image) }
|
49
|
+
|
50
|
+
# @param [String] input
|
51
|
+
def self.[](input)
|
52
|
+
case input
|
53
|
+
when /\A\h{8}-\h{4}-4\h{3}-[89ab]\h{3}-\h{12}\Z/i
|
54
|
+
find_by(uuid: input)
|
55
|
+
when /\A[a-f0-9]{64}\z/i
|
56
|
+
key = "data->>'#{ORIGINAL_CHECKSUM}'"
|
57
|
+
find_by(checksum: input) || find_by("#{key} = ?", input)
|
58
|
+
end
|
59
|
+
end
|
45
60
|
|
46
61
|
def self.entity_parameters
|
47
62
|
%i[caption image image_alt_text source_link source_name]
|
48
63
|
end
|
49
64
|
|
65
|
+
def self.json_attributes
|
66
|
+
%i[caption image_alt_text source_link source_name]
|
67
|
+
end
|
68
|
+
|
50
69
|
def name
|
51
70
|
File.basename(image.path)
|
52
71
|
end
|
@@ -58,4 +77,12 @@ class SimpleImage < ApplicationRecord
|
|
58
77
|
def image_slug
|
59
78
|
"#{uuid[0..2]}/#{uuid[3..5]}/#{uuid}"
|
60
79
|
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def calculate_checksum
|
84
|
+
return if image&.path.blank?
|
85
|
+
|
86
|
+
self.checksum = Digest::SHA256.file(image.path).hexdigest
|
87
|
+
end
|
61
88
|
end
|
@@ -9,22 +9,7 @@
|
|
9
9
|
# updated_at [DateTime]
|
10
10
|
class SimpleImageTag < ApplicationRecord
|
11
11
|
include Checkable
|
12
|
-
|
12
|
+
include SimpleTag
|
13
13
|
|
14
14
|
has_many :simple_image_tag_images, dependent: :delete_all
|
15
|
-
|
16
|
-
before_validation :normalize_name
|
17
|
-
validates_uniqueness_of :name, case_sensitive: false
|
18
|
-
|
19
|
-
scope :list_for_administration, -> { order('name asc') }
|
20
|
-
|
21
|
-
def self.entity_parameters
|
22
|
-
%i[name]
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def normalize_name
|
28
|
-
self.name = name.to_s[0..NAME_LIMIT]
|
29
|
-
end
|
30
15
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Uploaded file
|
4
|
+
#
|
5
|
+
# Attributes:
|
6
|
+
# attachment [SimpleFileUploader]
|
7
|
+
# agent_id [Agent], optional
|
8
|
+
# biovision_component_id [BiovisionComponent]
|
9
|
+
# checksum [String]
|
10
|
+
# created_at [DateTime]
|
11
|
+
# data [jsonb]
|
12
|
+
# description [String], optional
|
13
|
+
# ip_address_id [IpAddress], optional
|
14
|
+
# object_count [Integer]
|
15
|
+
# updated_at [DateTime]
|
16
|
+
# user_id [User], optional
|
17
|
+
# uuid [uuid]
|
18
|
+
class UploadedFile < ApplicationRecord
|
19
|
+
include Checkable
|
20
|
+
include HasOwner
|
21
|
+
include HasTrack
|
22
|
+
include HasUuid
|
23
|
+
|
24
|
+
META_LIMIT = 255
|
25
|
+
|
26
|
+
mount_uploader :attachment, SimpleFileUploader
|
27
|
+
|
28
|
+
belongs_to :agent, optional: true
|
29
|
+
belongs_to :biovision_component
|
30
|
+
belongs_to :user, optional: true
|
31
|
+
has_many :uploaded_file_tag_files, dependent: :destroy
|
32
|
+
has_many :uploaded_file_tags, through: :uploaded_file_tag_files
|
33
|
+
|
34
|
+
before_save :calculate_checksum
|
35
|
+
|
36
|
+
validates_presence_of :attachment
|
37
|
+
validates_length_of :description, maximum: META_LIMIT
|
38
|
+
|
39
|
+
scope :in_component, ->(v) { where(biovision_component: v) }
|
40
|
+
scope :filtered, ->(v) { where('description ilike ? or attachment ilike ?', "%#{v}%", "%#{v}%") unless v.blank? }
|
41
|
+
scope :list_for_administration, -> { order('attachment asc') }
|
42
|
+
|
43
|
+
def self.entity_parameters
|
44
|
+
%i[attachment description]
|
45
|
+
end
|
46
|
+
|
47
|
+
def name
|
48
|
+
File.basename(attachment.path)
|
49
|
+
end
|
50
|
+
|
51
|
+
def file_size
|
52
|
+
File.size(attachment.path)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def calculate_checksum
|
58
|
+
return if attachment&.path.blank?
|
59
|
+
|
60
|
+
self.checksum = Digest::SHA256.file(attachment.path).hexdigest
|
61
|
+
end
|
62
|
+
end
|