mirror of
https://github.com/gotson/komga.git
synced 2025-12-20 23:45:11 +01:00
feat(api): claim status
remove the claim profile added noclaim profile that will create initial user accounts if none exist related to #207
This commit is contained in:
parent
c98bcb0036
commit
47dd2f66e0
7 changed files with 25 additions and 13 deletions
|
|
@ -1,9 +1,9 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="komga [bootRun] dev,demo" type="GradleRunConfiguration" factoryName="Gradle">
|
||||
<configuration default="false" name="komga [bootRun] dev,demo,noclaim" type="GradleRunConfiguration" factoryName="Gradle">
|
||||
<ExternalSystemSettings>
|
||||
<option name="env">
|
||||
<map>
|
||||
<entry key="SPRING_PROFILES_ACTIVE" value="dev,demo" />
|
||||
<entry key="SPRING_PROFILES_ACTIVE" value="dev,demo,noclaim" />
|
||||
</map>
|
||||
</option>
|
||||
<option name="executionName" />
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="komga [bootRun] dev,localdb" type="GradleRunConfiguration" factoryName="Gradle">
|
||||
<configuration default="false" name="komga [bootRun] dev,localdb,noclaim" type="GradleRunConfiguration" factoryName="Gradle">
|
||||
<ExternalSystemSettings>
|
||||
<option name="env">
|
||||
<map>
|
||||
<entry key="SPRING_PROFILES_ACTIVE" value="dev,localdb" />
|
||||
<entry key="SPRING_PROFILES_ACTIVE" value="dev,localdb,noclaim" />
|
||||
</map>
|
||||
</option>
|
||||
<option name="executionName" />
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="komga [bootRun] dev,claim" type="GradleRunConfiguration" factoryName="Gradle">
|
||||
<configuration default="false" name="komga [bootRun] dev,noclaim" type="GradleRunConfiguration" factoryName="Gradle">
|
||||
<ExternalSystemSettings>
|
||||
<option name="env">
|
||||
<map>
|
||||
<entry key="SPRING_PROFILES_ACTIVE" value="dev,claim" />
|
||||
<entry key="SPRING_PROFILES_ACTIVE" value="dev,noclaim" />
|
||||
</map>
|
||||
</option>
|
||||
<option name="executionName" />
|
||||
|
|
@ -28,6 +28,9 @@ Komga is composed of 2 projects:
|
|||
Komga uses Spring Profiles extensively:
|
||||
- `dev`: add more logging, disable periodic scanning, in-memory database
|
||||
- `localdb`: a dev profile that stores the database in `./testdb`.
|
||||
- `noclaim`: will create initial users at startup if none exist and output users and passwords in the standard output
|
||||
- if `dev` is active, will create `admin@example.org` with password `admin`, and `user@example.org` with password `user`
|
||||
- if `dev` is not active, will create `admin@example.org` with a random password
|
||||
|
||||
### Gradle tasks
|
||||
|
||||
|
|
@ -40,8 +43,8 @@ Here is a list of useful tasks:
|
|||
- `jooq-codegen-primary`: generates the jOOQ DSL.
|
||||
|
||||
`bootRun` needs to be run with a profile or list of profiles, usually:
|
||||
- `dev`: when testing with a blank database
|
||||
- `dev,localdb`: when testing with an existing database
|
||||
- `dev,noclaim`: when testing with a blank database
|
||||
- `dev,localdb,noclaim`: when testing with an existing database
|
||||
|
||||
There are few ways you can run the task with a profile:
|
||||
- `./gradlew bootRun --args='--spring.profiles.active=dev'`
|
||||
|
|
|
|||
|
|
@ -44,6 +44,9 @@ class SecurityConfiguration(
|
|||
// restrict H2 console to ADMIN only
|
||||
.requestMatchers(PathRequest.toH2Console()).hasRole(ROLE_ADMIN)
|
||||
|
||||
// claim is unprotected
|
||||
.antMatchers("/api/v1/claim").permitAll()
|
||||
|
||||
// all other endpoints are restricted to authenticated users
|
||||
.antMatchers(
|
||||
"/api/**",
|
||||
|
|
@ -89,8 +92,7 @@ class SecurityConfiguration(
|
|||
"/js/**",
|
||||
"/favicon.ico",
|
||||
"/",
|
||||
"/index.html",
|
||||
"/api/v1/claim"
|
||||
"/index.html"
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ import org.gotson.komga.domain.model.KomgaUser
|
|||
import org.gotson.komga.domain.service.KomgaUserLifecycle
|
||||
import org.gotson.komga.interfaces.rest.dto.UserDto
|
||||
import org.gotson.komga.interfaces.rest.dto.toDto
|
||||
import org.springframework.context.annotation.Profile
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.validation.annotation.Validated
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestHeader
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
|
|
@ -16,13 +16,16 @@ import org.springframework.web.server.ResponseStatusException
|
|||
import javax.validation.constraints.Email
|
||||
import javax.validation.constraints.NotBlank
|
||||
|
||||
@Profile("claim")
|
||||
@RestController
|
||||
@RequestMapping("api/v1/claim", produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||
@Validated
|
||||
class ClaimController(
|
||||
private val userDetailsLifecycle: KomgaUserLifecycle
|
||||
) {
|
||||
|
||||
@GetMapping
|
||||
fun getClaimStatus() = ClaimStatus(userDetailsLifecycle.countUsers() > 0)
|
||||
|
||||
@PostMapping
|
||||
fun claimAdmin(
|
||||
@Email @RequestHeader("X-Komga-Email") email: String,
|
||||
|
|
@ -39,4 +42,8 @@ class ClaimController(
|
|||
)
|
||||
).toDto()
|
||||
}
|
||||
|
||||
data class ClaimStatus(
|
||||
val isClaimed: Boolean
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import org.springframework.stereotype.Component
|
|||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
@Profile("!(test | claim)")
|
||||
@Profile("!test & noclaim")
|
||||
@Component
|
||||
class InitialUserController(
|
||||
private val userLifecycle: KomgaUserLifecycle,
|
||||
|
|
|
|||
Loading…
Reference in a new issue