From ea863326dae8d8d49c3b8cd99f210d9d5adc4ace Mon Sep 17 00:00:00 2001 From: Burton DeWilde Date: Thu, 7 Dec 2023 22:17:33 -0500 Subject: [PATCH] fix: Fix review team change logic for assoc obj --- colandr/apis/resources/review_teams.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/colandr/apis/resources/review_teams.py b/colandr/apis/resources/review_teams.py index a6cf036e..d3fb4c8d 100644 --- a/colandr/apis/resources/review_teams.py +++ b/colandr/apis/resources/review_teams.py @@ -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 @@ -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)