snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
104
zerver/views/realm_linkifiers.py
Normal file
104
zerver/views/realm_linkifiers.py
Normal file
@@ -0,0 +1,104 @@
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.utils.translation import gettext as _
|
||||
from pydantic import Json
|
||||
|
||||
from zerver.actions.realm_linkifiers import (
|
||||
check_reorder_linkifiers,
|
||||
do_add_linkifier,
|
||||
do_remove_linkifier,
|
||||
do_update_linkifier,
|
||||
)
|
||||
from zerver.decorator import require_realm_admin
|
||||
from zerver.lib.exceptions import JsonableError, ValidationFailureError
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.typed_endpoint import PathOnly, typed_endpoint
|
||||
from zerver.models import RealmFilter, UserProfile
|
||||
from zerver.models.linkifiers import linkifiers_for_realm
|
||||
|
||||
|
||||
# Custom realm linkifiers
|
||||
def list_linkifiers(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
||||
linkifiers = linkifiers_for_realm(user_profile.realm_id)
|
||||
return json_success(request, data={"linkifiers": linkifiers})
|
||||
|
||||
|
||||
@require_realm_admin
|
||||
@typed_endpoint
|
||||
def create_linkifier(
|
||||
request: HttpRequest,
|
||||
user_profile: UserProfile,
|
||||
*,
|
||||
pattern: str,
|
||||
url_template: str,
|
||||
example_input: str | None = None,
|
||||
reverse_template: str | None = None,
|
||||
alternative_url_templates: Json[list[str]] | None = None,
|
||||
) -> HttpResponse:
|
||||
try:
|
||||
linkifier_id = do_add_linkifier(
|
||||
realm=user_profile.realm,
|
||||
pattern=pattern,
|
||||
url_template=url_template,
|
||||
example_input=example_input,
|
||||
reverse_template=reverse_template,
|
||||
alternative_url_templates=alternative_url_templates,
|
||||
acting_user=user_profile,
|
||||
)
|
||||
return json_success(request, data={"id": linkifier_id})
|
||||
except ValidationError as e:
|
||||
raise ValidationFailureError(e)
|
||||
|
||||
|
||||
@require_realm_admin
|
||||
def delete_linkifier(
|
||||
request: HttpRequest, user_profile: UserProfile, filter_id: int
|
||||
) -> HttpResponse:
|
||||
try:
|
||||
do_remove_linkifier(realm=user_profile.realm, id=filter_id, acting_user=None)
|
||||
except RealmFilter.DoesNotExist:
|
||||
raise JsonableError(_("Linkifier not found."))
|
||||
return json_success(request)
|
||||
|
||||
|
||||
@require_realm_admin
|
||||
@typed_endpoint
|
||||
def update_linkifier(
|
||||
request: HttpRequest,
|
||||
user_profile: UserProfile,
|
||||
*,
|
||||
filter_id: PathOnly[int],
|
||||
pattern: str,
|
||||
url_template: str,
|
||||
example_input: str | None = None,
|
||||
reverse_template: str | None = None,
|
||||
alternative_url_templates: Json[list[str]] | None = None,
|
||||
) -> HttpResponse:
|
||||
try:
|
||||
do_update_linkifier(
|
||||
realm=user_profile.realm,
|
||||
id=filter_id,
|
||||
pattern=pattern,
|
||||
url_template=url_template,
|
||||
example_input=example_input,
|
||||
reverse_template=reverse_template,
|
||||
alternative_url_templates=alternative_url_templates,
|
||||
acting_user=user_profile,
|
||||
)
|
||||
return json_success(request)
|
||||
except RealmFilter.DoesNotExist:
|
||||
raise JsonableError(_("Linkifier not found."))
|
||||
except ValidationError as e:
|
||||
raise ValidationFailureError(e)
|
||||
|
||||
|
||||
@require_realm_admin
|
||||
@typed_endpoint
|
||||
def reorder_linkifiers(
|
||||
request: HttpRequest,
|
||||
user_profile: UserProfile,
|
||||
*,
|
||||
ordered_linkifier_ids: Json[list[int]],
|
||||
) -> HttpResponse:
|
||||
check_reorder_linkifiers(user_profile.realm, ordered_linkifier_ids, acting_user=user_profile)
|
||||
return json_success(request)
|
||||
Reference in New Issue
Block a user