-
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.reject image #222
Clot.reject image #222
Changes from 4 commits
0afab60
f8414be
ea222e2
ba61384
10dc158
3f0d620
da5f0e7
8be0e6f
dd4f206
5583897
ebb56ba
456ee9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.codeforcommunity.dto.site; | ||
|
||
import com.codeforcommunity.dto.ApiDto; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class RejectImageRequest extends ApiDto { | ||
private String rejectionReason; | ||
|
||
public RejectImageRequest(String rejectionReason) { | ||
this.rejectionReason = rejectionReason; | ||
} | ||
|
||
private RejectImageRequest() {} | ||
|
||
public String getRejectionReason() { | ||
return rejectionReason; | ||
} | ||
|
||
public void setNewReason(String newEmail) { | ||
this.rejectionReason = rejectionReason; | ||
} | ||
|
||
@Override | ||
public List<String> validateFields(String fieldPrefix) { | ||
List<String> fields = new ArrayList<>(); | ||
return fields; | ||
} | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
|
||
import com.codeforcommunity.api.IProtectedSiteProcessor; | ||
import com.codeforcommunity.auth.JWTData; | ||
import com.codeforcommunity.dataaccess.AuthDatabaseOperations; | ||
import com.codeforcommunity.dto.site.*; | ||
import com.codeforcommunity.dto.site.AddSiteRequest; | ||
import com.codeforcommunity.dto.site.AddSitesRequest; | ||
import com.codeforcommunity.dto.site.AdoptedSitesResponse; | ||
|
@@ -43,6 +45,7 @@ | |
import com.codeforcommunity.exceptions.ResourceDoesNotExistException; | ||
import com.codeforcommunity.exceptions.WrongAdoptionStatusException; | ||
import com.codeforcommunity.logger.SLogger; | ||
import com.codeforcommunity.requester.Emailer; | ||
import com.codeforcommunity.requester.S3Requester; | ||
import com.fasterxml.jackson.databind.MappingIterator; | ||
import com.fasterxml.jackson.dataformat.csv.CsvMapper; | ||
|
@@ -52,7 +55,9 @@ | |
import java.sql.Timestamp; | ||
import java.time.LocalDate; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import org.jooq.Condition; | ||
import org.jooq.DSLContext; | ||
|
@@ -65,19 +70,21 @@ | |
import org.jooq.generated.tables.records.SitesRecord; | ||
import org.jooq.generated.tables.records.StewardshipRecord; | ||
import org.jooq.generated.tables.records.UsersRecord; | ||
import org.jooq.generated.tables.pojos.Users; | ||
|
||
public class ProtectedSiteProcessorImpl extends AbstractProcessor | ||
implements IProtectedSiteProcessor { | ||
|
||
private final DSLContext db; | ||
|
||
private final Emailer emailer; | ||
private final SLogger logger = new SLogger(ProtectedSiteProcessorImpl.class); | ||
|
||
private static final int MAX_SUBMITTED_SITE_IMAGES = 20; | ||
private static final int UPLOAD_SITE_IMAGE_SLACK_FREQ = 2; | ||
|
||
public ProtectedSiteProcessorImpl(DSLContext db) { | ||
public ProtectedSiteProcessorImpl(DSLContext db, Emailer emailer) { | ||
this.db = db; | ||
this.emailer = emailer; | ||
} | ||
|
||
/** | ||
|
@@ -663,7 +670,7 @@ private SiteEntriesRecord latestSiteEntry(int siteId) { | |
@Override | ||
public void uploadSiteImage( | ||
JWTData userData, int siteEntryId, UploadSiteImageRequest uploadSiteImageRequest) { | ||
checkSiteExists(siteEntryId); | ||
checkEntryExists(siteEntryId); | ||
checkCanUploadImage(userData); | ||
|
||
Integer maxImageId = | ||
|
@@ -915,4 +922,24 @@ public void approveSiteImage(JWTData userData, int imageID) { | |
imageRecord.setApprovalStatus(ImageApprovalStatus.APPROVED.getApprovalStatus()); | ||
imageRecord.store(); | ||
} | ||
|
||
@Override | ||
public void rejectSiteImage(JWTData userData, int imageId, RejectImageRequest rejectImageRequest) { | ||
checkImageExists(imageId); | ||
assertAdminOrSuperAdmin(userData.getPrivilegeLevel()); | ||
|
||
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()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess yes (#222 (comment)) |
||
deleteSiteImage(userData, imageId); | ||
} | ||
} |
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.
⛏️ 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