Skip to content

Commit

Permalink
fix: Fix review team change logic for assoc obj
Browse files Browse the repository at this point in the history
  • Loading branch information
bdewilde committed Dec 8, 2023
1 parent bcd1e1e commit ea86332
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions colandr/apis/resources/review_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ... import tasks
from ...extensions import db
from ...lib import constants
from ...models import Review, User
from ...models import Review, ReviewUserAssoc, User
from .. import auth
from ..errors import bad_request_error, forbidden_error, not_found_error
from ..schemas import UserSchema
Expand Down Expand Up @@ -188,16 +188,18 @@ def put(self, id, action, user_id, user_email, server_name):
elif action == "make_owner":
if user is None:
return not_found_error("no user found with given id or email")
review.owners.append(user)
review.review_user_assoc.append(ReviewUserAssoc(review, user, "owner"))
elif action == "remove":
if user is None:
return not_found_error("no user found with given id or email")
if user in review.owners:
return forbidden_error(
"current review owner can not be removed from team"
)
if review_users.filter_by(id=user_id).one_or_none() is not None:
review_users.remove(user)
review_owners = review.owners
if user in review_owners and len(review_owners) == 1:
return forbidden_error("only review owner can not be removed from team")
if (
review.review_user_assoc.filter_by(user_id=user_id).one_or_none()
is not None
):
review.review_user_assoc.remove(ReviewUserAssoc(review, user))

db.session.commit()
current_app.logger.info("for %s, %s %s", review, action, user)
Expand Down

0 comments on commit ea86332

Please sign in to comment.