2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
class SuperAdminsController < ApplicationController
|
2019-07-30 21:29:24 +00:00
|
|
|
layout 'layouts/page'
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-13 07:53:59 +00:00
|
|
|
before_action :authenticate_super_associate!
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def index; end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
def search_nonprofits
|
|
|
|
render json: QueryNonprofits.for_admin(params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def search_profiles
|
|
|
|
render json: QueryProfiles.for_admin(params)
|
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def search_fullcontact
|
2018-03-25 17:30:42 +00:00
|
|
|
begin
|
|
|
|
result = FullContact.person(email: params[:search])
|
|
|
|
rescue Exception => e
|
2019-07-30 21:29:24 +00:00
|
|
|
result = ''
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
render json: [result]
|
|
|
|
end
|
|
|
|
|
|
|
|
def resend_user_confirmation
|
2019-07-30 21:29:24 +00:00
|
|
|
ParamValidation.new(params || {},
|
|
|
|
profile_id: { required: true, is_integer: true })
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
profile = Profile.includes(:user).where('id = ?', params[:profile_id]).first
|
2019-07-30 21:29:24 +00:00
|
|
|
unless profile.user
|
|
|
|
raise ArgumentError, "#{params[:profile_id]} is a profile without a valid user"
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
profile.user.send_confirmation_instructions
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
render json: { status: :ok }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def recurring_donations_without_cards
|
2019-07-30 21:29:24 +00:00
|
|
|
odd_donations = QueryRecurringDonations.recurring_donations_without_cards
|
2018-03-25 17:30:42 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.csv do
|
2019-07-30 21:29:24 +00:00
|
|
|
csv_out = CSV.generate do |csv|
|
2018-03-25 17:30:42 +00:00
|
|
|
csv << ['supporter id', 'recurring donation id', 'rd created date', 'rd modified', 'donation id', 'donation card id',
|
|
|
|
'edit_token', 'nonprofit id',
|
|
|
|
'last charge succeeded id', 'last charge succeeded created at', 'last charge attempted id', 'last charge attempted created at', 'amount']
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
odd_donations.each do |rd|
|
2018-03-25 17:30:42 +00:00
|
|
|
csv << [rd.supporter.id, rd.id, rd.created_at, rd.updated_at, rd.donation.id, rd.donation.card_id, rd.edit_token, rd.nonprofit.id,
|
|
|
|
rd.most_recent_paid_charge.id, rd.most_recent_paid_charge.created_at, rd.most_recent_charge.id, rd.most_recent_charge.created_at,
|
|
|
|
rd.amount]
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
send_data(csv_out, filename: "recurring_donations_without_cards-#{Time.now.to_date}.csv")
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def export_supporters_with_rds
|
|
|
|
np = params[:np]
|
|
|
|
ids = params[:ids]
|
2019-07-30 21:29:24 +00:00
|
|
|
results = QuerySupporters.for_export(np, ids: ids)
|
|
|
|
results[0].push('Management URLS')
|
|
|
|
results.drop(1).each do |row|
|
|
|
|
rds = Supporter.includes(:recurring_donations).find(row.last).recurring_donations.select(&:active).map { |rd| "* #{root_url}recurring_donations/#{rd.id}/edit?t=#{rd.edit_token}" }.join("\n")
|
2018-03-25 17:30:42 +00:00
|
|
|
row.push(rds)
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
send_data(Format::Csv.from_vectors(results), filename: 'supporters_with_multiple_donations.csv')
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|