biovision 0.1.210414.0 → 0.3.210504.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +43 -34
  3. data/app/assets/stylesheets/biovision/admin/components.scss +10 -0
  4. data/app/assets/stylesheets/biovision/admin/components/users.scss +4 -0
  5. data/app/assets/stylesheets/biovision/admin/layout.scss +0 -8
  6. data/app/assets/stylesheets/biovision/biovision.scss +8 -0
  7. data/app/assets/stylesheets/biovision/components.scss +1 -0
  8. data/app/assets/stylesheets/biovision/components/filters.scss +41 -0
  9. data/app/assets/stylesheets/biovision/components/forms.scss +16 -0
  10. data/app/assets/stylesheets/biovision/components/quick_search.scss +24 -0
  11. data/app/assets/stylesheets/biovision/default.scss +4 -4
  12. data/app/assets/stylesheets/biovision/themes/default_theme.scss +0 -1
  13. data/app/assets/stylesheets/biovision/themes/default_theme/layout.scss +6 -3
  14. data/app/assets/stylesheets/biovision/themes/default_theme/layout/footer.scss +3 -0
  15. data/app/assets/stylesheets/biovision/themes/default_theme/layout/header.scss +2 -0
  16. data/app/assets/stylesheets/biovision/vars.scss +5 -0
  17. data/app/controllers/admin/components_controller.rb +25 -79
  18. data/app/controllers/admin/dynamic_pages_controller.rb +1 -1
  19. data/app/controllers/admin/index_controller.rb +8 -2
  20. data/app/controllers/admin/navigation_groups_controller.rb +31 -0
  21. data/app/controllers/admin/tokens_controller.rb +15 -0
  22. data/app/controllers/admin/users_controller.rb +33 -3
  23. data/app/controllers/admin_controller.rb +15 -2
  24. data/app/controllers/concerns/crud_entities.rb +13 -13
  25. data/app/controllers/contact_controller.rb +1 -1
  26. data/app/helpers/biovision_components_helper.rb +7 -3
  27. data/app/lib/biovision/components/base/component_parameters.rb +8 -0
  28. data/app/lib/biovision/components/base/component_privileges.rb +26 -17
  29. data/app/lib/biovision/components/base/component_settings.rb +8 -0
  30. data/app/lib/biovision/components/base_component.rb +20 -23
  31. data/app/lib/biovision/components/contact_component.rb +5 -1
  32. data/app/lib/biovision/components/content_component.rb +36 -10
  33. data/app/lib/biovision/components/track_component.rb +1 -1
  34. data/app/lib/biovision/components/users_component.rb +28 -2
  35. data/app/lib/biovision/helpers/data_helper.rb +43 -0
  36. data/app/lib/biovision/migrations/component_migration.rb +54 -0
  37. data/app/mailers/feedback_mailer.rb +14 -0
  38. data/app/models/biovision_component.rb +3 -0
  39. data/app/models/browser.rb +1 -1
  40. data/app/models/code.rb +2 -2
  41. data/app/models/concerns/tree_structure.rb +2 -1
  42. data/app/models/contact_method.rb +1 -1
  43. data/app/models/contact_type.rb +1 -1
  44. data/app/models/dynamic_block.rb +1 -1
  45. data/app/models/dynamic_page.rb +3 -1
  46. data/app/models/feedback_message.rb +7 -1
  47. data/app/models/feedback_response.rb +2 -2
  48. data/app/models/navigation_group.rb +11 -1
  49. data/app/models/role.rb +44 -6
  50. data/app/models/simple_image.rb +1 -1
  51. data/app/models/simple_image_tag.rb +1 -1
  52. data/app/models/token.rb +6 -2
  53. data/app/models/user.rb +25 -10
  54. data/app/uploaders/simple_file_uploader.rb +1 -1
  55. data/app/views/admin/components/_list.html.erb +1 -1
  56. data/app/views/admin/components/entity/_links.html.erb +31 -21
  57. data/app/views/admin/components/links/_base.html.erb +1 -0
  58. data/app/views/admin/components/settings.html.erb +2 -1
  59. data/app/views/admin/components/settings/_settings.html.erb +3 -3
  60. data/app/views/admin/dynamic_blocks/entity/_in_list.html.erb +6 -4
  61. data/app/views/admin/dynamic_blocks/index.html.erb +5 -3
  62. data/app/views/admin/dynamic_blocks/show.html.erb +6 -4
  63. data/app/views/admin/dynamic_pages/_dynamic_page.jbuilder +18 -0
  64. data/app/views/admin/dynamic_pages/entity/_in_list.html.erb +4 -2
  65. data/app/views/admin/dynamic_pages/entity/_in_search.html.erb +7 -0
  66. data/app/views/admin/dynamic_pages/index.html.erb +11 -4
  67. data/app/views/admin/dynamic_pages/search.jbuilder +4 -0
  68. data/app/views/admin/dynamic_pages/show.html.erb +1 -1
  69. data/app/views/admin/index/index.html.erb +7 -5
  70. data/app/views/admin/navigation_group_pages/entity/_in_list.html.erb +26 -0
  71. data/app/views/admin/navigation_groups/entity/_dynamic_pages.html.erb +38 -0
  72. data/app/views/admin/navigation_groups/entity/_in_list.html.erb +6 -4
  73. data/app/views/admin/navigation_groups/index.html.erb +11 -4
  74. data/app/views/admin/navigation_groups/show.html.erb +16 -3
  75. data/app/views/admin/tokens/_form.html.erb +31 -0
  76. data/app/views/admin/tokens/_nav_item.html.erb +6 -0
  77. data/app/views/admin/tokens/entity/_in_list.html.erb +27 -0
  78. data/app/views/admin/tokens/index.html.erb +16 -0
  79. data/app/views/admin/tokens/show.html.erb +26 -0
  80. data/app/views/admin/users/_user.jbuilder +18 -0
  81. data/app/views/admin/users/entity/_in_list.html.erb +3 -1
  82. data/app/views/admin/users/entity/_in_search.html.erb +18 -0
  83. data/app/views/admin/users/index.html.erb +13 -4
  84. data/app/views/admin/users/roles.html.erb +23 -0
  85. data/app/views/admin/users/roles/_component.html.erb +22 -0
  86. data/app/views/admin/users/search.jbuilder +4 -0
  87. data/app/views/admin/users/show.html.erb +14 -2
  88. data/app/views/admin/widgets/_filters.html.erb +15 -0
  89. data/app/views/admin/widgets/_quick_search.html.erb +13 -0
  90. data/app/views/admin/widgets/filters/_flag.html.erb +15 -0
  91. data/app/views/components/content/_dynamic_page.html.erb +6 -10
  92. data/app/views/components/content/_dynamic_page_content.html.erb +14 -0
  93. data/app/views/contact/_form.html.erb +1 -1
  94. data/app/views/feedback_mailer/new_feedback_request.html.erb +11 -0
  95. data/app/views/feedback_mailer/new_feedback_request.text.erb +6 -0
  96. data/app/views/index/index.html.erb +14 -0
  97. data/app/views/layouts/admin.html.erb +0 -1
  98. data/app/views/layouts/application/_footer.html.erb +1 -1
  99. data/app/views/my/index/index.html.erb +26 -0
  100. data/app/views/shared/entity/_time_field.html.erb +6 -0
  101. data/app/views/shared/entity/_track.html.erb +12 -0
  102. data/app/views/shared/entity/_tree_caches.html.erb +8 -1
  103. data/app/views/shared/entity/edit.html.erb +5 -3
  104. data/app/views/shared/forms/_simple_image.html.erb +12 -4
  105. data/config/locales/biovision-ru.yml +14 -1
  106. data/config/locales/components-ru.yml +4 -2
  107. data/config/locales/contact-ru.yml +4 -0
  108. data/config/locales/content-ru.yml +4 -0
  109. data/config/locales/users-ru.yml +27 -5
  110. data/config/routes.rb +14 -4
  111. data/db/migrate/20191228000000_create_biovision_components.rb +2 -0
  112. data/db/migrate/20200224000000_create_track_component.rb +8 -12
  113. data/db/migrate/20200224000010_create_users_component.rb +10 -40
  114. data/db/migrate/20210405000000_create_acl.rb +15 -0
  115. data/db/migrate/{20200529000000_create_content_component.rb → 20210421000000_create_content_component.rb} +3 -18
  116. data/db/migrate/{20210401000000_create_contact_component.rb → 20210421000010_create_contact_component.rb} +1 -22
  117. data/lib/biovision/version.rb +1 -1
  118. metadata +34 -13
  119. data/app/lib/biovision/components/base/privilege_handler.rb +0 -79
  120. data/app/views/admin/components/links/_content.html.erb +0 -9
  121. data/app/views/admin/components/links/_track.html.erb +0 -2
  122. data/app/views/admin/components/links/_users.html.erb +0 -4
  123. data/app/views/admin/components/links/extra/_content.html.erb +0 -0
  124. data/app/views/admin/components/privileges.html.erb +0 -20
  125. data/app/views/admin/components/privileges/_component_user.html.erb +0 -17
  126. data/app/views/admin/components/privileges/_links.html.erb +0 -17
  127. data/app/views/admin/components/privileges/_users.html.erb +0 -23
@@ -0,0 +1,14 @@
1
+ <% unless entity.simple_image.nil? %>
2
+ <figure><%= simple_image_hd(entity) %></figure>
3
+ <% end %>
4
+
5
+ <h1><%= entity.meta('heading') %></h1>
6
+
7
+ <% if content_component.permit?('edit', entity) %>
8
+ <nav class="entity-actions">
9
+ <%= gear_icon(entity) %>
10
+ <%= edit_icon(entity) %>
11
+ </nav>
12
+ <% end %>
13
+
14
+ <div class="text"><%= raw(entity.body) %></div>
@@ -100,7 +100,7 @@
100
100
  <%= button_tag(t('.submit'), class: 'button button-primary') %>
101
101
  </div>
102
102
  </div>
103
- <div class="state-2">
103
+ <div class="state-2 hidden">
104
104
  <div class="result">
105
105
  <p><%= raw message %></p>
106
106
  </div>
@@ -0,0 +1,11 @@
1
+ <h1><%= t('.title') %></h1>
2
+
3
+ <dl>
4
+ <% %w[name email phone comment attachment].each do |attribute| %>
5
+ <% next if @entity.attributes[attribute].blank? %>
6
+ <div>
7
+ <dt><%= @entity.class.human_attribute_name(attribute) %></dt>
8
+ <dd><%= @entity.attributes[attribute] %></dd>
9
+ </div>
10
+ <% end %>
11
+ </dl>
@@ -0,0 +1,6 @@
1
+ <%= t('.title') %>
2
+
3
+ <% %w[name email phone comment attachment].each do |a| %>
4
+ <% next if @entity.attributes[a].blank? %>
5
+ <%= @entity.class.human_attribute_name(a) %>: <%= @entity.attributes[a] %>
6
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <%= render partial: 'shared/entity/metadata', locals: { entity: @dynamic_page } %>
2
+
3
+ <article class="frontpage">
4
+ <div class="content-wrapper">
5
+ <% unless @dynamic_page.blank? %>
6
+ <%=
7
+ render(
8
+ partial: 'components/content/dynamic_page_content',
9
+ locals: { entity: @dynamic_page }
10
+ )
11
+ %>
12
+ <% end %>
13
+ </div>
14
+ </article>
@@ -10,7 +10,6 @@
10
10
  </head>
