Skip to content

Commit

Permalink
Saving will now trigger event that will refresh all Cogboard instance…
Browse files Browse the repository at this point in the history
…s - CR fixes
  • Loading branch information
szymon.owczarzak committed Apr 1, 2021
1 parent 1499e1d commit 9e0528b
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class CogboardConstants {

class StatusCode {
companion object {
const val `401` = 401
const val `200` = 200
const val a401 = 401
const val a200 = 200
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,20 @@ import com.cognifide.cogboard.CogboardConstants.EventType
import com.cognifide.cogboard.CogboardConstants.Props
import io.vertx.core.Vertx
import io.vertx.core.json.JsonObject
import io.vertx.core.logging.Logger
import io.vertx.core.logging.LoggerFactory

class ConfirmationSender(private val vertx: Vertx) {

fun sendOk() {
vertx.eventBus().send(Event.SEND_MESSAGE_TO_WEBSOCKET, JsonObject().message(OK_MESSAGE))
}

fun sendError(body: JsonObject) {
LOGGER.error("$ERROR_MESSAGE \nconfig:\n$body")
vertx.eventBus().send(Event.SEND_MESSAGE_TO_WEBSOCKET, JsonObject().message(ERROR_MESSAGE))
}

private fun JsonObject.message(message: String): JsonObject {
return this
.put(Props.EVENT_TYPE, EventType.CONFIG_SAVED)
.put("message", message)
}

companion object {
private val LOGGER: Logger = LoggerFactory.getLogger(ConfirmationSender::class.java)
private const val OK_MESSAGE = "Configuration saved"
private const val ERROR_MESSAGE = "Configuration not saved - wrong configuration"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ class LoginHandler(val storage: Storage = VolumeStorageFactory.admin()) : Routin
admin.password.isNotBlank() && admin.password == password

private fun sendUnauthorized(ctx: RoutingContext, message: String) {
ctx.response().setStatusMessage(message).setStatusCode(StatusCode.`401`).end()
ctx.response().setStatusMessage(message).setStatusCode(StatusCode.a401).end()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ class SessionHandler(val storage: Storage = VolumeStorageFactory.admin()) : Rout
}

private fun sendUnauthorized(ctx: RoutingContext, message: String) {
ctx.response().setStatusMessage(message).setStatusCode(StatusCode.`401`).end()
ctx.response().setStatusMessage(message).setStatusCode(StatusCode.a401).end()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ abstract class BaseWidget(
}

fun checkAuthorized(responseBody: JsonObject): Boolean {
val statusCode = responseBody.getInteger(Props.STATUS_CODE, StatusCode.`200`)
return if (statusCode == StatusCode.`401`) {
val statusCode = responseBody.getInteger(Props.STATUS_CODE, StatusCode.a200)
return if (statusCode == StatusCode.a401) {
sendConfigurationError("Unauthorized")
false
} else true
Expand Down
2 changes: 1 addition & 1 deletion detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ style:
active: false
ReturnCount:
active: true
max: 2
max: 3
excludedFunctions: "equals"
excludeLabeled: false
excludeReturnFromLambda: true
Expand Down

0 comments on commit 9e0528b

Please sign in to comment.