NIHVIVO-2728 provide a template variable for the link to the user's profile.
This commit is contained in:
parent
29cb6e4077
commit
8629772106
1 changed files with 32 additions and 2 deletions
|
@ -2,21 +2,44 @@
|
|||
|
||||
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();
|
||||
}
|
||||
|
||||
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() {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue