Class: Brightbox::UserCollaboration

Inherits:
Api
  • Object
show all
Defined in:
lib/brightbox-cli/user_collaboration.rb

Overview

These are collaborations from the perspective of the invited user so all that is expected is listing, getting details, accepting, rejecting and destroying them.

Instance Attribute Summary

Attributes inherited from Api

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Api

#attributes, cache_all!, cached_get, conn, #created_on, #exists?, find, find_all_or_warn, find_by_handle, find_or_call, #fog_attributes, #fog_model, #initialize, klass_name, #method_missing, require_account?, #respond_to_missing?

Constructor Details

This class inherits a constructor from Brightbox::Api

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Brightbox::Api

Class Method Details

.allObject



7
8
9
# File 'lib/brightbox-cli/user_collaboration.rb', line 7

def self.all
  conn.user_collaborations
end

.default_field_orderObject



37
38
39
# File 'lib/brightbox-cli/user_collaboration.rb', line 37

def self.default_field_order
  %i[id status account role]
end

.get(id) ⇒ Object



11
12
13
# File 'lib/brightbox-cli/user_collaboration.rb', line 11

def self.get(id)
  conn.user_collaborations.get(id)
end

.get_for_account(account_id) ⇒ Brightbox::UserCollaboration, NilClass

TODO:

Ensure filtering works when many collaborations exist between accounts, and correct states are honoured.

This returns the OPEN collaboration based on an account ID to work in with the UI.

Parameters:

  • account_id (String)

    The identifier of the account

Returns:



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/brightbox-cli/user_collaboration.rb', line 25

def self.()
  collaborations = conn.user_collaborations
  open_collaborations = collaborations.select { |col| %w[pending accepted].include?(col.status) }
  collaboration = open_collaborations.find do |col|
    col. == 
  end

  return unless collaboration

  new(collaboration)
end

Instance Method Details

#acceptObject

Accepts the collaboration request



46
47
48
# File 'lib/brightbox-cli/user_collaboration.rb', line 46

def accept
  fog_model.accept
end

#destroyObject



55
56
57
# File 'lib/brightbox-cli/user_collaboration.rb', line 55

def destroy
  fog_model.destroy
end

#rejectObject

Rejects the collaboration request



51
52
53
# File 'lib/brightbox-cli/user_collaboration.rb', line 51

def reject
  fog_model.reject
end

#removeObject

“removes” the invite by either rejecting or ending it based on the state of the collaboration



61
62
63
64
65
66
67
# File 'lib/brightbox-cli/user_collaboration.rb', line 61

def remove
  if status == "pending"
    reject
  else
    destroy
  end
end

#to_rowObject



69
70
71
72
73
# File 'lib/brightbox-cli/user_collaboration.rb', line 69

def to_row
  row_attributes = attributes
  row_attributes[:account] = attributes[:account]["id"]
  row_attributes.to_h
end

#to_sObject



41
42
43
# File 'lib/brightbox-cli/user_collaboration.rb', line 41

def to_s
  @id
end