mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-15 08:15:37 +00:00
Refine error handling in UI
Implement SystemEndpoint
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
package de.grimsi.gameyfin.config
|
||||
|
||||
enum class Roles(val roleName: String) {
|
||||
SUPERADMIN("ROLE_SUPERADMIN"),
|
||||
ADMIN("ROLE_ADMIN"),
|
||||
USER("ROLE_USER")
|
||||
SUPERADMIN(Names.SUPERADMIN),
|
||||
ADMIN(Names.ADMIN),
|
||||
USER(Names.USER);
|
||||
|
||||
// necessary for the ability to use the Roles class in the @RolesAllowed annotation
|
||||
class Names {
|
||||
companion object {
|
||||
const val SUPERADMIN = "ROLE_SUPERADMIN"
|
||||
const val ADMIN = "ROLE_ADMIN"
|
||||
const val USER = "ROLE_USER"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,13 +29,16 @@ class SetupDataLoader(
|
||||
log.info { "We will now set up some data..." }
|
||||
|
||||
setupRoles()
|
||||
//setupUsers()
|
||||
setupUsers()
|
||||
|
||||
log.info { "Setup completed..." }
|
||||
log.info { "Visit http://${InetAddress.getLocalHost().hostName}:${env.getProperty("server.port")}/setup to complete the setup" }
|
||||
}
|
||||
|
||||
fun setupUsers() {
|
||||
|
||||
log.info { "Setting up users..." }
|
||||
|
||||
val superadmin = User(
|
||||
username = "admin",
|
||||
password = "admin"
|
||||
@@ -49,6 +52,8 @@ class SetupDataLoader(
|
||||
)
|
||||
|
||||
userService.registerUser(user, Roles.USER)
|
||||
|
||||
log.info { "User setup completed." }
|
||||
}
|
||||
|
||||
fun setupRoles() {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package de.grimsi.gameyfin.system
|
||||
|
||||
import de.grimsi.gameyfin.config.Roles
|
||||
import dev.hilla.Endpoint
|
||||
import jakarta.annotation.security.RolesAllowed
|
||||
|
||||
@Endpoint
|
||||
class SystemEndpoint(
|
||||
private val systemService: SystemService
|
||||
) {
|
||||
|
||||
@RolesAllowed(Roles.Names.SUPERADMIN, Roles.Names.ADMIN)
|
||||
fun restart() {
|
||||
systemService.restart()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package de.grimsi.gameyfin.system
|
||||
|
||||
import org.springframework.cloud.context.restart.RestartEndpoint
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
class SystemService(
|
||||
private val restartEndpoint: RestartEndpoint,
|
||||
) {
|
||||
fun restart() {
|
||||
restartEndpoint.restart()
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,7 @@ import org.springframework.security.core.context.SecurityContextHolder
|
||||
|
||||
@Endpoint
|
||||
class UserEndpoint(
|
||||
private val userService: UserService,
|
||||
private val roleService: RoleService,
|
||||
private val userService: UserService
|
||||
) {
|
||||
|
||||
@PermitAll
|
||||
|
||||
@@ -7,6 +7,7 @@ import jakarta.validation.constraints.NotNull
|
||||
@Entity
|
||||
class Role(
|
||||
@NotNull
|
||||
@Column(unique = true)
|
||||
var rolename: String,
|
||||
|
||||
@Id
|
||||
|
||||
@@ -8,23 +8,27 @@ import jakarta.validation.constraints.NotNull
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
class User(
|
||||
@field:NotNull
|
||||
@NotNull
|
||||
@Column(unique = true)
|
||||
var username: String,
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
var id: Long? = null,
|
||||
|
||||
@field:NotNull
|
||||
@NotNull
|
||||
var password: String,
|
||||
|
||||
@field:Nullable
|
||||
@Nullable
|
||||
@Column(unique = true)
|
||||
var email: String? = null,
|
||||
|
||||
var email_confirmed: Boolean = false,
|
||||
|
||||
var enabled: Boolean = true,
|
||||
|
||||
@Embedded
|
||||
@field:Nullable
|
||||
@Nullable
|
||||
var avatar: Avatar? = null,
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
|
||||
@@ -7,6 +7,14 @@ server:
|
||||
session:
|
||||
tracking-modes: cookie
|
||||
|
||||
management:
|
||||
endpoints.web.exposure.include: '*'
|
||||
endpoint:
|
||||
pause:
|
||||
enabled: false
|
||||
restart:
|
||||
enabled: true
|
||||
|
||||
spring:
|
||||
# Workaround for https://github.com/vaadin/hilla/issues/842
|
||||
devtools.restart.additional-exclude: dev/hilla/openapi.json
|
||||
|
||||
Reference in New Issue
Block a user