Skip to content

Commit

Permalink
Merge pull request #1414 from DigitalCurationCentre/stats_fix_1410
Browse files Browse the repository at this point in the history
removed requirement that users are confirmed from stats controller
  • Loading branch information
briri committed Apr 25, 2018
2 parents 1cbf169 + 58e4c7c commit 3fa752b
Showing 1 changed file with 7 additions and 8 deletions.
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

0 comments on commit 3fa752b

Please sign in to comment.