Sha256: f7037940b542978f7ed4f00af7dd134fea1f7525f7959588f16c1b3885cf366b

Contents?: true

Size: 1.31 KB

Versions: 37

Compression:

Stored size: 1.31 KB

Contents

class Fastly
  # A representation of a User in Fastly
  class User < Base
    attr_accessor :id, :name, :login, :customer_id, :role, :password
    ##
    # :attr: id
    #
    # The id of this user
    #

    ##
    # :attr: name
    #
    # The name of this user
    #

    ##
    # :attr: customer_id
    #
    # The id of the customer this user belongs to
    #

    ##
    # :attr: role
    #
    # The role this user has (one of admin, owner, superuser, user, engineer, billing)

    # Get the Customer object this user belongs to
    def customer
      @customer ||= fetcher.get(Customer, customer_id)
    end

    # Whether or not this User is the owner of the Customer they belong to
    def owner?
      customer.owner_id == id
    end

    # :nodoc:
    PRIORITIES = {
      :admin      => 1,
      :owner      => 10,
      :superuser  => 10,
      :user       => 20,
      :engineer   => 30,
      :billing    => 30
    }

    # Does this User have sufficient permissions to perform the given role
    def can_do?(test_role)
      test_priority = PRIORITIES[test_role.to_sym] || 1000
      my_priority = PRIORITIES[role.to_sym] || 1000

      if test_priority == my_priority
        test_role.to_s == :owner ? owner? : test_role.to_sym == role.to_sym
      else
        my_priority < test_priority
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
fastly-1.10.0 lib/fastly/user.rb
fastly-1.9.0 lib/fastly/user.rb
fastly-1.8.0 lib/fastly/user.rb
fastly-1.7.0 lib/fastly/user.rb
fastly-1.6.1 lib/fastly/user.rb
fastly-1.6.0 lib/fastly/user.rb
fastly-1.5.0 lib/fastly/user.rb
fastly-1.4.3 lib/fastly/user.rb
fastly-1.4.2 lib/fastly/user.rb
fastly-1.4.1 lib/fastly/user.rb
fastly-1.4.0 lib/fastly/user.rb
fastly-1.3.0 lib/fastly/user.rb
fastly-1.2.3 lib/fastly/user.rb
fastly-1.2.2 lib/fastly/user.rb
fastly-1.2.1 lib/fastly/user.rb
fastly-1.2.0 lib/fastly/user.rb
fastly-1.1.5 lib/fastly/user.rb