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;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<HasAssociatedIndividual> getIdentifiers(
|
||||
private static Collection<HasAssociatedIndividual> 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 +
|
||||
")]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.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<String> uris = new ArrayList<String>();
|
||||
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);
|
||||
|
|
|
@ -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<String> uris = HasAssociatedIndividual.getIndividualUris(ids);
|
||||
Collection<String> uris = HasProfile.getProfileUris(ids);
|
||||
if (uris.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue