FIX: Redirect to login for anon user.
https://meta.discourse.org/t/link-to-upgrade-shows-500-error/70993/7
This commit is contained in:
parent
a6539a6cf5
commit
f117e28158
|
|
@ -20,7 +20,7 @@ module DockerManager
|
||||||
|
|
||||||
if (version < expected_version) || (ruby_version < expected_ruby_version)
|
if (version < expected_version) || (ruby_version < expected_ruby_version)
|
||||||
|
|
||||||
render text: <<HTML
|
render text: <<~HTML
|
||||||
<html><head></head><body>
|
<html><head></head><body>
|
||||||
<h2>You are running an old version of the Discourse image.</h2>
|
<h2>You are running an old version of the Discourse image.</h2>
|
||||||
<p>
|
<p>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
module DockerManager
|
module DockerManager
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
helper DockerManager::ApplicationHelper
|
helper DockerManager::ApplicationHelper
|
||||||
|
|
||||||
include CurrentUser
|
include CurrentUser
|
||||||
|
|
@ -17,7 +16,8 @@ module DockerManager
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def ensure_admin
|
def ensure_admin
|
||||||
raise Discourse::InvalidAccess.new unless current_user && current_user.admin?
|
return redirect_to '/login' if !current_user
|
||||||
|
return render(plain: I18n.t('invalid_access'), status: 404) if !current_user.admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe DockerManager::AdminController do
|
||||||
|
describe 'anonymous user' do
|
||||||
|
it 'should redirect to login page' do
|
||||||
|
get '/admin/upgrade'
|
||||||
|
|
||||||
|
expect(response.status).to eq(302)
|
||||||
|
expect(response).to redirect_to('/login')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'when user is not an admin' do
|
||||||
|
it 'should redirect to login page' do
|
||||||
|
sign_in(Fabricate(:user))
|
||||||
|
|
||||||
|
get '/admin/upgrade'
|
||||||
|
|
||||||
|
expect(response.status).to eq(404)
|
||||||
|
expect(response.body).to eq(I18n.t('invalid_access'))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'when user is an admin' do
|
||||||
|
it 'should return the right response' do
|
||||||
|
sign_in(Fabricate(:admin))
|
||||||
|
|
||||||
|
get '/admin/upgrade'
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue