Feat v0.9.4 package adoption + roles
All checks were successful
CI/CD / detect-changes (pull_request) Successful in 21s
CI/CD / test-frontend (pull_request) Has been skipped
CI/CD / test-runners (pull_request) Has been skipped
CI/CD / e2e-smoke (pull_request) Has been skipped
CI/CD / test-sqlite (pull_request) Successful in 2m52s
CI/CD / test-go-pg (pull_request) Successful in 3m6s
CI/CD / build-and-deploy (pull_request) Successful in 1m41s
All checks were successful
CI/CD / detect-changes (pull_request) Successful in 21s
CI/CD / test-frontend (pull_request) Has been skipped
CI/CD / test-runners (pull_request) Has been skipped
CI/CD / e2e-smoke (pull_request) Has been skipped
CI/CD / test-sqlite (pull_request) Successful in 2m52s
CI/CD / test-go-pg (pull_request) Successful in 3m6s
CI/CD / build-and-deploy (pull_request) Successful in 1m41s
Packages can declare `adoptable: true` in their manifest. When a team adopts an adoptable package, a team-scoped copy is created that references the original via `adopted_from` (shared assets, no disk duplication). The package's `requires_roles` auto-populate into a new `team_role_catalog` table so team admins know which roles to assign. Migration 017: adoptable/adopted_from columns on packages, team_role_catalog table. 4 new endpoints (adopt, list adoptable, unadopt, role catalog). AdoptTeamWorkflow deprecated. 11 new tests, all passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -107,15 +107,15 @@ func (s *PackageStore) Create(ctx context.Context, pkg *store.PackageRegistratio
|
||||
return DB.QueryRowContext(ctx, `
|
||||
INSERT INTO packages (id, title, type, version, description, author, tier,
|
||||
is_system, scope, team_id, installed_by, manifest, enabled, status,
|
||||
schema_version, package_settings, source)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17)
|
||||
schema_version, package_settings, source, adoptable, adopted_from)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19)
|
||||
RETURNING installed_at, updated_at`,
|
||||
pkg.ID, pkg.Title, pkg.Type, pkg.Version, pkg.Description, pkg.Author,
|
||||
pkg.Tier, pkg.IsSystem, pkg.Scope,
|
||||
nullStrPtr(pkg.TeamID), nullStrPtr(pkg.InstalledBy),
|
||||
manifestJSON, pkg.Enabled, pkg.Status,
|
||||
pkg.SchemaVersion, defaultJSON(pkg.PackageSettings),
|
||||
pkg.Source,
|
||||
pkg.Source, pkg.Adoptable, nullStrPtr(pkg.AdoptedFrom),
|
||||
).Scan(&pkg.InstalledAt, &pkg.UpdatedAt)
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ func (s *PackageStore) ListForUser(ctx context.Context, userID string) ([]store.
|
||||
var result []store.UserPackage
|
||||
for rows.Next() {
|
||||
var up store.UserPackage
|
||||
var teamID, installedBy sql.NullString
|
||||
var teamID, installedBy, adoptedFrom sql.NullString
|
||||
var manifestJSON []byte
|
||||
var pkgSettings []byte
|
||||
var userEnabled sql.NullBool
|
||||
@@ -185,13 +185,15 @@ func (s *PackageStore) ListForUser(ctx context.Context, userID string) ([]store.
|
||||
&teamID, &installedBy,
|
||||
&manifestJSON, &up.Enabled, &up.Status,
|
||||
&up.SchemaVersion, &pkgSettings,
|
||||
&up.Source, &up.InstalledAt, &up.UpdatedAt,
|
||||
&up.Source, &up.Adoptable, &adoptedFrom,
|
||||
&up.InstalledAt, &up.UpdatedAt,
|
||||
&userEnabled, &userSettings,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
up.TeamID = NullableStringPtr(teamID)
|
||||
up.InstalledBy = NullableStringPtr(installedBy)
|
||||
up.AdoptedFrom = NullableStringPtr(adoptedFrom)
|
||||
json.Unmarshal(manifestJSON, &up.Manifest)
|
||||
up.PackageSettings = json.RawMessage(pkgSettings)
|
||||
if userEnabled.Valid {
|
||||
@@ -250,11 +252,12 @@ const pkgCols = `p.id, p.title, p.type, p.version, p.description, p.author,
|
||||
p.tier, p.is_system, p.scope, p.team_id, p.installed_by,
|
||||
p.manifest, p.enabled, p.status,
|
||||
p.schema_version, p.package_settings,
|
||||
p.source, p.installed_at, p.updated_at`
|
||||
p.source, p.adoptable, p.adopted_from,
|
||||
p.installed_at, p.updated_at`
|
||||
|
||||
func (s *PackageStore) scanOne(ctx context.Context, query string, args ...interface{}) (*store.PackageRegistration, error) {
|
||||
var pkg store.PackageRegistration
|
||||
var teamID, installedBy sql.NullString
|
||||
var teamID, installedBy, adoptedFrom sql.NullString
|
||||
var manifestJSON []byte
|
||||
var pkgSettings []byte
|
||||
err := DB.QueryRowContext(ctx, query, args...).Scan(
|
||||
@@ -263,7 +266,8 @@ func (s *PackageStore) scanOne(ctx context.Context, query string, args ...interf
|
||||
&teamID, &installedBy,
|
||||
&manifestJSON, &pkg.Enabled, &pkg.Status,
|
||||
&pkg.SchemaVersion, &pkgSettings,
|
||||
&pkg.Source, &pkg.InstalledAt, &pkg.UpdatedAt,
|
||||
&pkg.Source, &pkg.Adoptable, &adoptedFrom,
|
||||
&pkg.InstalledAt, &pkg.UpdatedAt,
|
||||
)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
@@ -273,6 +277,7 @@ func (s *PackageStore) scanOne(ctx context.Context, query string, args ...interf
|
||||
}
|
||||
pkg.TeamID = NullableStringPtr(teamID)
|
||||
pkg.InstalledBy = NullableStringPtr(installedBy)
|
||||
pkg.AdoptedFrom = NullableStringPtr(adoptedFrom)
|
||||
json.Unmarshal(manifestJSON, &pkg.Manifest)
|
||||
pkg.PackageSettings = json.RawMessage(pkgSettings)
|
||||
return &pkg, nil
|
||||
@@ -288,7 +293,7 @@ func (s *PackageStore) scanMany(ctx context.Context, query string, args ...inter
|
||||
var result []store.PackageRegistration
|
||||
for rows.Next() {
|
||||
var pkg store.PackageRegistration
|
||||
var teamID, installedBy sql.NullString
|
||||
var teamID, installedBy, adoptedFrom sql.NullString
|
||||
var manifestJSON []byte
|
||||
var pkgSettings []byte
|
||||
if err := rows.Scan(
|
||||
@@ -297,12 +302,14 @@ func (s *PackageStore) scanMany(ctx context.Context, query string, args ...inter
|
||||
&teamID, &installedBy,
|
||||
&manifestJSON, &pkg.Enabled, &pkg.Status,
|
||||
&pkg.SchemaVersion, &pkgSettings,
|
||||
&pkg.Source, &pkg.InstalledAt, &pkg.UpdatedAt,
|
||||
&pkg.Source, &pkg.Adoptable, &adoptedFrom,
|
||||
&pkg.InstalledAt, &pkg.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pkg.TeamID = NullableStringPtr(teamID)
|
||||
pkg.InstalledBy = NullableStringPtr(installedBy)
|
||||
pkg.AdoptedFrom = NullableStringPtr(adoptedFrom)
|
||||
json.Unmarshal(manifestJSON, &pkg.Manifest)
|
||||
pkg.PackageSettings = json.RawMessage(pkgSettings)
|
||||
result = append(result, pkg)
|
||||
@@ -397,6 +404,23 @@ func (s *PackageStore) DeleteTeamSettings(ctx context.Context, pkgID, teamID str
|
||||
return err
|
||||
}
|
||||
|
||||
// ── v0.9.4 — Package Adoption ───────────────
|
||||
|
||||
func (s *PackageStore) ListAdoptable(ctx context.Context) ([]store.PackageRegistration, error) {
|
||||
return s.scanMany(ctx, `
|
||||
SELECT `+pkgCols+`
|
||||
FROM packages p
|
||||
WHERE p.adoptable = true AND p.scope = 'global' AND p.enabled = true
|
||||
ORDER BY p.title`)
|
||||
}
|
||||
|
||||
func (s *PackageStore) GetByAdoptedFrom(ctx context.Context, sourceID, teamID string) (*store.PackageRegistration, error) {
|
||||
return s.scanOne(ctx, `
|
||||
SELECT `+pkgCols+`
|
||||
FROM packages p
|
||||
WHERE p.adopted_from = $1 AND p.team_id = $2`, sourceID, teamID)
|
||||
}
|
||||
|
||||
// nullStrPtr converts *string to sql.NullString for nullable FK columns.
|
||||
func nullStrPtr(s *string) sql.NullString {
|
||||
if s == nil {
|
||||
|
||||
Reference in New Issue
Block a user