add edit reason when editing a post
This commit is contained in:
parent
674887dafc
commit
482b752046
|
@ -382,7 +382,10 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
||||||
archetype: this.get('model.archetype'),
|
archetype: this.get('model.archetype'),
|
||||||
metaData: this.get('model.metaData')
|
metaData: this.get('model.metaData')
|
||||||
})) : void 0;
|
})) : void 0;
|
||||||
}
|
},
|
||||||
|
|
||||||
|
canEdit: function() {
|
||||||
|
return this.get("model.action") === "edit" && Discourse.User.current().get("can_edit");
|
||||||
|
}.property("model.action")
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -412,6 +412,7 @@ Discourse.Composer = Discourse.Model.extend({
|
||||||
|
|
||||||
post.setProperties({
|
post.setProperties({
|
||||||
raw: this.get('reply'),
|
raw: this.get('reply'),
|
||||||
|
editReason: this.get('editReason'),
|
||||||
imageSizes: opts.imageSizes,
|
imageSizes: opts.imageSizes,
|
||||||
cooked: $('#wmd-preview').html()
|
cooked: $('#wmd-preview').html()
|
||||||
});
|
});
|
||||||
|
|
|
@ -155,7 +155,7 @@ Discourse.Post = Discourse.Model.extend({
|
||||||
return Discourse.ajax("/posts/" + (this.get('id')), {
|
return Discourse.ajax("/posts/" + (this.get('id')), {
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
data: {
|
data: {
|
||||||
post: { raw: this.get('raw') },
|
post: { raw: this.get('raw'), edit_reason: this.get('editReason') },
|
||||||
image_sizes: this.get('imageSizes')
|
image_sizes: this.get('imageSizes')
|
||||||
}
|
}
|
||||||
}).then(function(result) {
|
}).then(function(result) {
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<div class="title-input">
|
<div class="title-input">
|
||||||
{{textField value=model.title tabindex="2" id="reply-title" maxlength="255" class="span8" placeholderKey="composer.title_placeholder"}}
|
{{textField value=model.title tabindex="2" id="reply-title" maxlength="255" placeholderKey="composer.title_placeholder"}}
|
||||||
{{popupInputTip validation=view.titleValidation shownAt=view.showTitleTip}}
|
{{popupInputTip validation=view.titleValidation shownAt=view.showTitleTip}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -39,6 +39,11 @@
|
||||||
{{#if model.showAdminOptions}}
|
{{#if model.showAdminOptions}}
|
||||||
<button {{action toggleAdminOptions target="view"}} class="btn no-text" title='{{i18n composer.admin_options_title}}'><i class="icon icon-wrench"></i></button>
|
<button {{action toggleAdminOptions target="view"}} class="btn no-text" title='{{i18n composer.admin_options_title}}'><i class="icon icon-wrench"></i></button>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{#if canEdit}}
|
||||||
|
<div class="edit-reason-input">
|
||||||
|
{{textField value=model.editReason tabindex="5" id="edit-reason" maxlength="255" placeholderKey="composer.edit_reason_placeholder"}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,10 @@
|
||||||
optionValuePath="content.number"
|
optionValuePath="content.number"
|
||||||
selectionBinding="versionRight"}}
|
selectionBinding="versionRight"}}
|
||||||
|
|
||||||
|
{{#if postRight.edit_reason}}
|
||||||
|
<p><strong>{{i18n post.edit_reason}}</strong>{{postRight.edit_reason}}</p>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<div class='contents'>
|
<div class='contents'>
|
||||||
{{#if diff}}
|
{{#if diff}}
|
||||||
{{{diff}}}
|
{{{diff}}}
|
||||||
|
@ -41,4 +45,4 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -238,12 +238,12 @@
|
||||||
height: 400px;
|
height: 400px;
|
||||||
}
|
}
|
||||||
.contents {
|
.contents {
|
||||||
input#reply-title {
|
input#reply-title, input#edit-reason {
|
||||||
padding: 7px 10px;
|
padding: 7px 10px;
|
||||||
margin: 6px 10px 3px 0;
|
margin: 6px 10px 3px 0;
|
||||||
width: 400px;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
input#reply-title { width: 400px; }
|
||||||
|
input#edit-reason { width: 200px; }
|
||||||
.wmd-controls {
|
.wmd-controls {
|
||||||
@include transition(top 0.3s ease);
|
@include transition(top 0.3s ease);
|
||||||
top: 100px;
|
top: 100px;
|
||||||
|
@ -283,7 +283,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#reply-title {
|
#reply-title, #edit-reason {
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
float: left;
|
float: left;
|
||||||
&:disabled {
|
&:disabled {
|
||||||
|
@ -324,7 +324,7 @@
|
||||||
bottom: 8px;
|
bottom: 8px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.title-input, .category-input {
|
.title-input, .category-input, .edit-reason-input {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
@ -357,7 +357,6 @@ div.ac-wrap {
|
||||||
background-color: $white;
|
background-color: $white;
|
||||||
border: 1px solid #cccccc;
|
border: 1px solid #cccccc;
|
||||||
padding: 5px 10px;
|
padding: 5px 10px;
|
||||||
@include border-radius-all(3px);
|
|
||||||
div.item {
|
div.item {
|
||||||
float: left;
|
float: left;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
|
|
|
@ -82,7 +82,7 @@ class PostsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
revisor = PostRevisor.new(post)
|
revisor = PostRevisor.new(post)
|
||||||
if revisor.revise!(current_user, params[:post][:raw])
|
if revisor.revise!(current_user, params[:post][:raw], edit_reason: params[:post][:edit_reason])
|
||||||
TopicLink.extract_from(post)
|
TopicLink.extract_from(post)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ module Jobs
|
||||||
# have we already downloaded that file?
|
# have we already downloaded that file?
|
||||||
if !downloaded_urls.include?(src)
|
if !downloaded_urls.include?(src)
|
||||||
hotlinked = download(src)
|
hotlinked = download(src)
|
||||||
if hotlinked.size <= @max_size
|
if hotlinked.try(:size) <= @max_size
|
||||||
filename = File.basename(URI.parse(src).path)
|
filename = File.basename(URI.parse(src).path)
|
||||||
file = ActionDispatch::Http::UploadedFile.new(tempfile: hotlinked, filename: filename)
|
file = ActionDispatch::Http::UploadedFile.new(tempfile: hotlinked, filename: filename)
|
||||||
upload = Upload.create_for(post.user_id, file, hotlinked.size, src)
|
upload = Upload.create_for(post.user_id, file, hotlinked.size, src)
|
||||||
|
@ -64,7 +64,10 @@ module Jobs
|
||||||
|
|
||||||
# TODO: make sure the post hasn´t changed while we were downloading remote images
|
# TODO: make sure the post hasn´t changed while we were downloading remote images
|
||||||
if raw != post.raw
|
if raw != post.raw
|
||||||
options = { force_new_version: true }
|
options = {
|
||||||
|
force_new_version: true,
|
||||||
|
edit_reason: I18n.t("upload.edit_reason")
|
||||||
|
}
|
||||||
post.revise(Discourse.system_user, raw, options)
|
post.revise(Discourse.system_user, raw, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
class PostSerializer < BasicPostSerializer
|
class PostSerializer < BasicPostSerializer
|
||||||
|
|
||||||
# To pass in additional information we might need
|
# To pass in additional information we might need
|
||||||
attr_accessor :topic_slug
|
attr_accessor :topic_slug,
|
||||||
attr_accessor :topic_view
|
:topic_view,
|
||||||
attr_accessor :parent_post
|
:parent_post,
|
||||||
attr_accessor :add_raw
|
:add_raw,
|
||||||
attr_accessor :single_post_link_counts
|
:single_post_link_counts,
|
||||||
attr_accessor :draft_sequence
|
:draft_sequence,
|
||||||
attr_accessor :post_actions
|
:post_actions
|
||||||
|
|
||||||
attributes :post_number,
|
attributes :post_number,
|
||||||
:post_type,
|
:post_type,
|
||||||
|
@ -43,7 +43,8 @@ class PostSerializer < BasicPostSerializer
|
||||||
:trust_level,
|
:trust_level,
|
||||||
:deleted_at,
|
:deleted_at,
|
||||||
:deleted_by,
|
:deleted_by,
|
||||||
:user_deleted
|
:user_deleted,
|
||||||
|
:edit_reason
|
||||||
|
|
||||||
|
|
||||||
def moderator?
|
def moderator?
|
||||||
|
|
|
@ -479,6 +479,7 @@ en:
|
||||||
|
|
||||||
users_placeholder: "Add a user"
|
users_placeholder: "Add a user"
|
||||||
title_placeholder: "Type your title here. What is this discussion about in one brief sentence?"
|
title_placeholder: "Type your title here. What is this discussion about in one brief sentence?"
|
||||||
|
edit_reason_placeholder: "Short reason of your edit"
|
||||||
reply_placeholder: "Type here. Use Markdown or BBCode to format. Drag or paste an image to upload it."
|
reply_placeholder: "Type here. Use Markdown or BBCode to format. Drag or paste an image to upload it."
|
||||||
view_new_post: "View your new post."
|
view_new_post: "View your new post."
|
||||||
saving: "Saving..."
|
saving: "Saving..."
|
||||||
|
@ -798,6 +799,7 @@ en:
|
||||||
reply_topic: "Reply to {{link}}"
|
reply_topic: "Reply to {{link}}"
|
||||||
quote_reply: "quote reply"
|
quote_reply: "quote reply"
|
||||||
edit: "Editing {{link}} by {{replyAvatar}} {{username}}"
|
edit: "Editing {{link}} by {{replyAvatar}} {{username}}"
|
||||||
|
edit_reason: "Reason: "
|
||||||
post_number: "post {{number}}"
|
post_number: "post {{number}}"
|
||||||
in_reply_to: "in reply to"
|
in_reply_to: "in reply to"
|
||||||
last_edited_on: "post last edited on"
|
last_edited_on: "post last edited on"
|
||||||
|
|
|
@ -1178,6 +1178,7 @@ en:
|
||||||
deleted: 'deleted'
|
deleted: 'deleted'
|
||||||
|
|
||||||
upload:
|
upload:
|
||||||
|
edit_reason: "We have downloaded a copy of the remotes images"
|
||||||
unauthorized: "Sorry, the file you are trying to upload is not authorized (authorized extensions: %{authorized_extensions})."
|
unauthorized: "Sorry, the file you are trying to upload is not authorized (authorized extensions: %{authorized_extensions})."
|
||||||
pasted_image_filename: "Pasted image"
|
pasted_image_filename: "Pasted image"
|
||||||
attachments:
|
attachments:
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddEditReasonToPosts < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :posts, :edit_reason, :string
|
||||||
|
end
|
||||||
|
end
|
|
@ -70,6 +70,7 @@ class PostRevisor
|
||||||
@post.raw = @new_raw
|
@post.raw = @new_raw
|
||||||
@post.updated_by = @user
|
@post.updated_by = @user
|
||||||
@post.last_editor_id = @user.id
|
@post.last_editor_id = @user.id
|
||||||
|
@post.edit_reason = @opts[:edit_reason] if @opts[:edit_reason]
|
||||||
|
|
||||||
if @post.hidden && @post.hidden_reason_id == Post.hidden_reasons[:flag_threshold_reached]
|
if @post.hidden && @post.hidden_reason_id == Post.hidden_reasons[:flag_threshold_reached]
|
||||||
@post.hidden = false
|
@post.hidden = false
|
||||||
|
|
|
@ -217,9 +217,11 @@ describe PostsController do
|
||||||
|
|
||||||
let(:post) { Fabricate(:post, user: log_in) }
|
let(:post) { Fabricate(:post, user: log_in) }
|
||||||
let(:update_params) do
|
let(:update_params) do
|
||||||
{id: post.id,
|
{
|
||||||
post: {raw: 'edited body'},
|
id: post.id,
|
||||||
image_sizes: {'http://image.com/image.jpg' => {'width' => 123, 'height' => 456}}}
|
post: { raw: 'edited body', edit_reason: 'typo' },
|
||||||
|
image_sizes: { 'http://image.com/image.jpg' => {'width' => 123, 'height' => 456} },
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'passes the image sizes through' do
|
it 'passes the image sizes through' do
|
||||||
|
@ -227,6 +229,11 @@ describe PostsController do
|
||||||
xhr :put, :update, update_params
|
xhr :put, :update, update_params
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'passes the edit reason through' do
|
||||||
|
Post.any_instance.expects(:edit_reason=)
|
||||||
|
xhr :put, :update, update_params
|
||||||
|
end
|
||||||
|
|
||||||
it "raises an error when the post parameter is missing" do
|
it "raises an error when the post parameter is missing" do
|
||||||
update_params.delete(:post)
|
update_params.delete(:post)
|
||||||
lambda {
|
lambda {
|
||||||
|
@ -241,7 +248,7 @@ describe PostsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "calls revise with valid parameters" do
|
it "calls revise with valid parameters" do
|
||||||
PostRevisor.any_instance.expects(:revise!).with(post.user, 'edited body')
|
PostRevisor.any_instance.expects(:revise!).with(post.user, 'edited body', edit_reason: 'typo')
|
||||||
xhr :put, :update, update_params
|
xhr :put, :update, update_params
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue