-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task/DES-1996 restrict project deletion (#100)
* Add check for admin/creator * Add decorator and use at delete endpoint * Remove unused methods * Fix flake8 * Add create/admin info and check before project deletion * Add logging statement * Add test * Fix linting errors * Add migration * Use DesignSafe to get users and their admin status * Add env to gitignore * Add unit tests and update services * Fix linting error * Update refresh_observable_projects * Fix linting issues * Add requests-mock to requirements.txt * Rework migration so that existing project users are admins * Rework migration * Use clone to create new namepace model * Add model for user payload * Remove some dev logging * Remove unused import * Fix user_payload model
- Loading branch information
1 parent
a54c97d
commit 99ef290
Showing
21 changed files
with
552 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from geoapi.custom.designsafe.project_users import get_system_users | ||
|
||
custom_system_user_retrieval = {"DESIGNSAFE": get_system_users} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from urllib.parse import quote | ||
from geoapi.log import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_system_users(tenant_id, jwt, system_id: str): | ||
""" | ||
Get systems users based on the DesignSafe project's co-pis and pis. | ||
:param tenant_id: tenant id | ||
:param jwt: jwt of a user | ||
:param system_id: str | ||
:return: list of users with admin status | ||
""" | ||
from geoapi.utils.agave import service_account_client, SystemUser, get_default_system_users | ||
|
||
if not system_id.startswith("project-"): | ||
return get_default_system_users(tenant_id, jwt, system_id) | ||
|
||
uuid = system_id[len("project-"):] | ||
client = service_account_client(tenant_id=tenant_id) | ||
resp = client.get(quote(f'/projects/v2/{uuid}/')) | ||
resp.raise_for_status() | ||
project = resp.json()["value"] | ||
users = [] | ||
if "pi" in project: | ||
users.append(SystemUser(username=project["pi"], admin=True)) | ||
for u in project["coPis"]: | ||
users.append(SystemUser(username=u, admin=True)) | ||
for u in project["teamMembers"]: | ||
users.append(SystemUser(username=u, admin=False)) | ||
return users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""empty message | ||
Revision ID: dc0c2f6ba473 | ||
Revises: 0a10e4e1ea0c | ||
Create Date: 2022-08-02 02:54:09.836110 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'dc0c2f6ba473' | ||
down_revision = '0a10e4e1ea0c' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('projects_users', sa.Column('admin', sa.Boolean(), nullable=True)) | ||
op.add_column('projects_users', sa.Column('creator', sa.Boolean(), nullable=True)) | ||
|
||
# Update existing rows so that everyone is an admin | ||
op.execute("UPDATE projects_users SET admin = true") | ||
op.execute("UPDATE projects_users SET creator = false") | ||
|
||
op.alter_column('projects_users', 'admin', nullable=False) | ||
op.alter_column('projects_users', 'creator', nullable=False) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column('projects_users', 'creator') | ||
op.drop_column('projects_users', 'admin') | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.