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

SHARE-533 Email templates & preview #3779

Merged
merged 11 commits into from
Jun 9, 2023
Merged

Conversation

EifonUser
Copy link
Contributor


Your checklist for this pull request

Please review the contributing guidelines and wiki pages of this repository.

  • Include the name and id of the Jira ticket in the PR’s title eg.: SHARE-666 The devils ticket
  • Choose the proper base branch (develop)
  • Confirm that the changes follow the project’s coding guidelines
  • Verify that the changes generate no warnings and errors
  • Verify to commit no other files than the intentionally changed ones
  • Include reasonable and readable tests verifying the added or changed behavior
  • Verify that all tests are passing (CI), if not please state the test cases in the section below
  • Perform a self-review of the changes
  • Stick to the project’s git workflow (rebase and squash your commits)
  • Verify that your changes do not have any conflicts with the base branch
  • Put your ticket into the Code Review section in Jira
  • Post a message in the #catroweb Slack channel and ask for a code reviewer
  • Check that your pull request has been successfully deployed to https://web-test-1.catrob.at/

Additional Description

TODO: Add additional information that is not in your commit-message here

Tests - additional information

TODO: add additional information about testruns here

@codecov
Copy link

codecov bot commented Feb 26, 2023

Codecov Report

Merging #3779 (1744d5b) into develop (010b15c) will increase coverage by 19.03%.
The diff coverage is 1.66%.

@@              Coverage Diff               @@
##             develop    #3779       +/-   ##
==============================================
+ Coverage      30.85%   49.89%   +19.03%     
- Complexity      5713     5730       +17     
==============================================
  Files            654      654               
  Lines          20474    20530       +56     
==============================================
+ Hits            6318    10243     +3925     
+ Misses         14156    10287     -3869     
Flag Coverage Δ
behat 47.73% <1.66%> (+19.96%) ⬆️
phpunit 8.68% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
.../Tools/SendMailToUser/SendMailToUserController.php 0.00% <0.00%> (ø)
...m/Testing/Behat/Context/CatrowebBrowserContext.php 21.84% <0.00%> (+16.06%) ⬆️
...Admin/Tools/SendMailToUser/SendMailToUserAdmin.php 100.00% <100.00%> (ø)

... and 232 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@dmetzner dmetzner left a comment

Choose a reason for hiding this comment

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

What I have noticed during testing

  • in the case of the preview - the user name should be optional

All in all the feature looks good :)

@@ -2,14 +2,15 @@

