summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilo Casagrande <milo@ubuntu.com>2013-12-05 18:43:40 +0100
committerMilo Casagrande <milo@ubuntu.com>2013-12-05 18:43:40 +0100
commit52d9bf2bfcd4a0c47eab0f21d7fc5947333766ba (patch)
treebd341080bf8d7bb51aa2ef486de18b88409bab4a
parente255a154990b724bff7bd3bf183b0d487dfbdaa3 (diff)
Added crowd integration for email checking.
-rwxr-xr-xapps/patchwork/bin/parsemail.py45
1 files changed, 38 insertions, 7 deletions
diff --git a/apps/patchwork/bin/parsemail.py b/apps/patchwork/bin/parsemail.py
index d94d05b..f1f5766 100755
--- a/apps/patchwork/bin/parsemail.py
+++ b/apps/patchwork/bin/parsemail.py
@@ -20,6 +20,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import _pythonpath
+import atexit
import chardet
import datetime
import operator
@@ -37,8 +38,11 @@ except ImportError:
from email.Header import Header, decode_header
from email.Utils import parsedate_tz, mktime_tz
+from patchmetrics.crowd import Crowd
+from patchwork.db import PatchworkDB
from patchwork.parser import parse_patch
from patchwork.models import Patch, Project, Person, Comment, State
+from patchwork.utils import is_linaro_user
from django.contrib.auth.models import User
default_patch_state = 'New'
@@ -498,6 +502,39 @@ def get_delegate(delegate_email):
return None
+def is_valid_patch(submitter, author):
+ """A patch is valid if submitter or author are valid Linaro users.
+
+ :param submitter: The submitter to check, a Person object.
+ :param author: The author to check, a Person object.
+ :return True if one between submitter and author is a valid Linaro user.
+ """
+ valid_patch = False
+
+ if settings.AUTH_CROWD_APPLICATION_USER is None and
+ settings.CROWD_USERS_DB_FILE is None:
+ # If none of the above settings is defined, fallback to an hardoceded
+ # check and accept only linaro.org email addresses.
+ if "@linaro.org" in submitter.email:
+ valid_patch |= True
+
+ if author is not None and "@linaro.org" in author.email:
+ valid_patch |= True
+ else:
+ crwd = Crowd(settings.AUTH_CROWD_APPLICATION_USER,
+ settings.AUTH_CROWD_APPLICATION_PASSWORD,
+ settings.AUTH_CROWD_SERVER_REST_URI)
+
+ cache_db = PatchworkDB(settings.CROWD_USERS_DB_FILE)
+ atexit.register(cache_db.close)
+
+ valid_patch |= is_linaro_user(submitter.email, cache_db, crwd)
+ if author is not None:
+ valid_patch |= is_linaro_user(author.email, cache_db, crwd)
+
+ return valid_patch
+
+
def parse_mail(mail):
# some basic sanity checks
@@ -526,13 +563,7 @@ def parse_mail(mail):
(name, author, is_new_author) = find_patch_name_and_author(comment)
# If submitter nor author of a patch are not Linaro, we move on.
- # TODO: may be worth to integrate with crowd.
- valid_patch = False
- if "@linaro.org" in submitter.email:
- valid_patch |= True
-
- if author is not None and "@linaro.org" in author.email:
- valid_patch |= True
+ valid_patch = is_valid_patch(submitter, author)
if not valid_patch:
return 0