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

Fixed the 500 when client reached the limit. #7128

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ To minimize any disruption to your ORCID integration in the future, we would rec
Warm Regards,
ORCID Support Team
https://support.orcid.org
<@emailMacros.msg "email.common.you_have_received_this_email" />

<#include "email_footer.ftl"/>
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
</p>

<p style="font-family: arial, helvetica, sans-serif;font-size: 15px;color: #494A4C;">
<@emailMacros.msg "email.common.you_have_received_this_email" />
</p>
<p style="font-family: arial, helvetica, sans-serif;font-size: 15px;color: #494A4C;">
<#include "email_footer_html.ftl"/>
</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.MessageSource;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
Expand Down Expand Up @@ -79,6 +80,9 @@ public class ApiRateLimitFilter extends OncePerRequestFilter {

@Autowired
private OrcidTokenStore orcidTokenStore;

@Autowired
private MessageSource messageSource;

@Value("${org.orcid.papi.rate.limit.anonymous.requests:10000}")
private int anonymousRequestLimit;
Expand Down Expand Up @@ -202,8 +206,10 @@ private void rateLimitClientRequest(String clientId, LocalDate today) {

private Map<String, Object> createTemplateParams(String clientId, String clientName, String emailName, String orcidId) {
Map<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("messages", messageSource);
templateParams.put("messageArgs", new Object[0]);
templateParams.put("clientId", clientId);
templateParams.put("clientId", clientName);
templateParams.put("clientName", clientName);
templateParams.put("emailName", emailName);
templateParams.put("locale", LocaleUtils.toLocale("en"));
templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
Expand All @@ -218,9 +224,9 @@ private void sendEmail(String clientId, LocalDate requestDate) {
String emailName = recordNameManager.deriveEmailFriendlyName(profile.getId());
Map<String, Object> templateParams = this.createTemplateParams(clientId, clientDetailsEntity.getClientName(), emailName, profile.getId());
// Generate body from template
String body = templateManager.processTemplate("bad_orgs_email.ftl", templateParams);
String body = templateManager.processTemplate("papi_rate_limit_email.ftl", templateParams);
// Generate html from template
String html = templateManager.processTemplate("bad_orgs_email_html.ftl", templateParams);
String html = templateManager.processTemplate("papi_rate_limit_email_html.ftl", templateParams);
String email = emailManager.findPrimaryEmail(profile.getId()).getEmail();

LOG.info("text email={}", body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public void papiDailyLimitReport() {
if (enableRateLimiting) {
LocalDate yesterday = LocalDate.now().minusDays(1);
String mode = Features.ENABLE_PAPI_RATE_LIMITING.isActive() ? "ENFORCEMENT" : "MONITORING";
String SLACK_INTRO_MSG = "Public API Rate limit report - Date: " + yesterday.toString() + "\n Current Anonymous Requests Limit: " + anonymousRequestLimit
+ "\nCurrent Public API Clients Limit: " + knownRequestLimit + "\n Mode: " + mode;
String SLACK_INTRO_MSG = "Public API Rate limit report - Date: " + yesterday.toString() + "\nCurrent Anonymous Requests Limit: " + anonymousRequestLimit
+ "\nCurrent Public API Clients Limit: " + knownRequestLimit + "\nMode: " + mode;
LOG .info(SLACK_INTRO_MSG);
slackManager.sendAlert(SLACK_INTRO_MSG, slackChannel, webhookUrl, webhookUrl);

Expand Down
Loading