Class: News
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- News
- Includes:
- HasOwner, Toggleable
- Defined in:
- app/models/news.rb
Constant Summary collapse
- PER_PAGE =
20
- LEAD_LIMIT =
350
Class Method Summary collapse
- .entity_parameters ⇒ Object
- .page_for_administration(page) ⇒ Object
- .page_for_owner(user, page) ⇒ Object
- .page_for_visitors(page) ⇒ Object
- .regional(selected_region = nil, excluded_region = nil) ⇒ Object
- .repost_parameters ⇒ Object
Instance Method Summary collapse
- #category ⇒ Object
- #commentable_by?(user) ⇒ Boolean
- #editable_by?(user) ⇒ Boolean
- #regional? ⇒ Boolean
- #visible_to?(user) ⇒ Boolean
Class Method Details
.entity_parameters ⇒ Object
72 73 74 75 76 77 |
# File 'app/models/news.rb', line 72 def self.entity_parameters = %i(author_name author_title author_url) = %i(meta_title meta_keywords meta_description) basic_data = %i(title body post_type slug visible translation) repost_parameters + + + basic_data end |
.page_for_administration(page) ⇒ Object
40 41 42 |
# File 'app/models/news.rb', line 40 def self.page_for_administration(page) recent.page(page).per(PER_PAGE) end |
.page_for_owner(user, page) ⇒ Object
51 52 53 |
# File 'app/models/news.rb', line 51 def self.page_for_owner(user, page) owned_by(user).where(deleted: false).recent.page(page).per(PER_PAGE) end |
.page_for_visitors(page) ⇒ Object
45 46 47 |
# File 'app/models/news.rb', line 45 def self.page_for_visitors(page) visible.recent.page(page).per(PER_PAGE) end |
.regional(selected_region = nil, excluded_region = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'app/models/news.rb', line 57 def self.regional(selected_region = nil, excluded_region = nil) excluded_ids = Array(excluded_region&.subbranch_ids) if selected_region.nil? chunk = excluded_ids.any? ? where('region_id not in (?)', excluded_ids) : where('region_id is not null') else chunk = where(region_id: selected_region.subbranch_ids - excluded_ids) end chunk end |
.repost_parameters ⇒ Object
67 68 69 70 |
# File 'app/models/news.rb', line 67 def self.repost_parameters for_image = %i(image image_name image_author_name image_author_link) for_image + %i(lead region_id news_category_id show_name source source_link) end |
Instance Method Details
#category ⇒ Object
79 80 81 |
# File 'app/models/news.rb', line 79 def category self.news_category end |
#commentable_by?(user) ⇒ Boolean
93 94 95 |
# File 'app/models/news.rb', line 93 def commentable_by?(user) visible? && !deleted? && user.is_a?(User) end |
#editable_by?(user) ⇒ Boolean
88 89 90 |
# File 'app/models/news.rb', line 88 def editable_by?(user) !deleted? && !locked? && (owned_by?(user) || UserPrivilege.user_has_privilege?(user, :chief_editor)) end |
#regional? ⇒ Boolean
83 84 85 |
# File 'app/models/news.rb', line 83 def regional? region_id.to_i > 0 end |
#visible_to?(user) ⇒ Boolean
98 99 100 |
# File 'app/models/news.rb', line 98 def visible_to?(user) visible? || editable_by?(user) end |