-
Notifications
You must be signed in to change notification settings - Fork 14
Add support for a custom "home" icon #2696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
f7ffaeb
to
73dcf09
Compare
73dcf09
to
2909895
Compare
components/admin-config/backend/src/main/kotlin/endpoints/GetConfigByKey.kt
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
HttpStatusCode.InternalServerError to { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return BadRequest
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the endpoint returns InternalServerError
when a non-existing key is requested for, so I don't quite understand how I can force that behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This happens because enumValueOf<ConfigKey>
below throws an exception when the key is invalid and you do not catch it, so the catch-all hanlder in StatusPages.kt
in core
turns it into an internal server error.
Instead, you should catch the exception and return a meaningful error response like so:
val keyParameter = call.requireParameter("key")
val key = runCatching {
enumValueOf<ConfigKey>(keyParameter)
}.getOrElse {
call.respond(HttpStatusCode.BadRequest, ErrorResponse("Invalid config key $keyParameter.", "Allowed keys are: ..."))
return@get
}
You could also throw an exception that is mapped to BadRequest
in StatusPages.kt
, but this global error handling does not play well with the idea that component should be self-contained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I avoided the circular dependency problem by mapping the error response locally to a structure similar to the ErrorResponse
class. Also verified that the error toast is rendered properly. While this isn't as elegant as using ErrorResponse
directly for typing of the response, I hope it is sufficient for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to move ErrorResponse
to :shared:ktor-utils
but it can be done in a follow-up.
components/admin-config/backend/src/main/kotlin/endpoints/InsertOrUpdateConfig.kt
Outdated
Show resolved
Hide resolved
HttpStatusCode.OK to { | ||
description = "The configuration entry was successfully inserted or updated." | ||
} | ||
HttpStatusCode.InternalServerError to { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return BadRequest
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as before.
...onents/admin-config/backend/src/test/kotlin/endpoints/InsertOrUpdateConfigIntegrationTest.kt
Show resolved
Hide resolved
...onents/admin-config/backend/src/test/kotlin/endpoints/InsertOrUpdateConfigIntegrationTest.kt
Outdated
Show resolved
Hide resolved
...onents/admin-config/backend/src/test/kotlin/endpoints/InsertOrUpdateConfigIntegrationTest.kt
Show resolved
Hide resolved
...onents/admin-config/backend/src/test/kotlin/endpoints/InsertOrUpdateConfigIntegrationTest.kt
Show resolved
Hide resolved
2909895
to
6de5614
Compare
b153d48
to
106d681
Compare
Add a table to store key-value pairs which can be used for example for tailoring the ORT Server UI. To prevent unwanted insertion of arbitrary keys to the table, the table key (which acts as the primary key) is specified with an `enum` with a default value. Extending the table for future needs will be done by extending the `enum`. `isEnabled` will be used for the purposes of the UI to - toggle the specified configuration property on/off to see the effect in the UI - handle gracefully the case of a missing configuration parameter in the database. In this case, the `get()` function returns the default value of the `enum` with `isEnabled=false` so the UI can fall back to using a default value of the UI element This mechanism will be clarified in further commits. Signed-off-by: Jyrki Keisala <[email protected]>
106d681
to
918e6cb
Compare
In case of the configuration parameter missing in database, `getConfigByKey` returns the default value of the enumerated key with `isEnabled=false`, to be able to fall back to using the pre-configured default UI element. `insertOrUpdateConfig` uses `upsert` which adds a new configuration entry to the database in case it doesn't exist yet. The authorization tests are all implemented in a single class for performance reasons, because the Keycloak testcontainer takes a while to start. Signed-off-by: Jyrki Keisala <[email protected]>
In case of the configuration entry for the tailored home icon is missing from the database, fall back to showing the pre-configured default home icon (ORT Server favicon). Signed-off-by: Jyrki Keisala <[email protected]>
With the form the admin can provide a public URL to the home icon. The icon can be toggled on/off to see the effect in the UI. Resolves #2591. Signed-off-by: Jyrki Keisala <[email protected]>
Signed-off-by: Jyrki Keisala <[email protected]>
918e6cb
to
e263de9
Compare
This PR adds a table for storing key-value pairs for UI configuration, and endpoints for getting, inserting and updating the stored configuration values. A minimal UI is implemented as the first use case of the table: