1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2025-02-16 12:43:58 +00:00

Fix bug that prevented repos to be deleted

This commit is contained in:
Lorenzo Balugani 2021-05-27 11:27:23 +02:00
parent c19655e0e7
commit e1024af599

View file

@ -181,6 +181,44 @@ def page_repository(rid):
if repository.owner_id != user.email and not user.isAdmin:
return json_error("You are not the owner of this repository.", REPOSITORY_NOT_OWNER), 403
try:
# Deleting Tweets...
tweets = [t.tweet for t in repository.tweets]
for tweet in tweets:
if len(tweet.repositories) < 2:
# Delete Tweets if only attached to this repo
for conn in tweet.repositories:
ext.session.delete(conn)
for conn in tweet.conditions:
ext.session.delete(conn)
ext.session.delete(tweet)
ext.session.commit()
else:
conns = [conn for conn in tweet.repositories if conn.rid == rid]
for conn in conns:
ext.session.delete(conn)
ext.session.commit()
# Deleting authorizations...
for auth in repository.authorizations:
ext.session.delete(auth)
ext.session.commit()
# Deleting conditions...
for condition in repository.conditions:
ext.session.delete(condition)
ext.session.commit()
# Deleting Alerts...
for alert in repository.alerts:
for elem in alert.conditions:
condition = elem.condition
ext.session.delete(elem)
ext.session.commit()
if not condition.repository_id:
ext.session.delete(condition)
ext.session.commit()
for notification in alert.notifications:
ext.session.delete(notification)
ext.session.commit()
ext.session.delete(alert)
ext.session.commit()
ext.session.delete(repository)
ext.session.commit()
except Exception as e: