biovision-post 0.21.190513.0 → 0.26.191013.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/biovision_post_manifest.js +1 -0
  3. data/app/assets/images/biovision/post/icons/comment.svg +9 -0
  4. data/app/assets/javascripts/biovision/post/biovision-posts.js +21 -28
  5. data/app/assets/stylesheets/biovision/post/posts.scss +6 -0
  6. data/app/controllers/admin/editorial_members_controller.rb +9 -4
  7. data/app/controllers/admin/featured_posts_controller.rb +9 -4
  8. data/app/controllers/admin/post_categories_controller.rb +12 -6
  9. data/app/controllers/admin/post_group_categories_controller.rb +9 -4
  10. data/app/controllers/admin/post_group_tags_controller.rb +9 -4
  11. data/app/controllers/admin/post_groups_controller.rb +9 -4
  12. data/app/controllers/admin/post_illustrations_controller.rb +9 -4
  13. data/app/controllers/admin/post_images_controller.rb +9 -4
  14. data/app/controllers/admin/post_links_controller.rb +9 -4
  15. data/app/controllers/admin/post_tags_controller.rb +9 -4
  16. data/app/controllers/admin/post_types_controller.rb +13 -4
  17. data/app/controllers/admin/posts_controller.rb +6 -8
  18. data/app/controllers/articles_controller.rb +16 -6
  19. data/app/controllers/authors_controller.rb +9 -4
  20. data/app/controllers/blog_posts_controller.rb +16 -6
  21. data/app/controllers/editorial_members_controller.rb +9 -4
  22. data/app/controllers/featured_posts_controller.rb +6 -1
  23. data/app/controllers/my/posts_controller.rb +35 -38
  24. data/app/controllers/news_controller.rb +16 -6
  25. data/app/controllers/post_attachments_controller.rb +36 -0
  26. data/app/controllers/post_categories_controller.rb +6 -1
  27. data/app/controllers/post_groups_controller.rb +9 -4
  28. data/app/controllers/post_illustrations_controller.rb +6 -1
  29. data/app/controllers/post_images_controller.rb +9 -8
  30. data/app/controllers/post_links_controller.rb +5 -2
  31. data/app/controllers/post_tags_controller.rb +9 -4
  32. data/app/controllers/posts_controller.rb +39 -17
  33. data/app/helpers/biovision_posts_helper.rb +28 -27
  34. data/app/jobs/post_body_parser_job.rb +1 -1
  35. data/app/models/concerns/post_child_with_priority.rb +2 -1
  36. data/app/models/editorial_member.rb +10 -1
  37. data/app/models/post.rb +39 -11
  38. data/app/models/post_attachment.rb +49 -0
  39. data/app/models/post_category.rb +6 -0
  40. data/app/models/post_group_category.rb +1 -1
  41. data/app/models/post_illustration.rb +2 -1
  42. data/app/models/post_image.rb +2 -1
  43. data/app/models/post_type.rb +15 -0
  44. data/app/services/biovision/components/posts_component.rb +65 -0
  45. data/app/views/admin/components/links/_posts.html.erb +33 -0
  46. data/app/views/admin/editorial_members/index.html.erb +2 -1
  47. data/app/views/admin/editorial_members/show.html.erb +1 -0
  48. data/app/views/admin/featured_posts/index.html.erb +1 -0
  49. data/app/views/admin/post_categories/entity/_in_list.html.erb +10 -0
  50. data/app/views/admin/post_categories/show.html.erb +11 -0
  51. data/app/views/admin/post_groups/index.html.erb +2 -1
  52. data/app/views/admin/post_groups/show.html.erb +1 -0
  53. data/app/views/admin/post_illustrations/index.html.erb +1 -0
  54. data/app/views/admin/post_illustrations/show.html.erb +1 -0
  55. data/app/views/admin/post_images/index.html.erb +2 -1
  56. data/app/views/admin/post_images/show.html.erb +1 -0
  57. data/app/views/admin/post_tags/index.html.erb +2 -1
  58. data/app/views/admin/post_tags/posts.html.erb +4 -3
  59. data/app/views/admin/post_tags/show.html.erb +3 -2
  60. data/app/views/admin/post_types/authors.html.erb +1 -0
  61. data/app/views/admin/post_types/index.html.erb +2 -1
  62. data/app/views/admin/post_types/new_post.html.erb +13 -4
  63. data/app/views/admin/post_types/post_categories.html.erb +1 -0
  64. data/app/views/admin/post_types/post_tags.html.erb +4 -3
  65. data/app/views/admin/post_types/show.html.erb +3 -2
  66. data/app/views/admin/posts/entity/_in_list.html.erb +3 -3
  67. data/app/views/admin/posts/images.html.erb +1 -0
  68. data/app/views/admin/posts/index.html.erb +2 -1
  69. data/app/views/admin/posts/search.html.erb +10 -1
  70. data/app/views/admin/posts/show.html.erb +6 -7
  71. data/app/views/authors/show.html.erb +1 -1
  72. data/app/views/blog_posts/index.html.erb +4 -2
  73. data/app/views/editorial_members/edit.html.erb +1 -0
  74. data/app/views/editorial_members/new.html.erb +3 -2
  75. data/app/views/my/index/dashboard/_biovision_post.html.erb +5 -4
  76. data/app/views/my/posts/_form.html.erb +40 -194
  77. data/app/views/my/posts/_post.html.erb +2 -3
  78. data/app/views/my/posts/articles.html.erb +1 -1
  79. data/app/views/my/posts/blog_posts.html.erb +1 -1
  80. data/app/views/my/posts/index/_navigation.html.erb +3 -3
  81. data/app/views/my/posts/new.html.erb +9 -1
  82. data/app/views/my/posts/news_index.html.erb +1 -1
  83. data/app/views/posts/_breadcrumbs.html.erb +1 -6
  84. data/app/views/posts/_form.html.erb +9 -2
  85. data/app/views/posts/_post.html.erb +7 -11
  86. data/app/views/posts/_preview.html.erb +7 -1
  87. data/app/views/posts/edit.html.erb +9 -1
  88. data/app/views/posts/post_type/_category.html.erb +4 -2
  89. data/app/views/posts/post_type/_post_page.html.erb +7 -1
  90. data/app/views/posts/post_type/_posts.html.erb +11 -2
  91. data/app/views/posts/post_type/_tagged.html.erb +4 -4
  92. data/app/views/posts/rss.xml.erb +1 -1
  93. data/app/views/posts/show.html.erb +0 -5
  94. data/app/views/posts/zen.xml.erb +3 -3
  95. data/config/locales/posts-ru.yml +11 -1
  96. data/config/routes.rb +3 -0
  97. data/db/{migrate → amends}/20190202232323_add_spam_to_posts.rb +0 -0
  98. data/db/{migrate → amends}/20190224212121_add_data_to_posts.rb +0 -0
  99. data/db/{migrate → amends}/20190224212122_rename_post_image_source.rb +0 -0
  100. data/db/{migrate → amends}/20190224212123_add_uuid_to_post_images.rb +0 -0
  101. data/db/{migrate → amends}/20190313141414_convert_json_post_columns.rb +0 -0
  102. data/db/amends/20190925181818_add_search_index_to_posts.rb +24 -0
  103. data/db/migrate/20170930000001_create_post_types.rb +4 -13
  104. data/db/migrate/20170930000010_create_posts.rb +26 -3
  105. data/db/migrate/20190715141414_add_data_to_post_categories.rb +14 -0
  106. data/db/migrate/20190801161616_add_posts_component.rb +14 -0
  107. data/db/migrate/20190822121212_create_post_attachments.rb +20 -0
  108. data/db/migrate/20190914212121_convert_post_privileges.rb +56 -0
  109. data/lib/biovision/post/version.rb +1 -1
  110. metadata +18 -13
  111. data/app/services/post_manager.rb +0 -71
  112. data/app/views/admin/index/dashboard/_biovision_post.html.erb +0 -36
  113. data/app/views/articles/show.html.erb +0 -6
  114. data/app/views/blog_posts/show.html.erb +0 -6
  115. data/app/views/news/show.html.erb +0 -6
