biovision-post 0.28.191126.0 → 0.31.200627.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/admin/editorial_members_controller.rb +2 -2
  3. data/app/controllers/admin/featured_posts_controller.rb +2 -2
  4. data/app/controllers/admin/post_categories_controller.rb +2 -2
  5. data/app/controllers/admin/post_group_categories_controller.rb +2 -2
  6. data/app/controllers/admin/post_group_tags_controller.rb +2 -2
  7. data/app/controllers/admin/post_groups_controller.rb +2 -2
  8. data/app/controllers/admin/post_illustrations_controller.rb +2 -7
  9. data/app/controllers/admin/post_images_controller.rb +2 -7
  10. data/app/controllers/admin/post_links_controller.rb +2 -7
  11. data/app/controllers/admin/post_tags_controller.rb +2 -2
  12. data/app/controllers/admin/post_types_controller.rb +7 -6
  13. data/app/controllers/admin/posts_controller.rb +2 -2
  14. data/app/controllers/articles_controller.rb +2 -2
  15. data/app/controllers/authors_controller.rb +2 -2
  16. data/app/controllers/blog_posts_controller.rb +2 -2
  17. data/app/controllers/editorial_members_controller.rb +2 -2
  18. data/app/controllers/featured_posts_controller.rb +2 -2
  19. data/app/controllers/my/posts_controller.rb +6 -2
  20. data/app/controllers/news_controller.rb +2 -2
  21. data/app/controllers/post_attachments_controller.rb +2 -7
  22. data/app/controllers/post_categories_controller.rb +2 -2
  23. data/app/controllers/post_groups_controller.rb +2 -2
  24. data/app/controllers/post_illustrations_controller.rb +2 -2
  25. data/app/controllers/post_images_controller.rb +2 -2
  26. data/app/controllers/post_links_controller.rb +2 -2
  27. data/app/controllers/post_tags_controller.rb +2 -2
  28. data/app/controllers/posts_controller.rb +3 -3
  29. data/app/models/post.rb +14 -23
  30. data/app/models/post_attachment.rb +2 -3
  31. data/app/models/post_group.rb +1 -1
  32. data/app/models/post_image.rb +1 -1
  33. data/app/services/biovision/components/posts_component.rb +12 -2
  34. data/app/services/post_parser.rb +3 -7
  35. data/app/views/admin/post_attachments/entity/_in_list.html.erb +12 -0
  36. data/app/views/admin/post_types/show.html.erb +28 -24
  37. data/app/views/admin/posts/entity/_attachments.html.erb +14 -0
  38. data/app/views/my/posts/_form.html.erb +1 -1
  39. data/app/views/my/posts/edit.html.erb +9 -1
  40. data/app/views/posts/_form.html.erb +0 -4
  41. data/app/views/posts/form/_category_links.html.erb +1 -0
  42. data/config/locales/posts-ru.yml +4 -0
  43. data/config/routes.rb +5 -0
  44. data/db/{migrate → amends}/20190401101010_create_post_illustrations.rb +0 -0
  45. data/db/{migrate → amends}/20190407101010_create_editorial_member_post_types.rb +0 -0
  46. data/db/{migrate → amends}/20190410120000_create_post_groups.rb +0 -0
  47. data/db/{migrate → amends}/20190412191919_add_nav_text_to_post_categories.rb +0 -0
  48. data/db/{migrate → amends}/20190412212121_add_url_part_to_post_types.rb +0 -0
  49. data/db/{migrate → amends}/20190420212121_create_post_layouts.rb +0 -0
  50. data/db/{migrate → amends}/20190424161616_create_post_post_categories.rb +0 -0
  51. data/db/migrate/20170930000010_create_posts.rb +7 -9
  52. data/db/migrate/20200207141414_convert_posts_vote_data.rb +25 -0
  53. data/lib/biovision/post/decorators/controllers/profiles_controller_decorator.rb +9 -0
  54. data/lib/biovision/post/engine.rb +8 -2
  55. data/lib/biovision/post/version.rb +1 -1
  56. metadata +14 -39
  57. data/db/migrate/20190410101010_add_avoid_parsing_to_posts.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c0d863ab2108741c9a77e174dac0f5594b3ca41d966a286e74ffd1476239d58
4
- data.tar.gz: 85c93cc74bc7b4f372a1f7bc6093f10ef38f8af7e8359eaa3a076481a7f765f4
3
+ metadata.gz: b7a3512ea3126ec7b9823f20eb32cc4ada71f998d274bd9c9c054c444f52e70b
4
+ data.tar.gz: 8c50a8202a57385205a5f2fe430ed91bac2063cf3cebf12cb4726cb9d4a24ed9
5
5
  SHA512:
6
- metadata.gz: 683e5308e4e32a2f70d21095e8832480e676347c584c7040344138df02793126d18ec9856fd062b765be42fefd5d9743e311157f44710276fd8ddbb1f7939bfe
7
- data.tar.gz: 200cfb8832309fa195a011356ee76b6261d9d8f3d97f293d654436b27ccca2494bc5fbd0bf745adc7f89e7b08f463c4d082893268f42556b4fb744faa08d003c
6
+ metadata.gz: e2ee7bfb1beab756d00a123637c9f8da61b875a56b6957e71f114495f1651a4f8a85559a2fd43f24ee881094dc872f092486d1dedea09ac104a1f9a89491e519
7
+ data.tar.gz: a1779ab2260aed0a7148eb2d26c85149a053c6daff7f52bcc6c00193aa1286c0a22578553f4989cf271b3b9f8c187ec6caedc6afb0f4963184c45fdf26612d75
@@ -32,8 +32,8 @@ class Admin::EditorialMembersController < AdminController
32
32
 
