Handle users who don't meet requirements more sensibly
@@ -223,35 +223,38 @@ class Editor(models.Model):
To wit, users must:
* Have >= 500 edits
* Be active for >= 6 months
- * Have Special:Email User enabled
* Not be blocked on any projects
Note that we won't prohibit signups or applications on this basis.
Coordinators have discretion to approve people who are near the cutoff.
- Furthermore, editors who are active on multiple wikis may meet this
- minimum when their account activity is aggregated even if they do not
- meet it on their home wiki - but we can only check the home wiki.
"""
- try:
+ # If, for some reason, this information hasn't come through,
+ # default to user not being valid.
+ if not global_userinfo:
+ return False
# Check: >= 500 edits
- assert int(global_userinfo['editcount']) >= 500
+ enough_edits = int(global_userinfo['editcount']) >= 500
# Check: registered >= 6 months ago
- # Try oauth registration date first. If it's not valid, try the global_userinfo date
+ # Try oauth registration date first. If it's not valid,
+ # try the global_userinfo date
try:
- reg_date = datetime.strptime(identity['registered'], '%Y%m%d%H%M%S').date()
+ reg_date = datetime.strptime(identity['registered'],
+ '%Y%m%d%H%M%S').date()
except:
- reg_date = datetime.strptime(global_userinfo['registration'], '%Y-%m-%dT%H:%M:%SZ').date()
- assert datetime.today().date() - timedelta(days=182) >= reg_date
+ reg_date = datetime.strptime(global_userinfo['registration'],
+ '%Y-%m-%dT%H:%M:%SZ').date()
+ account_old_enough = datetime.today().date() - timedelta(days=182) >= reg_date
# Check: not blocked
- assert identity['blocked'] == False
+ not_blocked = identity['blocked'] == False
+ if enough_edits and account_old_enough and not_blocked:
return True
- # Was assertion error, now we're catching any error in case we have
- # an API communication or data problem.
- except:
- logger.exception('Editor was not valid.')
+ else:
+ logger.info('Editor {username} was not valid.'.format(
+ username=self.wp_username
+ ))
return False
def get_global_userinfo(self, identity):
