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.
This commit is contained in:
parent
643dcb224e
commit
a01c0fc74c
8 changed files with 108 additions and 39 deletions
|
@ -2,9 +2,6 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.auth.identifier.common;
|
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.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -108,7 +105,7 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory {
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
ids.add(id);
|
ids.add(id);
|
||||||
} else {
|
} 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);
|
UserAccount user = LoginStatusBean.getCurrentUser(req);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
for(String proxiedUri: user.getProxiedIndividualUris()) {
|
for(String proxiedUri: user.getProxiedIndividualUris()) {
|
||||||
ids.add(new HasAssociatedIndividual(proxiedUri, EXPLICIT_PROXY));
|
ids.add(new HasProxyEditingRights(proxiedUri));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,17 +10,17 @@ 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.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
|
* Subclasses exist to indicate how that association is created, as either a
|
||||||
* files to determine whether the associated individual is blacklisted.
|
* Self-Editor or a Proxy Editor. In some cases (e.g., the MyProfile link) the
|
||||||
*
|
* distinction is important.
|
||||||
* The mechanism is only to record how this was created, for diagnostic purposes.
|
|
||||||
*/
|
*/
|
||||||
public class HasAssociatedIndividual extends AbstractCommonIdentifier implements
|
public abstract class HasAssociatedIndividual extends AbstractCommonIdentifier
|
||||||
Identifier {
|
implements Identifier {
|
||||||
|
|
||||||
public static Collection<HasAssociatedIndividual> getIdentifiers(
|
private static Collection<HasAssociatedIndividual> getIdentifiers(
|
||||||
IdentifierBundle ids) {
|
IdentifierBundle ids) {
|
||||||
return getIdentifiersForClass(ids, HasAssociatedIndividual.class);
|
return getIdentifiersForClass(ids, HasAssociatedIndividual.class);
|
||||||
}
|
}
|
||||||
|
@ -33,23 +33,13 @@ public class HasAssociatedIndividual extends AbstractCommonIdentifier implements
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Mechanism {SELF, EXPLICIT_PROXY}
|
|
||||||
|
|
||||||
private final String associatedIndividualUri;
|
private final String associatedIndividualUri;
|
||||||
private final Mechanism mechanism;
|
|
||||||
|
|
||||||
public HasAssociatedIndividual(String associatedIndividualUri, Mechanism mechanism) {
|
public HasAssociatedIndividual(String associatedIndividualUri) {
|
||||||
this.associatedIndividualUri = associatedIndividualUri;
|
this.associatedIndividualUri = associatedIndividualUri;
|
||||||
this.mechanism = mechanism;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAssociatedIndividualUri() {
|
public String getAssociatedIndividualUri() {
|
||||||
return associatedIndividualUri;
|
return associatedIndividualUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "HasAssociatedIndividual[" + associatedIndividualUri + " (" + mechanism +
|
|
||||||
")]";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<HasProfile> getIdentifiers(IdentifierBundle ids) {
|
||||||
|
return getIdentifiersForClass(ids, HasProfile.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<String> getProfileUris(IdentifierBundle ids) {
|
||||||
|
Set<String> set = new HashSet<String>();
|
||||||
|
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() + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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<HasProxyEditingRights> getIdentifiers(IdentifierBundle ids) {
|
||||||
|
return getIdentifiersForClass(ids, HasProxyEditingRights.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<String> getProxiedPageUris(IdentifierBundle ids) {
|
||||||
|
Set<String> set = new HashSet<String>();
|
||||||
|
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() + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.IdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
|
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.HasRoleLevel;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsUser;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsUser;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public class EditN3Utils {
|
||||||
|
|
||||||
List<String> uris = new ArrayList<String>();
|
List<String> uris = new ArrayList<String>();
|
||||||
uris.addAll(IsUser.getUserUris(ids));
|
uris.addAll(IsUser.getUserUris(ids));
|
||||||
uris.addAll(HasAssociatedIndividual.getIndividualUris(ids));
|
uris.addAll(HasProfile.getProfileUris(ids));
|
||||||
uris.addAll(HasRoleLevel.getRoleLevelUris(ids));
|
uris.addAll(HasRoleLevel.getRoleLevelUris(ids));
|
||||||
uris.add("Unknown N3 Editor");
|
uris.add("Unknown N3 Editor");
|
||||||
return uris.get(0);
|
return uris.get(0);
|
||||||
|
|
|
@ -7,7 +7,7 @@ import java.util.Collection;
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
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.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.auth.policy.PolicyHelper;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
@ -29,7 +29,7 @@ public class User extends BaseTemplateModel {
|
||||||
|
|
||||||
private String figureAssociatedProfileUrl() {
|
private String figureAssociatedProfileUrl() {
|
||||||
IdentifierBundle ids = RequestIdentifiers.getIdBundleForRequest(vreq);
|
IdentifierBundle ids = RequestIdentifiers.getIdBundleForRequest(vreq);
|
||||||
Collection<String> uris = HasAssociatedIndividual.getIndividualUris(ids);
|
Collection<String> uris = HasProfile.getProfileUris(ids);
|
||||||
if (uris.isEmpty()) {
|
if (uris.isEmpty()) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,7 @@ import stubs.javax.servlet.ServletContextStub;
|
||||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
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.IdentifierBundle;
|
||||||
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.HasAssociatedIndividual.Mechanism;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper;
|
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.Authorization;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
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 UNSAFE_NS = VitroVocabulary.vitroURI;
|
||||||
|
|
||||||
private static final String SELFEDITOR_URI = SAFE_NS + "individual244";
|
private static final String SELFEDITOR_URI = SAFE_NS + "individual244";
|
||||||
private static final String SAFE_RESOURCE = SAFE_NS + "otherIndividual77777";
|
private static final String SAFE_RESOURCE = SAFE_NS
|
||||||
private static final String UNSAFE_RESOURCE = UNSAFE_NS + "otherIndividual99999";
|
+ "otherIndividual77777";
|
||||||
|
private static final String UNSAFE_RESOURCE = UNSAFE_NS
|
||||||
|
+ "otherIndividual99999";
|
||||||
|
|
||||||
private static final String SAFE_PREDICATE = SAFE_NS + "hasHairStyle";
|
private static final String SAFE_PREDICATE = SAFE_NS + "hasHairStyle";
|
||||||
private static final String UNSAFE_PREDICATE = UNSAFE_NS + "hasSuperPowers";
|
private static final String UNSAFE_PREDICATE = UNSAFE_NS + "hasSuperPowers";
|
||||||
|
@ -74,7 +75,7 @@ public class SelfEditingPolicyTest extends AbstractTestClass {
|
||||||
ind.setURI(SELFEDITOR_URI);
|
ind.setURI(SELFEDITOR_URI);
|
||||||
|
|
||||||
ids = new ArrayIdentifierBundle();
|
ids = new ArrayIdentifierBundle();
|
||||||
ids.add(new HasAssociatedIndividual(SELFEDITOR_URI, Mechanism.SELF));
|
ids.add(new HasProfile(SELFEDITOR_URI));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -323,11 +324,11 @@ public class SelfEditingPolicyTest extends AbstractTestClass {
|
||||||
|
|
||||||
IndividualImpl ind1 = new IndividualImpl();
|
IndividualImpl ind1 = new IndividualImpl();
|
||||||
ind1.setURI(SAFE_NS + "bozoUri");
|
ind1.setURI(SAFE_NS + "bozoUri");
|
||||||
ids.add(new HasAssociatedIndividual(ind1.getURI(), Mechanism.SELF));
|
ids.add(new HasProfile(ind1.getURI()));
|
||||||
|
|
||||||
IndividualImpl ind2 = new IndividualImpl();
|
IndividualImpl ind2 = new IndividualImpl();
|
||||||
ind2.setURI(SELFEDITOR_URI);
|
ind2.setURI(SELFEDITOR_URI);
|
||||||
ids.add(new HasAssociatedIndividual(ind2.getURI(), Mechanism.SELF));
|
ids.add(new HasProfile(ind2.getURI()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
|
@ -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.ArrayIdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier;
|
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.IdentifierBundle;
|
||||||
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.HasAssociatedIndividual.Mechanism;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper;
|
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.Authorization;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
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);
|
seIndividual.setURI(SELFEDITOR_URI);
|
||||||
|
|
||||||
ids = new ArrayIdentifierBundle();
|
ids = new ArrayIdentifierBundle();
|
||||||
ids.add(new HasAssociatedIndividual(SELFEDITOR_URI, Mechanism.SELF));
|
ids.add(new HasProfile(SELFEDITOR_URI));
|
||||||
|
|
||||||
// setLoggerLevel(SelfEditingPolicySetupTest.class, Level.DEBUG);
|
// setLoggerLevel(SelfEditingPolicySetupTest.class, Level.DEBUG);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue