Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and improvements for achievement notifications. #6

Conversation

drgrice1
Copy link

@drgrice1 drgrice1 commented Dec 1, 2023

The $mail{achievementEmailFrom} setting was not working because in the task it tried to use a non-existent $mail{achievementEmailSender} variable.

Make it so that achievement notifications are only sent if $mail{achievementEmailFrom} is set, and do NOT fall back to using $mail{smtpSender} or $$mail{set_return_path}. Those are not valid for this in any way.

Make the default template only remark on the number of points remaining until the next level-up if $nextLevelPoints is set. It is likely that a non-level achievement will occur before the first level achievement (for example if both of the one_click and level_one achievements are enabled, and the student gets the first question correct in one attempt) in which case the next level points has not been set yet. If that happens then the email says there are a negative number of points remaining until the next level-up.

Add a help file for the achievement notification editor page.

On the achievement list page, make the "Notifications" column say "Edit Email Template $templateName" if an email notification template is enabled for the achievement as requested by @somiaj. I would be happy with reverting this though as it can make this column rather wide.

Remove all of the radio options in the "Save As" form, and just assume it is being saved for the current achievement. I don't really see the need for any of those options.

Add the [ACHEVDIR] prefix to the "Save As" form, and add dir => 'ltr' to file names since those don't work right in right to left languages otherwise.

In the site navigation when editing an achievement evaluator, an achievement notification, or the achievement users, show sub links for all of those editors.

Change the text_field in the existing_form.html.ep to a select_field that shows all of the existing template files.

Don't use the WeBWorK::Utils::processEmailMessage method. I see no reason for that. There is not actually any merge data, so in reality this is only used to get the user's first name and potentially other information from the user record. That can be passed directly to the template and used there, so that is done instead. The default template is modified accordingly.

Lots of clean up of the AchievementNotificationEditor.pm file and the AchivievementNotification.pm file.

Instead of storing achievement email notification templates in the course templates/achievements directory directly, store them in templates/achievements/notifications subdirectory. This directory is added to the list of directories in the updateCourseDirectories method of WeBWorK::Utils::CourseIntegrityCheck that can be copied from the modelCourse. This has a couple of advantages. First, most courses will not have this directory so if the modelCourse is updated, then this directory will be copied and get the default template when the course is upgraded from the admin course. Second, it separates the achievement evaluator files from the achievement notification templates.

@drgrice1 drgrice1 force-pushed the feature/achievement-notifications-fixes branch 2 times, most recently from 8e0f591 to f3a978a Compare December 2, 2023 20:58
Copy link
Owner

@drdrew42 drdrew42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drgrice1 these are all excellent changes. I'm not sure I agree with including the template name in the table, as you mentioned, it can make the corresponding column unnecessarily wide. I don't feel super-strongly about it, so I'll go with the consensus.

@somiaj
Copy link

somiaj commented Dec 4, 2023

@drdrew42 You should probably just merge these in your branch (vs approve them).

Also don't keep the template name on my account, I use a wide screen so I saw extra space that could be used, but forgot about narrow screens. I just thought it might be useful to have a bit more info in that column, but it isn't necessary.

The `$mail{achievementEmailFrom}` setting was not working because in the
task it tried to use a non-existent `$mail{achievementEmailSender}`
variable.

Make it so that achievement notifications are only sent if
`$mail{achievementEmailFrom}` is set, and do NOT fall back to using
`$mail{smtpSender}` or `$$mail{set_return_path}`.  Those are not valid
for this in any way.

Make the default template only remark on the number of points remaining
until the next level-up if `$nextLevelPoints` is set.  It is likely that
a non-level achievement will occur before the first level achievement
(for example if both of the one_click and level_one achievements are
enabled, and the student gets the first question correct in one attempt)
in which case the next level points has not been set yet. If that
happens then the email says there are a negative number of points
remaining until the next level-up.

Add a help file for the achievement notification editor page.

On the achievement list page, make the "Notifications" column say "Edit
Email Template $templateName" if an email notification template is
enabled for the achievement as requested by @somiaj.  I would be happy
with reverting this though as it can make this column rather wide.

Remove all of the radio options in the "Save As" form, and just assume
it is being saved for the current achievement.  I don't really see the
need for any of those options.

Add the `[ACHEVDIR]` prefix to the "Save As" form, and add `dir =>
'ltr'` to file names since those don't work right in right to left
languages otherwise.

In the site navigation when editing an achievement evaluator, an
achievement notification, or the achievement users, show sub links for
all of those editors.

Change the `text_field` in the `existing_form.html.ep` to a
`select_field` that shows all of the existing template files.

Don't use the WeBWorK::Utils::processEmailMessage method.  I see no
reason for that.  There is not actually any merge data, so in reality
this is only used to get the user's first name and potentially other
information from the user record.  That can be passed directly to the
template and used there, so that is done instead.  The default template
is modified accordingly.

Lots of clean up of the AchievementNotificationEditor.pm file and the
AchivievementNotification.pm file.

Instead of storing achievement email notification templates in the
course templates/achievements directory directly, store them in
templates/achievements/notifications subdirectory.  This directory is
added to the list of directories in the `updateCourseDirectories` method
of `WeBWorK::Utils::CourseIntegrityCheck` that can be copied from the
modelCourse.  This has a couple of advantages.  First, most courses will
not have this directory so if the modelCourse is updated, then this
directory will be copied and get the default template when the course is
upgraded from the admin course.  Second, it separates the achievement
evaluator files from the achievement notification templates.
…tment.

To do so the WeBWorK::SafeTemplate module must be used.  This module
derives from the Mojo::Template module and overrides the _trap method.
The Mojo::Template _wrap method adds "use Mojo::Base -strict" and "no
warnings 'ambiguous'" to the code generated in this method.  When that
is called later it causes an error in the safe compartment because
"require" is trapped. So instead the WeBWorK::SafeTemplate override
method imports strict, warnings, and utf8 which is equivalent to calling
"use Mojo::Base -strict". Calling "no warnings 'ambiguous'" prevents
warnings from a lack of parentheses on a scalar call in the generated
code.  So if this package is used, those warnings need to be prevented
in another way.  That is done when the module is used in
Mojolicious::WeBWorK::Tasks::AchievementNotification using a
$SIG{__WARN__} handler that doesn't do anything if the ambiguous warning
is encountered.
@drgrice1 drgrice1 force-pushed the feature/achievement-notifications-fixes branch from f3a978a to 3aff69a Compare December 4, 2023 21:06
@drdrew42 drdrew42 merged commit 1a42cfb into drdrew42:feature/achievement-notifications Dec 4, 2023
1 check passed
@drgrice1 drgrice1 deleted the feature/achievement-notifications-fixes branch December 4, 2023 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants