Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
add access tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvatt committed Aug 29, 2024
1 parent 67cb8a3 commit 1bbd597
Show file tree
Hide file tree
Showing 12 changed files with 585 additions and 53 deletions.
1 change: 1 addition & 0 deletions .metabase_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.50.21
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LAST_COMMIT = $(shell git --no-pager log -1 --pretty=%h)
VERSION ?= $(DATE)-$(LAST_COMMIT)
LDFLAGS := -X github.com/navikt/nada-backend/backend/version.Revision=$(shell git rev-parse --short HEAD) -X github.com/navikt/nada-backend/backend/version.Version=$(VERSION)

METABASE_VERSION := v1.50.21
METABASE_VERSION := $(shell cat .metabase_version)
MOCKS_VERSION := v0.0.1

TARGET_ARCH := amd64
Expand Down
3 changes: 2 additions & 1 deletion pkg/database/gensql/datasets_v2.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/database/gensql/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions pkg/database/migrations/0092_add_access_owner_to_dataset_view.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
-- +goose Up
DROP VIEW dataset_view;

CREATE VIEW dataset_view AS(
SELECT
ds.id as ds_id,
ds.name as ds_name,
ds.description as ds_description,
ds.created as ds_created,
ds.last_modified as ds_last_modified,
ds.slug as ds_slug,
ds.pii as pii,
ds.keywords as ds_keywords,
dsrc.id AS bq_id,
dsrc.created as bq_created,
dsrc.last_modified as bq_last_modified,
dsrc.expires as bq_expires,
dsrc.description as bq_description,
dsrc.missing_since as bq_missing_since,
dsrc.pii_tags as pii_tags,
dsrc.project_id as bq_project,
dsrc.dataset as bq_dataset,
dsrc.table_name as bq_table_name,
dsrc.table_type as bq_table_type,
dsrc.pseudo_columns as pseudo_columns,
dsrc.schema as bq_schema,
ds.dataproduct_id as ds_dp_id,
dm.services as mapping_services,
da.id as access_id,
da.subject as access_subject,
da.owner as access_owner,
da.granter as access_granter,
da.expires as access_expires,
da.created as access_created,
da.revoked as access_revoked,
da.access_request_id as access_request_id,
mm.database_id as mb_database_id,
mm.deleted_at as mb_deleted_at
FROM
datasets ds
LEFT JOIN (
SELECT
*
FROM
datasource_bigquery
WHERE
is_reference = false
) dsrc ON ds.id = dsrc.dataset_id
LEFT JOIN third_party_mappings dm ON ds.id = dm.dataset_id
LEFT JOIN dataset_access da ON ds.id = da.dataset_id
LEFT JOIN metabase_metadata mm ON ds.id = mm.dataset_id
);

-- +goose Down
DROP VIEW dataset_view;

CREATE VIEW dataset_view AS(
SELECT
ds.id as ds_id,
ds.name as ds_name,
ds.description as ds_description,
ds.created as ds_created,
ds.last_modified as ds_last_modified,
ds.slug as ds_slug,
ds.pii as pii,
ds.keywords as ds_keywords,
dsrc.id AS bq_id,
dsrc.created as bq_created,
dsrc.last_modified as bq_last_modified,
dsrc.expires as bq_expires,
dsrc.description as bq_description,
dsrc.missing_since as bq_missing_since,
dsrc.pii_tags as pii_tags,
dsrc.project_id as bq_project,
dsrc.dataset as bq_dataset,
dsrc.table_name as bq_table_name,
dsrc.table_type as bq_table_type,
dsrc.pseudo_columns as pseudo_columns,
dsrc.schema as bq_schema,
ds.dataproduct_id as ds_dp_id,
dm.services as mapping_services,
da.id as access_id,
da.subject as access_subject,
da.granter as access_granter,
da.expires as access_expires,
da.created as access_created,
da.revoked as access_revoked,
da.access_request_id as access_request_id,
mm.database_id as mb_database_id,
mm.deleted_at as mb_deleted_at
FROM
datasets ds
LEFT JOIN (
SELECT
*
FROM
datasource_bigquery
WHERE
is_reference = false
) dsrc ON ds.id = dsrc.dataset_id
LEFT JOIN third_party_mappings dm ON ds.id = dm.dataset_id
LEFT JOIN dataset_access da ON ds.id = da.dataset_id
LEFT JOIN metabase_metadata mm ON ds.id = mm.dataset_id
);
8 changes: 1 addition & 7 deletions pkg/service/core/service_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,7 @@ func (s *accessService) DeleteAccessRequest(ctx context.Context, user *service.U
return errs.E(op, err)
}

splits := strings.Split(accessRequest.Owner, ":")
if len(splits) != 2 {
return errs.E(errs.InvalidRequest, op, fmt.Errorf("owner is not in the correct format"))
}
owner := splits[1]

if err := ensureOwner(user, owner); err != nil {
if err := ensureOwner(user, accessRequest.Owner); err != nil {
return errs.E(op, err)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/service/core/storage/postgres/postgres_dataproduct.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ func (s *dataProductStorage) datasetFromSQL(dsrows []gensql.DatasetView) (*servi
Created: dsrow.AccessCreated.Time,
Revoked: nullTimeToPtr(dsrow.AccessRevoked),
DatasetID: dsrow.DsID,
Owner: dsrow.AccessOwner.String,

Check warning on line 669 in pkg/service/core/storage/postgres/postgres_dataproduct.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/core/storage/postgres/postgres_dataproduct.go#L669

Added line #L669 was not covered by tests
AccessRequestID: nullUUIDToUUIDPtr(dsrow.AccessRequestID),
}
dataset.Access = append(dataset.Access, access)
Expand Down
Loading

0 comments on commit 1bbd597

Please sign in to comment.