Skip to content

Commit

Permalink
Fix 339 env description (#363)
Browse files Browse the repository at this point in the history
* adding field description on environment model

* alembic migration for environment.description

* API impact to update an env description

* black

* handle environment.description when add an env
  • Loading branch information
pierrotsmnrd authored Aug 4, 2022
1 parent 2f8d979 commit dfb4eda
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Add Environment.description
Revision ID: 8d63a091aff8
Revises: 48be4072fe58
Create Date: 2022-07-15 14:22:00.351131
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '8d63a091aff8'
down_revision = '48be4072fe58'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('environment', sa.Column('description', sa.UnicodeText(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('environment', 'description')
# ### end Alembic commands ###
15 changes: 15 additions & 0 deletions conda-store-server/conda_store_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,13 @@ def register_environment(
environment = orm.Environment(
name=specification.name,
namespace_id=namespace.id,
description=specification.spec["description"],
)
self.db.add(environment)
self.db.commit()
else:
environment.description = specification.description
self.db.commit()

build = self.create_build(environment.id, specification.sha256)

Expand Down Expand Up @@ -518,6 +522,17 @@ def update_environment_build(self, namespace, name, build_id):

tasks.task_update_environment_build.si(environment.id).apply_async()

def update_environment_description(self, namespace, name, description):

environment = api.get_environment(self.db, namespace=namespace, name=name)
if environment is None:
raise utils.CondaStoreError(
f"environment namespace={namespace} name={name} does not exist"
)

environment.description = description
self.db.commit()

def delete_namespace(self, namespace):
namespace = api.get_namespace(self.db, name=namespace)
if namespace is None:
Expand Down
3 changes: 3 additions & 0 deletions conda-store-server/conda_store_server/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
DateTime,
UniqueConstraint,
ForeignKey,
UnicodeText,
)
from sqlalchemy.orm import sessionmaker, relationship, scoped_session, backref
from sqlalchemy.ext.declarative import declarative_base
Expand Down Expand Up @@ -276,6 +277,8 @@ class Environment(Base):

deleted_on = Column(DateTime, default=None)

description = Column(UnicodeText, default=None)


class CondaChannel(Base):
__tablename__ = "conda_channel"
Expand Down
1 change: 1 addition & 0 deletions conda-store-server/conda_store_server/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class CondaSpecification(BaseModel):
channels: List[str] = []
dependencies: List[Union[str, CondaSpecificationPip]] = []
prefix: Optional[str]
description: Optional[str] = ""

@validator("dependencies", each_item=True)
def check_dependencies(cls, v):
Expand Down
10 changes: 8 additions & 2 deletions conda-store-server/conda_store_server/server/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,20 @@ def api_update_environment_build(
request: Request,
conda_store=Depends(dependencies.get_conda_store),
auth=Depends(dependencies.get_auth),
build_id: int = Body(..., embed=True),
build_id: int = Body(None, embed=True),
description: str = Body(None, embed=True),
):
auth.authorize_request(
request, f"{namespace}/{name}", {Permissions.ENVIRONMENT_UPDATE}, require=True
)

try:
conda_store.update_environment_build(namespace, name, build_id)
if build_id is not None:
conda_store.update_environment_build(namespace, name, build_id)

if description is not None:
conda_store.update_environment_description(namespace, name, description)

except utils.CondaStoreError as e:
raise HTTPException(status_code=400, detail=e.message)

Expand Down

0 comments on commit dfb4eda

Please sign in to comment.