// eslint-disable-next-line no-unused-vars
function AdminMail () {
$('.btn').click(function () {
$('.btn-send').click(function () {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be great to refactor this code without jquery, since it is already touched in this MR - (should be do-able by chatgpt in a few seconds ;)

Comment on lines 59 to 80
$resetToken = $this->resetPasswordHelper->generateFakeResetToken();

$signature = 'https:://example.url';

$template = (string) $request->query->get('template');

$user = $this->user_manager->findUserByUsername((string) $request->query->get('username'));
if (!$user) {
return new Response('User does not exist');
}

$subject = (string) $request->query->get('subject');
if ('' === $subject && '2' === $template) {
return new Response('Empty subject!');
}

$titel = (string) $request->query->get('titel');

$messageText = (string) $request->query->get('message');
if ('' === $messageText && '2' === $template) {
return new Response('Empty message!');
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

would be nice to execute each snippet only if it is necessary - think of this previewAction as delegator

switch $template:
case A: load fake data for A - render
case B: load fake data for B - render

Feel free to create multiple classes or at least methods in a way that each class/method only has one job

Comment on lines 113 to 115
<option value="0">Confirmation Email</option>
<option value="1">Reset Email</option>
<option value="2">Simple Message</option>
Copy link
Collaborator

Choose a reason for hiding this comment

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

using names instead of numbers makes the code more readable

Suggested change
<option value="0">Confirmation Email</option>
<option value="1">Reset Email</option>
<option value="2">Simple Message</option>
<option value="confirmation">Confirmation Email</option>
<option value="reset">Reset Email</option>
<option value="basic">Simple Message</option>

@dmetzner dmetzner marked this pull request as draft March 3, 2023 10:40
@EifonUser EifonUser marked this pull request as ready for review April 19, 2023 19:00
const subject = subjectInput.value
const titel = titelInput.value
const message = messageInput.value
const url = `send?username=${username}&subject=${subject}&titel=${titel}&message=${message}`
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will break on specific inputs. For example, let's consider you have the following example:

username = "user1"
subject = "Password Reset"
title = "...
....

Then you will get the following URL:

URL = "send?username=user1&subject=Password Reset&title=...

Since the parameters are not url-encoded, characters such as the space character will break your URL resulting into just fetching "send?username=user1&subject=Password"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

window.open() encodes the url parameter by itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you want i could also use a json body to pass the parameters. I guess this would be more convenient

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still an issue? I didnt see any problem during testing, is it resolved @dmetzner ?

}
})
.then(data => {
if (data && data.length >= 2 && data.substring(0, 2) === 'OK') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

you should just check if the status code is 200, not check for the message content

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The status code gets already checked above. If you dont like this code i can come up with a new structure that does the same.

return $this->renderBasic($request);
}

return new Response('404');
Copy link
Collaborator

Choose a reason for hiding this comment

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

The second param is the status code:

return new Response('Not Found', Response::HTTP_NOT_FOUND);

{
$user = $this->user_manager->findUserByUsername((string) $request->query->get('username'));
if (!$user) {
return new Response('User does not exist');
Copy link
Collaborator

Choose a reason for hiding this comment

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

404


$subject = (string) $request->query->get('subject');
if ('' === $subject) {
return new Response('Empty subject!');
Copy link
Collaborator

Choose a reason for hiding this comment

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

422 or 400


$messageText = (string) $request->query->get('message');
if ('' === $messageText) {
return new Response('Empty message!');
Copy link
Collaborator

Choose a reason for hiding this comment

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

422 or 400

const titel = titelInput.value
const message = messageInput.value
const template = templateSelect.value
const url = `preview?username=${username}&subject=${subject}&titel=${titel}&message=${message}&template=${template}`
Copy link
Collaborator

Choose a reason for hiding this comment

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

same url encoding issue

@dmetzner dmetzner marked this pull request as draft April 21, 2023 05:15
@EifonUser EifonUser marked this pull request as ready for review April 28, 2023 12:57
@hungryapeman
Copy link
Contributor

In the reset password preview, you can see the translation is not correct for "hour" its "Stunde", but not sure if that belongs in this PR:
image

@hungryapeman
Copy link
Contributor

Would it make sense to disable certain fields in the reset and confirmation mail form like Content and Subject/Title, as they arent used in those to mails right?

@EifonUser
Copy link
Contributor Author

This PR is more like a setup for SHARE-525 New E-Mail design.
If we would disable the unused preview fields, we would block the current "Send" option, which requires them.
For some reason, the string resetPassword.email.visitLink, is not translated in the crowdin_DE file on my branch. The translation for "hour" is present. On the current dev branch, the string is translated so it should not be an issue.
We could think of a solution, where there is either everything, or nothing translated. Anyways, this issue is not related to the preview, but to the current email template.

@hungryapeman
Copy link
Contributor

This PR is more like a setup for SHARE-525 New E-Mail design. If we would disable the unused preview fields, we would block the current "Send" option, which requires them. For some reason, the string resetPassword.email.visitLink, is not translated in the crowdin_DE file on my branch. The translation for "hour" is present. On the current dev branch, the string is translated so it should not be an issue. We could think of a solution, where there is either everything, or nothing translated. Anyways, this issue is not related to the preview, but to the current email template.

Ah ok, then it looks fine for me! :)

@dmetzner dmetzner self-requested a review June 9, 2023 07:28
@dmetzner dmetzner merged commit 7e360b2 into Catrobat:develop Jun 9, 2023
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