Sha256: f27dd28f4171444c80a65d047d149e8eaff5e28c0a7cbd56e129788b36b3b1ac

Contents?: true

Size: 662 Bytes

Versions: 6

Compression:

Stored size: 662 Bytes

Contents

# frozen_string_literal: true

require 'proxes/models/base'

module ProxES
  class Permission < Sequel::Model
    include ::ProxES::Base

    many_to_one :role
    many_to_one :user

    dataset_module do
      def for_user(a_user, action)
        where(verb: action).where { Sequel.|({ role: a_user.roles }, { user_id: a_user.id }) }
      end
    end

    def validate
      validates_presence [:verb, :pattern]
      validates_presence :role_id unless user_id
      validates_presence :user_id unless role_id
      validates_includes self.class.verbs, :verb
    end

    def self.verbs
      %w[GET POST PUT DELETE HEAD OPTIONS TRACE INDEX]
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
proxes-0.7.1 lib/proxes/models/permission.rb
proxes-0.7.0 lib/proxes/models/permission.rb
proxes-0.6.1 lib/proxes/models/permission.rb
proxes-0.6.0 lib/proxes/models/permission.rb
proxes-0.5.2 lib/proxes/models/permission.rb
proxes-0.5.1 lib/proxes/models/permission.rb