Merge pull request #4666 from tgxworld/fix_wiki_create_new_version
FIX: Toggling post's wiki status should not create a new version.
This commit is contained in:
commit
d043e9716f
|
@ -70,7 +70,6 @@ const Post = RestModel.extend({
|
|||
|
||||
return ajax(`/posts/${this.get('id')}/${field}`, { type: 'PUT', data }).then(() => {
|
||||
this.set(field, value);
|
||||
this.incrementProperty("version");
|
||||
}).catch(popupAjaxError);
|
||||
},
|
||||
|
||||
|
|
|
@ -23,19 +23,30 @@ export default createWidget('post-edits-indicator', {
|
|||
|
||||
html(attrs) {
|
||||
let icon = 'pencil';
|
||||
let titleKey = 'post.last_edited_on';
|
||||
const updatedAt = new Date(attrs.updated_at);
|
||||
let className = this.historyHeat(updatedAt);
|
||||
const date = longDate(updatedAt);
|
||||
let title;
|
||||
|
||||
if (attrs.wiki) {
|
||||
icon = 'pencil-square-o';
|
||||
titleKey = 'post.wiki_last_edited_on';
|
||||
className = `${className} wiki`;
|
||||
|
||||
if (attrs.version > 1) {
|
||||
title = `${I18n.t('post.last_edited_on')} ${date}`;
|
||||
} else {
|
||||
title = I18n.t('post.wiki.about');
|
||||
}
|
||||
} else {
|
||||
title = `${I18n.t('post.last_edited_on')} ${date}`;
|
||||
}
|
||||
|
||||
const contents = [attrs.version - 1, ' ', iconNode(icon)];
|
||||
const contents = [
|
||||
attrs.version > 1 ? attrs.version - 1 : '',
|
||||
' ',
|
||||
iconNode(icon)
|
||||
];
|
||||
|
||||
const title = `${I18n.t(titleKey)} ${longDate(updatedAt)}`;
|
||||
return h('a', {
|
||||
className,
|
||||
attributes: { title }
|
||||
|
@ -43,7 +54,9 @@ export default createWidget('post-edits-indicator', {
|
|||
},
|
||||
|
||||
click() {
|
||||
if (this.attrs.canViewEditHistory) {
|
||||
if (this.attrs.wiki && this.attrs.version === 1) {
|
||||
this.sendWidgetAction('editPost');
|
||||
} else if (this.attrs.canViewEditHistory) {
|
||||
this.sendWidgetAction('showHistory');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,7 +167,7 @@ createWidget('post-meta-data', {
|
|||
result.push(this.attach('post-email-indicator', attrs));
|
||||
}
|
||||
|
||||
if (attrs.version > 1) {
|
||||
if (attrs.version > 1 || attrs.wiki) {
|
||||
result.push(this.attach('post-edits-indicator', attrs));
|
||||
}
|
||||
|
||||
|
|
|
@ -394,7 +394,7 @@ class PostsController < ApplicationController
|
|||
post = find_post_from_params
|
||||
guardian.ensure_can_wiki!(post)
|
||||
|
||||
post.revise(current_user, { wiki: params[:wiki] })
|
||||
post.revise(current_user, { wiki: params[:wiki] }, { skip_revision: true })
|
||||
|
||||
render nothing: true
|
||||
end
|
||||
|
|
|
@ -132,7 +132,8 @@ class Post < ActiveRecord::Base
|
|||
updated_at: Time.now,
|
||||
user_id: user_id,
|
||||
last_editor_id: last_editor_id,
|
||||
type: type
|
||||
type: type,
|
||||
version: version
|
||||
}.merge(options)
|
||||
|
||||
if Topic.visible_post_types.include?(post_type)
|
||||
|
|
|
@ -1753,6 +1753,9 @@ en:
|
|||
via_auto_generated_email: "this post arrived via an auto generated email"
|
||||
whisper: "this post is a private whisper for moderators"
|
||||
|
||||
wiki:
|
||||
about: "this post is a wiki"
|
||||
|
||||
archetypes:
|
||||
save: 'Save Options'
|
||||
|
||||
|
|
|
@ -465,6 +465,20 @@ describe PostsController do
|
|||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
it "toggle wiki status should not create a new version" do
|
||||
admin = log_in(:admin)
|
||||
another_user = Fabricate(:user)
|
||||
another_post = Fabricate(:post, user: another_user)
|
||||
|
||||
expect { xhr :put, :wiki, post_id: another_post.id, wiki: 'true' }
|
||||
.to_not change { another_post.reload.version }
|
||||
|
||||
another_admin = log_in(:admin)
|
||||
|
||||
expect { xhr :put, :wiki, post_id: another_post.id, wiki: 'false' }
|
||||
.to_not change { another_post.reload.version }
|
||||
end
|
||||
|
||||
it "can wiki a post" do
|
||||
Guardian.any_instance.expects(:can_wiki?).with(post).returns(true)
|
||||
|
||||
|
|
|
@ -30,6 +30,20 @@ widgetTest('wiki', {
|
|||
}
|
||||
});
|
||||
|
||||
widgetTest('wiki without revision', {
|
||||
template: '{{mount-widget widget="post" args=args editPost="editPost"}}',
|
||||
setup() {
|
||||
this.set('args', { wiki: true, version: 1, canViewEditHistory: true });
|
||||
this.on('editPost', () => this.editPostCalled = true);
|
||||
},
|
||||
test(assert) {
|
||||
click('.post-info .wiki');
|
||||
andThen(() => {
|
||||
assert.ok(this.editPostCalled, 'clicking wiki icon edits the post');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
widgetTest('via-email', {
|
||||
template: '{{mount-widget widget="post" args=args showRawEmail="showRawEmail"}}',
|
||||
setup() {
|
||||
|
|
Loading…
Reference in New Issue