Sha256: d18c2de8b37007177d9da8204f55e22c8bd577d8174ccc7bc80bebef3efcbdf7
Contents?: true
Size: 1.19 KB
Versions: 10
Compression:
Stored size: 1.19 KB
Contents
# frozen_string_literal: true module Thredded class MessageboardPolicy # The scope of readable messageboards class Scope # @param user [Thredded.user_class] # @param scope [ActiveRecord::Relation<Thredded::Messageboard>] def initialize(user, scope) @user = user @scope = scope end # @return [ActiveRecord::Relation<Thredded::Messageboards>] def resolve @scope.merge(@user.thredded_can_read_messageboards) end end # @param user [Thredded.user_class] # @param messageboard [Thredded::Messageboard] def initialize(user, messageboard) @user = user @messageboard = messageboard end def create? @user.thredded_admin? end def read? @user.thredded_admin? || @user.thredded_can_read_messageboards.include?(@messageboard) end def update? @user.thredded_admin? end def post? @user.thredded_admin? || (!@messageboard.locked? || moderate?) && @user.thredded_can_write_messageboards.include?(@messageboard) end def moderate? @user.thredded_admin? || @user.thredded_can_moderate_messageboards.include?(@messageboard) end end end
Version data entries
10 entries across 10 versions & 2 rubygems