diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/User.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/User.java index 5b9a217d7..80c22699c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/User.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/User.java @@ -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 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; + } }