rails 5: fix lots of deprecation warnings

mostly s/uniq/distinct/, and choosing a content type for render :text

Change-Id: I53a2e77d23ecc43162f70b4fd88303cc1539c20b
Reviewed-on: https://gerrit.instructure.com/104762
Tested-by: Jenkins
Reviewed-by: Simon Williams <simon@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2017-03-10 13:01:31 -07:00
parent 7b66ff4e37
commit 6751891617
18 changed files with 39 additions and 35 deletions

View File

@ -423,7 +423,7 @@ class ApplicationController < ActionController::Base
def check_pending_otp
if session[:pending_otp] && params[:controller] != 'login/otp'
return render text: "Please finish logging in", status: 403 if request.xhr?
return render plain: "Please finish logging in", status: 403 if request.xhr?
reset_session
redirect_to login_url
@ -508,7 +508,7 @@ class ApplicationController < ActionController::Base
# to a web browser - but you've lost your cookies! This breaks not only store_location,
# but in the case of delegated authentication where the provider does an additional
# redirect storing important information in session, makes it impossible to log in at all
render text: '', status: 200
render plain: '', status: 200
return false
end
true
@ -544,7 +544,7 @@ class ApplicationController < ActionController::Base
}
format.zip { redirect_to(url_for(path_params)) }
format.json { render_json_unauthorized }
format.all { render text: 'Unauthorized', status: :unauthorized }
format.all { render plain: 'Unauthorized', status: :unauthorized }
end
set_no_cache_headers
end

View File

@ -25,7 +25,7 @@ class BrandConfigsController < ApplicationController
sharedBrandConfigs: visible_shared_brand_configs.as_json(include_root: false, include: 'brand_config'),
activeBrandConfig: active_brand_config(ignore_parents: true).as_json(include_root: false)
}
render text: '', layout: true
render html: '', layout: true
end
def new
@ -39,7 +39,7 @@ class BrandConfigsController < ApplicationController
variableSchema: default_schema,
allowGlobalIncludes: @account.allow_global_includes?,
account_id: @account.id
render text: '', layout: 'layouts/bare'
render html: '', layout: 'layouts/bare'
end
def show

View File

@ -231,7 +231,7 @@ class ConferencesController < ApplicationController
end
@conference.save
format.html { redirect_to named_context_url(@context, :context_conference_url, @conference.id) }
format.json { render :json => WebConference.find(@conference).as_json(:permissions => {:user => @current_user, :session => session},
format.json { render :json => WebConference.find(@conference.id).as_json(:permissions => {:user => @current_user, :session => session},
:url => named_context_url(@context, :context_conference_url, @conference)) }
else
format.html { render :index }

View File

@ -1130,7 +1130,7 @@ class CoursesController < ApplicationController
js_bundle :course_blueprint_settings
@page_title = join_title(t('Blueprint Settings'), @context.name)
render text: '', layout: true
render html: '', layout: true
else
render status: 404, template: 'shared/errors/404_message'
end

View File

@ -86,14 +86,14 @@ class Login::CasController < ApplicationController
def destroy
if !Canvas.redis_enabled?
# NOT SUPPORTED without redis
return render text: "NOT SUPPORTED", status: :method_not_allowed
return render plain: "NOT SUPPORTED", status: :method_not_allowed
elsif params['logoutRequest'] &&
(match = params['logoutRequest'].match(CAS_SAML_LOGOUT_REQUEST))
# we *could* validate the timestamp here, but the whole request is easily spoofed anyway, so there's no
# point. all the security is in the ticket being secret and non-predictable
return render text: "OK", status: :ok if Pseudonym.expire_cas_ticket(match[:session_index])
return render plain: "OK", status: :ok if Pseudonym.expire_cas_ticket(match[:session_index])
end
render text: "NO SESSION FOUND", status: :not_found
render plain: "NO SESSION FOUND", status: :not_found
end
protected

View File

@ -15,7 +15,7 @@ module SupportHelpers
run_fixer(SupportHelpers::Crocodoc::SubmissionFixer,
params[:assignment_id].to_i, params[:user_id].to_i)
else
render text: "Missing either assignment and/or user id parameters", status: 400
render plain: "Missing either assignment and/or user id parameters", status: 400
end
end
end

View File

@ -22,7 +22,7 @@ module SupportHelpers
if params[:id]
run_fixer(SupportHelpers::Tii::AssignmentFixer, params[:id].to_i)
else
render text: "Missing assignment `id` parameter", status: 400
render plain: "Missing assignment `id` parameter", status: 400
end
end

View File

@ -1691,7 +1691,7 @@ class Assignment < ActiveRecord::Base
@visible_students_for_speed_grader[[user.global_id, includes]] ||= (
student_scope = user ? context.students_visible_to(user, include: includes) : context.participating_students
students_with_visibility(student_scope)
).order_by_sortable_name.uniq.to_a
).order_by_sortable_name.distinct.to_a
end
def visible_rubric_assessments_for(user, opts={})
@ -2257,7 +2257,7 @@ class Assignment < ActiveRecord::Base
end
def self.assignment_ids_with_submissions(assignment_ids)
Submission.having_submission.where(:assignment_id => assignment_ids).uniq.pluck(:assignment_id)
Submission.having_submission.where(:assignment_id => assignment_ids).distinct.pluck(:assignment_id)
end
# override so validations are called

View File

@ -117,9 +117,9 @@ class Course < ActiveRecord::Base
has_many :course_account_associations
has_many :non_unique_associated_accounts, -> { order('course_account_associations.depth') }, source: :account, through: :course_account_associations
has_many :users, -> { uniq }, through: :enrollments, source: :user
has_many :current_users, -> { uniq }, through: :current_enrollments, source: :user
has_many :all_current_users, -> { uniq }, through: :all_current_enrollments, source: :user
has_many :users, -> { distinct }, through: :enrollments, source: :user
has_many :current_users, -> { distinct }, through: :current_enrollments, source: :user
has_many :all_current_users, -> { distinct }, through: :all_current_enrollments, source: :user
has_many :group_categories, -> {where(deleted_at: nil) }, as: :context, inverse_of: :context
has_many :all_group_categories, :class_name => 'GroupCategory', :as => :context, :inverse_of => :context
has_many :groups, :as => :context, :inverse_of => :context
@ -2416,7 +2416,7 @@ class Course < ActiveRecord::Base
def invited_count_visible_to(user)
scope = users_visible_to(user).
where("enrollments.workflow_state in ('invited', 'creation_pending') AND enrollments.type != 'StudentViewEnrollment'")
scope.select('users.id').uniq.count
scope.select('users.id').distinct.count
end
def published?

View File

@ -615,9 +615,9 @@ class DiscussionTopic < ActiveRecord::Base
student_ids = context.all_real_student_enrollments.select(:user_id)
topic_ids_with_entries = DiscussionEntry.active.where(discussion_topic_id: topics).
where(:user_id => student_ids).uniq.pluck(:discussion_topic_id)
where(:user_id => student_ids).distinct.pluck(:discussion_topic_id)
topic_ids_with_entries += DiscussionTopic.where("root_topic_id IS NOT NULL").
where(:id => topic_ids_with_entries).uniq.pluck(:root_topic_id)
where(:id => topic_ids_with_entries).distinct.pluck(:root_topic_id)
topics.each do |topic|
if topic.assignment_id

View File

@ -460,7 +460,11 @@ class Group < ActiveRecord::Base
def account_id=(new_account_id)
write_attribute(:account_id, new_account_id)
if self.account_id_changed?
self.root_account = self.account(true).try(:root_account)
if CANVAS_RAILS4_2
self.root_account = self.account(true)&.root_account
else
self.root_account = self.reload_account&.root_account
end
end
end

View File

@ -37,8 +37,8 @@ class Mailer < ActionMailer::Base
params[:reply_to] = reply_to if reply_to
mail(params) do |format|
format.text{ render text: m.body }
format.html{ render text: m.html_body } if m.html_body
format.text{ render plain: m.body }
format.html{ render html: m.html_body } if m.html_body
end
end

View File

@ -421,7 +421,7 @@ class Quizzes::Quiz < ActiveRecord::Base
@notify_of_update ? a.save : a.save_without_broadcasting!
end
self.assignment_id = a.id
Quizzes::Quiz.where(:id => self).update_all(:assignment_id => a)
Quizzes::Quiz.where(id: self).update_all(assignment_id: a.id)
end
end
end

View File

@ -248,9 +248,9 @@ class Role < ActiveRecord::Base
def self.custom_roles_and_counts_for_course(course, user, include_inactive=false)
users_scope = course.users_visible_to(user)
base_counts = users_scope.where('enrollments.role_id IS NULL OR enrollments.role_id IN (?)',
Role.built_in_course_roles.map(&:id)).group('enrollments.type').select('users.id').uniq.count
Role.built_in_course_roles.map(&:id)).group('enrollments.type').select('users.id').distinct.count
role_counts = users_scope.where('enrollments.role_id IS NOT NULL AND enrollments.role_id NOT IN (?)',
Role.built_in_course_roles.map(&:id)).group('enrollments.role_id').select('users.id').uniq.count
Role.built_in_course_roles.map(&:id)).group('enrollments.role_id').select('users.id').distinct.count
@enrollment_types = Role.all_enrollment_roles_for_account(course.account, include_inactive)
@enrollment_types.each do |base_type|

