From 44dc4b4a17ad90dcc988874468d306e8a8a0d870 Mon Sep 17 00:00:00 2001 From: Ben Lubar Date: Sat, 26 Jul 2014 23:04:46 -0500 Subject: [PATCH 1/3] add profile option for edit history, visible only when edit history is disabled globally. --- .../discourse/templates/user/preferences.js.handlebars | 3 +++ app/models/user.rb | 1 + app/serializers/user_serializer.rb | 3 ++- app/services/user_updater.rb | 3 ++- config/locales/client.en.yml | 1 + .../20140727030954_add_edit_history_public_to_users.rb | 5 +++++ lib/guardian/post_guardian.rb | 2 +- 7 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20140727030954_add_edit_history_public_to_users.rb diff --git a/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars b/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars index 1d683ba80..ca7a8213f 100644 --- a/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars +++ b/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars @@ -167,6 +167,9 @@ {{preference-checkbox labelKey="user.enable_quoting" checked=enable_quoting}} {{preference-checkbox labelKey="user.dynamic_favicon" checked=dynamic_favicon}} {{preference-checkbox labelKey="user.disable_jump_reply" checked=disable_jump_reply}} + {{#if !Discourse.SiteSettings.edit_history_available_to_public}} + {{preference-checkbox labelKey="user.edit_history_public" checked=edit_history_public}} + {{/if}} {{plugin-outlet "user_custom_preferences"}} diff --git a/app/models/user.rb b/app/models/user.rb index 6762bcfdf..7f8596c88 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -774,6 +774,7 @@ end # registration_ip_address :inet # last_redirected_to_top_at :datetime # disable_jump_reply :boolean default(FALSE), not null +# edit_history_public :boolean default(FALSE), not null # # Indexes # diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index 3968dc2b7..43237b55a 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -77,7 +77,8 @@ class UserSerializer < BasicUserSerializer :gravatar_avatar_upload_id, :custom_avatar_upload_id, :custom_fields, - :has_title_badges + :has_title_badges, + :edit_history_public ### ### ATTRIBUTES diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb index f1f7a2441..dce86dccf 100644 --- a/app/services/user_updater.rb +++ b/app/services/user_updater.rb @@ -15,7 +15,8 @@ class UserUpdater :enable_quoting, :dynamic_favicon, :mailing_list_mode, - :disable_jump_reply + :disable_jump_reply, + :edit_history_public ] PROFILE_ATTR = [ diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 4f90e8ae5..5e50e1985 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -271,6 +271,7 @@ en: notifications: "Notifications" disable_jump_reply: "Don't jump to your new post after replying" dynamic_favicon: "Show incoming message notifications on favicon (experimental)" + edit_history_public: "Let other users view my post revisions" external_links_in_new_tab: "Open all external links in a new tab" enable_quoting: "Enable quote reply for highlighted text" change: "change" diff --git a/db/migrate/20140727030954_add_edit_history_public_to_users.rb b/db/migrate/20140727030954_add_edit_history_public_to_users.rb new file mode 100644 index 000000000..61d571aeb --- /dev/null +++ b/db/migrate/20140727030954_add_edit_history_public_to_users.rb @@ -0,0 +1,5 @@ +class AddEditHistoryPublicToUsers < ActiveRecord::Migration + def change + add_column :users, :edit_history_public, :boolean, default: false, null: false + end +end diff --git a/lib/guardian/post_guardian.rb b/lib/guardian/post_guardian.rb index 17dcaf83d..244afbd58 100644 --- a/lib/guardian/post_guardian.rb +++ b/lib/guardian/post_guardian.rb @@ -137,7 +137,7 @@ module PostGuardian return false unless post if !post.hidden - return true if post.wiki || SiteSetting.edit_history_visible_to_public + return true if post.wiki || SiteSetting.edit_history_visible_to_public || post.user.edit_history_public end authenticated? && From ac8c2e1e077aba40d11cbfd31b62f2d0cd46af9b Mon Sep 17 00:00:00 2001 From: Ben Lubar Date: Sun, 27 Jul 2014 12:12:36 -0500 Subject: [PATCH 2/3] discourse#2591 --- .../discourse/templates/user/preferences.js.handlebars | 4 ++-- app/serializers/user_serializer.rb | 9 ++++++--- lib/guardian/post_guardian.rb | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars b/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars index ca7a8213f..f5406e2da 100644 --- a/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars +++ b/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars @@ -167,9 +167,9 @@ {{preference-checkbox labelKey="user.enable_quoting" checked=enable_quoting}} {{preference-checkbox labelKey="user.dynamic_favicon" checked=dynamic_favicon}} {{preference-checkbox labelKey="user.disable_jump_reply" checked=disable_jump_reply}} - {{#if !Discourse.SiteSettings.edit_history_available_to_public}} + {{#unless Discourse.SiteSettings.edit_history_available_to_public}} {{preference-checkbox labelKey="user.edit_history_public" checked=edit_history_public}} - {{/if}} + {{/unless}} {{plugin-outlet "user_custom_preferences"}} diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index 43237b55a..b2bde1321 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -43,7 +43,8 @@ class UserSerializer < BasicUserSerializer :suspended_till, :uploaded_avatar_id, :badge_count, - :has_title_badges + :has_title_badges, + :edit_history_public has_one :invited_by, embed: :object, serializer: BasicUserSerializer has_many :custom_groups, embed: :object, serializer: BasicGroupSerializer @@ -77,8 +78,7 @@ class UserSerializer < BasicUserSerializer :gravatar_avatar_upload_id, :custom_avatar_upload_id, :custom_fields, - :has_title_badges, - :edit_history_public + :has_title_badges ### ### ATTRIBUTES @@ -237,4 +237,7 @@ class UserSerializer < BasicUserSerializer object.badges.where(allow_title: true).count > 0 end + def include_edit_history_public? + can_edit && !SiteSetting.edit_history_visible_to_public + end end diff --git a/lib/guardian/post_guardian.rb b/lib/guardian/post_guardian.rb index 244afbd58..d40f17d80 100644 --- a/lib/guardian/post_guardian.rb +++ b/lib/guardian/post_guardian.rb @@ -137,7 +137,7 @@ module PostGuardian return false unless post if !post.hidden - return true if post.wiki || SiteSetting.edit_history_visible_to_public || post.user.edit_history_public + return true if post.wiki || SiteSetting.edit_history_visible_to_public || post.user.try(:edit_history_public) end authenticated? && From 93ea940a4db10be39031c374fbb6b906853a5a81 Mon Sep 17 00:00:00 2001 From: Ben Lubar Date: Mon, 28 Jul 2014 10:49:42 -0500 Subject: [PATCH 3/3] add spec for public edit history --- spec/components/guardian_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index 639dd5b63..42e21e955 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -395,6 +395,12 @@ describe Guardian do it 'is true when logged in' do Guardian.new(Fabricate(:user)).can_see?(post_revision).should == true end + + it 'is true if the author has public edit history' do + public_post_revision = Fabricate(:post_revision) + public_post_revision.post.user.edit_history_public = true + Guardian.new.can_see?(public_post_revision).should == true + end end context 'edit_history_visible_to_public is false' do @@ -412,6 +418,12 @@ describe Guardian do it 'is false for trust level lower than 4' do Guardian.new(Fabricate(:leader)).can_see?(post_revision).should == false end + + it 'is true if the author has public edit history' do + public_post_revision = Fabricate(:post_revision) + public_post_revision.post.user.edit_history_public = true + Guardian.new.can_see?(public_post_revision).should == true + end end end end