Class: Brightbox::UserCollaboration
- 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
Class Method Summary collapse
- .all ⇒ Object
- .default_field_order ⇒ Object
- .get(id) ⇒ Object
-
.get_for_account(account_id) ⇒ Brightbox::UserCollaboration, NilClass
This returns the OPEN collaboration based on an account ID to work in with the UI.
Instance Method Summary collapse
-
#accept ⇒ Object
Accepts the collaboration request.
- #destroy ⇒ Object
-
#reject ⇒ Object
Rejects the collaboration request.
-
#remove ⇒ Object
“removes” the invite by either rejecting or ending it based on the state of the collaboration.
- #to_row ⇒ Object
- #to_s ⇒ Object
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
.all ⇒ Object
7 8 9 |
# File 'lib/brightbox-cli/user_collaboration.rb', line 7 def self.all conn.user_collaborations end |
.default_field_order ⇒ Object
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
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.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/brightbox-cli/user_collaboration.rb', line 25 def self.get_for_account(account_id) collaborations = conn.user_collaborations open_collaborations = collaborations.select { |col| %w[pending accepted].include?(col.status) } collaboration = open_collaborations.find do |col| col.account_id == account_id end return unless collaboration new(collaboration) end |
Instance Method Details
#accept ⇒ Object
Accepts the collaboration request
46 47 48 |
# File 'lib/brightbox-cli/user_collaboration.rb', line 46 def accept fog_model.accept end |
#destroy ⇒ Object
55 56 57 |
# File 'lib/brightbox-cli/user_collaboration.rb', line 55 def destroy fog_model.destroy end |
#reject ⇒ Object
Rejects the collaboration request
51 52 53 |
# File 'lib/brightbox-cli/user_collaboration.rb', line 51 def reject fog_model.reject end |
#remove ⇒ Object
“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_row ⇒ Object
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_s ⇒ Object
41 42 43 |
# File 'lib/brightbox-cli/user_collaboration.rb', line 41 def to_s @id end |