Fix usage of email_alerts column

This commit is contained in:
mvdbeek
2021-02-04 20:41:21 +01:00
parent c17b02ed8c
commit c9dc398bf0
5 changed files with 11 additions and 30 deletions
+1 -2
View File
@@ -1,4 +1,3 @@
import json
import logging
from markupsafe import escape as escape_html
@@ -181,7 +180,7 @@ class RepositoryGrid(grids.Grid):
class EmailAlertsColumn(grids.TextColumn):
def get_value(self, trans, grid, repository):
if trans.user and repository.email_alerts and trans.user.email in json.loads(repository.email_alerts):
if trans.user and trans.user.email in repository.email_alerts:
return 'yes'
return ''
+1 -3
View File
@@ -1,6 +1,5 @@
import bz2
import gzip
import json
import logging
import os
import shutil
@@ -72,8 +71,7 @@ def check_file_contents_for_email_alerts(app):
admin_users = app.config.get("admin_users", "").split(",")
for repository in sa_session.query(app.model.Repository) \
.filter(app.model.Repository.table.c.email_alerts != null()):
email_alerts = json.loads(repository.email_alerts)
for user_email in email_alerts:
for user_email in repository.email_alerts:
if user_email in admin_users:
return True
return False
+1 -1
View File
@@ -385,7 +385,7 @@ def handle_email_alerts(app, host, repository, content_alert_str='', new_repo_al
email_alerts.append(user.email)
else:
subject = "Galaxy tool shed update alert for repository named %s" % str(repository.name)
email_alerts = json.loads(repository.email_alerts)
email_alerts = repository.email_alerts
for email in email_alerts:
to = email.strip()
# Send it
+7 -23
View File
@@ -1658,10 +1658,6 @@ class RepositoryController(BaseUIController, ratings_util.ItemRatings):
alerts = kwd.get('alerts', '')
alerts_checked = CheckboxField.is_checked(alerts)
category_ids = util.listify(kwd.get('category_id', ''))
if repository.email_alerts:
email_alerts = json.loads(repository.email_alerts)
else:
email_alerts = []
allow_push = kwd.get('allow_push', '')
error = False
user = trans.user
@@ -1714,14 +1710,12 @@ class RepositoryController(BaseUIController, ratings_util.ItemRatings):
elif kwd.get('receive_email_alerts_button', False):
flush_needed = False
if alerts_checked:
if user.email not in email_alerts:
email_alerts.append(user.email)
repository.email_alerts = json.dumps(email_alerts)
if user.email not in repository.email_alerts:
repository.email_alerts.append(user.email)
flush_needed = True
else:
if user.email in email_alerts:
email_alerts.remove(user.email)
repository.email_alerts = json.dumps(email_alerts)
if user.email in repository.email_alerts:
repository.email_alerts.remove(user.email)
flush_needed = True
if flush_needed:
trans.sa_session.add(repository)
@@ -1743,7 +1737,7 @@ class RepositoryController(BaseUIController, ratings_util.ItemRatings):
for obj in options:
label = obj.username
allow_push_select_field.add_option(label, trans.security.encode_id(obj.id))
checked = alerts_checked or user.email in email_alerts
checked = alerts_checked or user.email in repository.email_alerts
alerts_check_box = CheckboxField('alerts', value=checked)
changeset_revision_select_field = grids_util.build_changeset_revision_select_field(trans,
repository,
@@ -2273,19 +2267,14 @@ class RepositoryController(BaseUIController, ratings_util.ItemRatings):
flush_needed = False
for repository_id in repository_ids:
repository = repository_util.get_repository_in_tool_shed(trans.app, repository_id)
if repository.email_alerts:
email_alerts = json.loads(repository.email_alerts)
else:
email_alerts = []
email_alerts = repository.email_alerts
if user.email in email_alerts:
email_alerts.remove(user.email)
repository.email_alerts = json.dumps(email_alerts)
trans.sa_session.add(repository)
flush_needed = True
total_alerts_removed += 1
else:
email_alerts.append(user.email)
repository.email_alerts = json.dumps(email_alerts)
trans.sa_session.add(repository)
flush_needed = True
total_alerts_added += 1
@@ -2568,10 +2557,7 @@ class RepositoryController(BaseUIController, ratings_util.ItemRatings):
display_reviews = kwd.get('display_reviews', False)
alerts = kwd.get('alerts', '')
alerts_checked = CheckboxField.is_checked(alerts)
if repository.email_alerts:
email_alerts = json.loads(repository.email_alerts)
else:
email_alerts = []
email_alerts = repository.email_alerts
repository_dependencies = None
user = trans.user
if user and kwd.get('receive_email_alerts_button', False):
@@ -2579,12 +2565,10 @@ class RepositoryController(BaseUIController, ratings_util.ItemRatings):
if alerts_checked:
if user.email not in email_alerts:
email_alerts.append(user.email)
repository.email_alerts = json.dumps(email_alerts)
flush_needed = True
else:
if user.email in email_alerts:
email_alerts.remove(user.email)
repository.email_alerts = json.dumps(email_alerts)
flush_needed = True
if flush_needed:
trans.sa_session.add(repository)
+1 -1
View File
@@ -118,7 +118,7 @@ Repository.table = Table("repository", metadata,
Column("user_id", Integer, ForeignKey("galaxy_user.id"), index=True),
Column("private", Boolean, default=False),
Column("deleted", Boolean, index=True, default=False),
Column("email_alerts", JSONType, nullable=True),
Column("email_alerts", JSONType, nullable=True, default=list),
Column("times_downloaded", Integer),
Column("deprecated", Boolean, default=False))