add db-table configuration (WIP)
This commit is contained in:
@@ -1,23 +1,31 @@
|
||||
package de.mbremer.secutity;
|
||||
|
||||
import de.mbremer.configuration.Configuration;
|
||||
import de.mbremer.room.Room;
|
||||
import de.mbremer.traffic.TrafficAdminForm;
|
||||
import de.mbremer.traffic.TrafficUserForm;
|
||||
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
|
||||
import io.quarkus.panache.common.Sort;
|
||||
import io.quarkus.qute.Location;
|
||||
import io.quarkus.qute.Template;
|
||||
import io.quarkus.qute.TemplateInstance;
|
||||
import io.quarkus.security.identity.SecurityIdentity;
|
||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.jboss.resteasy.annotations.jaxrs.PathParam;
|
||||
import org.jboss.resteasy.annotations.providers.multipart.MultipartForm;
|
||||
|
||||
import javax.annotation.security.PermitAll;
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.transaction.Transactional;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.NewCookie;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.net.URI;
|
||||
import java.util.Optional;
|
||||
|
||||
import static de.mbremer.secutity.Role.ADMIN;
|
||||
|
||||
@@ -36,6 +44,9 @@ public class UserResource {
|
||||
@Inject
|
||||
@Location("user.html")
|
||||
Template userTemplate;
|
||||
// TODO: 12.10.21
|
||||
// @ConfigProperty(name = "google_api_key")
|
||||
// Optional<String> googleApiKey;
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.TEXT_HTML)
|
||||
@@ -44,11 +55,14 @@ public class UserResource {
|
||||
TemplateInstance templateInstance = userTemplate
|
||||
.data("current_user", User.find("username", identity.getPrincipal().getName()).singleResult());
|
||||
|
||||
// log.info("Google-API-Key" + googleApiKey.orElse("-"));
|
||||
|
||||
if (identity.hasRole("ADMIN")) {
|
||||
templateInstance
|
||||
.data("is_admin", true)
|
||||
.data("users", User.listAll(Sort.by("username")))
|
||||
.data("rooms", Room.listAll(Sort.by("name")));
|
||||
// .data("google_api_key", googleApiKey.orElse(""));
|
||||
}
|
||||
|
||||
return templateInstance;
|
||||
@@ -144,4 +158,35 @@ public class UserResource {
|
||||
|
||||
return getUser();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Produces(MediaType.TEXT_HTML)
|
||||
@Transactional
|
||||
@Path("/traffic/config/")
|
||||
public TemplateInstance configureTrafficAdmin(@MultipartForm TrafficAdminForm trafficAdminForm) {
|
||||
log.info("configure traffic");
|
||||
|
||||
try {
|
||||
Configuration apiKeyConfig = Configuration.find("propertyName", "google_api_key").singleResult();
|
||||
apiKeyConfig.setValue(trafficAdminForm.googleApiKey);
|
||||
log.info("update API-Key: " + trafficAdminForm.googleApiKey);
|
||||
} catch (NoResultException e) {
|
||||
new Configuration("google_api_key", trafficAdminForm.googleApiKey).persist();
|
||||
log.info("create API-Key: " + trafficAdminForm.googleApiKey);
|
||||
}
|
||||
|
||||
return getUser();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Produces(MediaType.TEXT_HTML)
|
||||
@Transactional
|
||||
@Path("/traffic/config/{username}")
|
||||
public TemplateInstance configureTrafficUser(@PathParam("username") String username, @MultipartForm TrafficUserForm trafficUserForm) {
|
||||
log.info("configure traffic for " + username);
|
||||
|
||||
return getUser();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user