Skip to content
This repository has been archived by the owner on Jul 17, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
hackedunit committed Aug 8, 2016
2 parents 99f0eb2 + e922dc7 commit 9e25bf7
Show file tree
Hide file tree
Showing 36 changed files with 195 additions and 167 deletions.
17 changes: 10 additions & 7 deletions app/admin/billing_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
start_date = Date.strptime params['account_report']['start'], '%Y-%m-%d'
end_date = Date.strptime params['account_report']['end'], '%Y-%m-%d'

filename = "cloudnet_account_report_#{start_date}_#{end_date}.csv"
send_data GenerateFinanceReport.new(start_date, end_date).account_report, filename: filename
SendAdminFinancials.perform_async(:periodic_csv, start_date, end_date, :account_report, current_user.id)
flash[:notice] = "Report will be emailed to you once generated"
redirect_to admin_billing_accounts_path
end
end

page_action :transaction_report, method: :post do
if params['transaction_report'].present?
start_date = Date.strptime params['transaction_report']['start'], '%Y-%m-%d'
end_date = Date.strptime params['transaction_report']['end'], '%Y-%m-%d'

filename = "cloudnet_transaction_report_#{start_date}_#{end_date}.csv"
send_data GenerateFinanceReport.new(start_date, end_date).transaction_report, filename: filename

SendAdminFinancials.perform_async(:periodic_csv, start_date, end_date, :transaction_report, current_user.id)
flash[:notice] = "Report will be emailed to you once generated"
redirect_to admin_billing_accounts_path
end
end

Expand All @@ -28,8 +30,9 @@
start_date = Date.strptime params['charge_report']['start'], '%Y-%m-%d'
end_date = Date.strptime params['charge_report']['end'], '%Y-%m-%d'

filename = "cloudnet_charge_report_#{start_date}_#{end_date}.csv"
send_data GenerateFinanceReport.new(start_date, end_date).charge_report, filename: filename
SendAdminFinancials.perform_async(:periodic_csv, start_date, end_date, :charge_report, current_user.id)
flash[:notice] = "Report will be emailed to you once generated"
redirect_to admin_billing_accounts_path
end
end
end
2 changes: 2 additions & 0 deletions app/admin/server_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def create_sift_event(server, order_status, reason = nil, description = nil)
"$analyst" => current_user.email
}
CreateSiftEvent.perform_async("$order_status", properties)
rescue StandardError => e
ErrorLogging.new.track_exception(e, extra: { user: server.user.id, source: 'ServerValidation#create_sift_event' })
end

def create_sift_label(server)
Expand Down
8 changes: 7 additions & 1 deletion app/assets/stylesheets/servers.scss
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,10 @@ ul.resources-footer {
}

}
}
}
#rebuild_server {
display: block;
position: relative;
top: -50px;
visibility: hidden;
}
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def format_error_messages(messages)

def create_sift_event(event, properties)
CreateSiftEvent.perform_async(event, properties)
rescue StandardError => e
ErrorLogging.new.track_exception(e, extra: { user: current_user.id, source: 'ApplicationController#create_sift_event' })
end

private
Expand Down
9 changes: 9 additions & 0 deletions app/mailers/admin_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ def monthly_csv(start_date, end_date, mailto = FINANCE_RECIPIENTS)

mail(to: mailto, subject: "#{ENV['BRAND_NAME']} Monthly CSV Reports - #{@date_name}")
end

def periodic_csv(start_date, end_date, report, admin_id)
@start_date, @end_date, @report = start_date, end_date, report
admin_user = User.where(admin: true, id: admin_id).first
filename = "cloudnet_#{report.to_s}_#{@start_date}_#{@end_date}.csv"
reporter = GenerateFinanceReport.new(@start_date, @end_date)
attachments[filename] = reporter.send(@report)
mail(to: admin_user.email, subject: "#{ENV['BRAND_NAME']} Billing Reports")
end

def notify_stuck_server_state(server)
@server = server
Expand Down
2 changes: 2 additions & 0 deletions app/models/charge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ def charge_number

def create_sift_event
CreateSiftEvent.perform_async("$transaction", sift_charge_properties)
rescue StandardError => e
ErrorLogging.new.track_exception(e, extra: { user: account.user.id, source: 'Charge#create_sift_event' })
end
end
4 changes: 3 additions & 1 deletion app/models/credit_note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def number
end

def create_sift_event
CreateSiftEvent.perform_async("$transaction", sift_credit_note_properties) rescue nil
CreateSiftEvent.perform_async("$transaction", sift_credit_note_properties)
rescue StandardError => e
ErrorLogging.new.track_exception(e, extra: { user: account.user.id, source: 'CreditNote#create_sift_event' })
end

private
Expand Down
2 changes: 2 additions & 0 deletions app/models/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def payg?

def create_sift_event
CreateSiftEvent.perform_async("$create_order", sift_invoice_properties)
rescue StandardError => e
ErrorLogging.new.track_exception(e, extra: { user: account.user.id, source: 'Invoice#create_sift_event' })
end

private
Expand Down
2 changes: 2 additions & 0 deletions app/models/payment_receipt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def pretty_pay_source

def create_sift_event
CreateSiftEvent.perform_async("$transaction", sift_payment_receipt_properties)
rescue StandardError => e
ErrorLogging.new.track_exception(e, extra: { user: account.user.id, source: 'PaymentReceipt#create_sift_event' })
end

private
Expand Down
4 changes: 4 additions & 0 deletions app/models/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ def monitor_and_provision
DockerCreation.perform_in(MonitorServer::POLL_INTERVAL.seconds, id, provisioner_role) if docker_provision
end

def supports_rebuild?
!(try(:os) == "windows" || try(:provisioner_role))
end

private

def template_should_match_location
Expand Down
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def after_database_authentication

def update_sift_account
CreateSiftEvent.perform_async("$update_account", sift_user_properties)
rescue StandardError => e
ErrorLogging.new.track_exception(e, extra: { user: self.id, source: 'User#update_sift_account' })
end

def update_forecasted_revenue
Expand All @@ -162,6 +164,8 @@ def forecasted_revenue
def create_sift_account(include_time_ip = false)
properties = sift_user_properties(include_time_ip)
CreateSiftEvent.perform_async("$create_account", properties)
rescue StandardError => e
ErrorLogging.new.track_exception(e, extra: { user: self.id, source: 'User#create_sift_account' })
end

def create_sift_login_event
Expand All @@ -171,6 +175,8 @@ def create_sift_login_event
"$login_status" => "$success"
}
CreateSiftEvent.perform_async("$login", properties)
rescue StandardError => e
ErrorLogging.new.track_exception(e, extra: { user: self.id, source: 'User#create_sift_login_event' })
end

def self.disposable_email_domains
Expand Down
30 changes: 22 additions & 8 deletions app/services/server_console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@ def initialize(server, user)
@server = server
@user = user
end

def resolve_redirects(url)
response = fetch_response(url, method: :head)
if response
return response.to_hash[:url].to_s
else
return nil
end
end

def process
squall = Squall::VirtualMachine.new(uri: ONAPP_CP[:uri], user: @user.onapp_user, pass: @user.onapp_password)
console = squall.console(@server.identifier)
def fetch_response(url, method: :get)
conn = Faraday.new do |b|
b.use FaradayMiddleware::FollowRedirects;
b.adapter :net_http
b.basic_auth @user.onapp_user, @user.onapp_password
end
return conn.send method, url
rescue Faraday::Error, Faraday::Error::ConnectionFailed => e
return nil
end

{
port: console['port'],
remote_key: console['remote_key'],
console_src: "#{ONAPP_CP[:uri]}/console_remote/#{console['remote_key']}"
}
def process
console_url = resolve_redirects("#{ONAPP_CP[:uri]}/virtual_machines/#{@server.identifier}/console_popup")
{ console_src: console_url }
end
end
2 changes: 2 additions & 0 deletions app/tasks/create_server_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ def create_sift_events
}
CreateSiftEvent.perform_async("$order_status", order_properties)
CreateSiftEvent.perform_async("create_server", server.sift_server_properties)
rescue StandardError => e
ErrorLogging.new.track_exception(e, extra: { user: user.id, source: 'CreateServerTask#create_sift_events' })
end
end
4 changes: 3 additions & 1 deletion app/tasks/destroy_server_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def charge_unpaid_invoices(account)
end

def create_sift_event
CreateSiftEvent.perform_async("destroy_server", @server.sift_server_properties) rescue nil
CreateSiftEvent.perform_async("destroy_server", @server.sift_server_properties)
rescue StandardError => e
ErrorLogging.new.track_exception(e, extra: { user: @user.id, source: 'DestroyServerTask#create_sift_event' })
end
end
2 changes: 2 additions & 0 deletions app/tasks/dispute_handler_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def create_sift_events

CreateSiftEvent.perform_async("$chargeback", chargeback_properties)
CreateSiftEvent.perform_async("$order_status", order_status_properties) if invoice_id
rescue StandardError => e
ErrorLogging.new.track_exception(e, extra: { user: @account.user.id, source: 'DisputeHandlerTask#create_sift_events' })
end

def create_sift_label
Expand Down
2 changes: 2 additions & 0 deletions app/tasks/edit_server_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,7 @@ def log_task_process(task)

def create_sift_event
CreateSiftEvent.perform_async("update_server", @server.sift_server_properties)
rescue StandardError => e
ErrorLogging.new.track_exception(e, extra: { user: @user.id, source: 'EditServerTask#create_sift_event' })
end
end
2 changes: 2 additions & 0 deletions app/tasks/payg_topup_card_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,7 @@ def create_sift_event(charge = nil, error = nil)
properties = SiftProperties.stripe_failure_properties(@account, cost, error, payment_properties)
end
CreateSiftEvent.perform_async("$transaction", properties)
rescue StandardError => e
ErrorLogging.new.track_exception(e, extra: { user: @user.id, source: 'PaygTopupCardTask#create_sift_event' })
end
end
2 changes: 2 additions & 0 deletions app/tasks/payg_topup_paypal_response_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ def create_sift_event(details, response = nil)
properties = SiftProperties.paypal_failure_properties(@account, details)
end
CreateSiftEvent.perform_async("$transaction", properties)
rescue StandardError => e
ErrorLogging.new.track_exception(e, extra: { user: @user.id, source: 'PaygTopupPaypalResponseTask#create_sift_event' })
end
end
2 changes: 1 addition & 1 deletion app/views/admin/billing_accounts/_account_report.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
= f.input :start, as: :date_picker, input_html: { value: Date.today - 1.month }
= f.input :end, as: :date_picker, input_html: { value: Date.today }
= f.actions do
= f.action :submit, label: "Download Account Report"
= f.action :submit, label: "Get Account Report"
2 changes: 1 addition & 1 deletion app/views/admin/billing_accounts/_charge_report.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
= f.input :start, as: :date_picker, input_html: { value: Date.today - 1.month }
= f.input :end, as: :date_picker, input_html: { value: Date.today }
= f.actions do
= f.action :submit, label: "Download Charge Report"
= f.action :submit, label: "Get Charge Report"
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
= f.input :start, as: :date_picker, input_html: { value: Date.today - 1.month }
= f.input :end, as: :date_picker, input_html: { value: Date.today }
= f.actions do
= f.action :submit, label: "Download Transaction Report"
= f.action :submit, label: "Get Transaction Report"
7 changes: 7 additions & 0 deletions app/views/admin_mailer/periodic_csv.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>Hello</p>

<p>Please find attached <%= ENV['BRAND_NAME'] %> <%= @report.to_s.humanize %> from <%= @start_date.strftime("%d/%m/%Y") %> until <%= @end_date.strftime("%d/%m/%Y") %>.</p>

<p>Thanks,</p>

<p><%= ENV['BRAND_NAME'] %> Team</p>
2 changes: 1 addition & 1 deletion app/views/server_wizards/steps/_resources.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- provisioner_templates = @wizard_object.location.provisioner_templates.group_by { |t| "#{t.os_type}-#{t.os_distro}" }
- hideTemplates = @server.try(:os) == "windows" || @server.try(:provisioner_role)
- hideTemplates = !@server.supports_rebuild?
%script
- t = render partial: 'locations/templates.json', formats: [:json], locals: { templates: @templates }
= raw "var templates = #{t}"
Expand Down
3 changes: 2 additions & 1 deletion app/views/servers/_template.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
=#FIXME: Not allowing to rebuild Windows platform until onapp core dev team fix the bug
- hideTemplates = @server && (@server.try(:os) == "windows" || @server.try(:provisioner_role))
- hideTemplates = @server && !@server.supports_rebuild?
#rebuild_server
.jg-widget-content{:class => ("hidden" if hideTemplates)}
.jg-widget-header.pure-g.clearfix{class: ('jg-form-withTabs' if @server.blank?)}
%h2.jg-icon.icon-cloud.pure-u Select Template
Expand Down
3 changes: 3 additions & 0 deletions app/views/servers/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
%a{"ng-show" => "server.state == 'on'", "rel" => "nofollow", "id" => "install-notes-button", "server-id" => @server.id} Install Notes
%li
%a{"href" => "/servers/{{ server.id }}/edit", "ng-show" => "server.state == 'on'", "rel" => "nofollow"} Edit Server
- if @server.supports_rebuild?
%li
%a{"href" => "/servers/{{ server.id }}/edit#rebuild_server", "ng-show" => "server.state == 'on'", "rel" => "nofollow"} Rebuild Server
%li
%a{"data-method" => "post", "href" => "/servers/{{ server.id }}/reboot", "ng-show" => "server.state == 'on'", "rel" => "nofollow"} Reboot Server
%li
Expand Down
11 changes: 9 additions & 2 deletions app/workers/send_admin_financials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class SendAdminFinancials
include Sidekiq::Worker
sidekiq_options unique: true

def perform(type)
send(type.to_sym)
def perform(type, *args)
send(type.to_sym, *args)
end

def daily
Expand Down Expand Up @@ -38,6 +38,13 @@ def monthly_csv

AdminMailer.monthly_csv(start_date, end_date).deliver_now
end

def periodic_csv(start_date, end_date, report, admin_id)
start_date = Date.strptime start_date, '%Y-%m-%d'
end_date = Date.strptime end_date, '%Y-%m-%d'

AdminMailer.periodic_csv(start_date, end_date, report, admin_id).deliver_now
end

def scope(klass, time)
klass.where('created_at > ? AND created_at < ?', time.beginning_of_day, time.end_of_day)
Expand Down
Loading

0 comments on commit 9e25bf7

Please sign in to comment.