From 686310fb8e3514e5e827b272a4e44b14f5711ab7 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Wed, 11 Apr 2018 01:51:23 +0200 Subject: [PATCH] Simplify /podmin redirect Some podmins were confuse how they can disable this redirect and I think the rule with two users can actually be a little confusing. I think the main goal of this page to give the podmin a little start and I think after they configured everything, the pod works and they found the link to the wiki to make themself an admin, it is OK to remove the redirect. Also it's bad for single-user pods where this page always stays active, even if they are an admin, but have only one user. It's more useful for single-user pods to have the login on the home page. closes #7783 --- Changelog.md | 2 ++ app/controllers/home_controller.rb | 2 +- spec/controllers/home_controller_spec.rb | 23 +++-------------------- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/Changelog.md b/Changelog.md index e70e51465..86eb81f1b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,12 +2,14 @@ ## Refactor * Remove the 'make contacts in this aspect visible to each other' option [#7769](https://github.com/diaspora/diaspora/pull/7769) +* Remove the requirement to have at least two users to disable the /podmin redirect [#7783](https://github.com/diaspora/diaspora/pull/7783) ## Bug fixes * Prefill conversation form on contacts page only with mutual contacts [#7744](https://github.com/diaspora/diaspora/pull/7744) * Fix profiles sometimes not loading properly in background tabs [#7740](https://github.com/diaspora/diaspora/pull/7740) * Show error message when creating posts with invalid aspects [#7742](https://github.com/diaspora/diaspora/pull/7742) * Fix mention syntax backport for two immediately consecutive mentions [#7777](https://github.com/diaspora/diaspora/pull/7777) +* Fix link to 'make yourself an admin' [#7783](https://github.com/diaspora/diaspora/pull/7783) ## Features * Make public stream accessible for logged out users [#7775](https://github.com/diaspora/diaspora/pull/7775) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index feaddad14..8d24202e8 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -21,7 +21,7 @@ class HomeController < ApplicationController partial_dir.join("_show.html.erb").exist? || partial_dir.join("_show.haml").exist? render :show - elsif User.count > 1 && Role.where(name: "admin").any? + elsif Role.admins.any? render :default else redirect_to podmin_path diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index 82cc10711..6f8b8e031 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -6,31 +6,14 @@ describe HomeController, type: :controller do describe "#show" do - it "does not redirect for :html if there are at least 2 users and an admin" do - allow(User).to receive(:count).and_return(2) - allow(Role).to receive_message_chain(:where, :any?).and_return(true) - allow(Role).to receive_message_chain(:where, :exists?).and_return(true) + it "does not redirect for :html if there is at least one admin" do + expect(Role).to receive_message_chain(:admins, :any?).and_return(true) get :show expect(response).not_to be_redirect end - it "redirects to the podmin page for :html if there are less than 2 users" do - allow(User).to receive(:count).and_return(1) - allow(Role).to receive_message_chain(:where, :any?).and_return(true) - get :show - expect(response).to redirect_to(podmin_path) - end - it "redirects to the podmin page for :html if there is no admin" do - allow(User).to receive(:count).and_return(2) - allow(Role).to receive_message_chain(:where, :any?).and_return(false) - get :show - expect(response).to redirect_to(podmin_path) - end - - it "redirects to the podmin page for :html if there are less than 2 users and no admin" do - allow(User).to receive(:count).and_return(0) - allow(Role).to receive_message_chain(:where, :any?).and_return(false) + expect(Role).to receive_message_chain(:admins, :any?).and_return(false) get :show expect(response).to redirect_to(podmin_path) end