update_message_backend: Reorganize validation checks.

The new organization more clearly does the permission check first.
This commit is contained in:
Tim Abbott 2016-07-10 18:01:03 -07:00
parent 05632b68e1
commit 3647973069
1 changed files with 4 additions and 2 deletions

View File

@ -798,10 +798,11 @@ def update_message_backend(request, user_profile,
propagate_mode=REQ(default="change_one"), propagate_mode=REQ(default="change_one"),
content=REQ(default=None)): content=REQ(default=None)):
# type: (HttpRequest, UserProfile, int, Optional[text_type], Optional[str], Optional[text_type]) -> HttpResponse # type: (HttpRequest, UserProfile, int, Optional[text_type], Optional[str], Optional[text_type]) -> HttpResponse
if subject is None and content is None:
return json_error(_("Nothing to change"))
if not user_profile.realm.allow_message_editing: if not user_profile.realm.allow_message_editing:
return json_error(_("Your organization has turned off message editing.")) return json_error(_("Your organization has turned off message editing."))
if subject is None and content is None:
return json_error(_("Nothing to change"))
if subject is not None: if subject is not None:
subject = subject.strip() subject = subject.strip()
if subject == "": if subject == "":
@ -810,6 +811,7 @@ def update_message_backend(request, user_profile,
content = content.strip() content = content.strip()
if content == "": if content == "":
raise JsonableError(_("Content can't be empty")) raise JsonableError(_("Content can't be empty"))
do_update_message(user_profile, message_id, subject, propagate_mode, content) do_update_message(user_profile, message_id, subject, propagate_mode, content)
return json_success() return json_success()