FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit ff8eb106 authored by Dr Rich Wareham's avatar Dr Rich Wareham
Browse files

Merge branch 'clean-group-desc' into 'master'

Clean Group Descriptions

Closes sync-deploy#11

See merge request !14
parents 8793623f 1795bfa1
No related branches found
No related tags found
1 merge request!14Clean Group Descriptions
Pipeline #50504 passed
...@@ -476,7 +476,10 @@ def sync(configuration, *, read_only=True): ...@@ -476,7 +476,10 @@ def sync(configuration, *, read_only=True):
'name': _trim_text( 'name': _trim_text(
managed_group_entry.groupName, maxlen=73, suffix=sync_config.group_name_suffix managed_group_entry.groupName, maxlen=73, suffix=sync_config.group_name_suffix
), ),
'description': _trim_text(managed_group_entry.description, maxlen=300) 'description': _trim_text(
_clean_group_desc(managed_group_entry.description),
maxlen=300
)
} }
# Find existing Google group (if any). # Find existing Google group (if any).
...@@ -867,3 +870,21 @@ def _trim_text(text, *, maxlen, cont='...', suffix=''): ...@@ -867,3 +870,21 @@ def _trim_text(text, *, maxlen, cont='...', suffix=''):
text[0:maxlen-len(cont)-len(suffix)]+cont+suffix text[0:maxlen-len(cont)-len(suffix)]+cont+suffix
if len(text)+len(suffix) > maxlen else text+suffix if len(text)+len(suffix) > maxlen else text+suffix
) )
def _clean_group_desc(s):
"""
Clean any "bad characters" in group descriptions.
Google support (https://support.google.com/a/answer/9193374) says:
"descriptions can’t contain equal signs (=), or brackets (<,>)"
>>> _clean_group_desc('a<b>c=d')
'abcd'
"""
return ''.join(c for c in s if c not in _CLEAN_GROUP_DESC_BAD_CHARS)
# Characters stripped by _clean_group_desc. Present as a constant to avoid re-creating it.
_CLEAN_GROUP_DESC_BAD_CHARS = '=<>'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment