mirror of
https://github.com/zulip/zulip.git
synced 2025-11-20 06:28:23 +00:00
Allow anyone to edit a "no topic" message
This change would allow anyone in the realm to set a topic for a "no topic" message. As soon as the message topic is set, only the sender can change it again. (imported from commit 0a91a93b8fd14549965cedc79f45ffd869d82307)
This commit is contained in:
@@ -2,14 +2,17 @@ var message_edit = (function () {
|
|||||||
var exports = {};
|
var exports = {};
|
||||||
var currently_editing_messages = {};
|
var currently_editing_messages = {};
|
||||||
|
|
||||||
|
|
||||||
|
//returns true if the edit task should end.
|
||||||
exports.save = function (row) {
|
exports.save = function (row) {
|
||||||
var msg_list = current_msg_list;
|
var msg_list = current_msg_list;
|
||||||
var message = current_msg_list.get(rows.id(row));
|
var message = current_msg_list.get(rows.id(row));
|
||||||
var new_subject = row.find(".message_edit_subject").val();
|
var new_topic = row.find(".message_edit_topic").val();
|
||||||
var new_content = row.find(".message_edit_content").val();
|
var new_content = row.find(".message_edit_content").val();
|
||||||
|
|
||||||
var request = {message_id: message.id};
|
var request = {message_id: message.id};
|
||||||
if (new_subject !== message.subject) {
|
if (new_topic !== message.subject && new_topic.trim() !== "") {
|
||||||
request.subject = new_subject;
|
request.subject = new_topic;
|
||||||
}
|
}
|
||||||
if (new_content !== message.raw_content) {
|
if (new_content !== message.raw_content) {
|
||||||
request.content = new_content;
|
request.content = new_content;
|
||||||
@@ -17,7 +20,7 @@ exports.save = function (row) {
|
|||||||
if (request.subject === undefined &&
|
if (request.subject === undefined &&
|
||||||
request.content === undefined) {
|
request.content === undefined) {
|
||||||
// If they didn't change anything, just cancel it.
|
// If they didn't change anything, just cancel it.
|
||||||
return message_edit.end(row);
|
return true;
|
||||||
}
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
@@ -26,12 +29,12 @@ exports.save = function (row) {
|
|||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (msg_list === current_msg_list) {
|
if (msg_list === current_msg_list) {
|
||||||
message_edit.end(row);
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function (xhr, error_type, xhn) {
|
error: function (xhr, error_type, xhn) {
|
||||||
var message = util.xhr_error_message("Error saving edit", xhr);
|
var message = util.xhr_error_message("Error saving edit", xhr);
|
||||||
row.find(".message_edit_error").text(message).show();
|
row.find(".edit_error").text(message).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// The message will automatically get replaced when it arrives.
|
// The message will automatically get replaced when it arrives.
|
||||||
@@ -43,7 +46,13 @@ function handle_edit_keydown(e) {
|
|||||||
if (e.target.id === "message_edit_content" && code === 13 &&
|
if (e.target.id === "message_edit_content" && code === 13 &&
|
||||||
(e.metaKey || e.ctrlKey)) {
|
(e.metaKey || e.ctrlKey)) {
|
||||||
row = $(".message_edit_content").filter(":focus").closest(".message_row");
|
row = $(".message_edit_content").filter(":focus").closest(".message_row");
|
||||||
message_edit.save(row);
|
if (message_edit.save(row) === true) {
|
||||||
|
message_edit.end(row);
|
||||||
|
}
|
||||||
|
} else if (e.target.id === "message_edit_topic" && code === 13) {
|
||||||
|
//hitting enter in topic field isn't so great.
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +64,7 @@ function edit_message (row, raw_content) {
|
|||||||
var edit_row = row.find(".message_edit");
|
var edit_row = row.find(".message_edit");
|
||||||
var form = $(templates.render('message_edit_form',
|
var form = $(templates.render('message_edit_form',
|
||||||
{is_stream: message.is_stream,
|
{is_stream: message.is_stream,
|
||||||
subject: message.subject,
|
topic: message.subject,
|
||||||
content: raw_content}));
|
content: raw_content}));
|
||||||
|
|
||||||
var edit_obj = {form: form, raw_content: raw_content};
|
var edit_obj = {form: form, raw_content: raw_content};
|
||||||
@@ -65,7 +74,7 @@ function edit_message (row, raw_content) {
|
|||||||
|
|
||||||
currently_editing_messages[message.id] = edit_obj;
|
currently_editing_messages[message.id] = edit_obj;
|
||||||
if (message.subject === compose.empty_subject_placeholder()) {
|
if (message.subject === compose.empty_subject_placeholder()) {
|
||||||
edit_row.find(".message_edit_subject").focus();
|
edit_row.find(".message_edit_topic").focus();
|
||||||
} else {
|
} else {
|
||||||
edit_row.find(".message_edit_content").focus();
|
edit_row.find(".message_edit_content").focus();
|
||||||
}
|
}
|
||||||
@@ -96,6 +105,13 @@ exports.start = function (row) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.start_topic_edit = function (recipient_row) {
|
||||||
|
var form = $(templates.render('topic_edit_form'));
|
||||||
|
current_msg_list.show_edit_topic(recipient_row, form);
|
||||||
|
form.keydown(handle_edit_keydown);
|
||||||
|
form.find(".message_edit_topic").focus();
|
||||||
|
};
|
||||||
|
|
||||||
exports.is_editing = function (id) {
|
exports.is_editing = function (id) {
|
||||||
return currently_editing_messages[id] !== undefined;
|
return currently_editing_messages[id] !== undefined;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -295,6 +295,17 @@ MessageList.prototype = {
|
|||||||
row.find(".message_edit").hide();
|
row.find(".message_edit").hide();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
show_edit_topic: function MessageList_show_edit_topic(recipient_row, form) {
|
||||||
|
recipient_row.find(".topic_edit_form").empty().append(form);
|
||||||
|
recipient_row.find(".stream_topic").hide();
|
||||||
|
recipient_row.find(".topic_edit").show();
|
||||||
|
},
|
||||||
|
|
||||||
|
hide_edit_topic: function MessageList_hide_edit_topic(recipient_row) {
|
||||||
|
recipient_row.find(".stream_topic").show();
|
||||||
|
recipient_row.find(".topic_edit").hide();
|
||||||
|
},
|
||||||
|
|
||||||
show_message_as_read: function (message, options) {
|
show_message_as_read: function (message, options) {
|
||||||
var row = this.get_row(message.id);
|
var row = this.get_row(message.id);
|
||||||
if (options.from === 'pointer' && feature_flags.mark_read_at_bottom) {
|
if (options.from === 'pointer' && feature_flags.mark_read_at_bottom) {
|
||||||
|
|||||||
@@ -1318,14 +1318,30 @@ $(function () {
|
|||||||
popovers.hide_all();
|
popovers.hide_all();
|
||||||
});
|
});
|
||||||
$('body').on('click', '.edit_subject', function (e) {
|
$('body').on('click', '.edit_subject', function (e) {
|
||||||
var row = current_msg_list.get_row(rows.id($(this).closest(".recipient_row")));
|
var recipient_row = $(this).closest(".recipient_row");
|
||||||
message_edit.start(row);
|
message_edit.start_topic_edit(recipient_row);
|
||||||
|
e.stopPropagation();
|
||||||
|
popovers.hide_all();
|
||||||
|
});
|
||||||
|
$("body").on("click", ".topic_edit_save", function (e) {
|
||||||
|
var recipient_row = $(this).closest(".recipient_row");
|
||||||
|
if (message_edit.save(recipient_row) === true) {
|
||||||
|
current_msg_list.hide_edit_topic(recipient_row);
|
||||||
|
}
|
||||||
|
e.stopPropagation();
|
||||||
|
popovers.hide_all();
|
||||||
|
});
|
||||||
|
$("body").on("click", ".topic_edit_cancel", function (e) {
|
||||||
|
var recipient_row = $(this).closest(".recipient_row");
|
||||||
|
current_msg_list.hide_edit_topic(recipient_row);
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
popovers.hide_all();
|
popovers.hide_all();
|
||||||
});
|
});
|
||||||
$("body").on("click", ".message_edit_save", function (e) {
|
$("body").on("click", ".message_edit_save", function (e) {
|
||||||
var row = $(this).closest(".message_row");
|
var row = $(this).closest(".message_row");
|
||||||
message_edit.save(row);
|
if (message_edit.save(row) === true) {
|
||||||
|
message_edit.end(row);
|
||||||
|
}
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
popovers.hide_all();
|
popovers.hide_all();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -554,13 +554,10 @@ function add_message_metadata(message) {
|
|||||||
involved_people = [{'full_name': message.sender_full_name,
|
involved_people = [{'full_name': message.sender_full_name,
|
||||||
'email': message.sender_email}];
|
'email': message.sender_email}];
|
||||||
|
|
||||||
if ((message.subject === compose.empty_subject_placeholder()) &&
|
if (message.subject === compose.empty_subject_placeholder()) {
|
||||||
message.sent_by_me) {
|
message.empty_subject = true;
|
||||||
// You can only edit messages you sent, so only show the edit hint
|
|
||||||
// for empty subjects on messages you sent.
|
|
||||||
message.your_empty_subject = true;
|
|
||||||
} else {
|
} else {
|
||||||
message.your_empty_subject = false;
|
message.empty_subject = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -736,9 +733,9 @@ function update_messages(events) {
|
|||||||
msg.subject = event.subject;
|
msg.subject = event.subject;
|
||||||
msg.subject_links = event.subject_links;
|
msg.subject_links = event.subject_links;
|
||||||
if (msg.subject === compose.empty_subject_placeholder()) {
|
if (msg.subject === compose.empty_subject_placeholder()) {
|
||||||
msg.your_empty_subject = true;
|
msg.empty_subject = true;
|
||||||
} else {
|
} else {
|
||||||
msg.your_empty_subject = false;
|
msg.empty_subject = false;
|
||||||
}
|
}
|
||||||
// Add the recent subjects entry for the new subject; must
|
// Add the recent subjects entry for the new subject; must
|
||||||
// be called after we update msg.subject
|
// be called after we update msg.subject
|
||||||
|
|||||||
@@ -2214,6 +2214,10 @@ div.edit_bot {
|
|||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#topic_edit_form {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
.message_edit_notice {
|
.message_edit_notice {
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,10 +55,17 @@
|
|||||||
<span class="message_label_clickable narrows_by_recipient stream_label"
|
<span class="message_label_clickable narrows_by_recipient stream_label"
|
||||||
title="Narrow to stream "{{display_recipient}}"">{{display_recipient}}</span>
|
title="Narrow to stream "{{display_recipient}}"">{{display_recipient}}</span>
|
||||||
<i class="icon-vector-narrow icon-vector-small"></i><span class="copy-paste-text">></span>
|
<i class="icon-vector-narrow icon-vector-small"></i><span class="copy-paste-text">></span>
|
||||||
|
<span class="stream_topic">
|
||||||
<span class="message_label_clickable narrows_by_subject"
|
<span class="message_label_clickable narrows_by_subject"
|
||||||
title="Narrow to stream "{{display_recipient}}", topic "{{subject}}"">{{#if ../../../../use_match_properties}}{{{match_subject}}}{{else}}{{subject}}{{/if}}</span>
|
title="Narrow to stream "{{display_recipient}}", topic "{{subject}}"">{{#if ../../../../use_match_properties}}{{{match_subject}}}{{else}}{{subject}}{{/if}}</span>
|
||||||
{{#if your_empty_subject}}<i class="icon-vector-pencil edit_subject"></i>{{/if}}
|
{{#if empty_subject}}
|
||||||
|
<i class="icon-vector-pencil edit_subject"></i>
|
||||||
|
{{/if}}
|
||||||
{{#each subject_links}}<a href="{{this}}" target="_blank"><i class="icon-vector-external-link-sign"></i>{{/each}}
|
{{#each subject_links}}<a href="{{this}}" target="_blank"><i class="icon-vector-external-link-sign"></i>{{/each}}
|
||||||
|
</span>
|
||||||
|
<span class="topic_edit">
|
||||||
|
<span class="topic_edit_form" id="{{id}}"></span>
|
||||||
|
</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
<form id="message_edit_form" class="form-horizontal">
|
<form id="message_edit_form" class="form-horizontal">
|
||||||
{{#if is_stream}}
|
{{#if is_stream}}
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label edit-control-label" for="message_edit_subject">Topic</label>
|
<label class="control-label edit-control-label" for="message_edit_topic">Topic</label>
|
||||||
<div class="controls edit-controls">
|
<div class="controls edit-controls">
|
||||||
<input type="text" value="{{subject}}" class="message_edit_subject" id="message_edit_subject">
|
<input type="text" value="{{topic}}" class="message_edit_topic" id="message_edit_topic">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
@@ -16,9 +16,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<div class="controls edit-controls">
|
<div class="controls edit-controls">
|
||||||
<button type="button" class="message_edit_save btn btn-primary btn-small">Save</a>
|
<button type="button" class="message_edit_save btn btn-primary btn-small">Save</button>
|
||||||
<button type="button" class="message_edit_cancel btn btn-small">Cancel</a>
|
<button type="button" class="message_edit_cancel btn btn-small">Cancel</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="alert alert-error message_edit_error hide"></div>
|
<div class="alert alert-error edit_error hide"></div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
10
static/templates/topic_edit_form.handlebars
Normal file
10
static/templates/topic_edit_form.handlebars
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{{! Client-side Mustache template for rendering the topic edit form. }}
|
||||||
|
|
||||||
|
<form id="topic_edit_form" class="form-horizontal">
|
||||||
|
{{! <div class="controls edit-controls"> }}
|
||||||
|
<input type="text" value="" class="message_edit_topic" id="message_edit_topic">
|
||||||
|
<button type="button" class="topic_edit_save btn btn-primary btn-small">Save</button>
|
||||||
|
<button type="button" class="topic_edit_cancel btn btn-small">Cancel</button>
|
||||||
|
{{! </div> }}
|
||||||
|
<div class="alert alert-error edit_error hide"></div>
|
||||||
|
</form>
|
||||||
@@ -963,6 +963,7 @@ def do_update_message(user_profile, message_id, subject, content):
|
|||||||
edit_history_event = {}
|
edit_history_event = {}
|
||||||
|
|
||||||
if message.sender != user_profile:
|
if message.sender != user_profile:
|
||||||
|
if not (message.subject == "(no topic)" and content is None):
|
||||||
raise JsonableError("Message was not sent by you")
|
raise JsonableError("Message was not sent by you")
|
||||||
|
|
||||||
# Set first_rendered_content to be the oldest version of the
|
# Set first_rendered_content to be the oldest version of the
|
||||||
|
|||||||
Reference in New Issue
Block a user