Skip to content

Commit 7df5439

Browse files
authored
Merge pull request #862 from gpodder/fix/download_user
Fix download archived user data
2 parents 3c5df77 + b1a62e6 commit 7df5439

9 files changed

Lines changed: 48 additions & 21 deletions

File tree

mygpo/api/subscriptions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def update_subscriptions(self, user, device, add, remove):
6363

6464
conflicts = intersect(add, remove)
6565
if conflicts:
66-
msg = "can not add and remove '{}' at the same time".format(str(conflicts))
66+
msg = "{} {} can not add and remove '{}' at the same time".format(
67+
user.pk, device.uid, str(conflicts)
68+
)
6769
logger.warning(msg)
6870
raise RequestException(msg)
6971

mygpo/history/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def create_entry(
170170
if exists:
171171
logger.debug(
172172
"Trying to save duplicate {cls} for {user} "
173-
"/ {episode}".format(cls=cls, user=user, episode=episode)
173+
"/ {episode}".format(cls=cls, user=user, episode=episode.get_id())
174174
)
175175
# if such an entry already exists, do nothing
176176
return

mygpo/maintenance/merge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
logger = logging.getLogger(__name__)
2424

2525

26-
PG_UNIQUE_VIOLATION = '23505'
26+
PG_UNIQUE_VIOLATION = "23505"
2727

2828

2929
class IncorrectMergeException(Exception):

mygpo/podcasts/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class TitleModel(models.Model):
4747
subtitle = models.TextField(null=False, blank=True)
4848

4949
def __str__(self):
50-
return self.title
50+
return self.title or f"NOTITLE<{self.pk}>"
5151

5252
class Meta:
5353
abstract = True

mygpo/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_intOrNone(name, default):
4040

4141
MANAGERS = ADMINS
4242

43-
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
43+
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
4444

4545
DATABASES = {
4646
"default": dj_database_url.config(default="postgres://mygpo:mygpo@localhost/mygpo")

mygpo/users/management/commands/archive.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def handle(
9797
returncode=1,
9898
)
9999

100-
if options.get('archive'):
100+
if options.get("archive"):
101101
archive = options["archive"]
102102
else:
103103
archive = os.path.join(
@@ -230,7 +230,7 @@ def export_chapters(self):
230230
last_episode = None
231231
last_episode_id = None
232232
for c in Chapter.objects.filter(user=self.user.id).order_by(
233-
'episode_id', 'start'
233+
"episode_id", "start"
234234
):
235235
if last_episode_id and last_episode_id != c.episode_id:
236236
data.append(last_episode)
@@ -460,7 +460,7 @@ def export_subscriptions(self, episodes_with_state_only=True):
460460
@timed
461461
def export_opml(self):
462462
podcasts = get_subscribed_podcasts(self.user)
463-
exporter = Exporter('')
463+
exporter = Exporter("")
464464
opml = exporter.generate(podcasts)
465465
with open(os.path.join(self.output_dir, "subscriptions.opml"), "wb") as f:
466466
f.write(opml)

mygpo/users/migrations/0017_add_user_archived.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
class Migration(migrations.Migration):
77

88
dependencies = [
9-
('users', '0016_alter_userprofile_twitter'),
9+
("users", "0016_alter_userprofile_twitter"),
1010
]
1111

1212
operations = [
1313
migrations.AddField(
14-
model_name='userprofile',
15-
name='archive_path',
14+
model_name="userprofile",
15+
name="archive_path",
1616
field=models.TextField(blank=True),
1717
),
1818
migrations.AddField(
19-
model_name='userprofile',
20-
name='archived_date',
19+
model_name="userprofile",
20+
name="archived_date",
2121
field=models.DateTimeField(null=True),
2222
),
2323
]

mygpo/users/tasks.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,34 @@ def remove_inactive_users():
5757

5858
for user in users:
5959
clients = models.Client.objects.filter(user=user)
60-
logger.warning('Deleting %d clients of user "%s"', len(clients), user.username)
61-
clients.delete()
62-
logger.warning('Deleting user "%s"', user.username)
63-
user.delete()
60+
if user.profile.archive_path:
61+
logger.warning(
62+
'Would delete %d clients of ARCHIVED user "%s" at "%s"',
63+
len(clients),
64+
user.username,
65+
user.profile.archive_path,
66+
)
67+
elif clients:
68+
logger.warning(
69+
'Would delete %d clients of user "%s" joined %s last_login %s',
70+
len(clients),
71+
user.username,
72+
user.date_joined,
73+
user.last_login,
74+
)
75+
else:
76+
logger.info(
77+
'Would delete user "%s" joined %s last_login %s without client',
78+
user.username,
79+
user.date_joined,
80+
user.last_login,
81+
)
82+
83+
84+
# logger.warning('Deleting %d clients of user "%s"', len(clients), user.username)
85+
# clients.delete()
86+
# logger.warning('Deleting user "%s"', user.username)
87+
# user.delete()
6488

6589

6690
@shared_task(run_every=timedelta(hours=1))

mygpo/users/views/user.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import requests
2424
from oauth2client.client import FlowExchangeError
2525

26+
from mygpo.settings import ARCHIVE_ROOT
2627
from mygpo.web.forms import RestorePasswordForm
2728
from mygpo.constants import DEFAULT_LOGIN_REDIRECT
2829
from mygpo.users.models import UserProxy
@@ -168,14 +169,14 @@ def get(self, request):
168169
"""Shows the info page"""
169170

170171
# Do not show this page for already-logged-in users
172+
username = request.GET.get("user", "")
171173
if request.user.is_authenticated:
172-
# return HttpResponseRedirect(DEFAULT_LOGIN_REDIRECT)
173-
raise Exception("coucou")
174+
username = request.user.username
174175

175176
return render(
176177
request,
177178
"user_archived.html",
178-
{"username": request.GET.get("user", "")},
179+
{"username": username},
179180
)
180181

181182

@@ -196,7 +197,7 @@ def download_archive(request):
196197

197198
if not user.is_active and user.profile.archive_path is not None:
198199
archive_path = os.path.abspath(os.path.normpath(user.profile.archive_path))
199-
if os.path.dirname(archive_path) == settings.ARCHIVE_ROOT:
200+
if os.path.dirname(archive_path) == ARCHIVE_ROOT:
200201
return FileResponse(open(archive_path, "rb"), as_attachment=True)
201202
return HttpResponseBadRequest("Invalid archive path")
202203

0 commit comments

Comments
 (0)