biovision-post 0.21.190513.0 → 0.26.191013.0

Sign up to get free protection for your applications and to get access to all the features.
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,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Displaying post authors
1
4
  class AuthorsController < ApplicationController
2
- before_action :set_entity, except: [:index]
5
+ before_action :set_entity, except: :index
3
6
 
4
7
  # get /authors
5
8
  def index
@@ -17,11 +20,13 @@ class AuthorsController < ApplicationController
17
20
 
18
21
  private
19
22
 
23
+ def component_slug
24
+ Biovision::Components::PostsComponent::SLUG
25
+ end
26
+
20
27
  def set_entity
21
28
  user = User.find_by(slug: params[:slug].downcase, deleted: false)
22
29
  @entity = EditorialMember.visible.find_by(user: user)
23
- if @entity.nil?
24
- handle_http_404('Cannot find user')
25
- end
30
+ handle_http_404('Cannot find user') if @entity.nil?
26
31
  end
27
32
  end
@@ -1,11 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Viewing blog posts
1
4
  class BlogPostsController < ApplicationController
2
5
  before_action :set_category, only: :category
3
6
  before_action :set_entity, only: :show
4
7
 
5
8
  # get /blog_posts
6
9
  def index
7
- post_type = PostType.find_by(slug: 'blog_post')
8
- @collection = post_type.posts.for_language(current_language).page_for_visitors(current_page)
10
+ posts = PostType['blog_post'].posts.for_language(current_language)
11
+ @collection = posts.page_for_visitors(current_page)
9
12
  respond_to do |format|
10
13
  format.html
11
14
  format.json { render('posts/index') }
@@ -14,7 +17,8 @@ class BlogPostsController < ApplicationController
14
17
 
15
18
  # get /blog_posts/:category_slug
16
19
  def category
17
- @collection = Post.in_category_branch(@category).for_language(current_language).page_for_visitors(current_page)
20
+ posts = Post.in_category_branch(@category).for_language(current_language)
21
+ @collection = posts.page_for_visitors(current_page)
18
22
  respond_to do |format|
19
23
  format.html
20
24
  format.json { render('posts/index') }
@@ -26,18 +30,24 @@ class BlogPostsController < ApplicationController
26
30
  @entity.increment :view_count
27
31
  @entity.increment :rating, 0.0025
28
32
  @entity.save
33
+
34
+ render 'posts/show'
29
35
  end
30
36
 
31
37
  # get /blog_posts/tagged/:tag_name
32
38
  def tagged
33
- post_type = PostType.find_by(slug: 'blog_post')
34
- @collection = post_type.posts.tagged(params[:tag_name]).page_for_visitors(current_page)
39
+ posts = PostType['blog_post'].posts.tagged(params[:tag_name])
40
+ @collection = posts.page_for_visitors(current_page)
35
41
  end
36
42
 
37
43
  private
38
44
 
45
+ def component_slug
46
+ Biovision::Components::PostsComponent::SLUG
47
+ end
48
+
39
49
  def set_category
40
- type = PostType.find_by(slug: 'blog_post')
50
+ type = PostType['blog_post']
41
51
  @category = type.post_categories.find_by(long_slug: params[:category_slug])
42
52
  handle_http_404('Cannot find post category (blog_post)') if @category.nil?
43
53
  end
@@ -40,6 +40,15 @@ class EditorialMembersController < AdminController
40
40
 
41
41
  private
42
42
 
43
+ def component_slug
44
+ Biovision::Components::PostsComponent::SLUG
45
+ end
46
+
47
+ def restrict_access
48
+ error = 'Managing editorial members is not allowed'
49
+ handle_http_401(error) unless component_handler.allow?('chief_editor')
50
+ end
51
+
43
52
  def set_entity
44
53
  @entity = EditorialMember.find_by(id: params[:id])
45
54
  if @entity.nil?
@@ -47,10 +56,6 @@ class EditorialMembersController < AdminController
47
56
  end
