use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.
the class TemplateExceptionRenderer method render.
@Override
public Response render(final RestFailure failure) {
if (!enabled)
// Don't run if we're not enabled
return null;
if (failure == null)
// Don't run if the failure is null
return null;
if (HttpCallContext.peek() == null)
// Don't run unless we have an HttpCallContext
return null;
else if (!shouldRenderHtmlForRequest(HttpCallContext.get().getRequest()))
// Don't run unless we should be rendering HTML for this request
return null;
final TemplateCall call = templater.template("exception");
call.set("failure", failure);
// Make sure there's a login (even if anonymous) associated with the current HTTP Session
// N.B. this is a bit of an ugly layering, we could duplicate the logic here but that also seems ugly
loginProvider.ensureLoginOnSession(HttpCallContext.get().getRequest().getSession());
return call.process(Response.status(failure.httpCode).type(MediaType.TEXT_HTML_TYPE));
}
use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.
the class ConfigUIServiceImpl method getConfigPage.
@Override
public String getConfigPage(final String path) {
final ConfigPropertyData config = repo.get(REF, path);
final List<String> paths = repo.getPaths(REF);
final List<ConfigPropertyValue> inheritedProperties;
final List<ConfigPropertyValue> definedProperties;
{
// Sort alphabetically for the UI
config.properties.sort(Comparator.comparing(ConfigPropertyValue::getName));
inheritedProperties = computeInheritedProperties(config);
definedProperties = computeDefinedProperties(config);
}
final TemplateCall call = templater.template("config-edit");
call.set("nonce", nonceStore.getValue(NONCE_USE));
call.set("repo", repo);
call.set("config", config);
call.set("inheritedProperties", inheritedProperties);
call.set("definedProperties", definedProperties);
call.set("path", config.path);
call.set("paths", paths);
call.set("children", getChildren(config.path, paths));
call.set("parent", getParent(config.path));
return call.process();
}
use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.
the class ConfigUIServiceImpl method getIndex.
@Override
public String getIndex() {
final TemplateCall call = templater.template("index");
call.set("paths", repo.getPaths(REF));
call.set("commits", repo.getRecentCommits(10));
return call.process();
}
use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.
the class RoleUIServiceImpl method get.
@Override
@Transactional(readOnly = true)
public String get(final String id) {
TemplateCall call = templater.template("role");
final RoleEntity entity = dao.getById(id);
if (entity == null)
throw new IllegalArgumentException("No such Role: " + id);
call.set("entity", entity);
call.set("allUsers", userDao.getAll());
call.set("users", userDao.findByUriQuery(new WebQuery().eq("roles.id", id)).getList());
call.set("nonce", nonceStore.getValue(NONCE_USE));
return call.process();
}
use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.
the class RegisterUIServiceImpl method getRegister.
@AuthConstraint(id = "register_service", skip = true, comment = "register page handles own constraints")
@Transactional(readOnly = true)
@Override
public String getRegister() {
if (!allowAnonymousRegistration && !login.isAdmin())
throw new AuthenticationFailureException("Anonymous registration is not enabled. Please log in to create other users");
TemplateCall call = templater.template("register");
call.set("nonce", nonceStore.allocate());
if (login.isAdmin())
// Admin user, role picker will be available
call.set("roles", roleDao.getAll());
else
// Anonymous registration, no role select
call.set("roles", Collections.emptyList());
return call.process();
}
Aggregations