effective_posts 2.4.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f406e0650b91463c3e1b876f9001bdafbf683563d9bf943512b7d87f8c00f9e
4
- data.tar.gz: 1241584d8be8da46c3fa6f44fb765796a34e8ee74e6f137580d1984dc0a0d982
3
+ metadata.gz: fb8b8e024f90c5178e6904396c0f2e565d54e5b4eb0eac92c41e9442089016c3
4
+ data.tar.gz: bfe539309dbf2538961d899773af1855a54127864f8fcd98f9e375b1500bd452
5
5
  SHA512:
6
- metadata.gz: 9eade43433c5c0da6e64816a25c5cc8857702a2af369b1f7027c4cbe44b8f78370e4ad853f40555a9ce7f1f9428a72f330ec09e530b0f956f74bdcb775d157eb
7
- data.tar.gz: d8107969ffb90e822afe14507044e8a040d65cb97e7c3a9444a648b90768cf9637c67a88ee2dbc07aacdeafea6a585895ac3f94f286f24275de9c2b8c466614a
6
+ metadata.gz: 821dc29782ba4a54c87425c9fec3f993d1febcd5b43c5b256462df60f700afddde1e07eb2bd803af1508c4b359ffda6f7f4e3c956ce8facd70c751d9b9590ba9
7
+ data.tar.gz: bbf9908b09e91896d285496ef14aa59bf1eab7bd07ef479ae7d528a91801a9705b439a5c78365fa78ee648b25118e46dce7488c053c92b346c33b4bd14311474
@@ -36,7 +36,9 @@ module Effective
36
36
  def show
37
37
  @category = EffectivePosts.category(params[:category])
38
38
 
39
- @posts ||= Effective::Post.posts(user: current_user, unpublished: EffectiveResources.authorized?(self, :admin, :effective_posts))
39
+ admin = EffectiveResources.authorized?(self, :admin, :effective_posts)
40
+
41
+ @posts ||= Effective::Post.posts(user: current_user, unpublished: admin, archived: admin)
40
42
  @post = @posts.find(params[:id])
41
43
 
42
44
  if @post.respond_to?(:roles_permit?)
@@ -45,10 +47,11 @@ module Effective
45
47
 
46
48
  EffectiveResources.authorize!(self, :show, @post)
47
49
 
48
- if EffectiveResources.authorized?(self, :admin, :effective_posts)
50
+ if admin
49
51
  flash.now[:warning] = [
50
52
  'Hi Admin!',
51
53
  ('You are viewing a hidden post.' unless @post.published?),
54
+ ('You are viewing an archived post.' if @post.archived?),
52
55
  'Click here to',
53
56
  ("<a href='#{effective_posts.edit_admin_post_path(@post)}' class='alert-link'>edit post settings</a>.")
54
57
  ].compact.join(' ')
@@ -1,15 +1,23 @@
1
1
  class EffectivePostsDatatable < Effective::Datatable
2
+ bulk_actions do
3
+ bulk_action('Archive selected', effective_posts.bulk_archive_admin_posts_path)
4
+ bulk_action('Unarchive selected', effective_posts.bulk_unarchive_admin_posts_path)
5
+ end
6
+
2
7
  filters do
3
- scope :all
8
+ scope :unarchived, label: 'All'
4
9
  scope :published
5
10
  scope :unpublished
6
11
  scope :news
7
12
  scope :events
13
+ scope :archived
8
14
  end
9
15
 
10
16
  datatable do
11
17
  order :published_at, :desc
12
18
 
19
+ bulk_actions_col
20
+
13
21
  col :published_at
14
22
  col :id, visible: false
15
23
 
@@ -27,6 +35,8 @@ class EffectivePostsDatatable < Effective::Datatable
27
35
  col :draft
28
36
  end
29
37
 
38
+ col :archived
39
+
30
40
  col :start_at
31
41
  col :end_at, visible: false
32
42
  col :location, visible: false
@@ -71,7 +71,9 @@ module EffectivePostsHelper
71
71
  def admin_post_status_badge(post)
72
72
  return nil unless EffectiveResources.authorized?(self, :admin, :effective_posts)
73
73
 
74
- if post.draft?
74
+ if post.archived?
75
+ content_tag(:span, 'ARCHIVED', class: 'badge badge-info')
76
+ elsif post.draft?
75
77
  content_tag(:span, 'DRAFT', class: 'badge badge-info')
76
78
  elsif post.published? == false
77
79
  content_tag(:span, "TO BE PUBLISHED AT #{post.published_at&.strftime('%F %H:%M') || 'LATER'}", class: 'badge badge-info')
@@ -8,7 +8,9 @@ module Effective
8
8
 
9
9
  attr_accessor :current_user
10
10
 
11
+ acts_as_archived
11
12
  acts_as_slugged
13
+
12
14
  log_changes if respond_to?(:log_changes)
13
15
  acts_as_tagged if respond_to?(:acts_as_tagged)
14
16
  acts_as_role_restricted if respond_to?(:acts_as_role_restricted)
@@ -34,6 +36,7 @@ module Effective
34
36
  tags :text
35
37
 
36
38
  roles_mask :integer
39
+ archived :boolean
37
40
 
38
41
  # Event Fields
39
42
  start_at :datetime
@@ -56,16 +59,24 @@ module Effective
56
59
  validates :published_at, presence: true, unless: -> { draft? }
57
60
  validates :start_at, presence: true, if: -> { category == 'events' }
58
61
 
59
- scope :drafts, -> { where(draft: true) }
60
- scope :published, -> { where(draft: false).where("published_at < ?", Time.zone.now) }
61
- scope :unpublished, -> { where(draft: true).or(where("published_at > ?", Time.zone.now)) }
62
- scope :with_category, -> (category) { where(category: category) }
62
+ scope :unarchived, -> { where(archived: false) }
63
+ scope :archived, -> { where(archived: true) }
64
+
65
+ scope :drafts, -> { unarchived.where(draft: true) }
66
+ scope :published, -> { unarchived.where(draft: false).where("published_at < ?", Time.zone.now) }
67
+ scope :unpublished, -> { unarchived.where(draft: true).or(where("published_at > ?", Time.zone.now)) }
63
68
 
64
69
  # Kind of a meta category
65
- scope :news, -> { where(category: EffectivePosts.news_categories) }
66
- scope :events, -> { where(category: EffectivePosts.event_categories) }
70
+ scope :news, -> { unarchived.where(category: EffectivePosts.news_categories) }
71
+ scope :events, -> { unarchived.where(category: EffectivePosts.event_categories) }
72
+
73
+ scope :with_category, -> (category) { where(category: category) } # Don't add unarchived here
67
74
 
68
- scope :deep, -> { with_rich_text_excerpt_and_embeds.with_rich_text_body_and_embeds }
75
+ scope :deep, -> {
76
+ base = with_attached_image.with_rich_text_excerpt_and_embeds.with_rich_text_body_and_embeds
77
+ base = base.includes(:pg_search_document) if defined?(PgSearch)
78
+ base
79
+ }
69
80
 
70
81
  scope :paginate, -> (page: nil, per_page: EffectivePosts.per_page) {
71
82
  page = (page || 1).to_i
@@ -74,7 +85,7 @@ module Effective
74
85
  limit(per_page).offset(offset)
75
86
  }
76
87
 
77
- scope :posts, -> (user: nil, category: nil, unpublished: false) {
88
+ scope :posts, -> (user: nil, category: nil, unpublished: false, archived: false) {
78
89
  scope = all.deep.order(published_at: :desc)
79
90
 
80
91
  if defined?(EffectiveRoles) && EffectivePosts.use_effective_roles
@@ -91,6 +102,10 @@ module Effective
91
102
  scope = scope.published
92
103
  end
93
104
 
105
+ unless archived
106
+ scope = scope.unarchived
107
+ end
108
+
94
109
  scope
95
110
  }
96
111
 
@@ -36,6 +36,8 @@
36
36
 
37
37
  = f.check_box :draft, hint: 'Save this post as a draft. It will not be accessible on the website.'
38
38
 
39
+ = f.check_box :archived, label: 'Yes, this post is archived. It will not be displayed.'
40
+
39
41
  - if EffectivePosts.use_effective_roles
40
42
  = render partial: '/admin/posts/roles', locals: { post: post, form: f, f: f }
41
43
 
data/config/routes.rb CHANGED
@@ -2,6 +2,11 @@ EffectivePosts::Engine.routes.draw do
2
2
  namespace :admin do
3
3
  resources :posts, except: [:show] do
4
4
  post :approve, on: :member
5
+
6
+ post :archive, on: :member
7
+ post :unarchive, on: :member
8
+ post :bulk_archive, on: :collection
9
+ post :bulk_unarchive, on: :collection
5
10
  end
6
11
  end
7
12
 
@@ -10,12 +10,13 @@ class CreateEffectivePosts < ActiveRecord::Migration[6.0]
10
10
  t.string :category
11
11
  t.string :slug
12
12
 
13
- t.boolean :draft, :default => false
13
+ t.boolean :draft, default: false
14
14
  t.datetime :published_at
15
15
 
16
16
  t.text :tags
17
17
 
18
- t.integer :roles_mask, :default => 0
18
+ t.integer :roles_mask, default: 0
19
+ t.boolean :archived, default: false
19
20
 
20
21
  # Events fields
21
22
  t.datetime :start_at
@@ -1,3 +1,3 @@
1
1
  module EffectivePosts
2
- VERSION = '2.4.1'.freeze
2
+ VERSION = '2.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_posts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-24 00:00:00.000000000 Z
11
+ date: 2024-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails