Skip to content

Commit

Permalink
Merge pull request #6948 from ORCID/TogglzCleanup
Browse files Browse the repository at this point in the history
Togglz cleanup
  • Loading branch information
amontenegro authored Dec 14, 2023
2 parents 8a44289 + 2e95d8c commit 10cda16
Show file tree
Hide file tree
Showing 33 changed files with 173 additions and 606 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import javax.annotation.Resource;
import javax.ws.rs.core.Response;

import org.apache.commons.lang3.StringEscapeUtils;
import org.orcid.api.common.util.ActivityUtils;
import org.orcid.api.common.util.ApiUtils;
import org.orcid.api.common.util.ElementUtils;
Expand Down Expand Up @@ -57,7 +56,6 @@
import org.orcid.core.manager.read_only.RecordManagerReadOnly;
import org.orcid.core.manager.read_only.ResearcherUrlManagerReadOnly;
import org.orcid.core.manager.read_only.WorkManagerReadOnly;
import org.orcid.core.togglz.Features;
import org.orcid.core.utils.ContributorUtils;
import org.orcid.core.utils.SourceUtils;
import org.orcid.core.version.impl.Api2_0_LastModifiedDatesHelper;
Expand Down Expand Up @@ -770,23 +768,14 @@ public Response viewEmails(String orcid) {
// return all emails if client has /email/read-private scope
orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.EMAIL_READ_PRIVATE);

if (Features.HIDE_UNVERIFIED_EMAILS.isActive()) {
emails = emailManagerReadOnly.getVerifiedEmails(orcid);
} else {
emails = emailManagerReadOnly.getEmails(orcid);
}
emails = emailManagerReadOnly.getVerifiedEmails(orcid);

// Lets copy the list so we don't modify the cached collection
List<Email> filteredList = new ArrayList<Email>(emails.getEmails());
emails = new Emails();
emails.setEmails(filteredList);
} catch (OrcidAccessControlException e) {

if (Features.HIDE_UNVERIFIED_EMAILS.isActive()) {
emails = emailManagerReadOnly.getVerifiedEmails(orcid);
} else {
emails = emailManagerReadOnly.getEmails(orcid);
}
emails = emailManagerReadOnly.getVerifiedEmails(orcid);

// Lets copy the list so we don't modify the cached collection
List<Email> filteredList = new ArrayList<Email>(emails.getEmails());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import org.orcid.core.manager.v3.read_only.ResearchResourceManagerReadOnly;
import org.orcid.core.manager.v3.read_only.ResearcherUrlManagerReadOnly;
import org.orcid.core.manager.v3.read_only.WorkManagerReadOnly;
import org.orcid.core.togglz.Features;
import org.orcid.core.utils.SourceEntityUtils;
import org.orcid.core.utils.v3.ContributorUtils;
import org.orcid.core.utils.v3.SourceUtils;
Expand Down Expand Up @@ -855,24 +854,14 @@ public Response viewEmails(String orcid) {
try {
// return all emails if client has /email/read-private scope
orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.EMAIL_READ_PRIVATE);

if (Features.HIDE_UNVERIFIED_EMAILS.isActive()) {
emails = emailManagerReadOnly.getVerifiedEmails(orcid);
} else {
emails = emailManagerReadOnly.getEmails(orcid);
}
emails = emailManagerReadOnly.getVerifiedEmails(orcid);

// Lets copy the list so we don't modify the cached collection
List<Email> filteredList = new ArrayList<Email>(emails.getEmails());
emails = new Emails();
emails.setEmails(filteredList);
} catch (OrcidAccessControlException e) {

if (Features.HIDE_UNVERIFIED_EMAILS.isActive()) {
emails = emailManagerReadOnly.getVerifiedEmails(orcid);
} else {
emails = emailManagerReadOnly.getEmails(orcid);
}
emails = emailManagerReadOnly.getVerifiedEmails(orcid);

// Lets copy the list so we don't modify the cached collection
List<Email> filteredList = new ArrayList<Email>(emails.getEmails());
Expand Down Expand Up @@ -1160,7 +1149,7 @@ public Response viewPersonalDetails(String orcid) {
@Override
public Response viewPerson(String orcid) {
checkProfileStatus(orcid, true);
Person person = personDetailsManagerReadOnly.getPersonDetails(orcid, !Features.HIDE_UNVERIFIED_EMAILS.isActive());
Person person = personDetailsManagerReadOnly.getPersonDetails(orcid, false);
orcidSecurityManager.checkAndFilter(orcid, person);
ElementUtils.setPathToPerson(person, orcid);
Api3_0LastModifiedDatesHelper.calculateLastModified(person);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package org.orcid.api.memberV2.server.delegator;

import static org.hamcrest.core.AnyOf.anyOf;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

Expand All @@ -14,14 +11,12 @@

import javax.annotation.Resource;
import javax.ws.rs.core.Response;
import org.orcid.test.DBUnitTest;
import org.orcid.test.helper.Utils;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.orcid.core.exception.OrcidUnauthorizedException;
import org.orcid.core.togglz.Features;
import org.orcid.core.utils.SecurityContextTestUtils;
import org.orcid.jaxb.model.common_v2.Visibility;
import org.orcid.jaxb.model.groupid_v2.GroupIdRecord;
Expand All @@ -39,7 +34,9 @@
import org.orcid.jaxb.model.record_v2.ResearcherUrl;
import org.orcid.jaxb.model.record_v2.Work;
import org.orcid.jaxb.model.record_v2.WorkBulk;
import org.orcid.test.DBUnitTest;
import org.orcid.test.OrcidJUnit4ClassRunner;
import org.orcid.test.helper.Utils;
import org.springframework.test.context.ContextConfiguration;

@RunWith(OrcidJUnit4ClassRunner.class)
Expand Down Expand Up @@ -142,50 +139,13 @@ public void testViewEmails() {
assertEquals("/4444-4444-4444-4443/email", emails.getPath());
Utils.verifyLastModified(emails.getLastModifiedDate());
assertNotNull(emails.getEmails());

if (Features.HIDE_UNVERIFIED_EMAILS.isActive()) {
assertEquals(1, emails.getEmails().size());
Email email = emails.getEmails().get(0);
Utils.verifyLastModified(email.getLastModifiedDate());
assertEquals(email.getEmail(), "[email protected]");
assertEquals(Visibility.PRIVATE, email.getVisibility());
assertEquals("APP-5555555555555555", email.retrieveSourcePath());
assertEquals(true, email.isVerified());
assertEquals(false, email.isPrimary());
} else {
assertEquals(3, emails.getEmails().size());
for (Email email : emails.getEmails()) {
Utils.verifyLastModified(email.getLastModifiedDate());
assertThat(email.getEmail(), anyOf(is("[email protected]"), is("[email protected]"), is("[email protected]")));
switch (email.getEmail()) {
case "[email protected]":
assertEquals(Visibility.LIMITED, email.getVisibility());
assertEquals("4444-4444-4444-4443", email.retrieveSourcePath());
assertEquals(false, email.isVerified());
assertEquals(false, email.isPrimary());
break;
case "[email protected]":
assertEquals(Visibility.PUBLIC, email.getVisibility());
assertEquals("4444-4444-4444-4443", email.retrieveSourcePath());
assertEquals(false, email.isVerified());
assertEquals(false, email.isPrimary());
break;
case "[email protected]":
assertEquals(Visibility.PRIVATE, email.getVisibility());
assertEquals("APP-5555555555555555", email.retrieveSourcePath());
assertEquals(true, email.isVerified());
assertEquals(false, email.isPrimary());
break;
case "[email protected]":
assertEquals(Visibility.PRIVATE, email.getVisibility());
assertEquals("APP-5555555555555555", email.retrieveSourcePath());
assertEquals(false, email.isVerified());
assertEquals(true, email.isPrimary());
break;
default:
fail("Invalid email: " + email.getEmail());
}
}
}
assertEquals(1, emails.getEmails().size());
Email email = emails.getEmails().get(0);
Utils.verifyLastModified(email.getLastModifiedDate());
assertEquals(email.getEmail(), "[email protected]");
assertEquals(Visibility.PRIVATE, email.getVisibility());
assertEquals("APP-5555555555555555", email.retrieveSourcePath());
assertEquals(true, email.isVerified());
assertEquals(false, email.isPrimary());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.orcid.core.exception.OrcidUnauthorizedException;
import org.orcid.core.togglz.Features;
import org.orcid.core.utils.SecurityContextTestUtils;
import org.orcid.jaxb.model.common_v2.Visibility;
import org.orcid.jaxb.model.groupid_v2.GroupIdRecord;
Expand Down Expand Up @@ -515,58 +514,28 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Person() {
Emails email = p.getEmails();
assertNotNull(email);
Utils.verifyLastModified(email.getLastModifiedDate());

if (Features.HIDE_UNVERIFIED_EMAILS.isActive()) {
assertEquals(4, email.getEmails().size());

boolean found1 = false, found2 = false, found3 = false, found4 = false;

for (Email element : email.getEmails()) {
if (element.getEmail().equals("[email protected]")) {
found1 = true;
} else if (element.getEmail().equals("[email protected]")) {
found2 = true;
} else if (element.getEmail().equals("[email protected]")) {
found3 = true;
} else if (element.getEmail().equals("[email protected]")) {
found4 = true;
} else {
fail("Invalid email " + element.getEmail());
}
}

assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
} else {
assertEquals(5, email.getEmails().size());

boolean found1 = false, found2 = false, found3 = false, found4 = false, found5 = false;

for (Email element : email.getEmails()) {
if (element.getEmail().equals("[email protected]")) {
found1 = true;
} else if (element.getEmail().equals("[email protected]")) {
found2 = true;
} else if (element.getEmail().equals("[email protected]")) {
found3 = true;
} else if (element.getEmail().equals("[email protected]")) {
found4 = true;
} else if (element.getEmail().equals("[email protected]")) {
found5 = true;
} else {
fail("Invalid email " + element.getEmail());
}
assertEquals(4, email.getEmails().size());

boolean found1 = false, found2 = false, found3 = false, found4 = false;

for (Email element : email.getEmails()) {
if (element.getEmail().equals("[email protected]")) {
found1 = true;
} else if (element.getEmail().equals("[email protected]")) {
found2 = true;
} else if (element.getEmail().equals("[email protected]")) {
found3 = true;
} else if (element.getEmail().equals("[email protected]")) {
found4 = true;
} else {
fail("Invalid email " + element.getEmail());
}

assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
assertTrue(found5);
}

assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
this.assertAllPublicButEmails(p);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.orcid.core.exception.OrcidUnauthorizedException;
import org.orcid.core.togglz.Features;
import org.orcid.core.utils.SecurityContextTestUtils;
import org.orcid.jaxb.model.common_v2.Iso3166Country;
import org.orcid.jaxb.model.common_v2.Locale;
Expand Down Expand Up @@ -1004,59 +1003,30 @@ public void testReadPrivateEmails_OtherThingsJustPublic_Record() {
assertNotNull(p.getEmails());
Emails email = p.getEmails();
assertNotNull(email);
Utils.verifyLastModified(email.getLastModifiedDate());

if (Features.HIDE_UNVERIFIED_EMAILS.isActive()) {
assertEquals(4, email.getEmails().size());

boolean found1 = false, found2 = false, found3 = false, found4 = false;

for (Email element : email.getEmails()) {
if (element.getEmail().equals("[email protected]")) {
found1 = true;
} else if (element.getEmail().equals("[email protected]")) {
found2 = true;
} else if (element.getEmail().equals("[email protected]")) {
found3 = true;
} else if (element.getEmail().equals("[email protected]")) {
found4 = true;
} else {
fail("Invalid email " + element.getEmail());
}
}

assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
} else {
assertEquals(5, email.getEmails().size());

boolean found1 = false, found2 = false, found3 = false, found4 = false, found5 = false;

for (Email element : email.getEmails()) {
if (element.getEmail().equals("[email protected]")) {
found1 = true;
} else if (element.getEmail().equals("[email protected]")) {
found2 = true;
} else if (element.getEmail().equals("[email protected]")) {
found3 = true;
} else if (element.getEmail().equals("[email protected]")) {
found4 = true;
} else if (element.getEmail().equals("[email protected]")) {
found5 = true;
} else {
fail("Invalid email " + element.getEmail());
}
Utils.verifyLastModified(email.getLastModifiedDate());
assertEquals(4, email.getEmails().size());

boolean found1 = false, found2 = false, found3 = false, found4 = false;

for (Email element : email.getEmails()) {
if (element.getEmail().equals("[email protected]")) {
found1 = true;
} else if (element.getEmail().equals("[email protected]")) {
found2 = true;
} else if (element.getEmail().equals("[email protected]")) {
found3 = true;
} else if (element.getEmail().equals("[email protected]")) {
found4 = true;
} else {
fail("Invalid email " + element.getEmail());
}

assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
assertTrue(found5);
}

assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);

this.assertAllPublicButEmails(p);
}

Expand Down
Loading

0 comments on commit 10cda16

Please sign in to comment.