33
33
  private
34
34
 
35
- def component_slug
36
- Biovision::Components::PostsComponent::SLUG
35
+ def component_class
36
+ Biovision::Components::PostsComponent
37
37
  end
38
38
 
39
39
  def restrict_access
@@ -10,8 +10,8 @@ class Admin::FeaturedPostsController < AdminController
10
10
 
11
11
  private
12
12
 
13
- def component_slug
14
- Biovision::Components::PostsComponent::SLUG
13
+ def component_class
14
+ Biovision::Components::PostsComponent
15
15
  end
16
16
 
17
17
  def restrict_access
@@ -31,8 +31,8 @@ class Admin::PostCategoriesController < AdminController
31
31
 
32
32
  private
33
33
 
34
- def component_slug
35
- Biovision::Components::PostsComponent::SLUG
34
+ def component_class
35
+ Biovision::Components::PostsComponent
36
36
  end
37
37
 
38
38
  def restrict_access
@@ -8,8 +8,8 @@ class Admin::PostGroupCategoriesController < AdminController
8
8
 
9
9
  private
10
10
 
11
- def component_slug
12
- Biovision::Components::PostsComponent::SLUG
11
+ def component_class
12
+ Biovision::Components::PostsComponent
13
13
  end
14
14
 
15
15
  def restrict_access
@@ -8,8 +8,8 @@ class Admin::PostGroupTagsController < AdminController
8
8
 
9
9
  private
10
10
 
11
- def component_slug
12
- Biovision::Components::PostsComponent::SLUG
11
+ def component_class
12
+ Biovision::Components::PostsComponent
13
13
  end
14
14
 
15
15
  def restrict_access
@@ -51,8 +51,8 @@ class Admin::PostGroupsController < AdminController
51
51
 
52
52
  private
53
53
 
54
- def component_slug
55
- Biovision::Components::PostsComponent::SLUG
54
+ def component_class
55
+ Biovision::Components::PostsComponent
56
56
  end
57
57
 
58
58
  def restrict_access
@@ -15,13 +15,8 @@ class Admin::PostIllustrationsController < AdminController
15
15
 
16
16
  private
17
17
 
18
- def component_slug
19
- Biovision::Components::PostsComponent::SLUG
20
- end
21
-
22
- def restrict_access
23
- error = 'Viewing post illustrations is not allowed'
24
- handle_http_401(error) unless component_handler.allow?
18
+ def component_class
19
+ Biovision::Components::PostsComponent
25
20
  end
26
21
 
27
22
  def set_entity
@@ -20,13 +20,8 @@ class Admin::PostImagesController < AdminController
20
20
 
21
21
  private
22
22
 
23
- def component_slug
24
- Biovision::Components::PostsComponent::SLUG
25
- end
26
-
27
- def restrict_access
28
- error = 'Viewing post images is not allowed'
29
- handle_http_401(error) unless component_handler.allow?
23
+ def component_class
24
+ Biovision::Components::PostsComponent
30
25
  end
31
26
 
32
27
  def set_entity
@@ -6,13 +6,8 @@ class Admin::PostLinksController < AdminController
6
6
 
7
7
  private
8
8
 
9
- def component_slug
10
- Biovision::Components::PostsComponent::SLUG
11
- end
12
-
13
- def restrict_access
14
- error = 'Managing post links is not allowed'
15
- handle_http_401(error) unless component_handler.allow?
9
+ def component_class
10
+ Biovision::Components::PostsComponent
16
11
  end
17
12
 
18
13
  def set_entity
@@ -17,8 +17,8 @@ class Admin::PostTagsController < AdminController
17
17
 
18
18
  private
19
19
 
20
- def component_slug
21
- Biovision::Components::PostsComponent::SLUG
20
+ def component_class
21
+ Biovision::Components::PostsComponent
22
22
  end
23
23
 
24
24
  def restrict_access
@@ -2,7 +2,8 @@
2
2
 
3
3
  # Administrative part of post type management
4
4
  class Admin::PostTypesController < AdminController
5
- before_action :set_entity, except: [:index]
5
+ before_action :set_entity, except: :index
6
+ before_action :restrict_post_type, only: %i[new_post]
6
7
 
7
8
  # get /admin/post_types
8
9
  def index
@@ -55,13 +56,13 @@ class Admin::PostTypesController < AdminController
55
56
 
56
57
  private
57
58
 
58
- def component_slug
59
- Biovision::Components::PostsComponent::SLUG
59
+ def component_class
60
+ Biovision::Components::PostsComponent
60
61
  end
61
62
 
62
- def restrict_access
63
- error = 'Viewing post types is not allowed'
64
- handle_http_401(error) unless component_handler.allow?
63
+ def restrict_post_type
64
+ error = 'Handling this post type is not allowed'
65
+ handle_http_401(error) unless component_handler.allow_post_type?(@entity)
65
66
  end
66
67
 
67
68
  def set_entity
