2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-12 20:03:43 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
|
|
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
2019-07-30 21:29:24 +00:00
|
|
|
class NonprofitsController < ApplicationController
|
2020-05-11 18:38:50 +00:00
|
|
|
include Controllers::Nonprofit::Current
|
|
|
|
include Controllers::Nonprofit::Authorization
|
2021-05-19 20:36:57 +00:00
|
|
|
include Controllers::XFrame
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
helper_method :current_nonprofit_user?
|
|
|
|
before_action :authenticate_nonprofit_user!, only: %i[dashboard dashboard_metrics dashboard_todos payment_history profile_todos recurring_donation_stats update verify_identity]
|
2020-06-18 22:35:22 +00:00
|
|
|
before_action :authenticate_super_admin!, if: proc {|c| ( c.action_name == "destroy") || (c.action_name == "show" && !current_nonprofit.published) }
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2021-05-19 20:36:57 +00:00
|
|
|
# we have to allow nonprofits/:id/donation and nonprofits/:id/btn to be framed
|
|
|
|
after_action :allow_framing, only: %i[donate btn]
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# get /nonprofits/:id
|
|
|
|
# get /:state_code/:city/:name
|
|
|
|
def show
|
|
|
|
@nonprofit = current_nonprofit
|
|
|
|
@url = Format::Url.concat(root_url, @nonprofit.url)
|
|
|
|
@supporters = @nonprofit.supporters.not_deleted
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
events = @nonprofit.events.not_deleted.order('start_datetime desc')
|
2019-02-06 17:24:37 +00:00
|
|
|
campaigns = @nonprofit.campaigns.not_deleted.not_a_child.order('created_at desc')
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
@events = events.upcoming
|
|
|
|
@any_past_events = events.past.any?
|
|
|
|
@active_campaigns = campaigns.active
|
|
|
|
@any_past_campaigns = campaigns.past.any?
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2020-05-15 19:01:59 +00:00
|
|
|
@nonprofit_background_image = @nonprofit.background_image.attached? ?
|
|
|
|
url_for(@nonprofit.background_image_by_size(:normal)) :
|
2020-06-10 22:31:47 +00:00
|
|
|
url_for(Houdini.defaults.image.nonprofit)
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json { @nonprofit }
|
|
|
|
end
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
def recurring_donation_stats
|
|
|
|
render json: QueryRecurringDonations.overall_stats(params[:nonprofit_id])
|
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def profile_todos
|
|
|
|
render json: FetchTodoStatus.for_profile(current_nonprofit)
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def dashboard_todos
|
|
|
|
render json: FetchTodoStatus.for_dashboard(current_nonprofit)
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def create
|
2018-03-25 17:30:42 +00:00
|
|
|
current_user ||= User.find(params[:user_id])
|
2019-08-06 14:06:41 +00:00
|
|
|
json_saved Nonprofit.register(current_user, nonprofit_params)
|
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
|
|
|
def update
|
|
|
|
flash[:notice] = 'Update successful!'
|
2020-05-20 21:03:16 +00:00
|
|
|
current_nonprofit.update nonprofit_params.except(:verification_status)
|
2019-07-30 21:29:24 +00:00
|
|
|
json_saved current_nonprofit
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def destroy
|
|
|
|
current_nonprofit.destroy
|
|
|
|
flash[:notice] = 'Nonprofit removed'
|
|
|
|
render json: {}
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
# get /nonprofits/:id/donate
|
|
|
|
def donate
|
|
|
|
@nonprofit = current_nonprofit
|
|
|
|
@referer = params[:origin] || request.env['HTTP_REFERER']
|
|
|
|
@campaign = current_nonprofit.campaigns.find_by_id(params[:campaign_id]) if params[:campaign_id]
|
|
|
|
@countries_translations = countries_list(I18n.locale)
|
2019-07-30 21:29:24 +00:00
|
|
|
respond_to { |format| format.html { render layout: 'layouts/embed' } }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def btn
|
|
|
|
@nonprofit = current_nonprofit
|
|
|
|
respond_to { |format| format.html { render layout: 'layouts/embed' } }
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
# get /nonprofits/:id/supporter_form
|
|
|
|
def supporter_form
|
2019-07-30 21:29:24 +00:00
|
|
|
@nonprofit = current_nonprofit
|
|
|
|
respond_to { |format| format.html { render layout: 'layouts/embed' } }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# post /nonprofits/:id/supporter_with_tag
|
|
|
|
def custom_supporter
|
|
|
|
@nonprofit = current_nonprofit
|
|
|
|
render json: InsertSupporter.with_tags_and_fields(@nonprofit.id, params[:supporter])
|
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def dashboard
|
|
|
|
@nonprofit = current_nonprofit
|
|
|
|
respond_to { |format| format.html }
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def dashboard_metrics
|
|
|
|
render json: Hamster::Hash[data: NonprofitMetrics.all_metrics(current_nonprofit.id)]
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def payment_history
|
2018-03-25 17:30:42 +00:00
|
|
|
render json: NonprofitMetrics.payment_history(params)
|
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
|
|
|
# put /nonprofits/:id/verify_identity
|
|
|
|
def verify_identity
|
2018-03-25 17:30:42 +00:00
|
|
|
if params[:legal_entity][:address]
|
|
|
|
tos = {
|
|
|
|
ip: current_user.current_sign_in_ip,
|
|
|
|
date: Time.current.to_i,
|
|
|
|
user_agent: request.user_agent
|
|
|
|
}
|
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
render_json { UpdateNonprofit.verify_identity(params[:nonprofit_id], params[:legal_entity], tos) }
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
def search
|
|
|
|
render json: QueryNonprofits.by_search_string(params[:npo_name])
|
|
|
|
end
|
|
|
|
|
|
|
|
def onboard
|
|
|
|
render_json do
|
|
|
|
result = OnboardAccounts.create_org(params)
|
|
|
|
sign_in result[:user]
|
|
|
|
result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def countries_list(locale)
|
|
|
|
all_countries = ISO3166::Country.translations(locale)
|
|
|
|
|
2020-06-10 22:31:47 +00:00
|
|
|
if Houdini.intl.all_countries
|
|
|
|
countries = all_countries.select { |code, _name| Houdini.intl.all_countries.include? code }
|
2019-07-30 21:29:24 +00:00
|
|
|
countries = countries.map { |code, name| [code.upcase, name] }.sort_by { |a| a[1] }
|
2018-03-25 17:30:42 +00:00
|
|
|
countries
|
|
|
|
else
|
2019-07-30 21:29:24 +00:00
|
|
|
all_countries.map { |code, name| [code.upcase, name] }.sort_by { |a| a[1] }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|
2019-08-06 14:06:41 +00:00
|
|
|
|
|
|
|
def nonprofit_params
|
|
|
|
params.require(:nonprofit).permit(
|
|
|
|
:name,
|
|
|
|
:stripe_account_id,
|
|
|
|
:summary,
|
|
|
|
:tagline,
|
|
|
|
:email,
|
|
|
|
:phone,
|
|
|
|
:main_image,
|
|
|
|
:second_image,
|
|
|
|
:third_image,
|
|
|
|
:background_image,
|
|
|
|
:remove_background_image,
|
|
|
|
:logo,
|
|
|
|
:zip_code,
|
|
|
|
:website,
|
|
|
|
:categories,
|
|
|
|
:achievements,
|
|
|
|
:full_description,
|
|
|
|
:state_code,
|
|
|
|
:statement,
|
|
|
|
:city,
|
|
|
|
:slug,
|
|
|
|
:city_slug,
|
|
|
|
:state_code_slug,
|
|
|
|
:ein,
|
|
|
|
:published,
|
|
|
|
:vetted,
|
|
|
|
:verification_status,
|
|
|
|
:timezone,
|
|
|
|
:address,
|
|
|
|
:thank_you_note,
|
|
|
|
:referrer,
|
|
|
|
:no_anon,
|
|
|
|
:roles_attributes,
|
|
|
|
:brand_font,
|
|
|
|
:brand_color,
|
|
|
|
:hide_activity_feed,
|
|
|
|
:tracking_script,
|
|
|
|
:facebook,
|
|
|
|
:twitter,
|
|
|
|
:youtube,
|
|
|
|
:instagram,
|
|
|
|
:blog,
|
|
|
|
:card_failure_message_top,
|
|
|
|
:card_failure_message_bottom,
|
|
|
|
:autocomplete_supporter_address
|
|
|
|
)
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|