Makes the local posts link be configured for special audiences
This commit is contained in:
parent
34d9d9c3ee
commit
4147249d2d
8 changed files with 75 additions and 6 deletions
|
|
@ -26,7 +26,18 @@ class StreamsController < ApplicationController
|
|||
end
|
||||
|
||||
def local_public
|
||||
stream_responder(Stream::LocalPublic)
|
||||
return stream_responder(Stream::LocalPublic) if AppConfig.settings.enable_show_local_post_link == "always"
|
||||
|
||||
if AppConfig.settings.enable_show_local_post_link == "admin" && Role.is_admin?(current_user)
|
||||
return stream_responder(Stream::LocalPublic)
|
||||
end
|
||||
|
||||
if AppConfig.settings.enable_show_local_post_link == "moderator" &&
|
||||
(Role.moderator?(current_user) || Role.is_admin?(current_user))
|
||||
return stream_responder(Stream::LocalPublic)
|
||||
end
|
||||
|
||||
stream_responder(Stream::Public)
|
||||
end
|
||||
|
||||
def activity
|
||||
|
|
|
|||
|
|
@ -42,6 +42,17 @@ module ApplicationHelper
|
|||
"bookmarklet('#{bookmarklet_url}', #{width}, #{height});"
|
||||
end
|
||||
|
||||
def show_local_posts_link?(current_user)
|
||||
return true if AppConfig.settings.enable_show_local_post_link == "always"
|
||||
return true if AppConfig.settings.enable_show_local_post_link == "admin" &&
|
||||
Role.is_admin?(current_user)
|
||||
|
||||
return true if AppConfig.settings.enable_show_local_post_link == "moderator" &&
|
||||
(Role.moderator?(current_user) || Role.is_admin?(current_user))
|
||||
|
||||
false
|
||||
end
|
||||
|
||||
def all_services_connected?
|
||||
current_user.services.size == AppConfig.configured_services.size
|
||||
end
|
||||
|
|
|
|||
|
|
@ -37,8 +37,9 @@
|
|||
= render "aspects/aspect_listings", stream: @stream
|
||||
%li.nested-list
|
||||
= render "tags/followed_tags_listings"
|
||||
%li{data: {stream: "local_public"}}
|
||||
= link_to t("streams.local_public.title"), local_public_stream_path, rel: "backbone", class: "hoverable"
|
||||
- if show_local_posts_link?(current_user)
|
||||
%li{data: {stream: "local_public"}}
|
||||
= link_to t("streams.local_public.title"), local_public_stream_path, rel: "backbone", class: "hoverable"
|
||||
%li{data: {stream: "public"}}
|
||||
= link_to t("streams.public.title"), public_stream_path, rel: "backbone", class: "hoverable"
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ defaults:
|
|||
settings:
|
||||
pod_name: 'diaspora*'
|
||||
enable_registrations: true
|
||||
enable_show_local_post_link: 'disabled'
|
||||
autofollow_on_join: true
|
||||
autofollow_on_join_user: 'hq@pod.diaspora.software'
|
||||
welcome_message:
|
||||
|
|
|
|||
|
|
@ -287,6 +287,12 @@
|
|||
## (or commented out) to enable the first registration (you).
|
||||
#enable_registrations = true
|
||||
|
||||
## Show local posts (default="disabled")
|
||||
## If any other setting than disabled local public posts
|
||||
## created on this pod can be showed.
|
||||
## Choose one setting
|
||||
# enable_show_local_post_link= "disabled"|"admin"|"moderator"|"always"
|
||||
|
||||
## Auto-follow on sign-up (default=true)
|
||||
## Users will automatically follow a specified account on creation.
|
||||
## Set this to false if you don't want your users to automatically
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
# rubocop:disable Style/ClassAndModuleChildren
|
||||
class Stream::LocalPublic < Stream::Base
|
||||
def link(opts={})
|
||||
Rails.application.routes.url_helpers.local_public_stream_path(opts)
|
||||
|
|
@ -27,3 +28,4 @@ class Stream::LocalPublic < Stream::Base
|
|||
["public"]
|
||||
end
|
||||
end
|
||||
# rubocop:enable Style/ClassAndModuleChildren
|
||||
|
|
|
|||
|
|
@ -122,6 +122,43 @@ describe ApplicationHelper, :type => :helper do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#enable_show_local_post_link" do
|
||||
let!(:moderator) { create(:person) }
|
||||
let!(:admin) { create(:person) }
|
||||
before do
|
||||
moderator.roles.create(name: "moderator")
|
||||
admin.roles.create(name: "admin")
|
||||
end
|
||||
|
||||
it "return false if show_local_posts_link is 'disabled'" do
|
||||
AppConfig.settings.enable_show_local_post_link = "disabled"
|
||||
expect(helper.show_local_posts_link?(admin)).to be false
|
||||
expect(helper.show_local_posts_link?(moderator)).to be false
|
||||
expect(helper.show_local_posts_link?(alice)).to be false
|
||||
end
|
||||
|
||||
it "return true for admins if show_local_posts_link is 'admin'" do
|
||||
AppConfig.settings.enable_show_local_post_link = "admin"
|
||||
expect(helper.show_local_posts_link?(admin)).to be true
|
||||
expect(helper.show_local_posts_link?(moderator)).to be false
|
||||
expect(helper.show_local_posts_link?(alice)).to be false
|
||||
end
|
||||
|
||||
it "return true for admins and moderators if show_local_posts_link is 'moderator'" do
|
||||
AppConfig.settings.enable_show_local_post_link = "moderator"
|
||||
expect(helper.show_local_posts_link?(admin)).to be true
|
||||
expect(helper.show_local_posts_link?(moderator)).to be true
|
||||
expect(helper.show_local_posts_link?(alice)).to be false
|
||||
end
|
||||
|
||||
it "return true for everybody if show_local_posts_link is 'always'" do
|
||||
AppConfig.settings.enable_show_local_post_link = "always"
|
||||
expect(helper.show_local_posts_link?(admin)).to be true
|
||||
expect(helper.show_local_posts_link?(moderator)).to be true
|
||||
expect(helper.show_local_posts_link?(alice)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe "#changelog_url" do
|
||||
let(:changelog_url_setting) {
|
||||
double.tap {|double| allow(AppConfig).to receive(:settings).and_return(double(changelog_url: double)) }
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('spec', 'shared_behaviors', 'stream')
|
||||
require Rails.root.join("spec/shared_behaviors/stream")
|
||||
|
||||
describe Stream::LocalPublic do
|
||||
before do
|
||||
@stream = Stream::LocalPublic.new(alice)
|
||||
end
|
||||
|
||||
describe 'shared behaviors' do
|
||||
it_should_behave_like 'it is a stream'
|
||||
describe "shared behaviors" do
|
||||
it_should_behave_like "it is a stream"
|
||||
end
|
||||
|
||||
describe "#posts" do
|
||||
|
|
|
|||
Loading…
Reference in a new issue