NIHVIVO-2728 provide a template variable for the link to the user's profile.

This commit is contained in:
j2blake 2011-06-22 16:31:56 +00:00
parent 29cb6e4077
commit 8629772106

View file

@ -2,24 +2,47 @@
package edu.cornell.mannlib.vitro.webapp.web.templatemodels;
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.policy.PolicyHelper;
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.RevisionInfoController;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.SiteAdminController;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
public class User extends BaseTemplateModel {
private final VitroRequest vreq;
private final UserAccount currentUser;
private final String profileUrl;
public User(VitroRequest vreq) {
this.vreq = vreq;
this.currentUser = LoginStatusBean.getCurrentUser(vreq);
this.profileUrl = figureAssociatedProfileUrl();
}
public boolean isLoggedIn() {
private String figureAssociatedProfileUrl() {
IdentifierBundle ids = RequestIdentifiers.getIdBundleForRequest(vreq);
Collection<String> uris = HasAssociatedIndividual.getIndividualUris(ids);
if (uris.isEmpty()) {
return "";
}
String uri = uris.iterator().next();
String url = UrlBuilder.getIndividualProfileUrl(uri, vreq);
if (url == null) {
return "";
}
return url;
}
public boolean isLoggedIn() {
return currentUser != null;
}
@ -63,4 +86,11 @@ public class User extends BaseTemplateModel {
return PolicyHelper.isAuthorizedForActions(vreq, RevisionInfoController.REQUIRED_ACTIONS);
}
public boolean getHasProfile() {
return !profileUrl.isEmpty();
}
public String getProfileUrl() {
return profileUrl;
}
}