Sha256: b00b2f2cb35e46a5ed334ec5039f3987777069626b5c5df7514166db7f3fa1be
Contents?: true
Size: 1.35 KB
Versions: 7
Compression:
Stored size: 1.35 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 readable = @user.thredded_can_read_messageboards if readable == Thredded::Messageboard.all @scope else @scope.merge(readable) end 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_messageboard?(@messageboard) end def update? @user.thredded_admin? end def destroy? @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_messageboard?(@messageboard) end end end
Version data entries
7 entries across 7 versions & 1 rubygems