NIHVIVO-3726 Clarify the way we determine the Viewer URI.

This commit is contained in:
j2blake 2012-06-25 19:52:51 +00:00
parent c46b148535
commit 1aed1c4976

View file

@ -9,6 +9,7 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -19,6 +20,8 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasProfile;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount; import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
@ -76,16 +79,22 @@ public class OpenSocialManager {
// Analyze the request to figure out whose page we are viewing. // Analyze the request to figure out whose page we are viewing.
this.ownerId = figureOwnerId(vreq); this.ownerId = figureOwnerId(vreq);
// in editMode we need to set the viewer to be the same as the owner // If we are authorized to edit on behalf of the page owner,
// otherwise, the gadget will not be able to save appData correctly // set the viewer ID to be the owner ID, so it looks like we are the page owner.
if (editMode) { if (editMode) {
this.viewerId = ownerId; this.viewerId = ownerId;
} }
else { else {
// If we have a profile page, use that URI. Otherwise, use the URI of the logged-in user account, if any.
UserAccount viewer = LoginStatusBean.getCurrentUser(vreq); UserAccount viewer = LoginStatusBean.getCurrentUser(vreq);
// attempt to use profile URI if present, otherwise user user oriented URI Collection<String> profileUris = HasProfile.getProfileUris(RequestIdentifiers.getIdBundleForRequest(vreq));
this.viewerId = viewer != null && viewer.getProxiedIndividualUris().size() == 1 ? if (!profileUris.isEmpty()) {
viewer.getProxiedIndividualUris().toArray()[0].toString() : (viewer != null ? viewer.getUri() : null); this.viewerId = profileUris.iterator().next();
} else if (viewer != null) {
this.viewerId = viewer.getUri();
} else {
this.viewerId = null;
}
} }
String requestAppId = vreq.getParameter("appId"); String requestAppId = vreq.getParameter("appId");