From c228850ae879d2c037784e265660a7c34ebbbb43 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Sat, 20 Aug 2022 00:17:10 +0200 Subject: [PATCH] Update find method --- app/channels/la_exercises_channel.rb | 2 +- app/controllers/code_ocean/files_controller.rb | 2 +- app/controllers/codeharbor_links_controller.rb | 2 +- app/controllers/comments_controller.rb | 6 +++--- app/controllers/community_solutions_controller.rb | 4 ++-- app/controllers/consumers_controller.rb | 2 +- app/controllers/error_template_attributes_controller.rb | 2 +- app/controllers/error_templates_controller.rb | 6 +++--- app/controllers/execution_environments_controller.rb | 2 +- app/controllers/exercise_collections_controller.rb | 2 +- app/controllers/exercises_controller.rb | 6 +++--- app/controllers/external_users_controller.rb | 6 +++--- app/controllers/file_templates_controller.rb | 2 +- app/controllers/file_types_controller.rb | 2 +- app/controllers/internal_users_controller.rb | 2 +- app/controllers/proxy_exercises_controller.rb | 6 +++--- app/controllers/request_for_comments_controller.rb | 6 +++--- app/controllers/sessions_controller.rb | 2 +- app/controllers/study_groups_controller.rb | 4 ++-- app/controllers/submissions_controller.rb | 2 +- app/controllers/subscriptions_controller.rb | 4 ++-- app/controllers/tags_controller.rb | 2 +- app/controllers/tips_controller.rb | 2 +- app/controllers/user_exercise_feedbacks_controller.rb | 6 +++--- 24 files changed, 41 insertions(+), 41 deletions(-) diff --git a/app/channels/la_exercises_channel.rb b/app/channels/la_exercises_channel.rb index a8821896..278dac36 100644 --- a/app/channels/la_exercises_channel.rb +++ b/app/channels/la_exercises_channel.rb @@ -12,7 +12,7 @@ class LaExercisesChannel < ApplicationCable::Channel private def specific_channel - reject unless StudyGroupPolicy.new(current_user, StudyGroup.find_by(id: params[:study_group_id])).stream_la? + reject unless StudyGroupPolicy.new(current_user, StudyGroup.find(params[:study_group_id])).stream_la? "la_exercises_#{params[:exercise_id]}_channel_study_group_#{params[:study_group_id]}" end end diff --git a/app/controllers/code_ocean/files_controller.rb b/app/controllers/code_ocean/files_controller.rb index 0bb2c63c..79331f6a 100644 --- a/app/controllers/code_ocean/files_controller.rb +++ b/app/controllers/code_ocean/files_controller.rb @@ -41,7 +41,7 @@ module CodeOcean end def destroy - @file = CodeOcean::File.find_by(id: params[:id]) + @file = CodeOcean::File.find(params[:id]) authorize! destroy_and_respond(object: @file, path: @file.context) end diff --git a/app/controllers/codeharbor_links_controller.rb b/app/controllers/codeharbor_links_controller.rb index 8772c8f0..c98b02b1 100644 --- a/app/controllers/codeharbor_links_controller.rb +++ b/app/controllers/codeharbor_links_controller.rb @@ -43,7 +43,7 @@ class CodeharborLinksController < ApplicationController end def set_codeharbor_link - @codeharbor_link = CodeharborLink.find_by(id: params[:id]) + @codeharbor_link = CodeharborLink.find(params[:id]) authorize! end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 1b23cf20..201246ce 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -10,7 +10,7 @@ class CommentsController < ApplicationController # GET /comments.json def index - file = CodeOcean::File.find_by(id: params[:file_id]) + file = CodeOcean::File.find(params[:file_id]) # there might be no submission yet, so dont use find submission = Submission.find_by(id: file.context_id) if submission @@ -38,7 +38,7 @@ class CommentsController < ApplicationController if @comment.save if comment_params[:request_id] - request_for_comment = RequestForComment.find_by(id: comment_params[:request_id]) + request_for_comment = RequestForComment.find(comment_params[:request_id]) send_mail_to_author @comment, request_for_comment send_mail_to_subscribers @comment, request_for_comment end @@ -71,7 +71,7 @@ class CommentsController < ApplicationController # Use callbacks to share common setup or constraints between actions. def set_comment - @comment = Comment.find_by(id: params[:id]) + @comment = Comment.find(params[:id]) end def comment_params_for_update diff --git a/app/controllers/community_solutions_controller.rb b/app/controllers/community_solutions_controller.rb index 07289e10..c6d95254 100644 --- a/app/controllers/community_solutions_controller.rb +++ b/app/controllers/community_solutions_controller.rb @@ -90,11 +90,11 @@ class CommunitySolutionsController < ApplicationController # Use callbacks to share common setup or constraints between actions. def set_community_solution - @community_solution = CommunitySolution.find_by(id: params[:id]) + @community_solution = CommunitySolution.find(params[:id]) end def set_community_solution_lock - @community_solution_lock = CommunitySolutionLock.find_by(id: params[:lock_id]) + @community_solution_lock = CommunitySolutionLock.find(params[:lock_id]) end def set_exercise_and_submission diff --git a/app/controllers/consumers_controller.rb b/app/controllers/consumers_controller.rb index af1072aa..2bf09d5b 100644 --- a/app/controllers/consumers_controller.rb +++ b/app/controllers/consumers_controller.rb @@ -38,7 +38,7 @@ class ConsumersController < ApplicationController end def set_consumer - @consumer = Consumer.find_by(id: params[:id]) + @consumer = Consumer.find(params[:id]) authorize! end private :set_consumer diff --git a/app/controllers/error_template_attributes_controller.rb b/app/controllers/error_template_attributes_controller.rb index 28a41e1c..3ad29480 100644 --- a/app/controllers/error_template_attributes_controller.rb +++ b/app/controllers/error_template_attributes_controller.rb @@ -86,7 +86,7 @@ class ErrorTemplateAttributesController < ApplicationController # Use callbacks to share common setup or constraints between actions. def set_error_template_attribute - @error_template_attribute = ErrorTemplateAttribute.find_by(id: params[:id]) + @error_template_attribute = ErrorTemplateAttribute.find(params[:id]) end def error_template_attribute_params diff --git a/app/controllers/error_templates_controller.rb b/app/controllers/error_templates_controller.rb index 17e7d8da..6825d3dc 100644 --- a/app/controllers/error_templates_controller.rb +++ b/app/controllers/error_templates_controller.rb @@ -77,7 +77,7 @@ class ErrorTemplatesController < ApplicationController def add_attribute authorize! - @error_template.error_template_attributes << ErrorTemplateAttribute.find_by(id: params[:error_template_attribute_id]) + @error_template.error_template_attributes << ErrorTemplateAttribute.find(params[:error_template_attribute_id]) respond_to do |format| format.html { redirect_to @error_template } format.json { head :no_content } @@ -86,7 +86,7 @@ class ErrorTemplatesController < ApplicationController def remove_attribute authorize! - @error_template.error_template_attributes.delete(ErrorTemplateAttribute.find_by(id: params[:error_template_attribute_id])) + @error_template.error_template_attributes.delete(ErrorTemplateAttribute.find(params[:error_template_attribute_id])) respond_to do |format| format.html { redirect_to @error_template } format.json { head :no_content } @@ -97,7 +97,7 @@ class ErrorTemplatesController < ApplicationController # Use callbacks to share common setup or constraints between actions. def set_error_template - @error_template = ErrorTemplate.find_by(id: params[:id]) + @error_template = ErrorTemplate.find(params[:id]) end def error_template_params diff --git a/app/controllers/execution_environments_controller.rb b/app/controllers/execution_environments_controller.rb index 75bb604a..10636a15 100644 --- a/app/controllers/execution_environments_controller.rb +++ b/app/controllers/execution_environments_controller.rb @@ -141,7 +141,7 @@ class ExecutionEnvironmentsController < ApplicationController private :set_docker_images def set_execution_environment - @execution_environment = ExecutionEnvironment.find_by(id: params[:id]) + @execution_environment = ExecutionEnvironment.find(params[:id]) authorize! end private :set_execution_environment diff --git a/app/controllers/exercise_collections_controller.rb b/app/controllers/exercise_collections_controller.rb index ce6c7882..40d49e64 100644 --- a/app/controllers/exercise_collections_controller.rb +++ b/app/controllers/exercise_collections_controller.rb @@ -41,7 +41,7 @@ class ExerciseCollectionsController < ApplicationController private def set_exercise_collection - @exercise_collection = ExerciseCollection.find_by(id: params[:id]) + @exercise_collection = ExerciseCollection.find(params[:id]) authorize! end diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index f0f07212..47fb7bed 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -40,7 +40,7 @@ class ExercisesController < ApplicationController @exercises = Exercise.all authorize! @exercises = params[:exercises].values.map do |exercise_params| - exercise = Exercise.find_by(id: exercise_params.delete(:id)) + exercise = Exercise.find(exercise_params.delete(:id)) exercise.update(exercise_params) exercise end @@ -439,7 +439,7 @@ class ExercisesController < ApplicationController private :set_execution_environments def set_exercise_and_authorize - @exercise = Exercise.find_by(id: params[:id]) + @exercise = Exercise.find(params[:id]) authorize! end @@ -447,7 +447,7 @@ class ExercisesController < ApplicationController def set_external_user_and_authorize if params[:external_user_id] - @external_user = ExternalUser.find_by(id: params[:external_user_id]) + @external_user = ExternalUser.find(params[:external_user_id]) authorize! end end diff --git a/app/controllers/external_users_controller.rb b/app/controllers/external_users_controller.rb index 65bcf4e6..95fa2634 100644 --- a/app/controllers/external_users_controller.rb +++ b/app/controllers/external_users_controller.rb @@ -15,7 +15,7 @@ class ExternalUsersController < ApplicationController end def show - @user = ExternalUser.find_by(id: params[:id]) + @user = ExternalUser.find(params[:id]) authorize! end @@ -58,7 +58,7 @@ class ExternalUsersController < ApplicationController end def statistics - @user = ExternalUser.find_by(id: params[:id]) + @user = ExternalUser.find(params[:id]) authorize! statistics = {} @@ -73,7 +73,7 @@ class ExternalUsersController < ApplicationController end def tag_statistics - @user = ExternalUser.find_by(id: params[:id]) + @user = ExternalUser.find(params[:id]) authorize! statistics = [] diff --git a/app/controllers/file_templates_controller.rb b/app/controllers/file_templates_controller.rb index 0333f23c..e8813e1c 100644 --- a/app/controllers/file_templates_controller.rb +++ b/app/controllers/file_templates_controller.rb @@ -87,7 +87,7 @@ class FileTemplatesController < ApplicationController # Use callbacks to share common setup or constraints between actions. def set_file_template - @file_template = FileTemplate.find_by(id: params[:id]) + @file_template = FileTemplate.find(params[:id]) end def file_template_params diff --git a/app/controllers/file_types_controller.rb b/app/controllers/file_types_controller.rb index 7bafd157..2f7fa37d 100644 --- a/app/controllers/file_types_controller.rb +++ b/app/controllers/file_types_controller.rb @@ -51,7 +51,7 @@ class FileTypesController < ApplicationController private :set_editor_modes def set_file_type - @file_type = FileType.find_by(id: params[:id]) + @file_type = FileType.find(params[:id]) authorize! end private :set_file_type diff --git a/app/controllers/internal_users_controller.rb b/app/controllers/internal_users_controller.rb index 94e556dc..aa528d25 100644 --- a/app/controllers/internal_users_controller.rb +++ b/app/controllers/internal_users_controller.rb @@ -127,7 +127,7 @@ class InternalUsersController < ApplicationController private :set_up_password def set_user - @user = InternalUser.find_by(id: params[:id]) + @user = InternalUser.find(params[:id]) authorize! end private :set_user diff --git a/app/controllers/proxy_exercises_controller.rb b/app/controllers/proxy_exercises_controller.rb index 930a18de..94074521 100644 --- a/app/controllers/proxy_exercises_controller.rb +++ b/app/controllers/proxy_exercises_controller.rb @@ -24,7 +24,7 @@ class ProxyExercisesController < ApplicationController def create myparams = proxy_exercise_params - myparams[:exercises] = Exercise.find_by(id: myparams[:exercise_ids].compact_blank) + myparams[:exercises] = Exercise.find(myparams[:exercise_ids].compact_blank) @proxy_exercise = ProxyExercise.new(myparams) authorize! @@ -63,7 +63,7 @@ class ProxyExercisesController < ApplicationController end def set_exercise_and_authorize - @proxy_exercise = ProxyExercise.find_by(id: params[:id]) + @proxy_exercise = ProxyExercise.find(params[:id]) authorize! end private :set_exercise_and_authorize @@ -78,7 +78,7 @@ class ProxyExercisesController < ApplicationController def update myparams = proxy_exercise_params - myparams[:exercises] = Exercise.find_by(id: myparams[:exercise_ids].compact_blank) + myparams[:exercises] = Exercise.find(myparams[:exercise_ids].compact_blank) update_and_respond(object: @proxy_exercise, params: myparams) end end diff --git a/app/controllers/request_for_comments_controller.rb b/app/controllers/request_for_comments_controller.rb index c4ef5ef3..32402f3e 100644 --- a/app/controllers/request_for_comments_controller.rb +++ b/app/controllers/request_for_comments_controller.rb @@ -58,7 +58,7 @@ class RequestForCommentsController < ApplicationController # GET /exercises/:id/request_for_comments def rfcs_for_exercise - exercise = Exercise.find_by(id: params[:exercise_id]) + exercise = Exercise.find(params[:exercise_id]) @search = RequestForComment .with_last_activity .where(exercise_id: exercise.id) @@ -141,7 +141,7 @@ class RequestForCommentsController < ApplicationController # Use callbacks to share common setup or constraints between actions. def set_request_for_comment - @request_for_comment = RequestForComment.find_by(id: params[:id]) + @request_for_comment = RequestForComment.find(params[:id]) end def request_for_comment_params @@ -154,7 +154,7 @@ class RequestForCommentsController < ApplicationController # The index page requires the grouping of the study groups # The study groups are grouped by the current study group and other study groups of the user def set_study_group_grouping - current_study_group = StudyGroup.find_by(id: session[:study_group_id]) + current_study_group = StudyGroup.find_by(session[:study_group_id]) my_study_groups = current_user.study_groups.reject {|group| group == current_study_group } @study_groups_grouping = [[t('request_for_comments.index.study_groups.current'), Array(current_study_group)], [t('request_for_comments.index.study_groups.my'), my_study_groups]] diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index ca2b084d..0bd9898d 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -42,7 +42,7 @@ class SessionsController < ApplicationController end def destroy_through_lti - @submission = Submission.find_by(id: params[:submission_id]) + @submission = Submission.find(params[:submission_id]) authorize(@submission, :show?) lti_parameter = LtiParameter.where(external_users_id: @submission.user_id, exercises_id: @submission.exercise_id).last @url = consumer_return_url(build_tool_provider(consumer: @submission.user.consumer, parameters: lti_parameter&.lti_parameters)) diff --git a/app/controllers/study_groups_controller.rb b/app/controllers/study_groups_controller.rb index 15fb5157..de84a945 100644 --- a/app/controllers/study_groups_controller.rb +++ b/app/controllers/study_groups_controller.rb @@ -23,7 +23,7 @@ class StudyGroupsController < ApplicationController def update myparams = study_group_params myparams[:external_users] = - StudyGroupMembership.find_by(id: myparams[:study_group_membership_ids].compact_blank).map(&:user) + StudyGroupMembership.find(myparams[:study_group_membership_ids].compact_blank).map(&:user) myparams.delete(:study_group_membership_ids) update_and_respond(object: @study_group, params: myparams) end @@ -38,7 +38,7 @@ class StudyGroupsController < ApplicationController private :study_group_params def set_group - @study_group = StudyGroup.find_by(id: params[:id]) + @study_group = StudyGroup.find(params[:id]) authorize! end private :set_group diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 738338cd..680af5d7 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -369,7 +369,7 @@ class SubmissionsController < ApplicationController end def set_submission - @submission = Submission.find_by(id: params[:id]) + @submission = Submission.find(params[:id]) authorize! end diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index 7cf59f9e..bff28ac4 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -22,7 +22,7 @@ class SubscriptionsController < ApplicationController # DELETE /subscriptions/1 # DELETE /subscriptions/1.json def destroy - @subscription = Subscription.find_by(id: params[:id]) + @subscription = Subscription.find(params[:id]) rescue StandardError skip_authorization respond_to do |format| @@ -47,7 +47,7 @@ class SubscriptionsController < ApplicationController end def set_subscription - @subscription = Subscription.find_by(id: params[:id]) + @subscription = Subscription.find(params[:id]) authorize! end private :set_subscription diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 91b2e9cb..6a60099b 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -38,7 +38,7 @@ class TagsController < ApplicationController end def set_tag - @tag = Tag.find_by(id: params[:id]) + @tag = Tag.find(params[:id]) authorize! end private :set_tag diff --git a/app/controllers/tips_controller.rb b/app/controllers/tips_controller.rb index 3c20f466..7d808d08 100644 --- a/app/controllers/tips_controller.rb +++ b/app/controllers/tips_controller.rb @@ -44,7 +44,7 @@ class TipsController < ApplicationController end def set_tip - @tip = Tip.find_by(id: params[:id]) + @tip = Tip.find(params[:id]) authorize! end private :set_tip diff --git a/app/controllers/user_exercise_feedbacks_controller.rb b/app/controllers/user_exercise_feedbacks_controller.rb index c17e1a26..e07b9c4a 100644 --- a/app/controllers/user_exercise_feedbacks_controller.rb +++ b/app/controllers/user_exercise_feedbacks_controller.rb @@ -25,7 +25,7 @@ class UserExerciseFeedbacksController < ApplicationController def create Sentry.set_extras(params: uef_params) - @exercise = Exercise.find_by(id: uef_params[:exercise_id]) + @exercise = Exercise.find(uef_params[:exercise_id]) rfc = RequestForComment.unsolved.where(exercise_id: @exercise.id, user_id: current_user.id).first submission = begin current_user.submissions.where(exercise_id: @exercise.id).order('created_at DESC').first @@ -67,7 +67,7 @@ class UserExerciseFeedbacksController < ApplicationController else params[:user_exercise_feedback][:exercise_id] end - @exercise = Exercise.find_by(id: exercise_id) + @exercise = Exercise.find(exercise_id) @uef = UserExerciseFeedback.find_or_initialize_by(user: current_user, exercise: @exercise) authorize! end @@ -105,7 +105,7 @@ class UserExerciseFeedbacksController < ApplicationController end def set_user_exercise_feedback - @uef = UserExerciseFeedback.find_by(id: params[:id]) + @uef = UserExerciseFeedback.find(params[:id]) @exercise = @uef.exercise end