Class: BlackStack::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/client.rb

Instance Method Summary collapse

Instance Method Details

#checkDomainForSSMVerifiedObject

llama a la api de postmark preguntando el reseller email configurado para este clietne fue ferificado



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/client.rb', line 87

def checkDomainForSSMVerified()
  return_message = {}
  domain = self.domain_for_ssm
  email = self.from_email_for_ssm
  id = ''
  client = ''
  
  if domain != nil && email != nil
    begin
      client_postmark = Postmark::AccountApiClient.new(POSTMARK_API_TOKEN, secure: true)      
      client_list = client_postmark.get_signatures()
  
      client_list.each do |sign|
        if sign[:domain] == domain
          if sign[:email_address] == email
            id = sign[:id]
            break
          end
        end
      end
  
      if id.to_s.size > 0
        client = client_postmark.get_sender(id)
        if !client[:confirmed]
          self.domain_for_ssm_verified = false
          self.save
  
          return_message[:status] = "No Verified"
          return_message[:value] = client[:id]
  
          return return_message.to_json 
        else
          self.domain_for_ssm_verified = true
          self.save
  
          # sincronizo con la central
          return_message = {}
  
          return_message[:status] = "success"
          return_message[:value] = client[:id]
  
          return return_message.to_json 
        end
      end

    rescue Postmark::ApiInputError => e
      return_message[:status] = e.to_s
      return return_message.to_json
      #return e
    rescue => e
      return_message[:status] = e.to_s
      return return_message.to_json
      #return e
    end
  else
    return_message[:status] = 'error'
    return_message[:value] = ''
    return return_message.to_json
  end # checkDomainForSSMVerified
end

#getTimezoneObject

si el cliente no tiene una zona horaria configurada, retorna la zona horaria por defecto excepciones:

> “Default timezone not found.”



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/client.rb', line 73

def getTimezone()
  ret = nil   
  if (self.timezone != nil)
    ret = self.timezone
  else
    ret = BlackStack::Timezone.where(:id=>BlackStack::Pampa::id_timezone_default).first
    if (ret == nil)
      raise "Default timezone not found."
    end
  end
  return ret
end

#hasBillingAddress?Boolean

retorna true si la 5 variables (billing_address, billing_city, billing_state, billing_zipcode, billing_id_lncountry) tienen un valor destinto a nil o a un string vacio.

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/client.rb', line 44

def hasBillingAddress?
  if (
    self.billing_address.to_s.size == 0 || 
    self.billing_city.to_s.size == 0 || 
    self.billing_state.to_s.size == 0 || 
    self.billing_zipcode.to_s.size == 0 ||
    self.billing_id_lncountry.to_s.size == 0
  )
    return false
  else
    return true
  end
end

#hostsObject

returns the hosts where this client has not-deleted workers, even if the host is not belong this client



28
29
30
# File 'lib/client.rb', line 28

def hosts()
  BlackStack::LocalHost.where(id: self.not_deleted_workers.select(:id_host).all.map(&:id_host))
end

#not_deleted_workersObject

returns the workers belong this clients, that have not been deleted



23
24
25
# File 'lib/client.rb', line 23

def not_deleted_workers()
  BlackStack::Worker.where(:id_client=>self.id, :delete_time=>nil)
end

#own_hostsObject

returns the hosts belong this client



33
34
35
# File 'lib/client.rb', line 33

def own_hosts()
  BlackStack::LocalHost.where(:id_client=>self.id, :delete_time=>nil)
end

#resellerSignature?Boolean

retorna true si el cliente esta configurado para usar su propia nombre/email en el envio de notificaciones

Returns:

  • (Boolean)


149
150
151
# File 'lib/client.rb', line 149

def resellerSignature?
  self.from_name_for_ssm.to_s.size>0 && self.from_email_for_ssm.to_s.size>0 
end

#resellerSignatureEmailObject

retorna el email configurado y confirmado en PostMark para cuenta reseller, o retorna el email por defecto



170
171
172
173
174
175
176
177
# File 'lib/client.rb', line 170

def resellerSignatureEmail
  # configuracion de cuenta reseller
  if self.resellerSignatureEnabled?
    return self.from_email_for_ssm.to_s
  else
    return BlackStack::Params.getValue("notifications.user.email_from")
  end
end

#resellerSignatureEnabled?Boolean

retorna true si el cliente esta configurado para usar su propia nombre/email en el envio de notificaciones, y si el email fue verificado en postmark

Returns:

  • (Boolean)


154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/client.rb', line 154

def resellerSignatureEnabled?
=begin # TODO: Mover esto a un proceso asincronico
  # si el cliente esta configurado para usar su propia nombre/email 
  if self.resellerSignature?
    # pero el email fue verificado en postmark
    if self.domain_for_ssm_verified==nil || self.domain_for_ssm_verified!=true
      # hago la verificacion contra postmark
      self.checkDomainForSSMVerified   
    end          
  end
=end
  # return
  resellerSignature? == true && self.domain_for_ssm_verified==true
end

#resellerSignatureNameObject

retorna el nombre configurado para cuenta reseller, solo si el email esta confirmado en PostMark; o retorna el email por defecto



180
181
182
183
184
185
186
187
# File 'lib/client.rb', line 180

def resellerSignatureName
  # configuracion de cuenta reseller
  if self.resellerSignatureEnabled?
    return self.from_email_for_ssm.to_s
  else
    return BlackStack::Params.getValue("notifications.user.name_from")
  end
end

#user_rolesObject

retorna un array de objectos UserRole, asignados a todos los usuarios de este cliente



59
60
61
62
63
64
65
66
67
68
# File 'lib/client.rb', line 59

def user_roles
  a = []
  self.users.each { |o| 
    a.concat o.user_roles 
    # libero recursos
    GC.start
    DB.disconnect
  }
  a    
end