-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Unify various API endpoints related to config
More details in the linked issue. Closes #1960
- Loading branch information
Showing
34 changed files
with
308 additions
and
530 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
backend/capellacollab/settings/configuration/unifiedconfig/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 |
25 changes: 25 additions & 0 deletions
25
backend/capellacollab/settings/configuration/unifiedconfig/models.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from capellacollab.core import pydantic as core_pydantic | ||
from capellacollab.settings.configuration import models as config_models | ||
|
||
|
||
class Metadata(core_pydantic.BaseModel): | ||
version: str | ||
privacy_policy_url: str | None | ||
imprint_url: str | None | ||
provider: str | None | ||
authentication_provider: str | None | ||
environment: str | None | ||
|
||
host: str | None | ||
port: str | None | ||
protocol: str | None | ||
|
||
|
||
class UnifiedConfig(core_pydantic.BaseModel): | ||
metadata: Metadata | ||
feedback: config_models.FeedbackConfiguration | ||
navbar: config_models.NavbarConfiguration | ||
beta: config_models.BetaConfiguration |
27 changes: 27 additions & 0 deletions
27
backend/capellacollab/settings/configuration/unifiedconfig/routes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import fastapi | ||
from sqlalchemy import orm | ||
|
||
from capellacollab.core import database | ||
from capellacollab.settings.configuration import core as config_core | ||
from capellacollab.settings.configuration.unifiedconfig import models, util | ||
|
||
router = fastapi.APIRouter() | ||
|
||
|
||
@router.get( | ||
"/unified", | ||
) | ||
def get_unified_config( | ||
db: orm.Session = fastapi.Depends(database.get_db), | ||
) -> models.UnifiedConfig: | ||
cfg = config_core.get_global_configuration(db) | ||
|
||
return models.UnifiedConfig( | ||
metadata=util.get_metadata(cfg), | ||
feedback=util.get_feedback(cfg), | ||
beta=util.get_beta(cfg), | ||
navbar=util.get_navbar(cfg), | ||
) |
47 changes: 47 additions & 0 deletions
47
backend/capellacollab/settings/configuration/unifiedconfig/util.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import capellacollab | ||
from capellacollab.config import config | ||
from capellacollab.settings.configuration import models as config_models | ||
from capellacollab.settings.configuration.unifiedconfig import models | ||
|
||
|
||
def get_metadata( | ||
global_config: config_models.GlobalConfiguration, | ||
) -> models.Metadata: | ||
return models.Metadata.model_validate( | ||
global_config.metadata.model_dump() | ||
| { | ||
"version": capellacollab.__version__, | ||
"host": config.general.host, | ||
"port": str(config.general.port), | ||
"protocol": config.general.scheme, | ||
} | ||
) | ||
|
||
|
||
def get_feedback( | ||
global_config: config_models.GlobalConfiguration, | ||
) -> config_models.FeedbackConfiguration: | ||
feedback = global_config.feedback | ||
if not (config.smtp and config.smtp.enabled): | ||
feedback.enabled = False | ||
feedback.after_session = False | ||
feedback.on_footer = False | ||
feedback.on_session_card = False | ||
feedback.interval.enabled = False | ||
|
||
return feedback | ||
|
||
|
||
def get_navbar( | ||
global_config: config_models.GlobalConfiguration, | ||
) -> config_models.NavbarConfiguration: | ||
return global_config.navbar | ||
|
||
|
||
def get_beta( | ||
global_config: config_models.GlobalConfiguration, | ||
) -> config_models.BetaConfiguration: | ||
return global_config.beta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.