Sha256: ecf116031628900a7ee7fe281b22e73f00ec98573582b3b7e3456b0ccdd1ce7d

Contents?: true

Size: 350 Bytes

Versions: 2

Compression:

Stored size: 350 Bytes

Contents

# frozen_string_literal: true

module Talkie
  class Permission < Struct.new(:user)
    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

2 entries across 2 versions & 1 rubygems

Version Path
talkie-0.3.1 lib/talkie/permission.rb
talkie-0.3.0 lib/talkie/permission.rb