Skip to content

Commit

Permalink
Update products/{id}/add_platforms for AlmaLinux/build-system#359
Browse files Browse the repository at this point in the history
- Add access control
- black formatting
  • Loading branch information
bklvsky committed Oct 22, 2024
1 parent d65f33c commit c557ed4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
18 changes: 12 additions & 6 deletions alws/crud/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def add_repos_to_product(
pulp_client: PulpClient,
product: models.Product,
owner: models.User,
platforms: List[models.Platform]
platforms: List[models.Platform],
):
repos_to_insert = []
repo_tasks = []
Expand Down Expand Up @@ -86,7 +86,7 @@ async def add_repos_to_product(
production=True,
export_path=export_path,
)

repos_to_insert.append(repo)
return repos_to_insert

Expand Down Expand Up @@ -390,13 +390,21 @@ async def add_platform_to_product(
session: AsyncSession,
product_id: int,
platforms: List[Platform],
user_id: int,
):
pulp_client = PulpClient(
settings.pulp_host,
settings.pulp_user,
settings.pulp_password,
)
db_product = await get_products(session, product_id=product_id)
db_user = await get_user(session, user_id=user_id)
if not db_user:
raise DataNotFoundError(f"User={user_id} doesn't exist")
if not can_perform(db_product, db_user, actions.UpdateProduct.name):
raise PermissionDenied(
f'User has no permissions to modify the product "{db_product.name}"'
)
db_platforms = (
(
await session.execute(
Expand All @@ -415,7 +423,7 @@ async def add_platform_to_product(
pulp_client=pulp_client,
owner=db_product.owner,
product=db_product,
platforms=db_platforms
platforms=db_platforms,
)
db_product.repositories.extend(repos)
session.add_all(repos)
Expand All @@ -438,9 +446,7 @@ async def get_repo_product(
await session.execute(
select(Build)
.filter(
Build.repos.any(
Repository.name.ilike(f'%{repository}')
)
Build.repos.any(Repository.name.ilike(f'%{repository}'))
)
.options(
joinedload(Build.team)
Expand Down
5 changes: 4 additions & 1 deletion alws/routers/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,12 @@ async def add_platforms(
product_id: int,
platforms: List[product_schema.Platform],
db: AsyncSession = Depends(AsyncSessionDependency(key=get_async_db_key())),
user: User = Depends(get_current_user),
):
try:
await products.add_platform_to_product(db, product_id, platforms)
await products.add_platform_to_product(
db, product_id, platforms, user.id
)
except Exception as exc:
raise HTTPException(
detail=str(exc),
Expand Down

0 comments on commit c557ed4

Please sign in to comment.