Sha256: 2b0a840ecf3566e102bf4674d8e67c0ed5a733305037f26aef82e3cb00c583b4

Contents?: true

Size: 469 Bytes

Versions: 8

Compression:

Stored size: 469 Bytes

Contents

# frozen_string_literal: true

module Talkie
  class Permission
    attr_reader :user

    def initialize(user)
      @user = user
    end

    def comment_form_displayable?
      user.present?
    end

    def allow?(action, comment = Talkie::Comment.new)
      action = action.to_s

      if user
        return true if action.in? %w[create index]
        return true if action.in?(%w[destroy]) && user.owns_comment?(comment)
      end

      false
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
talkie-0.5.1 lib/talkie/permission.rb
talkie-0.5.0 lib/talkie/permission.rb
talkie-0.4.1 lib/talkie/permission.rb
talkie-0.4.0 lib/talkie/permission.rb
talkie-0.3.5 lib/talkie/permission.rb
talkie-0.3.4 lib/talkie/permission.rb
talkie-0.3.3 lib/talkie/permission.rb
talkie-0.3.2 lib/talkie/permission.rb