This commit is contained in:
Shlok Srivastava 2017-08-10 06:09:24 +00:00 committed by GitHub
commit 304339f9fc
15 changed files with 240 additions and 7 deletions

View file

@ -30,6 +30,8 @@ linters:
- "app/views/admin/conferences/_targets.html.haml"
- "app/views/admin/conferences/_todo_list.html.haml"
- "app/views/admin/conferences/_top_submitter.html.haml"
- "app/views/admin/conferences/attach_custom_domain.html.haml"
- "app/views/admin/conferences/custom_domain.html.haml"
- "app/views/admin/conferences/edit.html.haml"
- "app/views/admin/conferences/index.html.haml"
- "app/views/admin/conferences/new.html.haml"

View file

@ -4,6 +4,23 @@ module Admin
load_resource :program, through: :conference, singleton: true, except: :index
load_resource :user, only: [:remove_user]
def custom_domain
redirect_to attach_custom_domain_admin_conference_path(@conference.short_title) unless @conference.custom_domain.present?
end
def attach_custom_domain; end
def update_domain
@conference.assign_attributes(conference_params)
if @conference.save
redirect_to custom_domain_admin_conference_path(id: @conference.short_title),
notice: 'Added new domain name to conference. This does not mean that the new domain should work. Please make sure you follow step 2 to point your domain to this hosted version'
else
redirect_to custom_domain_admin_conference_path(id: @conference.short_title),
notice: 'Failed to add the new domain as custom domain to the conference'
end
end
def index
# Redirect to new form if there is no conference
if Conference.count == 0
@ -211,7 +228,7 @@ module Admin
:vpositions_attributes, :use_volunteers, :color,
:sponsorship_levels_attributes, :sponsors_attributes,
:targets, :targets_attributes,
:campaigns, :campaigns_attributes, :registration_limit, :organization_id, :ticket_layout)
:campaigns, :campaigns_attributes, :registration_limit, :organization_id, :ticket_layout, :custom_domain)
end
end
end

View file

@ -1,18 +1,29 @@
class ConferencesController < ApplicationController
protect_from_forgery with: :null_session
before_action :respond_to_options
load_and_authorize_resource find_by: :short_title
load_resource :program, through: :conference, singleton: true, except: :index
load_and_authorize_resource find_by: :short_title, except: :show
def index
@current = Conference.where('end_date >= ?', Date.current).reorder(start_date: :asc)
@antiquated = @conferences - @current
end
def show; end
def show
@conference = if params[:id]
Conference.find_by(short_title: params[:id])
else
load_conference_by_domain
end
authorize! :show, @conference
@program = @conference.program
end
private
def load_conference_by_domain
Conference.find_by(custom_domain: request.domain)
end
def respond_to_options
respond_to do |format|
format.html { head :ok }

View file

@ -109,7 +109,7 @@ class AdminAbility
track_ids = Track.joins(:program).where('programs.conference_id IN (?)', conf_ids).pluck(:id)
can :manage, Resource, conference_id: conf_ids
can [:read, :update, :destroy], Conference, id: conf_ids
can [:read, :update, :destroy, :custom_domin], Conference, id: conf_ids
can :manage, Splashpage, conference_id: conf_ids
can :manage, Contact, conference_id: conf_ids
can :manage, EmailSettings, conference_id: conf_ids

View file

@ -92,6 +92,28 @@ class Conference < ActiveRecord::Base
user.present? && registrations.where(user_id: user.id).count > 0
end
##
# Checks if domain correctly points to the hosted version
# This feature is enabled only if ENV['OSEM_HOSTNAME'] is present
#
# ====Returns
# * +true+ -> If the custom domain has a CNAME record for the hosted version
# * +false+ -> If the custom domain does not have a CNAME record for the hosted version
def check_custom_domain
require 'resolv'
unless ENV['OSEM_HOSTNAME'].nil?
cname_record = Resolv::DNS.new.getresources(custom_domain, Resolv::DNS::Resource::IN::CNAME)
if cname_record.present?
return ENV['OSEM_HOSTNAME'] == Resolv::DNS.new.getresources(custom_domain, Resolv::DNS::Resource::IN::CNAME).first.name.to_s
else
return false
end
end
'--feature disabled--'
end
##
# Delete all EventSchedules that are not in the hours range
# After the conference has been successfully updated

