Merge branch 'stable' into develop

This commit is contained in:
Dennis Schubert 2015-05-25 04:18:46 +02:00
commit f9f73f56db
9 changed files with 191 additions and 77 deletions

View file

@ -55,7 +55,6 @@ Ruby 2.0 is no longer officially supported.
* Fix a freeze in new post parsing [#5965](https://github.com/diaspora/diaspora/pull/5965) * Fix a freeze in new post parsing [#5965](https://github.com/diaspora/diaspora/pull/5965)
* Add case insensitive unconfirmed email addresses as authentication key [#5967](https://github.com/diaspora/diaspora/pull/5967) * Add case insensitive unconfirmed email addresses as authentication key [#5967](https://github.com/diaspora/diaspora/pull/5967)
* Fix liking on single post views when accessed via GUID [#5978](https://github.com/diaspora/diaspora/pull/5978) * Fix liking on single post views when accessed via GUID [#5978](https://github.com/diaspora/diaspora/pull/5978)
* Gracefully handle mailer failures when a like is already deleted again [#5983](https://github.com/diaspora/diaspora/pull/5983)
## Features ## Features
* Hide post title of limited post in comment notification email [#5843](https://github.com/diaspora/diaspora/pull/5843) * Hide post title of limited post in comment notification email [#5843](https://github.com/diaspora/diaspora/pull/5843)
@ -70,6 +69,7 @@ Ruby 2.0 is no longer officially supported.
* Add a "Manage followed tags" page to mass unfollow tags in the mobile interface [#5945](https://github.com/diaspora/diaspora/pull/5945) * Add a "Manage followed tags" page to mass unfollow tags in the mobile interface [#5945](https://github.com/diaspora/diaspora/pull/5945)
* Add popover/tooltip about email visibility to registration/settings page [#5956](https://github.com/diaspora/diaspora/pull/5956) * Add popover/tooltip about email visibility to registration/settings page [#5956](https://github.com/diaspora/diaspora/pull/5956)
* Fetch person posts on sharing request [#5960](https://github.com/diaspora/diaspora/pull/5960) * Fetch person posts on sharing request [#5960](https://github.com/diaspora/diaspora/pull/5960)
* Introduce 'authorized' configuration option for services [#5985](https://github.com/diaspora/diaspora/pull/5985)
# 0.5.0.1 # 0.5.0.1

View file

@ -98,7 +98,7 @@ class StatisticsPresenter
def all_services_helper def all_services_helper
result = {} result = {}
Configuration::KNOWN_SERVICES.each {|service, options| Configuration::KNOWN_SERVICES.each {|service, options|
result[service.to_s] = AppConfig["services.#{service}.enable"] result[service.to_s] = AppConfig.show_service?(service, nil)
} }
result result
end end
@ -109,13 +109,13 @@ class StatisticsPresenter
def available_services def available_services
Configuration::KNOWN_SERVICES.select {|service| Configuration::KNOWN_SERVICES.select {|service|
AppConfig["services.#{service}.enable"] AppConfig.show_service?(service, nil)
}.map(&:to_s) }.map(&:to_s)
end end
def legacy_services def legacy_services
Configuration::KNOWN_SERVICES.each_with_object({}) {|service, result| Configuration::KNOWN_SERVICES.each_with_object({}) {|service, result|
result[service.to_s] = AppConfig["services.#{service}.enable"] result[service.to_s] = AppConfig.show_service?(service, nil)
} }
end end

View file

@ -4,19 +4,20 @@
- if AppConfig.configured_services.count > 0 - if AppConfig.configured_services.count > 0
- AppConfig.configured_services.each do |provider| - AppConfig.configured_services.each do |provider|
%h3= t("services.provider.#{provider}") - if AppConfig.show_service?(provider, current_user)
- services_for_provider = @services.select{|x| x.provider == provider.to_s} %h3= t("services.provider.#{provider}")
- if services_for_provider.count > 0 - services_for_provider = @services.select{|x| x.provider == provider.to_s}
- services_for_provider.each do |service| - if services_for_provider.count > 0
!= t("services.index.logged_in_as", nickname: content_tag(:strong, service.nickname )) - services_for_provider.each do |service|
= link_to t("services.index.disconnect"), != t("services.index.logged_in_as", nickname: content_tag(:strong, service.nickname ))
service_path(service), = link_to t("services.index.disconnect"),
data: { confirm: t("services.index.really_disconnect", service: t("services.provider.#{provider}")) }, service_path(service),
method: :delete data: { confirm: t("services.index.really_disconnect", service: t("services.provider.#{provider}")) },
method: :delete
- else - else
= t("services.index.not_logged_in") = t("services.index.not_logged_in")
= link_to(t("services.index.connect"), "/auth/#{provider}") = link_to(t("services.index.connect"), "/auth/#{provider}")
- else - else
.well .well

View file

@ -57,8 +57,9 @@
#right_service_icons #right_service_icons
- AppConfig.configured_services.each do |service| - AppConfig.configured_services.each do |service|
- unless current_user.services.any?{|x| x.provider == service} - if AppConfig.show_service?(service, current_user)
= link_to(content_tag(:div, nil, :class => "social_media_logos-#{service.to_s.downcase}-24x24", :title => service.to_s.titleize), "/auth/#{service}") - unless current_user.services.any?{|x| x.provider == service}
= link_to(content_tag(:div, nil, :class => "social_media_logos-#{service.to_s.downcase}-24x24", :title => service.to_s.titleize), "/auth/#{service}")
.section .section
.title .title

View file

@ -145,18 +145,22 @@ defaults:
app_id: app_id:
secret: secret:
open_graph_namespace: 'joindiaspora' open_graph_namespace: 'joindiaspora'
authorized: false
twitter: twitter:
enable: false enable: false
key: key:
secret: secret:
authorized: true
tumblr: tumblr:
enable: false enable: false
key: key:
secret: secret:
authorized: true
wordpress: wordpress:
enable: false enable: false
key: key:
secret: secret:
authorized: true
mail: mail:
enable: false enable: false
sender_address: 'no-reply@example.org' sender_address: 'no-reply@example.org'
@ -210,6 +214,7 @@ test:
enable: true enable: true
app_id: 'fake' app_id: 'fake'
secret: 'sdoigjosdfijg' secret: 'sdoigjosdfijg'
authorized: true
mail: mail:
enable: true enable: true
integration1: integration1:

View file

@ -532,6 +532,13 @@ configuration: ## Section
#app_id: 'abcdef' #app_id: 'abcdef'
#secret: 'change_me' #secret: 'change_me'
## This setting is required to define whether the Facebook app has permissions to post
## false == No permissions (default)
## true == Permissions for all users to post. App MUST have 'publish_actions' approved by Facebook!
## "username" == Set to local username to allow a single user to cross-post. The person who has created
## the Facebook app will always be able to cross-post, even without 'publish_actions'.
#authorized: false
## OAuth credentials for Twitter ## OAuth credentials for Twitter
twitter: ## Section twitter: ## Section

View file

@ -34,6 +34,13 @@ module Configuration
end end
attr_writer :configured_services attr_writer :configured_services
def show_service?(service, user)
return false unless self["services.#{service}.enable"]
# Return true only if 'authorized' is true or equal to user username
(user && self["services.#{service}.authorized"] == user.username) ||
self["services.#{service}.authorized"] == true
end
def secret_token def secret_token
if heroku? if heroku?
return ENV['SECRET_TOKEN'] if ENV['SECRET_TOKEN'] return ENV['SECRET_TOKEN'] if ENV['SECRET_TOKEN']

View file

@ -8,40 +8,40 @@ describe Configuration::Methods do
extend Configuration::Methods extend Configuration::Methods
end end
end end
describe "#pod_uri" do describe "#pod_uri" do
before do before do
@settings.environment.url = nil @settings.environment.url = nil
@settings.instance_variable_set(:@pod_uri, nil) @settings.instance_variable_set(:@pod_uri, nil)
end end
it "properly parses the pod url" do it "properly parses the pod url" do
@settings.environment.url = "http://example.org/" @settings.environment.url = "http://example.org/"
expect(@settings.pod_uri.scheme).to eq("http") expect(@settings.pod_uri.scheme).to eq("http")
expect(@settings.pod_uri.host).to eq("example.org") expect(@settings.pod_uri.host).to eq("example.org")
end end
it "adds a trailing slash if there isn't one" do it "adds a trailing slash if there isn't one" do
@settings.environment.url = "http://example.org" @settings.environment.url = "http://example.org"
expect(@settings.pod_uri.to_s).to eq("http://example.org/") expect(@settings.pod_uri.to_s).to eq("http://example.org/")
end end
it "does not add an extra trailing slash" do it "does not add an extra trailing slash" do
@settings.environment.url = "http://example.org/" @settings.environment.url = "http://example.org/"
expect(@settings.pod_uri.to_s).to eq("http://example.org/") expect(@settings.pod_uri.to_s).to eq("http://example.org/")
end end
it "adds http:// on the front if it's missing" do it "adds http:// on the front if it's missing" do
@settings.environment.url = "example.org/" @settings.environment.url = "example.org/"
expect(@settings.pod_uri.to_s).to eq("http://example.org/") expect(@settings.pod_uri.to_s).to eq("http://example.org/")
end end
it "does not add a prefix if there already is https:// on the front" do it "does not add a prefix if there already is https:// on the front" do
@settings.environment.url = "https://example.org/" @settings.environment.url = "https://example.org/"
expect(@settings.pod_uri.to_s).to eq("https://example.org/") expect(@settings.pod_uri.to_s).to eq("https://example.org/")
end end
end end
describe "#bare_pod_uri" do describe "#bare_pod_uri" do
it 'is #pod_uri.authority stripping www.' do it 'is #pod_uri.authority stripping www.' do
pod_uri = double pod_uri = double
@ -50,7 +50,7 @@ describe Configuration::Methods do
expect(@settings.bare_pod_uri).to eq('example.org') expect(@settings.bare_pod_uri).to eq('example.org')
end end
end end
describe "#configured_services" do describe "#configured_services" do
it "includes the enabled services only" do it "includes the enabled services only" do
services = double services = double
@ -69,7 +69,40 @@ describe Configuration::Methods do
expect(@settings.configured_services).not_to include :wordpress expect(@settings.configured_services).not_to include :wordpress
end end
end end
describe "#show_service" do
before do
AppConfig.services.twitter.authorized = true
AppConfig.services.twitter.enable = true
AppConfig.services.facebook.authorized = true
AppConfig.services.facebook.enable = true
AppConfig.services.wordpress.authorized = false
AppConfig.services.wordpress.enable = true
AppConfig.services.tumblr.authorized = "alice"
AppConfig.services.tumblr.enable = true
end
it "shows service with no authorized key" do
expect(AppConfig.show_service?("twitter", bob)).to be_truthy
end
it "shows service with authorized key true" do
expect(AppConfig.show_service?("facebook", bob)).to be_truthy
end
it "doesn't show service with authorized key false" do
expect(AppConfig.show_service?("wordpress", bob)).to be_falsey
end
it "doesn't show service with authorized key not equal to username" do
expect(AppConfig.show_service?("tumblr", bob)).to be_falsey
end
it "shows service with authorized key equal to username" do
expect(AppConfig.show_service?("tumblr", alice)).to be_truthy
end
end
describe "#version_string" do describe "#version_string" do
before do before do
@version = double @version = double
@ -83,61 +116,61 @@ describe Configuration::Methods do
it "includes the version" do it "includes the version" do
expect(@settings.version_string).to include @version.number expect(@settings.version_string).to include @version.number
end end
context "with git available" do context "with git available" do
before do before do
allow(@settings).to receive(:git_available?).and_return(true) allow(@settings).to receive(:git_available?).and_return(true)
allow(@settings).to receive(:git_revision).and_return("1234567890") allow(@settings).to receive(:git_revision).and_return("1234567890")
end end
it "includes the 'patchlevel'" do it "includes the 'patchlevel'" do
expect(@settings.version_string).to include "-p#{@settings.git_revision[0..7]}" expect(@settings.version_string).to include "-p#{@settings.git_revision[0..7]}"
expect(@settings.version_string).not_to include @settings.git_revision[0..8] expect(@settings.version_string).not_to include @settings.git_revision[0..8]
end end
end end
end end
describe "#get_redis_options" do describe "#get_redis_options" do
context "with REDISTOGO_URL set" do context "with REDISTOGO_URL set" do
before do before do
ENV["REDISTOGO_URL"] = "redis://myserver" ENV["REDISTOGO_URL"] = "redis://myserver"
end end
it "uses that" do it "uses that" do
expect(@settings.get_redis_options[:url]).to match "myserver" expect(@settings.get_redis_options[:url]).to match "myserver"
end end
end end
context "with REDIS_URL set" do context "with REDIS_URL set" do
before do before do
ENV["REDISTOGO_URL"] = nil ENV["REDISTOGO_URL"] = nil
ENV["REDIS_URL"] = "redis://yourserver" ENV["REDIS_URL"] = "redis://yourserver"
end end
it "uses that" do it "uses that" do
expect(@settings.get_redis_options[:url]).to match "yourserver" expect(@settings.get_redis_options[:url]).to match "yourserver"
end end
end end
context "with redis set" do context "with redis set" do
before do before do
ENV["REDISTOGO_URL"] = nil ENV["REDISTOGO_URL"] = nil
ENV["REDIS_URL"] = nil ENV["REDIS_URL"] = nil
@settings.environment.redis = "redis://ourserver" @settings.environment.redis = "redis://ourserver"
end end
it "uses that" do it "uses that" do
expect(@settings.get_redis_options[:url]).to match "ourserver" expect(@settings.get_redis_options[:url]).to match "ourserver"
end end
end end
context "with a unix socket set" do context "with a unix socket set" do
before do before do
ENV["REDISTOGO_URL"] = nil ENV["REDISTOGO_URL"] = nil
ENV["REDIS_URL"] = nil ENV["REDIS_URL"] = nil
@settings.environment.redis = "unix:///tmp/redis.sock" @settings.environment.redis = "unix:///tmp/redis.sock"
end end
it "uses that" do it "uses that" do
expect(@settings.get_redis_options[:url]).to match "/tmp/redis.sock" expect(@settings.get_redis_options[:url]).to match "/tmp/redis.sock"
end end

View file

@ -1,76 +1,136 @@
require 'spec_helper' require "spec_helper"
describe StatisticsPresenter do describe StatisticsPresenter do
before do before do
@presenter = StatisticsPresenter.new @presenter = StatisticsPresenter.new
end end
describe '#as_json' do describe "#as_json" do
it 'works' do it "works" do
expect(@presenter.as_json).to be_present expect(@presenter.as_json).to be_present
expect(@presenter.as_json).to be_a Hash expect(@presenter.as_json).to be_a Hash
end end
end end
describe '#statistics contents' do describe "#statistics contents" do
before do before do
AppConfig.privacy.statistics.user_counts = false AppConfig.privacy.statistics.user_counts = false
AppConfig.privacy.statistics.post_counts = false AppConfig.privacy.statistics.post_counts = false
AppConfig.privacy.statistics.comment_counts = false AppConfig.privacy.statistics.comment_counts = false
end end
it 'provides generic pod data in json' do it "provides generic pod data in json" do
expect(@presenter.as_json).to eq({ expect(@presenter.as_json).to eq(
"name" => AppConfig.settings.pod_name, "name" => AppConfig.settings.pod_name,
"network" => "Diaspora", "network" => "Diaspora",
"version" => AppConfig.version_string, "version" => AppConfig.version_string,
"registrations_open" => AppConfig.settings.enable_registrations?, "registrations_open" => AppConfig.settings.enable_registrations?,
"services"=> ["facebook",], "services" => ["facebook"],
"facebook" => true, "facebook" => true,
"tumblr" => false, "tumblr" => false,
"twitter" => false, "twitter" => false,
"wordpress" => false, "wordpress" => false
}) )
end end
context 'when services are enabled' do context "when services are enabled" do
before do
AppConfig.services = {
"facebook" => {
"enable" => true,
"authorized" => true
},
"twitter" => {"enable" => true},
"wordpress" => {"enable" => false},
"tumblr" => {
"enable" => true,
"authorized" => false
}
}
end
it "provides services in json" do
expect(@presenter.as_json).to eq(
"name" => AppConfig.settings.pod_name,
"network" => "Diaspora",
"version" => AppConfig.version_string,
"registrations_open" => AppConfig.settings.enable_registrations?,
"services" => %w(twitter facebook),
"facebook" => true,
"twitter" => true,
"tumblr" => false,
"wordpress" => false
)
end
end
context "when some services are set to username authorized" do
before do
AppConfig.services = {
"facebook" => {
"enable" => true,
"authorized" => "bob"
},
"twitter" => {"enable" => true},
"wordpress" => {
"enable" => true,
"authorized" => "alice"
},
"tumblr" => {
"enable" => true,
"authorized" => false
}
}
end
it "provides services in json" do
expect(@presenter.as_json).to eq(
"name" => AppConfig.settings.pod_name,
"network" => "Diaspora",
"version" => AppConfig.version_string,
"registrations_open" => AppConfig.settings.enable_registrations?,
"services" => ["twitter"],
"facebook" => false,
"twitter" => true,
"tumblr" => false,
"wordpress" => false
)
end
end
context "when counts are enabled" do
before do before do
AppConfig.privacy.statistics.user_counts = true AppConfig.privacy.statistics.user_counts = true
AppConfig.privacy.statistics.post_counts = true AppConfig.privacy.statistics.post_counts = true
AppConfig.privacy.statistics.comment_counts = true AppConfig.privacy.statistics.comment_counts = true
AppConfig.services = {
"facebook" => {"enable" => true},
"twitter" => {"enable" => true},
"wordpress" => {"enable" => false},
"tumblr" => {"enable" => false}
}
end end
it 'provides generic pod data and counts in json' do it "provides generic pod data and counts in json" do
expect(@presenter.as_json).to eq({ expect(@presenter.as_json).to eq(
"name" => AppConfig.settings.pod_name, "name" => AppConfig.settings.pod_name,
"network" => "Diaspora", "network" => "Diaspora",
"version" => AppConfig.version_string, "version" => AppConfig.version_string,
"registrations_open" => AppConfig.settings.enable_registrations?, "registrations_open" => AppConfig.settings.enable_registrations?,
"total_users" => User.active.count, "total_users" => User.active.count,
"active_users_halfyear" => User.halfyear_actives.count, "active_users_halfyear" => User.halfyear_actives.count,
"active_users_monthly" => User.monthly_actives.count, "active_users_monthly" => User.monthly_actives.count,
"local_posts" => @presenter.local_posts, "local_posts" => @presenter.local_posts,
"local_comments" => @presenter.local_comments, "local_comments" => @presenter.local_comments,
"services" => ["twitter","facebook"], "services" => ["facebook"],
"facebook" => true, "facebook" => true,
"twitter" => true, "twitter" => false,
"tumblr" => false, "tumblr" => false,
"wordpress" => false "wordpress" => false
}) )
end end
end end
context 'when registrations are closed' do
context "when registrations are closed" do
before do before do
AppConfig.settings.enable_registrations = false AppConfig.settings.enable_registrations = false
end end
it 'should mark open_registrations to be false' do it "should mark open_registrations to be false" do
expect(@presenter.open_registrations?).to be false expect(@presenter.open_registrations?).to be false
end end
end end