when the role-write is lower than the role-read, a forum is considered write-only for anyone who can write, but not read, they can create posts, but they can only see and reply to their own posts. users who can read are able to see and reply to all posts in the forum.
35 lines
743 B
Ruby
35 lines
743 B
Ruby
class Forum < ActiveRecord::Base
|
|
belongs_to :forumgroup
|
|
has_many :forumthreads
|
|
belongs_to :role_read, class_name: "Role", foreign_key: "role_read_id"
|
|
belongs_to :role_write, class_name: "Role", foreign_key: "role_write_id"
|
|
has_and_belongs_to_many :labels
|
|
|
|
def to_s
|
|
name
|
|
end
|
|
|
|
def group
|
|
forumgroup
|
|
end
|
|
|
|
def threads
|
|
forumthreads
|
|
end
|
|
|
|
def can_read?(user)
|
|
group && group.can_read?(user) && (role_read.nil? || (!user.nil? && user.role >= role_read))
|
|
end
|
|
|
|
def can_write?(user)
|
|
group.can_write?(user) && (role_write.nil? || (!user.nil? && user.role >= role_write))
|
|
end
|
|
|
|
def can_view?(user)
|
|
can_read?(user) || can_write?(user)
|
|
end
|
|
|
|
def to_param
|
|
[id, to_s.parameterize].join("-")
|
|
end
|
|
end |