mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
Fixes #2665. Regenerated by tabbott with `lint --fix` after a rebase and change in parameters. Note from tabbott: In a few cases, this converts technical debt in the form of unsorted imports into different technical debt in the form of our largest files having very long, ugly import sequences at the start. I expect this change will increase pressure for us to split those files, which isn't a bad thing. Signed-off-by: Anders Kaseorg <anders@zulip.com>
56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
"""
|
|
This module stores data for "External Account" custom profile field.
|
|
"""
|
|
from typing import Optional
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from zerver.lib.types import ProfileFieldData
|
|
from zerver.lib.validator import (
|
|
check_dict_only,
|
|
check_external_account_url_pattern,
|
|
check_required_string,
|
|
)
|
|
|
|
# Default external account fields are by default available
|
|
# to realm admins, where realm admin only need to select
|
|
# the default field and other values(i.e. name, url) will be
|
|
# fetch from this dictionary.
|
|
# text: Field text for admins - custom profile field in org settngs view
|
|
# name: Field label or name - user profile in user settings view
|
|
# hint: Field hint for realm users
|
|
# url_patter: Field url linkifier
|
|
DEFAULT_EXTERNAL_ACCOUNTS = {
|
|
"twitter": {
|
|
"text": "Twitter",
|
|
"url_pattern": "https://twitter.com/%(username)s",
|
|
"name": "Twitter",
|
|
"hint": "Enter your Twitter username",
|
|
},
|
|
"github": {
|
|
"text": 'GitHub',
|
|
"url_pattern": "https://github.com/%(username)s",
|
|
"name": "GitHub",
|
|
"hint": "Enter your GitHub username",
|
|
},
|
|
}
|
|
|
|
def validate_external_account_field_data(field_data: ProfileFieldData) -> Optional[str]:
|
|
field_validator = check_dict_only(
|
|
[('subtype', check_required_string)],
|
|
[('url_pattern', check_external_account_url_pattern)],
|
|
)
|
|
error = field_validator('field_data', field_data)
|
|
if error:
|
|
return error
|
|
|
|
field_subtype = field_data.get('subtype')
|
|
if field_subtype not in DEFAULT_EXTERNAL_ACCOUNTS.keys():
|
|
if field_subtype == "custom":
|
|
if 'url_pattern' not in field_data.keys():
|
|
return _("Custom external account must define url pattern")
|
|
else:
|
|
return _("Invalid external account type")
|
|
|
|
return None
|