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/forum.rb
jomo 55f92fe45a enable write-only forums
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.
2015-01-17 19:40:57 +01:00

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