11
11
  <body>
12
12
  <%= render 'layouts/admin/header' %>
13
- <%= controller_name %>/<%= action_name %>
14
13
  <main id="main">
15
14
  <%= render 'shared/flash_messages' %>
16
15
  <%= render 'layouts/admin/breadcrumbs' %>
@@ -1,7 +1,7 @@
1
1
  <footer class="main-footer">
2
2
  <div class="content-wrapper">
3
3
  <div class="copyright">&copy; <%= t(:copyright) %></div>
4
- <% if Biovision::Components::BaseComponent.privileged?(current_user) %>
4
+ <% if current_user&.role?('base.admin') %>
5
5
  <%= link_to(t('admin.index.index.nav_text'), admin_path) %>
6
6
  <% end %>
7
7
  </div>
@@ -29,5 +29,31 @@
29
29
  class: 'button button-ghost'
30
30
  )
31
31
  %>
32
+ <% if current_user.role?('base.admin') %>
33
+ <%=
34
+ link_to(
35
+ t('admin.index.index.nav_text'),
36
+ admin_path,
37
+ class: 'button button-secondary'
38
+ )
39
+ %>
40
+ <% end %>
32
41
  </nav>
42
+
43
+ <% prefix = 'my/components/' %>
44
+ <% BiovisionComponent.list_for_user.each do |component| %>
45
+ <% handler = Biovision::Components::BaseComponent.handler(component, current_user) %>
46
+ <% next unless handler&.permit?('default') %>
47
+ <% if lookup_context.exists?("#{prefix}_#{component.slug}") %>
48
+ <section>
49
+ <h2><%= component.name %></h2>
50
+ <%=
51
+ render(
52
+ partial: "#{prefix}#{component.slug}",
53
+ locals: { user: @entity, handler: handler }
54
+ )
55
+ %>
56
+ </section>
57
+ <% end %>
58
+ <% end %>
33
59
  </article>
