From 3c880d38cc79965e12fe6e673c4914b5990930c8 Mon Sep 17 00:00:00 2001 From: amontenegro Date: Fri, 15 Dec 2023 11:29:44 -0600 Subject: [PATCH 1/3] Some more togglz --- .../core/manager/impl/WorkManagerImpl.java | 22 +++-- .../core/manager/v3/impl/WorkManagerImpl.java | 46 +++++----- .../OrcidAuthorizationCodeTokenGranter.java | 11 +-- .../openid/OpenIDConnectTokenEnhancer.java | 8 +- .../orcid/core/solr/OrcidSolrOrgsClient.java | 6 +- .../java/org/orcid/core/togglz/Features.java | 42 --------- .../orcid/core/manager/WorkManagerTest.java | 8 +- .../core/manager/v3/WorkManagerTest.java | 14 --- .../controllers/PasswordResetController.java | 85 +++++-------------- .../PasswordResetControllerTest.java | 6 -- 10 files changed, 60 insertions(+), 188 deletions(-) diff --git a/orcid-core/src/main/java/org/orcid/core/manager/impl/WorkManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/impl/WorkManagerImpl.java index 8307ab15c39..2de18c6232f 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/impl/WorkManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/impl/WorkManagerImpl.java @@ -353,19 +353,17 @@ public Work updateWork(String orcid, Work work, boolean isApiRequest) { Work workSaved = jpaJaxbWorkAdapter.toWork(workEntity); WorkForm workFormSaved = WorkForm.valueOf(workSaved, maxContributorsForUI); - if (Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED.isActive()) { - if (workFormSaved.compare(WorkForm.valueOf(work, maxContributorsForUI))) { - SourceEntity sourceEntity = sourceManager.retrieveSourceEntity(); - String client = null; - if (sourceEntity.getSourceProfile() != null && sourceEntity.getSourceProfile().getId() != null) { - client = sourceEntity.getSourceProfile().getId(); - } - if (sourceEntity.getSourceClient() != null && sourceEntity.getSourceClient().getClientName() != null) { - client = sourceEntity.getSourceClient().getClientName(); - } - LOGGER.info("There is no changes in the work with putCode " + work.getPutCode() + " send it by " + client); - return workSaved; + if (workFormSaved.compare(WorkForm.valueOf(work, maxContributorsForUI))) { + SourceEntity sourceEntity = sourceManager.retrieveSourceEntity(); + String client = null; + if (sourceEntity.getSourceProfile() != null && sourceEntity.getSourceProfile().getId() != null) { + client = sourceEntity.getSourceProfile().getId(); + } + if (sourceEntity.getSourceClient() != null && sourceEntity.getSourceClient().getClientName() != null) { + client = sourceEntity.getSourceClient().getClientName(); } + LOGGER.info("There is no changes in the work with putCode " + work.getPutCode() + " send it by " + client); + return workSaved; } String originalVisibility = workEntity.getVisibility(); diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/WorkManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/WorkManagerImpl.java index 3aacb4dbab7..aafc1f8a6c7 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/WorkManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/WorkManagerImpl.java @@ -1,5 +1,17 @@ package org.orcid.core.manager.v3.impl; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import javax.annotation.Resource; + import org.orcid.core.adapter.jsonidentifier.converter.JSONWorkExternalIdentifiersConverterV3; import org.orcid.core.adapter.v3.converter.ContributorsRolesAndSequencesConverter; import org.orcid.core.contributors.roles.works.WorkContributorRoleConverter; @@ -17,7 +29,6 @@ import org.orcid.core.manager.v3.read_only.impl.WorkManagerReadOnlyImpl; import org.orcid.core.manager.v3.validator.ActivityValidator; import org.orcid.core.manager.v3.validator.ExternalIDValidator; -import org.orcid.core.togglz.Features; import org.orcid.core.utils.DisplayIndexCalculatorHelper; import org.orcid.core.utils.SourceEntityUtils; import org.orcid.core.utils.v3.ContributorUtils; @@ -49,17 +60,6 @@ import org.springframework.context.MessageSource; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - public class WorkManagerImpl extends WorkManagerReadOnlyImpl implements WorkManager { private static final Logger LOGGER = LoggerFactory.getLogger(WorkManagerImpl.class); @@ -359,13 +359,11 @@ public Work updateWork(String orcid, Work work, boolean isApiRequest) { Work workSaved = jpaJaxbWorkAdapter.toWork(workEntity); WorkForm workFormSaved = WorkForm.valueOf(workSaved, maxContributorsForUI); - if (Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED.isActive()) { - if (workFormSaved.compare(WorkForm.valueOf(work, maxContributorsForUI))) { - LOGGER.info("There is no changes in the work with putCode " + work.getPutCode() + " send it by " + getSourceName(sourceManager.retrieveActiveSource())); - return workSaved; - } + if (workFormSaved.compare(WorkForm.valueOf(work, maxContributorsForUI))) { + LOGGER.info("There is no changes in the work with putCode " + work.getPutCode() + " send it by " + getSourceName(sourceManager.retrieveActiveSource())); + return workSaved; } - + Visibility originalVisibility = Visibility.valueOf(workEntity.getVisibility()); Source activeSource = sourceManager.retrieveActiveSource(); @@ -548,14 +546,12 @@ public Work updateWork(String orcid, WorkForm workForm) { WorkExtended workSaved = jpaJaxbWorkAdapter.toWorkExtended(workEntity); WorkForm workFormSaved = WorkForm.valueOf(workSaved, maxContributorsForUI); - - if (Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED.isActive()) { - if (workFormSaved.compare(workForm)) { - LOGGER.info("There is no changes in the work with putCode " + work.getPutCode() + " send it by " + getSourceName(sourceManager.retrieveActiveSource())); - return workSaved; - } + + if (workFormSaved.compare(workForm)) { + LOGGER.info("There is no changes in the work with putCode " + work.getPutCode() + " send it by " + getSourceName(sourceManager.retrieveActiveSource())); + return workSaved; } - + Visibility originalVisibility = Visibility.valueOf(workEntity.getVisibility()); //Save the original source diff --git a/orcid-core/src/main/java/org/orcid/core/oauth/OrcidAuthorizationCodeTokenGranter.java b/orcid-core/src/main/java/org/orcid/core/oauth/OrcidAuthorizationCodeTokenGranter.java index c5c87aea9a8..a223c68dce8 100644 --- a/orcid-core/src/main/java/org/orcid/core/oauth/OrcidAuthorizationCodeTokenGranter.java +++ b/orcid-core/src/main/java/org/orcid/core/oauth/OrcidAuthorizationCodeTokenGranter.java @@ -10,7 +10,6 @@ import org.orcid.core.constants.RevokeReason; import org.orcid.core.manager.ClientDetailsEntityCacheManager; import org.orcid.core.oauth.service.OrcidOAuth2RequestValidator; -import org.orcid.core.togglz.Features; import org.orcid.persistence.dao.OrcidOauth2AuthoriziationCodeDetailDao; import org.orcid.persistence.jpa.entities.ClientDetailsEntity; import org.orcid.persistence.jpa.entities.OrcidOauth2AuthoriziationCodeDetail; @@ -84,12 +83,10 @@ protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, Tok //Validate scopes OrcidOauth2AuthoriziationCodeDetail codeDetails = orcidOauth2AuthoriziationCodeDetailDao.find(authorizationCode); if(codeDetails == null) { - if (Features.REVOKE_TOKEN_ON_CODE_REUSE.isActive()){ - int numDisabled = orcidOauthTokenDetailService.disableAccessTokenByCodeAndClient(authorizationCode, tokenRequest.getClientId(), RevokeReason.AUTH_CODE_REUSED); - if (numDisabled >0){ - throw new InvalidGrantException("Reused authorization code: " + authorizationCode); - } - } + int numDisabled = orcidOauthTokenDetailService.disableAccessTokenByCodeAndClient(authorizationCode, tokenRequest.getClientId(), RevokeReason.AUTH_CODE_REUSED); + if (numDisabled >0){ + throw new InvalidGrantException("Reused authorization code: " + authorizationCode); + } throw new InvalidGrantException("Invalid authorization code: " + authorizationCode); } else { // Check auth code expiration diff --git a/orcid-core/src/main/java/org/orcid/core/oauth/openid/OpenIDConnectTokenEnhancer.java b/orcid-core/src/main/java/org/orcid/core/oauth/openid/OpenIDConnectTokenEnhancer.java index 2b6e0429add..3d6931442c4 100644 --- a/orcid-core/src/main/java/org/orcid/core/oauth/openid/OpenIDConnectTokenEnhancer.java +++ b/orcid-core/src/main/java/org/orcid/core/oauth/openid/OpenIDConnectTokenEnhancer.java @@ -12,7 +12,6 @@ import org.orcid.core.manager.ClientDetailsEntityCacheManager; import org.orcid.core.manager.ProfileEntityCacheManager; import org.orcid.core.manager.read_only.PersonDetailsManagerReadOnly; -import org.orcid.core.togglz.Features; import org.orcid.jaxb.model.clientgroup.ClientType; import org.orcid.jaxb.model.message.ScopePathType; import org.orcid.jaxb.model.record_v2.Person; @@ -91,12 +90,7 @@ public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentica public String buildIdToken(OAuth2AccessToken accessToken, String orcid, String clientID, String nonce) throws JOSEException { Builder claims = new JWTClaimsSet.Builder(); claims.audience(clientID); - if (Features.OPENID_SIMPLE_SUBJECT.isActive()){ - claims.subject(orcid); - }else{ - claims.subject("https://orcid.org"+"/"+orcid); - claims.claim("id_path", orcid); - } + claims.subject(orcid); claims.issuer(path); claims.claim("at_hash", createAccessTokenHash(accessToken.getValue())); diff --git a/orcid-core/src/main/java/org/orcid/core/solr/OrcidSolrOrgsClient.java b/orcid-core/src/main/java/org/orcid/core/solr/OrcidSolrOrgsClient.java index b35c09b9262..35e8244fb7c 100644 --- a/orcid-core/src/main/java/org/orcid/core/solr/OrcidSolrOrgsClient.java +++ b/orcid-core/src/main/java/org/orcid/core/solr/OrcidSolrOrgsClient.java @@ -60,10 +60,8 @@ public List getOrgs(String searchTerm, int firstRe SolrQuery query = new SolrQuery(); query.setQuery(queryString.toString()); query.addOrUpdateSort("score", ORDER.desc); - if (Features.ORG_SEARCH_SORT_BY_POPULARITY.isActive()) { - query.addOrUpdateSort("org-disambiguated-popularity", ORDER.desc); - } - + query.addOrUpdateSort("org-disambiguated-popularity", ORDER.desc); + query.addFilterQuery(String.format("(%s:(%s OR %s))", SolrConstants.ORG_DISAMBIGUATED_ID_SOURCE_TYPE, "ROR", "FUNDREF")); LOGGER.debug("SOLR Query: " + query.toQueryString()); diff --git a/orcid-core/src/main/java/org/orcid/core/togglz/Features.java b/orcid-core/src/main/java/org/orcid/core/togglz/Features.java index ec5978bcc45..b9f95f45174 100644 --- a/orcid-core/src/main/java/org/orcid/core/togglz/Features.java +++ b/orcid-core/src/main/java/org/orcid/core/togglz/Features.java @@ -21,63 +21,21 @@ public enum Features implements Feature { @Label("Redirect PUT token actions from *.pub.orcid.org to *.orcid.org") REDIRECT_PUT_TOKEN_ENDPOINT, - @Label("Stop sending notification if work has not been updated") - STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED, - @Label("Enable Crazy Egg") CRAZY_EGG, - @Label("Restrict delegator access to account settings") - RESTRICTED_DELEGATORS, - @Label("HelpHero") ORCID_ANGULAR_HELP_HERO, @Label("Disable Badges") DISABLE_BADGES, - - @Label("Spam button") - SPAM_BUTTON, - - @Label("Shows an alert message when a user goes to /signin and is already signed in\n") - RE_LOGGIN_ALERT, - - @Label("Reset password send email in all cases") - RESET_PASSWORD_EMAIL, - - @Label("Revoke access token if authorization code is reused") - REVOKE_TOKEN_ON_CODE_REUSE, - - @Label("Survey link") - SURVEY, - - @Label("Two factor authentication") - TWO_FACTOR_AUTHENTICATION, - - @Label("Self service org ids") - SELF_SERVICE_ORG_IDS, - - @Label("Remove https://orcid.org from OpenID id_tokens") - OPENID_SIMPLE_SUBJECT, @Label("Enable the API record create endpoint for QA purposes") ENABLE_RECORD_CREATE_ENDPOINT, - @Label("User OBO") - USER_OBO, - - @Label("Works failure debug") - WORKS_FAILURE_DEBUG, - - @Label("Promote a client from public client to be a member") - UPGRADE_PUBLIC_CLIENT, - @Label("Stop caching works when doing bulk reads") READ_BULK_WORKS_DIRECTLY_FROM_DB, - @Label("Organization search add sort by popularity") - ORG_SEARCH_SORT_BY_POPULARITY, - @Label("Store failing login attempts to the database") ENABLE_ACCOUNT_LOCKOUT, diff --git a/orcid-core/src/test/java/org/orcid/core/manager/WorkManagerTest.java b/orcid-core/src/test/java/org/orcid/core/manager/WorkManagerTest.java index 1ec8de10421..26189e200e3 100644 --- a/orcid-core/src/test/java/org/orcid/core/manager/WorkManagerTest.java +++ b/orcid-core/src/test/java/org/orcid/core/manager/WorkManagerTest.java @@ -53,6 +53,7 @@ import org.orcid.jaxb.model.record.summary_v2.WorkGroup; import org.orcid.jaxb.model.record.summary_v2.WorkSummary; import org.orcid.jaxb.model.record.summary_v2.Works; +import org.orcid.jaxb.model.record_v2.Citation; import org.orcid.jaxb.model.record_v2.CitationType; import org.orcid.jaxb.model.record_v2.ExternalID; import org.orcid.jaxb.model.record_v2.ExternalIDs; @@ -61,7 +62,6 @@ import org.orcid.jaxb.model.record_v2.WorkBulk; import org.orcid.jaxb.model.record_v2.WorkTitle; import org.orcid.jaxb.model.record_v2.WorkType; -import org.orcid.jaxb.model.record_v2.Citation; import org.orcid.persistence.dao.WorkDao; import org.orcid.persistence.jpa.entities.ClientDetailsEntity; import org.orcid.persistence.jpa.entities.MinimizedWorkEntity; @@ -1133,8 +1133,6 @@ public void testCompareWorksDifferentContent() { NotificationManager mockNotificationManager = Mockito.mock(NotificationManager.class); ReflectionTestUtils.setField(workManager, "notificationManager", mockNotificationManager); - togglzRule.enable(Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED); - Work work = new Work(); fillWork(work); work = workManager.createWork(claimedOrcid, work, true); @@ -1161,9 +1159,7 @@ public void testCompareWorksDifferentContent() { public void testCompareWorksSameContent() { NotificationManager mockNotificationManager = Mockito.mock(NotificationManager.class); ReflectionTestUtils.setField(workManager, "notificationManager", mockNotificationManager); - - togglzRule.enable(Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED); - + Work work = new Work(); fillWork(work); Work workSaved = workManager.createWork(claimedOrcid, work, true); diff --git a/orcid-core/src/test/java/org/orcid/core/manager/v3/WorkManagerTest.java b/orcid-core/src/test/java/org/orcid/core/manager/v3/WorkManagerTest.java index 5d13a295cc1..b51db8e789c 100644 --- a/orcid-core/src/test/java/org/orcid/core/manager/v3/WorkManagerTest.java +++ b/orcid-core/src/test/java/org/orcid/core/manager/v3/WorkManagerTest.java @@ -1716,8 +1716,6 @@ public void testCompareWorksDifferentContent() { NotificationManager mockNotificationManager = Mockito.mock(NotificationManager.class); ReflectionTestUtils.setField(workManager, "notificationManager", mockNotificationManager); - togglzRule.enable(Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED); - Work work = new Work(); fillWork(work); work = workManager.createWork(claimedOrcid, work, true); @@ -1745,8 +1743,6 @@ public void testCompareWorksSameContent() { NotificationManager mockNotificationManager = Mockito.mock(NotificationManager.class); ReflectionTestUtils.setField(workManager, "notificationManager", mockNotificationManager); - togglzRule.enable(Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED); - Work work = new Work(); fillWork(work); Work workSaved = workManager.createWork(claimedOrcid, work, true); @@ -1764,8 +1760,6 @@ public void testCompareWorksNullAndEmptyValues() { NotificationManager mockNotificationManager = Mockito.mock(NotificationManager.class); ReflectionTestUtils.setField(workManager, "notificationManager", mockNotificationManager); - togglzRule.enable(Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED); - Work work = new Work(); fillWork(work); work = workManager.createWork(claimedOrcid, work, true); @@ -1794,8 +1788,6 @@ public void testCompareWorksPublicationDate() { NotificationManager mockNotificationManager = Mockito.mock(NotificationManager.class); ReflectionTestUtils.setField(workManager, "notificationManager", mockNotificationManager); - togglzRule.enable(Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED); - Work work = new Work(); fillWork(work); work = workManager.createWork(claimedOrcid, work, true); @@ -1833,8 +1825,6 @@ public void testCompareWorksContributors() { NotificationManager mockNotificationManager = Mockito.mock(NotificationManager.class); ReflectionTestUtils.setField(workManager, "notificationManager", mockNotificationManager); - togglzRule.enable(Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED); - Work work = new Work(); fillWork(work); work = workManager.createWork(claimedOrcid, work, true); @@ -1872,8 +1862,6 @@ public void testCompareWorksContributorsGroupedByOrcidId() { NotificationManager mockNotificationManager = Mockito.mock(NotificationManager.class); ReflectionTestUtils.setField(workManager, "notificationManager", mockNotificationManager); - togglzRule.enable(Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED); - WorkForm workForm = getWorkWithContributorsMultipleRoles(); Work work = workManager.createWork(claimedOrcid, workForm); @@ -1908,8 +1896,6 @@ public void testCompareWorksExternalIdentifiers() { NotificationManager mockNotificationManager = Mockito.mock(NotificationManager.class); ReflectionTestUtils.setField(workManager, "notificationManager", mockNotificationManager); - togglzRule.enable(Features.STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED); - Work work = new Work(); fillWork(work); work = workManager.createWork(claimedOrcid, work, true); diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PasswordResetController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PasswordResetController.java index 58dd41d5e43..50cf734c34a 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PasswordResetController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PasswordResetController.java @@ -24,7 +24,6 @@ import org.orcid.core.manager.RegistrationManager; import org.orcid.core.manager.v3.ProfileEntityManager; import org.orcid.core.manager.v3.read_only.EmailManagerReadOnly; -import org.orcid.core.togglz.Features; import org.orcid.core.utils.OrcidStringUtils; import org.orcid.core.utils.PasswordResetToken; import org.orcid.frontend.email.RecordEmailSender; @@ -153,75 +152,31 @@ public class PasswordResetController extends BaseController { errors.add(getMessage("Email.resetPasswordForm.invalidEmail")); return new ResponseEntity<>(passwordResetRequest, HttpStatus.OK); } - if (Features.RESET_PASSWORD_EMAIL.isActive()) { - try { - if (emailManager.emailExists(passwordResetRequest.getEmail())) { - String orcid = emailManager.findOrcidIdByEmail(passwordResetRequest.getEmail()); - if (profileEntityManager.isDeactivated(orcid)) { - LOGGER.info("Password reset: Reactivation email sent to '{}'", passwordResetRequest.getEmail()); - recordEmailSender.sendReactivationEmail(passwordResetRequest.getEmail(), orcid); - } else if (!profileEntityManager.isProfileClaimedByEmail(passwordResetRequest.getEmail())) { - LOGGER.info("Password reset: API record creation email sent to '{}'", passwordResetRequest.getEmail()); - recordEmailSender.sendClaimReminderEmail(orcid,0,passwordResetRequest.getEmail()); - } else { - LOGGER.info("Password reset: Reset password email sent to '{}'", passwordResetRequest.getEmail()); - recordEmailSender.sendPasswordResetEmail(passwordResetRequest.getEmail(), orcid); - } - } else { - Locale locale = localeManager.getLocale(); - LOGGER.info("Password reset: Email not found email sent to '{}' with locale '{}'", passwordResetRequest.getEmail(), locale); - recordEmailSender.sendPasswordResetNotFoundEmail(passwordResetRequest.getEmail(), locale); - } - passwordResetRequest.setSuccessMessage(getMessage("orcid.frontend.reset.password.successfulReset") + " " + passwordResetRequest.getEmail()); - return new ResponseEntity<>(passwordResetRequest, HttpStatus.OK); - } catch(Exception e) { - LOGGER.error("Password reset: Unable to reset password for " + passwordResetRequest.getEmail(), e); - errors.add(getMessage("Email.resetPasswordForm.error")); - return new ResponseEntity<>(passwordResetRequest, HttpStatus.BAD_REQUEST); - } - } else { - try { + try { + if (emailManager.emailExists(passwordResetRequest.getEmail())) { String orcid = emailManager.findOrcidIdByEmail(passwordResetRequest.getEmail()); - ProfileEntity profile = profileEntityCacheManager.retrieve(orcid); - if (profile == null) { - String message = getMessage("orcid.frontend.reset.password.email_not_found_1") + " " + passwordResetRequest.getEmail() + " " - + getMessage("orcid.frontend.reset.password.email_not_found_2"); - message += ""; - message += getMessage("orcid.frontend.reset.password.email_not_found_3"); - message += ""; - message += getMessage("orcid.frontend.reset.password.email_not_found_4"); - errors.add(message); - return new ResponseEntity<>(passwordResetRequest, HttpStatus.OK); - } - - if (profile.getDeactivationDate() != null) { - /* - * String message = getMessage( - * "orcid.frontend.reset.password.disabled_account_1"); - * message += ""; message += - * getMessage( - * "orcid.frontend.reset.password.disabled_account_2"); - * message += ""; errors.add(message); - */ - errors.add(getMessage("orcid.frontend.security.orcid_deactivated")); - return new ResponseEntity<>(passwordResetRequest, HttpStatus.OK); - } - - Boolean isClaimed = profile.getClaimed(); - String toEmail = passwordResetRequest.getEmail(); - if (isClaimed == null || !isClaimed) { - LOGGER.debug("Profile is not claimed so re-sending claim email instead of password reset: {}", orcid); - recordEmailSender.sendClaimReminderEmail(orcid, 0, toEmail); + if (profileEntityManager.isDeactivated(orcid)) { + LOGGER.info("Password reset: Reactivation email sent to '{}'", passwordResetRequest.getEmail()); + recordEmailSender.sendReactivationEmail(passwordResetRequest.getEmail(), orcid); + } else if (!profileEntityManager.isProfileClaimedByEmail(passwordResetRequest.getEmail())) { + LOGGER.info("Password reset: API record creation email sent to '{}'", passwordResetRequest.getEmail()); + recordEmailSender.sendClaimReminderEmail(orcid,0,passwordResetRequest.getEmail()); } else { - recordEmailSender.sendPasswordResetEmail(toEmail, orcid); + LOGGER.info("Password reset: Reset password email sent to '{}'", passwordResetRequest.getEmail()); + recordEmailSender.sendPasswordResetEmail(passwordResetRequest.getEmail(), orcid); } - - passwordResetRequest.setSuccessMessage(getMessage("orcid.frontend.reset.password.successfulReset") + " " + passwordResetRequest.getEmail()); - } catch (NoResultException nre) { - errors.add(getMessage("Email.resetPasswordForm.error")); + } else { + Locale locale = localeManager.getLocale(); + LOGGER.info("Password reset: Email not found email sent to '{}' with locale '{}'", passwordResetRequest.getEmail(), locale); + recordEmailSender.sendPasswordResetNotFoundEmail(passwordResetRequest.getEmail(), locale); } + passwordResetRequest.setSuccessMessage(getMessage("orcid.frontend.reset.password.successfulReset") + " " + passwordResetRequest.getEmail()); return new ResponseEntity<>(passwordResetRequest, HttpStatus.OK); - } + } catch(Exception e) { + LOGGER.error("Password reset: Unable to reset password for " + passwordResetRequest.getEmail(), e); + errors.add(getMessage("Email.resetPasswordForm.error")); + return new ResponseEntity<>(passwordResetRequest, HttpStatus.BAD_REQUEST); + } } @RequestMapping(value = "/reset-password-email/{encryptedEmail}", method = RequestMethod.GET) diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PasswordResetControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PasswordResetControllerTest.java index c48dfda69a0..55c1921a171 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PasswordResetControllerTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PasswordResetControllerTest.java @@ -118,8 +118,6 @@ public void before() { @Test public void testPasswordResetUnclaimedSendEmail() throws DatatypeConfigurationException { - //TODO: remove togglzRule.enable togglz when feature is live - togglzRule.enable(Features.RESET_PASSWORD_EMAIL); String email = "email1@test.orcid.org"; String orcid = "0000-0000-0000-0000"; when(emailManager.emailExists(email)).thenReturn(true); @@ -137,8 +135,6 @@ public void testPasswordResetUnclaimedSendEmail() throws DatatypeConfigurationEx @Test public void testPasswordResetUserNotFoundSendEmail() { - //TODO: remove togglzRule.enable togglz when feature is live - togglzRule.enable(Features.RESET_PASSWORD_EMAIL); EmailRequest resetRequest = new EmailRequest(); resetRequest.setEmail("not_in_orcid@test.orcid.org"); resetRequest = passwordResetController.issuePasswordResetRequest(new MockHttpServletRequest(), resetRequest).getBody(); @@ -148,8 +144,6 @@ public void testPasswordResetUserNotFoundSendEmail() { @Test public void testPasswordResetUserDeactivatedSendEmail() throws DatatypeConfigurationException { - //TODO: remove togglzRule.enable togglz when feature is live - togglzRule.enable(Features.RESET_PASSWORD_EMAIL); String email = "email1@test.orcid.org"; String orcid = "0000-0000-0000-0000"; when(emailManager.emailExists(email)).thenReturn(true); From 12e1cd1c4125b981668e68cf6a57961dd14b70cf Mon Sep 17 00:00:00 2001 From: amontenegro Date: Mon, 18 Dec 2023 11:20:29 -0600 Subject: [PATCH 2/3] Still working on togglz cleanup --- .../manager/v3/impl/SourceManagerImpl.java | 3 +-- .../orcid/core/utils/SourceEntityUtils.java | 18 +++++++---------- .../orcid/core/utils/v3/ContributorUtils.java | 20 +++++++++---------- .../web/controllers/AdminController.java | 10 +--------- 4 files changed, 18 insertions(+), 33 deletions(-) diff --git a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/SourceManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/SourceManagerImpl.java index da9712127fe..00982b8ce83 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/SourceManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/v3/impl/SourceManagerImpl.java @@ -10,7 +10,6 @@ import org.orcid.core.manager.v3.SourceManager; import org.orcid.core.oauth.OrcidProfileUserDetails; import org.orcid.core.security.OrcidWebRole; -import org.orcid.core.togglz.Features; import org.orcid.jaxb.model.v3.release.common.Source; import org.orcid.jaxb.model.v3.release.common.SourceClientId; import org.orcid.jaxb.model.v3.release.common.SourceName; @@ -100,7 +99,7 @@ public Source retrieveActiveSource() { ClientDetailsEntity oboClientDetails = clientDetailsManager.findByClientId(tokenDetail.getOboClientDetailsId()); source.setAssertionOriginClientId(new SourceClientId(oboClientDetails.getClientId())); source.setAssertionOriginName(new SourceName(oboClientDetails.getClientName())); - } else if (tokenDetail.getOrcid() != null && clientDetails.isUserOBOEnabled() && Features.USER_OBO.isActive()) { + } else if (tokenDetail.getOrcid() != null && clientDetails.isUserOBOEnabled()) { source.setAssertionOriginOrcid(new SourceOrcid(tokenDetail.getOrcid())); source.setAssertionOriginName(new SourceName(sourceNameCacheManager.retrieve(tokenDetail.getOrcid()))); } diff --git a/orcid-core/src/main/java/org/orcid/core/utils/SourceEntityUtils.java b/orcid-core/src/main/java/org/orcid/core/utils/SourceEntityUtils.java index 799982886a9..69a93843665 100644 --- a/orcid-core/src/main/java/org/orcid/core/utils/SourceEntityUtils.java +++ b/orcid-core/src/main/java/org/orcid/core/utils/SourceEntityUtils.java @@ -7,7 +7,6 @@ import org.orcid.core.manager.SourceNameCacheManager; import org.orcid.core.manager.impl.OrcidUrlManager; import org.orcid.core.manager.v3.read_only.RecordNameManagerReadOnly; -import org.orcid.core.togglz.Features; import org.orcid.jaxb.model.v3.release.common.Source; import org.orcid.jaxb.model.v3.release.common.SourceClientId; import org.orcid.jaxb.model.v3.release.common.SourceName; @@ -104,17 +103,14 @@ public static Source extractSourceFromEntity(SourceAwareEntity e, ClientDetai // client if (!StringUtils.isEmpty(e.getClientSourceId())) { source.setSourceClientId(new SourceClientId(e.getClientSourceId())); - - if (Features.USER_OBO.isActive() && e instanceof OrcidAware) { - ClientDetailsEntity clientSource = clientDetailsEntityCacheManager.retrieve(e.getClientSourceId()); - if (clientSource.isUserOBOEnabled()) { - String orcidId = null; - if (e instanceof OrcidAware) { - orcidId = ((OrcidAware) e).getOrcid(); - } - source.setAssertionOriginOrcid(new SourceOrcid(orcidId)); + ClientDetailsEntity clientSource = clientDetailsEntityCacheManager.retrieve(e.getClientSourceId()); + if (clientSource.isUserOBOEnabled()) { + String orcidId = null; + if (e instanceof OrcidAware) { + orcidId = ((OrcidAware) e).getOrcid(); } - } + source.setAssertionOriginOrcid(new SourceOrcid(orcidId)); + } } // member obo diff --git a/orcid-core/src/main/java/org/orcid/core/utils/v3/ContributorUtils.java b/orcid-core/src/main/java/org/orcid/core/utils/v3/ContributorUtils.java index b463e8da820..e1160f04ffc 100644 --- a/orcid-core/src/main/java/org/orcid/core/utils/v3/ContributorUtils.java +++ b/orcid-core/src/main/java/org/orcid/core/utils/v3/ContributorUtils.java @@ -375,19 +375,17 @@ public String getCreditRole(String contributorRole) { public String getAssertionOriginOrcid(String clientSourceId, String orcid, Long putCode, ClientDetailsEntityCacheManager clientDetailsEntityCacheManager, WorkDao workDao) { String assertionOriginOrcid = null; - if (Features.USER_OBO.isActive()) { - ClientDetailsEntity clientSource = clientDetailsEntityCacheManager.retrieve(clientSourceId); - if (clientSource.isUserOBOEnabled()) { - WorkEntity e = workDao.getWork(orcid, putCode); - - String orcidId = null; - if (e instanceof OrcidAware) { - orcidId = ((OrcidAware) e).getOrcid(); - } - assertionOriginOrcid = orcidId; + ClientDetailsEntity clientSource = clientDetailsEntityCacheManager.retrieve(clientSourceId); + if (clientSource.isUserOBOEnabled()) { + WorkEntity e = workDao.getWork(orcid, putCode); + + String orcidId = null; + if (e instanceof OrcidAware) { + orcidId = ((OrcidAware) e).getOrcid(); } + assertionOriginOrcid = orcidId; } - + return assertionOriginOrcid; } diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/AdminController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/AdminController.java index 989c9a90445..37c59ee65f9 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/AdminController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/AdminController.java @@ -24,7 +24,6 @@ import org.orcid.core.manager.v3.ProfileEntityManager; import org.orcid.core.manager.v3.SpamManager; import org.orcid.core.manager.v3.read_only.RecordNameManagerReadOnly; -import org.orcid.core.togglz.Features; import org.orcid.core.utils.OrcidStringUtils; import org.orcid.frontend.email.RecordEmailSender; import org.orcid.frontend.web.util.PasswordConstants; @@ -1061,9 +1060,6 @@ private String getOrcidFromParam(String orcidOrEmail) { @RequestMapping(value = "/validate-client-conversion.json", method = RequestMethod.POST) public @ResponseBody ConvertClient validateClientConversion(HttpServletRequest serverRequest, HttpServletResponse response, @RequestBody ConvertClient data) throws IllegalAccessException { - if (!Features.UPGRADE_PUBLIC_CLIENT.isActive()) { - throw new IllegalAccessException("Feature UPGRADE_PUBLIC_CLIENT is disabled"); - } data.setGroupIdNotFound(false); data.setGroupIdDeactivated(false); data.setClientNotFound(false); @@ -1118,11 +1114,7 @@ private String getOrcidFromParam(String orcidOrEmail) { @RequestMapping(value = "/convert-client.json", method = RequestMethod.POST) public @ResponseBody ConvertClient convertClient(HttpServletRequest serverRequest, HttpServletResponse response, @RequestBody ConvertClient data) - throws IllegalAccessException { - if (!Features.UPGRADE_PUBLIC_CLIENT.isActive()) { - throw new IllegalAccessException("Feature UPGRADE_PUBLIC_CLIENT is disabled"); - } - + throws IllegalAccessException { isAdmin(serverRequest, response); data = validateClientConversion(serverRequest, response, data); if (data.isClientNotFound() || data.isAlreadyMember() || data.isGroupIdNotFound()) { From 2a256785886b87840c46df731a302816ddbe2d03 Mon Sep 17 00:00:00 2001 From: amontenegro Date: Tue, 19 Dec 2023 13:28:04 -0600 Subject: [PATCH 3/3] Disable badges --- .../java/org/orcid/core/togglz/Features.java | 5 +- .../member-details-ng2-template.ftl | 231 ++++++------------ .../membersList/memberDetails.component.ts | 4 +- 3 files changed, 71 insertions(+), 169 deletions(-) diff --git a/orcid-core/src/main/java/org/orcid/core/togglz/Features.java b/orcid-core/src/main/java/org/orcid/core/togglz/Features.java index b9f95f45174..2bc5a0fe797 100644 --- a/orcid-core/src/main/java/org/orcid/core/togglz/Features.java +++ b/orcid-core/src/main/java/org/orcid/core/togglz/Features.java @@ -25,10 +25,7 @@ public enum Features implements Feature { CRAZY_EGG, @Label("HelpHero") - ORCID_ANGULAR_HELP_HERO, - - @Label("Disable Badges") - DISABLE_BADGES, + ORCID_ANGULAR_HELP_HERO, @Label("Enable the API record create endpoint for QA purposes") ENABLE_RECORD_CREATE_ENDPOINT, diff --git a/orcid-web/src/main/resources/freemarker/includes/ng2_templates/member-details-ng2-template.ftl b/orcid-web/src/main/resources/freemarker/includes/ng2_templates/member-details-ng2-template.ftl index c73cd22c4d3..1474a0bb60d 100644 --- a/orcid-web/src/main/resources/freemarker/includes/ng2_templates/member-details-ng2-template.ftl +++ b/orcid-web/src/main/resources/freemarker/includes/ng2_templates/member-details-ng2-template.ftl @@ -1,166 +1,73 @@ \ No newline at end of file diff --git a/orcid-web/src/main/webapp/static/javascript/ng1Orcid/app/modules/membersList/memberDetails.component.ts b/orcid-web/src/main/webapp/static/javascript/ng1Orcid/app/modules/membersList/memberDetails.component.ts index b8f506d4dde..55961bf92ca 100644 --- a/orcid-web/src/main/webapp/static/javascript/ng1Orcid/app/modules/membersList/memberDetails.component.ts +++ b/orcid-web/src/main/webapp/static/javascript/ng1Orcid/app/modules/membersList/memberDetails.component.ts @@ -29,8 +29,7 @@ export class MemberDetailsComponent { currentMemberDetails: any = null; badgesAwarded: any = {} assetsPath: String; - badgesDisabled: boolean; - + constructor( protected commonSrvc: CommonService, protected membersListService: MembersListService, @@ -97,7 +96,6 @@ export class MemberDetailsComponent { } ngOnInit(): void { - this.badgesDisabled = this.featuresService.isFeatureEnabled('DISABLE_BADGES'); this.getCommunityTypes(); this.getCurrentMemberDetails(); }