Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: show "edit message" button on message footer for staff

Arpit Jalan4010d8d9f99c
diff --git a/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6 b/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6
index af05e670fac..d2c110adfd8 100644
--- a/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6
+++ b/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6
@@ -28,6 +28,11 @@ export default Ember.Component.extend({
return !this.site.mobileView && this.currentUser && this.currentUser.get('canManageTopic');
},
+ showEditOnFooter: Ember.computed.and(
+ 'topic.isPrivateMessage',
+ 'site.can_tag_pms'
+ ),
+
@computed('topic.message_archived')
archiveIcon: archived => archived ? '' : 'folder',
diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6
index a4e6b2e08d8..dca8ddd0da6 100644
--- a/app/assets/javascripts/discourse/controllers/topic.js.es6
+++ b/app/assets/javascripts/discourse/controllers/topic.js.es6
@@ -265,6 +265,23 @@ export default Ember.Controller.extend(BufferedContent, {
}
},
+ editFirstPost() {
+ const postStream = this.get('model.postStream');
+ let firstPost = postStream.get('posts.firstObject');
+
+ if (firstPost.get('post_number') !== 1) {
+ const postId = postStream.findPostIdForPostNumber(1);
+ // try loading from identity map first
+ firstPost = postStream.findLoadedPost(postId);
+ if (firstPost === undefined) {
+ return this.get('model.postStream').loadPost(postId).then(post => {
+ this.send("editPost", post);
+ });
+ }
+ }
+ this.send("editPost", firstPost);
+ },
+
// Post related methods
replyToPost(post) {
const composerController = this.get('composer');
diff --git a/app/assets/javascripts/discourse/templates/components/topic-footer-buttons.hbs b/app/assets/javascripts/discourse/templates/components/topic-footer-buttons.hbs
index b38900977fb..1e6a61eef5c 100644
--- a/app/assets/javascripts/discourse/templates/components/topic-footer-buttons.hbs
+++ b/app/assets/javascripts/discourse/templates/components/topic-footer-buttons.hbs
@@ -58,6 +58,14 @@
action=toggleArchiveMessage}}
{{/if}}
+ {{#if showEditOnFooter}}
+ {{d-button class="edit-message"
+ title="topic.edit_message.help"
+ label="topic.edit_message.title"
+ icon="pencil"
+ action=editFirstPost}}
+ {{/if}}
+
{{plugin-outlet name="topic-footer-main-buttons-before-create"
args=(hash topic=topic)
tagName=""
diff --git a/app/assets/javascripts/discourse/templates/topic.hbs b/app/assets/javascripts/discourse/templates/topic.hbs
index 810679b3741..f0796dbc6d5 100644
--- a/app/assets/javascripts/discourse/templates/topic.hbs
+++ b/app/assets/javascripts/discourse/templates/topic.hbs
@@ -251,6 +251,7 @@
showFlagTopic=(action "topicRouteAction" "showFlagTopic")
showInvite=(action "topicRouteAction" "showInvite")
toggleArchiveMessage=(action "toggleArchiveMessage")
+ editFirstPost=(action "editFirstPost")
replyToPost=(action "replyToPost")
}}
{{else}}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 17dd034b17f..132fef53a6b 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -1583,6 +1583,9 @@ en:
move_to_inbox:
title: 'Move to Inbox'
help: 'Move message back to Inbox'
+ edit_message:
+ help: 'Edit first post of the message'
+ title: 'Edit Message'
list: 'Topics'
new: 'new topic'
unread: 'unread'
diff --git a/test/javascripts/acceptance/topic-test.js.es6 b/test/javascripts/acceptance/topic-test.js.es6
index b84afe844f7..697e68f0bd2 100644
--- a/test/javascripts/acceptance/topic-test.js.es6
+++ b/test/javascripts/acceptance/topic-test.js.es6
@@ -173,6 +173,14 @@ QUnit.test("Updating the topic title with emojis", assert => {
});
});
+QUnit.test("does not show 'edit first post' button on topic/pm footer", assert => {
+ visit("/t/pm-for-testing/12");
+
+ andThen(() => {
+ assert.ok(!exists('.edit-message'), 'it does not show edit button');
+ });
+});
+
acceptance("Topic featured links", {
loggedIn: true,
settings: {
@@ -199,3 +207,19 @@ QUnit.test("remove featured link", assert => {
// assert.ok(!exists('.title-wrapper .topic-featured-link'), 'link is gone');
// });
});
+
+acceptance("Personal message footer", {
+ loggedIn: true,
+ settings: {
+ allow_staff_to_tag_pms: true,
+ tagging_enabled: true
+ }
+});
+
+QUnit.test("shows edit 'first post button' on PM footer", assert => {
+ visit("/t/pm-for-testing/12");
+
+ andThen(() => {
+ assert.ok(exists('.edit-message'), 'it shows the edit button');
+ });
+});
diff --git a/test/javascripts/controllers/topic-test.js.es6 b/test/javascripts/controllers/topic-test.js.es6
index aa66bebe940..eeb72861e99 100644
--- a/test/javascripts/controllers/topic-test.js.es6
+++ b/test/javascripts/controllers/topic-test.js.es6
@@ -325,4 +325,3 @@ QUnit.test("selectBelow", function(assert) {
assert.equal(selectedPostIds[1], 4, "also selected 1st post below post #3");
assert.equal(selectedPostIds[2], 5, "also selected 2nd post below post #3");
});
-