diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 374042485cf..0ead53afa30 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -32,7 +32,7 @@ class AnnouncementsController < ApplicationController respond_to do |format| format.html do add_crumb(t(:announcements_crumb, "Announcements")) - can_create = @context.announcements.scope.new.grants_right?(@current_user, session, :create) + can_create = @context.announcements.temp_record.grants_right?(@current_user, session, :create) js_env :permissions => { :create => can_create, :moderate => can_create diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index afefc7938e0..1a47726a404 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -701,7 +701,7 @@ class ApplicationController < ActionController::Base if @just_viewing_one_course # fake assignment used for checking if the @current_user can read unpublished assignments - fake = @context.assignments.scope.new + fake = @context.assignments.temp_record fake.workflow_state = 'unpublished' assignment_scope = :active_assignments diff --git a/app/controllers/assignment_groups_api_controller.rb b/app/controllers/assignment_groups_api_controller.rb index 80e8a8619e8..b3f6702f6fe 100644 --- a/app/controllers/assignment_groups_api_controller.rb +++ b/app/controllers/assignment_groups_api_controller.rb @@ -80,7 +80,7 @@ class AssignmentGroupsApiController < ApplicationController # # @returns AssignmentGroup def create - @assignment_group = @context.assignment_groups.scope.new + @assignment_group = @context.assignment_groups.temp_record if authorized_action(@assignment_group, @current_user, :create) process_assignment_group end diff --git a/app/controllers/assignment_groups_controller.rb b/app/controllers/assignment_groups_controller.rb index 6967ecb0f1f..f5072458df4 100644 --- a/app/controllers/assignment_groups_controller.rb +++ b/app/controllers/assignment_groups_controller.rb @@ -105,7 +105,7 @@ class AssignmentGroupsController < ApplicationController # # @returns [AssignmentGroup] def index - if authorized_action(@context.assignment_groups.scope.new, @current_user, :read) + if authorized_action(@context.assignment_groups.temp_record, @current_user, :read) groups = Api.paginate(@context.assignment_groups.active, self, api_v1_course_assignment_groups_url(@context)) assignments = if include_params.include?('assignments') @@ -127,7 +127,7 @@ class AssignmentGroupsController < ApplicationController end def reorder - if authorized_action(@context.assignment_groups.scope.new, @current_user, :update) + if authorized_action(@context.assignment_groups.temp_record, @current_user, :update) order = params[:order].split(',') @context.assignment_groups.first.update_order(order) new_order = @context.assignment_groups.pluck(:id) @@ -171,7 +171,7 @@ class AssignmentGroupsController < ApplicationController end def create - @assignment_group = @context.assignment_groups.scope.new(params[:assignment_group]) + @assignment_group = @context.assignment_groups.temp_record(params[:assignment_group]) if authorized_action(@assignment_group, @current_user, :create) respond_to do |format| if @assignment_group.save diff --git a/app/controllers/assignments_controller.rb b/app/controllers/assignments_controller.rb index 226796b4f6c..02fe4235257 100644 --- a/app/controllers/assignments_controller.rb +++ b/app/controllers/assignments_controller.rb @@ -360,7 +360,7 @@ class AssignmentsController < ApplicationController end def new - @assignment ||= @context.assignments.scope.new + @assignment ||= @context.assignments.temp_record @assignment.workflow_state = 'unpublished' add_crumb t :create_new_crumb, "Create new" diff --git a/app/controllers/calendar_events_controller.rb b/app/controllers/calendar_events_controller.rb index 16dcf6fd737..e7d106c4636 100644 --- a/app/controllers/calendar_events_controller.rb +++ b/app/controllers/calendar_events_controller.rb @@ -45,7 +45,7 @@ class CalendarEventsController < ApplicationController def new - @event = @context.calendar_events.scope.new + @event = @context.calendar_events.temp_record add_crumb(t('crumbs.new', "New Calendar Event"), named_context_url(@context, :new_context_calendar_event_url)) @event.assign_attributes(params.slice(:title, :start_at, :end_at, :location_name, :location_address)) js_env(:DIFFERENTIATED_ASSIGNMENTS_ENABLED => @context.feature_enabled?(:differentiated_assignments), diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index 31e0c72baf8..abdadb25300 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -214,7 +214,7 @@ class ConferencesController < ApplicationController end def create - if authorized_action(@context.web_conferences.scope.new, @current_user, :create) + if authorized_action(@context.web_conferences.temp_record, @current_user, :create) params[:web_conference].try(:delete, :long_running) @conference = @context.web_conferences.build(params[:web_conference]) @conference.settings[:default_return_url] = named_context_url(@context, :context_url, :include_host => true) diff --git a/app/controllers/context_modules_api_controller.rb b/app/controllers/context_modules_api_controller.rb index 53d09432729..adc45ca7b58 100644 --- a/app/controllers/context_modules_api_controller.rb +++ b/app/controllers/context_modules_api_controller.rb @@ -514,7 +514,7 @@ class ContextModulesApiController < ApplicationController # # @returns Module def create - if authorized_action(@context.context_modules.scope.new, @current_user, :create) + if authorized_action(@context.context_modules.temp_record, @current_user, :create) return render :json => {:message => "missing module parameter"}, :status => :bad_request unless params[:module] return render :json => {:message => "missing module name"}, :status => :bad_request unless params[:module][:name].present? diff --git a/app/controllers/context_modules_controller.rb b/app/controllers/context_modules_controller.rb index 46313d60aba..337655d2e6e 100644 --- a/app/controllers/context_modules_controller.rb +++ b/app/controllers/context_modules_controller.rb @@ -122,7 +122,7 @@ class ContextModulesController < ApplicationController end def create - if authorized_action(@context.context_modules.scope.new, @current_user, :create) + if authorized_action(@context.context_modules.temp_record, @current_user, :create) @module = @context.context_modules.build @module.workflow_state = 'unpublished' @module.attributes = params[:context_module] @@ -139,7 +139,7 @@ class ContextModulesController < ApplicationController end def reorder - if authorized_action(@context.context_modules.scope.new, @current_user, :update) + if authorized_action(@context.context_modules.temp_record, @current_user, :update) m = @context.context_modules.not_deleted.first m.update_order(params[:order].split(",")) diff --git a/app/controllers/discussion_entries_controller.rb b/app/controllers/discussion_entries_controller.rb index e8f49124444..d1d676dbfd9 100644 --- a/app/controllers/discussion_entries_controller.rb +++ b/app/controllers/discussion_entries_controller.rb @@ -40,7 +40,7 @@ class DiscussionEntriesController < ApplicationController @topic = @context.discussion_topics.active.find(params[:discussion_entry].delete(:discussion_topic_id)) params[:discussion_entry].delete :remove_attachment rescue nil parent_id = params[:discussion_entry].delete(:parent_id) - @entry = @topic.discussion_entries.scope.new(params[:discussion_entry]) + @entry = @topic.discussion_entries.temp_record(params[:discussion_entry]) @entry.current_user = @current_user @entry.user_id = @current_user ? @current_user.id : nil @entry.parent_id = parent_id diff --git a/app/controllers/discussion_topics_controller.rb b/app/controllers/discussion_topics_controller.rb index 368ebf8dda0..126133439b9 100644 --- a/app/controllers/discussion_topics_controller.rb +++ b/app/controllers/discussion_topics_controller.rb @@ -268,7 +268,7 @@ class DiscussionTopicsController < ApplicationController # # @returns [DiscussionTopic] def index - return unless authorized_action(@context.discussion_topics.scope.new, @current_user, :read) + return unless authorized_action(@context.discussion_topics.temp_record, @current_user, :read) return child_topic if is_child_topic? scope = if params[:only_announcements] @@ -332,7 +332,7 @@ class DiscussionTopicsController < ApplicationController lockedTopics: locked_topics, newTopicURL: named_context_url(@context, :new_context_discussion_topic_url), permissions: { - create: @context.discussion_topics.scope.new.grants_right?(@current_user, session, :create), + create: @context.discussion_topics.temp_record.grants_right?(@current_user, session, :create), moderate: user_can_moderate, change_settings: user_can_edit_course_settings?, manage_content: @context.grants_right?(@current_user, session, :manage_content), @@ -376,7 +376,7 @@ class DiscussionTopicsController < ApplicationController hash = { URL_ROOT: named_context_url(@context, :api_v1_context_discussion_topics_url), PERMISSIONS: { - CAN_CREATE_ASSIGNMENT: @context.respond_to?(:assignments) && @context.assignments.scope.new.grants_right?(@current_user, session, :create), + CAN_CREATE_ASSIGNMENT: @context.respond_to?(:assignments) && @context.assignments.temp_record.grants_right?(@current_user, session, :create), CAN_ATTACH: @topic.grants_right?(@current_user, session, :attach), CAN_MODERATE: user_can_moderate } @@ -799,7 +799,7 @@ class DiscussionTopicsController < ApplicationController # (For example, "order=104,102,103".) # def reorder - if authorized_action(@context.discussion_topics.scope.new, @current_user, :update) + if authorized_action(@context.discussion_topics.temp_record, @current_user, :update) order = Api.value_to_array(params[:order]) reject! "order parameter required" unless order && order.length > 0 topics = pinned_topics.where(id: order) @@ -843,7 +843,7 @@ class DiscussionTopicsController < ApplicationController def process_discussion_topic(is_new = false) @errors = {} discussion_topic_hash = params.slice(*API_ALLOWED_TOPIC_FIELDS) - model_type = value_to_boolean(discussion_topic_hash.delete(:is_announcement)) && @context.announcements.scope.new.grants_right?(@current_user, session, :create) ? :announcements : :discussion_topics + model_type = value_to_boolean(discussion_topic_hash.delete(:is_announcement)) && @context.announcements.temp_record.grants_right?(@current_user, session, :create) ? :announcements : :discussion_topics if is_new @topic = @context.send(model_type).build else @@ -1092,7 +1092,7 @@ class DiscussionTopicsController < ApplicationController def handle_assignment_edit_params(hash) hash[:title] = params[:title] if params[:title] if params.slice(*[:due_at, :points_possible, :assignment_group_id]).present? - if hash[:assignment].nil? && @context.respond_to?(:assignments) && @context.assignments.scope.new.grants_right?(@current_user, session, :create) + if hash[:assignment].nil? && @context.respond_to?(:assignments) && @context.assignments.temp_record.grants_right?(@current_user, session, :create) hash[:assignment] ||= {} end diff --git a/app/controllers/external_feeds_controller.rb b/app/controllers/external_feeds_controller.rb index 9634b2a08bc..f30e53a9eec 100644 --- a/app/controllers/external_feeds_controller.rb +++ b/app/controllers/external_feeds_controller.rb @@ -82,7 +82,7 @@ class ExternalFeedsController < ApplicationController # # @returns [ExternalFeed] def index - if authorized_action(@context.announcements.scope.new, @current_user, :create) + if authorized_action(@context.announcements.temp_record, @current_user, :create) api_route = polymorphic_url([:api, :v1, @context, :external_feeds]) @feeds = Api.paginate(@context.external_feeds.order(:id), self, api_route) render :json => external_feeds_api_json(@feeds, @context, @current_user, session) @@ -111,7 +111,7 @@ class ExternalFeedsController < ApplicationController # # @returns ExternalFeed def create - if authorized_action(@context.announcements.scope.new, @current_user, :create) + if authorized_action(@context.announcements.temp_record, @current_user, :create) @feed = create_api_external_feed(@context, params, @current_user) if @feed.save render :json => external_feed_api_json(@feed, @context, @current_user, session) @@ -131,7 +131,7 @@ class ExternalFeedsController < ApplicationController # # @returns ExternalFeed def destroy - if authorized_action(@context.announcements.scope.new, @current_user, :create) + if authorized_action(@context.announcements.temp_record, @current_user, :create) @feed = @context.external_feeds.find(params[:external_feed_id]) if @feed.destroy render :json => external_feed_api_json(@feed, @context, @current_user, session) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index dc81345e3fd..95d1eeb8b02 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -119,7 +119,7 @@ class FilesController < ApplicationController def quota get_quota - if authorized_action(@context.attachments.scope.new, @current_user, :create) + if authorized_action(@context.attachments.temp_record, @current_user, :create) h = ActionView::Base.new h.extend ActionView::Helpers::NumberHelper result = { @@ -305,7 +305,7 @@ class FilesController < ApplicationController end def images - if authorized_action(@context.attachments.scope.new, @current_user, :read) + if authorized_action(@context.attachments.temp_record, @current_user, :read) if Folder.root_folders(@context).first.grants_right?(@current_user, session, :read_contents) if @context.grants_right?(@current_user, session, :manage_files) @images = @context.active_images.paginate :page => params[:page] @@ -721,7 +721,7 @@ class FilesController < ApplicationController @context = @group || @current_user @check_quota = false elsif @context && intent == 'attach_discussion_file' - permission_object = @context.discussion_topics.scope.new + permission_object = @context.discussion_topics.temp_record permission = :attach elsif @context && intent == 'message' permission_object = @context diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 1c2d1644ac2..83f80cb1287 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -436,7 +436,7 @@ class GroupsController < ApplicationController attrs = api_request? ? params : params[:group] attrs.delete :storage_quota_mb unless @context.grants_right? @current_user, session, :manage_storage_quotas - @group = @context.groups.scope.new(attrs.slice(*SETTABLE_GROUP_ATTRIBUTES)) + @group = @context.groups.temp_record(attrs.slice(*SETTABLE_GROUP_ATTRIBUTES)) if authorized_action(@group, @current_user, :create) respond_to do |format| diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 1a94947341f..bd8be83be23 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -96,7 +96,7 @@ class QuestionBanksController < ApplicationController end def create - if authorized_action(@context.assessment_question_banks.scope.new, @current_user, :create) + if authorized_action(@context.assessment_question_banks.temp_record, @current_user, :create) @bank = @context.assessment_question_banks.build(params[:assessment_question_bank]) respond_to do |format| if @bank.save diff --git a/app/controllers/quizzes/quizzes_api_controller.rb b/app/controllers/quizzes/quizzes_api_controller.rb index e1adcae0cf0..28c54d994c1 100644 --- a/app/controllers/quizzes/quizzes_api_controller.rb +++ b/app/controllers/quizzes/quizzes_api_controller.rb @@ -457,7 +457,7 @@ class Quizzes::QuizzesApiController < ApplicationController # # @returns Quiz def create - if authorized_action(@context.quizzes.scope.new, @current_user, :create) + if authorized_action(@context.quizzes.temp_record, @current_user, :create) @quiz = @context.quizzes.build update_api_quiz(@quiz, params) unless @quiz.new_record? diff --git a/app/controllers/quizzes/quizzes_controller.rb b/app/controllers/quizzes/quizzes_controller.rb index 71ad93038e4..1416bf20988 100644 --- a/app/controllers/quizzes/quizzes_controller.rb +++ b/app/controllers/quizzes/quizzes_controller.rb @@ -117,7 +117,7 @@ class Quizzes::QuizzesController < ApplicationController assignment_overrides: api_v1_course_quiz_assignment_overrides_url(@context) }, :PERMISSIONS => { - create: can_do(@context.quizzes.scope.new, @current_user, :create), + create: can_do(@context.quizzes.temp_record, @current_user, :create), manage: can_manage, read_question_banks: can_manage || can_do(@context, @current_user, :read_question_banks) }, @@ -240,7 +240,7 @@ class Quizzes::QuizzesController < ApplicationController end def new - if authorized_action(@context.quizzes.scope.new, @current_user, :create) + if authorized_action(@context.quizzes.temp_record, @current_user, :create) @assignment = nil @assignment = @context.assignments.active.find(params[:assignment_id]) if params[:assignment_id] @quiz = @context.quizzes.build @@ -307,7 +307,7 @@ class Quizzes::QuizzesController < ApplicationController end def create - if authorized_action(@context.quizzes.scope.new, @current_user, :create) + if authorized_action(@context.quizzes.temp_record, @current_user, :create) params[:quiz][:title] = nil if params[:quiz][:title] == "undefined" params[:quiz][:title] ||= t(:default_title, "New Quiz") params[:quiz].delete(:points_possible) unless params[:quiz][:quiz_type] == 'graded_survey' diff --git a/app/controllers/sections_controller.rb b/app/controllers/sections_controller.rb index b09fa0c8c97..56a5dd374ac 100644 --- a/app/controllers/sections_controller.rb +++ b/app/controllers/sections_controller.rb @@ -137,7 +137,7 @@ class SectionsController < ApplicationController # # @returns Section def create - if authorized_action(@context.course_sections.scope.new, @current_user, :create) + if authorized_action(@context.course_sections.temp_record, @current_user, :create) sis_section_id = params[:course_section].try(:delete, :sis_section_id) can_manage_sis = api_request? && sis_section_id.present? && @context.root_account.grants_right?(@current_user, session, :manage_sis) diff --git a/app/models/communication_channel.rb b/app/models/communication_channel.rb index 3d768ded9fc..28777da9067 100644 --- a/app/models/communication_channel.rb +++ b/app/models/communication_channel.rb @@ -244,7 +244,7 @@ class CommunicationChannel < ActiveRecord::Base end def send_otp!(code) - m = self.messages.scope.new + m = self.messages.temp_record m.to = self.path m.body = t :body, "Your Canvas verification code is %{verification_code}", :verification_code => code Mailer.create_message(m).deliver rescue nil # omg! just ignore delivery failures diff --git a/app/models/course.rb b/app/models/course.rb index 19733db5039..c0ae6c5adc1 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -2409,7 +2409,7 @@ class Course < ActiveRecord::Base tabs.delete_if {|t| [TAB_PEOPLE, TAB_OUTCOMES].include?(t[:id]) } end - unless discussion_topics.scope.new.grants_right?(user, :read) + unless discussion_topics.temp_record.grants_right?(user, :read) tabs.delete_if { |t| t[:id] == TAB_ANNOUNCEMENTS } end diff --git a/app/models/importers/discussion_topic_importer.rb b/app/models/importers/discussion_topic_importer.rb index c15c2642687..1e1744a697c 100644 --- a/app/models/importers/discussion_topic_importer.rb +++ b/app/models/importers/discussion_topic_importer.rb @@ -65,9 +65,9 @@ module Importers topic = DiscussionTopic.where(context_type: context.class.to_s, context_id: context.id). where(['id = ? OR (migration_id IS NOT NULL AND migration_id = ?)', options[:id], options[:migration_id]]).first topic ||= if options[:type] =~ /announcement/i - context.announcements.scope.new + context.announcements.temp_record else - context.discussion_topics.scope.new + context.discussion_topics.temp_record end topic.saved_by = :migration topic diff --git a/app/models/wiki.rb b/app/models/wiki.rb index 83db9f7e4c8..bb480802393 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -81,7 +81,7 @@ class Wiki < ActiveRecord::Base # return an implicitly created page if a page could not be found unless page - page = self.wiki_pages.scope.new(:title => url.titleize, :url => url) + page = self.wiki_pages.temp_record(:title => url.titleize, :url => url) page.wiki = self end page diff --git a/app/views/context_modules/_content_next.html.erb b/app/views/context_modules/_content_next.html.erb index dafd5728e1a..0cd7106b548 100644 --- a/app/views/context_modules/_content_next.html.erb +++ b/app/views/context_modules/_content_next.html.erb @@ -42,7 +42,7 @@