diff --git a/src/config/src/prebuilt_loader.rs b/src/config/src/prebuilt_loader.rs index 6579d0bb4b..ef96a4439f 100644 --- a/src/config/src/prebuilt_loader.rs +++ b/src/config/src/prebuilt_loader.rs @@ -108,6 +108,27 @@ fn load_prebuilt_config() -> PrebuiltDestinationsConfig { load_builtin_config() } +/// Prefix that marks system-managed template names. The full reserved set is +/// `prebuilt_` where `` is one of the registered prebuilt +/// destination types — see `is_prebuilt_template_name` below. +pub const PREBUILT_TEMPLATE_PREFIX: &str = "prebuilt_"; + +/// True only for template names the system actually manages: the name must be +/// `prebuilt_` where `` is a registered prebuilt destination type +/// (slack, opsgenie, servicenow, ...). +/// +/// Lives next to `get_prebuilt_template` so the public API surface +/// (`handler::http::models`), the service-layer guards +/// (`service::alerts::templates`), and any future caller all derive the +/// "is system template" answer from the same source of truth. +/// +/// User-created templates whose names happen to start with `prebuilt_` but +/// don't match a registered type stay freely editable and deletable. +pub fn is_prebuilt_template_name(name: &str) -> bool { + name.strip_prefix(PREBUILT_TEMPLATE_PREFIX) + .is_some_and(|t| get_prebuilt_template(t).is_some()) +} + /// Get a specific prebuilt template by type (e.g., "slack", "teams", "email") pub fn get_prebuilt_template(prebuilt_type: &str) -> Option + +