diff --git a/app/assets/javascripts/discourse/models/post.js.es6 b/app/assets/javascripts/discourse/models/post.js.es6 index b15683ca4a4..127b81f8612 100644 --- a/app/assets/javascripts/discourse/models/post.js.es6 +++ b/app/assets/javascripts/discourse/models/post.js.es6 @@ -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); }, diff --git a/app/assets/javascripts/discourse/widgets/post-edits-indicator.js.es6 b/app/assets/javascripts/discourse/widgets/post-edits-indicator.js.es6 index f0d3cc1141e..531e4396850 100644 --- a/app/assets/javascripts/discourse/widgets/post-edits-indicator.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post-edits-indicator.js.es6 @@ -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'); } } diff --git a/app/assets/javascripts/discourse/widgets/post.js.es6 b/app/assets/javascripts/discourse/widgets/post.js.es6 index f92dd1d9546..5309768e58b 100644 --- a/app/assets/javascripts/discourse/widgets/post.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post.js.es6 @@ -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)); } diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 52618c5cafd..054310d393c 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -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 diff --git a/app/models/post.rb b/app/models/post.rb index 51ac4442118..4667f93cfd0 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index d502aa3a1e4..ebdaee27768 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -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' diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index c2071de4f4b..41916d4d0ef 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -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) diff --git a/test/javascripts/widgets/post-test.js.es6 b/test/javascripts/widgets/post-test.js.es6 index 559ac879601..80b97b548a8 100644 --- a/test/javascripts/widgets/post-test.js.es6 +++ b/test/javascripts/widgets/post-test.js.es6 @@ -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() {