Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions readingbat-core/src/main/kotlin/com/readingbat/dsl/ContentDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,14 @@ fun readingBatContent(block: ReadingBatContent.() -> Unit) =
/** Returns true if the server is running in production mode. Accessible from Content.kt DSL files. */
fun isProduction() = IS_PRODUCTION.getProperty(false)

/** Returns true if the server is running in test mode. Accessible from Content.kt DSL files. */
fun isTesting() = IS_TESTING.getProperty(false)
/**
* Returns true if the server is running in test mode. Accessible from Content.kt DSL files.
*
* IS_TESTING is not part of [initProperties] (it is set directly via setProperty in tests and
* defaults to false in production), so it is read with errorOnNonInit = false: the single global
* init guard can never meaningfully flag this specific property anyway.
*/
fun isTesting() = IS_TESTING.getProperty(false, errorOnNonInit = false)

internal fun isDbmsEnabled() = DBMS_ENABLED.getProperty(false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.readingbat.dsl

import com.pambrose.common.util.ContentRoot
import com.pambrose.common.util.ContentSource
import com.pambrose.common.util.asRegex
import com.pambrose.common.util.decode
import com.pambrose.common.util.pathOf
Expand Down Expand Up @@ -52,15 +51,10 @@ class LanguageGroup<T : Challenge>(
val challengeGroups = mutableListOf<ChallengeGroup<T>>()

/**
* The content source for this language's challenge files. Defaults to the parent
* [ReadingBatContent.repo] value. Must be set to a valid source before challenges are loaded.
* The content source for this language's challenge files. Inherits the parent
* [ReadingBatContent.repo] value unless overridden in the DSL.
*/
var repo: ContentRoot = content.repo // Defaults to outer-level value
get() =
if (field == defaultContentRoot)
error("$languageName section is missing a repo value")
else
field

/** Git branch name for remote content. Defaults to the parent [ReadingBatContent.branchName]. */
var branchName = content.branchName // Defaults to outer-level value
Expand Down Expand Up @@ -145,18 +139,5 @@ class LanguageGroup<T : Challenge>(
companion object {
private val logger = KotlinLogging.logger {}
private val excludes = Regex("^__.*__.*$")

internal val defaultContentRoot =
object : ContentRoot {
override val sourcePrefix = ""
override val remote = false

override fun file(path: String) =
object : ContentSource {
override val content = ""
override val remote = false
override val source = ""
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,11 @@ internal object ClassSummaryPage {
throw InvalidRequestException("Invalid user")
}

classCode.fetchClassTeacherId() != user.userId -> {
val teacherId = classCode.fetchClassTeacherId()
throw InvalidRequestException("User id ${user.userId} does not match class code's teacher id $teacherId")
}

else -> {
// Do nothing
// Look up the teacher id once and reuse it for both the check and the message.
val teacherId = classCode.fetchClassTeacherId()
if (teacherId != user.userId)
throw InvalidRequestException("User id ${user.userId} does not match class code's teacher id $teacherId")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,12 @@ internal object StudentSummaryPage {
throw InvalidRequestException("Invalid user")
}

// classCode != activeClassCode -> throw InvalidRequestException("Class code mismatch")
classCode.fetchClassTeacherId() != user.userId -> {
val teacherId = classCode.fetchClassTeacherId()
throw InvalidRequestException("User id ${user.userId} does not match class code's teacher Id $teacherId")
}

else -> {
// Do nothing
// classCode != activeClassCode -> throw InvalidRequestException("Class code mismatch")
// Look up the teacher id once and reuse it for both the check and the message.
val teacherId = classCode.fetchClassTeacherId()
if (teacherId != user.userId)
throw InvalidRequestException("User id ${user.userId} does not match class code's teacher Id $teacherId")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ object WsCommon {
false to "Invalid user id: ${user.userId}"
}

classCode.fetchClassTeacherId() != user.userId -> {
val teacherId = classCode.fetchClassTeacherId()
false to "User id ${user.userId} does not match class code's teacher Id $teacherId"
}

else -> {
true to ""
// Look up the teacher id once and reuse it for both the check and the message.
val teacherId = classCode.fetchClassTeacherId()
if (teacherId != user.userId)
false to "User id ${user.userId} does not match class code's teacher Id $teacherId"
else
true to ""
}
}.also { (valid, msg) -> if (!valid) throw InvalidRequestException(msg) }

Expand Down
Loading