From 2db1d5d641d3d1cb793d3153f54c8df1f769d07d Mon Sep 17 00:00:00 2001 From: Thorsten Claus Date: Sun, 11 Apr 2021 21:45:31 +0200 Subject: [PATCH] Fixing PR Rewview issues --- app/controllers/streams_controller.rb | 15 +++------- app/helpers/application_helper.rb | 11 -------- app/views/streams/main_stream.html.haml | 2 +- config/diaspora.toml.example | 10 ++++--- config/locales/diaspora/de.yml | 2 -- lib/configuration_methods.rb | 9 ++++++ lib/stream/local_public.rb | 4 --- spec/helpers/application_helper_spec.rb | 37 ------------------------- spec/lib/configuration_methods_spec.rb | 37 +++++++++++++++++++++++++ spec/models/post_spec.rb | 4 +-- 10 files changed, 59 insertions(+), 72 deletions(-) diff --git a/app/controllers/streams_controller.rb b/app/controllers/streams_controller.rb index 4df4a9c24..943295908 100644 --- a/app/controllers/streams_controller.rb +++ b/app/controllers/streams_controller.rb @@ -26,18 +26,11 @@ class StreamsController < ApplicationController end def local_public - 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) + if AppConfig.local_posts_stream?(current_user) + stream_responder(Stream::LocalPublic) + else + head :not_found 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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2bd473b80..36cce9bce 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -42,17 +42,6 @@ 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 diff --git a/app/views/streams/main_stream.html.haml b/app/views/streams/main_stream.html.haml index d1682d76e..cf4aaebae 100644 --- a/app/views/streams/main_stream.html.haml +++ b/app/views/streams/main_stream.html.haml @@ -37,7 +37,7 @@ = render "aspects/aspect_listings", stream: @stream %li.nested-list = render "tags/followed_tags_listings" - - if show_local_posts_link?(current_user) + - if AppConfig.local_posts_stream?(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"}} diff --git a/config/diaspora.toml.example b/config/diaspora.toml.example index e2ddb7861..b41b4c1eb 100644 --- a/config/diaspora.toml.example +++ b/config/diaspora.toml.example @@ -287,11 +287,13 @@ ## (or commented out) to enable the first registration (you). #enable_registrations = true -## Show local posts (default="disabled") +## Show local posts stream (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" +## created on this pod can be shown. +## Setting this to admins shows the local posts stream only to users with the admin role. +## Setting this to moderators shows the local posts stream only to users with the moderator or admin role. +## Setting this to everyone shows the local posts stream to all users. +# enable_local_posts_stream= "disabled"|"admins"|"moderators"|"everyone" ## Auto-follow on sign-up (default=true) ## Users will automatically follow a specified account on creation. diff --git a/config/locales/diaspora/de.yml b/config/locales/diaspora/de.yml index 38a92f6fa..745af609a 100644 --- a/config/locales/diaspora/de.yml +++ b/config/locales/diaspora/de.yml @@ -1245,8 +1245,6 @@ de: title: "Stream" public: title: "Öffentliche Aktivität" - local_public: - title: "Lokale Posts" tags: title: "Getaggte Beiträge: %{tags}" tag_followings: diff --git a/lib/configuration_methods.rb b/lib/configuration_methods.rb index 0c7a358d6..22a5e1a16 100644 --- a/lib/configuration_methods.rb +++ b/lib/configuration_methods.rb @@ -50,6 +50,15 @@ module Configuration self["services.#{service}.authorized"] == true end + def local_posts_stream?(user) + return true if settings.enable_local_posts_stream == "admins" && + Role.is_admin?(user) + return true if settings.enable_local_posts_stream == "moderators" && + (Role.moderator?(user) || Role.is_admin?(user)) + + settings.enable_local_posts_stream == "everyone" + end + def secret_token if heroku? return ENV["SECRET_TOKEN"] if ENV["SECRET_TOKEN"] diff --git a/lib/stream/local_public.rb b/lib/stream/local_public.rb index 4ef873d94..9e0963cee 100644 --- a/lib/stream/local_public.rb +++ b/lib/stream/local_public.rb @@ -1,9 +1,5 @@ # frozen_string_literal: true -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# 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={}) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 32a93d073..f0b0ab500 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -122,43 +122,6 @@ 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)) } diff --git a/spec/lib/configuration_methods_spec.rb b/spec/lib/configuration_methods_spec.rb index ae812578c..2453d406f 100644 --- a/spec/lib/configuration_methods_spec.rb +++ b/spec/lib/configuration_methods_spec.rb @@ -128,6 +128,43 @@ describe Configuration::Methods do end end + describe "#has_local_posts_stream" 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_local_posts_stream = "disabled" + expect(AppConfig.local_posts_stream?(admin)).to be false + expect(AppConfig.local_posts_stream?(moderator)).to be false + expect(AppConfig.local_posts_stream?(alice)).to be false + end + + it "return true for admins if show_local_posts_link is 'admins'" do + AppConfig.settings.enable_local_posts_stream = "admins" + expect(AppConfig.local_posts_stream?(admin)).to be true + expect(AppConfig.local_posts_stream?(moderator)).to be false + expect(AppConfig.local_posts_stream?(alice)).to be false + end + + it "return true for admins and moderators if show_local_posts_link is 'moderators'" do + AppConfig.settings.enable_local_posts_stream = "moderators" + expect(AppConfig.local_posts_stream?(admin)).to be true + expect(AppConfig.local_posts_stream?(moderator)).to be true + expect(AppConfig.local_posts_stream?(alice)).to be false + end + + it "return true for everybody if show_local_posts_link is 'everyone'" do + AppConfig.settings.enable_local_posts_stream = "everyone" + expect(AppConfig.local_posts_stream?(admin)).to be true + expect(AppConfig.local_posts_stream?(moderator)).to be true + expect(AppConfig.local_posts_stream?(alice)).to be true + end + end + describe "#version_string" do before do @version = double diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 36440e650..11eaf55de 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -75,8 +75,8 @@ describe Post, type: :model do end end - describe '.for_a_stream' do - it 'calls #for_visible_shareable_sql' do + describe ".for_a_stream" do + it "calls #for_visible_shareable_sql" do time = double order = double expect(Post).to receive(:for_visible_shareable_sql).with(time, order).and_return(Post)