Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulling in latest bug fixes #1416

Merged
merged 7 commits into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions app/controllers/api/v0/statistics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ class StatisticsController < Api::V0::BaseController
def users_joined
raise Pundit::NotAuthorizedError unless Api::V0::StatisticsPolicy.new(@user, :statistics).users_joined?

scoped = User.unscoped.where.not(confirmed_at: nil)
if @user.can_super_admin? && params[:org_id].present?
scoped = scoped.where(org_id: params[:org_id])
scoped = User.unscoped.where(org_id: params[:org_id])
else
scoped = scoped.where(org_id: @user.org_id)
scoped = User.unscoped.where(org_id: @user.org_id)
end

if params[:range_dates].present?
Expand All @@ -28,13 +27,13 @@ def users_joined
end
respond_to do |format|
format.json { render(json: r.to_json) }
format.csv {
format.csv {
send_data(CSV.generate do |csv|
csv << [_('Month'), _('No. Users joined')]
total = 0
r.each_pair{ |k,v| csv << [k,v]; total+=v }
csv << [_('Total'), total]
end, filename: "#{_('users_joined')}.csv") }
end, filename: "#{_('users_joined')}.csv") }
end
else
scoped = scoped.where('created_at >= ?', Date.parse(params[:start_date])) if params[:start_date].present?
Expand Down Expand Up @@ -80,15 +79,15 @@ def completed_plans
plans = plans.where('plans.updated_at >= ?', Date.parse(params[:start_date])) if params[:start_date].present?
plans = plans.where('plans.updated_at <= ?', Date.parse(params[:end_date])) if params[:end_date].present?
count = roles.joins(:user, :plan).merge(users).merge(plans).select(:plan_id).distinct.count
render(json: { completed_plans: count })
render(json: { completed_plans: count })
end
end

# /api/v0/statistics/created_plans
# Returns the number of created plans within the user's org for the data start_date and end_date specified
def created_plans
raise Pundit::NotAuthorizedError unless Api::V0::StatisticsPolicy.new(@user, :statistics).plans?

roles = Role.where("#{Role.creator_condition} OR #{Role.administrator_condition}")

users = User.unscoped
Expand Down Expand Up @@ -232,4 +231,4 @@ def restrict_date_range( objects )
end
end
end
end
end
13 changes: 9 additions & 4 deletions app/controllers/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ class ContactUs::ContactsController < ApplicationController
def create
@contact = ContactUs::Contact.new(params[:contact_us_contact])

if verify_recaptcha(model: @contact) && @contact.save
if !user_signed_in?
unless verify_recaptcha(model: @contact) && @contact.save
flash[:alert] = _('Captcha verification failed, please retry.')
render_new_page and return
end
end
if @contact.save
redirect_to(ContactUs.success_redirect || '/', :notice => _('Contact email was successfully sent.'))
else
flash[:alert] = _('Captcha verification failed, please retry.')
redirect_to request.referrer
#render_new_page
flash[:alert] = _('Unable to submit your request')
render_new_page
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/plans/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
controller: 'paginable/plans',
action: 'privately_visible',
scope: @plans,
query_params: { sort_field: 'plans.updated_at', sort_direction: :desc }) %>
query_params: { sort_field: 'plans.updated_at', sort_direction: 'desc' }) %>
</div>
</div>
<div class="row">
Expand Down