@@ -0,0 +1,6 @@
1
+ <% unless entity.attributes[field.to_s].nil? %>
2
+ <div>
3
+ <dt><%= entity.class.human_attribute_name(field) %></dt>
4
+ <dd><%= time_tag entity.attributes[field.to_s] %></dd>
5
+ </div>
6
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <% unless entity.ip_address.blank? %>
2
+ <div>
3
+ <dt><%= entity.class.human_attribute_name(:ip_address) %></dt>
4
+ <dd><%= entity.ip_address.ip %></dd>
5
+ </div>
6
+ <% end %>
7
+ <% unless entity.agent.blank? %>
8
+ <div>
9
+ <dt><%= entity.class.human_attribute_name(:agent) %></dt>
10
+ <dd><%= entity.agent.name %></dd>
11
+ </div>
12
+ <% end %>
@@ -7,6 +7,13 @@
7
7
  <% unless entity.children_cache.blank? %>
8
8
  <div>
9
9
  <dt><%= entity.class.human_attribute_name(:children_cache) %></dt>
10
- <dd><%= entity.children_cache.join(', ') %></dd>
10
+ <dd>
11
+ <details>
12
+ <summary><%= t(:object_count, count: entity.children_cache.count) %></summary>
13
+ <div class="secondary-data">
14
+ <%= entity.children_cache.join(', ') %>
15
+ </div>
16
+ </details>
17
+ </dd>
11
18
  </div>
12
19
  <% end %>
@@ -13,9 +13,11 @@
13
13
  <article>
14
14
  <h1><%= t("#{prefix}.edit.heading", default: default_title) %></h1>
15
15
 
16
- <nav class="entity-actions">
17
- <%= destroy_icon(@entity) %>
18
- </nav>
16
+ <% if component_handler.permit?('edit', @entity) %>
17
+ <nav class="entity-actions">
18
+ <%= destroy_icon(@entity) %>
19
+ </nav>
20
+ <% end %>
19
21
 
20
22
  <%= render partial: "#{controller_path}/form", locals: { entity: @entity } %>
21
23
  </article>
@@ -23,15 +23,23 @@
23
23
  </figure>
24
24
  <div class="js-change" data-url="<%= handler_url %>">
25
25
  <div class="buttons">
26
- <button class="button button-ghost js-new-image" type="button">
27
- <%= t('.new_image') %>
28
- </button>
26
+ <label class="button button-ghost js-new-image">
27
+ <%=
28
+ file_field_tag(
29
+ nil,
30
+ accept: 'image/jpeg,image/png,image/svg+xml',
31
+ class: 'input-text visually-hidden'
32
+ )
33
+ %>
34
+ <span><%= t('.new_image') %></span>
35
+ </label>
36
+
29
37
  <button class="button button-ghost js-select-image" type="button">
