biovision-post 0.2.180325 → 0.21.190513.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +79 -13
- data/app/assets/images/biovision/post/icons/time.svg +6 -0
- data/app/assets/images/biovision/post/publisher_logo.png +0 -0
- data/app/assets/javascripts/biovision/post/biovision-posts.js +258 -0
- data/app/assets/stylesheets/biovision/post/admin/posts.scss +93 -0
- data/app/assets/stylesheets/biovision/post/posts.scss +88 -37
- data/app/controllers/admin/editorial_members_controller.rb +43 -0
- data/app/controllers/admin/featured_posts_controller.rb +23 -0
- data/app/controllers/admin/post_group_categories_controller.rb +19 -0
- data/app/controllers/admin/post_group_tags_controller.rb +19 -0
- data/app/controllers/admin/post_groups_controller.rb +62 -0
- data/app/controllers/admin/post_illustrations_controller.rb +26 -0
- data/app/controllers/admin/post_images_controller.rb +33 -0
- data/app/controllers/admin/post_links_controller.rb +19 -0
- data/app/controllers/admin/post_tags_controller.rb +30 -0
- data/app/controllers/admin/post_types_controller.rb +16 -4
- data/app/controllers/admin/posts_controller.rb +26 -2
- data/app/controllers/articles_controller.rb +23 -11
- data/app/controllers/authors_controller.rb +27 -0
- data/app/controllers/blog_posts_controller.rb +23 -11
- data/app/controllers/editorial_members_controller.rb +65 -0
- data/app/controllers/featured_posts_controller.rb +59 -0
- data/app/controllers/my/posts_controller.rb +124 -0
- data/app/controllers/news_controller.rb +23 -11
- data/app/controllers/post_categories_controller.rb +4 -14
- data/app/controllers/post_groups_controller.rb +76 -0
- data/app/controllers/post_illustrations_controller.rb +22 -0
- data/app/controllers/post_images_controller.rb +62 -0
- data/app/controllers/post_links_controller.rb +37 -0
- data/app/controllers/post_tags_controller.rb +41 -0
- data/app/controllers/posts_controller.rb +119 -14
- data/app/helpers/biovision_posts_helper.rb +114 -5
- data/app/jobs/application_job.rb +7 -0
- data/app/jobs/post_body_parser_job.rb +15 -0
- data/app/models/editorial_member.rb +92 -0
- data/app/models/editorial_member_post_type.rb +15 -0
- data/app/models/featured_post.rb +25 -0
- data/app/models/post.rb +203 -38
- data/app/models/post_category.rb +76 -54
- data/app/models/post_group.rb +84 -0
- data/app/models/post_group_category.rb +36 -0
- data/app/models/post_group_tag.rb +32 -0
- data/app/models/post_illustration.rb +62 -0
- data/app/models/post_image.rb +88 -0
- data/app/models/post_layout.rb +14 -0
- data/app/models/post_link.rb +2 -0
- data/app/models/post_post_category.rb +24 -0
- data/app/models/post_post_tag.rb +21 -0
- data/app/models/post_tag.rb +70 -0
- data/app/models/post_translation.rb +7 -0
- data/app/models/post_type.rb +18 -2
- data/app/models/post_zen_category.rb +6 -0
- data/app/models/zen_category.rb +21 -0
- data/app/services/post_manager.rb +52 -15
- data/app/services/post_parser.rb +80 -0
- data/app/uploaders/post_image_uploader.rb +9 -9
- data/app/views/admin/editorial_members/_nav_item.html.erb +2 -0
- data/app/views/admin/editorial_members/entity/_in_list.html.erb +37 -0
- data/app/views/admin/editorial_members/index.html.erb +15 -0
- data/app/views/admin/editorial_members/show.html.erb +71 -0
- data/app/views/admin/featured_posts/_add.html.erb +140 -0
- data/app/views/admin/featured_posts/_language.html.erb +14 -0
- data/app/views/admin/featured_posts/_nav_item.html.erb +2 -0
- data/app/views/admin/featured_posts/entity/_in_list.html.erb +26 -0
- data/app/views/admin/featured_posts/index.html.erb +18 -0
- data/app/views/admin/index/dashboard/_biovision_post.html.erb +32 -25
- data/app/views/admin/post_categories/entity/_in_list.html.erb +22 -6
- data/app/views/admin/post_categories/show.html.erb +6 -1
- data/app/views/admin/post_group_categories/entity/_in_list.html.erb +18 -0
- data/app/views/admin/post_group_tags/entity/_in_list.html.erb +18 -0
- data/app/views/admin/post_groups/_nav_item.html.erb +6 -0
- data/app/views/admin/post_groups/entity/_categories.html.erb +33 -0
- data/app/views/admin/post_groups/entity/_in_list.html.erb +25 -0
- data/app/views/admin/post_groups/index.html.erb +22 -0
- data/app/views/admin/post_groups/show.html.erb +65 -0
- data/app/views/admin/post_groups/tags.jbuilder +12 -0
- data/app/views/admin/post_illustrations/_nav_item.html.erb +6 -0
- data/app/views/admin/post_illustrations/entity/_in_list.html.erb +19 -0
- data/app/views/admin/post_illustrations/index.html.erb +23 -0
- data/app/views/admin/post_illustrations/show.html.erb +32 -0
- data/app/views/admin/post_images/_nav_item.html.erb +2 -0
- data/app/views/admin/post_images/entity/_in_list.html.erb +30 -0
- data/app/views/admin/post_images/index.html.erb +16 -0
- data/app/views/admin/post_images/show.html.erb +49 -0
- data/app/views/admin/post_links/entity/_in_list.html.erb +43 -0
- data/app/views/admin/post_tags/_nav_item.html.erb +2 -0
- data/app/views/admin/post_tags/entity/_in_list.html.erb +23 -0
- data/app/views/admin/post_tags/index.html.erb +16 -0
- data/app/views/admin/post_tags/posts.html.erb +18 -0
- data/app/views/admin/post_tags/show.html.erb +37 -0
- data/app/views/admin/post_types/authors.html.erb +23 -0
- data/app/views/admin/post_types/post_categories.html.erb +15 -4
- data/app/views/admin/post_types/post_tags.html.erb +18 -0
- data/app/views/admin/post_types/show.html.erb +28 -5
- data/app/views/admin/posts/_filter.html.erb +19 -0
- data/app/views/admin/posts/_nav_item.html.erb +3 -0
- data/app/views/admin/posts/_search_form.html.erb +13 -0
- data/app/views/admin/posts/entity/_in_list.html.erb +31 -7
- data/app/views/admin/posts/entity/_in_search.html.erb +8 -0
- data/app/views/admin/posts/entity/_links.html.erb +125 -0
- data/app/views/admin/posts/images.html.erb +22 -0
- data/app/views/admin/posts/index.html.erb +4 -0
- data/app/views/admin/posts/search.html.erb +21 -0
- data/app/views/admin/posts/search.jbuilder +26 -0
- data/app/views/admin/posts/show.html.erb +118 -18
- data/app/views/articles/category.html.erb +9 -9
- data/app/views/articles/index.html.erb +12 -9
- data/app/views/articles/show.html.erb +2 -4
- data/app/views/articles/tagged.html.erb +14 -0
- data/app/views/authors/_list.html.erb +18 -0
- data/app/views/authors/entity/_in_list.html.erb +9 -0
- data/app/views/authors/index.html.erb +10 -0
- data/app/views/authors/show.html.erb +31 -0
- data/app/views/blog_posts/category.html.erb +9 -9
- data/app/views/blog_posts/index.html.erb +12 -9
- data/app/views/blog_posts/show.html.erb +2 -4
- data/app/views/blog_posts/tagged.html.erb +14 -0
- data/app/views/editorial_members/_form.html.erb +107 -0
- data/app/views/editorial_members/edit.html.erb +17 -0
- data/app/views/editorial_members/new.html.erb +15 -0
- data/app/views/featured_posts/create.jbuilder +10 -0
- data/app/views/index/dashboard/_biovision_post.html.erb +18 -2
- data/app/views/my/index/dashboard/_biovision_post.html.erb +43 -0
- data/app/views/my/posts/_form.html.erb +357 -0
- data/app/views/my/posts/_list.html.erb +9 -0
- data/app/views/my/posts/_post.html.erb +80 -0
- data/app/views/my/posts/_preview.html.erb +35 -0
- data/app/views/my/posts/articles.html.erb +24 -0
- data/app/views/my/posts/blog_posts.html.erb +24 -0
- data/app/views/my/posts/edit.html.erb +19 -0
- data/app/views/my/posts/index.html.erb +14 -0
- data/app/views/my/posts/index/_navigation.html.erb +29 -0
- data/app/views/my/posts/new.html.erb +14 -0
- data/app/views/my/posts/news_index.html.erb +24 -0
- data/app/views/my/posts/show.html.erb +7 -0
- data/app/views/news/category.html.erb +9 -9
- data/app/views/news/index.html.erb +12 -9
- data/app/views/news/show.html.erb +2 -4
- data/app/views/news/tagged.html.erb +14 -0
- data/app/views/post_categories/_form.html.erb +82 -43
- data/app/views/post_groups/_form.html.erb +79 -0
- data/app/views/post_groups/edit.html.erb +17 -0
- data/app/views/post_groups/new.html.erb +15 -0
- data/app/views/post_groups/show.html.erb +10 -0
- data/app/views/post_images/_form.html.erb +121 -0
- data/app/views/post_images/edit.html.erb +19 -0
- data/app/views/post_images/new.html.erb +18 -0
- data/app/views/post_links/create.jbuilder +20 -0
- data/app/views/post_tags/_form.html.erb +26 -0
- data/app/views/post_tags/edit.html.erb +18 -0
- data/app/views/post_tags/new.html.erb +18 -0
- data/app/views/posts/_archive_dates.jbuilder +13 -0
- data/app/views/posts/_breadcrumbs.html.erb +4 -8
- data/app/views/posts/_calendar.html.erb +9 -0
- data/app/views/posts/_collection.html.erb +5 -0
- data/app/views/posts/_form.html.erb +204 -64
- data/app/views/posts/_list.html.erb +1 -1
- data/app/views/{articles/index.jbuilder → posts/_list.jbuilder} +3 -3
- data/app/views/posts/_post.html.erb +43 -16
- data/app/views/posts/_preview.html.erb +32 -21
- data/app/views/posts/_search.html.erb +6 -0
- data/app/views/posts/_wysiwyg.html.erb +25 -0
- data/app/views/posts/archive.jbuilder +3 -0
- data/app/views/posts/archive_day.html.erb +12 -0
- data/app/views/posts/category.html.erb +18 -0
- data/app/views/posts/entity/_gallery.html.erb +54 -0
- data/app/views/posts/entity/_linked_posts.html.erb +7 -0
- data/app/views/posts/entity/_metadata.html.erb +35 -12
- data/app/views/posts/entity/_publisher.html.erb +3 -1
- data/app/views/posts/form/_category_links.html.erb +32 -0
- data/app/views/posts/form/_gallery.html.erb +163 -0
- data/app/views/posts/index.html.erb +13 -0
- data/app/views/posts/index.jbuilder +1 -0
- data/app/views/posts/post_type/_category.html.erb +7 -0
- data/app/views/posts/post_type/_post_page.html.erb +9 -0
- data/app/views/posts/post_type/_posts.html.erb +5 -0
- data/app/views/posts/post_type/_tagged.html.erb +7 -0
- data/app/views/posts/rss.xml.erb +47 -0
- data/app/views/posts/search.html.erb +15 -0
- data/app/views/posts/show.html.erb +5 -3
- data/app/views/posts/tagged.html.erb +10 -0
- data/app/views/posts/tagged.jbuilder +1 -0
- data/app/views/posts/zen.xml.erb +42 -0
- data/config/locales/posts-en.yml +257 -19
- data/config/locales/posts-ru.yml +380 -14
- data/config/locales/posts-sv.yml +416 -0
- data/config/routes.rb +111 -15
- data/db/{migrate → amends}/20180124111113_add_language_to_posts.rb +0 -0
- data/db/{migrate → amends}/20180318215555_add_active_to_post_types.rb +0 -0
- data/db/amends/20180606120000_add_original_title_to_posts.rb +9 -0
- data/db/amends/20180606120001_add_time_required_to_posts.rb +11 -0
- data/db/amends/20180611111111_add_pubdate_and_translator_to_posts.rb +19 -0
- data/db/amends/20180618111111_add_default_category_name_to_post_types.rb +15 -0
- data/db/amends/20180703191919_add_rating_to_posts.rb +14 -0
- data/db/amends/20180810111111_add_explicit_to_posts.rb +11 -0
- data/db/amends/20180825111111_add_meta_description_to_post_categories.rb +11 -0
- data/db/amends/20180927111111_amend_editorial_member_about.rb +13 -0
- data/db/migrate/20170930000001_create_post_types.rb +98 -20
- data/db/migrate/20170930000010_create_posts.rb +194 -0
- data/db/migrate/20180706000000_create_editorial_members.rb +37 -0
- data/db/migrate/20180808000000_create_zen_categories.rb +42 -0
- data/db/migrate/20190202232323_add_spam_to_posts.rb +11 -0
- data/db/migrate/20190224212121_add_data_to_posts.rb +13 -0
- data/db/migrate/20190224212122_rename_post_image_source.rb +26 -0
- data/db/migrate/20190224212123_add_uuid_to_post_images.rb +10 -0
- data/db/migrate/20190313141414_convert_json_post_columns.rb +25 -0
- data/db/migrate/20190401101010_create_post_illustrations.rb +20 -0
- data/db/migrate/20190407101010_create_editorial_member_post_types.rb +18 -0
- data/db/migrate/20190410101010_add_avoid_parsing_to_posts.rb +14 -0
- data/db/migrate/20190410120000_create_post_groups.rb +47 -0
- data/db/migrate/20190412191919_add_nav_text_to_post_categories.rb +14 -0
- data/db/migrate/20190412212121_add_url_part_to_post_types.rb +26 -0
- data/db/migrate/20190420212121_create_post_layouts.rb +27 -0
- data/db/migrate/20190424161616_create_post_post_categories.rb +31 -0
- data/lib/biovision/post/version.rb +3 -1
- data/lib/tasks/posts.rake +6 -0
- metadata +170 -25
- data/app/assets/images/biovision/post/publisher_logo.svg +0 -3
- data/app/services/post_manager/article_handler.rb +0 -10
- data/app/services/post_manager/blog_post_handler.rb +0 -10
- data/app/services/post_manager/news_handler.rb +0 -10
- data/app/views/admin/index/dashboard/biovision_post/_additional_items.html.erb +0 -0
- data/app/views/blog_posts/index.jbuilder +0 -11
- data/app/views/news/index.jbuilder +0 -11
- data/app/views/post_categories/edit.jbuilder +0 -3
- data/app/views/post_categories/edit.js.erb +0 -1
- data/app/views/post_categories/new.jbuilder +0 -3
- data/app/views/post_categories/new.js.erb +0 -1
- data/db/migrate/20170930000002_create_post_categories.rb +0 -29
- data/db/migrate/20170930000003_create_posts.rb +0 -60
- data/db/migrate/20171218111111_add_meta_fields_to_posts.rb +0 -15
- data/db/migrate/20171219111112_add_author_fields_to_posts.rb +0 -11
- data/db/migrate/20180321100000_create_post_references.rb +0 -21
- data/db/migrate/20180321100001_create_post_notes.rb +0 -18
- data/db/migrate/20180321100002_create_post_links.rb +0 -20
@@ -1,21 +1,37 @@
|
|
1
1
|
class NewsController < ApplicationController
|
2
|
-
before_action :set_category, only:
|
3
|
-
before_action :set_entity, only:
|
2
|
+
before_action :set_category, only: :category
|
3
|
+
before_action :set_entity, only: :show
|
4
4
|
|
5
5
|
# get /news
|
6
6
|
def index
|
7
7
|
post_type = PostType.find_by(slug: 'news')
|
8
8
|
@collection = post_type.posts.for_language(current_language).page_for_visitors(current_page)
|
9
|
+
respond_to do |format|
|
10
|
+
format.html
|
11
|
+
format.json { render('posts/index') }
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
# get /news/:category_slug
|
12
16
|
def category
|
13
|
-
@collection = @category.
|
17
|
+
@collection = Post.in_category_branch(@category).for_language(current_language).page_for_visitors(current_page)
|
18
|
+
respond_to do |format|
|
19
|
+
format.html
|
20
|
+
format.json { render('posts/index') }
|
21
|
+
end
|
14
22
|
end
|
15
23
|
|
16
24
|
# get /news/:post_id-:post_slug
|
17
25
|
def show
|
18
|
-
@entity.increment
|
26
|
+
@entity.increment :view_count
|
27
|
+
@entity.increment :rating, 0.0025
|
28
|
+
@entity.save
|
29
|
+
end
|
30
|
+
|
31
|
+
# get /news/tagged/:tag_name
|
32
|
+
def tagged
|
33
|
+
post_type = PostType.find_by(slug: 'news')
|
34
|
+
@collection = post_type.posts.tagged(params[:tag_name]).page_for_visitors(current_page)
|
19
35
|
end
|
20
36
|
|
21
37
|
private
|
@@ -23,15 +39,11 @@ class NewsController < ApplicationController
|
|
23
39
|
def set_category
|
24
40
|
type = PostType.find_by(slug: 'news')
|
25
41
|
@category = type.post_categories.find_by(long_slug: params[:category_slug])
|
26
|
-
if @category.nil?
|
27
|
-
handle_http_404('Cannot find post category (news)')
|
28
|
-
end
|
42
|
+
handle_http_404('Cannot find post category (news)') if @category.nil?
|
29
43
|
end
|
30
44
|
|
31
45
|
def set_entity
|
32
|
-
@entity = Post.
|
33
|
-
if @entity.nil?
|
34
|
-
handle_http_404('Cannot find news')
|
35
|
-
end
|
46
|
+
@entity = Post.list_for_visitors.find_by(id: params[:post_id])
|
47
|
+
handle_http_404('Cannot find news') if @entity.nil?
|
36
48
|
end
|
37
49
|
end
|
@@ -11,14 +11,9 @@ class PostCategoriesController < AdminController
|
|
11
11
|
def create
|
12
12
|
@entity = PostCategory.new(creation_parameters)
|
13
13
|
if @entity.save
|
14
|
-
|
15
|
-
respond_to do |format|
|
16
|
-
format.html { redirect_to(next_page) }
|
17
|
-
format.json { render json: { links: { self: next_page } } }
|
18
|
-
format.js { render(js: "document.location.href = '#{next_page}'") }
|
19
|
-
end
|
14
|
+
form_processed_ok(admin_post_category_path(id: @entity.id))
|
20
15
|
else
|
21
|
-
|
16
|
+
form_processed_with_error(:new)
|
22
17
|
end
|
23
18
|
end
|
24
19
|
|
@@ -29,14 +24,9 @@ class PostCategoriesController < AdminController
|
|
29
24
|
# patch /post_categories/:id
|
30
25
|
def update
|
31
26
|
if @entity.update entity_parameters
|
32
|
-
|
33
|
-
respond_to do |format|
|
34
|
-
format.html { redirect_to(next_page, notice: t('post_categories.update.success')) }
|
35
|
-
format.json { render json: { links: { self: next_page } } }
|
36
|
-
format.js { render(js: "document.location.href = '#{next_page}'") }
|
37
|
-
end
|
27
|
+
form_processed_ok(admin_post_category_path(id: @entity.id))
|
38
28
|
else
|
39
|
-
|
29
|
+
form_processed_with_error(:edit)
|
40
30
|
end
|
41
31
|
end
|
42
32
|
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Handling post groups
|
4
|
+
class PostGroupsController < ApplicationController
|
5
|
+
before_action :restrict_access, except: :show
|
6
|
+
before_action :set_entity, only: %i[edit update destroy]
|
7
|
+
|
8
|
+
layout 'admin', except: :show
|
9
|
+
|
10
|
+
# post /post_groups/check
|
11
|
+
def check
|
12
|
+
@entity = PostGroup.instance_for_check(params[:entity_id], entity_parameters)
|
13
|
+
|
14
|
+
render 'shared/forms/check'
|
15
|
+
end
|
16
|
+
|
17
|
+
# get /post_groups/new
|
18
|
+
def new
|
19
|
+
@entity = PostGroup.new
|
20
|
+
end
|
21
|
+
|
22
|
+
# post /post_groups
|
23
|
+
def create
|
24
|
+
@entity = PostGroup.new(entity_parameters)
|
25
|
+
if @entity.save
|
26
|
+
form_processed_ok(admin_post_group_path(id: @entity.id))
|
27
|
+
else
|
28
|
+
form_processed_with_error(:new)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# get /post_groups/:id/edit
|
33
|
+
def edit
|
34
|
+
end
|
35
|
+
|
36
|
+
# patch /post_groups/:id
|
37
|
+
def update
|
38
|
+
if @entity.update(entity_parameters)
|
39
|
+
form_processed_ok(admin_post_group_path(id: @entity.id))
|
40
|
+
else
|
41
|
+
form_processed_with_error(:edit)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# delete /post_groups/:id
|
46
|
+
def destroy
|
47
|
+
flash[:notice] = t('post_groups.destroy.success') if @entity.destroy
|
48
|
+
|
49
|
+
redirect_to post_groups_admin_post_type_path(id: @entity.post_type_id)
|
50
|
+
end
|
51
|
+
|
52
|
+
# get /post_groups/:id
|
53
|
+
def show
|
54
|
+
@entity = PostGroup.visible.find_by(slug: params[:id])
|
55
|
+
if @entity.nil?
|
56
|
+
handle_http_404('Cannot find post_group')
|
57
|
+
else
|
58
|
+
@collection = @entity.posts_page(current_page)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def set_entity
|
65
|
+
@entity = PostGroup.find_by(id: params[:id])
|
66
|
+
handle_http_404('Cannot find post_group') if @entity.nil?
|
67
|
+
end
|
68
|
+
|
69
|
+
def restrict_access
|
70
|
+
require_privilege :chief_editor
|
71
|
+
end
|
72
|
+
|
73
|
+
def entity_parameters
|
74
|
+
params.require(:post_group).permit(PostGroup.entity_parameters)
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Handling inline post image uploads
|
4
|
+
class PostIllustrationsController < ApplicationController
|
5
|
+
before_action :restrict_access
|
6
|
+
skip_before_action :verify_authenticity_token
|
7
|
+
|
8
|
+
# post /post_illustrations
|
9
|
+
def create
|
10
|
+
render json: PostIllustration.ckeditor_upload!(ckeditor_parameters)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def restrict_access
|
16
|
+
require_privilege_group :editors
|
17
|
+
end
|
18
|
+
|
19
|
+
def ckeditor_parameters
|
20
|
+
{ image: params[:upload] }.merge(owner_for_entity(true))
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class PostImagesController < AdminController
|
2
|
+
before_action :set_entity, only: [:edit, :update, :destroy]
|
3
|
+
before_action :restrict_editing, only: [:edit, :update, :destroy]
|
4
|
+
|
5
|
+
# post /post_images
|
6
|
+
def create
|
7
|
+
@entity = PostImage.new(creation_parameters)
|
8
|
+
if @entity.save
|
9
|
+
form_processed_ok(images_admin_post_path(id: @entity.post_id))
|
10
|
+
else
|
11
|
+
form_processed_with_error(:new)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# get /post_images/:id/edit
|
16
|
+
def edit
|
17
|
+
end
|
18
|
+
|
19
|
+
# patch /post_images/:id
|
20
|
+
def update
|
21
|
+
if @entity.update(entity_parameters)
|
22
|
+
form_processed_ok(admin_post_image_path(id: @entity.id))
|
23
|
+
else
|
24
|
+
form_processed_with_error(:edit)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# delete /post_images/:id
|
29
|
+
def destroy
|
30
|
+
if @entity.destroy
|
31
|
+
flash[:notice] = t('post_images.destroy.success')
|
32
|
+
end
|
33
|
+
redirect_to admin_post_path(id: @entity.post_id)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
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
|
43
|
+
end
|
44
|
+
|
45
|
+
def restrict_access
|
46
|
+
require_privilege_group :editors
|
47
|
+
end
|
48
|
+
|
49
|
+
def restrict_editing
|
50
|
+
unless @entity.editable_by?(current_user)
|
51
|
+
handle_http_401('Post image is not editable by current user')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def entity_parameters
|
56
|
+
params.require(:post_image).permit(PostImage.entity_parameters)
|
57
|
+
end
|
58
|
+
|
59
|
+
def creation_parameters
|
60
|
+
params.require(:post_image).permit(PostImage.creation_parameters)
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class PostLinksController < AdminController
|
2
|
+
before_action :set_entity, only: :destroy
|
3
|
+
|
4
|
+
# post /post_links
|
5
|
+
def create
|
6
|
+
@entity = PostLink.new(entity_parameters)
|
7
|
+
if @entity.save
|
8
|
+
render status: :created
|
9
|
+
else
|
10
|
+
render json: { errors: @entity.errors }, status: :bad_request
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# delete /post_links/:id
|
15
|
+
def destroy
|
16
|
+
@entity.destroy
|
17
|
+
|
18
|
+
head :no_content
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def restrict_access
|
24
|
+
require_privilege_group :editors
|
25
|
+
end
|
26
|
+
|
27
|
+
def entity_parameters
|
28
|
+
params.require(:post_link).permit(PostLink.creation_parameters)
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_entity
|
32
|
+
@entity = PostLink.find_by(id: params[:id])
|
33
|
+
if @entity.nil?
|
34
|
+
handle_http_404('Cannot find post_link')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Handling post tags
|
4
|
+
class PostTagsController < AdminController
|
5
|
+
before_action :set_entity, only: %i[edit update destroy]
|
6
|
+
|
7
|
+
# get /post_tags/:id/edit
|
8
|
+
def edit
|
9
|
+
end
|
10
|
+
|
11
|
+
# patch /post_tags/:id
|
12
|
+
def update
|
13
|
+
if @entity.update(entity_parameters)
|
14
|
+
form_processed_ok(admin_post_tag_path(id: @entity.id))
|
15
|
+
else
|
16
|
+
form_processed_with_error(:edit)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# delete /post_tags/:id
|
21
|
+
def destroy
|
22
|
+
flash[:notice] = t('post_tags.destroy.success') if @entity.destroy
|
23
|
+
|
24
|
+
redirect_to post_tags_admin_post_type_path(id: @entity.post_type_id)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def set_entity
|
30
|
+
@entity = PostTag.find_by(id: params[:id])
|
31
|
+
handle_http_404('Cannot find post_tag') if @entity.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
def restrict_access
|
35
|
+
require_privilege_group :editors
|
36
|
+
end
|
37
|
+
|
38
|
+
def entity_parameters
|
39
|
+
params.require(:post_tag).permit(PostTag.entity_parameters)
|
40
|
+
end
|
41
|
+
end
|
@@ -1,30 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Posts management
|
1
4
|
class PostsController < ApplicationController
|
2
|
-
before_action :restrict_access, only: [
|
3
|
-
before_action :set_entity, only: [
|
4
|
-
before_action :restrict_editing, only: [
|
5
|
+
before_action :restrict_access, only: %i[new create]
|
6
|
+
before_action :set_entity, only: %i[edit update destroy]
|
7
|
+
before_action :restrict_editing, only: %i[edit update destroy]
|
5
8
|
|
6
|
-
layout 'admin', only: [
|
9
|
+
layout 'admin', only: %i[new edit]
|
7
10
|
|
8
11
|
# get /posts
|
9
12
|
def index
|
10
|
-
|
13
|
+
excluded = param_from_request(:x).split(',').map(&:to_i)
|
14
|
+
@collection = Post.exclude_ids(excluded).page_for_visitors(current_page)
|
11
15
|
end
|
12
16
|
|
13
17
|
# post /posts
|
14
18
|
def create
|
15
19
|
@entity = Post.new(creation_parameters)
|
16
20
|
if @entity.save
|
17
|
-
|
21
|
+
apply_post_tags
|
22
|
+
apply_post_categories
|
23
|
+
PostBodyParserJob.perform_later(@entity.id)
|
24
|
+
form_processed_ok(PostManager.new(@entity).post_path)
|
18
25
|
else
|
19
26
|
form_processed_with_error(:new)
|
20
27
|
end
|
21
28
|
end
|
22
29
|
|
23
|
-
# get /posts/:id
|
30
|
+
# get /posts/:id(-:slug)
|
24
31
|
def show
|
25
32
|
@entity = Post.list_for_visitors.find_by(id: params[:id])
|
26
33
|
if @entity.nil?
|
27
34
|
handle_http_404("Cannot find non-deleted post #{params[:id]}")
|
35
|
+
else
|
36
|
+
@entity.increment :view_count
|
37
|
+
@entity.increment :rating, 0.0025
|
38
|
+
@entity.save
|
28
39
|
end
|
29
40
|
end
|
30
41
|
|
@@ -35,7 +46,10 @@ class PostsController < ApplicationController
|
|
35
46
|
# patch /posts/:id
|
36
47
|
def update
|
37
48
|
if @entity.update(entity_parameters)
|
38
|
-
|
49
|
+
apply_post_tags
|
50
|
+
apply_post_categories
|
51
|
+
PostBodyParserJob.perform_later(@entity.id)
|
52
|
+
form_processed_ok(PostManager.new(@entity).post_path)
|
39
53
|
else
|
40
54
|
form_processed_with_error(:edit)
|
41
55
|
end
|
@@ -49,13 +63,54 @@ class PostsController < ApplicationController
|
|
49
63
|
redirect_to admin_posts_path
|
50
64
|
end
|
51
65
|
|
66
|
+
# get /posts/tagged/:tag_name
|
67
|
+
def tagged
|
68
|
+
@collection = Post.tagged(params[:tag_name]).page_for_visitors(current_page)
|
69
|
+
end
|
70
|
+
|
71
|
+
# get /posts/:category_slug
|
72
|
+
def category
|
73
|
+
@collection = Post.in_category(params[:category_slug]).page_for_visitors(current_page)
|
74
|
+
@category = @collection.first&.post_category
|
75
|
+
|
76
|
+
handle_http_404('Cannot find post category in collection') if @category.nil?
|
77
|
+
|
78
|
+
respond_to do |format|
|
79
|
+
format.html
|
80
|
+
format.json { render('posts/index') }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# get /posts/search?q=
|
85
|
+
def search
|
86
|
+
@collection = params.key?(:q) ? search_posts(param_from_request(:q)) : []
|
87
|
+
end
|
88
|
+
|
89
|
+
# get /posts/rss/zen.xml
|
90
|
+
def zen
|
91
|
+
@collection = Post.for_language(current_language).list_for_visitors.posted_after(3.days.ago)
|
92
|
+
end
|
93
|
+
|
94
|
+
# get /posts/rss.xml
|
95
|
+
def rss
|
96
|
+
@collection = Post.for_language(current_language).list_for_visitors.first(20)
|
97
|
+
end
|
98
|
+
|
99
|
+
# get /posts/archive/(:year)(-:month)(-:day)
|
100
|
+
def archive
|
101
|
+
if params.key?(:day)
|
102
|
+
archive_day
|
103
|
+
else
|
104
|
+
collect_dates
|
105
|
+
archive_group if params[:year]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
52
109
|
private
|
53
110
|
|
54
111
|
def set_entity
|
55
112
|
@entity = Post.find_by(id: params[:id])
|
56
|
-
if @entity.nil?
|
57
|
-
handle_http_404('Cannot find post')
|
58
|
-
end
|
113
|
+
handle_http_404('Cannot find post') if @entity.nil?
|
59
114
|
end
|
60
115
|
|
61
116
|
def restrict_access
|
@@ -64,16 +119,66 @@ class PostsController < ApplicationController
|
|
64
119
|
|
65
120
|
def restrict_editing
|
66
121
|
if @entity.locked? || !@entity.editable_by?(current_user)
|
67
|
-
|
122
|
+
handle_http_403('Post is locked or not editable by current user')
|
68
123
|
end
|
69
124
|
end
|
70
125
|
|
71
126
|
def entity_parameters
|
72
|
-
params.require(:post).permit(Post.entity_parameters)
|
127
|
+
params.require(:post).permit(Post.entity_parameters).merge(owner_for_post)
|
73
128
|
end
|
74
129
|
|
75
130
|
def creation_parameters
|
76
131
|
parameters = params.require(:post).permit(Post.creation_parameters)
|
77
|
-
parameters.merge(owner_for_entity(true))
|
132
|
+
parameters.merge(owner_for_entity(true)).merge(owner_for_post)
|
133
|
+
end
|
134
|
+
|
135
|
+
def apply_post_tags
|
136
|
+
@entity.tags_string = param_from_request(:tags_string)
|
137
|
+
end
|
138
|
+
|
139
|
+
def apply_post_categories
|
140
|
+
if params.key?(:post_category_ids)
|
141
|
+
@entity.post_category_ids = Array(params[:post_category_ids])
|
142
|
+
else
|
143
|
+
@entity.post_post_categories.destroy_all
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def owner_for_post
|
148
|
+
key = :user_for_entity
|
149
|
+
result = {}
|
150
|
+
if current_user_has_privilege?(:chief_editor) && params.key?(key)
|
151
|
+
result[:user_id] = param_from_request(key)
|
152
|
+
end
|
153
|
+
result
|
154
|
+
end
|
155
|
+
|
156
|
+
def collect_dates
|
157
|
+
array = Post.for_language(current_language).visible.published.archive
|
158
|
+
@dates = Post.archive_dates(array)
|
159
|
+
end
|
160
|
+
|
161
|
+
def archive_day
|
162
|
+
date = Date.parse("#{params[:year]}-#{params[:month]}-#{params[:day]}")
|
163
|
+
selection = Post.for_language(current_language).pubdate(date)
|
164
|
+
@collection = selection.page_for_visitors(current_page)
|
165
|
+
render 'archive_day'
|
166
|
+
end
|
167
|
+
|
168
|
+
def archive_group
|
169
|
+
year = params[:year].to_i
|
170
|
+
@dates.select! { |k, _| k == year }
|
171
|
+
return unless params.key?(:month)
|
172
|
+
|
173
|
+
@dates[year]&.select! { |k, _| k == params[:month].to_i }
|
174
|
+
end
|
175
|
+
|
176
|
+
# @param [String] q
|
177
|
+
def search_posts(q)
|
178
|
+
if Post.respond_to?(:search)
|
179
|
+
Post.search(q).records.first(50).select(&:visible_to_visitors?)
|
180
|
+
else
|
181
|
+
Post.where('title ilike ?', "%#{q}%").list_for_visitors.first(50)
|
182
|
+
end
|
78
183
|
end
|
79
184
|
end
|