Sha256: ada61e91d66ed59b7e13526358cd5b2591e0b56c6c6e4d918e30af2555f23e09

Contents?: true

Size: 603 Bytes

Versions: 3

Compression:

Stored size: 603 Bytes

Contents

module Faalis
  # This concern contains all the permission related methods
  # to use within `Faalis::User`
  module Concerns::User::Permission
    extend ActiveSupport::Concern

    def have_permission? action, obj
      perm = self.groups.includes(:permissions)
        .where(faalis_permissions: { model: obj, permission_type: action })
        .count
      perm == 1
    end

    def can_not? action, obj
      !have_permission? action, obj
    end

    alias_method :can?, :have_permission?

    def permissions
      groups.includes(:permissions).map(&:permissions).flatten.uniq
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
faalis-1.0.0.alpha4 app/models/faalis/concerns/user/permission.rb
faalis-1.0.0.alpha3 app/models/faalis/concerns/user/permission.rb
faalis-1.0.0.alpha2 app/models/faalis/concerns/user/permission.rb