biovision 0.0.200518.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +214 -0
  4. data/Rakefile +22 -0
  5. data/app/assets/config/biovision_manifest.js +1 -0
  6. data/app/assets/images/biovision/components/carousel/arrow-left.svg +4 -0
  7. data/app/assets/images/biovision/components/carousel/arrow-right.svg +4 -0
  8. data/app/assets/images/biovision/icons/breadcrumb-hover.svg +1 -0
  9. data/app/assets/images/biovision/icons/breadcrumb.svg +1 -0
  10. data/app/assets/images/biovision/icons/components/contact.svg +26 -0
  11. data/app/assets/images/biovision/icons/components/content.svg +20 -0
  12. data/app/assets/images/biovision/icons/components/users.svg +21 -0
  13. data/app/assets/images/biovision/icons/key.svg +16 -0
  14. data/app/assets/images/biovision/icons/log_in.svg +15 -0
  15. data/app/assets/images/biovision/icons/log_out.svg +15 -0
  16. data/app/assets/images/biovision/icons/messages/error.svg +14 -0
  17. data/app/assets/images/biovision/icons/messages/info.svg +8 -0
  18. data/app/assets/images/biovision/icons/messages/success.svg +12 -0
  19. data/app/assets/images/biovision/icons/messages/warning.svg +13 -0
  20. data/app/assets/images/biovision/icons/settings.svg +41 -0
  21. data/app/assets/images/biovision/placeholders/16x9.svg +11 -0
  22. data/app/assets/images/biovision/placeholders/1x1.svg +11 -0
  23. data/app/assets/images/biovision/placeholders/3x2.svg +11 -0
  24. data/app/assets/images/biovision/placeholders/user.svg +15 -0
  25. data/app/assets/stylesheets/biovision/admin.scss +6 -0
  26. data/app/assets/stylesheets/biovision/admin/components.scss +59 -0
  27. data/app/assets/stylesheets/biovision/admin/default.scss +57 -0
  28. data/app/assets/stylesheets/biovision/admin/layout.scss +95 -0
  29. data/app/assets/stylesheets/biovision/admin/vars.scss +56 -0
  30. data/app/assets/stylesheets/biovision/biovision.scss +134 -0
  31. data/app/assets/stylesheets/biovision/biovision/messages.scss +41 -0
  32. data/app/assets/stylesheets/biovision/components/carousel.scss +53 -0
  33. data/app/assets/stylesheets/biovision/components/forms.scss +85 -0
  34. data/app/assets/stylesheets/biovision/components/hamburger.scss +56 -0
  35. data/app/assets/stylesheets/biovision/components/lists.scss +91 -0
  36. data/app/assets/stylesheets/biovision/default.scss +57 -0
  37. data/app/assets/stylesheets/biovision/themes/default_theme.scss +2 -0
  38. data/app/assets/stylesheets/biovision/themes/default_theme/components.scss +3 -0
  39. data/app/assets/stylesheets/biovision/themes/default_theme/layout.scss +44 -0
  40. data/app/assets/stylesheets/biovision/themes/default_theme/layout/footer.scss +0 -0
  41. data/app/assets/stylesheets/biovision/themes/default_theme/layout/header.scss +39 -0
  42. data/app/assets/stylesheets/biovision/vars.scss +53 -0
  43. data/app/controllers/admin/agents_controller.rb +15 -0
  44. data/app/controllers/admin/components_controller.rb +174 -0
  45. data/app/controllers/admin/index_controller.rb +11 -0
  46. data/app/controllers/admin/ip_addresses_controller.rb +15 -0
  47. data/app/controllers/admin_controller.rb +14 -0
  48. data/app/controllers/authentication_controller.rb +79 -0
  49. data/app/controllers/concerns/authentication.rb +45 -0
  50. data/app/controllers/index_controller.rb +8 -0
  51. data/app/controllers/my/confirmations_controller.rb +2 -0
  52. data/app/controllers/my/index_controller.rb +8 -0
  53. data/app/controllers/my/profiles_controller.rb +128 -0
  54. data/app/controllers/my/recoveries_controller.rb +2 -0
  55. data/app/helpers/biovision_components_helper.rb +14 -0
  56. data/app/helpers/users_helper.rb +11 -0
  57. data/app/lib/biovision/components/base_component.rb +177 -0
  58. data/app/lib/biovision/components/component_settings.rb +30 -0
  59. data/app/lib/biovision/components/privilege_handler.rb +77 -0
  60. data/app/lib/biovision/components/track_component.rb +9 -0
  61. data/app/lib/biovision/components/users/authentication.rb +47 -0
  62. data/app/lib/biovision/components/users/code_handler.rb +23 -0
  63. data/app/lib/biovision/components/users/profile_handler.rb +12 -0
  64. data/app/lib/biovision/components/users/registration_handler.rb +99 -0
  65. data/app/lib/biovision/components/users_component.rb +47 -0
  66. data/app/lib/biovision/notifiers/base_notifier.rb +69 -0
  67. data/app/lib/biovision/notifiers/socialization_notifier.rb +31 -0
  68. data/app/lib/biovision/notifiers/users_notifier.rb +15 -0
  69. data/app/models/agent.rb +35 -0
  70. data/app/models/biovision_component.rb +45 -0
  71. data/app/models/biovision_component_user.rb +21 -0
  72. data/app/models/browser.rb +34 -0
  73. data/app/models/code.rb +71 -0
  74. data/app/models/concerns/checkable.rb +22 -0
  75. data/app/models/concerns/flat_priority.rb +50 -0
  76. data/app/models/concerns/has_language.rb +10 -0
  77. data/app/models/concerns/has_owner.rb +22 -0
  78. data/app/models/concerns/has_simple_image.rb +18 -0
  79. data/app/models/concerns/has_track.rb +10 -0
  80. data/app/models/concerns/has_uuid.rb +12 -0
  81. data/app/models/concerns/meta_texts.rb +16 -0
  82. data/app/models/concerns/nested_priority.rb +58 -0
  83. data/app/models/concerns/required_unique_name.rb +16 -0
  84. data/app/models/concerns/required_unique_slug.rb +15 -0
  85. data/app/models/concerns/toggleable.rb +33 -0
  86. data/app/models/foreign_site.rb +34 -0
  87. data/app/models/foreign_user.rb +21 -0
  88. data/app/models/ip_address.rb +31 -0
  89. data/app/models/language.rb +31 -0
  90. data/app/models/login_attempt.rb +35 -0
  91. data/app/models/metric.rb +48 -0
  92. data/app/models/metric_value.rb +11 -0
  93. data/app/models/notification.rb +37 -0
  94. data/app/models/simple_image.rb +47 -0
  95. data/app/models/simple_image_tag.rb +30 -0
  96. data/app/models/simple_image_tag_image.rb +13 -0
  97. data/app/models/token.rb +96 -0
  98. data/app/models/user.rb +136 -0
  99. data/app/models/user_language.rb +15 -0
  100. data/app/uploaders/simple_image_uploader.rb +96 -0
  101. data/app/uploaders/user_image_uploader.rb +58 -0
  102. data/app/views/admin/agents/_nav_item.html.erb +6 -0
  103. data/app/views/admin/agents/entity/_in_list.html.erb +6 -0
  104. data/app/views/admin/agents/index.html.erb +13 -0
  105. data/app/views/admin/components/_list.html.erb +12 -0
  106. data/app/views/admin/components/entity/_links.html.erb +35 -0
  107. data/app/views/admin/components/entity/_section.html.erb +12 -0
  108. data/app/views/admin/components/index.html.erb +12 -0
  109. data/app/views/admin/components/links/_track.html.erb +2 -0
  110. data/app/views/admin/components/links/_users.html.erb +11 -0
  111. data/app/views/admin/components/privileges.html.erb +20 -0
  112. data/app/views/admin/components/privileges/_component_user.html.erb +17 -0
  113. data/app/views/admin/components/privileges/_links.html.erb +35 -0
  114. data/app/views/admin/components/privileges/_privilege_flag.html.erb +28 -0
  115. data/app/views/admin/components/privileges/_users.html.erb +23 -0
  116. data/app/views/admin/components/settings.html.erb +39 -0
  117. data/app/views/admin/components/settings/_new_parameter.html.erb +46 -0
  118. data/app/views/admin/components/settings/_parameters.html.erb +20 -0
  119. data/app/views/admin/components/settings/_setting.html.erb +18 -0
  120. data/app/views/admin/components/settings/_settings.html.erb +31 -0
  121. data/app/views/admin/components/show.html.erb +14 -0
  122. data/app/views/admin/index/index.html.erb +14 -0
  123. data/app/views/admin/ip_addresses/_nav_item.html.erb +6 -0
  124. data/app/views/admin/ip_addresses/entity/_in_list.html.erb +6 -0
  125. data/app/views/admin/ip_addresses/index.html.erb +13 -0
  126. data/app/views/admin/unauthorized.html.erb +19 -0
  127. data/app/views/authentication/_form.html.erb +40 -0
  128. data/app/views/authentication/failed.js.erb +3 -0
  129. data/app/views/authentication/new.html.erb +21 -0
  130. data/app/views/index/index.html.erb +0 -0
  131. data/app/views/layouts/admin.html.erb +23 -0
  132. data/app/views/layouts/admin/_breadcrumbs.html.erb +8 -0
  133. data/app/views/layouts/admin/_footer.html.erb +10 -0
  134. data/app/views/layouts/admin/_header.html.erb +18 -0
  135. data/app/views/layouts/admin/header/_logo.html.erb +3 -0
  136. data/app/views/layouts/application/_footer.html.erb +8 -0
  137. data/app/views/layouts/application/_header.html.erb +9 -0
  138. data/app/views/layouts/application/header/_authentication.html.erb +13 -0
  139. data/app/views/my/index/index.html.erb +0 -0
  140. data/app/views/my/profiles/closed.html.erb +12 -0
  141. data/app/views/my/profiles/new.html.erb +17 -0
  142. data/app/views/my/profiles/new/_form.html.erb +147 -0
  143. data/app/views/shared/_breadcrumbs.html.erb +8 -0
  144. data/app/views/shared/_cookie_notification.html.erb +4 -0
  145. data/app/views/shared/_flash_messages.html.erb +7 -0
  146. data/app/views/shared/_meta_texts.html.erb +31 -0
  147. data/app/views/shared/_nothing_found.html.erb +1 -0
  148. data/app/views/shared/_pagination.jbuilder +15 -0
  149. data/app/views/shared/admin/_list.html.erb +19 -0
  150. data/app/views/shared/admin/_list_with_priority.html.erb +19 -0
  151. data/app/views/shared/admin/_toggleable.html.erb +8 -0
  152. data/app/views/shared/entity/_list_of_errors.html.erb +7 -0
  153. data/app/views/shared/forms/errors.js.erb +5 -0
  154. data/config/initializers/carrierwave.rb +27 -0
  155. data/config/initializers/pluralization.rb +2 -0
  156. data/config/locales/biovision-ru.yml +90 -0
  157. data/config/locales/components-ru.yml +81 -0
  158. data/config/locales/track-ru.yml +40 -0
  159. data/config/locales/users-ru.yml +130 -0
  160. data/config/routes.rb +75 -0
  161. data/db/migrate/20191228000000_create_biovision_components.rb +72 -0
  162. data/db/migrate/20200224000000_create_track_component.rb +59 -0
  163. data/db/migrate/20200224000010_create_users_component.rb +189 -0
  164. data/db/migrate/20200404000000_create_simple_images.rb +54 -0
  165. data/lib/biovision.rb +9 -0
  166. data/lib/biovision/base_methods.rb +167 -0
  167. data/lib/biovision/engine.rb +40 -0
  168. data/lib/biovision/version.rb +5 -0
  169. data/lib/tasks/biovision_tasks.rake +4 -0
  170. metadata +392 -0
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.routes.draw do
4
+ concern :check do
5
+ post :check, on: :collection, defaults: { format: :json }
6
+ end
7
+
8
+ concern :toggle do
9
+ post :toggle, on: :member, defaults: { format: :json }
10
+ end
11
+
12
+ concern :priority do
13
+ post :priority, on: :member, defaults: { format: :json }
14
+ end
15
+
16
+ concern :removable_image do
17
+ delete :image, action: :destroy_image, on: :member, defaults: { format: :json }
18
+ end
19
+
20
+ concern :lock do
21
+ member do
22
+ put :lock, defaults: { format: :json }
23
+ delete :lock, action: :unlock, defaults: { format: :json }
24
+ end
25
+ end
26
+
27
+ scope '(:locale)', constraints: { locale: /ru|en/ } do
28
+ # Handling errors
29
+ match '/400' => 'errors#bad_request', via: :all
30
+ match '/401' => 'errors#unauthorized', via: :all
31
+ match '/403' => 'errors#forbidden', via: :all
32
+ match '/404' => 'errors#not_found', via: :all
33
+ match '/422' => 'errors#unprocessable_entity', via: :all
34
+ match '/500' => 'errors#internal_server_error', via: :all
35
+
36
+ controller :authentication do
37
+ get 'login' => :new
38
+ post 'login' => :create
39
+ delete 'logout' => :destroy
40
+ get 'auth/:provider/callback' => :auth_callback, as: :auth_callback
41
+ end
42
+
43
+ namespace :admin do
44
+ get '/' => 'index#index'
45
+
46
+ scope :components, controller: :components do
47
+ get '/' => :index, as: :components
48
+ scope ':slug' do
49
+ get '/' => :show, as: :component
50
+ get 'settings' => :settings, as: :component_settings
51
+ patch 'settings' => :update_settings, as: nil
52
+ patch 'parameters' => :update_parameter, as: :component_parameters
53
+ get 'privileges' => :privileges, as: :component_privileges
54
+ patch 'privileges' => :update_privileges, as: nil
55
+ put 'administrators/:user_id' => :add_administrator, as: :component_administrators
56
+ delete 'administrators/:user_id' => :remove_administrator, as: nil
57
+ put 'users/:user_id/privileges/:privilege_slug' => :add_privilege, as: :component_privilege
58
+ delete 'users/:user_id/privileges/:privilege_slug' => :remove_privilege, as: nil
59
+ get 'images' => :images, as: :component_images
60
+ post 'images' => :create_image, as: nil
61
+ post 'ckeditor'
62
+ end
63
+ end
64
+
65
+ resources :agents, :ip_addresses, only: :index
66
+ end
67
+
68
+ namespace :my do
69
+ get '/' => 'index#index'
70
+
71
+ resource :profile, except: :destroy, concerns: :check
72
+ resource :confirmation, :recovery, only: %i[show create update]
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Create tables for Biovision components and metrics
4
+ class CreateBiovisionComponents < ActiveRecord::Migration[6.0]
5
+ def up
6
+ create_components unless BiovisionComponent.table_exists?
7
+ create_metrics unless Metric.table_exists?
8
+ create_metric_values unless MetricValue.table_exists?
9
+ create_languages unless Language.table_exists?
10
+ end
11
+
12
+ def down
13
+ drop_table :languages if Language.table_exists?
14
+ drop_table :metric_values if MetricValue.table_exists?
15
+ drop_table :metrics if Metric.table_exists?
16
+ drop_table :biovision_components if BiovisionComponent.table_exists?
17
+ end
18
+
19
+ private
20
+
21
+ def create_components
22
+ create_table :biovision_components, comment: 'Biovision CMS components' do |t|
23
+ t.integer :priority, limit: 2, default: 1, null: false
24
+ t.boolean :active, default: true, null: false
25
+ t.timestamps
26
+ t.string :slug, null: false
27
+ t.jsonb :settings, default: {}, null: false
28
+ t.jsonb :parameters, default: {}, null: false
29
+ end
30
+
31
+ add_index :biovision_components, :slug, unique: true
32
+ end
33
+
34
+ def create_metrics
35
+ create_table :metrics, comment: 'Component metrics' do |t|
36
+ t.references :biovision_component, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
37
+ t.timestamps
38
+ t.boolean :incremental, default: false, null: false
39
+ t.boolean :start_with_zero, default: true, null: false
40
+ t.boolean :show_on_dashboard, default: true, null: false
41
+ t.integer :default_period, limit: 2, default: 7, null: false
42
+ t.integer :value, default: 0, null: false
43
+ t.integer :previous_value, default: 0, null: false
44
+ t.string :name, null: false
45
+ end
46
+
47
+ add_index :metrics, %i[biovision_component_id name]
48
+ end
49
+
50
+ def create_metric_values
51
+ create_table :metric_values, comment: 'Component metric values' do |t|
52
+ t.references :metric, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
53
+ t.timestamp :time, null: false
54
+ t.integer :quantity, default: 1, null: false
55
+ end
56
+
57
+ execute "create index metric_values_day_idx on metric_values using btree (date_trunc('day', time));"
58
+ end
59
+
60
+ def create_languages
61
+ create_table :languages, comment: 'Interface languages' do |t|
62
+ t.integer :priority, limit: 2, default: 1, null: false
63
+ t.boolean :active, default: true, null: false
64
+ t.integer :object_count, default: 0, null: false
65
+ t.string :slug, null: false
66
+ t.string :code, null: false
67
+ end
68
+
69
+ Language.create!(code: 'ru', slug: 'russian')
70
+ Language.create!(code: 'en', slug: 'english', active: false)
71
+ end
72
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Create entry and tables for track component
4
+ class CreateTrackComponent < ActiveRecord::Migration[6.0]
5
+ def up
6
+ create_component
7
+ create_browsers unless Browser.table_exists?
8
+ create_agents unless Agent.table_exists?
9
+ create_ip_addresses unless IpAddress.table_exists?
10
+ end
11
+
12
+ def down
13
+ drop_table :ip_addresses if IpAddress.table_exists?
14
+ drop_table :agents if Agent.table_exists?
15
+ drop_table :browsers if Browser.table_exists?
16
+ end
17
+
18
+ private
19
+
20
+ def create_component
21
+ BiovisionComponent.create(slug: Biovision::Components::TrackComponent.slug)
22
+ end
23
+
24
+ def create_browsers
25
+ create_table :browsers, comment: 'Browsers' do |t|
26
+ t.boolean :mobile, default: false, null: false
27
+ t.boolean :banned, default: false, null: false
28
+ t.timestamps
29
+ t.integer :agents_count, default: 0, null: false
30
+ t.string :name, null: false
31
+ t.string :version, null: false
32
+ end
33
+
34
+ add_index :browsers, %i[name version], unique: true
35
+ end
36
+
37
+ def create_agents
38
+ create_table :agents, comment: 'User agents' do |t|
39
+ t.references :browser, foreign_key: { on_update: :cascade, on_delete: :nullify }
40
+ t.integer :object_count, default: 0, index: true, null: false
41
+ t.boolean :banned, default: false, null: false
42
+ t.timestamps
43
+ t.string :name, null: false
44
+ end
45
+
46
+ add_index :agents, :name, unique: true
47
+ end
48
+
49
+ def create_ip_addresses
50
+ create_table :ip_addresses, comment: 'IP addresses' do |t|
51
+ t.inet :ip, null: false
52
+ t.integer :object_count, default: 0, index: true, null: false
53
+ t.boolean :banned, default: false, null: false
54
+ t.timestamps
55
+ end
56
+
57
+ add_index :ip_addresses, :ip, unique: true
58
+ end
59
+ end
@@ -0,0 +1,189 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Create tables for Users component
4
+ class CreateUsersComponent < ActiveRecord::Migration[6.0]
5
+ def up
6
+ create_component
7
+ create_users unless User.table_exists?
8
+ create_tokens unless Token.table_exists?
9
+ create_login_attempts unless LoginAttempt.table_exists?
10
+ create_user_languages unless UserLanguage.table_exists?
11
+ create_foreign_sites unless ForeignSite.table_exists?
12
+ create_foreign_users unless ForeignUser.table_exists?
13
+ create_component_links unless BiovisionComponentUser.table_exists?
14
+ create_codes unless Code.table_exists?
15
+ create_notifications unless Notification.table_exists?
16
+ end
17
+
18
+ def down
19
+ drop_table :notifications if Notification.table_exists?
20
+ drop_table :codes if Code.table_exists?
21
+ drop_table :biovision_component_users if BiovisionComponentUser.table_exists?
22
+ drop_table :foreign_users if ForeignUser.table_exists?
23
+ drop_table :foreign_sites if ForeignSite.table_exists?
24
+ drop_table :user_languages if UserLanguage.table_exists?
25
+ drop_table :login_attempts if LoginAttempt.table_exists?
26
+ drop_table :tokens if Token.table_exists?
27
+ drop_table :users if User.table_exists?
28
+ BiovisionComponent[Biovision::Components::UsersComponent.slug]&.destroy
29
+ end
30
+
31
+ private
32
+
33
+ def create_component
34
+ slug = Biovision::Components::UsersComponent.slug
35
+
36
+ settings = {
37
+ registration_open: true,
38
+ email_as_login: false,
39
+ confirm_email: false,
40
+ require_email: false,
41
+ invite_only: false,
42
+ use_invites: false,
43
+ invite_count: 5,
44
+ bounce_count: 10,
45
+ bounce_timeout: 15
46
+ }
47
+
48
+ BiovisionComponent.create(slug: slug, settings: settings)
49
+ end
50
+
51
+ def create_users
52
+ create_table :users, comment: 'Users' do |t|
53
+ t.uuid :uuid, null: false
54
+ t.references :language, foreign_key: { on_update: :cascade, on_delete: :nullify }
55
+ t.references :agent, foreign_key: { on_update: :cascade, on_delete: :nullify }
56
+ t.references :ip_address, foreign_key: { on_update: :cascade, on_delete: :nullify }
57
+ t.timestamps
58
+ t.integer :primary_id, index: true
59
+ t.integer :inviter_id, index: true
60
+ t.integer :balance, default: 0, null: false
61
+ t.boolean :super_user, default: false, null: false
62
+ t.boolean :banned, default: false, null: false
63
+ t.boolean :bot, default: false, null: false
64
+ t.boolean :deleted, default: false, null: false
65
+ t.boolean :consent, default: false, null: false
66
+ t.boolean :email_confirmed, default: false, null: false
67
+ t.boolean :phone_confirmed, default: false, null: false
68
+ t.boolean :allow_mail, default: true, null: false
69
+ t.datetime :last_seen
70
+ t.date :birthday
71
+ t.string :slug, null: false
72
+ t.string :screen_name, null: false
73
+ t.string :password_digest, null: false
74
+ t.string :email, index: true
75
+ t.string :phone, index: true
76
+ t.string :image
77
+ t.string :notice
78
+ t.string :referral_link
79
+ t.jsonb :data, default: { profile: {} }, null: false
80
+ end
81
+
82
+ add_foreign_key :users, :users, column: :inviter_id, on_update: :cascade, on_delete: :nullify
83
+ add_foreign_key :users, :users, column: :primary_id, on_update: :cascade, on_delete: :nullify
84
+
85
+ add_index :users, :uuid, unique: true
86
+ add_index :users, :slug, unique: true
87
+ add_index :users, :data, using: :gin
88
+ add_index :users, :referral_link, unique: true
89
+ end
90
+
91
+ def create_tokens
92
+ create_table :tokens, comment: 'Authentication tokens' do |t|
93
+ t.references :user, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
94
+ t.references :agent, foreign_key: { on_update: :cascade, on_delete: :nullify }
95
+ t.references :ip_address, foreign_key: { on_update: :cascade, on_delete: :nullify }
96
+ t.timestamps
97
+ t.datetime :last_used, index: true
98
+ t.boolean :active, default: true, null: false
99
+ t.string :token, null: false
100
+ end
101
+
102
+ add_index :tokens, :token, unique: true
103
+ end
104
+
105
+ def create_login_attempts
106
+ create_table :login_attempts, comment: 'Failed login attempts' do |t|
107
+ t.references :user, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
108
+ t.references :agent, foreign_key: { on_update: :cascade, on_delete: :nullify }
109
+ t.references :ip_address, foreign_key: { on_update: :cascade, on_delete: :nullify }
110
+ t.timestamps
111
+ t.string :password, default: '', null: false
112
+ end
113
+ end
114
+
115
+ def create_user_languages
116
+ create_table :user_languages, comment: 'Languages for users' do |t|
117
+ t.references :user, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
118
+ t.references :language, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
119
+ t.timestamps
120
+ end
121
+ end
122
+
123
+ def create_foreign_sites
124
+ create_table :foreign_sites, comment: 'Sites for external authentication' do |t|
125
+ t.string :slug, null: false
126
+ t.string :name, null: false
127
+ t.integer :foreign_users_count, default: 0, null: false
128
+ end
129
+
130
+ add_index :foreign_sites, :slug, unique: true
131
+ end
132
+
133
+ def create_foreign_users
134
+ create_table :foreign_users, comment: 'Users from external sites' do |t|
135
+ t.references :foreign_site, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
136
+ t.references :user, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
137
+ t.references :agent, foreign_key: { on_update: :cascade, on_delete: :nullify }
138
+ t.references :ip_address, foreign_key: { on_update: :cascade, on_delete: :nullify }
139
+ t.string :slug, null: false
140
+ t.timestamps
141
+ t.jsonb :data, default: {}, null: false
142
+ end
143
+
144
+ add_index :foreign_users, :data, using: :gin
145
+ end
146
+
147
+ def create_component_links
148
+ create_table :biovision_component_users, comment: 'Privileges and settings for users in components' do |t|
149
+ t.references :biovision_component, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
150
+ t.references :user, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
151
+ t.boolean :administrator, default: false, null: false
152
+ t.timestamps
153
+ t.jsonb :data, default: {}, null: false
154
+ end
155
+
156
+ add_index :biovision_component_users, :data, using: :gin
157
+ end
158
+
159
+ def create_codes
160
+ create_table :codes, comment: 'Codes for different purposes' do |t|
161
+ t.references :biovision_component, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
162
+ t.references :user, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
163
+ t.references :agent, foreign_key: { on_update: :cascade, on_delete: :nullify }
164
+ t.references :ip_address, foreign_key: { on_update: :cascade, on_delete: :nullify }
165
+ t.integer :quantity, default: 1, null: false
166
+ t.string :body, null: false
167
+ t.timestamps
168
+ t.jsonb :data, default: {}, null: false
169
+ end
170
+
171
+ add_index :codes, :body, unique: true
172
+ add_index :codes, :data, using: :gin
173
+ end
174
+
175
+ def create_notifications
176
+ create_table :notifications, comment: 'Component notifications for users' do |t|
177
+ t.uuid :uuid, null: false
178
+ t.references :biovision_component, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
179
+ t.references :user, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
180
+ t.boolean :email_sent, default: false, null: false
181
+ t.boolean :read, default: false, null: false
182
+ t.timestamps
183
+ t.jsonb :data, default: {}, null: false
184
+ end
185
+
186
+ add_index :notifications, :uuid, unique: true
187
+ add_index :notifications, :data, using: :gin
188
+ end
189
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Create tables for simple images
4
+ class CreateSimpleImages < ActiveRecord::Migration[6.0]
5
+ def up
6
+ create_simple_images unless SimpleImage.table_exists?
7
+ create_tags unless SimpleImageTag.table_exists?
8
+ create_tag_links unless SimpleImageTagImage.table_exists?
9
+ end
10
+
11
+ def down
12
+ drop_table :simple_image_tag_images if SimpleImageTagImage.table_exists?
13
+ drop_table :simple_image_tags if SimpleImageTag.table_exists?
14
+ drop_table :simple_images if SimpleImage.table_exists?
15
+ end
16
+
17
+ private
18
+
19
+ def create_simple_images
20
+ create_table :simple_images, comment: 'Universal simple images' do |t|
21
+ t.references :biovision_component, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
22
+ t.references :user, foreign_key: { on_update: :cascade, on_delete: :nullify }
23
+ t.references :agent, foreign_key: { on_update: :cascade, on_delete: :nullify }
24
+ t.references :ip_address, foreign_key: { on_update: :cascade, on_delete: :nullify }
25
+ t.uuid :uuid, null: false
26
+ t.timestamps
27
+ t.integer :object_count, default: 0, null: false
28
+ t.string :image
29
+ t.string :image_alt_text, default: '', null: false
30
+ t.string :caption
31
+ t.string :source_name
32
+ t.string :source_link
33
+ t.jsonb :data, default: {}, null: false
34
+ end
35
+
36
+ add_index :simple_images, :uuid, unique: true
37
+ add_index :simple_images, :data, using: :gin
38
+ end
39
+
40
+ def create_tags
41
+ create_table :simple_image_tags, comment: 'Tags for simple images' do |t|
42
+ t.string :name, null: false, index: true
43
+ t.timestamps
44
+ t.integer :simple_images_count, default: 0, null: false
45
+ end
46
+ end
47
+
48
+ def create_tag_links
49
+ create_table :simple_image_tag_images, comment: 'Links between simple images and tags' do |t|
50
+ t.references :simple_image, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
51
+ t.references :simple_image_tag, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
52
+ end
53
+ end
54
+ end