(fix) Konfiguration-Setup Umbau zu SCS

This commit is contained in:
stefan 2025-07-19 14:19:05 +02:00
parent e38ab27fbe
commit db465e461e
5 changed files with 13 additions and 25 deletions

View File

@ -124,7 +124,7 @@ logging.responses=false
Die Konfiguration wird über die zentrale `AppConfig`-Klasse bereitgestellt: Die Konfiguration wird über die zentrale `AppConfig`-Klasse bereitgestellt:
```kotlin ```kotlin
import at.mocode.shared.config.AppConfig 'import at.mocode.shared.config.AppConfig'
// Verwendung der Konfiguration // Verwendung der Konfiguration
fun example() { fun example() {

View File

@ -2,15 +2,9 @@ package at.mocode.gateway
import at.mocode.gateway.config.MigrationSetup import at.mocode.gateway.config.MigrationSetup
import at.mocode.shared.config.AppConfig import at.mocode.shared.config.AppConfig
import at.mocode.shared.database.DatabaseConfig
import at.mocode.shared.database.DatabaseFactory import at.mocode.shared.database.DatabaseFactory
import io.ktor.serialization.kotlinx.json.*
import io.ktor.server.application.*
import io.ktor.server.engine.* import io.ktor.server.engine.*
import io.ktor.server.netty.* import io.ktor.server.netty.*
import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
fun main() { fun main() {
// Konfiguration laden (wird automatisch beim ersten Zugriff auf AppConfig initialisiert) // Konfiguration laden (wird automatisch beim ersten Zugriff auf AppConfig initialisiert)

View File

@ -91,7 +91,7 @@ class VeranstaltungRepositoryImpl : VeranstaltungRepository {
val now = Clock.System.now() val now = Clock.System.now()
val updatedVeranstaltung = veranstaltung.copy(updatedAt = now) val updatedVeranstaltung = veranstaltung.copy(updatedAt = now)
// Check if record exists // Check if a record exists
val existingRecord = VeranstaltungTable.selectAll() val existingRecord = VeranstaltungTable.selectAll()
.where { VeranstaltungTable.id eq veranstaltung.veranstaltungId } .where { VeranstaltungTable.id eq veranstaltung.veranstaltungId }
.singleOrNull() .singleOrNull()
@ -103,7 +103,7 @@ class VeranstaltungRepositoryImpl : VeranstaltungRepository {
} }
updatedVeranstaltung updatedVeranstaltung
} else { } else {
// Insert new record // Insert a new record
VeranstaltungTable.insert { VeranstaltungTable.insert {
it[id] = veranstaltung.veranstaltungId it[id] = veranstaltung.veranstaltungId
veranstaltungToStatement(it, updatedVeranstaltung) veranstaltungToStatement(it, updatedVeranstaltung)

View File

@ -1,15 +1,9 @@
package at.mocode.members.domain.service package at.mocode.members.domain.service
import at.mocode.members.domain.model.DomUser
import at.mocode.members.domain.repository.UserRepository
import at.mocode.members.domain.repository.PersonRolleRepository
import at.mocode.members.domain.repository.RolleRepository
import at.mocode.members.domain.repository.RolleBerechtigungRepository
import at.mocode.members.domain.repository.BerechtigungRepository
import at.mocode.enums.RolleE
import at.mocode.enums.BerechtigungE import at.mocode.enums.BerechtigungE
import at.mocode.enums.RolleE
import at.mocode.members.domain.repository.*
import com.benasher44.uuid.Uuid import com.benasher44.uuid.Uuid
import kotlinx.datetime.LocalDate
import kotlinx.datetime.Clock import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone import kotlinx.datetime.TimeZone
import kotlinx.datetime.todayIn import kotlinx.datetime.todayIn
@ -44,16 +38,16 @@ class UserAuthorizationService(
* Fetches complete authorization information for a user. * Fetches complete authorization information for a user.
* *
* @param userId The user ID * @param userId The user ID
* @return UserAuthInfo if user exists and is active, null otherwise * @return UserAuthInfo if the user exists and is active, null otherwise
*/ */
suspend fun getUserAuthInfo(userId: Uuid): UserAuthInfo? { suspend fun getUserAuthInfo(userId: Uuid): UserAuthInfo? {
// Get user // Get user
val user = userRepository.findById(userId) ?: return null val user = userRepository.findById(userId) ?: return null
// Check if user is active // Check if the user is active
if (!user.istAktiv) return null if (!user.istAktiv) return null
// Check if user is locked // Check if the user is locked
val now = Clock.System.now() val now = Clock.System.now()
if (user.gesperrtBis != null && user.gesperrtBis!! > now) return null if (user.gesperrtBis != null && user.gesperrtBis!! > now) return null
@ -77,10 +71,10 @@ class UserAuthorizationService(
* Fetches authorization information for a user by username or email. * Fetches authorization information for a user by username or email.
* *
* @param usernameOrEmail The username or email * @param usernameOrEmail The username or email
* @return UserAuthInfo if user exists and is active, null otherwise * @return UserAuthInfo if the user exists and is active, null otherwise
*/ */
suspend fun getUserAuthInfoByUsernameOrEmail(usernameOrEmail: String): UserAuthInfo? { suspend fun getUserAuthInfoByUsernameOrEmail(usernameOrEmail: String): UserAuthInfo? {
// Try to find user by username first // Try to find the user by username first
val user = userRepository.findByUsername(usernameOrEmail) val user = userRepository.findByUsername(usernameOrEmail)
?: userRepository.findByEmail(usernameOrEmail) ?: userRepository.findByEmail(usernameOrEmail)
?: return null ?: return null
@ -152,7 +146,7 @@ class UserAuthorizationService(
* *
* @param userId The user ID * @param userId The user ID
* @param role The role to check * @param role The role to check
* @return true if user has the role, false otherwise * @return true if the user has the role, false otherwise
*/ */
suspend fun hasRole(userId: Uuid, role: RolleE): Boolean { suspend fun hasRole(userId: Uuid, role: RolleE): Boolean {
val authInfo = getUserAuthInfo(userId) ?: return false val authInfo = getUserAuthInfo(userId) ?: return false
@ -164,7 +158,7 @@ class UserAuthorizationService(
* *
* @param userId The user ID * @param userId The user ID
* @param permission The permission to check * @param permission The permission to check
* @return true if user has the permission, false otherwise * @return true if the user has the permission, false otherwise
*/ */
suspend fun hasPermission(userId: Uuid, permission: BerechtigungE): Boolean { suspend fun hasPermission(userId: Uuid, permission: BerechtigungE): Boolean {
val authInfo = getUserAuthInfo(userId) ?: return false val authInfo = getUserAuthInfo(userId) ?: return false

View File

@ -19,7 +19,7 @@ enum class AppEnvironment {
val envName = System.getenv("APP_ENV")?.uppercase() ?: "DEVELOPMENT" val envName = System.getenv("APP_ENV")?.uppercase() ?: "DEVELOPMENT"
return try { return try {
valueOf(envName) valueOf(envName)
} catch (e: IllegalArgumentException) { } catch (_: IllegalArgumentException) {
println("Warnung: Unbekannte Umgebung '$envName', verwende DEVELOPMENT") println("Warnung: Unbekannte Umgebung '$envName', verwende DEVELOPMENT")
DEVELOPMENT DEVELOPMENT
} }