Adding deletion of sites to Account dialog. Sends an email with exported OPML as a backup/undo.

This commit is contained in:
Samuel Clay 2013-05-23 18:14:21 -07:00
parent 37cc5eb7d3
commit fbb9586d7b
7 changed files with 104 additions and 5 deletions

View file

@ -20,7 +20,7 @@ from apps.reader.models import UserSubscription
from apps.rss_feeds.models import Feed, MStory
from apps.rss_feeds.tasks import NewFeeds
from apps.rss_feeds.tasks import SchedulePremiumSetup
from apps.feed_import.models import GoogleReaderImporter
from apps.feed_import.models import GoogleReaderImporter, OPMLExporter
from utils import log as logging
from utils import json_functions as json
from utils.user_functions import generate_secret_token
@ -304,7 +304,7 @@ class Profile(models.Model):
logging.user(self.user, "~FRCanceling Stripe subscription")
return True
def queue_new_feeds(self, new_feeds=None):
if not new_feeds:
new_feeds = UserSubscription.objects.filter(user=self.user,
@ -353,7 +353,34 @@ class Profile(models.Model):
msg.send(fail_silently=True)
logging.user(self.user, "~BB~FM~SBSending email for new user: %s" % self.user.email)
def send_opml_export_email(self):
if not self.user.email:
return
MSentEmail.objects.get_or_create(receiver_user_id=self.user.pk,
email_type='opml_export')
exporter = OPMLExporter(self.user)
opml = exporter.process()
params = {
'feed_count': UserSubscription.objects.filter(user=self.user).count(),
}
user = self.user
text = render_to_string('mail/email_opml_export.txt', params)
html = render_to_string('mail/email_opml_export.xhtml', params)
subject = "Backup OPML file of your NewsBlur sites"
filename= 'NewsBlur Subscriptions - %s.xml' % datetime.datetime.now().strftime('%Y-%m-%d')
msg = EmailMultiAlternatives(subject, text,
from_email='NewsBlur <%s>' % settings.HELLO_EMAIL,
to=['%s <%s>' % (user, user.email)])
msg.attach_alternative(html, "text/html")
msg.attach(filename, opml, 'text/xml')
msg.send(fail_silently=True)
logging.user(self.user, "~BB~FM~SBSending OPML backup email to: %s" % self.user.email)
def send_first_share_to_blurblog_email(self, force=False):
from apps.social.models import MSocialProfile, MSharedStory

View file

@ -21,4 +21,5 @@ urlpatterns = patterns('',
url(r'^delete_account/?', views.delete_account, name='profile-delete-account'),
url(r'^forgot_password_return/?', views.forgot_password_return, name='profile-forgot-password-return'),
url(r'^forgot_password/?', views.forgot_password, name='profile-forgot-password'),
url(r'^delete_all_sites/?', views.delete_all_sites, name='profile-delete-all-sites'),
)

View file

@ -13,7 +13,7 @@ from django.shortcuts import render_to_response
from django.core.mail import mail_admins
from django.conf import settings
from apps.profile.models import Profile, PaymentHistory, RNewUserQueue
from apps.reader.models import UserSubscription
from apps.reader.models import UserSubscription, UserSubscriptionFolders
from apps.profile.forms import StripePlusPaymentForm, PLANS, DeleteAccountForm
from apps.profile.forms import ForgotPasswordForm, ForgotPasswordReturnForm, AccountSettingsForm
from apps.social.models import MSocialServices, MActivity, MSocialProfile
@ -389,4 +389,21 @@ def forgot_password_return(request):
return {
'forgot_password_return_form': form,
}
}
@ajax_login_required
@json.json_view
def delete_all_sites(request):
request.user.profile.send_opml_export_email()
subs = UserSubscription.objects.filter(user=request.user)
sub_count = subs.count()
subs.delete()
usf = UserSubscriptionFolders.objects.get(user=request.user)
usf.folders = '[]'
usf.save()
logging.user(request.user, "~BC~FRDeleting %s sites" % sub_count)
return dict(code=1)

View file

@ -1432,6 +1432,10 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
}, callback, error_callback);
},
delete_all_sites: function(callback, error_callback) {
this.make_request('/profile/delete_all_sites', {}, callback, error_callback);
},
follow_twitter_account: function(username, callback) {
this.make_request('/oauth/follow_twitter_account', {'username': username}, callback);
},

View file

@ -100,10 +100,19 @@ _.extend(NEWSBLUR.ReaderAccount.prototype, {
]),
$.make('div', { className: 'NB-preference NB-preference-delete' }, [
$.make('div', { className: 'NB-preference-options' }, [
$.make('a', { className: 'NB-splash-link', href: NEWSBLUR.URLs['delete-account'] }, 'Delete my account')
$.make('div', { className: 'NB-splash-link NB-account-delete-all-sites' }, 'Delete all of my sites')
]),
$.make('div', { className: 'NB-preference-label'}, [
'Erase yourself',
$.make('div', { className: 'NB-preference-sublabel' }, 'Notice: You will be emailed a backup of your sites')
])
]),
$.make('div', { className: 'NB-preference NB-preference-delete' }, [
$.make('div', { className: 'NB-preference-options' }, [
$.make('a', { className: 'NB-splash-link', href: NEWSBLUR.URLs['delete-account'] }, 'Delete my account')
]),
$.make('div', { className: 'NB-preference-label'}, [
'Erase yourself permanently',
$.make('div', { className: 'NB-preference-sublabel' }, 'Warning: This is actually permanent')
])
])
@ -237,6 +246,19 @@ _.extend(NEWSBLUR.ReaderAccount.prototype, {
}, this));
},
delete_all_sites: function() {
var $link = $(".NB-account-delete-all-sites", this.$modal);
if (window.confirm("Positive you want to delete everything?")) {
NEWSBLUR.assets.delete_all_sites(_.bind(function() {
NEWSBLUR.assets.load_feeds();
$link.replaceWith($.make('div', 'Everything has been deleted.'));
}, this), _.bind(function() {
$link.replaceWith($.make('div', { className: 'NB-error' }, 'There was a problem deleting your sites.'));
}, this));
}
},
handle_cancel: function() {
var $cancel = $('.NB-modal-cancel', this.$modal);
@ -347,6 +369,11 @@ _.extend(NEWSBLUR.ReaderAccount.prototype, {
e.preventDefault();
self.cancel_premium();
});
$.targetIs(e, { tagSelector: '.NB-account-delete-all-sites' }, function($t, $p) {
e.preventDefault();
self.delete_all_sites();
});
$.targetIs(e, { tagSelector: '.NB-modal-cancel' }, function($t, $p) {
e.preventDefault();

View file

@ -0,0 +1,8 @@
{% extends "mail/email_base.txt" %}
{% load utils_tags %}
{% block body %}Here's a backup of your sites on NewsBlur. It contains <b>{{ feed_count }}</b> site{{ feed_count|pluralize }}.
You can re-upload the attached file to NewsBlur and get all of your sites back.
Just go to Manage > Import > Upload OPML.{% endblock body %}

View file

@ -0,0 +1,15 @@
{% extends "mail/email_base.xhtml" %}
{% load utils_tags %}
{% block body %}
<p style="margin-top: 12px;">
Here's a backup of your sites on NewsBlur. It contains <b>{{ feed_count }}</b>
site{{ feed_count|pluralize }}.
</p>
<p style="margin-top: 12px;">
You can re-upload the attached file to NewsBlur and get all of your sites back. <br />
Just go to Manage > Import > Upload OPML.
</p>
{% endblock %}