@@ -18,24 +18,26 @@ def reset_password_email(user)
1818 mail ( subject : t ( 'mailers.user_mailer.reset_password.subject' ) , to : user . email )
1919 end
2020
21- def got_new_comment ( comment , request_for_comment , commenting_user )
21+ def got_new_comment
2222 # TODO: check whether we can take the last known locale of the receiver?
23+ request_for_comment = params . fetch ( :request_for_comment )
2324 token = AuthenticationToken . generate! ( request_for_comment . user , request_for_comment . submission . study_group )
2425 @receiver_displayname = request_for_comment . user . displayname
25- @commenting_user_displayname = commenting_user . displayname
26- @comment_text = ERB ::Util . html_escape comment . text
26+ @commenting_user_displayname = params . fetch ( : commenting_user) . displayname
27+ @comment_text = ERB ::Util . html_escape params . fetch ( : comment) . text
2728 @rfc_link = request_for_comment_url ( request_for_comment , token : token . shared_secret )
2829 mail (
2930 subject : t ( 'mailers.user_mailer.got_new_comment.subject' ,
3031 commenting_user_displayname : @commenting_user_displayname ) , to : request_for_comment . user . email
3132 )
3233 end
3334
34- def got_new_comment_for_subscription ( comment , subscription , from_user )
35+ def got_new_comment_for_subscription
36+ subscription = params . fetch ( :subscription )
3537 token = AuthenticationToken . generate! ( subscription . user , subscription . study_group )
3638 @receiver_displayname = subscription . user . displayname
37- @author_displayname = from_user . displayname
38- @comment_text = ERB ::Util . html_escape comment . text
39+ @author_displayname = params . fetch ( : from_user) . displayname
40+ @comment_text = ERB ::Util . html_escape params . fetch ( : comment) . text
3941 @rfc_link = request_for_comment_url ( subscription . request_for_comment , token : token . shared_secret )
4042 @unsubscribe_link = unsubscribe_subscription_url ( subscription )
4143 mail (
@@ -44,22 +46,28 @@ def got_new_comment_for_subscription(comment, subscription, from_user)
4446 )
4547 end
4648
47- def send_thank_you_note ( request_for_comment , receiver )
49+ def send_thank_you_note
50+ request_for_comment = params . fetch ( :request_for_comment )
51+ receiver = params . fetch ( :receiver )
4852 token = AuthenticationToken . generate! ( receiver , request_for_comment . submission . study_group )
53+
4954 @receiver_displayname = receiver . displayname
5055 @author = request_for_comment . user . displayname
5156 @thank_you_note = ERB ::Util . html_escape request_for_comment . thank_you_note
5257 @rfc_link = request_for_comment_url ( request_for_comment , token : token . shared_secret )
5358 mail ( subject : t ( 'mailers.user_mailer.send_thank_you_note.subject' , author : @author ) , to : receiver . email )
5459 end
5560
56- def exercise_anomaly_detected ( exercise_collection , anomalies )
61+ def exercise_anomaly_detected
5762 # First, we try to find the best matching study group for the user being notified.
5863 # The study group is relevant, since it determines the access rights to the exercise within the collection.
5964 # The best matching study group is the one that grants access to the most exercises in the collection.
6065 # This approach might look complicated, but since it is called from a Rake task and no active user session, we need it.
61- @relevant_exercises = Exercise . where ( id : anomalies . keys )
62- potential_study_groups = exercise_collection . user . study_groups . where ( study_group_memberships : { role : StudyGroupMembership . roles [ :teacher ] } )
66+ @collection = params . fetch ( :exercise_collection )
67+ @anomalies = params . fetch ( :anomalies )
68+ @relevant_exercises = Exercise . where ( id : @anomalies . keys )
69+
70+ potential_study_groups = @collection . user . study_groups . where ( study_group_memberships : { role : StudyGroupMembership . roles [ :teacher ] } )
6371 potential_study_groups_with_expected_access = potential_study_groups . to_h do |study_group |
6472 exercises_granting_access = @relevant_exercises . count do |exercise |
6573 author_study_groups = exercise . author . study_groups . where ( study_group_memberships : { role : StudyGroupMembership . roles [ :teacher ] } )
@@ -70,18 +78,17 @@ def exercise_anomaly_detected(exercise_collection, anomalies)
7078 best_matching_study_group = potential_study_groups_with_expected_access . max_by { |_study_group , exercises_granting_access | exercises_granting_access } . first
7179
7280 # Second, all relevant values are passed to the view
73- @user = exercise_collection . user
81+ @user = @collection . user
7482 @receiver_displayname = @user . displayname
7583 @token = AuthenticationToken . generate! ( @user , best_matching_study_group ) . shared_secret
76- @collection = exercise_collection
77- @anomalies = anomalies
78- mail ( subject : t ( 'mailers.user_mailer.exercise_anomaly_detected.subject' ) , to : exercise_collection . user . email )
84+ mail ( subject : t ( 'mailers.user_mailer.exercise_anomaly_detected.subject' ) , to : @user . email )
7985 end
8086
81- def exercise_anomaly_needs_feedback ( user , exercise , link )
87+ def exercise_anomaly_needs_feedback
88+ user = params . fetch ( :user )
8289 @receiver_displayname = user . displayname
83- @exercise_title = exercise . title
84- @link = link
90+ @exercise_title = params . fetch ( : exercise) . title
91+ @link = params . fetch ( : link)
8592 mail ( subject : t ( 'mailers.user_mailer.exercise_anomaly_needs_feedback.subject' ) , to : user . email )
8693 end
8794end
0 commit comments