30
38
  <%= t('.select') %>
31
39
  </button>
32
40
  </div>
33
41
  <%= render 'shared/forms/simple_image/browse' %>
34
- <%= render 'shared/forms/simple_image/load_image' %>
42
+ <%#= render 'shared/forms/simple_image/load_image' %>
35
43
  </div>
36
44
  <%= f.hidden_field(:simple_image_id) %>
37
45
  </div>
@@ -27,6 +27,7 @@ ru:
27
27
  keywords: "Ключевые слова"
28
28
  title: "Заголовок окна (title)"
29
29
  name: "Название"
30
+ nav_text: "Текст для ссылки"
30
31
  object_count: "Количество объектов"
31
32
  parent: "Родитель"
32
33
  parent_id: "Родитель"
@@ -69,7 +70,7 @@ ru:
69
70
  previous: "←"
70
71
  next: "→"
71
72
  truncate: "…"
72
- copyright: "2020 example.com"
73
+ copyright: "2021 example.com"
73
74
  home: "Главная"
74
75
  application:
75
76
  errors:
@@ -93,11 +94,23 @@ ru:
93
94
  unauthorized:
94
95
  heading: "Не хватает прав"
95
96
  message: "У вас не хватает прав для просмотра этой страницы"
97
+ missing_role: "У вас не хватает роли %{role} для просмотра этой страницы"
96
98
  index:
97
99
  index:
98
100
  nav_text: "Администрирование"
99
101
  title: "Администрирование"
100
102
  heading: "Администрирование"
103
+ widgets:
104
+ quick_search:
105
+ heading: "Быстрый поиск"
106
+ search_string: "Строка поиска"
107
+ filters:
108
+ apply: "Применить"
109
+ flag:
110
+ any: "Неважно"
111
+ set: "Да"
112
+ unset: "Нет"
113
+ heading: "Фильтры"
101
114
  layouts:
102
115
  admin:
103
116
  footer:
@@ -71,8 +71,6 @@ ru:
71
71
  privileges:
72
72
  nav_text: "Привилегии"
73
73
  title: "Привилении компонента «%{slug}»"
74
- users:
75
- heading: "Привилегии"
76
74
  settings:
77
75
  nav_text: "Настройки"
78
76
  title: "Настройки компонента «%{slug}»"
@@ -107,3 +105,7 @@ ru:
107
105
  select: "Выбрать"
108
106
  browse:
109
107
  filter: "Фильтр по названию или имени файла"
108
+ biovision:
109
+ components:
110
+ base:
111
+ name: "Базовый компонент"
@@ -104,3 +104,7 @@ ru:
104
104
  index:
105
105
  nav_text: "Контакты"
106
106
  title: "Контакты"
107
+ feedback_mailer:
108
+ new_feedback_request:
109
+ subject: "Новый запрос обратной связи"
110
+ title: "Поступил новый запрос на обратную связь"
@@ -82,6 +82,10 @@ ru:
82
82
  title: "Добавление группы навигации"
83
83
  nav_text: "Создать"
84
84
  heading: "Новая группа навигации"
85
+ entity:
86
+ dynamic_pages:
87
+ heading: "Ссылки"
88
+ add: "Добавить страницу"
85
89
  biovision:
86
90
  components:
87
91
  content:
@@ -109,11 +109,14 @@ ru:
109
109
  bounce_count: "Максимальное количество неудачных попыток входа"
110
110
  bounce_timeout: "Тайм-аут для запрета повторных попыток входа"
111
111
  confirm_email: "Отправлять письмо для подтверждения почты"
112
+ confirm_phone: "Отправлять SMS для подтверждения телефона"
112
113
  email_as_login: "Использовать электронную почту в качестве логина"
113
114
  invite_count: "Количество кодов приглашения после регистрации"
114
115
  invite_only: "Только по приглашениям"
