diff --git a/app/controllers/api/v0/statistics_controller.rb b/app/controllers/api/v0/statistics_controller.rb index 57c2e430f4..761cf26df2 100644 --- a/app/controllers/api/v0/statistics_controller.rb +++ b/app/controllers/api/v0/statistics_controller.rb @@ -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? @@ -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? @@ -80,7 +79,7 @@ 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 @@ -88,7 +87,7 @@ def completed_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 @@ -232,4 +231,4 @@ def restrict_date_range( objects ) end end end -end \ No newline at end of file +end