Sha256: 6c88d9c2cc70f76549281c66a894108e22338de71959c9c9a2b8cea0a568bff9

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

class UserDecorator < ApplicationDecorator
  def can?(scope, account)
    return true if object.can_manage?(account.organization)
    user_scopes = account_permissions(account).map(&:scope)
    user_scopes.include?('manage') || user_scopes.include?(scope)
  end

  def cached_organizations
    garner
      .bind(h.controller.session_token)
      .bind(h.controller.current_organization) do
        object.organizations
      end
  end

  def organization_count
    cached_organizations.count
  end

  def cached_roles
    garner.bind(h.controller.session_token) do
      object.roles
    end
  end

  def cached_organization_roles(organization)
    garner.bind(h.controller.session_token)
      .bind(organization)
      .bind(object) do
      object.organization_roles(organization)
    end
  end

  def cached_permissions
    garner.bind(h.controller.session_token) do
      permissions = []
      cached_roles.each do |role|
        permissions += role.permissions
      end
      permissions
    end
  end

  def account_permissions(account)
    cached_permissions.select do |permission|
      permission.links[:account].href == account.href
    end
  end

  def current_training
    training_logs.first
  end

  def training_current?
    training_logs.any?
  end

  def training_logs
    training_criterion.documents.select do |doc|
      doc.links['user'].href == object.href
    end
  end

  def training_criterion
    context[:criterion]
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
aptible-rails-0.6.5 lib/aptible/rails/decorators/user_decorator.rb
aptible-rails-0.6.4 lib/aptible/rails/decorators/user_decorator.rb
aptible-rails-0.6.3 lib/aptible/rails/decorators/user_decorator.rb
aptible-rails-0.6.2 lib/aptible/rails/decorators/user_decorator.rb
aptible-rails-0.6.1 lib/aptible/rails/decorators/user_decorator.rb
aptible-rails-0.6.0 lib/aptible/rails/decorators/user_decorator.rb