Skip to content

Commit

Permalink
Move the admin dashboard to a subdomain (#56)
Browse files Browse the repository at this point in the history
This commit moves the administration dashboard from its current
location at /dashboard, to a subdomain named dashboard. On deployed
sites, this will change the dashboard location from
www.makigas.es/dashboard to dashboard.makigas.es.

Given that the public website has no need for user authentication, the
login path has moved to the dashboard subdomain as well. Therefore,
www is only used for serving public pages now. Everything related to
the admin panel is now located at the dashboard subdomain.
  • Loading branch information
danirod authored Aug 12, 2017
1 parent c67b818 commit 5557fff
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 20 deletions.
2 changes: 2 additions & 0 deletions app/controllers/dashboard/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class Dashboard::DashboardController < ApplicationController

before_action :authenticate_user!

def index
@videos = Video.count
@playlists = Playlist.count
Expand Down
3 changes: 2 additions & 1 deletion app/views/layouts/dashboard/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
<%= navigation_link t('.users'), [:dashboard, :users] %>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><%= link_to t('.view_site'), root_path %></li>
<li class="navbar-text hidden-xs"><%= current_user.email %></li>
<li><%= link_to t('.view_site'), root_url(subdomain: nil), target: :blank %></li>
<li><%= link_to t('.log_out'), destroy_user_session_path %></li>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/session_store.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Be sure to restart your server when you modify this file.

Rails.application.config.session_store :cookie_store, key: '_makigas_session'
Rails.application.config.session_store :cookie_store, key: '_makigas_session', secure: Rails.env.production?
30 changes: 12 additions & 18 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

# Application error routes
get '/404', to: 'error#not_found', via: :all
get '/422', to: 'error#unprocessable_entity', via: :all
get '/500', to: 'error#internal_server_error', via: :all

devise_for :users, controllers: {
sessions: 'users/sessions',
passwords: 'users/passwords'
}
root to: 'front#index'

# Routes for the dashboard
authenticate :user do
namespace :dashboard do
# Dashboard routes
constraints subdomain: 'dashboard' do
devise_for :users, controllers: { sessions: 'users/sessions', passwords: 'users/passwords' }
namespace :dashboard, path: '' do
root to: 'dashboard#index', as: ''
resources :topics
resources :videos, only: [:index, :new, :create]
Expand All @@ -29,18 +22,19 @@
end
end

get :terms, to: 'pages#terms'
get :privacy, to: 'pages#privacy'
get :disclaimer, to: 'pages#disclaimer'
get :cookies, to: 'pages#cookies'

# Main application routes
root to: 'front#index'
resources :topics, only: [:index, :show], constraints: { format: :html }
resources :videos, only: :index, constraints: { format: :html }
resources :playlists, path: 'series', only: [:index, :show], constraints: { format: :html } do
resources :videos, path: '/', only: [:show], constraints: { format: :html }
end
resources :topics, only: [:index, :show], constraints: { format: :html }
get :terms, to: 'pages#terms'
get :privacy, to: 'pages#privacy'
get :disclaimer, to: 'pages#disclaimer'
get :cookies, to: 'pages#cookies'

# Redirect old routes.
# Legacy routes (redirect only).
get '/videos/:topic/:playlist/episodio/:video' => redirect('/series/%{playlist}/%{video}')
get '/videos/:topic/:playlist' => redirect('/series/%{playlist}')
get '/videos/:playlist' => redirect('/series/%{playlist}')
Expand Down
20 changes: 20 additions & 0 deletions spec/features/dashboard/dashboard_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'rails_helper'

RSpec.feature "Dashboard", type: :feature do
before { Capybara.default_host = "http://dashboard.example.com" }
after { Capybara.default_host = "http://www.example.com" }

context "when not logged in" do
it "should not be success" do
visit dashboard_path
expect(page.current_path).not_to eq dashboard_topics_path
end
end

context "when logged in" do
it "should be success" do
visit dashboard_path
expect(page.status_code).to eq 200
end
end
end
3 changes: 3 additions & 0 deletions spec/features/dashboard/opinions_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'rails_helper'

RSpec.feature "Dashboard opinions", type: :feature do
before { Capybara.default_host = "http://dashboard.example.com" }
after { Capybara.default_host = "http://www.example.com" }

context "when not logged in" do
it "should not be success" do
visit dashboard_opinions_path
Expand Down
3 changes: 3 additions & 0 deletions spec/features/dashboard/playlist_videos_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'rails_helper'

RSpec.feature "Dashboard playlist videos", type: :feature do
before { Capybara.default_host = "http://dashboard.example.com" }
after { Capybara.default_host = "http://www.example.com" }

before(:each) {
@playlist = FactoryGirl.create(:playlist)
@videos = [
Expand Down
3 changes: 3 additions & 0 deletions spec/features/dashboard/playlists_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'rails_helper'

RSpec.feature "Dashboard playlists", type: :feature do
before { Capybara.default_host = "http://dashboard.example.com" }
after { Capybara.default_host = "http://www.example.com" }

context "when not logged in" do
it "should not be success" do
visit dashboard_playlists_path
Expand Down
3 changes: 3 additions & 0 deletions spec/features/dashboard/topics_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'rails_helper'

RSpec.feature "Dashboard topics", type: :feature do
before { Capybara.default_host = "http://dashboard.example.com" }
after { Capybara.default_host = "http://www.example.com" }

context "when not logged in" do
it "should not be success" do
visit dashboard_topics_path
Expand Down
5 changes: 5 additions & 0 deletions spec/features/dashboard/videos_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'rails_helper'

RSpec.feature "Dashboard videos", type: :feature do
before { Capybara.default_host = "http://dashboard.example.com" }
after { Capybara.default_host = "http://www.example.com" }

context "when not logged in" do
it "should not be success" do
visit dashboard_videos_path
Expand Down Expand Up @@ -59,6 +62,8 @@
click_button 'Crear Vídeo'
}.to change { Video.count }.by 1

# Test the video does not appear
Capybara.default_host = "http://www.example.com"
visit root_path
within '.recent-videos' do
expect(page).not_to have_link 'My video title'
Expand Down

0 comments on commit 5557fff

Please sign in to comment.