Skip to content

Commit 98e7c0a

Browse files
authored
feat/ISD-3609: Add multi-level category setting to charm config (#341)
* feat/ISD-3609: Add multi-level category setting to charm config * feat/ISD-3609: Adding a config check to make sure the setting is either 2 or 3.
1 parent a886fb2 commit 98e7c0a

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ options:
3535
type: boolean
3636
description: "Force SAML login (full screen, no local database logins)."
3737
default: false
38+
max_category_nesting:
39+
type: int
40+
description: "Maximum category nesting allowed. Minimum is 2, maximum is 3."
41+
default: 2
3842
saml_sync_groups:
3943
type: string
4044
description: "Comma-separated list of groups to sync from SAML provider."

src/charm.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
f"{DISCOURSE_PATH}/log/unicorn.stderr.log",
7070
f"{DISCOURSE_PATH}/log/unicorn.stdout.log",
7171
]
72+
MAX_CATEGORY_NESTING_LEVELS = [2, 3]
7273
PROMETHEUS_PORT = 3000
7374
REQUIRED_S3_SETTINGS = ["s3_access_key_id", "s3_bucket", "s3_region", "s3_secret_access_key"]
7475
SCRIPT_PATH = "/srv/scripts"
@@ -311,7 +312,11 @@ def _is_config_valid(self) -> bool:
311312
and self.model.get_relation(DEFAULT_RELATION_NAME) is None
312313
):
313314
errors.append("force_saml_login cannot be true without a saml relation")
314-
315+
if self.config["max_category_nesting"] not in MAX_CATEGORY_NESTING_LEVELS:
316+
errors.append(
317+
"max_category_nesting must be one of: "
318+
f"{', '.join(map(str, MAX_CATEGORY_NESTING_LEVELS))}"
319+
)
315320
if (
316321
self.config["saml_sync_groups"]
317322
and self.model.get_relation(DEFAULT_RELATION_NAME) is None
@@ -465,6 +470,7 @@ def _create_discourse_environment_settings(self) -> typing.Dict[str, str]:
465470
"DISCOURSE_DEVELOPER_EMAILS": self.config["developer_emails"],
466471
"DISCOURSE_ENABLE_CORS": str(self.config["enable_cors"]).lower(),
467472
"DISCOURSE_HOSTNAME": self._get_external_hostname(),
473+
"DISCOURSE_MAX_CATEGORY_NESTING": str(self.config["max_category_nesting"]),
468474
"DISCOURSE_REDIS_HOST": redis_relation_data[0],
469475
"DISCOURSE_REDIS_PORT": str(redis_relation_data[1]),
470476
"DISCOURSE_REFRESH_MAXMIND_DB_DURING_PRECOMPILE_DAYS": "0",

tests/unit_harness/test_charm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def bundle_handler(args: ops.testing.ExecArgs) -> None:
201201
assert "someuser" == updated_plan_env["DISCOURSE_DB_USERNAME"]
202202
assert updated_plan_env["DISCOURSE_ENABLE_CORS"]
203203
assert "discourse-k8s" == updated_plan_env["DISCOURSE_HOSTNAME"]
204+
assert "2" == updated_plan_env["DISCOURSE_MAX_CATEGORY_NESTING"]
204205
assert "redis-host" == updated_plan_env["DISCOURSE_REDIS_HOST"]
205206
assert "1010" == updated_plan_env["DISCOURSE_REDIS_PORT"]
206207
assert updated_plan_env["DISCOURSE_SERVE_STATIC_ASSETS"]
@@ -258,6 +259,7 @@ def test_on_config_changed_when_valid():
258259
assert "[email protected]" == updated_plan_env["DISCOURSE_DEVELOPER_EMAILS"]
259260
assert updated_plan_env["DISCOURSE_ENABLE_CORS"]
260261
assert "discourse.local" == updated_plan_env["DISCOURSE_HOSTNAME"]
262+
assert "2" == updated_plan_env["DISCOURSE_MAX_CATEGORY_NESTING"]
261263
assert "redis-host" == updated_plan_env["DISCOURSE_REDIS_HOST"]
262264
assert "1010" == updated_plan_env["DISCOURSE_REDIS_PORT"]
263265
assert updated_plan_env["DISCOURSE_SAML_CERT_FINGERPRINT"] is not None

0 commit comments

Comments
 (0)