mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-05 16:58:59 +00:00
Only premiums users can share multiple stories from a single feed per day.
This commit is contained in:
parent
7098af9fa2
commit
162b0346a5
3 changed files with 37 additions and 0 deletions
|
@ -152,6 +152,14 @@ class Profile(models.Model):
|
|||
|
||||
logging.user(self.user, "Deleting user: %s" % self.user)
|
||||
self.user.delete()
|
||||
|
||||
def check_if_spammer(self):
|
||||
feed_opens = UserSubscription.objects.filter(user=self.user)\
|
||||
.aggregate(sum=Sum('feed_opens'))['sum']
|
||||
feed_count = UserSubscription.objects.filter(user=self.user).count()
|
||||
|
||||
if not feed_opens and not feed_count:
|
||||
return True
|
||||
|
||||
def activate_premium(self):
|
||||
from apps.profile.tasks import EmailNewPremium
|
||||
|
|
|
@ -9,6 +9,7 @@ import random
|
|||
import requests
|
||||
import HTMLParser
|
||||
from collections import defaultdict
|
||||
from pprint import pprint
|
||||
from BeautifulSoup import BeautifulSoup
|
||||
from mongoengine.queryset import Q
|
||||
from django.conf import settings
|
||||
|
@ -1486,7 +1487,30 @@ class MSharedStory(mongo.Document):
|
|||
socialsub.save()
|
||||
|
||||
self.delete()
|
||||
|
||||
@classmethod
|
||||
def feed_quota(cls, user_id, feed_id, days=1, quota=1):
|
||||
day_ago = datetime.datetime.now()-datetime.timedelta(days=days)
|
||||
shared_count = cls.objects.filter(shared_date__gte=day_ago, story_feed_id=feed_id).count()
|
||||
|
||||
return shared_count >= quota
|
||||
|
||||
@classmethod
|
||||
def count_potential_spammers(cls, days=1):
|
||||
day_ago = datetime.datetime.now()-datetime.timedelta(days=days)
|
||||
stories = cls.objects.filter(shared_date__gte=day_ago)
|
||||
shared = [{'u': s.user_id, 'f': s.story_feed_id} for s in stories]
|
||||
ddusers = defaultdict(lambda: defaultdict(int))
|
||||
for story in shared:
|
||||
ddusers[story['u']][story['f']] += 1
|
||||
|
||||
users = {}
|
||||
for user_id, feeds in ddusers.items():
|
||||
users[user_id] = dict(feeds)
|
||||
|
||||
pprint(users)
|
||||
return users
|
||||
|
||||
@classmethod
|
||||
def get_shared_stories_from_site(cls, feed_id, user_id, story_url, limit=3):
|
||||
your_story = cls.objects.filter(story_feed_id=feed_id,
|
||||
|
|
|
@ -542,6 +542,11 @@ def mark_story_as_shared(request):
|
|||
'message': 'Could not find the original story and no copies could be found.'
|
||||
})
|
||||
|
||||
if not request.user.profile.is_premium and MSharedStory.feed_quota(request.user.pk, feed_id):
|
||||
return json.json_response(request, {
|
||||
'code': -1,
|
||||
'message': 'Only premium users can share multiple stories per day from the same site.'
|
||||
})
|
||||
shared_story = MSharedStory.objects.filter(user_id=request.user.pk,
|
||||
story_feed_id=feed_id,
|
||||
story_hash=story['story_hash']).limit(1).first()
|
||||
|
|
Loading…
Add table
Reference in a new issue