@@ -1,10 +1,9 @@
1
- <% handler = PostManager.new(post) %>
2
1
  <article class="post" itemscope itemtype="http://schema.org/Article" itemprop="mainEntityOfPage">
3
2
  <h1 itemprop="headline"><%= post.title %></h1>
4
3
  <ul class="actions">
5
4
  <li><%= back_icon(my_posts_path) %></li>
6
5
  <% if post.visible? %>
7
- <li><%= world_icon(handler.post_path) %></li>
6
+ <li><%= world_icon(post.url) %></li>
8
7
  <% end %>
9
8
  <% unless post.locked? %>
10
9
  <li><%= edit_icon(edit_my_post_path(id: post.id)) %></li>
@@ -38,7 +37,7 @@
38
37
  <% end %>
39
38
 
40
39
  <div class="body" itemprop="articleBody mainEntityOfPage">
41
- <%= raw(post.parsed_body || post.body) %>
40
+ <%= raw(post.body) %>
42
41
  </div>
43
42
 
44
43
  <% if post.tags_cache.any? %>
@@ -6,7 +6,7 @@
6
6
  <article>
7
7
  <h1><%= t('.heading') %></h1>
8
8
 
9
- <% if current_user_has_privilege?(:editor) %>
9
+ <% if component_handler.allow_post_type?('article') %>
10
10
  <nav>
