Skip to content

Commit 885afb9

Browse files
committed
db: only match on org id when deleting blueprints
There are certain scenarios where the account number isn't set in the identity header. For instance when using service accounts and working via the api, the account number will be empty. Deleting the same blueprint via the UI will fail because there the account number will be set.
1 parent 87c09a6 commit 885afb9

5 files changed

Lines changed: 9 additions & 8 deletions

File tree

cmd/image-builder-db-test/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ func testBlueprints(ctx context.Context, t *testing.T) {
444444
require.NoError(t, err)
445445
require.Equal(t, 2, count)
446446

447-
err = d.DeleteBlueprint(ctx, id, ORGID1, ANR1)
447+
err = d.DeleteBlueprint(ctx, id, ORGID1)
448448
require.NoError(t, err)
449449

450450
_, count, err = d.GetComposes(ctx, ORGID1, (time.Hour * 24 * 14), 100, 0, nil)

internal/db/db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type DB interface {
8383
GetBlueprints(ctx context.Context, orgID string, limit, offset int) ([]BlueprintWithNoBody, int, error)
8484
FindBlueprints(ctx context.Context, orgID, search string, limit, offset int) ([]BlueprintWithNoBody, int, error)
8585
FindBlueprintByName(ctx context.Context, orgID, nameQuery string) (*BlueprintWithNoBody, error)
86-
DeleteBlueprint(ctx context.Context, id uuid.UUID, orgID, accountNumber string) error
86+
DeleteBlueprint(ctx context.Context, id uuid.UUID, orgID string) error
8787
}
8888

8989
const (

internal/db/db_blueprints.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const (
9595
WHERE composes.blueprint_version_id = blueprint_versions.id
9696
AND composes.org_id=$1 AND blueprint_versions.blueprint_id=$2`
9797

98-
sqlDeleteBlueprint = `UPDATE blueprints SET deleted = TRUE, name = id WHERE deleted = FALSE AND id = $1 AND org_id = $2 AND account_number = $3`
98+
sqlDeleteBlueprint = `UPDATE blueprints SET deleted = TRUE, name = id WHERE deleted = FALSE AND id = $1 AND org_id = $2`
9999

100100
sqlGetBlueprints = `
101101
SELECT blueprints.id, blueprints.name, blueprints.description, MAX(blueprint_versions.version) as version, MAX(blueprint_versions.created_at) as last_modified_at
@@ -294,7 +294,7 @@ func (db *dB) UpdateBlueprint(ctx context.Context, id uuid.UUID, blueprintId uui
294294
return err
295295
}
296296

297-
func (db *dB) DeleteBlueprint(ctx context.Context, id uuid.UUID, orgID, accountNumber string) error {
297+
func (db *dB) DeleteBlueprint(ctx context.Context, id uuid.UUID, orgID string) error {
298298
conn, err := db.Pool.Acquire(ctx)
299299
if err != nil {
300300
return err
@@ -306,7 +306,7 @@ func (db *dB) DeleteBlueprint(ctx context.Context, id uuid.UUID, orgID, accountN
306306
return fmt.Errorf("marking blueprint(%s) composes as deleted failed: %w", id, err)
307307
}
308308

309-
tag, err := conn.Exec(ctx, sqlDeleteBlueprint, id, orgID, accountNumber)
309+
tag, err := conn.Exec(ctx, sqlDeleteBlueprint, id, orgID)
310310
if err != nil {
311311
return err
312312
}

internal/v1/handler_blueprints.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ func (h *Handlers) DeleteBlueprint(ctx echo.Context, blueprintId openapi_types.U
728728
return err
729729
}
730730

731-
err = h.server.db.DeleteBlueprint(ctx.Request().Context(), blueprintId, userID.OrgID(), userID.AccountNumber())
731+
err = h.server.db.DeleteBlueprint(ctx.Request().Context(), blueprintId, userID.OrgID())
732732
if err != nil {
733733
if errors.Is(err, db.ErrBlueprintNotFound) {
734734
return echo.NewHTTPError(http.StatusNotFound)

internal/v1/handler_blueprints_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func makeTestServer(t *testing.T, apiSrv *string) (dbase db.DB, srvURL string, s
4747
DistributionsDir: "../../distributions",
4848
CSReposURL: "https://content-sources.org",
4949
})
50+
5051
return srv.DB, srv.URL, func(t *testing.T) {
5152
srv.Shutdown(t)
5253
}
@@ -1621,7 +1622,7 @@ func TestLintBlueprint(t *testing.T) {
16211622
require.NoError(t, json.Unmarshal([]byte(body), &result))
16221623
require.ElementsMatch(t, c.lintErrors, result.Lint.Errors)
16231624

1624-
require.NoError(t, srv.DB.DeleteBlueprint(context.Background(), bpID, "000000", "000000"))
1625+
require.NoError(t, srv.DB.DeleteBlueprint(context.Background(), bpID, "000000"))
16251626
}
16261627
}
16271628

@@ -1693,6 +1694,6 @@ func TestFixupBlueprint(t *testing.T) {
16931694
require.NoError(t, json.Unmarshal([]byte(body), &result))
16941695
require.Empty(t, result.Lint.Errors)
16951696

1696-
require.NoError(t, srv.DB.DeleteBlueprint(context.Background(), bpID, "000000", "000000"))
1697+
require.NoError(t, srv.DB.DeleteBlueprint(context.Background(), bpID, "000000"))
16971698
}
16981699
}

0 commit comments

Comments
 (0)