Skip to content

Commit

Permalink
Merge pull request #8 from eea/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
valipod committed Apr 8, 2021
2 parents 891725c + 3f0e5e9 commit e3419a7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

2.6 - (2021-04-08)
---------------------------
* add email validation (replacing validate_email package) [dumitval]

2.5 - (2021-01-08)
---------------------------
* Bugfix related to encoding in search [dumitval]
Expand Down
10 changes: 9 additions & 1 deletion eea/usersdb/db_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,6 @@ def set_user_info(self, user_id, new_info):
log.info("Modifying info for user %r", user_id)

for dn, modify_statements in six.iteritems(diff):
# import pdb; pdb.set_trace() # no longer needed ?
result = self.conn.modify_s(dn, tuple(modify_statements))
assert result[:2] == (ldap.RES_MODIFY, [])

Expand Down Expand Up @@ -1439,6 +1438,15 @@ def members_in_org(self, org_id):
return [self._user_id(d) for d in attr['uniqueMember'] if
d.decode() != '']

@log_ldap_exceptions
def org_country(self, org_id):
''' return two letter ISD country code of organisation '''
query_dn = self._org_dn(org_id)
result = self.conn.search_s(query_dn, ldap.SCOPE_BASE,
attrlist=('c',))
assert len(result) == 1
return result[0][1]['c'][0].decode('utf-8')

@log_ldap_exceptions
def pending_members_in_org(self, org_id):
''' list pending members of org '''
Expand Down
14 changes: 10 additions & 4 deletions eea/usersdb/schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
''' users db schema '''
import re
from six.moves import range
import colander
import phonenumbers
Expand All @@ -10,7 +11,7 @@
"country / area code provided. If you second check and believe "
"the number is correct, please contact HelpDesk.")
)
INVALID_EMAIL = "Invalid email format"
INVALID_EMAIL = "Invalid email format %s"

NUMBER_FORMAT = phonenumbers.PhoneNumberFormat.INTERNATIONAL

Expand Down Expand Up @@ -74,9 +75,14 @@ def _latin_validator(node, value):

# max length for domain name labels is 63 characters per RFC 1034
_url_validator = colander.Regex(r'^http[s]?\://', msg=INVALID_URL)
_email_validator = colander.Regex(
r"(?:^|\s)[-a-z-A-Z0-9_.']+@(?:[-a-z-A-Z0-9]+\.)+[a-z-A-Z]{2,63}(?:\s|$)",
msg=INVALID_EMAIL)


def _email_validator(node, value):
""" email validator """
pattern = (r"(?:^|\s)[-a-z-A-Z0-9_.']+@(?:[-a-z-A-Z0-9]+\.)+[a-z-A-Z]"
r"{2,63}(?:\s|$)")
if not re.match(pattern, value):
raise colander.Invalid(node, INVALID_EMAIL % value)


class UserInfoSchema(colander.MappingSchema):
Expand Down
2 changes: 1 addition & 1 deletion eea/usersdb/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5
2.6

0 comments on commit e3419a7

Please sign in to comment.