48
57
  end
49
58
 
50
- def restrict_access
51
- require_privilege :chief_editor
52
- end
53
-
54
59
  def entity_parameters
55
60
  params.require(:editorial_member).permit(EditorialMember.entity_parameters)
56
61
  end
@@ -21,8 +21,13 @@ class FeaturedPostsController < AdminController
21
21
 
22
22
  private
23
23
 
24
+ def component_slug
25
+ Biovision::Components::PostsComponent::SLUG
26
+ end
27
+
24
28
  def restrict_access
25
- require_privilege :chief_editor
29
+ error = 'Managing featured posts is not allowed'
30
+ handle_http_401(error) unless component_handler.allow?('chief_editor', 'deputy_chief_editor')
26
31
  end
27
32
 
28
33
  def creation_parameters
@@ -1,51 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Post handler for user
1
4
  class My::PostsController < ProfileController
2
- before_action :set_entity, only: [:show, :edit, :update, :destroy]
3
- before_action :restrict_editing, only: [:edit, :update, :destroy]
5
+ before_action :set_entity, only: %i[show edit update destroy]
6
+ before_action :restrict_editing, only: %i[edit update destroy]
4
7
 
5
8
  # get /my/posts
6
9
  def index
7
10
  @collection = Post.page_for_owner(current_user, current_page)
8
11
  end
9
12
 
10
- # get /my/posts/new
11
- def new
12
- @entity = Post.new
13
- end
14
-
15
13
  # get /my/articles/new
16
14
  def new_article
17
- if current_user_has_privilege?(:editor)
18
- @entity = Post.of_type(:article).new
19
- render :new
20
- else
21
- handle_http_401('User has no editor privilege')
22
- end
15
+ render_form_if_allowed 'article'
23
16
  end
24
17
 
25
18
  # get /my/news/new
26
19
  def new_news
27
- if current_user_has_privilege?(:reporter)
28
- @entity = Post.of_type(:news).new
29
- render :new
30
- else
31
- handle_http_401('User has no reporter privilege')
32
- end
20
+ render_form_if_allowed 'news'
33
21
  end
34
22
 
35
23
  # get /my/blog_posts/new
36
24
  def new_blog_post
37
- if current_user_has_privilege?(:blogger)
38
- @entity = Post.of_type(:blog_post).new
39
- render :new
40
- else
41
- handle_http_401('User has no blogger privilege')
42
- end
25
+ render_form_if_allowed 'blog_post'
43
26
  end
44
27
 
45
28
  # post /my/posts
46
29
  def create
47
30
  @entity = Post.new(creation_parameters)
48
- if @entity.save
31
+ if component_handler.allow_post_type?(@entity.post_type) && @entity.save
49
32
  apply_post_tags
50
33
  form_processed_ok(my_post_path(id: @entity.id))
51
34
  else
@@ -73,40 +56,54 @@ class My::PostsController < ProfileController
73
56
 
74
57
  # delete /my/posts/:id
75
58
  def destroy
76
- if @entity.destroy
77
- flash[:notice] = t('posts.destroy.success')
78
- end
59
+ flash[:notice] = t('posts.destroy.success') if @entity.destroy
60
+
79
61
  redirect_to my_posts_path
80
62
  end
81
63
 
82
64
  # get /my/articles
83
65
  def articles
84
- @collection = Post.of_type(:article).page_for_owner(current_user, current_page)
66
+ prepare_collection 'article'
85
67
  end
86
68
 
87
69
  # get /my/news
88
70
  def news_index
89
- @collection = Post.of_type(:news).page_for_owner(current_user, current_page)
71
+ prepare_collection 'news'
90
72
  end
91
73
 
92
74
  # get /my/blog
93
75
  def blog_posts
94
- @collection = Post.of_type(:blog_post).page_for_owner(current_user, current_page)
76
+ prepare_collection 'blog_post'
95
77
  end
96
78
 
97
79
  private
98
80
 
81
+ def component_slug
82
+ Biovision::Components::PostsComponent::SLUG
83
+ end
84
+
85
+ # @param [String] slug
86
+ def render_form_if_allowed(slug)
87
+ if component_handler.allow_post_type?(slug)
88
+ @entity = PostType[slug].posts.new
89
+ render :new
90
+ else
91
+ handle_http_401("User cannot create posts of type #{slug}")
92
+ end
93
+ end
94
+
95
+ # @param [String] slug
96
+ def prepare_collection(slug)
97
+ @collection = PostType[slug].posts.page_for_owner(current_user, current_page)
98
+ end
99
+
99
100
  def set_entity
100
101
  @entity = Post.owned_by(current_user).find_by(id: params[:id])
101
- if @entity.nil?
102
- handle_http_404('Cannot find post')
103
- end
102
+ handle_http_404('Cannot find post') if @entity.nil?
104
103
  end
105
104
 
106
105
  def restrict_editing
107
- if @entity.locked?
108
- handle_http_403('Entity is locked')
109
- end
106
+ handle_http_403('Entity is locked') if @entity.locked?
110
107
  end
111
108
 
112
109
  def entity_parameters
@@ -1,11 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # News for visitors
1
4
  class NewsController < ApplicationController
2
5
  before_action :set_category, only: :category
3
6
  before_action :set_entity, only: :show
4
7
 
5
8
  # get /news
6
9
  def index
7
- post_type = PostType.find_by(slug: 'news')
8
- @collection = post_type.posts.for_language(current_language).page_for_visitors(current_page)
10
+ posts = PostType['news'].posts.for_language(current_language)
11
+ @collection = posts.page_for_visitors(current_page)
9
12
  respond_to do |format|
10
13
  format.html
11
14
  format.json { render('posts/index') }
@@ -14,7 +17,8 @@ class NewsController < ApplicationController
14
17
 
15
18
  # get /news/:category_slug
16
19
  def category
17
- @collection = Post.in_category_branch(@category).for_language(current_language).page_for_visitors(current_page)
20
+ posts = Post.in_category_branch(@category).for_language(current_language)
21
+ @collection = posts.page_for_visitors(current_page)
18
22
  respond_to do |format|
19
23
  format.html
20
24
  format.json { render('posts/index') }
@@ -26,18 +30,24 @@ class NewsController < ApplicationController
26
30
  @entity.increment :view_count
27
31
  @entity.increment :rating, 0.0025
28
32
  @entity.save
33
+
34
+ render 'posts/show'
29
35
  end
30
36
 
31
37
  # get /news/tagged/:tag_name
32
38
  def tagged
33
- post_type = PostType.find_by(slug: 'news')
34
- @collection = post_type.posts.tagged(params[:tag_name]).page_for_visitors(current_page)
39
+ posts = PostType['news'].posts
40
+ @collection = posts.tagged(params[:tag_name]).page_for_visitors(current_page)
35
41
  end
36
42
 
37
43
  private
38
44
 
45
+ def component_slug
46
+ Biovision::Components::PostsComponent::SLUG
47
+ end
48
+
39
49
  def set_category
40
- type = PostType.find_by(slug: 'news')
50
+ type = PostType['news']
41
51
  @category = type.post_categories.find_by(long_slug: params[:category_slug])
42
52
  handle_http_404('Cannot find post category (news)') if @category.nil?
43
53
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Controller for deleting post attachments
4
+ class PostAttachmentsController < AdminController
5
+ before_action :set_entity, only: :destroy
6
+ before_action :restrict_editing, only: :destroy
7
+
8
+ # delete /post_attachments/:id
9
+ def destroy
10
+ @entity.destroy
11
+
12
+ redirect_to(admin_post_path(id: @entity.post_id))
13
+ end
14
+
15
+ private
16
+
17
+ def component_slug
18
+ Biovision::Components::PostsComponent::SLUG
19
+ end
20
+
21
+ def restrict_access
22
+ error = 'Managing post attachments is not allowed'
23
+ handle_http_401(error) unless component_handler.allow?
24
+ end
25
+
26
+ def restrict_editing
27
+ return if component_handler.editable?(@entity)
28
+
29
+ handle_http_403("Attachment is not editable by user #{current_user&.id}")
30
+ end
31
+
32
+ def set_entity
33
+ @entity = PostAttachment.find_by(id: params[:id])
34
+ handle_http_404('Cannot find post_attachment') if @entity.nil?
35
+ end
36
+ end
@@ -40,8 +40,13 @@ class PostCategoriesController < AdminController
40
40
 
