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

Show "Edit Message" button on personal message footer for staff if PM tagging is enabled.
This commit is contained in:
Arpit Jalan 2018-02-26 21:58:37 +05:30
parent 410b90dde0
commit 4010d8d9f9
7 changed files with 58 additions and 1 deletions

View File

@ -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',

View File

@ -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');

View File

@ -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=""

View File

@ -251,6 +251,7 @@
showFlagTopic=(action "topicRouteAction" "showFlagTopic")
showInvite=(action "topicRouteAction" "showInvite")
toggleArchiveMessage=(action "toggleArchiveMessage")
editFirstPost=(action "editFirstPost")
replyToPost=(action "replyToPost")
}}
{{else}}

View File

@ -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'

View File

@ -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');
});
});

View File

@ -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");
});