2018-04-18 04:31:57 +02:00
|
|
|
import re
|
2020-10-20 01:28:13 +02:00
|
|
|
from typing import Any, List, Optional
|
2018-04-18 04:31:57 +02:00
|
|
|
from typing.re import Match
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2020-10-19 06:37:43 +02:00
|
|
|
from markdown import Markdown
|
|
|
|
from markdown.extensions import Extension
|
2018-04-18 04:31:57 +02:00
|
|
|
from markdown.preprocessors import Preprocessor
|
|
|
|
|
2018-09-15 06:17:04 +02:00
|
|
|
# There is a lot of duplicated code between this file and
|
|
|
|
# help_relative_links.py. So if you're making a change here consider making
|
|
|
|
# it there as well.
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
REGEXP = re.compile(r"\{settings_tab\|(?P<setting_identifier>.*?)\}")
|
2018-04-18 04:31:57 +02:00
|
|
|
|
|
|
|
link_mapping = {
|
|
|
|
# a mapping from the setting identifier that is the same as the final URL
|
|
|
|
# breadcrumb to that setting to the name of its setting type, the setting
|
|
|
|
# name as it appears in the user interface, and a relative link that can
|
|
|
|
# be used to get to that setting
|
2021-02-12 08:20:45 +01:00
|
|
|
"your-account": ["Settings", "Your account", "/#settings/your-account"],
|
|
|
|
"display-settings": ["Settings", "Display settings", "/#settings/display-settings"],
|
|
|
|
"notifications": ["Settings", "Notifications", "/#settings/notifications"],
|
|
|
|
"your-bots": ["Settings", "Your bots", "/#settings/your-bots"],
|
|
|
|
"alert-words": ["Settings", "Alert words", "/#settings/alert-words"],
|
|
|
|
"uploaded-files": ["Settings", "Uploaded files", "/#settings/uploaded-files"],
|
|
|
|
"muted-topics": ["Settings", "Muted topics", "/#settings/muted-topics"],
|
|
|
|
"organization-profile": [
|
|
|
|
"Manage organization",
|
|
|
|
"Organization profile",
|
|
|
|
"/#organization/organization-profile",
|
2021-02-12 08:19:30 +01:00
|
|
|
],
|
2021-02-12 08:20:45 +01:00
|
|
|
"organization-settings": [
|
|
|
|
"Manage organization",
|
|
|
|
"Organization settings",
|
|
|
|
"/#organization/organization-settings",
|
2021-02-12 08:19:30 +01:00
|
|
|
],
|
2021-02-12 08:20:45 +01:00
|
|
|
"organization-permissions": [
|
|
|
|
"Manage organization",
|
|
|
|
"Organization permissions",
|
|
|
|
"/#organization/organization-permissions",
|
2021-02-12 08:19:30 +01:00
|
|
|
],
|
2021-02-12 08:20:45 +01:00
|
|
|
"emoji-settings": ["Manage organization", "Custom emoji", "/#organization/emoji-settings"],
|
|
|
|
"auth-methods": [
|
|
|
|
"Manage organization",
|
|
|
|
"Authentication methods",
|
|
|
|
"/#organization/auth-methods",
|
2021-02-12 08:19:30 +01:00
|
|
|
],
|
2021-02-12 08:20:45 +01:00
|
|
|
"user-groups-admin": ["Manage organization", "User groups", "/#organization/user-groups-admin"],
|
|
|
|
"user-list-admin": ["Manage organization", "Users", "/#organization/user-list-admin"],
|
|
|
|
"deactivated-users-admin": [
|
|
|
|
"Manage organization",
|
|
|
|
"Deactivated users",
|
|
|
|
"/#organization/deactivated-users-admin",
|
2021-02-12 08:19:30 +01:00
|
|
|
],
|
2021-02-12 08:20:45 +01:00
|
|
|
"bot-list-admin": ["Manage organization", "Bots", "/#organization/bot-list-admin"],
|
|
|
|
"default-streams-list": [
|
|
|
|
"Manage organization",
|
|
|
|
"Default streams",
|
|
|
|
"/#organization/default-streams-list",
|
2021-02-12 08:19:30 +01:00
|
|
|
],
|
2021-03-13 18:15:14 +01:00
|
|
|
"linkifier-settings": [
|
|
|
|
"Manage organization",
|
|
|
|
"Linkifiers",
|
|
|
|
"/#organization/linkifier-settings",
|
|
|
|
],
|
2021-02-12 08:20:45 +01:00
|
|
|
"profile-field-settings": [
|
|
|
|
"Manage organization",
|
|
|
|
"Custom profile fields",
|
|
|
|
"/#organization/profile-field-settings",
|
2021-02-12 08:19:30 +01:00
|
|
|
],
|
2021-02-12 08:20:45 +01:00
|
|
|
"invites-list-admin": [
|
|
|
|
"Manage organization",
|
|
|
|
"Invitations",
|
|
|
|
"/#organization/invites-list-admin",
|
2021-02-12 08:19:30 +01:00
|
|
|
],
|
2021-02-12 08:20:45 +01:00
|
|
|
"data-exports-admin": [
|
|
|
|
"Manage organization",
|
|
|
|
"Data exports",
|
|
|
|
"/#organization/data-exports-admin",
|
2021-02-12 08:19:30 +01:00
|
|
|
],
|
2018-04-18 04:31:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
settings_markdown = """
|
|
|
|
1. From your desktop, click on the **gear**
|
2018-10-19 01:12:15 +02:00
|
|
|
(<i class="fa fa-cog"></i>) in the upper right corner.
|
2018-04-18 04:31:57 +02:00
|
|
|
|
2020-07-10 01:57:43 +02:00
|
|
|
1. Select **{setting_type_name}**.
|
2018-04-18 04:31:57 +02:00
|
|
|
|
2020-07-10 01:57:43 +02:00
|
|
|
1. On the left, click {setting_reference}.
|
2018-04-18 04:31:57 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
2020-10-19 06:37:43 +02:00
|
|
|
class SettingHelpExtension(Extension):
|
|
|
|
def extendMarkdown(self, md: Markdown) -> None:
|
2018-04-18 04:31:57 +02:00
|
|
|
""" Add SettingHelpExtension to the Markdown instance. """
|
|
|
|
md.registerExtension(self)
|
2021-02-12 08:20:45 +01:00
|
|
|
md.preprocessors.register(Setting(), "setting", 515)
|
2018-04-18 04:31:57 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
relative_settings_links: Optional[bool] = None
|
2018-04-18 04:31:57 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-04-26 00:56:00 +02:00
|
|
|
def set_relative_settings_links(value: bool) -> None:
|
2018-04-18 04:31:57 +02:00
|
|
|
global relative_settings_links
|
|
|
|
relative_settings_links = value
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-04-18 04:31:57 +02:00
|
|
|
class Setting(Preprocessor):
|
|
|
|
def run(self, lines: List[str]) -> List[str]:
|
|
|
|
done = False
|
|
|
|
while not done:
|
|
|
|
for line in lines:
|
|
|
|
loc = lines.index(line)
|
|
|
|
match = REGEXP.search(line)
|
|
|
|
|
|
|
|
if match:
|
|
|
|
text = [self.handleMatch(match)]
|
|
|
|
# The line that contains the directive to include the macro
|
|
|
|
# may be preceded or followed by text or tags, in that case
|
|
|
|
# we need to make sure that any preceding or following text
|
|
|
|
# stays the same.
|
|
|
|
line_split = REGEXP.split(line, maxsplit=0)
|
|
|
|
preceding = line_split[0]
|
|
|
|
following = line_split[-1]
|
2020-09-02 06:59:07 +02:00
|
|
|
text = [preceding, *text, following]
|
2021-02-12 08:19:30 +01:00
|
|
|
lines = lines[:loc] + text + lines[loc + 1 :]
|
2018-04-18 04:31:57 +02:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
done = True
|
|
|
|
return lines
|
|
|
|
|
2018-05-10 19:13:36 +02:00
|
|
|
def handleMatch(self, match: Match[str]) -> str:
|
2021-02-12 08:20:45 +01:00
|
|
|
setting_identifier = match.group("setting_identifier")
|
2018-04-18 04:31:57 +02:00
|
|
|
setting_type_name = link_mapping[setting_identifier][0]
|
|
|
|
setting_name = link_mapping[setting_identifier][1]
|
|
|
|
setting_link = link_mapping[setting_identifier][2]
|
|
|
|
if relative_settings_links:
|
2020-06-10 06:41:04 +02:00
|
|
|
return f"1. Go to [{setting_name}]({setting_link})."
|
2020-07-10 01:57:43 +02:00
|
|
|
return settings_markdown.format(
|
|
|
|
setting_type_name=setting_type_name,
|
|
|
|
setting_reference=f"**{setting_name}**",
|
|
|
|
)
|
2018-04-18 04:31:57 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-04-18 04:31:57 +02:00
|
|
|
def makeExtension(*args: Any, **kwargs: Any) -> SettingHelpExtension:
|
|
|
|
return SettingHelpExtension(*args, **kwargs)
|