Adding full delete user capability. Also removing social beta invite system in prep for launch.

This commit is contained in:
Samuel Clay 2012-07-28 18:33:07 -07:00
parent eaf585d47d
commit 43045a85d7
8 changed files with 53 additions and 114 deletions

View file

@ -67,6 +67,51 @@ class Profile(models.Model):
except DatabaseError:
print " ---> Profile not saved. Table isn't there yet."
def delete_user(self, confirm=False):
if not confirm:
print " ---> You must pass confirm=True to delete this user."
return
from apps.social.models import MSocialProfile, MSharedStory, MSocialSubscription
from apps.social.models import MActivity, MInteraction
social_profile = MSocialProfile.objects.get(user_id=self.user.pk)
print " ---> Unfollowing %s followings and %s followers" % (social_profile.following_count,
social_profile.follower_count)
for follow in social_profile.following_user_ids:
social_profile.unfollow_user(follow)
for follower in social_profile.follower_user_ids:
follower_profile = MSocialProfile.objects.get(user_id=follower)
follower_profile.unfollow_user(self.user.pk)
social_profile.delete()
shared_stories = MSharedStory.objects.filter(user_id=self.user.pk)
print " ---> Deleting %s shared stories" % shared_stories.count()
for story in shared_stories:
story.delete()
subscriptions = MSocialSubscription.objects.filter(subscription_user_id=self.user.pk)
print " ---> Deleting %s social subscriptions" % subscriptions.count()
subscriptions.delete()
interactions = MInteraction.objects.filter(user_id=self.user.pk)
print " ---> Deleting %s interactions for user."
interactions.delete()
interactions = MInteraction.objects.filter(with_user_id=self.user.pk)
print " ---> Deleting %s interactions with user."
interactions.delete()
activities = MActivity.objects.filter(user_id=self.user.pk)
print " ---> Deleting %s activities for user."
activities.delete()
activities = MActivity.objects.filter(with_user_id=self.user.pk)
print " ---> Deleting %s activities with user."
activities.delete()
print " ---> Deleting user: %s" % self.user
self.user.delete()
def activate_premium(self):
from apps.profile.tasks import EmailNewPremium
EmailNewPremium.delay(user_id=self.user.pk)
@ -184,36 +229,7 @@ NewsBlur""" % {'user': self.user.username, 'feeds': subs.count()}
user.save()
logging.user(self.user, "~BB~FM~SBSending email for forgotten password: %s" % self.user.email)
def send_social_beta_email(self):
from apps.social.models import MRequestInvite
if not self.user.email:
print "Please provide an email address."
return
user = self.user
text = render_to_string('mail/email_social_beta.txt', locals())
html = render_to_string('mail/email_social_beta.xhtml', locals())
subject = "Psst, you're in..."
msg = EmailMultiAlternatives(subject, text,
from_email='NewsBlur <%s>' % settings.HELLO_EMAIL,
to=['%s <%s>' % (user, user.email)])
msg.attach_alternative(html, "text/html")
msg.send()
invites = MRequestInvite.objects.filter(username__iexact=self.user.username)
if not invites:
invites = MRequestInvite.objects.filter(username__iexact=self.user.email)
if not invites:
print "User not on invite list"
else:
for invite in invites:
print "Invite listed as: %s" % invite.username
invite.email_sent = True
invite.save()
logging.user(self.user, "~BB~FM~SBSending email for social beta: %s" % self.user.email)
def send_upload_opml_finished_email(self, feed_count):
if not self.user.email:
print "Please provide an email address."

View file

@ -29,63 +29,6 @@ from utils.story_functions import truncate_chars, strip_tags, linkify
from utils import json_functions as json
RECOMMENDATIONS_LIMIT = 5
class MRequestInvite(mongo.Document):
username = mongo.StringField()
email_sent = mongo.BooleanField()
meta = {
'collection': 'social_invites',
'allow_inheritance': False,
}
def __unicode__(self):
return "%s%s" % (self.username, '*' if self.email_sent else '')
@classmethod
def blast(cls):
invites = cls.objects.filter(email_sent=None)
print ' ---> Found %s invites...' % invites.count()
for invite in invites:
try:
invite.send_email()
except:
print ' ***> Could not send invite to: %s. Deleting.' % invite.username
invite.delete()
def send_email(self):
user = User.objects.filter(username__iexact=self.username)
if not user:
user = User.objects.filter(email__iexact=self.username)
if user:
user = user[0]
email = user.email or self.username
else:
user = {
'username': self.username,
'profile': {
'autologin_url': '/',
}
}
email = self.username
params = {
'user': user,
}
text = render_to_string('mail/email_social_beta.txt', params)
html = render_to_string('mail/email_social_beta.xhtml', params)
subject = "Psst, you're in..."
msg = EmailMultiAlternatives(subject, text,
from_email='NewsBlur <%s>' % settings.HELLO_EMAIL,
to=['<%s>' % (email)])
msg.attach_alternative(html, "text/html")
msg.send()
self.email_sent = True
self.save()
logging.debug(" ---> ~BB~FM~SBSending email for social beta: %s" % self.username)
class MSocialProfile(mongo.Document):
user_id = mongo.IntField(unique=True)
@ -1414,7 +1357,8 @@ class MSharedStory(mongo.Document):
if comment['source_user_id']:
stories[s][comment_set][c]['source_user'] = profiles[comment['source_user_id']]
for r, reply in enumerate(comment['replies']):
stories[s][comment_set][c]['replies'][r]['user'] = profiles[reply['user_id']]
if reply['user_id'] in profiles:
stories[s][comment_set][c]['replies'][r]['user'] = profiles[reply['user_id']]
return stories

View file

@ -2,7 +2,6 @@ from django.conf.urls.defaults import url, patterns
from apps.social import views
urlpatterns = patterns('',
url(r'^request_invite/?$', views.request_invite, name='request-invite'),
url(r'^share_story/?$', views.mark_story_as_shared, name='mark-story-as-shared'),
url(r'^unshare_story/?$', views.mark_story_as_unshared, name='mark-story-as-unshared'),
url(r'^load_user_friends/?$', views.load_user_friends, name='load-user-friends'),

View file

@ -12,7 +12,7 @@ from django.conf import settings
from django.template import RequestContext
from apps.rss_feeds.models import MStory, Feed, MStarredStory
from apps.social.models import MSharedStory, MSocialServices, MSocialProfile, MSocialSubscription, MCommentReply
from apps.social.models import MRequestInvite, MInteraction, MActivity
from apps.social.models import MInteraction, MActivity
from apps.social.tasks import PostToService, EmailCommentReplies, EmailStoryReshares
from apps.analyzer.models import MClassifierTitle, MClassifierAuthor, MClassifierFeed, MClassifierTag
from apps.analyzer.models import apply_classifier_titles, apply_classifier_feeds, apply_classifier_authors, apply_classifier_tags
@ -30,14 +30,6 @@ from utils.story_functions import strip_tags
from utils import jennyholzer
from vendor.timezones.utilities import localtime_for_timezone
@json.json_view
def request_invite(request):
if not request.POST.get('username'):
return {}
MRequestInvite.objects.create(username=request.POST['username'])
logging.user(request, " ---> ~BG~FB~SBInvite requested: %s" % request.POST['username'])
return {}
@json.json_view
def load_social_stories(request, user_id, username=None):

View file

@ -7,7 +7,9 @@ NEWSBLUR.Views.ProfileThumb = Backbone.View.extend({
},
initialize: function() {
this.model.profile_thumb_view = this;
if (this.model) {
this.model.profile_thumb_view = this;
}
},
render: function() {

View file

@ -64,6 +64,7 @@ NEWSBLUR.Views.StoryComment = Backbone.View.extend({
var user_id = NEWSBLUR.Globals.user_id;
var $replies = this.model.replies.map(_.bind(function(reply) {
if (!NEWSBLUR.assets.get_user(reply.user_id)) return;
return new NEWSBLUR.Views.StoryCommentReply({model: reply, comment: this}).render().el;
}, this));
$replies = $.make('div', { className: 'NB-story-comment-replies' }, $replies);
@ -75,6 +76,7 @@ NEWSBLUR.Views.StoryComment = Backbone.View.extend({
var $users = $.make('div', { className: 'NB-story-comment-likes-users' });
_.each(this.model.get('liking_users'), function(user_id) {
if (!NEWSBLUR.assets.get_user(user_id)) return;
var $thumb = NEWSBLUR.Views.ProfileThumb.create(user_id).render().el;
$users.append($thumb);
});

View file

@ -1,8 +0,0 @@
{% extends "mail/email_base.txt" %}
{% block body %}Sweet! It's beta time.
OK, you made it into the private beta for NewsBlur's new social features. There's a whole world of story sharing and interaction waiting for you.
Go here and sign in: http://dev.newsblur.com/?letmein={{ user.username }}
If you notice anything oddball, incorrect, or doesn't have that new website smell, just reply to this email. I'm all ears and then some.{% endblock body %}

View file

@ -1,8 +0,0 @@
{% extends "mail/email_base.xhtml" %}
{% block body %}
<p style="font-size: 37px; color:#555555; margin-top: 18px;margin-bottom: 10px;padding-top:6px;">Sweet! It's beta time.</p>
<p style="line-height: 20px;">OK, you made it into the private beta for NewsBlur's new social features. There's a whole world of story sharing and interaction waiting for you.</p>
<p style="line-height: 20px;">Go here and sign in: <a href="http://dev.newsblur.com/?letmein={{ user.username }}">http://dev.newsblur.com/?letmein={{ user.username }}</a></p>
<p style="line-height: 20px;">If you notice anything oddball, incorrect, or doesn't have that new website smell, just reply to this email. I'm all ears and then some.</p>
{% endblock %}