Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1682 from johngian/getpocket-autovouch
Browse files Browse the repository at this point in the history
Autovouch users with getpocket.com emails as employees.
  • Loading branch information
johngian committed Apr 4, 2017
2 parents bfa6c31 + d428c2c commit ecadb51
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mozillians/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,12 @@ def COMPRESS_JINJA2_GET_ENVIRONMENT():

MAX_PHOTO_UPLOAD_SIZE = 8 * (1024 ** 2)

AUTO_VOUCH_DOMAINS = ('mozilla.com', 'mozilla.org', 'mozillafoundation.org')
AUTO_VOUCH_DOMAINS = (
'mozilla.com',
'mozilla.org',
'mozillafoundation.org',
'getpocket.com',
)
AUTO_VOUCH_REASON = 'An automatic vouch for being a Mozilla employee.'

# Django-CSP
Expand Down
62 changes: 62 additions & 0 deletions mozillians/users/migrations/0017_auto_20170404_0448.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from datetime import datetime

from django.db import migrations
from django.conf import settings


def autovouch_getpocket(apps, schema_editor):
"""Vouch all users with a getpocket email."""

UserProfile = apps.get_model('users', 'UserProfile')
ExternalAccount = apps.get_model('users', 'ExternalAccount')

primary_qs_list = UserProfile.objects.filter(
user__email__endswith='@getpocket.com',
).values_list('id', flat=True)

alternate_qs_list = ExternalAccount.objects.filter(
type='EMAIL',
identifier__endswith='@getpocket.com'
).values_list('user__id', flat=True)

unique_ids = set(list(primary_qs_list) + list(alternate_qs_list))

userprofile_qs = UserProfile.objects.filter(pk__in=unique_ids)

q_args = {
'autovouch': True,
'description': settings.AUTO_VOUCH_REASON
}

for user in userprofile_qs:
already_autovouched = user.vouches_received.filter(**q_args).exists()
reached_max_vouches = user.vouches_received.all().count() >= settings.VOUCH_COUNT_LIMIT
if not already_autovouched and not reached_max_vouches:
user.vouches_received.create(
voucher=None,
date=datetime.now(),
description=settings.AUTO_VOUCH_REASON,
autovouch=True
)
vouches = user.vouches_received.all().count()
user.is_vouched = vouches > 0
user.can_vouch = vouches > settings.CAN_VOUCH_THRESHOLD
user.save()


def backwards(apps, schema_editor):
pass


class Migration(migrations.Migration):

dependencies = [
('users', '0016_auto_20170331_0812'),
]

operations = [
migrations.RunPython(autovouch_getpocket, backwards),
]

0 comments on commit ecadb51

Please sign in to comment.