This repository has been archived on 2024-08-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
redstoner.com/app/models/forumgroup.rb
2017-07-10 21:26:15 +02:00

33 lines
927 B
Ruby

class Forumgroup < ActiveRecord::Base
has_many :forums
belongs_to :role_read, class_name: "Role", foreign_key: "role_read_id"
belongs_to :role_write, class_name: "Role", foreign_key: "role_write_id"
accepts_nested_attributes_for :forums
has_many :badgeassociations
has_many :badges, through: :badgeassociations
validates_presence_of :name, :position
validates_length_of :name, in: 2..20
def to_s
name
end
def can_read?(user)
role_read.nil? || (!user.nil? && user.role >= role_read) || Badgeassociation.find_by(badge: user.badge, forumgroup: self, permission: 1)
end
def can_write?(user)
!user.nil? && user.confirmed? && (role_write.nil? || user.role >= role_write) || Badgeassociation.find_by(badge: user.badge, forumgroup: self, permission: 2)
end
def can_view?(user)
can_read?(user) || can_write?(user)
end
def to_param
[id, to_s.parameterize].join("-")
end
end