-
Notifications
You must be signed in to change notification settings - Fork 2
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
Clot.email attchment #217
Clot.email attchment #217
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work guys! Great job with figuring out how to send attachments 🥳
|
||
private EmailAttachment() {} | ||
|
||
private static String getFileExtension(String base64Image) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ We should clean up this method so the variable names and comments better reflect what we're working with, so anybody in the future (including you!) that looks at this code can quickly and clearly understand what the method does.
For example, the variable base64Image
doesn't only contain base 64 image data - it could contain base 64 data for any kind of file now, so something more accurate (maybe base64File
?) would better communicate what's going on here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding onto that, since this method is getting a file's mime type, could we rename it so it better describe what it's doing - maybe getFileMimeType
?
//String[] data = dataSplit[1].split("/", 2); // Split the image type here (e.g. "image/png") | ||
//if (data.length != 2 || !data[0].equals("image")) { | ||
// // Ensure the encoded data is an image | ||
// return null; | ||
//} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ Remember to clean up any blocks that are commented out! If you don't need this code, make sure to delete it
|
||
try { | ||
// Temporarily writes the image to disk to decode | ||
mimeType = getFileExtension(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ It looks like getFileExtension()
could potentially return null
, but we don't ever check for that here. Once we call getFileExtension()
, we should check if its result is null (in which case we should probably throw an exception) so we deal with the failure as soon as possible, rather than have it break something else down the line.
try { | ||
// Temporarily writes the image to disk to decode | ||
mimeType = getFileExtension(data); | ||
System.out.println(mimeType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ Similar to the commented-out blocks of code - make sure to remove any prints before you merge! If you think this information is important enough to print out, we can use the SLogger.java
class for more robust logging
List<AttachmentResource> attachments = sendEmailRequest.getAttachments().stream() | ||
.map(ea -> ea.getAttachmentResource()).collect(Collectors.toList()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
@@ -660,7 +660,7 @@ private SiteEntriesRecord latestSiteEntry(int siteId) { | |||
@Override | |||
public void uploadSiteImage( | |||
JWTData userData, int siteEntryId, UploadSiteImageRequest uploadSiteImageRequest) { | |||
checkEntryExists(siteEntryId); | |||
checkSiteExists(siteEntryId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Forgot to mention (sorry for the double review 😞) - was there a reason for changing this method? IIRC site images are associated with site entries, not sites, which is why we use checkEntryExists()
rather than checkSiteExists()
…r-the-trees-backend-v2 into CLOT.emailAttchment update old branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
System.out.println(mimeType); | ||
mimeType = getFileMimeType(data); | ||
if (mimeType==null) { | ||
throw new MalformedParameterException("data"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know we had this exception, good find!
{ | ||
"systemParams": "darwin-arm64-83", | ||
"modulesFolders": [ | ||
"node_modules" | ||
], | ||
"flags": [], | ||
"linkedModules": [], | ||
"topLevelPatterns": [], | ||
"lockfileEntries": {}, | ||
"files": [], | ||
"artifacts": {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 If you'd like, you can remove this folder along with package-lock.json
and yarn.lock
- not sure how these ended up here but they shouldn't affect anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, just a couple of comments
@@ -0,0 +1,105 @@ | |||
package com.codeforcommunity.dto.emailer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the same comments as on reject email
- avoid using comments and instead focus on good names (which it looks like you have, so you can delete these)
- baseEncoding validation based on length
String filePath = "/emails/Email.html"; | ||
|
||
Map<String, String> templateValues = new HashMap<>(); | ||
templateValues.put("body", body.replaceAll("\n", "<br />")); | ||
Optional<String> emailBody = emailOperations.getTemplateString(filePath, templateValues); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super nitpicky but avoid adding extraneous spaces
Retested both emailing with attachments and rejecting images after merge |
Why
Resolves #201
This allows admins to send a lot of different types of attachments to volunteers.
This PR
Converts base64 to bytearraydata (which takes the mime type and data as byte[]) to use simplejavamail api.
Frontend devs need to convert attachment to base 64 before using route.
Verification Steps
Sent emails with jpg, docx, csv, zip, pdf