Module: MnoEnterprise::Concerns::Models::Organization

Extended by:
ActiveSupport::Concern
Included in:
Organization
Defined in:
lib/mno_enterprise/concerns/models/organization.rb

Overview

Schema Information

Endpoint:

- /v1/organizations
- /v1/users/:user_id/organizations

id                       :integer         not null, primary key
uid                      :string(255)
name                     :string(255)
created_at               :datetime        not null
updated_at               :datetime        not null
account_frozen           :boolean         default(FALSE)
free_trial_end_at        :datetime
soa_enabled              :boolean         default(TRUE)
mails                    :text
logo                     :string(255)
latitude                 :float           default(0.0)
longitude                :float           default(0.0)
geo_country_code         :string(255)
geo_state_code           :string(255)
geo_city                 :string(255)
geo_tz                   :string(255)
geo_currency             :string(255)
meta_data                :text
industry                 :string(255)
size                     :string(255)

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#add_user(user, role = 'Member') ⇒ Object

Add a user to the organization with the provided role TODO: specs



86
87
88
# File 'lib/mno_enterprise/concerns/models/organization.rb', line 86

def add_user(user,role = 'Member')
  self.users.create(id: user.id, role: role)
end

#has_credit_card_details?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/mno_enterprise/concerns/models/organization.rb', line 123

def has_credit_card_details?
  credit_card.persisted?
end

#last_invoiceObject



90
91
92
93
# File 'lib/mno_enterprise/concerns/models/organization.rb', line 90

def last_invoice
  inv = self.raw_last_invoice
  inv.id ? inv : nil
end

#members(show_staged = false) ⇒ Object

Instance methods

Return the list of users + active invites TODO: specs



79
80
81
82
# File 'lib/mno_enterprise/concerns/models/organization.rb', line 79

def members(show_staged=false)
  invites = show_staged ? self.org_invites.active_or_staged : self.org_invites.active
  [self.users, invites.to_a].flatten
end

#payment_restrictionObject



119
120
121
# File 'lib/mno_enterprise/concerns/models/organization.rb', line 119

def payment_restriction
   && ['payment_restriction']
end

#remove_user(user) ⇒ Object

Remove a user from the organization TODO: specs



101
102
103
# File 'lib/mno_enterprise/concerns/models/organization.rb', line 101

def remove_user(user)
  self.users.destroy(id: user.id)
end

#to_audit_eventObject



111
112
113
114
115
116
117
# File 'lib/mno_enterprise/concerns/models/organization.rb', line 111

def to_audit_event
  {
    id: id,
    uid: uid,
    name: name
  }
end

#update_user(user, role = 'Member') ⇒ Object

Change a user role in the organization TODO: specs



107
108
109
# File 'lib/mno_enterprise/concerns/models/organization.rb', line 107

def update_user(user, role = 'Member')
  self.users.update(id: user.id, role: role)
end