Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/api/internal/template/register_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"fmt"
"net/http"
"os"
"strconv"

"github.com/google/uuid"
"go.opentelemetry.io/otel"
Expand Down Expand Up @@ -227,6 +229,14 @@ func registerBuild(
data.Public = previous.Public
}

// When TEMPLATES_DEFAULT_PUBLIC=true, force every newly created or rebuilt
// template to be public, so templates created by any team are visible
// platform-wide. Applied after the rebuild-inheritance above so it overrides
// any inherited value; a value of false (or unset) keeps the prior behavior.
if templatesDefaultPublic() {
data.Public = true
}

var clusterID *uuid.UUID
if data.ClusterID != consts.LocalClusterID {
clusterID = &data.ClusterID
Expand Down Expand Up @@ -487,3 +497,15 @@ func registerBuild(
Tags: tags,
}, nil
}

// templatesDefaultPublic reports whether newly created templates should be
// forced public, controlled by the TEMPLATES_DEFAULT_PUBLIC environment
// variable. Unset, empty, or unparseable values default to false, preserving
// the original per-team-private behavior.
func templatesDefaultPublic() bool {
v, err := strconv.ParseBool(os.Getenv("TEMPLATES_DEFAULT_PUBLIC"))
if err != nil {
return false
}
return v
}
31 changes: 31 additions & 0 deletions packages/api/internal/template/register_build_public_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package template

import (
"os"
"testing"
)

func TestTemplatesDefaultPublic(t *testing.T) {
cases := []struct {
val string
set bool
want bool
}{
{set: false, want: false},
{val: "true", set: true, want: true},
{val: "1", set: true, want: true},
{val: "false", set: true, want: false},
{val: "", set: true, want: false},
{val: "garbage", set: true, want: false},
}
for _, c := range cases {
if c.set {
t.Setenv("TEMPLATES_DEFAULT_PUBLIC", c.val)
} else {
os.Unsetenv("TEMPLATES_DEFAULT_PUBLIC")
}
if got := templatesDefaultPublic(); got != c.want {
t.Errorf("val=%q set=%v: got %v want %v", c.val, c.set, got, c.want)
}
}
}