11
11
  <%=
12
12
  link_to(
@@ -6,7 +6,7 @@
6
6
  <article>
7
7
  <h1><%= t('.heading') %></h1>
8
8
 
9
- <% if current_user_has_privilege?(:blogger) %>
9
+ <% if component_handler.allow_post_type?('blog_post') %>
10
10
  <nav>
11
11
  <%=
12
12
  link_to(
@@ -1,5 +1,5 @@
1
1
  <nav>
2
- <% if current_user_has_privilege?(:editor) %>
2
+ <% if component_handler.allow_post_type?('article') %>
3
3
  <%=
4
4
  link_to(
5
5
  t('my.posts.new_article.nav_text'),
@@ -8,7 +8,7 @@
8
8
  )
9
9
  %>
10
10
  <% end %>
11
- <% if current_user_has_privilege?(:reporter) %>
11
+ <% if component_handler.allow_post_type?('news') %>
12
12
  <%=
13
13
  link_to(
14
14
  t('my.posts.new_news.nav_text'),
@@ -17,7 +17,7 @@
17
17
  )
18
18
  %>
19
19
  <% end %>
20
- <% if current_user_has_privilege?(:blogger) %>
20
+ <% if component_handler.allow_post_type?('blog_post') %>
21
21
  <%=
22
22
  link_to(
23
23
  t('my.posts.new_blog_post.nav_text'),
@@ -10,5 +10,13 @@
10
10
  <li><%= return_icon(my_posts_path) %></li>
11
11
  </ul>
12
12
 
13
- <%= render partial: 'form', locals: { entity: @entity } %>
13
+ <%=
14
+ render(
15
+ partial: 'form',
16
+ locals: {
17
+ entity: @entity,
18
+ handler: component_handler
19
+ }
20
+ )
21
+ %>
14
22
  </article>
@@ -6,7 +6,7 @@
6
6
  <article>
7
7
  <h1><%= t('.heading') %></h1>
8
8
 
9
- <% if current_user_has_privilege?(:reporter) %>
9
+ <% if component_handler.allow_post_type?('news') %>
10
10
  <nav>
11
11
  <%=
12
12
  link_to(
@@ -1,7 +1,2 @@
1
- <% unless entity.post_category.blank? %>
2
- <% entity.post_category.parents.each do |parent| %>
3
- <%= post_category_link(parent) %>
4
- <% end %>
5
- <%= post_category_link(entity.post_category) %>
6
- <% end %>
1
+ <%= post_type_link(entity.post_type) %>
7
2
  <span><%= entity.title %></span>
@@ -1,4 +1,5 @@
1
1
  <%
2
+ handler ||= Biovision::Components::BaseComponent.handler('post', current_user)
2
3
  model_name = entity.class.to_s.underscore
3
4
  languages = Language.active
4
5
  %>
@@ -6,7 +7,7 @@
6
7
  <%= render partial: 'shared/list_of_errors', locals: { entity: entity } %>
7
8
 
8
9
  <dl>
9
- <% if current_user_has_privilege?(:chief_editor) %>
10
+ <% if handler.allow?('chief_editor') %>
10
11
  <dt><%= t('activerecord.attributes.post.user') %></dt>
11
12
  <dd>
12
13
  <div>
@@ -364,7 +365,7 @@
364
365
  <div class="guideline"><%= t('.guidelines.meta_keywords') %></div>
365
366
  </dd>
366
367
 
367
- <% if current_user_has_privilege?(:chief_editor) %>
368
+ <% if handler.allow?('chief_editor', 'deputy_chief_editor') %>
368
369
  <dt><%= f.label :rating %></dt>
369
370
  <dd>
370
371
  <%=
@@ -381,6 +382,12 @@
381
382
  <dt><%= t(:flags) %></dt>
382
383
  <dd>
383
384
  <ul class="flags">
385
+ <% if entity.id.nil? && handler.allow?('chief_editor', 'deputy_chief_editor') %>
386
+ <li>
387
+ <%= check_box_tag :featured, '1' %>
388
+ <%= label_tag :featured, t('activerecord.models.featured_post') %>
389
+ </li>
390
+ <% end %>
384
391
  <li>
385
392
  <%= f.check_box :visible, id: "#{model_name}_visible" %>
386
393
  <%= f.label :visible %>
@@ -1,19 +1,15 @@
1
- <% handler = PostManager.new(post) %>
1
+ <% handler = Biovision::Components::BaseComponent.handler('posts', current_user) %>
2
2
  <article class="post" itemscope itemtype="http://schema.org/Article" itemprop="mainEntityOfPage">
3
3
  <h1 itemprop="headline"><%= post.title %></h1>
4
- <% if post.editable_by? current_user %>
4
+ <% if handler.editable?(post) %>
5
5
  <ul class="actions">
6
- <% if post.owned_by?(current_user) %>
7
- <li><%= gear_icon(my_post_path(id: post.id)) %></li>
8
- <% elsif UserPrivilege.user_in_group?(current_user, :editors) %>
6
+ <% if handler.group?(:chief) %>
9
7
  <li><%= gear_icon(admin_post_path(id: post.id)) %></li>
8
+ <% elsif post.owned_by?(current_user) %>
9
+ <li><%= gear_icon(my_post_path(id: post.id)) %></li>
10
10
  <% end %>
11
11
  <% unless post.locked? %>
12
- <% if post.owned_by?(current_user) %>
13
- <li><%= edit_icon(edit_my_post_path(id: post.id)) %></li>
14
- <% else %>
15
- <li><%= edit_icon(handler.edit_path) %></li>
16
- <% end %>
12
+ <li><%= edit_icon(handler.edit_path(post)) %></li>
17
13
  <% end %>
18
14
  </ul>
19
15
  <% end %>
@@ -50,7 +46,7 @@
50
46
  <div class="lead"><%= post.lead %></div>
51
47
 
52
48
  <div class="body">
53
- <%= raw(post.parsed_body || post.body) %>
49
+ <%= raw(post.body) %>
54
50
  </div>
55
51
  </div>
56
52
 
@@ -24,7 +24,13 @@
24
24
  <%= time_tag(entity.publication_time.to_date, format: :default) %>
25
25
  </div>
26
26
  <div class="category" aria-label="<%= t('activerecord.attributes.post.post_category_id') %>">
27
- <%= post_category_link(entity) %>
27
+ <% if entity.post_categories.any? %>
28
+ <% entity.post_categories.each do |category| %>
29
+ <%= post_category_link(category) %>
30
+ <% end %>
31
+ <% else %>
32
+ <%= post_type_link(entity.post_type) %>
33
+ <% end %>
28
34
  </div>
29
35
  <% if entity.tags_cache.any? %>
30
36
  <ul class="post-tags">
@@ -8,5 +8,13 @@
8
8
  <li class="danger"><%= destroy_icon(@entity) %></li>
9
9
  </ul>
10
10
 
11
- <%= render partial: 'form', locals: { entity: @entity } %>
11
+ <%=
12
+ render(
13
+ partial: 'form',
14
+ locals: {
15
+ entity: @entity,
16
+ handler: component_handler
17
+ }
18
+ )
19
+ %>
12
20
  </article>
@@ -1,7 +1,9 @@
1
1
  <% content_for :meta_description, category.meta_description unless category.meta_description.blank? %>
2
2
 
3
3
  <article>
4
- <h1><%= category.name %></h1>
4
+ <div class="content-wrapper">
5
+ <h1><%= category.name %></h1>
5
6
 
6
- <%= render partial: 'posts/collection', locals: { collection: collection } %>
7
+ <%= render partial: 'posts/collection', locals: { collection: collection } %>
8
+ </div>
7
9
  </article>
@@ -1,6 +1,12 @@
1
+ <% content_for :breadcrumbs do %>
2
+ <%= render partial: 'posts/breadcrumbs', locals: { entity: entity } %>
3
+ <% end %>
4
+
1
5
  <%= render partial: 'posts/entity/metadata', locals: { entity: entity } %>
2
6
  <%= render partial: 'posts/post', locals: { post: entity } %>
3
- <%# render partial: 'comments/list', locals: { commentable: entity, comments: entity.comments } %>
7
+ <% if Gem.loaded_specs.key?('biovision-comment') %>
8
+ <%= render partial: 'comments/section', locals: { entity: entity } %>
9
+ <% end %>
4
10
  <%=
5
11
  render(
6
12
  partial: 'posts/entity/linked_posts',
@@ -1,5 +1,14 @@
1
+ <% allow_new ||= false %>
1
2
  <article>
2
- <h1><%= heading %></h1>
3
+ <div class="content-wrapper">
4
+ <h1><%= heading %></h1>
3
5
 
4
- <%= render partial: 'posts/collection', locals: { collection: collection } %>
6
+ <% if allow_new && local_assigns[:path_for_new] %>
7
+ <ul class="actions">
8
+ <li><%= create_icon(path_for_new) %></li>
9
+ </ul>
10
+ <% end %>
11
+
12
+ <%= render partial: 'posts/collection', locals: { collection: collection } %>
13
+ </div>
5
14
  </article>
@@ -1,7 +1,7 @@
1
1
  <article>
2
- <header>
3
- <h1><%= heading %></h1>
4
- </header>
2
+ <div class="content-wrapper">
3
+ <header><h1><%= heading %></h1></header>
5
4
 
6
- <%= render partial: 'posts/collection', locals: { collection: collection } %>
5
+ <%= render partial: 'posts/collection', locals: { collection: collection } %>
6
+ </div>
7
7
  </article>
@@ -16,7 +16,7 @@
16
16
  <% @collection.each do |post| %>
17
17
  <item>
18
18
  <title><%= post.title %></title>
19
- <link><%= site_link + PostManager.new(post).post_path %></link>
19
+ <link><%= site_link + post.url %></link>
20
20
  <description><%= post.lead! %></description>
21
21
  <guid isPermaLink="false"><%= post.uuid %></guid>
22
22
  <pubDate><%= post.publication_time.rfc822 %></pubDate>
@@ -1,6 +1 @@
1
- <% content_for :breadcrumbs do %>
2
- <%= link_to(t('posts.index.nav_text'), posts_path) %>
3
- <%= render partial: 'posts/breadcrumbs', locals: { entity: @entity } %>
4
- <% end %>
5
-
6
1
  <%= render partial: 'posts/post_type/post_page', locals: { entity: @entity } %>
@@ -19,7 +19,7 @@
19
19
  <% next if item.image.blank? %>
20
20
  <item>
21
21
  <title><%= item.title %></title>
22
- <link><%= site_link + PostManager.new(item).post_path %></link>
22
+ <link><%= site_link + item.url %></link>
23
23
  <media:rating scheme="urn:simple"><%= item.explicit? ? 'adult' : 'nonadult' %></media:rating>
24
24
  <pubDate><%= item.publication_time.rfc822 %></pubDate>
25
25
  <author><![CDATA[<%= item.author!(t(:anonymous)) %>]]></author>
@@ -31,11 +31,11 @@
31
31
  length="<%= File.size(item.image.hd.current_path) %>"
32
32
  type="<%= item.image.content_type %>"
33
33
  />
34
- <% PostManager.enclosures(item).each do |url| %>
34
+ <% item.enclosures.each do |url| %>
35
35
  <enclosure url="<%= media_link + url %>" type="<%= Rack::Mime::MIME_TYPES[File.extname(url)] %>"/>
36
36
  <% end %>
37
37
  <description><![CDATA[<%= item.lead! %>]]></description>
38
- <content:encoded><![CDATA[<%= raw(item.parsed_body) %>]]></content:encoded>
38
+ <content:encoded><![CDATA[<%= raw(item.body) %>]]></content:encoded>
39
39
  </item>
40
40
  <% end %>
41
41
  </channel>
@@ -269,7 +269,7 @@ ru:
269
269
  posts:
270
270
  nav_item:
271
271
  description: "Управление публикациями"
272
- text: "Публикации"
272
+ text: "Все публикации"
273
273
  index:
274
274
  heading: "Публикации"
275
275
  title: "Публикации, страница %{page}"
@@ -304,6 +304,14 @@ ru:
304
304
  entity:
305
305
  in_list:
306
306
  post_categories: "Категории публикаций"
307
+ biovision:
308
+ components:
309
+ posts:
310
+ name: "Публикации"
311
+ privileges:
312
+ chief_editor: "Главный редактор"
313
+ deputy_chief_editor: "Заместитель главного редактора"
314
+ editor: "Редактор"
307
315
  editorial_members:
308
316
  new:
309
317
  heading: "Добавление члена редакции"
@@ -542,3 +550,5 @@ ru:
542
550
  title: "Редактирование моей публикации"
543
551
  nav_text: "Редактировать"
544
552
  heading: "Редактирование публикации"
553
+ form:
554
+ categories: "Категории"
@@ -54,6 +54,7 @@ Rails.application.routes.draw do
54
54
 
55
55
  scope :articles, controller: :articles do
56
56
  get '/' => :index, as: :articles
57
+ get 'new' => :new, as: :new_article
57
58
  get 'archive/(:year)(-:month)(-:day)' => :archive, as: :articles_archive, constraints: archive_constraints
58
59
  get 'tagged/(:tag_name)' => :tagged, as: :tagged_articles, constraints: { tag_name: /[^\/]+?/ }
59
60
  get '/:category_slug' => :category, as: :articles_category, constraints: { category_slug: category_slug_pattern }
@@ -62,6 +63,7 @@ Rails.application.routes.draw do
62
63
 
63
64
  scope :news, controller: :news do
64
65
  get '/' => :index, as: :news_index
66
+ get 'new' => :new, as: :new_news
65
67
  get 'archive/(:year)(-:month)(-:day)' => :archive, as: :news_archive, constraints: archive_constraints
66
68
  get 'tagged/(:tag_name)' => :tagged, as: :tagged_news, constraints: { tag_name: /[^\/]+?/ }
67
69
  get '/:category_slug' => :category, as: :news_category, constraints: { category_slug: category_slug_pattern }
@@ -70,6 +72,7 @@ Rails.application.routes.draw do
70
72
 
71
73
  scope :blog_posts, controller: :blog_posts do
72
74
  get '/' => :index, as: :blog_posts
75
+ get 'new' => :new, as: :new_blog_post
73
76
  get 'archive/(:year)(-:month)(-:day)' => :archive, as: :blog_posts_archive, constraints: archive_constraints
74
77
  get 'tagged/(:tag_name)' => :tagged, as: :tagged_blog_posts, constraints: { tag_name: /[^\/]+?/ }
75
78
  get '/:category_slug' => :category, as: :blog_posts_category, constraints: { category_slug: category_slug_pattern }
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add full-text search to posts table
4
+ class AddSearchIndexToPosts < ActiveRecord::Migration[5.2]
5
+ def up
6
+ execute %(
7
+ create or replace function posts_tsvector(title text, lead text, body text)
8
+ returns tsvector as $$
9
+ begin
10
+ return (
11
+ setweight(to_tsvector('russian', title), 'A') ||
12
+ setweight(to_tsvector('russian', coalesce(lead, '')), 'B') ||
13
+ setweight(to_tsvector('russian', body), 'C')
14
+ );
15
+ end
16
+ $$ language 'plpgsql' immutable;
17
+ )
18
+ execute 'create index posts_search_idx on posts using gin(posts_tsvector(title, lead, body));'
19
+ end
20
+
21
+ def down
22
+ # no rollback needed
23
+ end
24
+ end
@@ -3,6 +3,7 @@
3
3
  # Tables for post types, categories and tags
4
4
  class CreatePostTypes < ActiveRecord::Migration[5.2]
5
5
  def up
6
+ create_component
6
7
  create_post_types unless PostType.table_exists?
7
8
  create_post_categories unless PostCategory.table_exists?
8
9
  create_post_tags unless PostTag.table_exists?
@@ -34,7 +35,6 @@ class CreatePostTypes < ActiveRecord::Migration[5.2]
34
35
  add_index :post_types, :name, unique: true
35
36
 
36
37
  create_default_types
37
- create_privileges
38
38
  end
39
39
 
40
40
  def create_post_categories
@@ -54,6 +54,7 @@ class CreatePostTypes < ActiveRecord::Migration[5.2]
54
54
  t.string :meta_description
55
55
  t.string :parents_cache, default: '', null: false
56
56
  t.integer :children_cache, default: [], array: true, null: false
57
+ t.jsonb :data, default: {}, null: false
57
58
  end
58
59
 
59
60
  add_foreign_key :post_categories, :post_categories, column: :parent_id, on_update: :cascade, on_delete: :cascade
@@ -89,17 +90,7 @@ class CreatePostTypes < ActiveRecord::Migration[5.2]
89
90
  end
90
91
  end
91
92
 
92
- def create_privileges
93
- group = PrivilegeGroup.find_by(slug: 'editors') || PrivilegeGroup.create!(slug: 'editors', name: 'Редакторы')
94
- chief_editor = Privilege.find_by(slug: 'chief_editor') || Privilege.create(slug: 'chief_editor', name: 'Главный редактор')
95
- children = {
96
- editor: 'Редактор'
97
- }
98
-
99
- children.each do |slug, name|
100
- child = Privilege.new(parent: chief_editor, slug: slug, name: name, administrative: false)
101
-
102
- group.add_privilege(child) if child.save
103
- end
93
+ def create_component
94
+ BiovisionComponent.create(slug: 'posts')
104
95
  end
105
96
  end
@@ -13,9 +13,11 @@ class CreatePosts < ActiveRecord::Migration[5.2]
13
13
  create_post_notes unless PostNote.table_exists?
14
14
  create_featured_posts unless FeaturedPost.table_exists?
15
15
  create_post_illustrations unless PostIllustration.table_exists?
16
+ create_post_attachments unless PostAttachment.table_exists?
16
17
  end
17
18
 
18
19
  def down
20
+ drop_table :post_attachments if PostAttachment.table_exists?
19
21
  drop_table :post_illustrations if PostIllustration.table_exists?
20
22
  drop_table :featured_posts if FeaturedPost.table_exists?
21
23
  drop_table :post_notes if PostNote.table_exists?
@@ -87,15 +89,26 @@ class CreatePosts < ActiveRecord::Migration[5.2]
87
89
 
88
90
  execute "create index posts_created_at_month_idx on posts using btree (date_trunc('month', created_at), post_type_id, user_id);"
89
91
  execute "create index posts_pubdate_month_idx on posts using btree (date_trunc('month', publication_time), post_type_id, user_id);"
92
+ execute %(
93
+ create or replace function posts_tsvector(title text, lead text, body text)
94
+ returns tsvector as $$
95
+ begin
96
+ return (
97
+ setweight(to_tsvector('russian', title), 'A') ||
98
+ setweight(to_tsvector('russian', coalesce(lead, '')), 'B') ||
99
+ setweight(to_tsvector('russian', body), 'C')
100
+ );
101
+ end
102
+ $$ language 'plpgsql' immutable;
103
+ )
104
+ execute "create index posts_search_idx on posts using gin(posts_tsvector(title, lead, body));"
90
105
 
91
106
  add_foreign_key :posts, :posts, column: :original_post_id, on_update: :cascade, on_delete: :nullify
92
107
 
93
108
  add_index :posts, :created_at
94
109
  add_index :posts, :data, using: :gin
95
110
 
96
- if Gem.loaded_specs.key?('elasticsearch-model')
97
- Post.__elasticsearch__.create_index!
98
- end
111
+ Post.__elasticsearch__.create_index! if Gem.loaded_specs.key?('elasticsearch-model')
99
112
  end
100
113
 
101
114
  def create_post_post_tags
@@ -191,4 +204,14 @@ class CreatePosts < ActiveRecord::Migration[5.2]
191
204
  t.string :image
192
205
  end
193
206
  end
207
+
208
+ def create_post_attachments
209
+ create_table :post_attachments, comment: 'Attachment for post' do |t|
210
+ t.references :post, foreign_key: { on_update: :cascade, on_delete: :cascade }
211
+ t.uuid :uuid
212
+ t.timestamps
213
+ t.string :name
214
+ t.string :file
215
+ end
216
+ end
194
217
  end