Module: Plugins::VisibilityPost::VisibilityPostHelper

Defined in:
app/apps/plugins/visibility_post/visibility_post_helper.rb

Constant Summary collapse

SESSION_UNLOCKED_KEY =

Session key listing the post ids this session has unlocked by password (audit M2). Shared with FrontController#unlock, which writes it after a successful comparison.

'cama_visibility_unlocked_posts'.freeze

Instance Method Summary collapse

Instance Method Details

#plugin_visibility_can_visit(args) ⇒ Object



43
44
45
46
47
48
49
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 43

def plugin_visibility_can_visit(args)
  post = args[:post]
  return args[:flag] = false if post.published_at.present? && post.published_at > Time.zone.now
  return if post.visibility != 'private'

  args[:flag] = false unless signin? && post.visibility_value.split(',').include?(current_site.visitor_role)
end

#plugin_visibility_create_post(args) ⇒ Object



35
36
37
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 35

def plugin_visibility_create_post(args)
  save_visibility(args[:post])
end

#plugin_visibility_extra_columns(args) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 51

def plugin_visibility_extra_columns(args)
  if args[:from_body]
    is_published = args[:post].published_at
    post_visibility = args[:post].visibility
    args[:content] =
      "<td><i class='fa fa-#{{ 'private' => 'lock', '' => 'lock', 'public' => 'eye',
                               'password' => 'eye-slash' }[post_visibility]}'></i> #{post_visibility}</td>"
    args[:content] +=
      "<td>#{is_published.present? ? is_published.strftime('%B %e, %Y %H:%M') : args[:post].the_created_at}</td>"
  else
    args[:content] = "<th>#{t('camaleon_cms.admin.table.visibility')}</th>"
    args[:content] += "<th>#{t('camaleon_cms.admin.table.date_published')}</th>"
  end
end

#plugin_visibility_filter_post(args) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 66

def plugin_visibility_filter_post(args)
  db_table = CamaleonCms::Post.table_name
  args[:active_record] =
    args[:active_record].where(
      "(#{db_table}.published_at is null or #{db_table}.published_at <= ?)", Time.zone.now
    )
  not_private = "visibility != 'private'"
  args[:active_record] =
    if signin?
      if ActiveRecord::Base.connection.adapter_name.downcase.include?('mysql')
        args[:active_record].where(
          "#{not_private} or (visibility = 'private' and FIND_IN_SET(?, #{db_table}.visibility_value))",
          current_site.visitor_role
        )
      else
        args[:active_record].where(
          "#{not_private} or (visibility = 'private' and (',' || #{db_table}.visibility_value || ',') LIKE ?)",
          "%,#{current_site.visitor_role},%"
        )
      end
    else
      args[:active_record].where(not_private)
    end
end

#plugin_visibility_new_post(args) ⇒ Object



39
40
41
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 39

def plugin_visibility_new_post(args)
  args[:extra_settings] << form_html(args[:post])
end

#plugin_visibility_on_active(_plugin) ⇒ Object



25
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 25

def plugin_visibility_on_active(_plugin); end

#plugin_visibility_on_inactive(_plugin) ⇒ Object



27
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 27

def plugin_visibility_on_inactive(_plugin); end

#plugin_visibility_post_list(args) ⇒ Object



29
30
31
32
33
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 29

def plugin_visibility_post_list(args)
  args[:posts] = args[:posts].where(visibility: 'private') if params[:s] == 'private'
  args[:btns][:private] =
    "#{t('camaleon_cms.admin.table.private')} (#{args[:all_posts].where(visibility: 'private').size})"
end

#plugin_visibility_post_the_content(args) ⇒ Object

object.content.translate(@_deco_locale), post: object



9
10
11
12
13
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 9

def plugin_visibility_post_the_content(args)
  return unless _visibility_password_locked?(args[:post])

  args[:content] = _password_form(args[:post])
end

#plugin_visibility_post_the_excerpt(args) ⇒ Object

, post: object Security (audit M1): the excerpt is derived from the post body (or its summary meta), so it must honor the same password gate as the content -- otherwise listings, search results and the RSS builders leak the body of a still-locked post through the_excerpt.



19
20
21
22
23
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 19

def plugin_visibility_post_the_excerpt(args)
  return unless _visibility_password_locked?(args[:post])

  args[:content] = ct('password_protected_excerpt', default: 'This content is password protected.')
end