This is an automated email from the ASF dual-hosted git repository.
gcruz pushed a commit to branch gc/8484
in repository https://gitbox.apache.org/repos/asf/allura.git
The following commit(s) were added to refs/heads/gc/8484 by this push:
new 43e08e949 fixup! fixup! [#8484] added fediverse and instagram form
fields for projects
43e08e949 is described below
commit 43e08e949e8ef9a54c7f6474d52d76009b63ae7d
Author: Guillermo Cruz <[email protected]>
AuthorDate: Tue Dec 13 17:51:49 2022 -0600
fixup! fixup! [#8484] added fediverse and instagram form fields for projects
---
Allura/allura/ext/admin/widgets.py | 2 +-
Allura/allura/lib/validators.py | 2 +
Allura/allura/tests/functional/test_auth.py | 71 +++++++++++++++++++++++++----
3 files changed, 64 insertions(+), 11 deletions(-)
diff --git a/Allura/allura/ext/admin/widgets.py
b/Allura/allura/ext/admin/widgets.py
index 1c316772a..7af817d0b 100644
--- a/Allura/allura/ext/admin/widgets.py
+++ b/Allura/allura/ext/admin/widgets.py
@@ -224,7 +224,7 @@ class MetadataAdmin(ff.AdminForm):
field_type="text", label="Google Analytics ID",
attrs=(dict(placeholder='UA-123456-0',
pattern='UA-[0-9]+-[0-9]+')))
twitter_handle = ew.InputField(
- field_type="text", label='Twitter Handle')
+ field_type="text", label='Twitter Handle',
validator=V.SocialDomainValidator('twitter.com'))
facebook_page = ew.InputField(field_type="text", label='Facebook page',
validator=formencode.All(fev.URL(add_http=True),
V.SocialDomainValidator('facebook.com')) )
instagram_page = ew.InputField(
diff --git a/Allura/allura/lib/validators.py b/Allura/allura/lib/validators.py
index 7691138ef..aa0488705 100644
--- a/Allura/allura/lib/validators.py
+++ b/Allura/allura/lib/validators.py
@@ -508,6 +508,8 @@ class SocialDomainValidator(fev.FancyValidator):
self.domains = kw.get('domains')
def _to_python(self, value, state):
+ if value.startswith('@') and not re.match(FEDIVERSE_REGEX , value):
+ value = f'https://twitter.com/{value.replace("@","")}'
url = urlsplit(value)
if not re.match(FEDIVERSE_REGEX , value):
if self.domain and not self.domain ==
url.netloc.replace('www.',''):
diff --git a/Allura/allura/tests/functional/test_auth.py
b/Allura/allura/tests/functional/test_auth.py
index 5c459db65..941215623 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -1172,6 +1172,7 @@ class TestAuthRest(TestRestApiBase):
class TestPreferences(TestController):
+
@td.with_user_project('test-admin')
def test_personal_data(self):
from pytz import country_names
@@ -1179,7 +1180,6 @@ class TestPreferences(TestController):
setsex, setbirthdate, setcountry, setcity, settimezone = \
('Male', '19/08/1988', 'IT', 'Milan', 'Europe/Rome')
self.app.get('/auth/user_info/')
-
# Check if personal data is properly set
r = self.app.post('/auth/user_info/change_personal_data',
params=dict(
@@ -1231,6 +1231,40 @@ class TestPreferences(TestController):
user = M.User.query.get(username='test-admin')
assert user.birthdate is None
+ @td.with_user_project('test-admin')
+ def test_contacts_not_allowed(self):
+ self.app.get('/auth/user_info/')
+ socialnetwork = 'Facebook'
+ accounturl = 'http://www.faceboookk.com/test'
+ self.app.post('/auth/user_info/contacts/add_social_network',
+ params=dict(socialnetwork=socialnetwork,
+ accounturl=accounturl,
+ _session_id=self.app.cookies['_session_id'],
+ ))
+ user = M.User.query.get(username='test-admin')
+ assert len(user.socialnetworks) == 0
+
+ socialnetwork = 'Instagram'
+ accounturl = 'http://www.insta.com/test'
+ self.app.post('/auth/user_info/contacts/add_social_network',
+ params=dict(socialnetwork=socialnetwork,
+ accounturl=accounturl,
+ _session_id=self.app.cookies['_session_id'],
+ ))
+ user = M.User.query.get(username='test-admin')
+ assert len(user.socialnetworks) == 0
+
+ socialnetwork = 'Mastodon'
+ accounturl = '@username@server'
+ self.app.post('/auth/user_info/contacts/add_social_network',
+ params=dict(socialnetwork=socialnetwork,
+ accounturl=accounturl,
+ _session_id=self.app.cookies['_session_id'],
+ ))
+ user = M.User.query.get(username='test-admin')
+ assert len(user.socialnetworks) == 0
+
+
@td.with_user_project('test-admin')
def test_contacts(self):
# Add skype account
@@ -1256,7 +1290,7 @@ class TestPreferences(TestController):
# Add second social network account
socialnetwork2 = 'Twitter'
- accounturl2 = 'http://twitter.com/test'
+ accounturl2 = 'https://twitter.com/test'
self.app.post('/auth/user_info/contacts/add_social_network',
params=dict(socialnetwork=socialnetwork2,
accounturl='@test',
@@ -1264,8 +1298,19 @@ class TestPreferences(TestController):
))
user = M.User.query.get(username='test-admin')
assert len(user.socialnetworks) == 2
- assert {'socialnetwork': socialnetwork, 'accounturl': accounturl} in
user.socialnetworks
- assert {'socialnetwork': socialnetwork2, 'accounturl': accounturl2} in
user.socialnetworks
+ expected = [{'socialnetwork': socialnetwork, 'accounturl': accounturl},
+ {'socialnetwork': socialnetwork2, 'accounturl':
accounturl2}]
+ assert all([social in expected for social in user.socialnetworks])
+
+ socialnetwork3 = 'Mastodon'
+ accounturl3 = '@[email protected]'
+ self.app.post('/auth/user_info/contacts/add_social_network',
+ params=dict(socialnetwork=socialnetwork3,
+ accounturl=accounturl3,
+ _session_id=self.app.cookies['_session_id'],
+ ))
+ user = M.User.query.get(username='test-admin')
+ assert len(user.socialnetworks) == 3
# Remove first social network account
self.app.post('/auth/user_info/contacts/remove_social_network',
@@ -1274,8 +1319,10 @@ class TestPreferences(TestController):
_session_id=self.app.cookies['_session_id'],
))
user = M.User.query.get(username='test-admin')
- assert len(user.socialnetworks) == 1
- assert {'socialnetwork': socialnetwork2, 'accounturl': accounturl2} in
user.socialnetworks
+ assert len(user.socialnetworks) == 2
+ expected = [{'socialnetwork': socialnetwork2, 'accounturl':
accounturl2},
+ {'socialnetwork': socialnetwork3, 'accounturl': accounturl3}]
+ assert all([social in expected for social in user.socialnetworks])
# Add empty social network account
self.app.post('/auth/user_info/contacts/add_social_network',
@@ -1283,8 +1330,10 @@ class TestPreferences(TestController):
_session_id=self.app.cookies['_session_id'],
))
user = M.User.query.get(username='test-admin')
- assert len(user.socialnetworks) == 1
- assert {'socialnetwork': socialnetwork2, 'accounturl': accounturl2} in
user.socialnetworks
+ assert len(user.socialnetworks) == 2
+ expected = [{'socialnetwork': socialnetwork2, 'accounturl':
accounturl2},
+ {'socialnetwork': socialnetwork3, 'accounturl': accounturl3}]
+ assert all([social in expected for social in user.socialnetworks])
# Add invalid social network account
self.app.post('/auth/user_info/contacts/add_social_network',
@@ -1292,8 +1341,10 @@ class TestPreferences(TestController):
_session_id=self.app.cookies['_session_id'],
))
user = M.User.query.get(username='test-admin')
- assert len(user.socialnetworks) == 1
- assert {'socialnetwork': socialnetwork2, 'accounturl': accounturl2} in
user.socialnetworks
+ assert len(user.socialnetworks) == 2
+ expected = [{'socialnetwork': socialnetwork2, 'accounturl':
accounturl2},
+ {'socialnetwork': socialnetwork3, 'accounturl': accounturl3}]
+ assert all([social in expected for social in user.socialnetworks])
# Add telephone number
telnumber = '+3902123456'