Skip to content

Commit

Permalink
feat(api): claim status
Browse files Browse the repository at this point in the history
remove the claim profile
added noclaim profile that will create initial user accounts if none exist

related to #207
  • Loading branch information
gotson committed Jul 5, 2020
1 parent c98bcb0 commit 47dd2f6
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/**",
Expand Down Expand Up @@ -89,8 +92,7 @@ class SecurityConfiguration(
"/js/**",
"/favicon.ico",
"/",
"/index.html",
"/api/v1/claim"
"/index.html"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -39,4 +42,8 @@ class ClaimController(
)
).toDto()
}

data class ClaimStatus(
val isClaimed: Boolean
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 47dd2f6

Please sign in to comment.