FEATURE: basic info route for all sites, even ones that require login

This information is public in meta tags already on home page, providing a
route allows consumers to check it way more cheaply
This commit is contained in:
Sam 2016-08-12 17:10:08 +10:00
parent afaba56de3
commit 7e4503dd99
3 changed files with 49 additions and 0 deletions

View file

@ -3,6 +3,7 @@ require_dependency 'site_serializer'
class SiteController < ApplicationController class SiteController < ApplicationController
layout false layout false
skip_before_filter :preload_json, :check_xhr skip_before_filter :preload_json, :check_xhr
skip_before_filter :redirect_to_login_if_required, only: ['basic_info']
def site def site
render json: Site.json_for(guardian) render json: Site.json_for(guardian)
@ -23,4 +24,22 @@ class SiteController < ApplicationController
def emoji def emoji
render json: custom_emoji render json: custom_emoji
end end
def basic_info
results = {
logo_url: UrlHelper.absolute(SiteSetting.logo_url),
logo_small_url: UrlHelper.absolute(SiteSetting.logo_small_url),
apple_touch_icon_url: UrlHelper.absolute(SiteSetting.apple_touch_icon_url),
favicon_url: UrlHelper.absolute(SiteSetting.favicon_url),
title: SiteSetting.title,
description: SiteSetting.site_description
}
if SiteSetting.mobile_logo_url.present?
results[:mobile_logo_url] = SiteSetting.mobile_logo_url
end
# this info is always available cause it can be scraped from a 404 page
render json: results
end
end end

View file

@ -45,6 +45,9 @@ Discourse::Application.routes.draw do
get "banner" get "banner"
get "emoji" get "emoji"
end end
get "site/basic-info" => 'site#basic_info'
get "site_customizations/:key" => "site_customizations#show" get "site_customizations/:key" => "site_customizations#show"
resources :forums resources :forums

View file

@ -0,0 +1,27 @@
require 'rails_helper'
describe SiteController do
describe '.basic_info' do
it 'is visible always even for sites requiring login' do
SiteSetting.login_required = true
SiteSetting.title = "Hammer Time"
SiteSetting.site_description= "A time for Hammer"
SiteSetting.logo_url = "/uploads/logo.png"
SiteSetting.logo_small_url = "http://boom.com/uploads/logo_small.png"
SiteSetting.apple_touch_icon_url = "https://boom.com/apple/logo.png"
SiteSetting.mobile_logo_url = "https://a.a/a.png"
xhr :get, :basic_info
json = JSON.parse(response.body)
expect(json["title"]).to eq("Hammer Time")
expect(json["description"]).to eq("A time for Hammer")
expect(json["logo_url"]).to eq("http://test.localhost/uploads/logo.png")
expect(json["apple_touch_icon_url"]).to eq("https://boom.com/apple/logo.png")
expect(json["logo_small_url"]).to eq("http://boom.com/uploads/logo_small.png")
expect(json["mobile_logo_url"]).to eq("https://a.a/a.png")
end
end
end