Merge pull request #1861 from slainer68/login_required_allow_api
Allow to use the API when Login required site setting is on
This commit is contained in:
commit
c0f2298a84
|
@ -281,7 +281,9 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_to_login_if_required
|
def redirect_to_login_if_required
|
||||||
redirect_to :login if SiteSetting.login_required? && !current_user
|
return if current_user || (request.format.json? && api_key_valid?)
|
||||||
|
|
||||||
|
redirect_to :login if SiteSetting.login_required?
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_not_found_page(status=404, layout=false)
|
def build_not_found_page(status=404, layout=false)
|
||||||
|
|
|
@ -583,10 +583,22 @@ describe TopicsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'and the user is not logged in' do
|
context 'and the user is not logged in' do
|
||||||
|
let(:api_key) { topic.user.generate_api_key(topic.user) }
|
||||||
|
|
||||||
it 'redirects to the login page' do
|
it 'redirects to the login page' do
|
||||||
get :show, topic_id: topic.id, slug: topic.slug
|
get :show, topic_id: topic.id, slug: topic.slug
|
||||||
expect(response).to redirect_to login_path
|
expect(response).to redirect_to login_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'shows the topic if valid api key is provided' do
|
||||||
|
get :show, topic_id: topic.id, slug: topic.slug, api_key: api_key.key
|
||||||
|
expect(response).to be_successful
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects to the login page if invalid key is provided' do
|
||||||
|
get :show, topic_id: topic.id, slug: topic.slug, api_key: "bad"
|
||||||
|
expect(response).to redirect_to login_path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue