Skip to content

Commit 986427d

Browse files
committed
send email to all admins.
1 parent 5481e0e commit 986427d

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

app/controllers/accounts_controller.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ def new
1414
def create
1515
redirect_to teamname_path(slug: @team.slug) if @plan.free?
1616

17-
@account = @team.build_account(account_params)
18-
@account.admin_id = current_user.id
19-
# TODO: (whatupdave) this doesn't look like it's being used any more. Remove if possible
20-
# @account.trial_end = Date.new(2013, 1, 1).to_time.to_i if session[:discount] == ENV['DISCOUNT_TOKEN']
17+
@account = @team.build_account(account_params)
2118

2219
if @account.save_with_payment(@plan)
2320
unless @team.is_member?(current_user)
@@ -62,7 +59,7 @@ def send_invoice
6259
team, period = Team.find(params[:team_id]), 1.month.ago
6360

6461
if team.account.send_invoice_for(period)
65-
flash[:notice] = "sent invoice for #{period.strftime("%B")} to #{team.account.admin.email}"
62+
flash[:notice] = "sent invoice for #{period.strftime("%B")} to the team's admins "
6663
else
6764
flash[:error] = 'There was an error in sending an invoice'
6865
end
@@ -72,13 +69,16 @@ def send_invoice
7269

7370
private
7471
def lookup_account
75-
@team = (current_user && current_user.team) || (params[:team_id] && Team.find(params[:team_id]))
76-
return redirect_to employers_path if @team.nil?
72+
begin
73+
@team = Team.includes(:account).find(params[:team_id])
74+
rescue ActiveRecord::RecordNotFound
75+
redirect_to employers_path if @team.nil?
76+
end
7777
@account = @team.account
7878
end
7979

8080
def ensure_account_admin
81-
is_admin? || current_user.team && current_user.team.admin?(current_user)
81+
is_admin? || @team.admins.exists?(user_id: current_user)
8282
end
8383

8484
def determine_plan

app/mailers/notifier_mailer.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,11 @@ def invoice(team_id, time, invoice_id=nil)
209209
headers['X-Mailgun-Variables'] = {email_type: INVOICE_EVENT}.to_json
210210
#track_campaign("new_applicant")
211211
@team = Team.find(team_id)
212-
@admin = @team.account.admin
212+
team_admin_emails = @team.admin_accounts.pluck :email
213213
@invoice = invoice_id.nil? ? @team.account.invoice_for(Time.at(time)) : Stripe::Invoice.retrieve(invoice_id).to_hash.with_indifferent_access
214214
@customer = @team.account.customer
215215

216-
mail to: @admin.email, bcc: admin_emails, subject: "Invoice for Coderwall enhanced team profile subscription"
216+
mail to: team_admin_emails, bcc: admin_emails, subject: "Invoice for Coderwall enhanced team profile subscription"
217217
end
218218

219219

@@ -268,6 +268,6 @@ def badge_for_message(badge)
268268
end
269269

270270
def admin_emails
271-
YAML.load(ENV['NOTIFIER_ADMIN_EMAILS'])
271+
User.admins.pluck(:email)
272272
end
273273
end

app/models/teams/account.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ def add_analytics
123123
end
124124

125125
def send_invoice(invoice_id)
126-
NotifierMailer.invoice(self.team.id, nil, invoice_id).deliver
126+
NotifierMailer.invoice(team_id, nil, invoice_id).deliver
127127
end
128128

129129
def send_invoice_for(time = Time.now)
130-
NotifierMailer.invoice(self.team.id, time.to_i).deliver
130+
NotifierMailer.invoice(team_id, time.to_i).deliver
131131
end
132132

133133
def invoice_for(time)

0 commit comments

Comments
 (0)