String message = "Could not fetch streams. We expected HTTP 200, but got a HTTP " + e.getHttpCode() + ".";
return status(504, views.html.errors.error.render(message, e, request()));
}
}
final ChangeUserRequestForm formData = requestForm.get();
// translate session timeout value from form fields to millis
if (!formData.session_timeout_never) {
TimeUnit timeoutUnit;
if (formData.timeout_unit != null) {
try {
timeoutUnit = TimeUnit.valueOf(formData.timeout_unit.toUpperCase());
formData.sessionTimeoutMs = timeoutUnit.toMillis(formData.timeout);
} catch (IllegalArgumentException e) {
log.warn("Unknown value for session timeout unit. Cannot set session timeout value.", e);
}
}
} else {
formData.sessionTimeoutMs = -1; // which translates to "never".
}
Set<String> permissions = Sets.newHashSet(user.getPermissions());
// TODO this does not handle combined permissions like streams:edit,read:1,2 !
// remove all streams:edit, streams:read permissions and add the ones from the form back.
permissions = Sets.newHashSet(Sets.filter(permissions, new Predicate<String>() {
@Override
public boolean apply(@Nullable String input) {
return (input != null) &&
!(input.startsWith(STREAMS_READ) || input.startsWith(STREAMS_EDIT) ||
input.startsWith(DASHBOARDS_READ) || input.startsWith(DASHBOARDS_EDIT));
}
}));
for (String streampermission : formData.streampermissions) {
permissions.add(RestPermissions.STREAMS_READ + ":" + streampermission);
}
for (String streameditpermission : formData.streameditpermissions) {
permissions.add(RestPermissions.STREAMS_EDIT + ":" + streameditpermission);
}
for (String dashboardpermission : formData.dashboardpermissions) {
permissions.add(RestPermissions.DASHBOARDS_READ + ":" + dashboardpermission);
}
for (String dashboardeditpermissions : formData.dashboardeditpermissions) {
permissions.add(RestPermissions.DASHBOARDS_EDIT + ":" + dashboardeditpermissions);
}
final ChangeUserRequest changeRequest = formData.toApiRequest();
changeRequest.permissions = Lists.newArrayList(permissions);
user.update(changeRequest);
return redirect(routes.UsersController.index());
}