school.rb 641 B

123456789101112131415161718192021222324252627
  1. class School < ApplicationRecord
  2. validates :name, presence: true, length: { maximum: 255 }
  3. has_many :administrations, dependent: :destroy
  4. has_many :administrators, through: :administrations,
  5. class_name: "User", source: :user
  6. has_many :courses
  7. has_many :users
  8. has_many :data_files, as: :repository
  9. def can_download_files?(user)
  10. self.users.include?(user) || self.administrators.include?(user)
  11. end
  12. def can_upload_files?(user)
  13. self.administrators.include?(user)
  14. end
  15. has_many :news_posts, as: :news_feed
  16. def can_post_news?(user)
  17. self.administrators.include?(user)
  18. end
  19. end