Skip to content
Extraits de code Groupes Projets
Valider b7791e6c rédigé par hilkoc's avatar hilkoc Validation de Benjamin Neff
Parcourir les fichiers

Add user setting for default post visibility

fixes #4319

closes #7118
parent 74fff52e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 157 ajouts et 56 suppressions
...@@ -49,6 +49,7 @@ Note: Although this is a minor release, the configuration file changed because t ...@@ -49,6 +49,7 @@ Note: Although this is a minor release, the configuration file changed because t
* Add optional `Content-Security-Policy` header [#7128](https://github.com/diaspora/diaspora/pull/7128) * Add optional `Content-Security-Policy` header [#7128](https://github.com/diaspora/diaspora/pull/7128)
* Add links to main stream and public stream to the mobile drawer [#7144](https://github.com/diaspora/diaspora/pull/7144) * Add links to main stream and public stream to the mobile drawer [#7144](https://github.com/diaspora/diaspora/pull/7144)
* Allow opening search results from the dropdown in a new tab [#7021](https://github.com/diaspora/diaspora/issues/7021) * Allow opening search results from the dropdown in a new tab [#7021](https://github.com/diaspora/diaspora/issues/7021)
* Add user setting for default post visibility [#7118](https://github.com/diaspora/diaspora/issues/7118)
# 0.6.0.1 # 0.6.0.1
......
...@@ -9,6 +9,11 @@ app.pages.Settings = Backbone.View.extend({ ...@@ -9,6 +9,11 @@ app.pages.Settings = Backbone.View.extend({
preFill: gon.preloads.tagsArray preFill: gon.preloads.tagsArray
}); });
new Diaspora.ProfilePhotoUploader(); new Diaspora.ProfilePhotoUploader();
this.viewAspectSelector = new app.views.PublisherAspectSelector({
el: $(".aspect_dropdown"),
form: $("#post-default-aspects")
});
} }
}); });
// @license-end // @license-end
...@@ -144,6 +144,7 @@ class UsersController < ApplicationController ...@@ -144,6 +144,7 @@ class UsersController < ApplicationController
:auto_follow_back, :auto_follow_back,
:auto_follow_back_aspect_id, :auto_follow_back_aspect_id,
:getting_started, :getting_started,
:post_default_public,
email_preferences: %i( email_preferences: %i(
someone_reported someone_reported
also_commented also_commented
...@@ -167,6 +168,8 @@ class UsersController < ApplicationController ...@@ -167,6 +168,8 @@ class UsersController < ApplicationController
change_email(user_data) change_email(user_data)
elsif user_data[:auto_follow_back] elsif user_data[:auto_follow_back]
change_settings(user_data, "users.update.follow_settings_changed", "users.update.follow_settings_not_changed") change_settings(user_data, "users.update.follow_settings_changed", "users.update.follow_settings_not_changed")
elsif user_data[:post_default_public]
change_post_default(user_data)
elsif user_data[:color_theme] elsif user_data[:color_theme]
change_settings(user_data, "users.update.color_theme_changed", "users.update.color_theme_not_changed") change_settings(user_data, "users.update.color_theme_changed", "users.update.color_theme_not_changed")
else else
...@@ -184,6 +187,18 @@ class UsersController < ApplicationController ...@@ -184,6 +187,18 @@ class UsersController < ApplicationController
end end
end end
def change_post_default(user_data)
# by default user_data[:post_default_public] is set to false
case params[:aspect_ids].try(:first)
when "public"
user_data[:post_default_public] = true
when "all_aspects"
params[:aspect_ids] = @user.aspects.map {|a| a.id.to_s }
end
@user.update_post_default_aspects params[:aspect_ids].to_a
change_settings(user_data)
end
# change email notifications # change email notifications
def change_email_preferences(user_data) def change_email_preferences(user_data)
@user.update_user_preferences(user_data[:email_preferences]) @user.update_user_preferences(user_data[:email_preferences])
......
...@@ -17,13 +17,24 @@ module AspectGlobalHelper ...@@ -17,13 +17,24 @@ module AspectGlobalHelper
aspect = stream.aspect aspect = stream.aspect
aspect_ids = stream.aspect_ids aspect_ids = stream.aspect_ids
elsif current_user elsif current_user
aspects = current_user.aspects aspects = current_user.post_default_aspects
aspect = aspects.first aspect = aspects.first
aspect_ids = current_user.aspect_ids aspect_ids = current_user.aspect_ids
else else
return {} return {}
end end
{selected_aspects: aspects, aspect: aspect, aspect_ids: aspect_ids}
end
def public_selected?(selected_aspects)
"public" == selected_aspects.try(:first)
end
def all_aspects_selected?(aspects, selected_aspects)
!aspects.empty? && aspects.size == selected_aspects.size && !public_selected?(selected_aspects)
end
{ selected_aspects: aspects, aspect: aspect, aspect_ids: aspect_ids } def aspect_selected?(aspect, aspects, selected_aspects)
selected_aspects.include?(aspect) && !all_aspects_selected?(aspects, selected_aspects)
end end
end end
...@@ -46,8 +46,4 @@ module InterimStreamHackinessHelper ...@@ -46,8 +46,4 @@ module InterimStreamHackinessHelper
def publisher_open def publisher_open
publisher_method(:open) publisher_method(:open)
end end
def publisher_public
publisher_method(:public)
end
end end
...@@ -7,10 +7,6 @@ module PublisherHelper ...@@ -7,10 +7,6 @@ module PublisherHelper
params[:controller] != "tags" params[:controller] != "tags"
end end
def all_aspects_selected?(selected_aspects)
@all_aspects_selected ||= all_aspects.size == selected_aspects.size
end
def service_button(service) def service_button(service)
provider_title = I18n.t( provider_title = I18n.t(
"services.index.share_to", "services.index.share_to",
......
...@@ -252,6 +252,21 @@ class User < ActiveRecord::Base ...@@ -252,6 +252,21 @@ class User < ActiveRecord::Base
end end
end end
def post_default_aspects
if post_default_public
["public"]
else
aspects.where(post_default: true).to_a
end
end
def update_post_default_aspects(post_default_aspect_ids)
aspects.each do |aspect|
enable = post_default_aspect_ids.include?(aspect.id.to_s)
aspect.update_attribute(:post_default, enable)
end
end
def salmon(post) def salmon(post)
Salmon::EncryptedSlap.create_by_user_and_activity(self, post.to_diaspora_xml) Salmon::EncryptedSlap.create_by_user_and_activity(self, post.to_diaspora_xml)
end end
...@@ -502,7 +517,8 @@ class User < ActiveRecord::Base ...@@ -502,7 +517,8 @@ class User < ActiveRecord::Base
self[field] = nil self[field] = nil
end end
[:getting_started, [:getting_started,
:show_community_spotlight_in_stream].each do |field| :show_community_spotlight_in_stream,
:post_default_public].each do |field|
self[field] = false self[field] = false
end end
self[:disable_mail] = true self[:disable_mail] = true
......
-# locals: selected_aspects. Note: all_aspects is a global in the ApplicationController
:ruby
dropdown_css = {"data-toggle" => "dropdown"}
if current_user.getting_started?
dropdown_css[:title] = popover_with_close_html("2. #{t('shared.public_explain.control_your_audience')}")
dropdown_css["data-content"] = t("shared.public_explain.visibility_dropdown")
end
.btn-group.aspect_dropdown
%button.btn.btn-default.dropdown-toggle{dropdown_css}
- if public_selected?(selected_aspects)
%i.entypo-globe.small#visibility-icon
%span.text
= t("public")
- else
%i.entypo-lock.small#visibility-icon
%span.text
- if all_aspects_selected?(all_aspects, selected_aspects)
= t("all_aspects")
- elsif selected_aspects.size == 1
= selected_aspects.first.name
- else
= t("shared.aspect_dropdown.toggle", count: selected_aspects.size)
%span.caret
%ul.dropdown-menu.pull-right{unSelectable: "on"}
%li.public.radio{"data-aspect_id" => "public", :class => ("selected" if public_selected?(selected_aspects))}
%a
%span.status_indicator
%i.glyphicon.glyphicon-ok
%span.text
= t("public")
%li.all_aspects.radio{"data-aspect_id" => "all_aspects",
:class => ("selected" if all_aspects_selected?(all_aspects, selected_aspects))}
%a
%span.status_indicator
%i.glyphicon.glyphicon-ok
%span.text
= t("all_aspects")
%li.divider
- all_aspects.each do |aspect|
%li.aspect_selector{"data-aspect_id" => aspect.id,
:class => ("selected" if aspect_selected?(aspect, all_aspects, selected_aspects))}
%a
%span.status_indicator
%i.glyphicon.glyphicon-ok
%span.text
= aspect.name
.btn-group.aspect_dropdown
%button.btn.btn-default.dropdown-toggle{ ! current_user.getting_started? ? {'data-toggle' => 'dropdown'} : {'data-toggle' => 'dropdown', title: popover_with_close_html("2. #{t('shared.public_explain.control_your_audience')}"), 'data-content'=> t('shared.public_explain.visibility_dropdown')} }
- if publisher_public
%i#visibility-icon.entypo-globe.small
%span.text
= t('public')
- else
%i#visibility-icon.entypo-lock.small
%span.text
- if all_aspects_selected?(selected_aspects)
= t('all_aspects')
- elsif selected_aspects.size == 1
= selected_aspects.first.name
- else
= t('shared.aspect_dropdown.toggle', count: selected_aspects.size)
%span.caret
%ul.dropdown-menu.pull-right{ unSelectable: 'on' }
%li.public.radio{"data-aspect_id" => "public", class: ("selected" if publisher_public)}
%a
%span.status_indicator
%i.glyphicon.glyphicon-ok
%span.text
= t('public')
%li.all_aspects.radio{"data-aspect_id" => "all_aspects", class: ("selected" if (!publisher_public && all_aspects_selected?(selected_aspects)))}
%a
%span.status_indicator
%i.glyphicon.glyphicon-ok
%span.text
= t('all_aspects')
%li.divider
- for aspect in all_aspects
%li.aspect_selector{ 'data-aspect_id' => aspect.id, class: !all_aspects_selected?(selected_aspects) && selected_aspects.include?(aspect) ? "selected" : "" }
%a
%span.status_indicator
%i.glyphicon.glyphicon-ok
%span.text
= aspect.name
...@@ -40,9 +40,9 @@ ...@@ -40,9 +40,9 @@
!= t("shared.publisher.formatWithMarkdown", markdown_link: link_to(t("help.markdown"), != t("shared.publisher.formatWithMarkdown", markdown_link: link_to(t("help.markdown"),
"https://diasporafoundation.org/formatting", target: :blank)) "https://diasporafoundation.org/formatting", target: :blank))
- if publisher_public - if public_selected?(selected_aspects)
= hidden_field_tag "aspect_ids[]", "public" = hidden_field_tag "aspect_ids[]", "public"
- elsif all_aspects_selected?(selected_aspects) - elsif all_aspects_selected?(all_aspects, selected_aspects)
= hidden_field_tag "aspect_ids[]", "all_aspects" = hidden_field_tag "aspect_ids[]", "all_aspects"
- else - else
- for aspect_id in aspect_ids - for aspect_id in aspect_ids
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
.options_and_submit.col-sm-12 .options_and_submit.col-sm-12
.public_toggle.clearfix .public_toggle.clearfix
.btn-toolbar.pull-right .btn-toolbar.pull-right
= render partial: "publisher/aspect_dropdown", locals: {selected_aspects: selected_aspects} = render partial: "aspects/aspect_dropdown", locals: {selected_aspects: selected_aspects}
%button.btn.btn-group.btn-primary#submit= t("shared.publisher.share") %button.btn.btn-group.btn-primary#submit= t("shared.publisher.share")
.btn-toolbar.pull-right#publisher-service-icons .btn-toolbar.pull-right#publisher-service-icons
......
...@@ -115,6 +115,7 @@ ...@@ -115,6 +115,7 @@
.clearfix= f.submit t(".change"), class: "btn btn-primary pull-right" .clearfix= f.submit t(".change"), class: "btn btn-primary pull-right"
%hr %hr
= render partial: "post_default"
.row .row
.col-md-12 .col-md-12
......
.row
.col-md-12
%h3
= t("users.edit.default_post_visibility")
= form_for current_user, url: edit_user_path,
html: {method: :put, id: "post-default-aspects", class: "form-horizontal"} do |f|
= f.hidden_field :post_default_public, value: false
- selected_aspects = current_user.post_default_aspects
= render partial: "aspects/aspect_dropdown", locals: {selected_aspects: selected_aspects}
.small-horizontal-spacer
.clearfix= f.submit t("users.edit.change"), class: "btn btn-primary pull-right"
%hr
-# This feature is not supported in mobile format.
...@@ -1156,6 +1156,7 @@ en: ...@@ -1156,6 +1156,7 @@ en:
following: "Sharing settings" following: "Sharing settings"
auto_follow_back: "Automatically share with users who start sharing with you" auto_follow_back: "Automatically share with users who start sharing with you"
auto_follow_aspect: "Aspect for users you automatically share with:" auto_follow_aspect: "Aspect for users you automatically share with:"
default_post_visibility: "Default aspects selected for posting"
receive_email_notifications: "Receive email notifications when:" receive_email_notifications: "Receive email notifications when:"
started_sharing: "someone starts sharing with you" started_sharing: "someone starts sharing with you"
someone_reported: "someone sends a report" someone_reported: "someone sends a report"
......
class AddPostDefaultToAspects < ActiveRecord::Migration
def change
add_column :aspects, :post_default, :boolean, default: true
add_column :users, :post_default_public, :boolean, default: false
end
end
...@@ -48,6 +48,7 @@ ActiveRecord::Schema.define(version: 20160906225138) do ...@@ -48,6 +48,7 @@ ActiveRecord::Schema.define(version: 20160906225138) do
t.boolean "contacts_visible", default: true, null: false t.boolean "contacts_visible", default: true, null: false
t.integer "order_id", limit: 4 t.integer "order_id", limit: 4
t.boolean "chat_enabled", default: false t.boolean "chat_enabled", default: false
t.boolean "post_default", default: true
end end
add_index "aspects", ["user_id", "contacts_visible"], name: "index_aspects_on_user_id_and_contacts_visible", using: :btree add_index "aspects", ["user_id", "contacts_visible"], name: "index_aspects_on_user_id_and_contacts_visible", using: :btree
...@@ -634,6 +635,7 @@ ActiveRecord::Schema.define(version: 20160906225138) do ...@@ -634,6 +635,7 @@ ActiveRecord::Schema.define(version: 20160906225138) do
t.datetime "exported_photos_at" t.datetime "exported_photos_at"
t.boolean "exporting_photos", default: false t.boolean "exporting_photos", default: false
t.string "color_theme", limit: 255 t.string "color_theme", limit: 255
t.boolean "post_default_public", default: false
end end
add_index "users", ["authentication_token"], name: "index_users_on_authentication_token", unique: true, using: :btree add_index "users", ["authentication_token"], name: "index_users_on_authentication_token", unique: true, using: :btree
......
...@@ -3,6 +3,9 @@ Feature: Change settings ...@@ -3,6 +3,9 @@ Feature: Change settings
Background: Background:
Given I am signed in Given I am signed in
And I have following aspects:
| Friends |
| Family |
When I go to the edit user page When I go to the edit user page
Scenario: Change my email Scenario: Change my email
...@@ -25,3 +28,24 @@ Feature: Change settings ...@@ -25,3 +28,24 @@ Feature: Change settings
And I press "Change language" And I press "Change language"
Then I should see "Język został zmieniony" Then I should see "Język został zmieniony"
And "polski" should be selected from "user_language" And "polski" should be selected from "user_language"
Scenario: Change my post default aspects
When I go to the stream page
And I expand the publisher
Then I should see "All aspects" within ".aspect_dropdown"
When I go to the edit user page
And I press the aspect dropdown
And I toggle the aspect "Family"
And I press the aspect dropdown
And I press "Change" within "#post-default-aspects"
And I go to the stream page
And I expand the publisher
Then I should see "Family" within ".aspect_dropdown"
Scenario: Change my post default to public
When I press the aspect dropdown
And I toggle the aspect "Public"
And I press "Change" within "#post-default-aspects"
And I go to the stream page
And I expand the publisher
Then I should see "Public" within ".aspect_dropdown"
...@@ -4,7 +4,11 @@ module AspectCukeHelpers ...@@ -4,7 +4,11 @@ module AspectCukeHelpers
end end
def toggle_aspect(a_name) def toggle_aspect(a_name)
a_id = @me.aspects.where(name: a_name).pluck(:id).first a_id = if "Public" == a_name
"public"
else
@me.aspects.where(name: a_name).pluck(:id).first
end
aspect_css = ".aspect_dropdown li[data-aspect_id='#{a_id}']" aspect_css = ".aspect_dropdown li[data-aspect_id='#{a_id}']"
expect(page).to have_selector(aspect_css) expect(page).to have_selector(aspect_css)
find(aspect_css).click find(aspect_css).click
......
...@@ -62,7 +62,7 @@ class Stream::Base ...@@ -62,7 +62,7 @@ class Stream::Base
#NOTE: MBS bad bad methods the fact we need these means our views are foobared. please kill them and make them #NOTE: MBS bad bad methods the fact we need these means our views are foobared. please kill them and make them
#private methods on the streams that need them #private methods on the streams that need them
def aspects def aspects
user.aspects user.post_default_aspects
end end
# @return [Aspect] The first aspect in #aspects # @return [Aspect] The first aspect in #aspects
...@@ -71,7 +71,7 @@ class Stream::Base ...@@ -71,7 +71,7 @@ class Stream::Base
end end
def aspect_ids def aspect_ids
aspects.map{|x| x.id} aspects.map {|x| x.try(:id) }
end end
def max_time=(time_string) def max_time=(time_string)
......
...@@ -28,7 +28,7 @@ class Stream::Multi < Stream::Base ...@@ -28,7 +28,7 @@ class Stream::Multi < Stream::Base
if welcome? if welcome?
{open: true, prefill: publisher_prefill, public: true} {open: true, prefill: publisher_prefill, public: true}
else else
super {public: user.post_default_public}
end end
end end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter