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

Clot.reject image #222

Merged
merged 12 commits into from
Mar 31, 2024
Merged

Clot.reject image #222

merged 12 commits into from
Mar 31, 2024

Conversation

CiciLing
Copy link
Contributor

@CiciLing CiciLing commented Feb 4, 2024

Why

Resolves #219

This allows the admins to send rejection email to the users who uploaded inappropriate images.

This PR

We added a new email template "RejectImageEmail.html" to be used for image rejection email.

Verification Steps

Note that it will only send email when a rejection reason is given. When a reason is not given, it will delete the user image in database by using deleteSiteImage without sending the email.

Copy link
Contributor

@huang0h huang0h left a 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 quick comments:

Comment on lines 931 to 942
if (rejectImageRequest.getRejectionReason() != null) {
int uploaderId = db.select(SITE_IMAGES.UPLOADER_ID)
.from(SITE_IMAGES)
.where(SITE_IMAGES.ID.eq(imageId))
.fetchOne(0, int.class);

UsersRecord user = db.selectFrom(USERS).where(USERS.ID.eq(uploaderId)).fetchOne();
String userEmail = user.getEmail();
String userFullName =
AuthDatabaseOperations.getFullName(user.into(Users.class));
emailer.sendRejectImageEmail(userEmail, userFullName, rejectImageRequest.getRejectionReason());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ I think we should send a rejection email regardless of if a reason was added just so to keep users updated - we could probably just add a default rejection message. Also, can we check if the reason is an empty string as well so we don't accidentally send no message?
Sorry if the API spec wasn't clear about this - that's totally my bad

</tbody>
</table>
</td>
</tr>a
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ a (can we get rid of this extra a? it shows up in the template and it looks a little weird)

image

Copy link
Contributor

@SurabhiKeesara SurabhiKeesara left a 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 few questions/clarifications

private EmailAttachment() {}

private static String getFileExtension(String base64Image) {
// Expected Base64 format: "data:image/{extension};base64,{imageData}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Just cleanup comments throughout, the code is generally understandable when there are good naming conventions

private static String getFileExtension(String base64Image) {
// Expected Base64 format: "data:image/{extension};base64,{imageData}"

if (base64Image == null || base64Image.length() < 10) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If the encoding length is 11 will it still be valid? If this is based on legacy code that's fine, just wondering if there's other ways to check image validity

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah this is based on the s3requester legacy code, unsure of the reason behind 10

try {
// Temporarily writes the image to disk to decode
mimeType = getFileExtension(data);
System.out.println(mimeType);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to print this out?

Copy link
Contributor

Choose a reason for hiding this comment

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

oops good catch

@@ -0,0 +1,392 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit long. It's good for now, since we want to send this out. Just a follow up on our conversation to create a ticket for making email customization easier down the line

String userFullName =
AuthDatabaseOperations.getFullName(user.into(Users.class));
emailer.sendRejectImageEmail(userEmail, userFullName, rejectImageRequest.getRejectionReason());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to notify people that their image was rejected/deleted even if a reason isn't provided?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess yes (#222 (comment))

@CerberusLatrans
Copy link
Contributor

Now throws error if trying to reject an approved image (should never happen).
Now deletes and sends rejection email with default message if rejectionReason is null.
Screenshot 2024-03-24 at 3 31 35 PM

Comment on lines +26 to +27
private final String subjectImageRejected =
PropertiesLoader.loadProperty("email_subject_image_rejected");
Copy link
Contributor

Choose a reason for hiding this comment

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

If we want to load the email subject this way, we'll want to add this to server.properties.example - you can simply match what we do for the other email subjects.

When the backend gets deployed to AWS, it'll copy the property name and value into the server.properties and be available here; if you're really interested you can take a look at deploy.py for more details

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the info, good catch! Ill add it

@huang0h
Copy link
Contributor

huang0h commented Mar 28, 2024

This is out of scope for this ticket, but I think it'd be a good idea to attach the image that was rejected to the email so the user knows which of their images got rejected, once we finish implementing email attachments as well - this'll probably be another ticket.

Copy link
Contributor

@huang0h huang0h left a comment

Choose a reason for hiding this comment

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

lgtm, great work here!

@CerberusLatrans CerberusLatrans merged commit df9f2b1 into master Mar 31, 2024
1 check passed
@CerberusLatrans CerberusLatrans deleted the CLOT.rejectImage branch March 31, 2024 22:58
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.

Add Reject Site Image Route
4 participants