mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: Toggling post's wiki status should not create a new version.
This commit is contained in:
@ -70,7 +70,6 @@ const Post = RestModel.extend({
|
|||||||
|
|
||||||
return ajax(`/posts/${this.get('id')}/${field}`, { type: 'PUT', data }).then(() => {
|
return ajax(`/posts/${this.get('id')}/${field}`, { type: 'PUT', data }).then(() => {
|
||||||
this.set(field, value);
|
this.set(field, value);
|
||||||
this.incrementProperty("version");
|
|
||||||
}).catch(popupAjaxError);
|
}).catch(popupAjaxError);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -23,19 +23,30 @@ export default createWidget('post-edits-indicator', {
|
|||||||
|
|
||||||
html(attrs) {
|
html(attrs) {
|
||||||
let icon = 'pencil';
|
let icon = 'pencil';
|
||||||
let titleKey = 'post.last_edited_on';
|
|
||||||
const updatedAt = new Date(attrs.updated_at);
|
const updatedAt = new Date(attrs.updated_at);
|
||||||
let className = this.historyHeat(updatedAt);
|
let className = this.historyHeat(updatedAt);
|
||||||
|
const date = longDate(updatedAt);
|
||||||
|
let title;
|
||||||
|
|
||||||
if (attrs.wiki) {
|
if (attrs.wiki) {
|
||||||
icon = 'pencil-square-o';
|
icon = 'pencil-square-o';
|
||||||
titleKey = 'post.wiki_last_edited_on';
|
|
||||||
className = `${className} wiki`;
|
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', {
|
return h('a', {
|
||||||
className,
|
className,
|
||||||
attributes: { title }
|
attributes: { title }
|
||||||
@ -43,7 +54,9 @@ export default createWidget('post-edits-indicator', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
click() {
|
click() {
|
||||||
if (this.attrs.canViewEditHistory) {
|
if (this.attrs.wiki && this.attrs.version === 1) {
|
||||||
|
this.sendWidgetAction('editPost');
|
||||||
|
} else if (this.attrs.canViewEditHistory) {
|
||||||
this.sendWidgetAction('showHistory');
|
this.sendWidgetAction('showHistory');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ createWidget('post-meta-data', {
|
|||||||
result.push(this.attach('post-email-indicator', attrs));
|
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));
|
result.push(this.attach('post-edits-indicator', attrs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,7 +394,7 @@ class PostsController < ApplicationController
|
|||||||
post = find_post_from_params
|
post = find_post_from_params
|
||||||
guardian.ensure_can_wiki!(post)
|
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
|
render nothing: true
|
||||||
end
|
end
|
||||||
|
@ -132,7 +132,8 @@ class Post < ActiveRecord::Base
|
|||||||
updated_at: Time.now,
|
updated_at: Time.now,
|
||||||
user_id: user_id,
|
user_id: user_id,
|
||||||
last_editor_id: last_editor_id,
|
last_editor_id: last_editor_id,
|
||||||
type: type
|
type: type,
|
||||||
|
version: version
|
||||||
}.merge(options)
|
}.merge(options)
|
||||||
|
|
||||||
if Topic.visible_post_types.include?(post_type)
|
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"
|
via_auto_generated_email: "this post arrived via an auto generated email"
|
||||||
whisper: "this post is a private whisper for moderators"
|
whisper: "this post is a private whisper for moderators"
|
||||||
|
|
||||||
|
wiki:
|
||||||
|
about: "this post is a wiki"
|
||||||
|
|
||||||
archetypes:
|
archetypes:
|
||||||
save: 'Save Options'
|
save: 'Save Options'
|
||||||
|
|
||||||
|
@ -465,6 +465,20 @@ describe PostsController do
|
|||||||
expect(response).to be_forbidden
|
expect(response).to be_forbidden
|
||||||
end
|
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
|
it "can wiki a post" do
|
||||||
Guardian.any_instance.expects(:can_wiki?).with(post).returns(true)
|
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', {
|
widgetTest('via-email', {
|
||||||
template: '{{mount-widget widget="post" args=args showRawEmail="showRawEmail"}}',
|
template: '{{mount-widget widget="post" args=args showRawEmail="showRawEmail"}}',
|
||||||
setup() {
|
setup() {
|
||||||
|
Reference in New Issue
Block a user