View File

@ -320,7 +320,7 @@ class User < ActiveRecord::Base
after_save :self_enroll_if_necessary
def courses_for_enrollments(enrollment_scope)
Course.active.joins(:all_enrollments).merge(enrollment_scope.except(:joins)).uniq
Course.active.joins(:all_enrollments).merge(enrollment_scope.except(:joins)).distinct
end
def courses
@ -479,7 +479,7 @@ class User < ActiveRecord::Base
Enrollment.where("workflow_state<>'deleted' AND type<>'StudentViewEnrollment'").
where(:user_id => shard_user_ids).
select([:user_id, :course_id, :course_section_id]).
uniq.to_a
distinct.to_a
# probably a lot of dups, so more efficient to use a set than uniq an array
course_section_ids = Set.new
@ -495,9 +495,9 @@ class User < ActiveRecord::Base
data[:courses] += Course.select([:id, :account_id]).where(:id => course_ids.to_a).to_a unless course_ids.empty?
data[:pseudonyms] += Pseudonym.active.select([:user_id, :account_id]).uniq.where(:user_id => shard_user_ids).to_a
data[:pseudonyms] += Pseudonym.active.select([:user_id, :account_id]).distinct.where(:user_id => shard_user_ids).to_a
AccountUser.unscoped do
data[:account_users] += AccountUser.select([:user_id, :account_id]).uniq.where(:user_id => shard_user_ids).to_a
data[:account_users] += AccountUser.select([:user_id, :account_id]).distinct.where(:user_id => shard_user_ids).to_a
end
end
# now make it easy to get the data by user id
@ -1542,7 +1542,7 @@ class User < ActiveRecord::Base
expecting_submission.
where(:moderated_grading => true).
where("assignments.grades_published_at IS NULL").
joins(:provisional_grades).uniq.preload(:context).
joins(:provisional_grades).distinct.preload(:context).
need_grading_info.
lazy.select{|a| a.context.grants_right?(self, :moderate_grades)}.take(opts[:limit]).to_a
end
@ -2319,7 +2319,7 @@ class User < ActiveRecord::Base
@roles = Rails.cache.fetch(['user_roles_for_root_account3', self, root_account].cache_key) do
roles = ['user']
enrollment_types = root_account.all_enrollments.where(user_id: self, workflow_state: 'active').uniq.pluck(:type)
enrollment_types = root_account.all_enrollments.where(user_id: self, workflow_state: 'active').distinct.pluck(:type)
roles << 'student' unless (enrollment_types & %w[StudentEnrollment StudentViewEnrollment]).empty?
roles << 'teacher' unless (enrollment_types & %w[TeacherEnrollment TaEnrollment DesignerEnrollment]).empty?
roles << 'observer' unless (enrollment_types & %w[ObserverEnrollment]).empty?

View File

@ -100,7 +100,7 @@ module Api::V1::Outcome
#
# Assumption: All of the outcome links have the same context.
#
opts[:assessed_outcomes] = LearningOutcomeResult.uniq.where(
opts[:assessed_outcomes] = LearningOutcomeResult.distinct.where(
context_type: outcome_links.first.context_type,
context_id: outcome_links.map(&:context_id),
learning_outcome_id: outcome_links.map(&:content_id)

View File

@ -165,7 +165,7 @@ class MessageableUser
def count_messageable_users_in_scope(scope)
if scope
scope.except(:select, :group, :order).uniq.count
scope.except(:select, :group, :order).distinct.count
else
0
end

View File

@ -12,7 +12,7 @@ module SupportHelpers
fixer = fixer_klass.new(@current_user.email, params[:after_time], *args)
fixer.send_later_if_production(:monitor_and_fix)
render text: "Enqueued #{fixer.fixer_name}..."
render plain: "Enqueued #{fixer.fixer_name}..."
end
end
end