diff --git a/tasks/sync_teams.py b/tasks/sync_teams.py index 1f0e42016..11c80d80e 100644 --- a/tasks/sync_teams.py +++ b/tasks/sync_teams.py @@ -58,6 +58,16 @@ def run_impl(self, db_session, ownerid, *, username=None, **kwargs): ownerid=ownerid, ), ) + for org_ownerid in removed_orgs: + org = ( + db_session.query(Owner).filter(Owner.ownerid == org_ownerid).first() + ) + if org and ownerid in org.plan_activated_users: + log.info( + "Removing user from org's plan_activated_users", + extra=dict(user_ownerid=ownerid, org_ownerid=org_ownerid), + ) + org.plan_activated_users.remove(ownerid) owner.updatestamp = datetime.now() owner.organizations = team_ids diff --git a/tasks/tests/unit/test_sync_teams_task.py b/tasks/tests/unit/test_sync_teams_task.py index 8b7056e33..b85455bc8 100644 --- a/tasks/tests/unit/test_sync_teams_task.py +++ b/tasks/tests/unit/test_sync_teams_task.py @@ -37,10 +37,13 @@ def test_team_removed(self, mocker, mock_configuration, dbsession, codecov_vcr): service="github", unencrypted_oauth_token=token, ) + prev_team.plan_activated_users = [user.ownerid] dbsession.add(user) + dbsession.add(prev_team) dbsession.flush() SyncTeamsTask().run_impl(dbsession, user.ownerid, using_integration=False) assert prev_team.ownerid not in user.organizations + assert user.ownerid not in prev_team.plan_activated_users def test_team_data_updated( self, mocker, mock_configuration, dbsession, codecov_vcr