Skip to content

Commit

Permalink
Merge pull request #6811 from ORCID/8654-improvements-to-spam-detecti…
Browse files Browse the repository at this point in the history
…on_access_token

check if the profile has an auth token
  • Loading branch information
amontenegro authored Jun 8, 2023
2 parents 9595d8f + 653002c commit e516f6d
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.orcid.core.togglz.OrcidTogglzConfiguration;
import org.orcid.core.utils.OrcidStringUtils;
import org.orcid.frontend.email.RecordEmailSender;
import org.orcid.persistence.dao.OrcidOauth2TokenDetailDao;
import org.orcid.persistence.jpa.entities.ProfileEntity;
import org.orcid.pojo.ajaxForm.PojoUtil;
import org.slf4j.Logger;
Expand All @@ -44,6 +45,9 @@ public class AutoLockSpamRecords {

@Resource(name = "notificationManagerV3")
private NotificationManager notificationManager;

@Resource
private OrcidOauth2TokenDetailDao orcidOauthDao;

private static int ONE_DAY = 86400000;

Expand Down Expand Up @@ -93,8 +97,9 @@ private void autolockRecords(List<String> toLock) {
LOG.info("Processing orcidId: " + orcidId);
if(OrcidStringUtils.isValidOrcid(orcidId)) {
ProfileEntity profileEntity = profileEntityManager.findByOrcid(orcidId);
//only lock account was not reviewed and not already locked
if(!profileEntity.isReviewed() && profileEntity.isAccountNonLocked()) {
//only lock account was not reviewed and not already locked and not have an auth token

if(!profileEntity.isReviewed() && profileEntity.isAccountNonLocked() && !orcidOauthDao.hasToken(orcidId)) {
boolean wasLocked = profileEntityManager.lockProfile(orcidId, LockReason.SPAM_AUTO.getLabel(), "ML Detected", "");
if(wasLocked) {
recordEmailSender.sendOrcidLockedEmail(orcidId);
Expand All @@ -120,6 +125,7 @@ private void init() {
profileEntityCacheManager = (ProfileEntityCacheManager) context.getBean("profileEntityCacheManager");
notificationManager = (NotificationManager) context.getBean("notificationManagerV3");
recordEmailSender = (RecordEmailSender) context.getBean("recordEmailSender");
orcidOauthDao = (OrcidOauth2TokenDetailDao) context.getBean("orcidOauth2TokenDetailDao");
bootstrapTogglz(context.getBean(OrcidTogglzConfiguration.class));
}

Expand Down

0 comments on commit e516f6d

Please sign in to comment.