41
41
  protected
42
42
 
43
+ def component_slug
44
+ Biovision::Components::PostsComponent::SLUG
45
+ end
46
+
43
47
  def restrict_access
44
- require_privilege :chief_editor
48
+ error = 'Managing post categories is not allowed'
49
+ handle_http_401(error) unless component_handler.allow?('chief_editor')
45
50
  end
46
51
 
47
52
  def restrict_editing
@@ -61,13 +61,18 @@ class PostGroupsController < ApplicationController
61
61
 
62
62
  private
63
63
 
64
- def set_entity
65
- @entity = PostGroup.find_by(id: params[:id])
66
- handle_http_404('Cannot find post_group') if @entity.nil?
64
+ def component_slug
65
+ Biovision::Components::PostsComponent::SLUG
67
66
  end
68
67
 
69
68
  def restrict_access
70
- require_privilege :chief_editor
69
+ error = 'Managing post groups is not allowed'
70
+ handle_http_401(error) unless component_handler.allow?('chief_editor')
71
+ end
72
+
73
+ def set_entity
74
+ @entity = PostGroup.find_by(id: params[:id])
75
+ handle_http_404('Cannot find post_group') if @entity.nil?
71
76
  end
72
77
 
73
78
  def entity_parameters
@@ -12,8 +12,13 @@ class PostIllustrationsController < ApplicationController
12
12
 
13
13
  private
14
14
 
15
+ def component_slug
16
+ Biovision::Components::PostsComponent::SLUG
17
+ end
18
+
15
19
  def restrict_access
16
- require_privilege_group :editors
20
+ error = 'Managing post groups is not allowed'
21
+ handle_http_401(error) unless component_handler.allow?
17
22
  end
18
23
 
19
24
  def ckeditor_parameters
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Managing post images
1
4
  class PostImagesController < AdminController
2
5
  before_action :set_entity, only: [:edit, :update, :destroy]
3
6
  before_action :restrict_editing, only: [:edit, :update, :destroy]
@@ -35,19 +38,17 @@ class PostImagesController < AdminController
35
38
 
36
39
  private
37
40
 
38
- def set_entity
39
- @entity = PostImage.find_by(id: params[:id])
40
- if @entity.nil?
41
- handle_http_404('Cannot find post_image')
42
- end
41
+ def component_slug
42
+ Biovision::Components::PostsComponent::SLUG
43
43
  end
44
44
 
45
- def restrict_access
46
- require_privilege_group :editors
45
+ def set_entity
46
+ @entity = PostImage.find_by(id: params[:id])
47
+ handle_http_404('Cannot find post_image') if @entity.nil?
47
48
  end
48
49
 
49
50
  def restrict_editing
50
- unless @entity.editable_by?(current_user)
51
+ unless component_handler.editable?(@entity.post)
51
52
  handle_http_401('Post image is not editable by current user')
52
53
  end
53
54
  end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Managing post links
1
4
  class PostLinksController < AdminController
2
5
  before_action :set_entity, only: :destroy
3
6
 
@@ -20,8 +23,8 @@ class PostLinksController < AdminController
20
23
 
21
24
  private
22
25
 
23
- def restrict_access
24
- require_privilege_group :editors
26
+ def component_slug
27
+ Biovision::Components::PostsComponent::SLUG
25
28
  end
26
29
 
27
30
  def entity_parameters