Class: News::Administration

Inherits:
News show all
Defined in:
app/models/news/administration.rb

Overview

New corresponding to the administration of this instance of TaxonWorks

Direct Known Subclasses

BlogPost, Notice, Warning

Defined Under Namespace

Classes: BlogPost, Notice, Warning

Constant Summary

Constants inherited from News

ADMINISTRATION_TYPES, PROJECT_TYPES

Instance Attribute Summary

Attributes included from Housekeeping::Users

#by

Instance Method Summary collapse

Methods inherited from News

#display_end_after_display_start, #is_current?

Methods included from Shared::Permissions

#is_destroyable?, #is_editable?, #is_in_users_projects?

Methods included from Shared::HasPapertrail

#attribute_updated, #attribute_updater, #detect_version

Methods included from Shared::IsData::Metamorphosize

#metamorphosize

Methods included from Shared::IsData::Navigation

#base_navigation_next, #base_navigation_previous, #next, #next_by_created_at, #next_by_user_created_at, #previous, #previous_by_created_at, #previous_by_user_created_at

Methods included from Housekeeping::Users

#set_created_by_id, #set_updated_by_id

Methods inherited from ApplicationRecord

transaction_with_retry

Instance Method Details

#user_must_be_administratorObject (private)



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/news/administration.rb', line 13

def user_must_be_administrator
  return unless created_by_id || updated_by_id

  if created_by_id
    user = User.find_by(id: created_by_id)
    unless user&.is_administrator
      errors.add(:base, 'only administrators can edit administration news')
    end
  end

  if updated_by_id
    user = User.find_by(id: updated_by_id)
    unless user&.is_administrator
      errors.add(:base, 'only administrators can edit administration news')
    end
  end

end