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

Seed super user permissions #468

Merged
merged 1 commit into from
May 5, 2022
Merged
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
5 changes: 5 additions & 0 deletions create_superuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from fidesops.db.session import get_db_session
from fidesops.models.client import ClientDetail, ADMIN_UI_ROOT
from fidesops.models.fidesops_user import FidesopsUser
from fidesops.models.fidesops_user_permissions import FidesopsUserPermissions
from fidesops.schemas.user import UserCreate


Expand Down Expand Up @@ -61,6 +62,10 @@ def create_user_and_client(db: Session) -> FidesopsUser:
ClientDetail.create_client_and_secret(
db, scopes, fides_key=ADMIN_UI_ROOT, user_id=superuser.id
)

FidesopsUserPermissions.create(
db=db, data={"user_id": superuser.id, "scopes": scopes}
)
print(f"Superuser '{user_data.username}' created successfully!")
return superuser

Expand Down
4 changes: 4 additions & 0 deletions tests/scripts/test_create_superuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from fidesops.common_exceptions import KeyOrNameAlreadyExists
from fidesops.models.client import ClientDetail, ADMIN_UI_ROOT
from fidesops.models.fidesops_user import FidesopsUser
from fidesops.models.fidesops_user_permissions import FidesopsUserPermissions
from fidesops.schemas.user import UserCreate
from fidesops.api.v1.scope_registry import CLIENT_CREATE

Expand Down Expand Up @@ -64,6 +65,9 @@ def test_create_user_and_client(self, mock_pass, mock_user, db):
assert client_detail.fides_key == ADMIN_UI_ROOT
assert CLIENT_CREATE not in client_detail.scopes

user_permissions = FidesopsUserPermissions.get_by(db=db, field="user_id", value=superuser.id)
assert user_permissions is not None

with pytest.raises(KeyOrNameAlreadyExists):
create_user_and_client(db)

Expand Down