API: Migrate POST `json/fetch_raw_message` to GET `json/messages/<id>`

This commit is contained in:
Rafid Aslam 2016-12-22 02:31:16 +07:00 committed by showell
parent 400c8c1f65
commit bfe84a10f0
4 changed files with 12 additions and 12 deletions

View File

@ -301,10 +301,9 @@ function start_edit_maintaining_scroll(row, content) {
exports.start = function (row) {
var message = current_msg_list.get(rows.id(row));
var msg_list = current_msg_list;
channel.post({
url: '/json/fetch_raw_message',
channel.get({
url: '/json/messages/' + message.id,
idempotent: true,
data: {message_id: message.id},
success: function (data) {
if (current_msg_list === msg_list) {
message.raw_content = data.raw_content;

View File

@ -1004,21 +1004,21 @@ class EditMessageTest(ZulipTestCase):
self.login("hamlet@zulip.com")
msg_id = self.send_message("hamlet@zulip.com", "cordelia@zulip.com", Recipient.PERSONAL,
subject="editing", content="**before** edit")
result = self.client_post('/json/fetch_raw_message', dict(message_id=msg_id))
result = self.client_get('/json/messages/' + str(msg_id))
self.assert_json_success(result)
data = ujson.loads(result.content)
self.assertEqual(data['raw_content'], '**before** edit')
# Test error cases
result = self.client_post('/json/fetch_raw_message', dict(message_id=999999))
result = self.client_get('/json/messages/999999')
self.assert_json_error(result, 'Invalid message(s)')
self.login("cordelia@zulip.com")
result = self.client_post('/json/fetch_raw_message', dict(message_id=msg_id))
result = self.client_get('/json/messages/' + str(msg_id))
self.assert_json_success(result)
self.login("othello@zulip.com")
result = self.client_post('/json/fetch_raw_message', dict(message_id=msg_id))
result = self.client_get('/json/messages/' + str(msg_id))
self.assert_json_error(result, 'Invalid message(s)')
def test_fetch_raw_message_stream_wrong_realm(self):
@ -1029,11 +1029,11 @@ class EditMessageTest(ZulipTestCase):
self.subscribe_to_stream(email, stream.name)
msg_id = self.send_message(email, stream.name, Recipient.STREAM,
subject="test", content="test")
result = self.client_post('/json/fetch_raw_message', dict(message_id=msg_id))
result = self.client_get('/json/messages/' + str(msg_id))
self.assert_json_success(result)
self.login("sipbtest@mit.edu")
result = self.client_post('/json/fetch_raw_message', dict(message_id=msg_id))
result = self.client_get('/json/messages/' + str(msg_id))
self.assert_json_error(result, 'Invalid message(s)')
def test_fetch_raw_message_private_stream(self):
@ -1044,10 +1044,10 @@ class EditMessageTest(ZulipTestCase):
self.subscribe_to_stream(email, stream.name)
msg_id = self.send_message(email, stream.name, Recipient.STREAM,
subject="test", content="test")
result = self.client_post('/json/fetch_raw_message', dict(message_id=msg_id))
result = self.client_get('/json/messages/' + str(msg_id))
self.assert_json_success(result)
self.login("othello@zulip.com")
result = self.client_post('/json/fetch_raw_message', dict(message_id=msg_id))
result = self.client_get('/json/messages/' + str(msg_id))
self.assert_json_error(result, 'Invalid message(s)')
def test_edit_message_no_changes(self):

View File

@ -938,7 +938,6 @@ def update_message_backend(request, user_profile,
queue_json_publish('embed_links', event_data, lambda x: None)
return json_success()
@authenticated_json_post_view
@has_request_variables
def json_fetch_raw_message(request, user_profile,
message_id=REQ(converter=to_non_negative_int)):

View File

@ -196,6 +196,8 @@ v1_api_and_json_patterns = [
{'GET': 'zerver.views.messages.get_old_messages_backend',
'PATCH': 'zerver.views.messages.update_message_backend',
'POST': 'zerver.views.messages.send_message_backend'}),
url(r'^messages/(?P<message_id>[0-9]+)$', rest_dispatch,
{'GET': 'zerver.views.messages.json_fetch_raw_message'}),
url(r'^messages/render$', rest_dispatch,
{'GET': 'zerver.views.messages.render_message_backend'}),
url(r'^messages/flags$', rest_dispatch,