Sha256: ee0885ed238ba8a54be3b1f80fa6d9177d145465296ddfe98ee65dcdb3e7d483

Contents?: true

Size: 798 Bytes

Versions: 10

Compression:

Stored size: 798 Bytes

Contents

module Thredded
  class MessageboardUserPermissions
    attr_reader :messageboard, :user

    def initialize(messageboard, user)
      @messageboard = messageboard
      @user = user
    end

    def readable?
      (messageboard.restricted_to_private? && messageboard.has_member?(user)) ||
      (messageboard.restricted_to_logged_in? && user.valid?) ||
      messageboard.public?
    end

    def postable?
      if messageboard.posting_for_anonymous? &&
        (messageboard.restricted_to_private? || messageboard.restricted_to_logged_in?)
          false
      else
        messageboard.posting_for_anonymous? ||
          (messageboard.posting_for_logged_in? && user.try(:valid?)) ||
          (messageboard.posting_for_members? && messageboard.has_member?(user))
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
thredded-0.0.12 lib/thredded/messageboard_user_permissions.rb
thredded-0.0.10 lib/thredded/messageboard_user_permissions.rb
thredded-0.0.9 lib/thredded/messageboard_user_permissions.rb
thredded-0.0.8 lib/thredded/messageboard_user_permissions.rb
thredded-0.0.7 lib/thredded/messageboard_user_permissions.rb
thredded-0.0.6 lib/thredded/messageboard_user_permissions.rb
thredded-0.0.5 lib/thredded/messageboard_user_permissions.rb
thredded-0.0.4 lib/thredded/messageboard_user_permissions.rb
thredded-0.0.3 lib/thredded/messageboard_user_permissions.rb
thredded-0.0.1 lib/thredded/messageboard_user_permissions.rb