@@ -29,8 +29,8 @@ class Admin::PostsController < AdminController
29
29
 
30
30
  private
31
31
 
32
- def component_slug
33
- Biovision::Components::PostsComponent::SLUG
32
+ def component_class
33
+ Biovision::Components::PostsComponent
34
34
  end
35
35
 
36
36
  def set_entity
@@ -42,8 +42,8 @@ class ArticlesController < ApplicationController
42
42
 
43
43
  private
44
44
 
45
- def component_slug
46
- Biovision::Components::PostsComponent::SLUG
45
+ def component_class
46
+ Biovision::Components::PostsComponent
47
47
  end
48
48
 
49
49
  def set_category
@@ -20,8 +20,8 @@ class AuthorsController < ApplicationController
20
20
 
21
21
  private
22
22
 
23
- def component_slug
24
- Biovision::Components::PostsComponent::SLUG
23
+ def component_class
24
+ Biovision::Components::PostsComponent
25
25
  end
26
26
 
27
27
  def set_entity
@@ -42,8 +42,8 @@ class BlogPostsController < ApplicationController
42
42
 
43
43
  private
44
44
 
45
- def component_slug
46
- Biovision::Components::PostsComponent::SLUG
45
+ def component_class
46
+ Biovision::Components::PostsComponent
47
47
  end
48
48
 
49
49
  def set_category
@@ -40,8 +40,8 @@ class EditorialMembersController < AdminController
40
40
 
41
41
  private
42
42
 
43
- def component_slug
44
- Biovision::Components::PostsComponent::SLUG
43
+ def component_class
44
+ Biovision::Components::PostsComponent
45
45
  end
46
46
 
47
47
  def restrict_access
@@ -21,8 +21,8 @@ class FeaturedPostsController < AdminController
21
21
 
22
22
  private
23
23
 
24
- def component_slug
25
- Biovision::Components::PostsComponent::SLUG
24
+ def component_class
25
+ Biovision::Components::PostsComponent
26
26
  end
27
27
 
28
28
  def restrict_access
@@ -8,6 +8,10 @@ class My::PostsController < ProfileController
8
8
  # get /my/posts
9
9
  def index
10
10
  @collection = Post.page_for_owner(current_user, current_page)
11
+ respond_to do |format|
12
+ format.html
13
+ format.json { render 'posts/index' }
14
+ end
11
15
  end
12
16
 
13
17
  # get /my/articles/new
@@ -80,8 +84,8 @@ class My::PostsController < ProfileController
80
84
 
81
85
  private
82
86
 
83
- def component_slug
84
- Biovision::Components::PostsComponent::SLUG
87
+ def component_class
88
+ Biovision::Components::PostsComponent
85
89
  end
86
90
 
87
91
  # @param [String] slug
@@ -42,8 +42,8 @@ class NewsController < ApplicationController
42
42
 
43
43
  private
44
44
 
45
- def component_slug
46
- Biovision::Components::PostsComponent::SLUG
45
+ def component_class
46
+ Biovision::Components::PostsComponent
47
47
  end
48
48
 
49
49
  def set_category
@@ -14,13 +14,8 @@ class PostAttachmentsController < AdminController
14
14
 
15
15
  private
16
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?
17
+ def component_class
18
+ Biovision::Components::PostsComponent
24
19
  end
25
20
 
26
21
  def restrict_editing
@@ -40,8 +40,8 @@ class PostCategoriesController < AdminController
40
40
 
41
41
  protected
42
42
 
43
- def component_slug
44
- Biovision::Components::PostsComponent::SLUG
43
+ def component_class
44
+ Biovision::Components::PostsComponent
45
45
  end
46
46
 
47
47
  def restrict_access
@@ -61,8 +61,8 @@ class PostGroupsController < ApplicationController
61
61
 
62
62
  private
63
63
 
64
- def component_slug
65
- Biovision::Components::PostsComponent::SLUG
64
+ def component_class
65
+ Biovision::Components::PostsComponent
66
66
  end
67
67
 
68
68
  def restrict_access
@@ -12,8 +12,8 @@ class PostIllustrationsController < ApplicationController
12
12
 
13
13
  private
14
14
 
15
- def component_slug
16
- Biovision::Components::PostsComponent::SLUG
15
+ def component_class
16
+ Biovision::Components::PostsComponent
17
17
  end
18
18
 
19
19
  def restrict_access
@@ -38,8 +38,8 @@ class PostImagesController < AdminController
38
38
 
39
39
  private
40
40
 
41
- def component_slug
42
- Biovision::Components::PostsComponent::SLUG
41
+ def component_class
42
+ Biovision::Components::PostsComponent
43
43
  end
44
44
 
45
45
  def set_entity
@@ -23,8 +23,8 @@ class PostLinksController < AdminController
23
23
 
24
24
  private
25
25
 
26
- def component_slug
27
- Biovision::Components::PostsComponent::SLUG
26
+ def component_class
27
+ Biovision::Components::PostsComponent
28
28
  end
29
29
 
30
30
  def entity_parameters
@@ -26,8 +26,8 @@ class PostTagsController < AdminController
26
26
 
27
27
  private
28
28
 
29
- def component_slug
30
- Biovision::Components::PostsComponent::SLUG
29
+ def component_class
30
+ Biovision::Components::PostsComponent
31
31
  end
