NIHVIVO-2343 Remove hardcoded kluges for base URL, matching property and AJAX URL. Only show the proxy panel if the user has a profile and is authorized to manage the proxy.

This commit is contained in:
j2blake 2011-10-30 16:54:23 +00:00
parent 743b96281e
commit b7ec17856e
5 changed files with 33 additions and 9 deletions

View file

@ -181,6 +181,7 @@ public abstract class UserAccountsPage {
map.put("firstTimeExternal",
UrlBuilder.getUrl("/accounts/firstTimeExternal"));
map.put("accountsAjax", UrlBuilder.getUrl("/accountsAjax"));
map.put("sparqlQueryAjax", UrlBuilder.getUrl("/ajax/sparqlQuery"));
return map;
}

View file

@ -13,6 +13,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.ManageOwnProxies;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
@ -146,6 +148,11 @@ public class UserAccountsMyAccountPage extends UserAccountsPage {
}
body.put("formUrls", buildUrlsMap());
// Could I do this without exposing this mechanism? But how to search
// for an associated profile in AJAX?
body.put("matchingProperty", SelfEditingConfiguration.getBean(vreq)
.getMatchingPropertyUri());
if (userAccount.isExternalAuthOnly()) {
body.put("externalAuthOnly", Boolean.TRUE);
}
@ -155,6 +162,9 @@ public class UserAccountsMyAccountPage extends UserAccountsPage {
if (!confirmationCode.isEmpty()) {
body.put(confirmationCode, Boolean.TRUE);
}
if (isProxyPanelAuthorized()) {
body.put("showProxyPanel", Boolean.TRUE);
}
strategy.addMoreBodyValues(body);
@ -180,6 +190,12 @@ public class UserAccountsMyAccountPage extends UserAccountsPage {
confirmationCode = strategy.getConfirmationCode();
}
boolean isProxyPanelAuthorized() {
return PolicyHelper
.isAuthorizedForActions(vreq, new ManageOwnProxies())
&& (getProfilePage(userAccount) != null);
}
boolean isExternalAuthOnly() {
return (userAccount != null) && userAccount.isExternalAuthOnly();
}