diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index 84a6cb79..ef8a3913 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -22,7 +22,7 @@ linters: - "app/views/admin/comments/_posted_comments.html.haml" - "app/views/admin/comments/_unread_comments.html.haml" - "app/views/admin/commercials/index.html.haml" - - "app/views/admin/conference_domains/edit.haml" + - "app/views/admin/conference_domains/_form.haml" - "app/views/admin/conference_domains/show.haml" - "app/views/admin/conferences/_campaigns.html.haml" - "app/views/admin/conferences/_doughnut_chart.html.haml" diff --git a/app/controllers/admin/conference_domains_controller.rb b/app/controllers/admin/conference_domains_controller.rb index 40785c14..61a5ecca 100644 --- a/app/controllers/admin/conference_domains_controller.rb +++ b/app/controllers/admin/conference_domains_controller.rb @@ -1,26 +1,43 @@ module Admin class ConferenceDomainsController < Admin::BaseController - load_and_authorize_resource :conference, find_by: :short_title + load_resource :conference, find_by: :short_title + + def new + # To only allow organizers, organization admin and site administrators + authorize! :update, @conference + end def show # To only allow organizers, organization admin and site administrators authorize! :update, @conference - redirect_to admin_conference_conference_domains_edit_path(@conference.short_title) unless @conference.custom_domain.present? + redirect_to new_admin_conference_domain_path(@conference.short_title) unless @conference.custom_domain.present? end def edit - authorize! :edit, @conference + authorize! :update, @conference end def update authorize! :update, @conference @conference.assign_attributes(conference_params) if @conference.save - redirect_to admin_conference_conference_domain_path(@conference.short_title), + redirect_to admin_conference_domain_path(@conference.short_title), notice: 'Attached new domain name to conference. This does not mean that the new domain should work. Please make sure you follow step 3 to point your domain to this hosted version' else - redirect_to admin_conference_conference_domains_edit_path(@conference.short_title), - notice: 'Failed to add the new domain as custom domain to the conference' + redirect_to edit_admin_conference_domain_path(@conference.short_title), + error: 'Failed to add the new domain as custom domain to the conference' + end + end + + def destroy + authorize! :update, @conference + @conference.custom_domain = nil + if @conference.save + redirect_to new_admin_conference_domain_path(@conference.short_title), + notice: 'Custom domain successfully removed from conference' + else + redirect_to admin_conference_domain_path(@conference.short_title), + error: 'Failed o remove custom domain from the conference' end end diff --git a/app/views/admin/conference_domains/_form.haml b/app/views/admin/conference_domains/_form.haml new file mode 100644 index 00000000..5d255470 --- /dev/null +++ b/app/views/admin/conference_domains/_form.haml @@ -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: admin_conference_domain_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 registrar’s 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 doesn’t, 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. diff --git a/app/views/admin/conference_domains/edit.haml b/app/views/admin/conference_domains/edit.haml index 002b78a1..68fab10f 100644 --- a/app/views/admin/conference_domains/edit.haml +++ b/app/views/admin/conference_domains/edit.haml @@ -1,41 +1 @@ -.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: admin_conference_conference_domain_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 registrar’s 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 doesn’t, 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. += render 'form', conference: @conference diff --git a/app/views/admin/conference_domains/new.haml b/app/views/admin/conference_domains/new.haml new file mode 100644 index 00000000..68fab10f --- /dev/null +++ b/app/views/admin/conference_domains/new.haml @@ -0,0 +1 @@ += render 'form', conference: @conference diff --git a/app/views/admin/conference_domains/show.haml b/app/views/admin/conference_domains/show.haml index 304c09de..f95376f0 100644 --- a/app/views/admin/conference_domains/show.haml +++ b/app/views/admin/conference_domains/show.haml @@ -31,9 +31,9 @@ feature disabled %td .btn-group - = link_to 'Edit', admin_conference_conference_domains_edit_path(@conference.short_title), + = link_to 'Edit', edit_admin_conference_domain_path(@conference.short_title), method: :get, class: 'btn btn-primary' - = link_to 'Delete', admin_conference_path(@conference.short_title), + = link_to 'Delete', admin_conference_domain_path(@conference.short_title), method: :delete, class: 'btn btn-danger' .row .col-md-9.text-right @@ -66,25 +66,30 @@ %i three steps: - %ol + %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 + Attach your existing domain to your conference by adding it in the new/edit domain name page of your conference. That domain name will point to the splashpage of your conference after completion of all steps. + %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 registrar’s 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 doesn’t, you probably should get in touch with your domain registrar and ask him how to register a CNAME record in their platform. + %ul %li - Pick a domain you want to host your conference on from a domain registrar or register it with a domain registrar. + = link_to 'GoDaddy', 'https://in.godaddy.com/help/add-a-cname-record-19236' %li - Add your own domain name to OSEM - = link_to 'here', admin_conference_conference_domains_edit_path(@conference.short_title) + = 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 - The last step is adding a CNAME record in your registrar’s 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 doesn’t, 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' + = 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' diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index 60b036d2..e67cdb1d 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -29,7 +29,7 @@ Dashboard - if can? :edit, @conference %li - = link_to(admin_conference_conference_domain_path(@conference.short_title)) do + = link_to(admin_conference_domain_path(@conference.short_title)) do %span.fa.fa-link Custom domain - if can? :show, @conference diff --git a/config/routes.rb b/config/routes.rb index e759d9ea..fd6065f6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -32,10 +32,7 @@ Osem::Application.routes.draw do end resources :comments, only: [:index] resources :conferences do - get 'conference_domains/edit' => 'conference_domains#edit' - get 'conference_domain' => 'conference_domains#show' - patch 'conference_domain' => 'conference_domains#update' - + resource :domain, controller: 'conference_domains' resource :contact, except: [:index, :new, :create, :show, :destroy] resources :schedules, only: [:index, :create, :show, :update, :destroy] resources :event_schedules, only: [:create, :update, :destroy] diff --git a/spec/controllers/admin/conference_domains_controller_spec.rb b/spec/controllers/admin/conference_domains_controller_spec.rb index 2469559b..a5fc68ea 100644 --- a/spec/controllers/admin/conference_domains_controller_spec.rb +++ b/spec/controllers/admin/conference_domains_controller_spec.rb @@ -11,7 +11,7 @@ describe Admin::ConferenceDomainsController do describe 'GET #show' do it 'redirects to edit if custom domain is not present' do get :show, conference_id: conference.short_title - expect(response).to redirect_to(admin_conference_conference_domains_edit_path) + expect(response).to redirect_to(edit_admin_conference_domain_path) end it 'renders correct template if custom domain is present' do diff --git a/spec/features/conference_domains_spec.rb b/spec/features/conference_domains_spec.rb index 97a0e7a0..42adc724 100644 --- a/spec/features/conference_domains_spec.rb +++ b/spec/features/conference_domains_spec.rb @@ -15,7 +15,7 @@ feature Conference do shared_examples 'successfully adds, update or show custom domain' do scenario 'adds or update custom domain of a conference', feature: true, js: true do - visit admin_conference_conference_domains_edit_path(conference.short_title) + visit edit_admin_conference_domain_path(conference.short_title) fill_in 'conference_custom_domain', with: 'newdomain.conf' click_button 'Attach this domain' @@ -25,7 +25,7 @@ feature Conference do end scenario 'show custom domain of a conference', feature: true, js: true do - visit admin_conference_conference_domain_path(conference.short_title) + visit admin_conference_domain_path(conference.short_title) expect(page).to have_text('mydomain.conf') end @@ -33,13 +33,13 @@ feature Conference do shared_examples 'does not add, update or show custom domain' do scenario 'does not add or update custom domain', feature: true, js: true do - visit admin_conference_conference_domains_edit_path(conference.short_title) + visit edit_admin_conference_domain_path(conference.short_title) expect(flash).to eq 'You are not authorized to access this page.' end scenario 'does not show custom domain of a conference', feature: true, js: true do - visit admin_conference_conference_domain_path(conference.short_title) + visit admin_conference_domain_path(conference.short_title) expect(flash).to eq 'You are not authorized to access this page.' end