View file

@ -0,0 +1,41 @@
.row
.col-md-12
%h1
Custom Domain
%p.text-muted
Point your own domain to #{@conference.title}
%hr
.row
.col-md-12
%h2
Step 1:
%strong
Unfortunately, we can't do this for you and you have to perform this step with the help your domain registrar!
%p
Pick a domain you want to host your conference on from a domain registrar or register it with a domain registrar.
%h2
Step 2:
%p
Enter your existing domain in the field below to point the domain to your conference splashpage.
= semantic_form_for(@conference, url: update_domain_admin_conference_path(@conference.short_title)) do |f|
= f.input :custom_domain, label: false
= f.action :submit, button_html: { class: 'btn btn-primary', value: 'Attach this domain' }
%h2
Step 3:
%strong
Unfortunately, we can't do this for you and you have to perform this step with the help your domain registrar!
%p
The last step is adding a CNAME record in your registrars DNS Settings. Different registrars have different ways of adding a CNAME record. The following guides would help you setup a CNAME record depending upon the registrar of your domain. If it doesnt, you probably should get in touch with your domain registrar and ask him how to register a CNAME record in their platform.
%ul
%li
= link_to 'GoDaddy', 'https://in.godaddy.com/help/add-a-cname-record-19236'
%li
= link_to 'Namecheap', 'https://www.namecheap.com/support/knowledgebase/article.aspx/9646/2237/how-can-i-set-up-a-cname-record-for-my-domain'
%li
= link_to 'BlueHost', 'https://my.bluehost.com/cgi/help/cname#creating_a_cname'
%li
= link_to '12-reg.co.uk', 'https://www.123-reg.co.uk/support/answers/Domains/Domain-Configuration/how-do-i-set-up-a-cname-record-on-my-domain-name-1198/'
%li
= link_to '1&1', 'https://help.1and1.com/domains-c36931/manage-domains-c79822/dns-c37586/enter-a-cname-for-your-subdomain-a643600.html'
.well.well-lg
It might take upto 24-48 hours depending upon your registrar to update your DNS Settings.

View file

@ -0,0 +1,82 @@
.row
.col-md-12
%h1
Custom domain
%p.text-muted
Point your own domain to #{@conference.title}
%hr
.row
.col-md-12
%table.table
%thead
%th Domain Name
%th Correctly points to #{@conference.short_title}
%th Actions
%tbody
%tr
%td
= @conference.custom_domain
%td
- ck_domain = @conference.check_custom_domain
- if ck_domain == true
%span.glyphicon.glyphicon-ok
- elsif ck_domain == false
%span.glyphicon.glyphicon-remove
- else
%i
= ck_domain
%td
.btn-group
= link_to 'Edit', attach_custom_domain_admin_conference_path(@conference.short_title),
method: :get, class: 'btn btn-primary'
= link_to 'Delete', admin_conference_path(@conference.short_title),
method: :delete, class: 'btn btn-danger'
.row
.col-md-9.text-right
= link_to '#status-help', class: 'btn btn-default', "data-toggle"=>"collapse" do
Help?
.row
.col-md-12
.collapse#status-help
%h2
Instructions to add your own domain
%hr
%p
When you created the conference, the conference splash page is available in the following domain:
%strong
osem.io/conferences/#{@conference.short_title}
%p
However, we also provide support for hosting conferences on your own domain.
Terms to get familiar with:
%p
%strong
Domain registrar:
Domain registrar is just another term used for providers who work on reserving domain names.
%p
%strong
CNAME:
A Canonical Name record is a resource used which defines that your domain name is an alias for another domain name.
%p
To add your own domain you can follow these
%i
three
steps:
%ol
%li
Pick a domain you want to host your conference on from a domain registrar or register it with a domain registrar.
%li
Add your own domain name to OSEM ( link to conference/custom_domain#create ) and select the conference it should belong to.
%li
The last step is adding a CNAME record in your registrars DNS Settings. Different registrars have different ways of adding a CNAME record. The following guides would help you setup a CNAME record depending upon the registrar of your domain. If it doesnt, you probably should get in touch with your domain registrar and ask him how to register a CNAME record in their platform.
%ul
%li
= link_to 'GoDaddy', 'https://in.godaddy.com/help/add-a-cname-record-19236'
%li
= link_to 'Namecheap', 'https://www.namecheap.com/support/knowledgebase/article.aspx/9646/2237/how-can-i-set-up-a-cname-record-for-my-domain'
%li
= link_to 'BlueHost', 'https://my.bluehost.com/cgi/help/cname#creating_a_cname'
%li
= link_to '12-reg.co.uk', 'https://www.123-reg.co.uk/support/answers/Domains/Domain-Configuration/how-do-i-set-up-a-cname-record-on-my-domain-name-1198/'
%li
= link_to '1&1', 'https://help.1and1.com/domains-c36931/manage-domains-c79822/dns-c37586/enter-a-cname-for-your-subdomain-a643600.html'

View file

@ -27,6 +27,11 @@
= link_to(admin_conference_path(@conference.short_title)) do
%span.fa.fa-tachometer
Dashboard
- if can? :edit, @conference
%li
= link_to(custom_domain_admin_conference_path(@conference.short_title)) do
%span.fa.fa-link
Custom domain
- if can? :show, @conference
%li{class: "#{active_nav_li(edit_admin_conference_path(@conference.short_title))}"}
- if can? :edit, @conference

View file

@ -0,0 +1,6 @@
class DomainConstraint
def self.matches?(request)
domains = Conference.where.not(custom_domain: nil).pluck(:custom_domain)
domains.include?(request.domain)
end
end

View file

@ -1,5 +1,9 @@
Osem::Application.routes.draw do
constraints DomainConstraint do
get '/', to: 'conferences#show'
end
if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
devise_for :users, controllers: { registrations: :registrations }
else
@ -28,6 +32,11 @@ Osem::Application.routes.draw do
end
resources :comments, only: [:index]
resources :conferences do
member do
get :custom_domain
get :attach_custom_domain
patch :update_domain
end
resource :contact, except: [:index, :new, :create, :show, :destroy]
resources :schedules, only: [:index, :create, :show, :update, :destroy]
resources :event_schedules, only: [:create, :update, :destroy]

View file

@ -0,0 +1,5 @@
class AddCustomDomainToConferences < ActiveRecord::Migration
def change
add_column :conferences, :custom_domain, :string
end
end

View file

@ -11,10 +11,10 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170721001700) do
ActiveRecord::Schema.define(version: 20170721184810) do
create_table "ahoy_events", force: :cascade do |t|
t.integer "visit_id"
t.uuid "visit_id", limit: 16
t.integer "user_id"
t.string "name"
t.text "properties"
@ -127,6 +127,7 @@ ActiveRecord::Schema.define(version: 20170721001700) do
t.integer "end_hour", default: 20
t.integer "organization_id"
t.integer "ticket_layout", default: 0
t.string "custom_domain"
end
add_index "conferences", ["organization_id"], name: "index_conferences_on_organization_id"

View file

@ -135,6 +135,15 @@ describe Admin::ConferencesController do
end
end
end
describe 'GET #custom_domain', blah: true do
it 'render custom domain' do
get :custom_domain, id: conference.short_title
expect(response).to render_template :custom_domain
expect(response).to be_success
end
end
end
shared_examples 'access as organization_admin' do

View file

@ -24,6 +24,20 @@ describe ConferencesController do
expect(response).to render_template :show
end
end
context 'accessing conference via custom domain' do
before do
conference.update_attribute(:custom_domain, 'lvh.me')
@request.host = 'lvh.me'
end
it 'assigns correct conference' do
get :show
expect(response).to render_template :show
expect(assigns(:conference)).to eq conference
end
end
end
describe 'OPTIONS #index' do

View file

@ -68,6 +68,15 @@ feature Conference do
expect(conference.short_title).to eq('NewCon')
expect(Conference.count).to eq(expected_count)
end
scenario 'show custom domain of a conference', feature: true, js: true do
conference = create(:conference, custom_domain: 'mydomain.conf')
sign_in user
visit custom_domain_admin_conference_path(conference.short_title)
expect(page).to have_text('mydomain.conf')
end
end
describe 'admin' do