mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 17:07:07 +00:00
Since production testing of `message_retention_days` is finished, we can enable this feature in the organization settings page. We already had this setting in frontend but it was bit rotten and not rendered in templates. Here we replaced our past text-input based setting with a dropdown-with-text-input setting approach which is more consistent with our existing UI. Along with frontend changes, we also incorporated a backend change to handle making retention period forever. This change introduces a new convertor `to_positive_or_allowed_int` which only allows positive integers and an allowed value for settings like `message_retention_days` which can be a positive integer or has the value `Realm.RETAIN_MESSAGE_FOREVER` when we change the setting to retain message forever. This change made `to_not_negative_int_or_none` redundant so removed it as well. Fixes: #14854
27 lines
1.1 KiB
Python
27 lines
1.1 KiB
Python
from django.http import HttpRequest, HttpResponse
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from zerver.lib.actions import do_update_pointer
|
|
from zerver.lib.request import has_request_variables, JsonableError, REQ
|
|
from zerver.lib.response import json_success
|
|
from zerver.lib.validator import to_non_negative_int
|
|
from zerver.models import UserProfile, get_usermessage_by_message_id
|
|
|
|
def get_pointer_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
|
return json_success({'pointer': user_profile.pointer})
|
|
|
|
@has_request_variables
|
|
def update_pointer_backend(request: HttpRequest, user_profile: UserProfile,
|
|
pointer: int=REQ(converter=to_non_negative_int)) -> HttpResponse:
|
|
if pointer <= user_profile.pointer:
|
|
return json_success()
|
|
|
|
if get_usermessage_by_message_id(user_profile, pointer) is None:
|
|
raise JsonableError(_("Invalid message ID"))
|
|
|
|
request._log_data["extra"] = "[%s]" % (pointer,)
|
|
update_flags = (request.client.name.lower() in ['android', "zulipandroid"])
|
|
do_update_pointer(user_profile, request.client, pointer, update_flags=update_flags)
|
|
|
|
return json_success()
|