116
+ phone_as_login: "Использовать телефон в качестве логина"
115
117
  registration_open: "Регистрация открыта"
116
118
  require_email: "Электронная почта обязательна при регистрации"
119
+ require_phone: "Телефон обязателен при регистрации"
117
120
  use_invites: "Использовать приглашения"
118
121
  use_phone: "Использовать номер телефона"
119
122
  anonymous: "Анонимно"
@@ -224,18 +227,37 @@ ru:
224
227
  use_invites: "Использовать пришлашения"
225
228
  use_phone: "Использовать телефон"
226
229
  admin:
227
- users:
230
+ tokens:
231
+ destroy:
232
+ success: "Жетон пользователя удалён"
233
+ index:
234
+ title: "Жетоны пользователей, страница %{page}"
235
+ heading: "Жетоны пользователей"
228
236
  nav_item:
229
- description: "Управление пользователями сайта"
230
- text: "Список пользователей"
237
+ description: "Управление жетонами пользователей сайта"
238
+ text: "Жетоны доступа (сессии)"
239
+ show:
240
+ title: "Жетон доступа №%{id}"
241
+ users:
242
+ destroy:
243
+ success: "Пользователь удалён"
231
244
  index:
232
245
  title: "Пользователи, страница %{page}"
233
246
  heading: "Пользователи"
247
+ nav_item:
248
+ description: "Управление пользователями сайта"
249
+ text: "Список пользователей"
250
+ roles:
251
+ nav_text: "Роли"
252
+ title: "Роли пользователя %{user}"
253
+ heading: "Роли и группы в компонентах"
234
254
  show:
235
255
  title: "Пользователь %{name}"
236
256
  deleted: "Пользователь удалён"
237
- destroy:
238
- success: "Пользователь удалён"
257
+ tokens:
258
+ nav_text: "Жетоны"
259
+ title: "Жетоны доступа пользователя %{user}"
260
+ heading: "Жетоны доступа"
239
261
  users:
240
262
  profile:
241
263
  registration_date: "Дата регистрации"
data/config/routes.rb CHANGED
@@ -13,6 +13,10 @@ Rails.application.routes.draw do
13
13
  post :toggle, on: :member, defaults: { format: :json }
14
14
  end
15
15
 
16
+ concern :search do
17
+ get :search, on: :collection
18
+ end
19
+
16
20
  # Handling errors
17
21
  match '/400' => 'errors#bad_request', via: :all
18
22
  match '/401' => 'errors#unauthorized', via: :all
@@ -58,8 +62,6 @@ Rails.application.routes.draw do
58
62
  get 'settings' => :settings, as: :component_settings
59
63
  patch 'settings' => :update_settings, as: nil
60
64
  patch 'parameters' => :update_parameter, as: :component_parameters
61
- get 'privileges' => :privileges, as: :component_privileges
62
- patch 'privileges' => :update_privileges, as: nil
63
65
  put 'administrators/:user_id' => :add_administrator, as: :component_administrators
64
66
  delete 'administrators/:user_id' => :remove_administrator, as: nil
65
67
  get 'images' => :images, as: :component_images
@@ -72,7 +74,7 @@ Rails.application.routes.draw do
72
74
  resources :agents, :ip_addresses, only: :index
73
75
 
74
76
  # Content component
75
- resources :dynamic_pages, :dynamic_blocks, concerns: %i[check toggle]
77
+ resources :dynamic_pages, :dynamic_blocks, concerns: %i[check search toggle]
76
78
  resources :navigation_groups, concerns: :check do
77
79
  member do
78
80
  put 'dynamic_pages/:page_id' => :add_page, as: :dynamic_page
@@ -81,7 +83,15 @@ Rails.application.routes.draw do
81
83
  end
82
84
  end
83
85
 
84
- resources :users, concerns: %i[check toggle]
86
+ # Users component
87
+ resources :users, concerns: %i[check search toggle] do
88
+ member do
89
+ get 'roles'
90
+ put 'roles/:role_id' => :add_role, as: :role
91
+ delete 'roles/:role_id' => :remove_role
92
+ end
93
+ end
94
+ resources :tokens, concerns: %i[toggle]
85
95
  end
86
96
 
87
97
  namespace :my do
@@ -7,6 +7,8 @@ class CreateBiovisionComponents < ActiveRecord::Migration[6.0]
7
7
  create_metrics unless Metric.table_exists?
8
8
  create_metric_values unless MetricValue.table_exists?
9
9
  create_languages unless Language.table_exists?
10
+
11
+ Biovision::Components::BaseComponent.create
10
12
  end
11
13
 
12
14
  def down
@@ -1,21 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Create entry and tables for track component
4
- class CreateTrackComponent < ActiveRecord::Migration[6.0]
5
- def up
6
- BiovisionComponent.create(slug: Biovision::Components::TrackComponent.slug)
4
+ class CreateTrackComponent < ActiveRecord::Migration[6.1]
5
+ include Biovision::Migrations::ComponentMigration
7
6
 
8
- create_browsers unless Browser.table_exists?
9
- create_agents unless Agent.table_exists?
10
- create_ip_addresses unless IpAddress.table_exists?
11
- end
7
+ def up
8
+ component.create
9
+ component.dependent_models.each do |model|
10
+ next if model.table_exists?
12
11
 
13
- def down
14
- Biovision::Components::TrackComponent.dependent_models.each do |model|
15
- drop_table model.table_name if model.table_exists?
12
+ message = "create_#{model.table_name}".to_sym
13
+ send(message) if respond_to?(message, true)
16
14
  end
17
-
18
- BiovisionComponent[Biovision::Components::TrackComponent]&.destroy
19
15
  end
20
16
 
21
17
  private
@@ -1,50 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Create tables for Users component
4
- class CreateUsersComponent < ActiveRecord::Migration[6.0]
4
+ class CreateUsersComponent < ActiveRecord::Migration[6.1]
5
+ include Biovision::Migrations::ComponentMigration
6
+
5
7
  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_component_links unless BiovisionComponentUser.table_exists?
12
- create_codes unless Code.table_exists?
13
- create_notifications unless Notification.table_exists?
14
- end
8
+ component.create
9
+ component.dependent_models.each do |model|
10
+ next if model.table_exists?
15
11
 
16
- def down
17
- Biovision::Components::UsersComponent.dependent_models.each do |model|
18
- drop_table model.table_name if model.table_exists?
12
+ message = "create_#{model.table_name}".to_sym
13
+ send(message) if respond_to?(message, true)
19
14
  end
20
-
21
- BiovisionComponent[Biovision::Components::UsersComponent]&.destroy
22
15
  end
23
16
 
24
17
  private
25
18
 
26
- def create_component
27
- slug = Biovision::Components::UsersComponent.slug
28
-
29
- settings = {
30
- registration_open: true,
31
- email_as_login: false,
32
- phone_as_login: false,
33
- confirm_email: false,
34
- require_email: false,
35
- confirm_phone: false,
36
- require_phone: false,
37
- invite_only: false,
38
- use_invites: false,
39
- invite_count: 5,
40
- bounce_count: 10,
41
- bounce_timeout: 3,
42
- use_phone: false
43
- }
44
-
45
- BiovisionComponent.create(slug: slug, settings: settings)
46
- end
47
-
48
19
  def create_users
49
20
  create_table :users, comment: 'Users' do |t|
50
21
  t.uuid :uuid, null: false
@@ -117,11 +88,10 @@ class CreateUsersComponent < ActiveRecord::Migration[6.0]
117
88
  end
118
89
  end
119
90
 
120
- def create_component_links
121
- create_table :biovision_component_users, comment: 'Privileges and settings for users in components' do |t|
91
+ def create_biovision_component_users
92
+ create_table :biovision_component_users, comment: 'Settings for users in components' do |t|
122
93
  t.references :biovision_component, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
123
94
  t.references :user, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
124
- t.boolean :administrator, default: false, null: false
125
95
  t.timestamps
126
96
  t.jsonb :data, default: {}, null: false
127
97
  end