32
32
 
33
33
  def restrict_access
@@ -17,7 +17,7 @@ class PostsController < ApplicationController
17
17
  # post /posts
18
18
  def create
19
19
  @entity = Post.new(creation_parameters)
20
- if @entity.save
20
+ if component_handler.allow_post_type?(@entity.post_type) && @entity.save
21
21
  apply_post_tags
22
22
  apply_post_categories
23
23
  add_attachments if params.key?(:post_attachment)
@@ -111,8 +111,8 @@ class PostsController < ApplicationController
111
111
 
112
112
  private
113
113
 
114
- def component_slug
115
- Biovision::Components::PostsComponent::SLUG
114
+ def component_class
115
+ Biovision::Components::PostsComponent
116
116
  end
117
117
 
118
118
  def restrict_access
@@ -4,17 +4,11 @@
4
4
  class Post < ApplicationRecord
5
5
  include Checkable
6
6
  include HasOwner
7
+ include HasUuid
7
8
  include CommentableItem if Gem.loaded_specs.key?('biovision-comment')
8
9
  include VotableItem if Gem.loaded_specs.key?('biovision-vote')
9
10
  include Toggleable
10
11
 
11
- if Gem.loaded_specs.key?('elasticsearch-model')
12
- include Elasticsearch::Model
13
- include Elasticsearch::Model::Callbacks
14
-
15
- index_name Rails.configuration.post_index_name
16
- end
17
-
18
12
  ALT_LIMIT = 255
19
13
  BODY_LIMIT = 16_777_215
20
14
  IMAGE_NAME_LIMIT = 500
@@ -32,6 +26,8 @@ class Post < ApplicationRecord
32
26
 
33
27
  mount_uploader :image, PostImageUploader
34
28
 
29
+ paginates_per 12
30
+
35
31
  belongs_to :user
36
32
  belongs_to :post_type, counter_cache: true
37
33
  belongs_to :language, optional: true
@@ -50,12 +46,11 @@ class Post < ApplicationRecord
50
46
  has_many :post_zen_categories, dependent: :destroy
51
47
  has_many :zen_categories, through: :post_zen_categories
52
48
 
53
- after_initialize { self.uuid = SecureRandom.uuid if uuid.nil? }
54
49
  after_initialize { self.publication_time = Time.now if publication_time.nil? }
55
50
  before_validation :prepare_slug
56
51
  before_validation :prepare_source_names
57
52
 
58
- validates_presence_of :uuid, :title, :slug, :body
53
+ validates_presence_of :title, :slug, :body
59
54
  validates_length_of :title, maximum: TITLE_LIMIT
60
55
  validates_length_of :lead, maximum: LEAD_LIMIT
61
56
  validates_length_of :image_name, maximum: IMAGE_NAME_LIMIT
@@ -79,21 +74,21 @@ class Post < ApplicationRecord
79
74
  scope :popular, -> { order('rating desc') }
80
75
  scope :visible, -> { where(visible: true, deleted: false, approved: true) }
81
76
  scope :published, -> { where('publication_time <= current_timestamp') }
82
- scope :for_language, ->(language) { where(language: language).or(where(language: nil)) }
77
+ scope :for_language, ->(v) { where(language: v).or(where(language: nil)) }
83
78
  scope :pg_search, ->(v) { where("posts_tsvector(title, lead, body) @@ phraseto_tsquery('russian', ?)", v) }
84
79
  scope :exclude_ids, ->(v) { where('posts.id not in (?)', Array(v)) unless v.blank? }
85
80
  scope :list_for_visitors, -> { visible.published.recent }
86
81
  scope :list_for_administration, -> { order('id desc') }
87
- scope :list_for_owner, ->(user) { owned_by(user).recent }
88
- scope :tagged, ->(tag) { joins(:post_post_tags).where(post_post_tags: { post_tag_id: PostTag.ids_for_name(tag) }).distinct unless tag.blank? }
89
- scope :in_category, ->(slug) { joins(:post_post_categories).where(post_post_categories: { post_category_id: PostCategory.ids_for_slug(slug) }).distinct unless slug.blank? }
90
- scope :in_category_branch, ->(category) { joins(:post_post_categories).where(post_post_categories: { post_category_id: category.subbranch_ids }).distinct }
82
+ scope :list_for_owner, ->(v) { owned_by(v).recent }
83
+ scope :tagged, ->(v) { joins(:post_post_tags).where(post_post_tags: { post_tag_id: PostTag.ids_for_name(v) }).distinct unless v.blank? }
84
+ scope :in_category, ->(v) { joins(:post_post_categories).where(post_post_categories: { post_category_id: PostCategory.ids_for_slug(v) }).distinct unless v.blank? }
85
+ scope :in_category_branch, ->(v) { joins(:post_post_categories).where(post_post_categories: { post_category_id: v.subbranch_ids }).distinct }
91
86
  scope :with_category_ids, ->(v) { joins(:post_post_categories).where(post_post_categories: { post_category_id: Array(v) }) }
92
87
  scope :authors, -> { User.where(id: Post.author_ids).order('screen_name asc') }
93
- scope :of_type, ->(slug) { where(post_type: PostType.find_by(slug: slug)) unless slug.blank? }
88
+ scope :of_type, ->(v) { where(post_type: PostType.find_by(slug: v)) unless v.blank? }
94
89
  scope :archive, -> { f = Arel.sql('date(publication_time)'); distinct.order(f).pluck(f) }
95
- scope :posted_after, ->(time) { where('publication_time >= ?', time) }
96
- scope :pubdate, ->(date) { where('date(publication_time) = ?', date) }
90
+ scope :posted_after, ->(v) { where('publication_time >= ?', v) }
91
+ scope :pubdate, ->(v) { where('date(publication_time) = ?', v) }
97
92
  scope :f_visible, ->(f) { where(visible: f.to_i.positive?) unless f.blank? }
98
93
  scope :filtered, ->(f) { f_visible(f[:visible]) }
99
94
 
@@ -105,8 +100,8 @@ class Post < ApplicationRecord
105
100
 
106
101
  # @param [Integer] page
107
102
  # @param [Integer] per_page
108
- def self.page_for_visitors(page = 1, per_page = Post.items_per_page)
109
- list_for_visitors.page(page).per(per_page)
103
+ def self.page_for_visitors(page = 1)
104
+ list_for_visitors.page(page)
110
105
  end
111
106
 
112
107
  # @param [User] user
@@ -125,10 +120,6 @@ class Post < ApplicationRecord
125
120
  main_data + image_data + meta_data + author_data + flags_data
126
121
  end
127
122
 
128
- def self.items_per_page
129
- 12
130
- end
131
-
132
123
  def self.creation_parameters
133
124
  entity_parameters + %i[post_type_id]
134
125
  end
@@ -11,6 +11,7 @@
11
11
  # uuid [UUID]
12
12
  class PostAttachment < ApplicationRecord
13
13
  include Checkable
14
+ include HasUuid
14
15
 
15
16
  NAME_LIMIT = 120
16
17
 
@@ -18,8 +19,6 @@ class PostAttachment < ApplicationRecord
18
19
 
19
20
  belongs_to :post
20
21
 
21
- after_initialize { self.uuid = SecureRandom.uuid if uuid.nil? }
22
-
23
22
  validates_length_of :name, maximum: NAME_LIMIT
24
23
  validates_presence_of :file
25
24
 
@@ -44,6 +43,6 @@ class PostAttachment < ApplicationRecord
44
43
  # @param [User] user
45
44
  # @deprecated use component handler
46
45
  def editable_by?(user)
47
- Biovision::Components::BaseComponent.handler('posts', user).editable?(post)
46
+ Biovision::Components::PostsComponent[user]&.editable?(post)
48
47
  end
49
48
  end
@@ -77,7 +77,7 @@ class PostGroup < ApplicationRecord
77
77
 
78
78
  # @param [Integer] page
79
79
  def posts_page(page = 1)
80
- post_ids = Post.where(post_category_id: post_category_ids).pluck(:id)
80
+ post_ids = PostPostCategory.where(post_category_id: post_category_ids).pluck(:post_id)
81
81
  post_ids += PostPostTag.where(post_tag_id: post_tag_ids).pluck(:post_id)
82
82
  Post.list_for_visitors.where(id: post_ids.uniq).page(page)
83
83
  end
@@ -1,4 +1,5 @@
1
1
  class PostImage < ApplicationRecord
2
+ include HasUuid
2
3
  include Toggleable
3
4
 
4
5
  DESCRIPTION_LIMIT = 5000
@@ -11,7 +12,6 @@ class PostImage < ApplicationRecord
11
12
 
12
13
  belongs_to :post
13
14
 
14
- after_initialize { self.uuid = SecureRandom.uuid if uuid.nil? }
15
15
  after_initialize :set_next_priority
16
16
  before_validation :normalize_priority
17
17
 
@@ -51,8 +51,18 @@ module Biovision
51
51
  return true if user.super_user?
52
52
  return true if group?(:chief)
53
53
 
54
- ids = Array(user_link!.data.dig('settings', 'categories'))
55
- ids.map(&:to_i).include?(entity.respond_to?(:id) ? entity.id : entity)
54
+ ids = Array(user_link!.data.dig('settings', 'categories')).map(&:to_i)
55
+ ids.include?(entity.respond_to?(:id) ? entity.id : entity)
56
+ end
57
+
58
+ # @param [PostCategory] entity
59
+ def allow_category_branch?(entity)
60
+ return false if user.nil?
61
+ return true if allow_post_category?(entity)
62
+
63
+ ids = Array(user_link!.data.dig('settings', 'categories')).map(&:to_i)
64
+ item = entity.is_a?(PostCategory) ? entity : PostCategory.find(entity)
65
+ (ids & item.subbranch_ids).any?
56
66
  end
57
67
 
58
68
  # @param [PostType] entity
@@ -9,13 +9,9 @@ class PostParser
9
9
  end
10
10
 
11
11
  def parsed_body
12
- unless @entity.avoid_parsing?
13
- @body = escape_scripts
14
- @body = convert_video_links
15
- @body = convert_asides
16
- end
17
-
18
- @body
12
+ @body = escape_scripts
13
+ @body = convert_video_links
14
+ convert_asides
19
15
  end
20
16
 
21
17
  def escape_scripts
