From 92750a4a2b8b75972bf28cb1074750ac21eb2a7d Mon Sep 17 00:00:00 2001 From: Abhay Rana Date: Thu, 2 Feb 2017 02:12:49 +0530 Subject: [PATCH] Adds domain support to OSEM - This is a very basic support. All it affects is the listings on the homepage. Every conference can set a domain, and as long as the request host matches this domain, the conference will be shown on the list - If a conference does not have a domain set (which will be the case for older conferences), such conferences are shown always - Conference creation and edits now have an optional domain field - Also adds corresponding migrations (+index) --- app/controllers/admin/conferences_controller.rb | 2 +- app/controllers/application_controller.rb | 3 ++- app/controllers/conferences_controller.rb | 3 ++- app/models/conference.rb | 4 ++++ app/views/admin/conferences/edit.html.haml | 1 + app/views/admin/conferences/new.html.haml | 1 + db/migrate/20170201193336_add_domain_to_conferences.rb | 6 ++++++ db/schema.rb | 5 ++++- 8 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20170201193336_add_domain_to_conferences.rb diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index b7063e6e..c768d6ee 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -176,7 +176,7 @@ module Admin private def conference_params - params.require(:conference).permit(:title, :short_title, :description, :timezone, + params.require(:conference).permit(:title, :short_title, :description, :timezone, :domain, :start_date, :end_date, :rooms_attributes, :tracks_attributes, :tickets_attributes, :event_types_attributes, :picture, :picture_cache, :questions_attributes, diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9646b86c..1dbda21e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -37,7 +37,8 @@ class ApplicationController < ActionController::Base end def get_conferences - @conferences =Conference.all + domain = request.host + @conferences = Conference.get_conferences_to_list(domain, 0) end def current_ability diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index 53e5bd6d..13e889e6 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -5,7 +5,8 @@ class ConferencesController < ApplicationController load_resource :program, through: :conference, singleton: true, except: :index def index - @current = Conference.where('end_date >= ?', Date.current).reorder(start_date: :asc) + domain = request.host + @current = Conference.get_conferences_to_list domain @antiquated = @conferences - @current end diff --git a/app/models/conference.rb b/app/models/conference.rb index 31c61d73..3c253f61 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -499,6 +499,10 @@ class Conference < ActiveRecord::Base result - active_conferences end + def self.get_conferences_to_list(domain, end_date = Date.current) + return Conference.where('end_date >= ? AND (domain = ? OR domain IS NULL)', end_date, domain).reorder(start_date: :asc) + end + ## # A list with the three event states submitted, confirmed, unconfirmed with corresponding colors # diff --git a/app/views/admin/conferences/edit.html.haml b/app/views/admin/conferences/edit.html.haml index dfc6d72a..5640425e 100644 --- a/app/views/admin/conferences/edit.html.haml +++ b/app/views/admin/conferences/edit.html.haml @@ -9,6 +9,7 @@ = semantic_form_for(@conference, :url => admin_conference_path(@conference.short_title),:html => {:multipart => true}) do |f| = f.input :title, :hint => "The full title of the conference, e.g. 'openSUSE Conference 2014'" = f.input :short_title, :hint => "A short title, e.g. 'oSC14', to be used in URLs" + = f.input :domain, hint: "Optional domain on which the conference will be visible. This only affects the conference listings." = f.input :description, hint: markdown_hint('A description of the conference.'), input_html: { rows: 5, data: { provide: 'markdown-editable' } } = f.input :color, :hint => "The color will be used eg for the dashboard.", :input_html => {:size => 6, :type => "color"} = f.label 'Conference Logo' diff --git a/app/views/admin/conferences/new.html.haml b/app/views/admin/conferences/new.html.haml index 80307e4f..907c0f63 100644 --- a/app/views/admin/conferences/new.html.haml +++ b/app/views/admin/conferences/new.html.haml @@ -6,6 +6,7 @@ input_html: { required: 'required' } = f.input :short_title, hint: "A short and unique handle for your conference, using only lower-case letters, numbers and underscores. This will be used to identify your conference in URLs etc. Example: 'froscon2011'", input_html: { required: 'required' } + = f.input :domain, hint: "Optional domain on which the conference will be visible. This only affects the conference listings." = f.inputs 'Scheduling' do = f.input :timezone, as: :time_zone, default: Time.zone.name, hint: 'Please select in what time zone your conference will take place.' = f.input :start_date, as: :string, input_html: { id: 'conference-start-datepicker', required: 'required' } diff --git a/db/migrate/20170201193336_add_domain_to_conferences.rb b/db/migrate/20170201193336_add_domain_to_conferences.rb new file mode 100644 index 00000000..458f9f03 --- /dev/null +++ b/db/migrate/20170201193336_add_domain_to_conferences.rb @@ -0,0 +1,6 @@ +class AddDomainToConferences < ActiveRecord::Migration + def change + add_column :conferences, :domain, :string + add_index :conferences, [:domain] + end +end diff --git a/db/schema.rb b/db/schema.rb index 7da98fe3..96c86660 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160815140302) do +ActiveRecord::Schema.define(version: 20170201193336) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -98,8 +98,11 @@ ActiveRecord::Schema.define(version: 20160815140302) do t.text "description" t.integer "registration_limit", default: 0 t.string "picture" + t.string "domain" end + add_index "conferences", ["domain"], name: "index_conferences_on_domain" + create_table "conferences_questions", id: false, force: :cascade do |t| t.integer "conference_id" t.integer "question_id"