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

Subdomain changes #7150

Merged
merged 12 commits into from
Dec 13, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public Response viewRecord(String orcid) {
Record record = recordManagerReadOnly.getRecord(orcid);
orcidSecurityManager.checkAndFilter(orcid, record);
if (record.getPerson() != null) {
emailDomainManager.processProfessionalEmailsForV2API(record.getPerson().getEmails());
sourceUtils.setSourceName(record.getPerson());
}
if (record.getActivitiesSummary() != null) {
Expand Down Expand Up @@ -797,8 +798,7 @@ public Response viewEmails(String orcid) {
orcidSecurityManager.checkAndFilter(orcid, emails.getEmails(), ScopePathType.ORCID_BIO_READ_LIMITED);
}

processProfessionalEmails(emails);

emailDomainManager.processProfessionalEmailsForV2API(emails);
ElementUtils.setPathToEmail(emails, orcid);
Api2_0_LastModifiedDatesHelper.calculateLastModified(emails);
sourceUtils.setSourceName(emails);
Expand Down Expand Up @@ -1066,6 +1066,7 @@ public Response viewPersonalDetails(String orcid) {
public Response viewPerson(String orcid) {
Person person = personDetailsManagerReadOnly.getPersonDetails(orcid);
orcidSecurityManager.checkAndFilter(orcid, person);
emailDomainManager.processProfessionalEmailsForV2API(person.getEmails());
ElementUtils.setPathToPerson(person, orcid);
Api2_0_LastModifiedDatesHelper.calculateLastModified(person);
sourceUtils.setSourceName(person);
Expand Down Expand Up @@ -1113,22 +1114,6 @@ private void validateSearchParams(Map<String, List<String>> queryMap) {
}
}

private void processProfessionalEmails(Emails emails) {
for (Email email : emails.getEmails()) {
if (email.isVerified()) {
String domain = email.getEmail().split("@")[1];
EmailDomainEntity domainInfo = emailDomainManager.findByEmailDomain(domain);
// Set appropriate source name and source id for professional emails
if (domainInfo != null && domainInfo.getCategory().equals(EmailDomainEntity.DomainCategory.PROFESSIONAL)) {
if(email.getSource() == null) {
email.setSource(new Source());
}
email.setSource(sourceEntityUtils.convertEmailSourceToOrcidValidator(email.getSource()));
}
}
}
}

@Override
public Response viewClient(String clientId) {
orcidSecurityManager.checkScopes(ScopePathType.READ_PUBLIC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ public Response viewRecord(String orcid) {
Record record = recordManagerReadOnly.getRecord(orcid, filterVersionOfIdentifiers);
orcidSecurityManager.checkAndFilter(orcid, record);
if (record.getPerson() != null) {
emailDomainManager.processProfessionalEmailsForV3API(record.getPerson().getEmails());
sourceUtils.setSourceName(record.getPerson());
}
if (record.getActivitiesSummary() != null) {
Expand Down Expand Up @@ -885,7 +886,7 @@ public Response viewEmails(String orcid) {
orcidSecurityManager.checkAndFilter(orcid, emails.getEmails(), ScopePathType.ORCID_BIO_READ_LIMITED);
}

processProfessionalEmails(emails);
emailDomainManager.processProfessionalEmailsForV3API(emails);

ElementUtils.setPathToEmail(emails, orcid);
Api3_0LastModifiedDatesHelper.calculateLastModified(emails);
Expand Down Expand Up @@ -1165,6 +1166,7 @@ public Response viewPerson(String orcid) {
checkProfileStatus(orcid, true);
Person person = personDetailsManagerReadOnly.getPersonDetails(orcid, false);
orcidSecurityManager.checkAndFilter(orcid, person);
emailDomainManager.processProfessionalEmailsForV3API(person.getEmails());
ElementUtils.setPathToPerson(person, orcid);
Api3_0LastModifiedDatesHelper.calculateLastModified(person);
sourceUtils.setSourceName(person);
Expand Down Expand Up @@ -1227,19 +1229,6 @@ private void validateSearchParams(Map<String, List<String>> queryMap) {
}
}

private void processProfessionalEmails(Emails emails) {
for (Email email : emails.getEmails()) {
if (email.isVerified()) {
String domain = email.getEmail().split("@")[1];
EmailDomainEntity domainInfo = emailDomainManager.findByEmailDomain(domain);
// Set appropriate source name and source id for professional emails
if (domainInfo != null && domainInfo.getCategory().equals(EmailDomainEntity.DomainCategory.PROFESSIONAL)) {
email.setSource(sourceEntityUtils.convertEmailSourceToOrcidValidator(email.getSource()));
}
}
}
}

@Override
public Response viewClient(String clientId) {
orcidSecurityManager.checkScopes(ScopePathType.READ_PUBLIC);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package org.orcid.api.memberV2.server.delegator;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -39,6 +35,8 @@
import org.orcid.test.helper.Utils;
import org.springframework.test.context.ContextConfiguration;

import static org.junit.Assert.*;

@RunWith(OrcidJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:test-orcid-api-web-context.xml" })
public class MemberV2ApiServiceDelegator_EmailsTest extends DBUnitTest {
Expand Down Expand Up @@ -69,13 +67,51 @@ public void testViewEmailsWrongToken() {
}

@Test
public void testViewEmailsReadPublic() {
public void testViewEmailsReadPublic_withSourceClient() {
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_PUBLIC);
Response r = serviceDelegator.viewEmails(ORCID);
Emails element = (Emails) r.getEntity();
assertNotNull(element);
assertEquals("/0000-0000-0000-0003/email", element.getPath());
Utils.assertIsPublicOrSource(element, "APP-5555555555555555");
assertEquals(4, element.getEmails().size());

List<String> emails = new ArrayList<>();
emails.add("[email protected]");
emails.add("[email protected]");
emails.add("[email protected]");
emails.add("[email protected]");

for(Email e : element.getEmails()) {
if(!emails.contains(e.getEmail())) {
fail(e.getEmail() + " is not in the email list");
}
emails.remove(e.getEmail());
}

assertTrue(emails.isEmpty());
}

@Test
public void testViewEmailsReadPublic_withOtherClient() {
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555556", ScopePathType.READ_PUBLIC);
Response r = serviceDelegator.viewEmails(ORCID);
Emails element = (Emails) r.getEntity();
assertNotNull(element);
assertEquals("/0000-0000-0000-0003/email", element.getPath());
assertEquals(2, element.getEmails().size());

List<String> emails = new ArrayList<>();
emails.add("[email protected]");
emails.add("[email protected]");

for(Email e : element.getEmails()) {
if(!emails.contains(e.getEmail())) {
fail(e.getEmail() + " is not in the email list");
}
emails.remove(e.getEmail());
}

assertTrue(emails.isEmpty());
}

@Test
Expand Down Expand Up @@ -154,4 +190,32 @@ public void testViewEmails() {
assertEquals(true, email.isVerified());
assertEquals(false, email.isPrimary());
}

@Test
public void checkSourceOnEmail_EmailEndpointTest() {
String orcid = "0000-0000-0000-0001";
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_LIMITED);
Response r = serviceDelegator.viewEmails(orcid);
Emails emails = (Emails) r.getEntity();
checkEmails(emails);
}

private void checkEmails(Emails emails) {
assertEquals(2, emails.getEmails().size());
for(Email e : emails.getEmails()) {
if(e.getEmail().equals("[email protected]")) {
assertTrue(e.isVerified());
// The source and name on verified professional email addresses should change
assertEquals("0000-0000-0000-0000", e.getSource().retrieveSourcePath());
assertEquals("ORCID email validation", e.getSource().getSourceName().getContent());
} else if(e.getEmail().equals("[email protected]")) {
assertTrue(e.isVerified());
// The source and name on non professional email addresses should not change
assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath());
assertEquals("Source Client 1", e.getSource().getSourceName().getContent());
} else {
fail("Unexpected email " + e.getEmail());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package org.orcid.api.memberV2.server.delegator;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -46,6 +42,8 @@
import org.orcid.test.helper.Utils;
import org.springframework.test.context.ContextConfiguration;

import static org.junit.Assert.*;

@RunWith(OrcidJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:test-orcid-api-web-context.xml" })
public class MemberV2ApiServiceDelegator_ReadPersonTest extends DBUnitTest {
Expand Down Expand Up @@ -84,6 +82,22 @@ public void testViewPersonReadPublic() {
assertNotNull(element);
assertEquals("/0000-0000-0000-0003/person", element.getPath());
Utils.assertIsPublicOrSource(element, "APP-5555555555555555");
assertNotNull(element.getEmails());
assertEquals(4, element.getEmails().getEmails().size());
List<String> emails = new ArrayList<>();
emails.add("[email protected]");
emails.add("[email protected]");
emails.add("[email protected]");
emails.add("[email protected]");

for(Email e : element.getEmails().getEmails()) {
if(!emails.contains(e.getEmail())) {
fail(e.getEmail() + " is not in the email list");
}
emails.remove(e.getEmail());
}

assertTrue(emails.isEmpty());
}

@Test
Expand Down Expand Up @@ -617,4 +631,33 @@ private void assertAllPublicButEmails(Person p) {
assertEquals(Long.valueOf(13), ru.getResearcherUrls().get(0).getPutCode());
assertEquals(Visibility.PUBLIC, ru.getResearcherUrls().get(0).getVisibility());
}

@Test
public void checkSourceOnEmail_PersonEndpointTest() {
String orcid = "0000-0000-0000-0001";
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_LIMITED);
Response r = serviceDelegator.viewPerson(orcid);
Person p = (Person) r.getEntity();
assertNotNull(p.getEmails());
checkEmails(p.getEmails());
}

private void checkEmails(Emails emails) {
assertEquals(2, emails.getEmails().size());
for(Email e : emails.getEmails()) {
if(e.getEmail().equals("[email protected]")) {
assertTrue(e.isVerified());
// The source and name on verified professional email addresses should change
assertEquals("0000-0000-0000-0000", e.getSource().retrieveSourcePath());
assertEquals("ORCID email validation", e.getSource().getSourceName().getContent());
} else if(e.getEmail().equals("[email protected]")) {
assertTrue(e.isVerified());
// The source and name on non professional email addresses should not change
assertEquals("APP-5555555555555555", e.getSource().retrieveSourcePath());
assertEquals("Source Client 1", e.getSource().getSourceName().getContent());
} else {
fail("Unexpected email " + e.getEmail());
}
}
}
}
Loading
Loading