@@ -0,0 +1,12 @@
1
+ <div class="data">
2
+ <div><%= post_attachment_link(entity) %></div>
3
+ <div class="info">
4
+ <%= number_to_human_size(entity.size) %>
5
+ </div>
6
+
7
+ <% if entity.editable_by?(current_user) %>
8
+ <ul class="actions">
9
+ <li><%= destroy_icon(entity) %></li>
10
+ </ul>
11
+ <% end %>
12
+ </div>
@@ -10,32 +10,36 @@
10
10
 
11
11
  <ul class="actions">
12
12
  <li><%= back_icon(admin_post_types_path) %></li>
13
- <li><%= create_icon(new_post_admin_post_type_path(id: @entity.id)) %></li>
13
+ <% if component_handler.allow_post_type?(@entity.slug) %>
14
+ <li><%= create_icon(new_post_admin_post_type_path(id: @entity.id)) %></li>
15
+ <% end %>
14
16
  </ul>
15
17
 
16
- <nav>
17
- <%=
18
- link_to(
19
- t('admin.post_types.post_categories.nav_text'),
20
- post_categories_admin_post_type_path(id: @entity.id),
21
- class: 'button-nav'
22
- )
23
- %>
24
- <%=
25
- link_to(
26
- t('admin.post_types.post_tags.nav_text'),
27
- post_tags_admin_post_type_path(id: @entity.id),
28
- class: 'button-nav'
29
- )
30
- %>
31
- <%=
32
- link_to(
33
- t('admin.post_types.authors.nav_text'),
34
- authors_admin_post_type_path(id: @entity.id),
35
- class: 'button-nav'
36
- )
37
- %>
38
- </nav>
18
+ <% if component_handler.group?(:chief) %>
19
+ <nav>
20
+ <%=
21
+ link_to(
22
+ t('admin.post_types.post_categories.nav_text'),
23
+ post_categories_admin_post_type_path(id: @entity.id),
24
+ class: 'button-nav'
25
+ )
26
+ %>
27
+ <%=
28
+ link_to(
29
+ t('admin.post_types.post_tags.nav_text'),
30
+ post_tags_admin_post_type_path(id: @entity.id),
31
+ class: 'button-nav'
32
+ )
33
+ %>
34
+ <%=
35
+ link_to(
36
+ t('admin.post_types.authors.nav_text'),
37
+ authors_admin_post_type_path(id: @entity.id),
38
+ class: 'button-nav'
39
+ )
40
+ %>
41
+ </nav>
42
+ <% end %>
39
43
 
40
44
  <dl>
41
45
  <dt><%= t('activerecord.attributes.post_type.slug') %></dt>
@@ -0,0 +1,14 @@
1
+ <% if collection.load.any? %>
2
+ <section>
3
+ <h2><%= t('.heading') %></h2>
4
+
5
+ <%=
6
+ render(
7
+ partial: 'shared/admin/list',
8
+ locals: {
9
+ collection: collection
10
+ }
11
+ )
12
+ %>
13
+ </section>
14
+ <% end %>
@@ -1,5 +1,5 @@
1
1
  <%
2
- handler ||= Biovision::Components::BaseComponent.handler('post', current_user)
2
+ handler ||= Biovision::Components::BaseComponent.handler('posts', current_user)
3
3
  model_name = entity.class.to_s.underscore
4
4
  %>
5
5
  <%=
@@ -15,5 +15,13 @@
15
15
  </ul>
16
16
  <% end %>
17
17
 
18
- <%= render partial: 'form', locals: { entity: @entity } %>
18
+ <%=
19
+ render(
20
+ partial: 'form',
21
+ locals: {
22
+ entity: @entity,
23
+ handler: component_handler
24
+ }
25
+ )
26
+ %>
19
27
  </article>
@@ -149,10 +149,6 @@
149
149
  <dd>
150
150
  <div>
151
151
  <button type="button" class="js-wysiwyg-toggle" data-element="<%= model_name %>_body">WYSIWYG</button>
152
- <div>
153
- <%= f.check_box :avoid_parsing, id: "#{model_name}_avoid_parsing" %>
154
- <%= f.label :avoid_parsing %>
155
- </div>
156
152
  </div>
157
153
  <%=
