diff options
author | Milo Casagrande <milo.casagrande@linaro.org> | 2014-02-14 17:10:20 +0100 |
---|---|---|
committer | Milo Casagrande <milo.casagrande@linaro.org> | 2014-02-14 17:10:20 +0100 |
commit | 1d13056dddfdc8fca3262621ce781443e8460b6a (patch) | |
tree | ae1f5d2756b8bee4c661ae4ca348de6cf54305a4 | |
parent | ad201c218cc4d1495f8fb984a6e807c423114b18 (diff) |
Reworked the way we chacke if a patch is valid.
Change-Id: I8efc2e5cd8a8f10811ad311c6f587b7eef4bf25c
-rwxr-xr-x | apps/patchwork/bin/parsemail.py | 70 |
1 files changed, 34 insertions, 36 deletions
diff --git a/apps/patchwork/bin/parsemail.py b/apps/patchwork/bin/parsemail.py index f3cd6e2..85f9fb6 100755 --- a/apps/patchwork/bin/parsemail.py +++ b/apps/patchwork/bin/parsemail.py @@ -487,26 +487,27 @@ def is_valid_patch(submitter, author): """ 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) + # XXX: dumb, but effective, and leave the crowd validation only when + # necessary. + if "@linaro.org" in submitter.email: + valid_patch |= True - cache_db = PatchworkDB(settings.CROWD_USERS_DB_FILE) - atexit.register(cache_db.close) + if author is not None and "@linaro.org" in author.email: + valid_patch |= True - 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) + if not valid_patch: + if (settings.AUTH_CROWD_APPLICATION_USER is not None and + settings.CROWD_USERS_DB_FILE is not None): + 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 @@ -538,13 +539,24 @@ def parse_mail(mail): (patch, comment) = find_content(project, mail) (name, author, is_new_author) = find_patch_name_and_author(comment) + if comment: + if save_required: + submitter.save() + # looks like the original constructor for Comment takes the pk + # when the Comment is created. reset it here. + if patch: + comment.patch = patch + comment.submitter = submitter + comment.msgid = msgid + try: + comment.save() + except Exception, ex: + print str(ex) + # If submitter nor author of a patch are not Linaro, we move on. valid_patch = is_valid_patch(submitter, author) - if not valid_patch: - return 0 - - if patch: + if patch and valid_patch: # we delay the saving until we know we have a patch. if save_required: submitter.save() @@ -568,20 +580,6 @@ def parse_mail(mail): except Exception, ex: print str(ex) - if comment: - if save_required: - submitter.save() - # looks like the original constructor for Comment takes the pk - # when the Comment is created. reset it here. - if patch: - comment.patch = patch - comment.submitter = submitter - comment.msgid = msgid - try: - comment.save() - except Exception, ex: - print str(ex) - return 0 |