From a01c0fc74c15aa86e44f565f707dd1bfafaaaeab Mon Sep 17 00:00:00 2001 From: j2blake Date: Tue, 22 Nov 2011 18:32:54 +0000 Subject: [PATCH] NIHVIVO-3343 Distinguish between Self-editors and Proxy-self-editors by the class of their identifiers, not by an option on the identifier. Only true self-editors get a "My Profile" link. --- .../common/CommonIdentifierBundleFactory.java | 7 +--- .../common/HasAssociatedIndividual.java | 28 ++++--------- .../auth/identifier/common/HasProfile.java | 41 +++++++++++++++++++ .../common/HasProxyEditingRights.java | 41 +++++++++++++++++++ .../n3editing/processEdit/EditN3Utils.java | 4 +- .../vitro/webapp/web/templatemodels/User.java | 4 +- .../auth/policy/SelfEditingPolicyTest.java | 17 ++++---- .../auth/policy/SelfEditingPolicy_2_Test.java | 5 +-- 8 files changed, 108 insertions(+), 39 deletions(-) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/HasProfile.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/HasProxyEditingRights.java diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/CommonIdentifierBundleFactory.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/CommonIdentifierBundleFactory.java index 11dc42b6b..31688baba 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/CommonIdentifierBundleFactory.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/CommonIdentifierBundleFactory.java @@ -2,9 +2,6 @@ package edu.cornell.mannlib.vitro.webapp.auth.identifier.common; -import static edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasAssociatedIndividual.Mechanism.EXPLICIT_PROXY; -import static edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasAssociatedIndividual.Mechanism.SELF; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -108,7 +105,7 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory { if (id != null) { ids.add(id); } else { - ids.add(new HasAssociatedIndividual(ind.getURI(), SELF)); + ids.add(new HasProfile(ind.getURI())); } } @@ -153,7 +150,7 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory { UserAccount user = LoginStatusBean.getCurrentUser(req); if (user != null) { for(String proxiedUri: user.getProxiedIndividualUris()) { - ids.add(new HasAssociatedIndividual(proxiedUri, EXPLICIT_PROXY)); + ids.add(new HasProxyEditingRights(proxiedUri)); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/HasAssociatedIndividual.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/HasAssociatedIndividual.java index a50984d46..5747a02fe 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/HasAssociatedIndividual.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/HasAssociatedIndividual.java @@ -10,17 +10,17 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; /** - * The current user is associated with this Individual. + * The current user is associated with this Individual page, and has editing + * rights relating to it. * - * This includes a thick factory method that will look through a directory of - * files to determine whether the associated individual is blacklisted. - * - * The mechanism is only to record how this was created, for diagnostic purposes. + * Subclasses exist to indicate how that association is created, as either a + * Self-Editor or a Proxy Editor. In some cases (e.g., the MyProfile link) the + * distinction is important. */ -public class HasAssociatedIndividual extends AbstractCommonIdentifier implements - Identifier { +public abstract class HasAssociatedIndividual extends AbstractCommonIdentifier + implements Identifier { - public static Collection getIdentifiers( + private static Collection getIdentifiers( IdentifierBundle ids) { return getIdentifiersForClass(ids, HasAssociatedIndividual.class); } @@ -32,24 +32,14 @@ public class HasAssociatedIndividual extends AbstractCommonIdentifier implements } return set; } - - public enum Mechanism {SELF, EXPLICIT_PROXY} private final String associatedIndividualUri; - private final Mechanism mechanism; - public HasAssociatedIndividual(String associatedIndividualUri, Mechanism mechanism) { + public HasAssociatedIndividual(String associatedIndividualUri) { this.associatedIndividualUri = associatedIndividualUri; - this.mechanism = mechanism; } public String getAssociatedIndividualUri() { return associatedIndividualUri; } - - @Override - public String toString() { - return "HasAssociatedIndividual[" + associatedIndividualUri + " (" + mechanism + - ")]"; - } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/HasProfile.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/HasProfile.java new file mode 100644 index 000000000..392656102 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/HasProfile.java @@ -0,0 +1,41 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.auth.identifier.common; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; + +/** + * The current user has this Individual page as their profile, and has + * self-editing rights relating to it. + */ +public class HasProfile extends HasAssociatedIndividual { + private static Collection getIdentifiers(IdentifierBundle ids) { + return getIdentifiersForClass(ids, HasProfile.class); + } + + public static Collection getProfileUris(IdentifierBundle ids) { + Set set = new HashSet(); + for (HasProfile id : getIdentifiers(ids)) { + set.add(id.getAssociatedIndividualUri()); + } + return set; + } + + public HasProfile(String associatedIndividualUri) { + super(associatedIndividualUri); + } + + public String getProfileUri() { + return getAssociatedIndividualUri(); + } + + @Override + public String toString() { + return "HasProfile[" + getAssociatedIndividualUri() + "]"; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/HasProxyEditingRights.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/HasProxyEditingRights.java new file mode 100644 index 000000000..569d89419 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/HasProxyEditingRights.java @@ -0,0 +1,41 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.auth.identifier.common; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; + +/** + * The current user has a Proxy relationship to this Individual page, and has + * proxy editing rights relating to it. + */ +public class HasProxyEditingRights extends HasAssociatedIndividual { + private static Collection getIdentifiers(IdentifierBundle ids) { + return getIdentifiersForClass(ids, HasProxyEditingRights.class); + } + + public static Collection getProxiedPageUris(IdentifierBundle ids) { + Set set = new HashSet(); + for (HasProxyEditingRights id : getIdentifiers(ids)) { + set.add(id.getAssociatedIndividualUri()); + } + return set; + } + + public HasProxyEditingRights(String associatedIndividualUri) { + super(associatedIndividualUri); + } + + public String getProxiedPageUri() { + return getAssociatedIndividualUri(); + } + + @Override + public String toString() { + return "HasProxyEditingRights[" + getAssociatedIndividualUri() + "]"; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/EditN3Utils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/EditN3Utils.java index e8c4ca5b6..e8a8256b4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/EditN3Utils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/processEdit/EditN3Utils.java @@ -11,7 +11,7 @@ import org.apache.xerces.util.XMLChar; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasAssociatedIndividual; +import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasProfile; import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasRoleLevel; import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsUser; @@ -22,7 +22,7 @@ public class EditN3Utils { List uris = new ArrayList(); uris.addAll(IsUser.getUserUris(ids)); - uris.addAll(HasAssociatedIndividual.getIndividualUris(ids)); + uris.addAll(HasProfile.getProfileUris(ids)); uris.addAll(HasRoleLevel.getRoleLevelUris(ids)); uris.add("Unknown N3 Editor"); return uris.get(0); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/User.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/User.java index 8c55e19b3..47d0434a3 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/User.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/User.java @@ -7,7 +7,7 @@ import java.util.Collection; import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasAssociatedIndividual; +import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasProfile; import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper; import edu.cornell.mannlib.vitro.webapp.beans.UserAccount; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; @@ -29,7 +29,7 @@ public class User extends BaseTemplateModel { private String figureAssociatedProfileUrl() { IdentifierBundle ids = RequestIdentifiers.getIdBundleForRequest(vreq); - Collection uris = HasAssociatedIndividual.getIndividualUris(ids); + Collection uris = HasProfile.getProfileUris(ids); if (uris.isEmpty()) { return ""; } diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicyTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicyTest.java index fa3e7d116..f1858e094 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicyTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicyTest.java @@ -16,8 +16,7 @@ import stubs.javax.servlet.ServletContextStub; import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasAssociatedIndividual; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasAssociatedIndividual.Mechanism; +import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasProfile; import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision; @@ -48,8 +47,10 @@ public class SelfEditingPolicyTest extends AbstractTestClass { private static final String UNSAFE_NS = VitroVocabulary.vitroURI; private static final String SELFEDITOR_URI = SAFE_NS + "individual244"; - private static final String SAFE_RESOURCE = SAFE_NS + "otherIndividual77777"; - private static final String UNSAFE_RESOURCE = UNSAFE_NS + "otherIndividual99999"; + private static final String SAFE_RESOURCE = SAFE_NS + + "otherIndividual77777"; + private static final String UNSAFE_RESOURCE = UNSAFE_NS + + "otherIndividual99999"; private static final String SAFE_PREDICATE = SAFE_NS + "hasHairStyle"; private static final String UNSAFE_PREDICATE = UNSAFE_NS + "hasSuperPowers"; @@ -72,9 +73,9 @@ public class SelfEditingPolicyTest extends AbstractTestClass { IndividualImpl ind = new IndividualImpl(); ind.setURI(SELFEDITOR_URI); - + ids = new ArrayIdentifierBundle(); - ids.add(new HasAssociatedIndividual(SELFEDITOR_URI, Mechanism.SELF)); + ids.add(new HasProfile(SELFEDITOR_URI)); } @Test @@ -323,11 +324,11 @@ public class SelfEditingPolicyTest extends AbstractTestClass { IndividualImpl ind1 = new IndividualImpl(); ind1.setURI(SAFE_NS + "bozoUri"); - ids.add(new HasAssociatedIndividual(ind1.getURI(), Mechanism.SELF)); + ids.add(new HasProfile(ind1.getURI())); IndividualImpl ind2 = new IndividualImpl(); ind2.setURI(SELFEDITOR_URI); - ids.add(new HasAssociatedIndividual(ind2.getURI(), Mechanism.SELF)); + ids.add(new HasProfile(ind2.getURI())); } // ---------------------------------------------------------------------- diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicy_2_Test.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicy_2_Test.java index eaac6bae3..e0238bc1f 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicy_2_Test.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/SelfEditingPolicy_2_Test.java @@ -22,8 +22,7 @@ import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasAssociatedIndividual; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasAssociatedIndividual.Mechanism; +import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasProfile; import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision; @@ -96,7 +95,7 @@ public class SelfEditingPolicy_2_Test extends AbstractTestClass { seIndividual.setURI(SELFEDITOR_URI); ids = new ArrayIdentifierBundle(); - ids.add(new HasAssociatedIndividual(SELFEDITOR_URI, Mechanism.SELF)); + ids.add(new HasProfile(SELFEDITOR_URI)); // setLoggerLevel(SelfEditingPolicySetupTest.class, Level.DEBUG); }