158
154
  f.text_area(
@@ -1,6 +1,7 @@
1
1
  <% if collection.any? %>
2
2
  <ul class="post-category-tree">
3
3
  <% collection.each do |category_id, item| %>
4
+ <% next unless handler.allow_category_branch?(category_id) %>
4
5
  <li>
5
6
  <%
6
7
  element_id = "post_category_#{category_id}"
@@ -101,6 +101,8 @@ ru:
101
101
  uuid: "UUID"
102
102
  view_count: "Количество просмотров"
103
103
  visible: "Показывать"
104
+ post_attachment:
105
+ file: "Файл"
104
106
  post_category:
105
107
  children_cache: "Кеш дочек"
106
108
  meta_description: "Описание для тэга meta"
@@ -287,6 +289,8 @@ ru:
287
289
  search: "Искать"
288
290
  in_list:
289
291
  post_categories: "Категории публикаций"
292
+ attachments:
293
+ heading: "Приложения"
290
294
  filter:
291
295
  filter: "Фильтровать"
292
296
  search:
@@ -30,6 +30,7 @@ Rails.application.routes.draw do
30
30
  resources :featured_posts, only: :destroy
31
31
  resources :post_illustrations, only: :create
32
32
  resources :post_groups, only: %i[update destroy]
33
+ resources :post_attachments, only: :destroy
33
34
 
34
35
  scope '/(:locale)', constraints: { locale: /ru|en|sv|cn/ } do
35
36
  resources :post_categories, except: %i[index show update destroy]
@@ -84,6 +85,10 @@ Rails.application.routes.draw do
84
85
  get ':slug' => :show, as: :author
85
86
  end
86
87
 
88
+ scope 'u/:slug', controller: :profiles, constraints: { slug: %r{[^/]+} } do
89
+ get 'posts' => :posts, as: :user_posts
90
+ end
91
+
87
92
  namespace :admin do
88
93
  resources :post_types, only: %i[index show] do
89
94
  member do
@@ -52,14 +52,10 @@ class CreatePosts < ActiveRecord::Migration[5.2]
52
52
  t.boolean :translation, default: false, null: false
53
53
  t.boolean :explicit, default: false, null: false
54
54
  t.boolean :spam, default: false, null: false
55
- t.boolean :avoid_parsing, default: false, null: false
56
55
  t.float :rating, default: 0.0, null: false
57
56
  t.integer :privacy, limit: 2, default: 0
58
57
  t.integer :comments_count, default: 0, null: false
59
58
  t.integer :view_count, default: 0, null: false
60
- t.integer :upvote_count, default: 0, null: false
61
- t.integer :downvote_count, default: 0, null: false
62
- t.integer :vote_result, default: 0, null: false
63
59
  t.integer :time_required, limit: 2
64
60
  t.datetime :publication_time
65
61
  t.uuid :uuid, null: false
@@ -82,7 +78,6 @@ class CreatePosts < ActiveRecord::Migration[5.2]
82
78
  t.string :translator_name
83
79
  t.text :lead
84
80
  t.text :body, null: false
85
- t.text :parsed_body
86
81
  t.string :tags_cache, array: true, default: [], null: false
87
82
  t.jsonb :data, default: {}, null: false
88
83
  end
@@ -105,10 +100,9 @@ class CreatePosts < ActiveRecord::Migration[5.2]
105
100
 
106
101
  add_foreign_key :posts, :posts, column: :original_post_id, on_update: :cascade, on_delete: :nullify
107
102
 
103
+ add_index :posts, :uuid, unique: true
108
104
  add_index :posts, :created_at
109
105
  add_index :posts, :data, using: :gin
110
-
111
- Post.__elasticsearch__.create_index! if Gem.loaded_specs.key?('elasticsearch-model')
112
106
  end
113
107
 
114
108
  def create_post_post_tags
@@ -144,7 +138,7 @@ class CreatePosts < ActiveRecord::Migration[5.2]
144
138
  t.timestamps
145
139
  t.boolean :visible, default: true, null: false
146
140
  t.integer :priority, limit: 2, default: 1, null: false
147
- t.uuid :uuid
141
+ t.uuid :uuid, null: false
148
142
  t.string :image
149
143
  t.string :image_alt_text
150
144
  t.string :caption
@@ -152,6 +146,8 @@ class CreatePosts < ActiveRecord::Migration[5.2]
152
146
  t.string :source_link
153
147
  t.text :description
154
148
  end
149
+
150
+ add_index :post_images, :uuid, unique: true
155
151
  end
156
152
 
157
153
  def create_post_translations
@@ -208,10 +204,12 @@ class CreatePosts < ActiveRecord::Migration[5.2]
208
204
  def create_post_attachments
209
205
  create_table :post_attachments, comment: 'Attachment for post' do |t|
210
206
  t.references :post, foreign_key: { on_update: :cascade, on_delete: :cascade }
211
- t.uuid :uuid
207
+ t.uuid :uuid, null: false
212
208
  t.timestamps
213
209
  t.string :name
214
210
  t.string :file
215
211
  end
212
+
213
+ add_index :post_attachments, :uuid, unique: true
216
214
  end
217
215
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Move legacy votes component fields to data in posts
4
+ class ConvertPostsVoteData < ActiveRecord::Migration[5.2]
5
+ def up
6
+ return unless column_exists?(:posts, :vote_result)
7
+
8
+ Post.order('id asc').each do |post|
9
+ post.data['votes'] = {
10
+ up: post.upvote_count,
11
+ down: post.downvote_count,
12
+ total: post.vote_result
13
+ }
14
+ post.save!
15
+ end
16
+
17
+ remove_column :posts, :upvote_count
18
+ remove_column :posts, :downvote_count
19
+ remove_column :posts, :vote_result
20
+ end
21
+
22
+ def down
23
+ # No rollback needed
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ ProfilesController.class_eval do
4
+ # get /u/:slug/posts
5
+ def posts
6
+ @collection = Post.owned_by(@entity).page_for_visitors(current_page)
7
+ render 'posts/index'
8
+ end
9
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'biovision/base'
2
4
  require 'carrierwave'
3
5
  require 'carrierwave-bombshelter'
@@ -5,14 +7,18 @@ require 'mini_magick'
5
7
 
6
8
  module Biovision
7
9
  module Post
10
+ # Initialization of the engine
8
11
  class Engine < ::Rails::Engine
12
+ initializer 'biovision_post.load_base_methods' do
13
+ require_dependency 'biovision/post/decorators/controllers/profiles_controller_decorator'
14
+ end
15
+
9
16
  config.generators do |g|
10
17
  g.test_framework :rspec
11
18
  g.fixture_replacement :factory_bot, :dir => 'spec/factories'
12
19
  end
13
20
 
14
- config.assets.precompile << %w(admin.scss)
15
- config.assets.precompile << %w(biovision/base/**/*)
21
+ config.assets.precompile << %w[admin.scss biovision/base/**/*]
16
22
  end
17
23
  end
18
24
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Biovision
4
4
  module Post
5
- VERSION = '0.28.191126.0'
5
+ VERSION = '0.31.200627.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biovision-post
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.191126.0
4
+ version: 0.31.200627.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxim Khan-Magomedov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-26 00:00:00.000000000 Z
11
+ date: 2020-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '5.1'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '5.1'
27
- - !ruby/object:Gem::Dependency
28
- name: rails-i18n
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '5.0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '5.0'
41
13
  - !ruby/object:Gem::Dependency
42
14
  name: biovision-base
43
15
  requirement: !ruby/object:Gem::Requirement
@@ -201,6 +173,7 @@ files:
201
173
  - app/views/admin/featured_posts/_nav_item.html.erb
202
174
  - app/views/admin/featured_posts/entity/_in_list.html.erb
203
175
  - app/views/admin/featured_posts/index.html.erb
176
+ - app/views/admin/post_attachments/entity/_in_list.html.erb
204
177
  - app/views/admin/post_categories/entity/_in_list.html.erb
205
178
  - app/views/admin/post_categories/show.html.erb
206
179
  - app/views/admin/post_group_categories/entity/_in_list.html.erb
@@ -236,6 +209,7 @@ files:
236
209
  - app/views/admin/posts/_filter.html.erb
237
210
  - app/views/admin/posts/_nav_item.html.erb
238
211
  - app/views/admin/posts/_search_form.html.erb
212
+ - app/views/admin/posts/entity/_attachments.html.erb
239
213
  - app/views/admin/posts/entity/_in_list.html.erb
240
214
  - app/views/admin/posts/entity/_in_search.html.erb
241
215
  - app/views/admin/posts/entity/_links.html.erb
@@ -342,25 +316,26 @@ files:
342
316
  - db/amends/20190224212122_rename_post_image_source.rb
343
317
  - db/amends/20190224212123_add_uuid_to_post_images.rb
344
318
  - db/amends/20190313141414_convert_json_post_columns.rb
319
+ - db/amends/20190401101010_create_post_illustrations.rb
320
+ - db/amends/20190407101010_create_editorial_member_post_types.rb
321
+ - db/amends/20190410120000_create_post_groups.rb
322
+ - db/amends/20190412191919_add_nav_text_to_post_categories.rb
323
+ - db/amends/20190412212121_add_url_part_to_post_types.rb
324
+ - db/amends/20190420212121_create_post_layouts.rb
325
+ - db/amends/20190424161616_create_post_post_categories.rb
345
326
  - db/amends/20190925181818_add_search_index_to_posts.rb
346
327
  - db/migrate/20170930000001_create_post_types.rb
347
328
  - db/migrate/20170930000010_create_posts.rb
348
329
  - db/migrate/20180706000000_create_editorial_members.rb
349
330
  - db/migrate/20180808000000_create_zen_categories.rb
350
- - db/migrate/20190401101010_create_post_illustrations.rb
351
- - db/migrate/20190407101010_create_editorial_member_post_types.rb
352
- - db/migrate/20190410101010_add_avoid_parsing_to_posts.rb
353
- - db/migrate/20190410120000_create_post_groups.rb
354
- - db/migrate/20190412191919_add_nav_text_to_post_categories.rb
355
- - db/migrate/20190412212121_add_url_part_to_post_types.rb
356
- - db/migrate/20190420212121_create_post_layouts.rb
357
- - db/migrate/20190424161616_create_post_post_categories.rb
358
331
  - db/migrate/20190715141414_add_data_to_post_categories.rb
359
332
  - db/migrate/20190801161616_add_posts_component.rb
360
333
  - db/migrate/20190822121212_create_post_attachments.rb
361
334
  - db/migrate/20190914212121_convert_post_privileges.rb
362
335
  - db/migrate/20191124232323_convert_editorial_privileges.rb
336
+ - db/migrate/20200207141414_convert_posts_vote_data.rb
363
337
  - lib/biovision/post.rb
338
+ - lib/biovision/post/decorators/controllers/profiles_controller_decorator.rb
364
339
  - lib/biovision/post/engine.rb
365
340
  - lib/biovision/post/version.rb
366
341
  - lib/tasks/biovision/post_tasks.rake
@@ -384,7 +359,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
384
359
  - !ruby/object:Gem::Version
385
360
  version: '0'
386
361
  requirements: []
387
- rubygems_version: 3.0.6
362
+ rubygems_version: 3.1.4
388
363
  signing_key:
389
364
  specification_version: 4
390
365
  summary: Posts for biovision-based applications
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Add flag for avoiding post parsing
4
- class AddAvoidParsingToPosts < ActiveRecord::Migration[5.2]
5
- def up
6
- return if column_exists?(:posts, :avoid_parsing)
7
-
8
- add_column :posts, :avoid_parsing, :boolean, default: false, null: false
9
- end
10
-
11
- def down
12
- # No rollback needed
13
- end
14
- end