From 1ba797bead3bd3c9daaad7fd1f69d9601428d38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A1n=20Schmidt?= Date: Sat, 8 Jul 2017 18:45:38 +0200 Subject: [PATCH 01/24] Fix schema.rb In #1570, db/schema.rb got broken, as the version was not updated. --- db/schema.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 4a9cc724..6608495b 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: 20170629162450) do +ActiveRecord::Schema.define(version: 20170629232817) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From 9c6286182ef8c9b33f6a170e2b2cf989eb71f4ef Mon Sep 17 00:00:00 2001 From: shlok007 Date: Thu, 29 Dec 2016 03:17:33 -0500 Subject: [PATCH 02/24] caching comment counts --- app/models/comment.rb | 2 +- app/views/admin/events/index.html.haml | 2 +- ...1229080315_add_comments_count_to_events.rb | 10 ++++++++ db/schema.rb | 1 + spec/models/event_spec.rb | 23 +++++++++++++++++++ 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20161229080315_add_comments_count_to_events.rb diff --git a/app/models/comment.rb b/app/models/comment.rb index 947b2f54..4bb90719 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -8,7 +8,7 @@ class Comment < ActiveRecord::Base # want user to vote on the quality of comments. #acts_as_votable - belongs_to :commentable, polymorphic: true + belongs_to :commentable, counter_cache: true, polymorphic: true # NOTE: Comments belong to a user belongs_to :user diff --git a/app/views/admin/events/index.html.haml b/app/views/admin/events/index.html.haml index 0e204c87..50d7acd5 100644 --- a/app/views/admin/events/index.html.haml +++ b/app/views/admin/events/index.html.haml @@ -184,4 +184,4 @@ %ul.dropdown-menu{ role: 'menu' } = render 'change_state_dropdown', event: event %td.text-center - = link_to "#{event.comment_threads.count}", admin_conference_program_event_path(@conference.short_title, event), anchor: 'comments-div' + = link_to "#{event.comments_count}", admin_conference_program_event_path(@conference.short_title, event), anchor: 'comments-div' diff --git a/db/migrate/20161229080315_add_comments_count_to_events.rb b/db/migrate/20161229080315_add_comments_count_to_events.rb new file mode 100644 index 00000000..e1d6ebec --- /dev/null +++ b/db/migrate/20161229080315_add_comments_count_to_events.rb @@ -0,0 +1,10 @@ +class AddCommentsCountToEvents < ActiveRecord::Migration + def change + add_column :events, :comments_count, :integer, default: 0, null: false + + Event.find_each do |event| + comments_count = event.comment_threads.count + event.update_attribute(:comments_count, comments_count) unless comments_count.zero? + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 6608495b..9f0f9ff5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -242,6 +242,7 @@ ActiveRecord::Schema.define(version: 20170629232817) do t.boolean "is_highlight", default: false t.integer "program_id" t.integer "max_attendees" + t.integer "comments_count", default: 0, null: false end create_table "events_registrations", force: :cascade do |t| diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index e1c2297c..b723d151 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -98,6 +98,29 @@ describe Event do end end + describe '#comments_count' do + context 'has a valid counter cache' do + before do + create(:comment, commentable: event) + end + + it 'successfully increments comments_count' do + expected = expect do + create(:comment, commentable: event) + end + expected.to change { event.comments_count }.by(1) + end + + it 'successfully decrements comments_count' do + expected = expect do + event.comment_threads.last.destroy + event.reload + end + expected.to change { event.comments_count }.by(-1) + end + end + end + describe 'scope ' do context 'confirmed' do it 'returns only confirmed events' do From 518ecc3d4ef53a95a8ac52e66f0e5f9879f0579f Mon Sep 17 00:00:00 2001 From: shlok007 Date: Sun, 9 Jul 2017 01:29:15 +0530 Subject: [PATCH 03/24] rebuild schema.rb for sqlite3 --- db/schema.rb | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 9f0f9ff5..7a640259 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -13,20 +13,17 @@ ActiveRecord::Schema.define(version: 20170629232817) do - # These are extensions that must be enabled in order to support this database - enable_extension "plpgsql" - 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" t.datetime "time" end - add_index "ahoy_events", ["time"], name: "index_ahoy_events_on_time", using: :btree - add_index "ahoy_events", ["user_id"], name: "index_ahoy_events_on_user_id", using: :btree - add_index "ahoy_events", ["visit_id"], name: "index_ahoy_events_on_visit_id", using: :btree + add_index "ahoy_events", ["time"], name: "index_ahoy_events_on_time" + add_index "ahoy_events", ["user_id"], name: "index_ahoy_events_on_user_id" + add_index "ahoy_events", ["visit_id"], name: "index_ahoy_events_on_visit_id" create_table "answers", force: :cascade do |t| t.string "title" @@ -69,9 +66,9 @@ ActiveRecord::Schema.define(version: 20170629232817) do t.integer "rgt" end - add_index "comments", ["commentable_id"], name: "index_comments_on_commentable_id", using: :btree - add_index "comments", ["commentable_type"], name: "index_comments_on_commentable_type", using: :btree - add_index "comments", ["user_id"], name: "index_comments_on_user_id", using: :btree + add_index "comments", ["commentable_id"], name: "index_comments_on_commentable_id" + add_index "comments", ["commentable_type"], name: "index_comments_on_commentable_type" + add_index "comments", ["user_id"], name: "index_comments_on_user_id" create_table "commercials", force: :cascade do |t| t.string "commercial_id" @@ -142,7 +139,7 @@ ActiveRecord::Schema.define(version: 20170629232817) do t.datetime "updated_at" end - add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree + add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority" create_table "difficulty_levels", force: :cascade do |t| t.string "title" @@ -195,10 +192,10 @@ ActiveRecord::Schema.define(version: 20170629232817) do t.datetime "updated_at", null: false end - add_index "event_schedules", ["event_id", "schedule_id"], name: "index_event_schedules_on_event_id_and_schedule_id", unique: true, using: :btree - add_index "event_schedules", ["event_id"], name: "index_event_schedules_on_event_id", using: :btree - add_index "event_schedules", ["room_id"], name: "index_event_schedules_on_room_id", using: :btree - add_index "event_schedules", ["schedule_id"], name: "index_event_schedules_on_schedule_id", using: :btree + add_index "event_schedules", ["event_id", "schedule_id"], name: "index_event_schedules_on_event_id_and_schedule_id", unique: true + add_index "event_schedules", ["event_id"], name: "index_event_schedules_on_event_id" + add_index "event_schedules", ["room_id"], name: "index_event_schedules_on_room_id" + add_index "event_schedules", ["schedule_id"], name: "index_event_schedules_on_schedule_id" create_table "event_types", force: :cascade do |t| t.string "title", null: false @@ -313,7 +310,7 @@ ActiveRecord::Schema.define(version: 20170629232817) do t.integer "schedule_interval", default: 15, null: false end - add_index "programs", ["selected_schedule_id"], name: "index_programs_on_selected_schedule_id", using: :btree + add_index "programs", ["selected_schedule_id"], name: "index_programs_on_selected_schedule_id" create_table "qanswers", force: :cascade do |t| t.integer "question_id" @@ -385,8 +382,8 @@ ActiveRecord::Schema.define(version: 20170629232817) do t.string "resource_type" end - add_index "roles", ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id", using: :btree - add_index "roles", ["name"], name: "index_roles_on_name", using: :btree + add_index "roles", ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id" + add_index "roles", ["name"], name: "index_roles_on_name" create_table "rooms", force: :cascade do |t| t.string "guid", null: false @@ -401,7 +398,7 @@ ActiveRecord::Schema.define(version: 20170629232817) do t.datetime "updated_at", null: false end - add_index "schedules", ["program_id"], name: "index_schedules_on_program_id", using: :btree + add_index "schedules", ["program_id"], name: "index_schedules_on_program_id" create_table "splashpages", force: :cascade do |t| t.integer "conference_id" @@ -525,17 +522,17 @@ ActiveRecord::Schema.define(version: 20170629232817) do t.boolean "is_disabled", default: false end - add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree - add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree - add_index "users", ["username"], name: "index_users_on_username", unique: true, using: :btree + add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true + add_index "users", ["email"], name: "index_users_on_email", unique: true + add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + add_index "users", ["username"], name: "index_users_on_username", unique: true create_table "users_roles", force: :cascade do |t| t.integer "role_id" t.integer "user_id" end - add_index "users_roles", ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id", using: :btree + add_index "users_roles", ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id" create_table "vchoices", force: :cascade do |t| t.integer "vday_id" @@ -579,10 +576,10 @@ ActiveRecord::Schema.define(version: 20170629232817) do t.integer "conference_id" end - add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id", using: :btree + add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id" create_table "visits", force: :cascade do |t| - t.uuid "visitor_id" + t.uuid "visitor_id", limit: 16 t.string "ip" t.text "user_agent" t.text "referrer" @@ -604,7 +601,7 @@ ActiveRecord::Schema.define(version: 20170629232817) do t.datetime "started_at" end - add_index "visits", ["user_id"], name: "index_visits_on_user_id", using: :btree + add_index "visits", ["user_id"], name: "index_visits_on_user_id" create_table "votes", force: :cascade do |t| t.integer "event_id" From b33e9ed28ee444f45e5bac2f9e1761fe896784ea Mon Sep 17 00:00:00 2001 From: shlok007 Date: Wed, 4 Jan 2017 22:27:46 -0500 Subject: [PATCH 04/24] fix revision count and drop observers --- Gemfile | 3 --- Gemfile.lock | 3 --- app/models/concerns/revision_count.rb | 11 ++++++++ app/models/conference.rb | 10 +++++++ app/models/event.rb | 5 ++++ app/models/revision_observer.rb | 26 ------------------ app/models/room.rb | 5 ++++ app/models/track.rb | 5 ++++ config/application.rb | 1 - ...1_add_default_to_revision_in_conference.rb | 5 ++++ db/schema.rb | 2 +- spec/models/conference_spec.rb | 27 +++++++++++++++++++ 12 files changed, 69 insertions(+), 34 deletions(-) create mode 100644 app/models/concerns/revision_count.rb delete mode 100644 app/models/revision_observer.rb create mode 100644 db/migrate/20170108053041_add_default_to_revision_in_conference.rb diff --git a/Gemfile b/Gemfile index e6245e78..1af89f34 100644 --- a/Gemfile +++ b/Gemfile @@ -22,9 +22,6 @@ gem 'responders', '~> 2.0' gem 'mysql2' # gem 'pg' -# for observing records -gem 'rails-observers' - # for tracking data changes gem 'paper_trail' diff --git a/Gemfile.lock b/Gemfile.lock index 89d52471..9ea214c2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -399,8 +399,6 @@ GEM rails-i18n (4.0.8) i18n (~> 0.7) railties (~> 4.0) - rails-observers (0.1.2) - activemodel (~> 4.0) rails_12factor (0.0.3) rails_serve_static_assets rails_stdout_logging @@ -632,7 +630,6 @@ DEPENDENCIES rails-assets-trianglify! rails-assets-waypoints! rails-i18n (~> 4.0.0) - rails-observers rails_12factor rdoc-generator-fivefish redcarpet diff --git a/app/models/concerns/revision_count.rb b/app/models/concerns/revision_count.rb new file mode 100644 index 00000000..71789f34 --- /dev/null +++ b/app/models/concerns/revision_count.rb @@ -0,0 +1,11 @@ +module RevisionCount + extend ActiveSupport::Concern + + included do + after_update :increment_revision + end + + def increment_revision + conference.update_column(:revision, conference.revision + 1) + end +end diff --git a/app/models/conference.rb b/app/models/conference.rb index cf94b334..69571dc9 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -1,4 +1,5 @@ class Conference < ActiveRecord::Base + include RevisionCount require 'uri' serialize :events_per_week, Hash # Needed to call 'Conference.with_role' in /models/ability.rb @@ -734,6 +735,15 @@ class Conference < ActiveRecord::Base (start_hour..(end_hour - 1)).cover?(current_hour) ? current_hour - start_hour : 0 end + ## + # Return the current conference object to be used in RevisionCount + # + # ====Returns + # * +ActiveRecord+ + def conference + self + end + private # Returns a different html colour for every i and consecutive colors are diff --git a/app/models/event.rb b/app/models/event.rb index f8f9c2d8..8436aac9 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,5 +1,6 @@ class Event < ActiveRecord::Base include ActiveRecord::Transitions + include RevisionCount has_paper_trail on: [:create, :update], ignore: [:updated_at, :guid, :week], meta: { conference_id: :conference_id } acts_as_commentable @@ -251,6 +252,10 @@ class Event < ActiveRecord::Base event_schedules.find_by(schedule_id: program.selected_schedule_id).try(:start_time) end + def conference + program.conference + end + private ## diff --git a/app/models/revision_observer.rb b/app/models/revision_observer.rb deleted file mode 100644 index 4d2784f4..00000000 --- a/app/models/revision_observer.rb +++ /dev/null @@ -1,26 +0,0 @@ -# -# suseconferenceclient relies on a 'revision' attribute for caching and -# doing some calculations. -# -# It should be incremented after any change in the conference or in any -# associated models -# -# This observer updates the revision column in a non-intrusive way, -# preventing validations, callbacks or exceptions to be triggered -# -# Relying on paper_trail could also be an option, but a 'revision' column -# in table 'conferences' looks like a more simple and straightforward solution -# -class RevisionObserver < ActiveRecord::Observer - observe :conference, :event, :room, :track - - def after_save(model) - begin - conference = model.kind_of?(Conference) ? model : model.conference - conference.reload.increment(:revision) - conference.update_column(:revision, conference.revision) - rescue - nil - end - end -end diff --git a/app/models/room.rb b/app/models/room.rb index 1477a2c6..f8150f78 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -1,4 +1,5 @@ class Room < ActiveRecord::Base + include RevisionCount belongs_to :venue has_many :event_schedules, dependent: :destroy @@ -10,6 +11,10 @@ class Room < ActiveRecord::Base validates :size, numericality: { only_integer: true, greater_than: 0 }, allow_nil: true + def conference + venue.conference + end + private def generate_guid diff --git a/app/models/track.rb b/app/models/track.rb index d3502bb0..f65506d8 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -1,4 +1,5 @@ class Track < ActiveRecord::Base + include RevisionCount belongs_to :program has_many :events, dependent: :nullify @@ -16,6 +17,10 @@ class Track < ActiveRecord::Base before_validation :capitalize_color + def conference + program.conference + end + private def generate_guid diff --git a/config/application.rb b/config/application.rb index 9123e5bb..07ba40f3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -25,7 +25,6 @@ module Osem # Activate observers that should always be running. # config.active_record.observers = :cacher, :garbage_collector, :forum_observer - config.active_record.observers = :revision_observer # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. diff --git a/db/migrate/20170108053041_add_default_to_revision_in_conference.rb b/db/migrate/20170108053041_add_default_to_revision_in_conference.rb new file mode 100644 index 00000000..1c3571de --- /dev/null +++ b/db/migrate/20170108053041_add_default_to_revision_in_conference.rb @@ -0,0 +1,5 @@ +class AddDefaultToRevisionInConference < ActiveRecord::Migration + def change + change_column :conferences, :revision, :integer, default: 0, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 7a640259..af227946 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -90,7 +90,7 @@ ActiveRecord::Schema.define(version: 20170629232817) do t.datetime "created_at" t.datetime "updated_at" t.string "logo_file_name" - t.integer "revision" + t.integer "revision", default: 0, null: false t.boolean "use_vpositions", default: false t.boolean "use_vdays", default: false t.boolean "use_volunteers" diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index eaef9293..89863412 100755 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -1660,4 +1660,31 @@ describe Conference do expect{ conference.save }.to change{ EventSchedule.count }.from(2).to(1) end end + + describe '#revision' do + let(:track) { create(:track, program: subject.program) } + let(:event) { create(:event, program: subject.program, track: track) } + let(:venue) { create(:venue, conference: subject) } + let(:room) { create(:room, venue: venue) } + + it 'for change in conference' do + subject.title = 'changed' + expect{ subject.save }.to change { subject.revision }.by(1) + end + + it 'for change in event' do + event.title = 'changed' + expect{ event.save }.to change { subject.revision }.by(1) + end + + it 'for change in track' do + track.name = 'changed' + expect{ track.save }.to change { subject.revision }.by(1) + end + + it 'for change in room' do + room.name = 'changed' + expect{ room.save }.to change { subject.revision }.by(1) + end + end end From f15fe9ddb0cc5422b777d4ef299b043af7e6a75f Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Sat, 25 Mar 2017 22:51:21 +0100 Subject: [PATCH 05/24] Docker support for production use This commit adds a Docker infrastructure that is ready for production use. It is meant to simplify the deployment of OSEM for everyone who wants to host their own instances. It includes many features like data persistence, automatic secret key generation and persistence and automatic database initialization and upgrading. This should make updating the Docker container as easy as possible. --- .dockerignore | 2 ++ Dockerfile | 46 ++++++++++++++++++++++++++++++++++++++ config/database.yml.docker | 7 ++++++ docker-compose.env.example | 38 +++++++++++++++++++++++++++++++ docker-compose.yml.example | 29 ++++++++++++++++++++++++ docker/init.sh | 45 +++++++++++++++++++++++++++++++++++++ 6 files changed, 167 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 config/database.yml.docker create mode 100644 docker-compose.env.example create mode 100644 docker-compose.yml.example create mode 100644 docker/init.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..e235b236 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +Dockerfile +docker-compose.* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..86a6d4d1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,46 @@ +FROM ruby:2.3 + +MAINTAINER TheAssassin + +# required for compiling assets +RUN apt-get update && \ + apt-get install -y nodejs nodejs-legacy mariadb-client + +# used to run the container without root permissions +RUN adduser --home /osem/ --system --group --disabled-login --disabled-password osem + +# required to detect when the database is up and running in init.sh +RUN cd /usr/bin && \ + wget https://github.com/jwilder/dockerize/releases/download/v0.3.0/dockerize-linux-amd64-v0.3.0.tar.gz -O dockerize.tar.gz && \ + echo "36e8319cdf9d2b07340f456ec61cfa0f495ec6c130b02ad9c116fd55a5c43fa1 dockerize.tar.gz" | sha256sum -c && \ + tar -xf dockerize.tar.gz && \ + rm dockerize.tar.gz + +# explicitly add Gemfile and install dependencies using bundler to make use of +# Docker's caching +WORKDIR /osem/ +RUN gem install puma +COPY Gemfile /osem/ +COPY Gemfile.lock /osem/ +RUN bundle install --without test development + +# add OSEM files and prepare them for use inside a Docker container +COPY . /osem/ +RUN chown osem.osem /osem/ -R && \ + mv /osem/config/database.yml.docker /osem/config/database.yml + +# data directory is used to cache the secret key in a file +ENV DATA_DIR /data +RUN install -d -m 0700 -o osem $DATA_DIR +VOLUME ["$DATA_DIR"] + +USER osem +EXPOSE 9292 + +COPY docker/init.sh /init.sh + +# a user could override this if they wanted to serve the static files directly +# from a webserver +ENV RAILS_SERVE_STATIC_FILES 1 + +CMD ["bash", "/init.sh"] diff --git a/config/database.yml.docker b/config/database.yml.docker new file mode 100644 index 00000000..60ef8947 --- /dev/null +++ b/config/database.yml.docker @@ -0,0 +1,7 @@ +production: + adapter: mysql2 + host: <%= ENV['DATABASE_HOST'] %> + port: <%= ENV['DATABASE_PORT'] %> + username: <%= ENV['MYSQL_USER'] %> + password: <%= ENV['MYSQL_PASSWORD'] %> + database: <%= ENV['MYSQL_DATABASE'] %> diff --git a/docker-compose.env.example b/docker-compose.env.example new file mode 100644 index 00000000..911b8062 --- /dev/null +++ b/docker-compose.env.example @@ -0,0 +1,38 @@ +## database related variables ## + +# variables prefixed with MYSQL_ are used by both database and web containers +# variables prefixed with DATABASE_ are used exlusively by the web container + +MYSQL_DATABASE=osem +MYSQL_USER=osem +MYSQL_PASSWORD=changemeimmediately +MYSQL_ROOT_PASSWORD=changemeevenmoreimmediately + +# the following settings should not be modified unless the database service +# is renamed in docker-compose.yml or you plan to use an external database +DATABASE_HOST=database +DATABASE_PORT=3306 + + +## OSEM options ## +# you can configure any option described in this document here instead of +# having to create a .env file: +# https://github.com/openSUSE/osem/blob/master/dotenv.example + +OSEM_NAME=Dockerized OSEM +OSEM_HOSTNAME=http://localhost:9292 +OSEM_ERRBIT_HOST=localhost +SECRET_KEY_BASE=changemechangemechangeme + +# these settings work for the MailHog server that is enabled by default in +# docker-compose.yml +# if you do not plan to use MailHog (you most likely don't want to), you need +# to change these settings to use an external working mailserver, otherwise +# your users are going to see the HTTP status 500 page +# you should comment out or remove the mailhog service from docker-compose.yml, +# too +OSEM_EMAIL_ADDRESS=osem@mailhog +OSEM_SMTP_ADDRESS=mailhog +OSEM_SMTP_PORT=1025 +OSEM_SMTP_USERNAME=mailhog +OSEM_SMTP_PASSWORD=mailhog diff --git a/docker-compose.yml.example b/docker-compose.yml.example new file mode 100644 index 00000000..0959523c --- /dev/null +++ b/docker-compose.yml.example @@ -0,0 +1,29 @@ +version: "2" + +services: + database: + image: mariadb:10.1 + env_file: docker-compose.env + volumes: + - database:/var/lib/mysql + + mailhog: + image: mailhog/mailhog:latest + ports: + - "127.0.0.1:8025:8025" + + web: + build: . + env_file: docker-compose.env + depends_on: + - database + - mailhog + ports: + - "127.0.0.1:9292:9292" + volumes: + - "web:/data" + +# these named volumes are used to persist data +volumes: + database: + web: diff --git a/docker/init.sh b/docker/init.sh new file mode 100644 index 00000000..36601e6c --- /dev/null +++ b/docker/init.sh @@ -0,0 +1,45 @@ +#! /bin/bash + +set -e + +# data directory is required for caching the secret key in a file +if [ "$DATA_DIR" == "" ]; then + echo -n "Error: DATA_DIR environment variable not set!" + echo "Are you sure you are running this script in a Docker container?" + exit 1 +fi + +SECRET_KEY_FILE="$DATA_DIR/secret_key" + +if [ ! -f "$SECRET_KEY_FILE" ]; then + install -m 0600 /dev/null "$SECRET_KEY_FILE" + SECRET_KEY=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 100 | head -n 1) + echo "$key" > "$SECRET_KEY_FILE" + chmod -w "$SECRET_KEY_FILE" +else + SECRET_KEY=$(cat "$SECRET_KEY_FILE") +fi + +export SECRET_KEY +export RAILS_ENV=production + +install -m 0600 /dev/null .my.cnf +cat > .my.cnf <>> Initializing database..." + dockerize -wait tcp://$DATABASE_HOST:$DATABASE_PORT -timeout 60s bundle exec rake db:schema:load +fi + +echo ">>> Upgrading database..." +dockerize -wait tcp://$DATABASE_HOST:$DATABASE_PORT -timeout 60s bundle exec rake db:migrate + +echo ">>> Precompiling assets..." +bundle exec rake assets:precompile + +echo ">>> Starting application server..." +exec puma -e production From 8229cca1e83ec5222ab3c44beccd169adbaeb0e3 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Fri, 31 Mar 2017 13:33:03 +0200 Subject: [PATCH 06/24] Add missing dependency to Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 86a6d4d1..0e7a70aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ MAINTAINER TheAssassin # required for compiling assets RUN apt-get update && \ - apt-get install -y nodejs nodejs-legacy mariadb-client + apt-get install -y nodejs nodejs-legacy mariadb-client imagemagick # used to run the container without root permissions RUN adduser --home /osem/ --system --group --disabled-login --disabled-password osem From 9402eb36d85530b3c1f4da3d7a53b8283fb48e04 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Fri, 31 Mar 2017 13:33:24 +0200 Subject: [PATCH 07/24] Add beginner guide for deploying OSEM with Docker --- INSTALL.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index 9cbfafcc..6307b7ae 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -11,7 +11,9 @@ OSEM is an [semantic versioned](http://semver.org/) app. That means given a vers ## Download You can find the latest OSEM releases on our [release page](https://github.com/openSUSE/osem/releases/latest) ([older release here](https://github.com/openSUSE/osem/releases)) + ## Deploy + OSEM is a *Ruby on Rails* application. We recommend to run OSEM in production with [mod_passenger](https://www.phusionpassenger.com/download/#open_source) and the [apache web-server](https://www.apache.org/). There are tons of guides on how to deploy rails apps on various base operating systems. [Check Google](https://encrypted.google.com/search?hl=en&q=ruby%20on%20rails%20apache%20passenger) ;-) @@ -24,6 +26,53 @@ If you have an heroku account you can also Deploy +### Deploy with Docker + +You can deploy OSEM using [Docker](https://docker.com/) and [Docker-Compose](https://docs.docker.com/compose/overview/). + +*This is just a short guide and does not explain how to use Docker and/or Docker-Compose. You need some experience with these tools to be able to deploy OSEM with Docker properly.* + +First of all, copy `docker-compose.yml.example` to `docker-compose.yml` and `docker-compose.env.example` to `docker-compose.env`. + +There are two configurations to deploy OSEM with Docker: *evaluation mode* and *production mode*. + +#### Evaluation mode + +If you want to evaluate OSEM to see if it fits your needs, the default configuration in `docker-compose.env` will work perfectly fine for you. +For convenience reasons, `docker-compose.yml` already contains a [MailHog](https://github.com/mailhog/MailHog) service configuration. MailHog +is going to catch every email sent by OSEM and displays them on a special web service. Thus, it eliminitates the need to set up an SMTP server just to try out OSEM. +Just point your browser to http://localhost:8025 to get access to registration confirmation links etc. + +Run `docker-compose up --build` to start the services. On first run, it will take a few minutes to initialize the database. Thus, wait a few minutes before you open up +http://localhost:9292 in your browser. + +#### Production mode + +To deploy OSEM for production, you have to make a few changes to `docker-compose.yml`. First, remove (or comment) the `mailhog` service, as it is only useful for evaluation and +cannot be used for production. +You can change the forwarded port from port `9292` to any other value if this port is already in use or you just want to use another one. + +Next, you have to modify `docker-compose.env`. This file works as a Docker-like replacement for the regular Rails `.env` files described below. +You can configure any of the configuration values shown in the **Configure** section below in it. The most essential variables are already configured to standard +values in `docker-compose.env` which you most likely want to change. + +First, you need to modify the email related settings. You need a working SMTP server for OSEM to send out registration confirmation mails etc. + +For security reasons, the following variables have to be changed, too: + + - `MYSQL_PASSWORD` + - `MYSQL_ROOT_PASSWORD` + - `SECRET_KEY_BASE` + +These variables need to be set to the correct values at first, as they are used to initialize everything. Modification of these variables after installation and initialization is more +complicated and out of this document's scope. + +As with any other Docker-Compose configuration, run `docker-compose up --build` (or `docker-compose up --build -d` to run in background) to start the services. During the first +start, the database has to be initialized which can take several minutes. The web service is by default exposed on localhost only as it is intended to be served by a reverse proxy (for SSL +termination, caching etc.). +You should not directly expose the web server port unless you have a good reason to do so. + + ## Configure There are a couple of environment variables you can set to configure OSEM. Check out the *dotenv.example* file. From 2c3c070f7e20bea9d932a99c783ccc5beba56e1f Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Sat, 1 Apr 2017 00:48:22 +0200 Subject: [PATCH 08/24] Update Docker docs --- INSTALL.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 6307b7ae..29dc5cec 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -32,7 +32,9 @@ You can deploy OSEM using [Docker](https://docker.com/) and [Docker-Compose](htt *This is just a short guide and does not explain how to use Docker and/or Docker-Compose. You need some experience with these tools to be able to deploy OSEM with Docker properly.* -First of all, copy `docker-compose.yml.example` to `docker-compose.yml` and `docker-compose.env.example` to `docker-compose.env`. +First of all, copy `docker-compose.yml.example` to `docker-compose.yml` and `docker-compose.env.example` to `docker-compose.env`. You should immediately change +`docker-compose.env`'s permissions to `0600` to make sure all the passphrases in it are kept secret. +(Tip: the easiest and most secure way to do it is to do it with a single command, for example `install -m 0600 docker-compose.env.example docker-compose.env`). There are two configurations to deploy OSEM with Docker: *evaluation mode* and *production mode*. From 28d9ac9b1fb37400133cad675ab3b822e66a02a8 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Sat, 1 Apr 2017 01:13:39 +0200 Subject: [PATCH 09/24] Switch to built in rails server --- Dockerfile | 1 - docker/init.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0e7a70aa..dab432ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,7 +19,6 @@ RUN cd /usr/bin && \ # explicitly add Gemfile and install dependencies using bundler to make use of # Docker's caching WORKDIR /osem/ -RUN gem install puma COPY Gemfile /osem/ COPY Gemfile.lock /osem/ RUN bundle install --without test development diff --git a/docker/init.sh b/docker/init.sh index 36601e6c..4d71ec77 100644 --- a/docker/init.sh +++ b/docker/init.sh @@ -42,4 +42,4 @@ echo ">>> Precompiling assets..." bundle exec rake assets:precompile echo ">>> Starting application server..." -exec puma -e production +exec bundle exec rails server -e production -p 9292 From 769643a642c6161c72459cbdbdf5f687a54181af Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Sat, 1 Apr 2017 01:16:30 +0200 Subject: [PATCH 10/24] Remove MySQL config file again as soon as possible --- docker/init.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/init.sh b/docker/init.sh index 4d71ec77..be418b9e 100644 --- a/docker/init.sh +++ b/docker/init.sh @@ -38,6 +38,8 @@ fi echo ">>> Upgrading database..." dockerize -wait tcp://$DATABASE_HOST:$DATABASE_PORT -timeout 60s bundle exec rake db:migrate +rm .my.cnf + echo ">>> Precompiling assets..." bundle exec rake assets:precompile From d7765bf4fdaa33f9db3ece41d65e761ccef26ace Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Sat, 1 Apr 2017 01:16:51 +0200 Subject: [PATCH 11/24] Update ignores --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4d5fd427..37bd6b81 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ pickle-email-*.html .env.development .env.test .env.local +docker-compose.{env,yml} From c592a19f2deb8b7ec25f6bf2ba13370595c728a8 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Tue, 4 Apr 2017 07:32:33 +0200 Subject: [PATCH 12/24] Use rails secret to generate the secret key --- docker/init.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/init.sh b/docker/init.sh index be418b9e..81ab11b5 100644 --- a/docker/init.sh +++ b/docker/init.sh @@ -12,8 +12,9 @@ fi SECRET_KEY_FILE="$DATA_DIR/secret_key" if [ ! -f "$SECRET_KEY_FILE" ]; then + echo ">>> Creating a new secret key file..." install -m 0600 /dev/null "$SECRET_KEY_FILE" - SECRET_KEY=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 100 | head -n 1) + SECRET_KEY=$(bundle exec rails secret) echo "$key" > "$SECRET_KEY_FILE" chmod -w "$SECRET_KEY_FILE" else From dd993b74481e158bee3a7105ca85bdb01e5f61fe Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Tue, 16 May 2017 22:16:46 +0200 Subject: [PATCH 13/24] Fix issue mentioned in osem/pull/1407 After the rebase (to update the PR with the latest changes), I had the same issue @lguerard has had. I noticed that the rails server didn't lisen on all interfaces any more, but bound the port to the loopback device only. By adding the parameter `-b 0.0.0.0`, I restored the previous behavior, and OSEM could be reached with the browser after it started up (takes a few seconds). --- docker/init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/init.sh b/docker/init.sh index 81ab11b5..8f1ba766 100644 --- a/docker/init.sh +++ b/docker/init.sh @@ -45,4 +45,4 @@ echo ">>> Precompiling assets..." bundle exec rake assets:precompile echo ">>> Starting application server..." -exec bundle exec rails server -e production -p 9292 +exec bundle exec rails server -e production -b 0.0.0.0 -p 9292 From b5ca626873cd6d4c95c481238b9f117203fe4de2 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Sun, 9 Jul 2017 15:47:24 +0200 Subject: [PATCH 14/24] Fix Git ignores --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 37bd6b81..75a1bdc6 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,5 @@ pickle-email-*.html .env.development .env.test .env.local -docker-compose.{env,yml} +docker-compose.env +docker-compose.yml From ad9ef4aba36710f9c032a5473e96fd782b983d8b Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Sun, 9 Jul 2017 15:48:09 +0200 Subject: [PATCH 15/24] Fix secret key generation --- docker/init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/init.sh b/docker/init.sh index 8f1ba766..aedb0874 100644 --- a/docker/init.sh +++ b/docker/init.sh @@ -14,7 +14,7 @@ SECRET_KEY_FILE="$DATA_DIR/secret_key" if [ ! -f "$SECRET_KEY_FILE" ]; then echo ">>> Creating a new secret key file..." install -m 0600 /dev/null "$SECRET_KEY_FILE" - SECRET_KEY=$(bundle exec rails secret) + SECRET_KEY=$(bundle exec rake secret) echo "$key" > "$SECRET_KEY_FILE" chmod -w "$SECRET_KEY_FILE" else From 13d6bf471da363a2901009aa60781c0a5339e13e Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Sun, 9 Jul 2017 15:54:51 +0200 Subject: [PATCH 16/24] Wait for database to be started before running MySQL client command --- docker/init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/init.sh b/docker/init.sh index aedb0874..16a55231 100644 --- a/docker/init.sh +++ b/docker/init.sh @@ -31,7 +31,7 @@ user=$MYSQL_USER password=$MYSQL_PASSWORD ABC -if [ $(echo "show tables;" | mysql --host $DATABASE_HOST --port $DATABASE_PORT $MYSQL_DATABASE | wc -l) -le 1 ]; then +if [ $(echo "show tables;" | dockerize -wait tcp://$DATABASE_HOST:$DATABASE_PORT -timeout 60s mysql --host $DATABASE_HOST --port $DATABASE_PORT $MYSQL_DATABASE | wc -l) -le 1 ]; then echo ">>> Initializing database..." dockerize -wait tcp://$DATABASE_HOST:$DATABASE_PORT -timeout 60s bundle exec rake db:schema:load fi From 6dea37ec413630ad45dace2891294942eccd9061 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Sun, 9 Jul 2017 19:57:29 +0200 Subject: [PATCH 17/24] Add missing environment variable --- docker-compose.env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.env.example b/docker-compose.env.example index 911b8062..2aedbe73 100644 --- a/docker-compose.env.example +++ b/docker-compose.env.example @@ -32,6 +32,7 @@ SECRET_KEY_BASE=changemechangemechangeme # you should comment out or remove the mailhog service from docker-compose.yml, # too OSEM_EMAIL_ADDRESS=osem@mailhog +OSEM_SMTP_AUTHENTICATION=login OSEM_SMTP_ADDRESS=mailhog OSEM_SMTP_PORT=1025 OSEM_SMTP_USERNAME=mailhog From 93d5e360ca0fbf42dba804e1bf3c71ad936f2cc9 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Sun, 9 Jul 2017 20:55:09 +0200 Subject: [PATCH 18/24] Merge dockerize commands --- docker/init.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docker/init.sh b/docker/init.sh index 16a55231..3a2031f3 100644 --- a/docker/init.sh +++ b/docker/init.sh @@ -31,13 +31,16 @@ user=$MYSQL_USER password=$MYSQL_PASSWORD ABC -if [ $(echo "show tables;" | dockerize -wait tcp://$DATABASE_HOST:$DATABASE_PORT -timeout 60s mysql --host $DATABASE_HOST --port $DATABASE_PORT $MYSQL_DATABASE | wc -l) -le 1 ]; then +echo ">>> Waiting for database to get ready to connect..." +dockerize -wait tcp://$DATABASE_HOST:$DATABASE_PORT -timeout 60s true + +if [ $(echo "show tables;" | mysql --host $DATABASE_HOST --port $DATABASE_PORT $MYSQL_DATABASE | wc -l) -le 1 ]; then echo ">>> Initializing database..." - dockerize -wait tcp://$DATABASE_HOST:$DATABASE_PORT -timeout 60s bundle exec rake db:schema:load + bundle exec rake db:schema:load fi echo ">>> Upgrading database..." -dockerize -wait tcp://$DATABASE_HOST:$DATABASE_PORT -timeout 60s bundle exec rake db:migrate +bundle exec rake db:migrate rm .my.cnf From fbd4be3503131022fb3d037576239a8f3c64d954 Mon Sep 17 00:00:00 2001 From: siddhantbajaj Date: Mon, 10 Jul 2017 17:45:05 +0530 Subject: [PATCH 19/24] Ticket show page --- app/views/physical_ticket/show.html.haml | 51 ++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/app/views/physical_ticket/show.html.haml b/app/views/physical_ticket/show.html.haml index e69de29b..19b89473 100644 --- a/app/views/physical_ticket/show.html.haml +++ b/app/views/physical_ticket/show.html.haml @@ -0,0 +1,51 @@ +.container + .row + .col-md-12 + .page-header + %h1 + Ticket for + = @conference.title + %p.text-muted + - if @conference.venue + at + %strong + #{@conference.venue.name}, + #{@conference.venue.street}, + #{@conference.venue.city} / #{@conference.venue.country_name}. + %small + = date_string(@conference.start_date, @conference.end_date) + .row + .col-md-6 + - if @conference.picture? + = image_tag(@conference.picture_url, class: 'img-responsive') + - else + = image_tag('/img/osem-logo.png', class: 'img-responsive') + .col-md-6 + %address + %strong + Ticket Type + %br + = @physical_ticket.ticket.title + %br + %strong + Ticket REF. + %br + = @physical_ticket.ticket_purchase.id + %br + %strong + Organization + %br + = @conference.organization.name + %br + %strong + Transaction Date + %br + = @physical_ticket.created_at.strftime('%B %d, %Y') + .row + .col-md-12 + %p.text-right + = link_to 'Generate PDF', + conference_physical_ticket_path(@conference.short_title, + @physical_ticket.id, + format: :pdf), + class: 'button btn btn-default btn-info' From c066aadae2138961952a1495d2afa7953ef2e539 Mon Sep 17 00:00:00 2001 From: siddhantbajaj Date: Tue, 11 Jul 2017 17:05:07 +0530 Subject: [PATCH 20/24] Added TicketScanning Model --- app/models/physical_ticket.rb | 1 + app/models/ticket_scanning.rb | 3 +++ db/migrate/20170711102511_create_ticket_scannings.rb | 9 +++++++++ db/schema.rb | 8 +++++++- 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 app/models/ticket_scanning.rb create mode 100644 db/migrate/20170711102511_create_ticket_scannings.rb diff --git a/app/models/physical_ticket.rb b/app/models/physical_ticket.rb index a0874a6e..6142c875 100644 --- a/app/models/physical_ticket.rb +++ b/app/models/physical_ticket.rb @@ -3,4 +3,5 @@ class PhysicalTicket < ActiveRecord::Base has_one :ticket, through: :ticket_purchase has_one :conference, through: :ticket_purchase has_one :user, through: :ticket_purchase + has_many :ticket_scannings end diff --git a/app/models/ticket_scanning.rb b/app/models/ticket_scanning.rb new file mode 100644 index 00000000..6ce9d00c --- /dev/null +++ b/app/models/ticket_scanning.rb @@ -0,0 +1,3 @@ +class TicketScanning < ActiveRecord::Base + belongs_to :physical_ticket +end diff --git a/db/migrate/20170711102511_create_ticket_scannings.rb b/db/migrate/20170711102511_create_ticket_scannings.rb new file mode 100644 index 00000000..d1879f68 --- /dev/null +++ b/db/migrate/20170711102511_create_ticket_scannings.rb @@ -0,0 +1,9 @@ +class CreateTicketScannings < ActiveRecord::Migration + def change + create_table :ticket_scannings do |t| + t.integer :physical_ticket_id, null: false + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index af227946..b9f8e3f4 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: 20170629232817) do +ActiveRecord::Schema.define(version: 20170711102511) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -468,6 +468,12 @@ ActiveRecord::Schema.define(version: 20170629232817) do t.integer "week" end + create_table "ticket_scannings", force: :cascade do |t| + t.integer "physical_ticket_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "tickets", force: :cascade do |t| t.integer "conference_id" t.string "title", null: false From 43b4204e308ffa7ffafd808d4d8a391214ae3cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20D=C3=A9niz=20Alem=C3=A1n?= Date: Wed, 12 Jul 2017 10:33:16 +0200 Subject: [PATCH 21/24] Revert "Ticket show page" --- app/views/physical_ticket/show.html.haml | 51 ------------------------ 1 file changed, 51 deletions(-) diff --git a/app/views/physical_ticket/show.html.haml b/app/views/physical_ticket/show.html.haml index 19b89473..e69de29b 100644 --- a/app/views/physical_ticket/show.html.haml +++ b/app/views/physical_ticket/show.html.haml @@ -1,51 +0,0 @@ -.container - .row - .col-md-12 - .page-header - %h1 - Ticket for - = @conference.title - %p.text-muted - - if @conference.venue - at - %strong - #{@conference.venue.name}, - #{@conference.venue.street}, - #{@conference.venue.city} / #{@conference.venue.country_name}. - %small - = date_string(@conference.start_date, @conference.end_date) - .row - .col-md-6 - - if @conference.picture? - = image_tag(@conference.picture_url, class: 'img-responsive') - - else - = image_tag('/img/osem-logo.png', class: 'img-responsive') - .col-md-6 - %address - %strong - Ticket Type - %br - = @physical_ticket.ticket.title - %br - %strong - Ticket REF. - %br - = @physical_ticket.ticket_purchase.id - %br - %strong - Organization - %br - = @conference.organization.name - %br - %strong - Transaction Date - %br - = @physical_ticket.created_at.strftime('%B %d, %Y') - .row - .col-md-12 - %p.text-right - = link_to 'Generate PDF', - conference_physical_ticket_path(@conference.short_title, - @physical_ticket.id, - format: :pdf), - class: 'button btn btn-default btn-info' From eb23d838b53ce0dc61e333206a2fa24b1eb80440 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Tue, 11 Jul 2017 04:59:03 +0530 Subject: [PATCH 22/24] correct past and upcoming conferences in admin/organizations#index --- app/models/conference.rb | 2 ++ app/views/admin/organizations/index.html.haml | 4 ++-- spec/models/conference_spec.rb | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/models/conference.rb b/app/models/conference.rb index 69571dc9..68cdc186 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -7,6 +7,8 @@ class Conference < ActiveRecord::Base resourcify :roles, dependent: :delete_all default_scope { order('start_date DESC') } + scope :upcoming, (-> { where('end_date >= ?', Date.current) }) + scope :past, (-> { where('end_date < ?', Date.current) }) belongs_to :organization diff --git a/app/views/admin/organizations/index.html.haml b/app/views/admin/organizations/index.html.haml index 52e2877a..aa682c57 100644 --- a/app/views/admin/organizations/index.html.haml +++ b/app/views/admin/organizations/index.html.haml @@ -20,9 +20,9 @@ %td = organization.name %td - = organization.conferences.count + = organization.conferences.upcoming.count %td - = organization.conferences.count + = organization.conferences.past.count %td .btn-group = link_to 'Edit', edit_admin_organization_path(organization), diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index 89863412..91c06140 100755 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -1687,4 +1687,21 @@ describe Conference do expect{ room.save }.to change { subject.revision }.by(1) end end + + describe '.upcoming' do + let!(:upcoming_conference) { create(:conference) } + let!(:past_conference) { create(:conference, start_date: Date.current - 1.days, end_date: Date.current - 1.days) } + subject { Conference.upcoming } + + it { is_expected.to eq [upcoming_conference] } + end + + describe '.past' do + let!(:upcoming_conference) { create(:conference) } + let!(:past_conference1) { create(:conference, start_date: Date.current - 1.days, end_date: Date.current - 1.days) } + let!(:past_conference2) { create(:conference, start_date: Date.current - 2.days, end_date: Date.current - 1.days) } + subject { Conference.past } + + it { is_expected.to eq [past_conference1, past_conference2] } + end end From ddf6f4b4c90954b1483fc3d6f446967795eac817 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Tue, 11 Jul 2017 03:59:52 +0530 Subject: [PATCH 23/24] fix new conference links --- app/views/layouts/_admin_sidebar.html.haml | 2 +- app/views/layouts/_admin_sidebar_index.html.haml | 2 +- app/views/layouts/_user_menu.html.haml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index 2c3eaf52..1c7bac9a 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -16,7 +16,7 @@ %span.fa.fa-cog Manage = conference.short_title - - if (current_user.is_admin) || (current_user.has_role? :organizer, :any) + - if can? :new, Conference.new %li = link_to(new_admin_conference_path) do %span.fa.fa-plus diff --git a/app/views/layouts/_admin_sidebar_index.html.haml b/app/views/layouts/_admin_sidebar_index.html.haml index 3844339b..01356f42 100644 --- a/app/views/layouts/_admin_sidebar_index.html.haml +++ b/app/views/layouts/_admin_sidebar_index.html.haml @@ -16,7 +16,7 @@ %span.fa.fa-cog Manage = conference.short_title - - if can? :create, Conference + - if can? :new, Conference.new %li = link_to(new_admin_conference_path) do %span.fa.fa-plus diff --git a/app/views/layouts/_user_menu.html.haml b/app/views/layouts/_user_menu.html.haml index 01432b3c..38a96b08 100644 --- a/app/views/layouts/_user_menu.html.haml +++ b/app/views/layouts/_user_menu.html.haml @@ -28,10 +28,10 @@ = link_to(admin_conferences_path()) do %span.fa.fa-home Administration - - if can? :create, Conference + - if can? :new, Conference.new =link_to(new_admin_conference_path) do %span.fa.fa-plus - Create Conference + New Conference -if @conference and @conference.id and can? :show, @conference %li = link_to(admin_conference_path(@conference.short_title)) do From ea43b19ef489e5fb61ab3672483a5e589c482e1d Mon Sep 17 00:00:00 2001 From: shlok007 Date: Wed, 12 Jul 2017 17:34:33 +0530 Subject: [PATCH 24/24] add tests for new conference links --- spec/features/cfp_ability_spec.rb | 1 + spec/features/info_desk_ability_spec.rb | 1 + spec/features/organization_admin_ability_spec.rb | 1 + spec/features/organizer_ability_spec.rb | 1 + 4 files changed, 4 insertions(+) diff --git a/spec/features/cfp_ability_spec.rb b/spec/features/cfp_ability_spec.rb index 235dedea..7af4e119 100644 --- a/spec/features/cfp_ability_spec.rb +++ b/spec/features/cfp_ability_spec.rb @@ -46,6 +46,7 @@ feature 'Has correct abilities' do expect(page).to_not have_link('Goals', href: "/admin/conferences/#{conference.short_title}/targets") expect(page).to have_link('Roles', href: "/admin/conferences/#{conference.short_title}/roles") expect(page).to have_link('Resources', href: "/admin/conferences/#{conference.short_title}/resources") + expect(page).to_not have_link('New Conference', href: '/admin/conferences/new') visit admin_conference_venue_rooms_path(conference.short_title) expect(current_path).to eq(admin_conference_venue_rooms_path(conference.short_title)) diff --git a/spec/features/info_desk_ability_spec.rb b/spec/features/info_desk_ability_spec.rb index 7d0039fe..20aa586b 100644 --- a/spec/features/info_desk_ability_spec.rb +++ b/spec/features/info_desk_ability_spec.rb @@ -46,6 +46,7 @@ feature 'Has correct abilities' do expect(page).to have_link('Registrations', href: "/admin/conferences/#{conference.short_title}/registrations") expect(page).to have_link('Questions', href: "/admin/conferences/#{conference.short_title}/questions") expect(page).to_not have_link('E-Mails', href: "/admin/conferences/#{conference.short_title}/emails") + expect(page).to_not have_link('New Conference', href: '/admin/conferences/new') visit admin_organizations_path expect(current_path).to eq(admin_organizations_path) diff --git a/spec/features/organization_admin_ability_spec.rb b/spec/features/organization_admin_ability_spec.rb index 3a5ffcd3..aefb89f4 100644 --- a/spec/features/organization_admin_ability_spec.rb +++ b/spec/features/organization_admin_ability_spec.rb @@ -55,6 +55,7 @@ feature 'Has correct abilities' do expect(page).to have_link('E-Mails', href: "/admin/conferences/#{conference.short_title}/emails") expect(page).to have_link('Roles', href: "/admin/conferences/#{conference.short_title}/roles") expect(page).to have_link('Resources', href: "/admin/conferences/#{conference.short_title}/resources") + expect(page).to have_link('New Conference', href: '/admin/conferences/new') visit edit_admin_conference_path(conference.short_title) expect(current_path).to eq(edit_admin_conference_path(conference.short_title)) diff --git a/spec/features/organizer_ability_spec.rb b/spec/features/organizer_ability_spec.rb index 7617bc0a..34d87b0a 100644 --- a/spec/features/organizer_ability_spec.rb +++ b/spec/features/organizer_ability_spec.rb @@ -58,6 +58,7 @@ feature 'Has correct abilities' do expect(page).to have_link('E-Mails', href: "/admin/conferences/#{conference.short_title}/emails") expect(page).to have_link('Roles', href: "/admin/conferences/#{conference.short_title}/roles") expect(page).to have_link('Resources', href: "/admin/conferences/#{conference.short_title}/resources") + expect(page).to_not have_link('New Conference', href: '/admin/conferences/new') visit admin_conference_path(other_conference.short_title) expect(page).to have_link('Add venue', href: "/admin/conferences/#{other_conference.short_title}/venue/new")