From c5db5dba1e96e996ec902d2e51daea5df1fca917 Mon Sep 17 00:00:00 2001 From: siddhantbajaj Date: Mon, 10 Jul 2017 17:45:05 +0530 Subject: [PATCH 01/50] Ticket show page --- app/assets/stylesheets/osem.css.scss | 6 +- app/views/physical_ticket/show.html.haml | 77 ++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/osem.css.scss b/app/assets/stylesheets/osem.css.scss index bc8b6388..5a331436 100644 --- a/app/assets/stylesheets/osem.css.scss +++ b/app/assets/stylesheets/osem.css.scss @@ -89,4 +89,8 @@ p.comment-body { .changeset{ display: none; -} \ No newline at end of file +} + +.box{ + height: 230px; +} diff --git a/app/views/physical_ticket/show.html.haml b/app/views/physical_ticket/show.html.haml index e69de29b..26fa7853 100644 --- a/app/views/physical_ticket/show.html.haml +++ b/app/views/physical_ticket/show.html.haml @@ -0,0 +1,77 @@ +.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-5.box.well + %h3.text-center + Ticket Holder + %p.text-left + %strong + Name + %br + = @user.name + %br + %br + %strong + Email + %br + = @user.email + .col-md-5.col-md-offset-2.box.well + - if @conference.picture? + - width = @conference.picture.image[:width] + - height = @conference.picture.image[:height] + - if 10 * width > 15 * height + = image_tag(@conference.picture_url, width: '150') + - else + = image_tag(@conference.picture_url, height: '100') + - else + = image_tag('/img/osem-logo.png', class: 'img-responsive') + %p.text-left + %br + %strong + Organization + %br + = @conference.organization.name + .col-md-5.box.well + %p.text-left + %strong + Event + %br + = @conference.title + %br + = @conference.start_date.strftime('%B %d, %Y') + %br + %br + %strong + Ticket + %br + = @physical_ticket.ticket.title + %br + %br + %strong + Ticket Ref. + %br + = @physical_ticket.ticket_purchase.id + %br + .col-md-5.col-md-offset-2.box.well + .row + .col-md-12 + %p.text-left + = link_to 'Generate PDF', + conference_physical_ticket_path(@conference.short_title, + @physical_ticket.id, + format: :pdf), + class: 'button btn btn-default btn-info' From 4779bef9f7d486e5d316a732589929b268193735 Mon Sep 17 00:00:00 2001 From: siddhantbajaj Date: Wed, 19 Jul 2017 17:47:02 +0530 Subject: [PATCH 02/50] Fixed flickering proposal feature test Test were sometimes failing because of the delay between the click_link and the actual completion of the code that is run as a result of that click. --- spec/features/proposals_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index b5620475..70bcbf63 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -32,7 +32,7 @@ feature Event do click_button 'New' click_link "reject_event_#{@event.id}" - expect(flash).to eq('Event rejected!') + expect(page).to have_content 'Event rejected!' @event.reload expect(@event.state).to eq('rejected') end @@ -43,7 +43,7 @@ feature Event do click_button 'New' click_link "accept_event_#{@event.id}" - expect(flash).to eq('Event accepted!') + expect(page).to have_content 'Event accepted!' expect(page.has_content?('Unconfirmed')).to be true @event.reload expect(@event.state).to eq('unconfirmed') @@ -56,7 +56,7 @@ feature Event do click_button 'Rejected' click_link "restart_event_#{@event.id}" - expect(flash).to eq('Review started!') + expect(page).to have_content 'Review started!' @event.reload expect(@event.state).to eq('new') end From 0501ecd8f6fce5883fc68b5cfe340846c8e1c6f7 Mon Sep 17 00:00:00 2001 From: siddhantbajaj Date: Thu, 20 Jul 2017 17:30:27 +0530 Subject: [PATCH 03/50] Refactored proposal feature spec. Fixes #1561. --- spec/features/proposals_spec.rb | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index 70bcbf63..9dda06bf 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -28,7 +28,7 @@ feature Event do scenario 'rejects a proposal', feature: true, js: true do visit admin_conference_program_events_path(conference.short_title) - expect(page.has_content?('Example Proposal')).to be true + expect(page).to have_content 'Example Proposal' click_button 'New' click_link "reject_event_#{@event.id}" @@ -39,12 +39,12 @@ feature Event do scenario 'accepts a proposal', feature: true, js: true do visit admin_conference_program_events_path(conference.short_title) - expect(page.has_content?('Example Proposal')).to be true + expect(page).to have_content 'Example Proposal' click_button 'New' click_link "accept_event_#{@event.id}" expect(page).to have_content 'Event accepted!' - expect(page.has_content?('Unconfirmed')).to be true + expect(page).to have_content 'Unconfirmed' @event.reload expect(@event.state).to eq('unconfirmed') end @@ -52,7 +52,7 @@ feature Event do scenario 'restarts review of a proposal', feature: true, js: true do @event.reject!(@options) visit admin_conference_program_events_path(conference.short_title) - expect(page.has_content?('Example Proposal')).to be true + expect(page).to have_content 'Example Proposal' click_button 'Rejected' click_link "restart_event_#{@event.id}" @@ -83,7 +83,7 @@ feature Event do fill_in 'event_abstract', with: 'Lorem ipsum abstract' click_button 'Create Proposal' - expect(flash).to eq('Proposal was successfully submitted.') + expect(page).to have_content 'Proposal was successfully submitted.' expect(Event.count).to eq(expected_count_event) expect(User.count).to eq(expected_count_user) @@ -101,7 +101,7 @@ feature Event do select('Easy', from: 'event[difficulty_level_id]') click_button 'Update Proposal' - expect(flash).to eq('Proposal was successfully updated.') + expect(page).to have_content 'Proposal was successfully updated.' end scenario 'signed_in user submits a valid proposal', feature: true, js: true do @@ -119,7 +119,7 @@ feature Event do fill_in 'event_description', with: 'Lorem ipsum description' click_button 'Create Proposal' - expect(flash).to eq('Proposal was successfully submitted.') + expect(page).to have_content 'Proposal was successfully submitted.' expect(current_path).to eq(conference_program_proposals_path(conference.short_title)) expect(Event.count).to eq(expected_count) @@ -128,11 +128,10 @@ feature Event do scenario 'confirms a proposal', feature: true, js: true do sign_in participant visit conference_program_proposals_path(conference.short_title) - expect(page.has_content?('Example Proposal')).to be true + expect(page).to have_content 'Example Proposal' expect(@event.state).to eq('unconfirmed') click_link "confirm_proposal_#{@event.id}" - expect(flash) - .to eq('The proposal was confirmed. Please register to attend the conference.') + expect(page).to have_content 'The proposal was confirmed. Please register to attend the conference.' expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title)) @event.reload expect(@event.state).to eq('confirmed') @@ -142,9 +141,9 @@ feature Event do sign_in participant @event.confirm! visit conference_program_proposals_path(conference.short_title) - expect(page.has_content?('Example Proposal')).to be true + expect(page).to have_content 'Example Proposal' click_link "delete_proposal_#{@event.id}" - expect(flash).to eq('Proposal was successfully withdrawn.') + expect(page).to have_content 'Proposal was successfully withdrawn.' @event.reload expect(@event.state).to eq('withdrawn') end From c6b0a1f52e9936aeff7705d3037b409a89e3e0c0 Mon Sep 17 00:00:00 2001 From: nasia Date: Sun, 16 Jul 2017 18:20:12 +0300 Subject: [PATCH 04/50] Add tests for booth controller --- app/models/booth.rb | 2 +- app/views/admin/booths/_form.html.haml | 2 +- .../admin/booths_controller_spec.rb | 148 ++++++++++++++++++ spec/factories/booth_request.rb | 8 + spec/factories/booths.rb | 4 +- spec/models/booth_spec.rb | 4 +- 6 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 spec/controllers/admin/booths_controller_spec.rb create mode 100644 spec/factories/booth_request.rb diff --git a/app/models/booth.rb b/app/models/booth.rb index 911f9485..5c20550a 100644 --- a/app/models/booth.rb +++ b/app/models/booth.rb @@ -55,7 +55,7 @@ class Booth < ActiveRecord::Base transitions to: :rejected, from: [:new, :to_reject] end event :cancel do - transitions to: :canceled, from: [:accepted, :rejected] + transitions to: :canceled, from: [:accepted, :rejected, :to_accept, :to_reject] end end diff --git a/app/views/admin/booths/_form.html.haml b/app/views/admin/booths/_form.html.haml index e4a7d05d..f70079fa 100644 --- a/app/views/admin/booths/_form.html.haml +++ b/app/views/admin/booths/_form.html.haml @@ -5,7 +5,7 @@ .row .col-md-8 = semantic_form_for(@booth, url: @booth.new_record? ? admin_conference_booths_path(@conference.short_title) : admin_conference_booth_path(@conference.short_title, @booth.id), html: { multipart: true }) do |f| - = f.input :title, as: :string, required: true + = f.input :title, as: :string, autofocus: true, required: true = f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true, hint: 'This field becomes public upon request acceptance' = f.input :reasoning, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true, diff --git a/spec/controllers/admin/booths_controller_spec.rb b/spec/controllers/admin/booths_controller_spec.rb new file mode 100644 index 00000000..569862d1 --- /dev/null +++ b/spec/controllers/admin/booths_controller_spec.rb @@ -0,0 +1,148 @@ +require 'spec_helper' + +describe Admin::BoothsController do + + let(:admin) { create(:admin) } + let(:conference) { create(:conference) } + let(:booth) { create(:booth, title: 'Title', conference: conference) } + let(:admin) { create(:admin) } + + context 'not logged in user' do + + describe 'GET index' do + it 'does not render admin/booths#index' do + get :index, conference_id: conference.short_title + expect(response).to redirect_to(user_session_path) + end + end + + describe 'GET show' do + it 'does not render admin/booths#show' do + get :show, id: booth.id, conference_id: conference.short_title + expect(response).to redirect_to(user_session_path) + end + end + end + + context 'user is admin' do + before :each do + sign_in admin + end + + describe 'GET index' do + before { get :index, conference_id: conference.short_title } + + it 'assigns attributes for booths' do + expect(assigns(:booths)).to eq([booth]) + end + + it 'renders index template' do + expect(response).to render_template('index') + end + end + + describe 'GET new' do + before { get :new, conference_id: conference.short_title } + + it 'assigns attributes for booths' do + expect(assigns(:booth)).to be_a_new(Booth) + end + + it 'renders new template' do + expect(response).to render_template('new') + end + end + + describe 'POST #create' do + context 'successfully created' do + before { post :create, booth: attributes_for(:booth), conference_id: conference.short_title } + + it 'creates a new booth' do + expected = expect do + post :create, booth: attributes_for(:booth), conference_id: conference.short_title + end + expected.to change { Booth.count }.by(1) + end + + it 'redirects to admin booth index' do + expect(response).to redirect_to(admin_conference_booths_path) + end + + it 'has responsibles' do + expect(booth.responsibles.count).to_not eq(0) + end + + it 'shows success message' do + expect(flash[:notice]).to match('Booth successfully created.') + end + end + + context 'create action fails' do + before { post :create, booth: attributes_for(:booth, title: ''), conference_id: conference.short_title } + + it 'does not create any record' do + expected = expect do + post :create, booth: attributes_for(:booth, title: ''), conference_id: conference.short_title + end + expected.to_not change(Booth, :count) + end + + it 'redirects to new' do + expect(response).to render_template('new') + end + + it 'shows flash message' do + expect(flash[:error]).to eq("Creating booth failed. Title can't be blank.") + end + end + end + + describe 'GET #edit' do + before { get :edit, id: booth.id, conference_id: conference.short_title } + + it 'renders edit template' do + expect(response).to render_template('edit') + end + + it 'assigns booth variable' do + expect(assigns(:booth)).to eq booth + end + end + + describe 'PATCH #update' do + context 'updates suchessfully' do + before { patch :update, id: booth.id, booth: attributes_for(:booth, title: 'different'), conference_id: conference.short_title } + it 'redirects to admin booth index path' do + expect(response).to redirect_to admin_conference_booths_path + end + + it 'shows success message' do + expect(flash[:notice]).to match 'Successfully updated booth.' + end + + it 'updates booth' do + booth.reload + expect(booth.title).to eq('different') + end + end + end + + describe 'DELETE #destroy' do + context 'deletes successfully' do + before { delete :destroy, id: booth.id, conference_id: conference.short_title } + + it 'booth deleted' do + expect(Booth.count).to eq(0) + end + + it 'redirects to admin booth index path' do + expect(response).to redirect_to(admin_conference_booths_path) + end + + it 'show success message' do + expect(flash[:notice]).to match('Booth successfully destroyed.') + end + end + end + end +end diff --git a/spec/factories/booth_request.rb b/spec/factories/booth_request.rb new file mode 100644 index 00000000..fba0cace --- /dev/null +++ b/spec/factories/booth_request.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :booth_request do + booth + user + role 'responsible' + + end +end diff --git a/spec/factories/booths.rb b/spec/factories/booths.rb index a67d30f0..b1cd1956 100644 --- a/spec/factories/booths.rb +++ b/spec/factories/booths.rb @@ -8,8 +8,6 @@ FactoryGirl.define do conference - after(:build) do |booth| - booth.responsibles << create(:user) - end + responsible_ids { [create(:user).id] } end end diff --git a/spec/models/booth_spec.rb b/spec/models/booth_spec.rb index f13eb536..5e86a393 100644 --- a/spec/models/booth_spec.rb +++ b/spec/models/booth_spec.rb @@ -38,8 +38,8 @@ describe 'Booth' do states_transitions = { new: { restart: false, withdraw: true, accept: true, to_accept: true, to_reject: true, reject: true, cancel: false }, withdrawn: { restart: true, withdraw: false, accept: false, to_accept: false, to_reject: false, reject: false, cancel: false }, - to_accept: { restart: true, withdraw: true, accept: true, to_accept: false, to_reject: true, reject: false, cancel: false }, - to_reject: { restart: true, withdraw: true, accept: false, to_accept: true, to_reject: false, reject: true, cancel: false }, + to_accept: { restart: true, withdraw: true, accept: true, to_accept: false, to_reject: true, reject: false, cancel: true }, + to_reject: { restart: true, withdraw: true, accept: false, to_accept: true, to_reject: false, reject: true, cancel: true }, accepted: { restart: false, withdraw: true, accept: false, to_accept: false, to_reject: false, reject: false, cancel: true }, rejected: { restart: false, withdraw: true, accept: false, to_accept: false, to_reject: false, reject: false, cancel: true }, canceled: { restart: true, withdraw: false, accept: false, to_accept: false, to_reject: false, reject: false, cancel: false } } From 2bf7e4bbd343e0a4a062762dd0dfd4a421b997e9 Mon Sep 17 00:00:00 2001 From: Dimitris Date: Sat, 15 Jul 2017 03:02:03 +0300 Subject: [PATCH 05/50] Fix user already subscribed exception Prevent excpetion at user subscription when already is subscribed to a conference and add hanling to the similar unsubscribe event. remove double validation at app/models/subscription.rb update subscription_controller_spec --- app/controllers/subscriptions_controller.rb | 10 ++++++---- app/models/subscription.rb | 1 - spec/controllers/subscriptions_controller_spec.rb | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index 351f9e9d..76d5c74a 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -5,17 +5,19 @@ class SubscriptionsController < ApplicationController def create @subscription = current_user.subscriptions.build(conference_id: @conference.id) - if @subscription.save! - redirect_to root_path, notice: "You have been subscribed to receive email notifications for #{@conference.short_title}." + if @subscription.save + redirect_to root_path, notice: "You have subscribed to receive email notifications for #{@conference.title}." else - redirect_to root_path, error: subscription.errors.full_messages.to_sentence + redirect_to root_path, error: @subscription.errors.full_messages.to_sentence end end def destroy @subscription = current_user.subscriptions.find_by(conference_id: @conference.id) + + redirect_to(root_path, error: "You are not subscribed to #{@conference.title}.") && return unless @subscription if @subscription.destroy - redirect_to root_path, notice: "You have been unsubscribed and now you will not be receiving email notifications for #{@conference.short_title}." + redirect_to root_path, notice: "You have unsubscribed and you will not be receiving email notifications for #{@conference.title}." else redirect_to root_path, error: @subscription.errors.full_messages.to_sentence end diff --git a/app/models/subscription.rb b/app/models/subscription.rb index aa688ae8..984c46f3 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -1,5 +1,4 @@ class Subscription < ActiveRecord::Base - validates :user_id, uniqueness: { scope: [:conference_id] } belongs_to :conference belongs_to :user diff --git a/spec/controllers/subscriptions_controller_spec.rb b/spec/controllers/subscriptions_controller_spec.rb index 193ae23d..ac20a34b 100644 --- a/spec/controllers/subscriptions_controller_spec.rb +++ b/spec/controllers/subscriptions_controller_spec.rb @@ -24,7 +24,7 @@ describe SubscriptionsController do it 'shows success message in flash notice' do post :create, conference_id: conference.short_title - expect(flash[:notice]).to match("You have been subscribed to receive email notifications for #{conference.short_title}") + expect(flash[:notice]).to match("You have subscribed to receive email notifications for #{conference.title}") end it 'subscribes user to conference' do @@ -47,7 +47,7 @@ describe SubscriptionsController do it 'shows success message in flash notice' do delete :destroy, conference_id: conference.short_title - expect(flash[:notice]).to match("You have been unsubscribed and now you will not be receiving email notifications for #{conference.short_title}.") + expect(flash[:notice]).to match("You have unsubscribed and you will not be receiving email notifications for #{conference.title}.") end end end From 9e154a1dcd5d28102d852eb6a26eefba2cf054db Mon Sep 17 00:00:00 2001 From: siddhantbajaj Date: Mon, 10 Jul 2017 20:43:27 +0530 Subject: [PATCH 06/50] Added Token field for physical_ticket Added token field in physical_ticket model. This token will also be stored in the qr code and will uniqely identify the ticket. --- app/controllers/physical_ticket_controller.rb | 2 +- app/models/physical_ticket.rb | 15 +++++++++++++++ app/views/admin/physical_ticket/index.html.haml | 6 +++--- app/views/physical_ticket/index.html.haml | 4 ++-- app/views/physical_ticket/show.html.haml | 2 +- ...0170721001700_add_index_to_physical_tickets.rb | 6 ++++++ db/schema.rb | 5 ++++- .../physical_ticket_controller_spec.rb | 2 +- 8 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20170721001700_add_index_to_physical_tickets.rb diff --git a/app/controllers/physical_ticket_controller.rb b/app/controllers/physical_ticket_controller.rb index 6bb7f50b..fb25ae63 100644 --- a/app/controllers/physical_ticket_controller.rb +++ b/app/controllers/physical_ticket_controller.rb @@ -1,7 +1,7 @@ class PhysicalTicketController < ApplicationController before_action :authenticate_user! load_resource :conference, find_by: :short_title - load_and_authorize_resource + load_and_authorize_resource find_by: :token authorize_resource :conference_registrations, class: Registration def index diff --git a/app/models/physical_ticket.rb b/app/models/physical_ticket.rb index 6142c875..689d118a 100644 --- a/app/models/physical_ticket.rb +++ b/app/models/physical_ticket.rb @@ -4,4 +4,19 @@ class PhysicalTicket < ActiveRecord::Base has_one :conference, through: :ticket_purchase has_one :user, through: :ticket_purchase has_many :ticket_scannings + + before_create :set_token + + private + + def set_token + self.token = generate_token + end + + def generate_token + loop do + token = SecureRandom.hex(10) + break token unless PhysicalTicket.exists?(token: token) + end + end end diff --git a/app/views/admin/physical_ticket/index.html.haml b/app/views/admin/physical_ticket/index.html.haml index fe128932..96c5911f 100644 --- a/app/views/admin/physical_ticket/index.html.haml +++ b/app/views/admin/physical_ticket/index.html.haml @@ -32,12 +32,12 @@ .btn-group = link_to 'Show', conference_physical_ticket_path(@conference.short_title, - physical_ticket.id), + physical_ticket.token), class: 'btn btn-primary' = link_to 'Generate PDF', conference_physical_ticket_path(@conference.short_title, - physical_ticket.id, - format: :pdf), + physical_ticket.token, + format: :pdf), class: 'button btn btn-default btn-info' - else %h5 No Tickets sold! diff --git a/app/views/physical_ticket/index.html.haml b/app/views/physical_ticket/index.html.haml index b077400b..cb0710ad 100644 --- a/app/views/physical_ticket/index.html.haml +++ b/app/views/physical_ticket/index.html.haml @@ -24,11 +24,11 @@ .btn-group = link_to 'Show', conference_physical_ticket_path(@conference.short_title, - physical_ticket.id), + physical_ticket.token), class: 'btn btn-primary' = link_to 'Generate PDF', conference_physical_ticket_path(@conference.short_title, - physical_ticket.id, + physical_ticket.token, format: :pdf), class: 'button btn btn-default btn-info' - else diff --git a/app/views/physical_ticket/show.html.haml b/app/views/physical_ticket/show.html.haml index 26fa7853..067f0a9b 100644 --- a/app/views/physical_ticket/show.html.haml +++ b/app/views/physical_ticket/show.html.haml @@ -72,6 +72,6 @@ %p.text-left = link_to 'Generate PDF', conference_physical_ticket_path(@conference.short_title, - @physical_ticket.id, + @physical_ticket.token, format: :pdf), class: 'button btn btn-default btn-info' diff --git a/db/migrate/20170721001700_add_index_to_physical_tickets.rb b/db/migrate/20170721001700_add_index_to_physical_tickets.rb new file mode 100644 index 00000000..46a0b8c0 --- /dev/null +++ b/db/migrate/20170721001700_add_index_to_physical_tickets.rb @@ -0,0 +1,6 @@ +class AddIndexToPhysicalTickets < ActiveRecord::Migration + def change + add_column :physical_tickets, :token, :string + add_index :physical_tickets, :token, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 64ac0393..d49dfa03 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: 20170711102511) do +ActiveRecord::Schema.define(version: 20170721001700) do create_table "ahoy_events", force: :cascade do |t| t.integer "visit_id" @@ -317,8 +317,11 @@ ActiveRecord::Schema.define(version: 20170711102511) do t.integer "ticket_purchase_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "token" end + add_index "physical_tickets", ["token"], name: "index_physical_tickets_on_token", unique: true + create_table "programs", force: :cascade do |t| t.integer "conference_id" t.integer "rating", default: 0 diff --git a/spec/controllers/physical_ticket_controller_spec.rb b/spec/controllers/physical_ticket_controller_spec.rb index 7a430479..863e27af 100644 --- a/spec/controllers/physical_ticket_controller_spec.rb +++ b/spec/controllers/physical_ticket_controller_spec.rb @@ -9,7 +9,7 @@ describe PhysicalTicketController do describe 'GET #show' do before :each do sign_in user - get :show, id: physical_ticket.id, conference_id: conference.short_title + get :show, id: physical_ticket.token, conference_id: conference.short_title end it 'assigns ticket_layout' do From 906f08baf867a11379061a70bb54cd516e6214ea Mon Sep 17 00:00:00 2001 From: siddhantbajaj Date: Mon, 17 Jul 2017 21:22:53 +0530 Subject: [PATCH 07/50] Send mail on ticket confirmation. Added mailer method to send ticket confirmation email along with the attached pdf for ticket. --- app/mailers/mailbot.rb | 16 ++++++++++++++++ app/models/ticket_purchase.rb | 1 + .../ticket_confirmation_template.text.erb | 8 ++++++++ 3 files changed, 25 insertions(+) create mode 100644 app/views/mailbot/ticket_confirmation_template.text.erb diff --git a/app/mailers/mailbot.rb b/app/mailers/mailbot.rb index 3d70f18d..f5b7f375 100644 --- a/app/mailers/mailbot.rb +++ b/app/mailers/mailbot.rb @@ -8,6 +8,22 @@ class Mailbot < ActionMailer::Base conference.email_settings.registration_body)) end + def ticket_confirmation_mail(ticket_purchase) + @ticket_purchase = ticket_purchase + @conference = ticket_purchase.conference + @user = ticket_purchase.user + + PhysicalTicket.last(ticket_purchase.quantity).each do |physical_ticket| + pdf = TicketPdf.new(@conference, @user, physical_ticket, @conference.ticket_layout.to_sym, "ticket_for_#{@conference.short_title}_#{physical_ticket.id}") + attachments["ticket_for_#{@conference.short_title}_#{physical_ticket.id}"] = pdf.render + end + + mail(to: @user.email, + from: @conference.contact.email, + template_name: 'ticket_confirmation_template', + subject: "#{@conference.title} | Ticket Confirmation and PDF!") + end + def acceptance_mail(event) conference = event.program.conference diff --git a/app/models/ticket_purchase.rb b/app/models/ticket_purchase.rb index a19678a7..a2ed2747 100644 --- a/app/models/ticket_purchase.rb +++ b/app/models/ticket_purchase.rb @@ -69,6 +69,7 @@ class TicketPurchase < ActiveRecord::Base PhysicalTicket.transaction do quantity.times { physical_tickets.create } end + Mailbot.ticket_confirmation_mail(self).deliver_later end end diff --git a/app/views/mailbot/ticket_confirmation_template.text.erb b/app/views/mailbot/ticket_confirmation_template.text.erb new file mode 100644 index 00000000..08f5175a --- /dev/null +++ b/app/views/mailbot/ticket_confirmation_template.text.erb @@ -0,0 +1,8 @@ +Dear <%= @user.name %>, + +Thanks! You have successfully booked <%= @ticket_purchase.quantity %> <%= @ticket_purchase.ticket.title %> ticket(s) for the event <%= @conference.title %>. Your transaction id is <%= @ticket_purchase.id %>. + +Please, find the ticket(s) pdf attached. + +Best wishes, +<%= @conference.title %> Team From 80a95442795a833db09d4a7614b0c77aa3058cd4 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Fri, 14 Jul 2017 21:09:28 +0530 Subject: [PATCH 08/50] move admin/users to be accessed only by site admins --- app/models/admin_ability.rb | 1 - spec/features/cfp_ability_spec.rb | 6 ++++++ spec/features/info_desk_ability_spec.rb | 6 ++++++ spec/features/organizer_ability_spec.rb | 6 ++++++ spec/models/admin_ability_spec.rb | 4 ++++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/models/admin_ability.rb b/app/models/admin_ability.rb index 4244d049..716aecb0 100644 --- a/app/models/admin_ability.rb +++ b/app/models/admin_ability.rb @@ -18,7 +18,6 @@ class AdminAbility end def common_abilities_for_roles(user) - can :manage, User, id: user.id can :manage, Registration, user_id: user.id can :index, Conference diff --git a/spec/features/cfp_ability_spec.rb b/spec/features/cfp_ability_spec.rb index 46db11c2..d40a54a4 100644 --- a/spec/features/cfp_ability_spec.rb +++ b/spec/features/cfp_ability_spec.rb @@ -269,6 +269,12 @@ feature 'Has correct abilities' do visit edit_admin_conference_resource_path(conference.short_title, conference.resources.first) expect(current_path).to eq(edit_admin_conference_resource_path(conference.short_title, conference.resources.first)) + visit admin_users_path + expect(current_path).to eq(root_path) + + visit admin_user_path(user_cfp) + expect(current_path).to eq(root_path) + visit admin_revision_history_path expect(current_path).to eq(root_path) end diff --git a/spec/features/info_desk_ability_spec.rb b/spec/features/info_desk_ability_spec.rb index 20aa586b..c005f9de 100644 --- a/spec/features/info_desk_ability_spec.rb +++ b/spec/features/info_desk_ability_spec.rb @@ -237,6 +237,12 @@ feature 'Has correct abilities' do visit admin_conference_program_tracks_path(conference.short_title) expect(current_path).to eq(root_path) + visit admin_users_path + expect(current_path).to eq(root_path) + + visit admin_user_path(user_info_desk) + expect(current_path).to eq(root_path) + visit admin_conference_emails_path(conference.short_title) expect(current_path).to eq(root_path) end diff --git a/spec/features/organizer_ability_spec.rb b/spec/features/organizer_ability_spec.rb index 06a2a836..3ed6ee39 100644 --- a/spec/features/organizer_ability_spec.rb +++ b/spec/features/organizer_ability_spec.rb @@ -266,6 +266,12 @@ feature 'Has correct abilities' do visit edit_admin_conference_resource_path(conference.short_title, conference.resources.first) expect(current_path).to eq(edit_admin_conference_resource_path(conference.short_title, conference.resources.first)) + visit admin_users_path + expect(current_path).to eq(root_path) + + visit admin_user_path(user_organizer) + expect(current_path).to eq(root_path) + visit admin_revision_history_path expect(current_path).to eq(admin_revision_history_path) end diff --git a/spec/models/admin_ability_spec.rb b/spec/models/admin_ability_spec.rb index 9baae4a9..5398b7d2 100644 --- a/spec/models/admin_ability_spec.rb +++ b/spec/models/admin_ability_spec.rb @@ -64,6 +64,10 @@ describe 'User with admin role' do it{ should_not be_able_to(:edit, Role.find_by(name: 'organization_admin', resource: other_organization)) } it{ should_not be_able_to(:show, Role.find_by(name: 'organization_admin', resource: other_organization)) } + it{ should_not be_able_to(:new, User.new) } + it{ should_not be_able_to(:create, User.new) } + it{ should_not be_able_to(:manage, User) } + %w[organizer cfp info_desk volunteers_coordinator].each do |role| it{ should_not be_able_to(:toggle_user, Role.find_by(name: role, resource: other_conference)) } it{ should_not be_able_to(:update, Role.find_by(name: role, resource: other_conference)) } From 50c66e2e0221b84aade66cb7aec5a5cb619b2d89 Mon Sep 17 00:00:00 2001 From: Wexpo Lyu Date: Fri, 4 Aug 2017 04:01:42 -0500 Subject: [PATCH 09/50] Explicitly add `.pdf` to make it a PDF file. Some SMTP providers would treat all files w/o suffix as `.txt`s. This patch would make it work in most cases. --- app/mailers/mailbot.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mailers/mailbot.rb b/app/mailers/mailbot.rb index f5b7f375..837e2c1e 100644 --- a/app/mailers/mailbot.rb +++ b/app/mailers/mailbot.rb @@ -15,7 +15,7 @@ class Mailbot < ActionMailer::Base PhysicalTicket.last(ticket_purchase.quantity).each do |physical_ticket| pdf = TicketPdf.new(@conference, @user, physical_ticket, @conference.ticket_layout.to_sym, "ticket_for_#{@conference.short_title}_#{physical_ticket.id}") - attachments["ticket_for_#{@conference.short_title}_#{physical_ticket.id}"] = pdf.render + attachments["ticket_for_#{@conference.short_title}_#{physical_ticket.id}.pdf"] = pdf.render end mail(to: @user.email, From a4b82bc83060897b60d002e46433cd8feb18680f Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Wed, 24 May 2017 18:43:40 +0300 Subject: [PATCH 10/50] Update sass-rails to 5.0.6 --- Gemfile.lock | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8f7ef5d6..ae118542 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -473,11 +473,12 @@ GEM rubyzip (1.2.1) safe_yaml (1.0.4) sass (3.2.19) - sass-rails (4.0.4) - railties (>= 4.0.0, < 5.0) - sass (~> 3.2.2) - sprockets (~> 2.8, < 2.12) - sprockets-rails (~> 2.0) + sass-rails (5.0.6) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) selectize-rails (0.12.4) shellany (0.0.1) shoulda-matchers (2.8.0) From da8b72343bce28269599ae6635af732b5b119037 Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Tue, 18 Jul 2017 10:15:53 +0300 Subject: [PATCH 11/50] Update font-awesome-rails to 4.7.0.2 --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ae118542..17f96de1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -180,8 +180,8 @@ GEM fastimage (2.0.0) addressable (~> 2) ffi (1.9.18) - font-awesome-rails (4.1.0.0) - railties (>= 3.2, < 5.0) + font-awesome-rails (4.7.0.2) + railties (>= 3.2, < 5.2) formatador (0.2.5) formtastic (3.1.3) actionpack (>= 3.2.13) From d94fdb2a28520e96f03d0a5192a00ba7086d2880 Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Tue, 18 Jul 2017 10:16:32 +0300 Subject: [PATCH 12/50] Update dotenv-rails to 2.2.1 --- Gemfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 17f96de1..3e2deeb4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -162,10 +162,10 @@ GEM docile (1.1.5) domain_name (0.5.20160310) unf (>= 0.0.5, < 1.0.0) - dotenv (2.1.1) - dotenv-rails (2.1.1) - dotenv (= 2.1.1) - railties (>= 4.0, < 5.1) + dotenv (2.2.1) + dotenv-rails (2.2.1) + dotenv (= 2.2.1) + railties (>= 3.2, < 5.2) erubis (2.7.0) execjs (2.6.0) factory_girl (4.5.0) From f74f2d3f52f9fb3a8c68cd50aab07192bad74c1e Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Wed, 24 May 2017 18:53:16 +0300 Subject: [PATCH 13/50] Update responders to 2.4.0 --- Gemfile.lock | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3e2deeb4..0b90d844 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -425,8 +425,9 @@ GEM redcarpet (3.2.3) referer-parser (0.2.1) request_store (1.1.0) - responders (2.1.1) - railties (>= 4.2.0, < 5.1) + responders (2.4.0) + actionpack (>= 4.2.0, < 5.3) + railties (>= 4.2.0, < 5.3) rest-client (1.8.0) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 3.0) From d9649a4446bce677eebc753636bb00bd66069063 Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Wed, 24 May 2017 19:36:42 +0300 Subject: [PATCH 14/50] Update jquery-rails to 4.3.1 --- Gemfile.lock | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0b90d844..d8c8c850 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -235,8 +235,9 @@ GEM jquery-datatables-rails (2.2.3) jquery-rails sass-rails - jquery-rails (3.1.4) - railties (>= 3.0, < 5.0) + jquery-rails (4.3.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) thor (>= 0.14, < 2.0) jquery-ui-rails (4.2.1) railties (>= 3.2.16) From 7e2bb8043f2612a16ec49e20defdb57a405f2c90 Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Wed, 24 May 2017 19:49:48 +0300 Subject: [PATCH 15/50] Update coffee-rails to 4.2.2 --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d8c8c850..216b7dc0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -117,13 +117,13 @@ GEM rest-client cocoon (1.2.6) coderay (1.1.1) - coffee-rails (4.1.1) + coffee-rails (4.2.2) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.1.x) + railties (>= 4.0.0) coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.10.0) + coffee-script-source (1.12.2) countable-rails (0.0.1) railties (>= 3.1) countries (1.2.5) From 57f450e857f19d36a86ee61c38aa33165d06c4cb Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Wed, 24 May 2017 20:26:50 +0300 Subject: [PATCH 16/50] Update delayed_job_active_record to 4.1.2 --- Gemfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 216b7dc0..8246c724 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -145,10 +145,10 @@ GEM dante (0.2.0) database_cleaner (1.3.0) debug_inspector (0.0.2) - delayed_job (4.1.1) - activesupport (>= 3.0, < 5.0) - delayed_job_active_record (4.1.0) - activerecord (>= 3.0, < 5) + delayed_job (4.1.3) + activesupport (>= 3.0, < 5.2) + delayed_job_active_record (4.1.2) + activerecord (>= 3.0, < 5.2) delayed_job (>= 3.0, < 5) devise (4.2.0) bcrypt (~> 3.0) From 4e1d45382cb27affaacf38920cd6de60fbb7c709 Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Wed, 24 May 2017 20:35:38 +0300 Subject: [PATCH 17/50] Update awesome_nested_set to 3.1.3 --- Gemfile | 2 +- Gemfile.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 1b0a3c1d..08170e30 100644 --- a/Gemfile +++ b/Gemfile @@ -57,7 +57,7 @@ gem 'unobtrusive_flash', '>=3' gem 'transitions', :require => %w( transitions active_record/transitions ) # for comments -gem 'awesome_nested_set', '~> 3.0.0.rc.5' +gem 'awesome_nested_set', '~> 3.1.3' gem 'acts_as_commentable_with_threading' # as templating language diff --git a/Gemfile.lock b/Gemfile.lock index 8246c724..85e7438f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -72,8 +72,8 @@ GEM autoprefixer-rails (5.1.9) execjs json - awesome_nested_set (3.0.0.rc.5) - activerecord (>= 4.0.0, < 5) + awesome_nested_set (3.1.3) + activerecord (>= 4.0.0, < 5.2) aws_cf_signer (0.1.3) axlsx_rails (0.2.0) axlsx (>= 2.0.1) @@ -569,7 +569,7 @@ DEPENDENCIES acts_as_list ahoy_matey autoprefixer-rails - awesome_nested_set (~> 3.0.0.rc.5) + awesome_nested_set (~> 3.1.3) axlsx! axlsx_rails bootstrap-sass (~> 3.3.4.1) From 27996531248eadeb3437fc34d30a817db5f21963 Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Wed, 24 May 2017 21:05:24 +0300 Subject: [PATCH 18/50] Update omniauth to 1.6.1 --- Gemfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 85e7438f..1288d067 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -219,7 +219,7 @@ GEM rubocop (>= 0.47.0) sysexits (~> 1.1) hashdiff (0.3.4) - hashie (2.1.1) + hashie (3.5.5) hike (1.2.3) hoptoad_notifier (2.4.11) activesupport @@ -302,9 +302,9 @@ GEM multi_json (~> 1.3) multi_xml (~> 0.5) rack (~> 1.2) - omniauth (1.2.1) - hashie (>= 1.2, < 3) - rack (~> 1.0) + omniauth (1.6.1) + hashie (>= 3.4.6, < 3.6.0) + rack (>= 1.6.2, < 3) omniauth-facebook (1.6.0) omniauth-oauth2 (~> 1.1) omniauth-github (1.1.2) From 2824336ead6f6ed5ea938f3410168df63ec15433 Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Wed, 24 May 2017 21:49:53 +0300 Subject: [PATCH 19/50] Update sprockets to 3.7.1 --- Gemfile.lock | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1288d067..ecc7ec98 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -124,6 +124,7 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) + concurrent-ruby (1.0.5) countable-rails (0.0.1) railties (>= 3.1) countries (1.2.5) @@ -220,7 +221,6 @@ GEM sysexits (~> 1.1) hashdiff (0.3.4) hashie (3.5.5) - hike (1.2.3) hoptoad_notifier (2.4.11) activesupport builder @@ -497,11 +497,9 @@ GEM spring (1.6.3) spring-commands-rspec (1.0.4) spring (>= 0.9.1) - sprockets (2.11.3) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) + sprockets (3.7.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) sprockets-rails (2.3.3) actionpack (>= 3.0) activesupport (>= 3.0) From cb8010bafe3bb914c0ca72ea4f49879a486c1fe9 Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Wed, 24 May 2017 22:03:39 +0300 Subject: [PATCH 20/50] Update omniauth-oauth2 to 1.4.0 --- Gemfile.lock | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ecc7ec98..8a1c97f7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -296,12 +296,12 @@ GEM notiffany (0.1.1) nenv (~> 0.1) shellany (~> 0.0) - oauth2 (0.9.4) - faraday (>= 0.8, < 0.10) + oauth2 (1.3.1) + faraday (>= 0.8, < 0.12) jwt (~> 1.0) multi_json (~> 1.3) multi_xml (~> 0.5) - rack (~> 1.2) + rack (>= 1.2, < 3) omniauth (1.6.1) hashie (>= 3.4.6, < 3.6.0) rack (>= 1.6.2, < 3) @@ -313,10 +313,8 @@ GEM omniauth-google-oauth2 (0.2.4) omniauth (~> 1.0) omniauth-oauth2 (~> 1.1) - omniauth-oauth2 (1.1.2) - faraday (>= 0.8, < 0.10) - multi_json (~> 1.3) - oauth2 (~> 0.9.3) + omniauth-oauth2 (1.4.0) + oauth2 (~> 1.0) omniauth (~> 1.2) omniauth-openid (1.0.1) omniauth (~> 1.0) From 9b7562fe2e394a47bc4c91c3666fbe09556cba7b Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Sun, 4 Jun 2017 19:50:48 +0300 Subject: [PATCH 21/50] Update autoprefixer-rails to 7.1.1 --- Gemfile.lock | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8a1c97f7..faaa8246 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -69,9 +69,8 @@ GEM uuidtools arel (6.0.4) ast (2.3.0) - autoprefixer-rails (5.1.9) + autoprefixer-rails (7.1.1) execjs - json awesome_nested_set (3.1.3) activerecord (>= 4.0.0, < 5.2) aws_cf_signer (0.1.3) From 033dbe4c40fd9c428b0167e84668c11e127de9e7 Mon Sep 17 00:00:00 2001 From: Wexpo Lyu Date: Fri, 4 Aug 2017 01:01:36 -0500 Subject: [PATCH 22/50] Fix the dropdown to get enough bottom padding. --- app/assets/stylesheets/osem-navbar.css.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/stylesheets/osem-navbar.css.scss b/app/assets/stylesheets/osem-navbar.css.scss index ef05c0a9..bfaac9ac 100644 --- a/app/assets/stylesheets/osem-navbar.css.scss +++ b/app/assets/stylesheets/osem-navbar.css.scss @@ -29,7 +29,7 @@ } } .dropdown-menu { - padding: 17px 17px 0px 17px; + padding: 17px; min-width: 225px; } } From 32c5af2a17f08162e113c8d32298b71b9839a0e9 Mon Sep 17 00:00:00 2001 From: nasia Date: Thu, 20 Jul 2017 14:20:46 +0300 Subject: [PATCH 23/50] Add booths to non admin --- .haml-lint_todo.yml | 6 +- .rubocop_todo.yml | 2 + app/controllers/admin/booths_controller.rb | 22 ++-- app/controllers/booths_controller.rb | 97 +++++++++++++++ app/helpers/format_helper.rb | 13 +++ app/models/ability.rb | 6 + app/models/booth.rb | 10 +- app/views/admin/booths/_form.html.haml | 33 ------ app/views/admin/booths/edit.html.haml | 2 +- app/views/admin/booths/index.html.haml | 11 +- app/views/admin/booths/new.html.haml | 2 +- app/views/admin/booths/show.html.haml | 3 +- app/views/booths/_form.html.haml | 30 +++++ app/views/booths/edit.html.haml | 6 + app/views/booths/index.html.haml | 51 ++++++++ app/views/booths/new.html.haml | 4 + app/views/booths/show.html.haml | 60 ++++++++++ config/routes.rb | 8 +- .../admin/booths_controller_spec.rb | 18 --- spec/controllers/booths_controller_spec.rb | 110 ++++++++++++++++++ spec/factories/booths.rb | 1 + spec/models/booth_spec.rb | 17 +-- 22 files changed, 426 insertions(+), 86 deletions(-) create mode 100644 app/controllers/booths_controller.rb delete mode 100644 app/views/admin/booths/_form.html.haml create mode 100644 app/views/booths/_form.html.haml create mode 100644 app/views/booths/edit.html.haml create mode 100644 app/views/booths/index.html.haml create mode 100644 app/views/booths/new.html.haml create mode 100644 app/views/booths/show.html.haml create mode 100644 spec/controllers/booths_controller_spec.rb diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index b42ccb06..52d5f5ca 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -11,7 +11,6 @@ linters: # Offense count: 945 LineLength: exclude: - - "app/views/admin/booths/_form.html.haml" - "app/views/admin/booths/index.html.haml" - "app/views/admin/booths/show.html.haml" - "app/views/admin/campaigns/_form.html.haml" @@ -109,6 +108,9 @@ linters: - "app/views/admin/versions/_object_desc_and_link.html.haml" - "app/views/admin/versions/index.html.haml" - "app/views/admin/volunteers/index.html.haml" + - "app/views/booths/_form.html.haml" + - "app/views/booths/index.html.haml" + - "app/views/booths/show.html.haml" - "app/views/commercials/edit.html.haml" - "app/views/commercials/new.html.haml" - "app/views/conference_registrations/_form.html.haml" @@ -369,6 +371,7 @@ linters: - "app/views/admin/tracks/show.html.haml" - "app/views/admin/venues/show.html.haml" - "app/views/admin/versions/index.html.haml" + - "app/views/booths/index.html.haml" - "app/views/conference_registrations/_form.html.haml" - "app/views/conference_registrations/_ticket.html.haml" - "app/views/conference_registrations/show.html.haml" @@ -397,6 +400,7 @@ linters: - "app/views/admin/schedules/_day_tab.html.haml" - "app/views/admin/schedules/_event.html.haml" - "app/views/admin/versions/_object_desc_and_link.html.haml" + - "app/views/booths/index.html.haml" - "app/views/schedules/_carousel.html.haml" # Offense count: 29 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7a9ab03c..8d752446 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -333,6 +333,8 @@ Metrics/MethodLength: # Configuration parameters: CountComments. Metrics/ModuleLength: Max: 159 + Exclude: + - 'app/helpers/format_helper.rb' # Offense count: 15 Metrics/PerceivedComplexity: diff --git a/app/controllers/admin/booths_controller.rb b/app/controllers/admin/booths_controller.rb index f5096c34..e5b55552 100644 --- a/app/controllers/admin/booths_controller.rb +++ b/app/controllers/admin/booths_controller.rb @@ -7,9 +7,13 @@ module Admin def show; end - def new; end + def new + @url = admin_conference_booths_path(@conference.short_title) + end def create + @url = admin_conference_booths_path(@conference.short_title) + @booth = @conference.booths.new(booth_params) @booth.submitter = current_user @@ -23,9 +27,13 @@ module Admin end end - def edit; end + def edit + @url = admin_conference_booth_path(@conference.short_title, @booth.id) + end def update + @url = admin_conference_booth_path(@conference.short_title, @booth.id) + @booth.update_attributes(booth_params) if @booth.save @@ -38,16 +46,6 @@ module Admin end end - def destroy - if @booth.destroy - redirect_to admin_conference_booths_path, - notice: 'Booth successfully destroyed.' - else - redirect_to admin_conference_booths_path, - error: "Booth couldn't be deleted. #{@booth.errors.full_messages.join('. ')}." - end - end - def accept update_state(:accept, 'Booth accepted!') end diff --git a/app/controllers/booths_controller.rb b/app/controllers/booths_controller.rb new file mode 100644 index 00000000..99fde3bc --- /dev/null +++ b/app/controllers/booths_controller.rb @@ -0,0 +1,97 @@ +class BoothsController < ApplicationController + before_action :authenticate_user! + load_resource :conference, find_by: :short_title + load_and_authorize_resource through: :conference + skip_authorize_resource only: [:withdraw, :confirm, :restart] + + def index + @booths = current_user.booths.where(conference_id: @conference.id).uniq + end + + def show; end + + def new + @url = conference_booths_path(@conference.short_title) + end + + def create + @url = conference_booths_path(@conference.short_title) + + @booth.submitter = current_user + + if @booth.save + redirect_to conference_booths_path, + notice: 'Booth successfully created.' + else + flash[:error] = "Creating booth failed. #{@booth.errors.full_messages.to_sentence}." + render :new + end + end + + def edit + @url = conference_booth_path(@conference.short_title, @booth.id) + end + + def update + @url = conference_booth_path(@conference.short_title, @booth.id) + @booth.update_attributes(booth_params) + + if @booth.save + redirect_to conference_booths_path, + notice: 'Booth successfully updated!' + else + flash[:error] = "Booth could not be updated. #{@booth.errors.full_messages.to_sentence}." + end + end + + def destroy; end + + def withdraw + authorize! :update, @booth + @url = conference_booth_path(@conference.short_title, @booth.id) + + @booth.withdraw! + + if @booth.save + redirect_to conference_booths_path, + notice: 'Booth successfully withdrawn' + else + flash[:error] = "Booth could not be withdrawn. #{@booth.errors.full_messages.to_sentence}." + end + end + + def confirm + authorize! :update, @booth + @url = conference_booth_path(@conference.short_title, @booth.id) + + @booth.confirm! + + if @booth.save + redirect_to conference_booths_path, + notice: 'Booth successfully confirmed' + else + flash[:error] = "Booth could not be confirmed. #{@booth.errors.full_messages.to_sentence}." + end + end + + def restart + authorize! :update, @booth + @url = conference_booth_path(@conference.short_title, @booth.id) + + @booth.restart! + + if @booth.save + redirect_to conference_booths_path, + notice: 'Booth successfully re-submitted' + else + flash[:error] = "Booth could not be re-submitted. #{@booth.errors.full_messages.to_sentence}." + end + end + + private + + def booth_params + params.require(:booth).permit(:title, :description, :reasoning, :state, :picture, :conference_id, + :created_at, :updated_at, :submitter_relationship, :website_url, responsible_ids: []) + end +end diff --git a/app/helpers/format_helper.rb b/app/helpers/format_helper.rb index 334c70bf..65578ba6 100644 --- a/app/helpers/format_helper.rb +++ b/app/helpers/format_helper.rb @@ -15,6 +15,19 @@ module FormatHelper end end + def booth_status_icon(booth) + case booth.state + when 'new', 'to_reject', 'to_accept' + 'fa-eye' + when 'accepted' + 'fa-check text-muted' + when 'confirmed' + 'fa-check text-success' + when 'rejected', 'withdrawn', 'canceled' + 'fa-ban' + end + end + def event_progress_color(progress) progress = progress.to_i if progress == 100 diff --git a/app/models/ability.rb b/app/models/ability.rb index afc51a68..0ebabfdc 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -75,6 +75,12 @@ class Ability can [:new, :create], Payment, user_id: user.id can [:index, :show], PhysicalTicket, user: user + can [:new, :create], Booth + + can [:edit, :update, :index, :show], Booth do |booth| + booth.users.include?(user) + end + can [:create, :destroy], Subscription, user_id: user.id can [:new, :create], Event do |event| diff --git a/app/models/booth.rb b/app/models/booth.rb index 5c20550a..853bca9e 100644 --- a/app/models/booth.rb +++ b/app/models/booth.rb @@ -35,12 +35,16 @@ class Booth < ActiveRecord::Base state :to_reject state :rejected state :canceled + state :confirmed event :restart do - transitions to: :new, from: [:withdrawn, :to_accept, :to_reject, :canceled] + transitions to: :new, from: [:withdrawn, :rejected, :canceled] end event :withdraw do - transitions to: :withdrawn, from: [:new, :to_accept, :accepted, :to_reject, :rejected] + transitions to: :withdrawn, from: [:new, :to_accept, :accepted, :to_reject, :rejected, :confirmed] + end + event :confirm do + transitions to: :confirmed, from: [:accepted] end event :to_accept do transitions to: :to_accept, from: [:new, :to_reject] @@ -55,7 +59,7 @@ class Booth < ActiveRecord::Base transitions to: :rejected, from: [:new, :to_reject] end event :cancel do - transitions to: :canceled, from: [:accepted, :rejected, :to_accept, :to_reject] + transitions to: :canceled, from: [:accepted, :rejected, :to_accept, :to_reject, :confirmed] end end diff --git a/app/views/admin/booths/_form.html.haml b/app/views/admin/booths/_form.html.haml deleted file mode 100644 index f70079fa..00000000 --- a/app/views/admin/booths/_form.html.haml +++ /dev/null @@ -1,33 +0,0 @@ -.row - .col-md-12 - .page-header - %title Request a Booth -.row - .col-md-8 - = semantic_form_for(@booth, url: @booth.new_record? ? admin_conference_booths_path(@conference.short_title) : admin_conference_booth_path(@conference.short_title, @booth.id), html: { multipart: true }) do |f| - = f.input :title, as: :string, autofocus: true, required: true - = f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true, - hint: 'This field becomes public upon request acceptance' - = f.input :reasoning, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true, - label: 'How it fits the conference' - = f.input :submitter_relationship, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true, - label: 'Submitter\'s relation', - hint: 'e.g. employee, comunity manager, etc' - = f.input :website_url - = responsibles_selector_input f - = image_tag f.object.picture.thumb.url if f.object.picture? - = f.input :picture - - %p.text-right - - if @booth.new_record? - = f.submit 'Create Booth Request', class: 'btn btn-success' - - else - = f.submit 'Update Booth Request', class: 'btn btn-success' - -:javascript - $(document).ready(function() { - $('#booth_responsible_ids').selectize({ - plugins: ['remove_button'], - minItems: 2 - } ) - }); diff --git a/app/views/admin/booths/edit.html.haml b/app/views/admin/booths/edit.html.haml index 9f9a5a61..0cac17e7 100644 --- a/app/views/admin/booths/edit.html.haml +++ b/app/views/admin/booths/edit.html.haml @@ -2,4 +2,4 @@ Editing = @booth.title -= render 'form' += render 'booths/form' diff --git a/app/views/admin/booths/index.html.haml b/app/views/admin/booths/index.html.haml index 15833bd7..27f505ad 100644 --- a/app/views/admin/booths/index.html.haml +++ b/app/views/admin/booths/index.html.haml @@ -41,8 +41,9 @@ = link_to booth.submitter.name, admin_user_path(booth.submitter) if booth.submitter %td .responsibles - - booth.responsibles.each do |responsible| + - booth.responsibles.each_with_index do |responsible, i| = link_to responsible.name, admin_user_path(responsible) + = ", " unless i == booth.responsibles.length - 1 %td .btn-group %button{ type: 'button', class: 'btn btn-link dropdown-toggle', 'data-toggle' => 'dropdown' } @@ -51,9 +52,5 @@ %ul.dropdown-menu{ role: 'menu' } = render 'change_state_dropdown', booth: booth %td - .btn-group{ role: "group" } - = link_to 'Edit', edit_admin_conference_booth_path(@conference.short_title, booth.id), - class: 'btn btn-primary' - = link_to 'Delete', admin_conference_booth_path(@conference.short_title, booth.id), - method: :delete, class: 'btn btn-danger', - data: {confirm: "Do you really want to delete this booth request?"} + = link_to 'Edit', edit_admin_conference_booth_path(@conference.short_title, booth.id), + class: 'btn btn-primary' diff --git a/app/views/admin/booths/new.html.haml b/app/views/admin/booths/new.html.haml index db1c4736..99ec9b20 100644 --- a/app/views/admin/booths/new.html.haml +++ b/app/views/admin/booths/new.html.haml @@ -1,3 +1,3 @@ %h1 New booth -= render 'form' += render 'booths/form' diff --git a/app/views/admin/booths/show.html.haml b/app/views/admin/booths/show.html.haml index 8c692bc4..6ed823e5 100644 --- a/app/views/admin/booths/show.html.haml +++ b/app/views/admin/booths/show.html.haml @@ -39,12 +39,13 @@ %td.col-md-2 %b Responsibles %td - - @booth.responsibles.each do |responsibles| + - @booth.responsibles.each_with_index do |responsibles, i| .responsibles = link_to responsibles.name, admin_user_path(responsibles) ( = responsibles.email ) + = " , " unless i == @booth.responsibles.length - 1 %tr %td.col-md-2 %b Submitted on diff --git a/app/views/booths/_form.html.haml b/app/views/booths/_form.html.haml new file mode 100644 index 00000000..55a51432 --- /dev/null +++ b/app/views/booths/_form.html.haml @@ -0,0 +1,30 @@ +.container + .row + .col-md-8 + = semantic_form_for(@booth, url: @url, html: { multipart: true }) do |f| + = f.input :title, as: :string, autofocus: true, required: true + = f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true, + hint: 'This field becomes public upon request acceptance' + = f.input :reasoning, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true, + label: 'How it fits the conference' + = f.input :submitter_relationship, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true, + label: 'Submitter\'s relation', + hint: 'e.g. employee, comunity manager, etc' + = f.input :website_url + = responsibles_selector_input f + = image_tag f.object.picture.thumb.url if f.object.picture? + = f.input :picture + + %p.text-right + - if @booth.new_record? + = f.submit 'Create Booth Request', class: 'btn btn-success' + - else + = f.submit 'Update Booth Request', class: 'btn btn-success' + + :javascript + $(document).ready(function() { + $('#booth_responsible_ids').selectize({ + plugins: ['remove_button'], + minItems: 2 + } ) + }); diff --git a/app/views/booths/edit.html.haml b/app/views/booths/edit.html.haml new file mode 100644 index 00000000..9f60196d --- /dev/null +++ b/app/views/booths/edit.html.haml @@ -0,0 +1,6 @@ +.container + %h1 + Editing + = @booth.title + + = render 'form' diff --git a/app/views/booths/index.html.haml b/app/views/booths/index.html.haml new file mode 100644 index 00000000..d6c392dd --- /dev/null +++ b/app/views/booths/index.html.haml @@ -0,0 +1,51 @@ +.container + .row + .col-md-12.page-header + %h1 + Your booth requests for + = @conference.title + .row + .col-md-12 + .margin-booth-table + %table.table.table-striped.table-hover + %thead + %th + %b State + %th + %b Logo + %th + %b Title + %th + %b Actions + - @booths.each do |booth| + %tr + %td{ style: "padding:20px 8px 20px 8px;" } + - if (booth.state == 'to_accept' || booth.state == 'to_reject') + - show_state = 'new' + - else + - show_state = booth.state + %span{ title: show_state, class: "fa #{booth_status_icon(booth)}" } + %td + - if booth.logo_link + = image_tag(booth.picture.thumb.url, width: '20%') + %td + = link_to booth.title, conference_booth_path(@conference.short_title, booth) + %td + -if can? :edit, booth + = link_to 'Edit', edit_conference_booth_path(@conference.short_title, booth.id), + class: 'btn btn-default' + - if booth.transition_possible? :withdraw + = link_to 'Withdraw', + withdraw_conference_booth_path(@conference.short_title, booth), + method: :patch, class: 'btn btn-mini btn-warning', id: "withdraw_booth_#{booth.id}", + data: { confirm: 'Are you sure you really want to withdraw this request?' } + - if booth.transition_possible? :confirm + = link_to 'Confirm', + confirm_conference_booth_path(@conference.short_title, booth), + method: :patch, class: 'btn btn-mini btn-success', id: "confirm_booth_#{booth.id}" + - if booth.transition_possible? :restart + = link_to 'Re-submit', + restart_conference_booth_path(@conference.short_title, booth), + method: :patch, class: 'btn btn-mini btn-success', id: "restart_booth_#{booth.id}" + .pull-right + = link_to 'Add Booth', new_conference_booth_path(@conference.short_title), class: 'button btn btn-primary' diff --git a/app/views/booths/new.html.haml b/app/views/booths/new.html.haml new file mode 100644 index 00000000..169efd17 --- /dev/null +++ b/app/views/booths/new.html.haml @@ -0,0 +1,4 @@ +.container + %h1 Request a booth + + = render 'form' diff --git a/app/views/booths/show.html.haml b/app/views/booths/show.html.haml new file mode 100644 index 00000000..6b12229d --- /dev/null +++ b/app/views/booths/show.html.haml @@ -0,0 +1,60 @@ +.container + .row + .col-md-12 + %h3 + - if @booth.logo_link + = image_tag(@booth.picture.thumb.url, size: '20%', alt: '') + = @booth.title + .btn-group.pull-right + = link_to 'Edit', edit_admin_conference_booth_path(@conference.short_title, @booth), class: 'btn btn-mini btn-primary' + + .row + .col-md-12 + %table.table + %tr + %td.col-md-2 + %b Description + %td + = markdown(@booth.description) + %tr + %td.col-md-2 + %b Reasoning + %td + = markdown(@booth.reasoning) + %tr + %td.col-md-2 + %b Website + %td + - if @booth.website_url.present? + = link_to @booth.website_url, @booth.website_url + %tr + %td.col-md-2 + %b Submitter + %td + = link_to @booth.submitter.name, user_path(@booth.submitter) + %tr + %td.col-md-2 + %b Submitter's relationship + %td + = @booth.submitter_relationship + %tr + %td.col-md-2 + %b Responsibles + %td + - @booth.responsibles.each_with_index do |responsibles, i| + .responsibles + = link_to responsibles.name, user_path(responsibles) + ( + = responsibles.email + ) + = ", " unless i == @booth.responsibles.length - 1 + %tr + %td.col-md-2 + %b Submitted on + %td + = @booth.created_at + %tr + %td.col-md-2 + %b Last updated on + %td + = @booth.updated_at diff --git a/config/routes.rb b/config/routes.rb index 5a17d314..be507d35 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -41,7 +41,6 @@ Osem::Application.routes.draw do member do patch :accept patch :restart - patch :withdrawn patch :to_accept patch :reject patch :reset @@ -131,6 +130,13 @@ Osem::Application.routes.draw do end resources :organizations, only: [:index] resources :conferences, only: [:index, :show] do + resources :booths do + member do + patch :withdraw + patch :confirm + patch :restart + end + end resource :program, only: [] do resources :proposals, except: :destroy do get 'commercials/render_commercial' => 'commercials#render_commercial' diff --git a/spec/controllers/admin/booths_controller_spec.rb b/spec/controllers/admin/booths_controller_spec.rb index 569862d1..37004531 100644 --- a/spec/controllers/admin/booths_controller_spec.rb +++ b/spec/controllers/admin/booths_controller_spec.rb @@ -126,23 +126,5 @@ describe Admin::BoothsController do end end end - - describe 'DELETE #destroy' do - context 'deletes successfully' do - before { delete :destroy, id: booth.id, conference_id: conference.short_title } - - it 'booth deleted' do - expect(Booth.count).to eq(0) - end - - it 'redirects to admin booth index path' do - expect(response).to redirect_to(admin_conference_booths_path) - end - - it 'show success message' do - expect(flash[:notice]).to match('Booth successfully destroyed.') - end - end - end end end diff --git a/spec/controllers/booths_controller_spec.rb b/spec/controllers/booths_controller_spec.rb new file mode 100644 index 00000000..243bc6e2 --- /dev/null +++ b/spec/controllers/booths_controller_spec.rb @@ -0,0 +1,110 @@ +require 'spec_helper' + +describe BoothsController do + + let(:user) { create(:user) } + let(:conference) { create(:conference) } + let(:booth) { create(:booth, title: 'Title', conference: conference) } + + context 'user is signed in with submitter role' do + before :each do + sign_in booth.submitter + end + + describe 'GET index' do + before { get :index, conference_id: conference.short_title } + + it 'assigns attributes for booths' do + expect(assigns(:booths)).to eq([booth]) + end + + it 'renders index template' do + expect(response).to render_template('index') + end + end + + describe 'GET #new' do + before { get :new, conference_id: conference.short_title } + + it 'assigns attributes for booths' do + expect(assigns(:booth)).to be_a_new(Booth) + end + + it 'renders new template' do + expect(response).to render_template('new') + end + end + + describe 'POST #create' do + context 'successfully created' do + before { post :create, booth: attributes_for(:booth), conference_id: conference.short_title } + + it 'creates a new booth' do + expect(Booth.count).to_not eq(0) + end + + it 'redirects to booth index' do + expect(response).to redirect_to(conference_booths_path) + end + + it 'has responsibles' do + expect(booth.responsibles.count).to_not eq(0) + end + + it 'shows success message' do + expect(flash[:notice]).to match('Booth successfully created.') + end + end + + context 'create action fails' do + before { post :create, booth: attributes_for(:booth, title: ''), conference_id: conference.short_title } + + it 'does not create any record' do + expected = expect do + post :create, booth: attributes_for(:booth, title: ''), conference_id: conference.short_title + end + expected.to_not change(Booth, :count) + end + + it 'redirects to new' do + expect(response).to render_template('new') + end + + it 'shows flash message' do + expect(flash[:error]).to eq("Creating booth failed. Title can't be blank.") + end + end + end + + describe 'GET #edit' do + before { get :edit, id: booth.id, conference_id: conference.short_title } + + it 'renders edit template' do + expect(response).to render_template('edit') + end + + it 'assigns booth variable' do + expect(assigns(:booth)).to eq booth + end + end + + describe 'PATCH #update' do + context 'updates suchessfully' do + before { patch :update, id: booth.id, booth: attributes_for(:booth, title: 'different'), conference_id: conference.short_title } + + it 'redirects to booth index path' do + expect(response).to redirect_to conference_booths_path + end + + it 'shows success message' do + expect(flash[:notice]).to match 'Booth successfully updated!' + end + + it 'updates booth' do + booth.reload + expect(booth.title).to eq('different') + end + end + end + end +end diff --git a/spec/factories/booths.rb b/spec/factories/booths.rb index b1cd1956..1ac3ff87 100644 --- a/spec/factories/booths.rb +++ b/spec/factories/booths.rb @@ -8,6 +8,7 @@ FactoryGirl.define do conference + submitter { create(:user) } responsible_ids { [create(:user).id] } end end diff --git a/spec/models/booth_spec.rb b/spec/models/booth_spec.rb index 5e86a393..287653ac 100644 --- a/spec/models/booth_spec.rb +++ b/spec/models/booth_spec.rb @@ -33,16 +33,17 @@ describe 'Booth' do end end - states = [:new, :withdrawn, :to_accept, :accepted, :to_reject, :rejected, :canceled] + states = [:new, :withdrawn, :to_accept, :accepted, :to_reject, :rejected, :canceled, :confirmed] transitions = [:restart, :withdraw, :accept, :reject, :to_accept, :to_reject, :cancel] - states_transitions = { new: { restart: false, withdraw: true, accept: true, to_accept: true, to_reject: true, reject: true, cancel: false }, - withdrawn: { restart: true, withdraw: false, accept: false, to_accept: false, to_reject: false, reject: false, cancel: false }, - to_accept: { restart: true, withdraw: true, accept: true, to_accept: false, to_reject: true, reject: false, cancel: true }, - to_reject: { restart: true, withdraw: true, accept: false, to_accept: true, to_reject: false, reject: true, cancel: true }, - accepted: { restart: false, withdraw: true, accept: false, to_accept: false, to_reject: false, reject: false, cancel: true }, - rejected: { restart: false, withdraw: true, accept: false, to_accept: false, to_reject: false, reject: false, cancel: true }, - canceled: { restart: true, withdraw: false, accept: false, to_accept: false, to_reject: false, reject: false, cancel: false } } + states_transitions = { new: { restart: false, withdraw: true, accept: true, to_accept: true, to_reject: true, reject: true, cancel: false, confirm: false }, + withdrawn: { restart: true, withdraw: false, accept: false, to_accept: false, to_reject: false, reject: false, cancel: false, confirm: false }, + to_accept: { restart: false, withdraw: true, accept: true, to_accept: false, to_reject: true, reject: false, cancel: true, confirm: false }, + to_reject: { restart: false, withdraw: true, accept: false, to_accept: true, to_reject: false, reject: true, cancel: true, confirm: false }, + accepted: { restart: false, withdraw: true, accept: false, to_accept: false, to_reject: false, reject: false, cancel: true, confirm: true }, + rejected: { restart: true, withdraw: true, accept: false, to_accept: false, to_reject: false, reject: false, cancel: true, confirm: false }, + canceled: { restart: true, withdraw: false, accept: false, to_accept: false, to_reject: false, reject: false, cancel: false, confirm: false }, + confirmed: { restart: false, withdraw: true, accept: false, to_accept: false, to_reject: false, reject: false, cancel: true, confirm: false } } states.each do |state| transitions.each do |transition| From 540c982771ea96c4f17e563179139e976519c3ea Mon Sep 17 00:00:00 2001 From: shlok007 Date: Thu, 13 Jul 2017 04:02:13 +0530 Subject: [PATCH 24/50] mention organization in dashboard, splashpage and admin/conference#edit --- app/views/admin/conferences/edit.html.haml | 1 + app/views/admin/conferences/show.html.haml | 2 +- app/views/conferences/show.html.haml | 3 +++ spec/features/conference_spec.rb | 9 +++++++++ spec/features/splashpage_spec.rb | 11 +++++++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/views/admin/conferences/edit.html.haml b/app/views/admin/conferences/edit.html.haml index 2d5df126..49d65235 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 :organization, hint: 'The organization in which this conference belongs', input_html: { disabled: true } = 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/show.html.haml b/app/views/admin/conferences/show.html.haml index cddae4c2..f270867b 100644 --- a/app/views/admin/conferences/show.html.haml +++ b/app/views/admin/conferences/show.html.haml @@ -1,6 +1,6 @@ %h1 %span.fa.fa-tachometer - Dashboard for #{@conference.title} + Dashboard for #{@conference.title} ( by #{@conference.organization.name} ) %hr .row .col-sm-4.col-xs-4 diff --git a/app/views/conferences/show.html.haml b/app/views/conferences/show.html.haml index fb488e22..b133c26a 100644 --- a/app/views/conferences/show.html.haml +++ b/app/views/conferences/show.html.haml @@ -22,6 +22,9 @@ .col-md-8 %h1 = @conference.title + %h3 + %i + = "( by #{@conference.organization.name} )" %p.lead - if @conference.venue = "#{@conference.venue.city} / #{@conference.venue.country_name}" diff --git a/spec/features/conference_spec.rb b/spec/features/conference_spec.rb index d17ce5fc..5b9f9c54 100644 --- a/spec/features/conference_spec.rb +++ b/spec/features/conference_spec.rb @@ -71,6 +71,15 @@ feature Conference do end describe 'admin' do + let!(:conference) { create(:conference) } + + scenario 'has organization name in edit form', feature: true, js: true do + sign_in user + visit edit_admin_conference_path(conference.short_title) + org_id = find('#conference_organization_id').value + expect(Organization.find(org_id)).to eq conference.organization + end + it_behaves_like 'add and update conference' end end diff --git a/spec/features/splashpage_spec.rb b/spec/features/splashpage_spec.rb index e913d023..ee9b63d5 100644 --- a/spec/features/splashpage_spec.rb +++ b/spec/features/splashpage_spec.rb @@ -61,4 +61,15 @@ feature Splashpage do expect(current_path).to eq(root_path) end end + + context 'public splashpage already created' do + let!(:splashpage) { create(:splashpage, conference: conference, public: true)} + + scenario 'should have organization name', feature: true, js: true do + sign_in participant + visit conference_path(conference.short_title) + + expect(page).to have_text(conference.organization.name) + end + end end From cdc08052b140fc1bca6bb8847f40a4e61a1e169f Mon Sep 17 00:00:00 2001 From: shlok007 Date: Mon, 24 Jul 2017 13:46:09 +0530 Subject: [PATCH 25/50] display organization name in menu bar --- app/views/admin/conferences/edit.html.haml | 1 - app/views/conferences/show.html.haml | 3 --- app/views/layouts/_navigation.html.haml | 5 ++++- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/views/admin/conferences/edit.html.haml b/app/views/admin/conferences/edit.html.haml index 49d65235..2d5df126 100644 --- a/app/views/admin/conferences/edit.html.haml +++ b/app/views/admin/conferences/edit.html.haml @@ -9,7 +9,6 @@ = 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 :organization, hint: 'The organization in which this conference belongs', input_html: { disabled: true } = 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/conferences/show.html.haml b/app/views/conferences/show.html.haml index b133c26a..fb488e22 100644 --- a/app/views/conferences/show.html.haml +++ b/app/views/conferences/show.html.haml @@ -22,9 +22,6 @@ .col-md-8 %h1 = @conference.title - %h3 - %i - = "( by #{@conference.organization.name} )" %p.lead - if @conference.venue = "#{@conference.venue.city} / #{@conference.venue.country_name}" diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index 6683ea23..92be2e89 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -7,7 +7,10 @@ %span.icon-bar %span.icon-bar %span.icon-bar - = link_to (ENV['OSEM_NAME'] || 'OSEM'), root_path, class: 'navbar-brand', title: 'Open Source Event Manager' + - if @conference.nil? || @conference.new_record? + = link_to (ENV['OSEM_NAME'] || 'OSEM'), root_path, class: 'navbar-brand', title: 'Open Source Event Manager' + - else + = link_to (ENV['OSEM_NAME'] || "#{@conference.organization.name} Organization"), organizations_path, class: 'navbar-brand', title: 'Open Source Event Manager' .collapse.navbar-collapse - if content_for :splash_nav %ul.nav.navbar-nav#splash-nav From 17eacaec0dcf154f8d4a11af6b83d0d3bcfbb68e Mon Sep 17 00:00:00 2001 From: shlok007 Date: Tue, 25 Jul 2017 08:16:44 +0530 Subject: [PATCH 26/50] add tests for organization name in conference views remove tests for organization name in conference#edit --- app/views/admin/conferences/show.html.haml | 2 +- app/views/layouts/_navigation.html.haml | 4 ++-- app/views/layouts/application.html.haml | 2 +- spec/features/conference_spec.rb | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/views/admin/conferences/show.html.haml b/app/views/admin/conferences/show.html.haml index f270867b..cddae4c2 100644 --- a/app/views/admin/conferences/show.html.haml +++ b/app/views/admin/conferences/show.html.haml @@ -1,6 +1,6 @@ %h1 %span.fa.fa-tachometer - Dashboard for #{@conference.title} ( by #{@conference.organization.name} ) + Dashboard for #{@conference.title} %hr .row .col-sm-4.col-xs-4 diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index 92be2e89..dbbfdbc0 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -7,10 +7,10 @@ %span.icon-bar %span.icon-bar %span.icon-bar - - if @conference.nil? || @conference.new_record? + - if conference.nil? || conference.new_record? = link_to (ENV['OSEM_NAME'] || 'OSEM'), root_path, class: 'navbar-brand', title: 'Open Source Event Manager' - else - = link_to (ENV['OSEM_NAME'] || "#{@conference.organization.name} Organization"), organizations_path, class: 'navbar-brand', title: 'Open Source Event Manager' + = link_to (ENV['OSEM_NAME'] || "#{conference.organization.name} Organization"), organizations_path, class: 'navbar-brand', title: 'Open Source Event Manager' .collapse.navbar-collapse - if content_for :splash_nav %ul.nav.navbar-nav#splash-nav diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 09be2523..c1a6ce78 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -21,7 +21,7 @@ = yield(:head) %body - = render 'layouts/navigation' + = render 'layouts/navigation', conference: @conference -# Admin area - if controller.class.name.split("::").first=="Admin" = render 'layouts/admin' diff --git a/spec/features/conference_spec.rb b/spec/features/conference_spec.rb index 5b9f9c54..5ac9f29b 100644 --- a/spec/features/conference_spec.rb +++ b/spec/features/conference_spec.rb @@ -73,11 +73,11 @@ feature Conference do describe 'admin' do let!(:conference) { create(:conference) } - scenario 'has organization name in edit form', feature: true, js: true do + scenario 'has organization name in menu bar for conference views', feature: true, js: true do sign_in user - visit edit_admin_conference_path(conference.short_title) - org_id = find('#conference_organization_id').value - expect(Organization.find(org_id)).to eq conference.organization + visit admin_conference_path(conference.short_title) + + expect(find('.navbar-brand').text).to eq "#{conference.organization.name} Organization" end it_behaves_like 'add and update conference' From 28b55a9d72e8c3b4de5e1271ed4082d31e97fe0a Mon Sep 17 00:00:00 2001 From: shlok007 Date: Wed, 2 Aug 2017 15:00:08 +0530 Subject: [PATCH 27/50] remove OSEM_NAME from navigation --- app/views/layouts/_navigation.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index dbbfdbc0..193e6b76 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -10,7 +10,7 @@ - if conference.nil? || conference.new_record? = link_to (ENV['OSEM_NAME'] || 'OSEM'), root_path, class: 'navbar-brand', title: 'Open Source Event Manager' - else - = link_to (ENV['OSEM_NAME'] || "#{conference.organization.name} Organization"), organizations_path, class: 'navbar-brand', title: 'Open Source Event Manager' + = link_to "#{conference.organization.name} Organization", organizations_path, class: 'navbar-brand', title: 'Open Source Event Manager' .collapse.navbar-collapse - if content_for :splash_nav %ul.nav.navbar-nav#splash-nav From 83abc9f71f1f857ceab691dfea6b2664baaea847 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Wed, 9 Aug 2017 23:34:58 +0530 Subject: [PATCH 28/50] remove Organization suffix from navbar-brand in navigation --- app/views/layouts/_navigation.html.haml | 2 +- spec/features/conference_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index 193e6b76..9750be92 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -10,7 +10,7 @@ - if conference.nil? || conference.new_record? = link_to (ENV['OSEM_NAME'] || 'OSEM'), root_path, class: 'navbar-brand', title: 'Open Source Event Manager' - else - = link_to "#{conference.organization.name} Organization", organizations_path, class: 'navbar-brand', title: 'Open Source Event Manager' + = link_to conference.organization.name, organizations_path, class: 'navbar-brand', title: 'Open Source Event Manager' .collapse.navbar-collapse - if content_for :splash_nav %ul.nav.navbar-nav#splash-nav diff --git a/spec/features/conference_spec.rb b/spec/features/conference_spec.rb index 5ac9f29b..f3205e07 100644 --- a/spec/features/conference_spec.rb +++ b/spec/features/conference_spec.rb @@ -77,7 +77,7 @@ feature Conference do sign_in user visit admin_conference_path(conference.short_title) - expect(find('.navbar-brand').text).to eq "#{conference.organization.name} Organization" + expect(find('.navbar-brand').text).to eq(conference.organization.name) end it_behaves_like 'add and update conference' From f31651ad9c0ce80a3fe41013d01773c9c7cb0307 Mon Sep 17 00:00:00 2001 From: siddhantbajaj Date: Mon, 7 Aug 2017 15:10:06 +0530 Subject: [PATCH 29/50] Added registration-ticket Added registration type tickets that will used in the check-in process --- app/controllers/admin/tickets_controller.rb | 2 +- app/views/admin/tickets/_form.html.haml | 1 + app/views/admin/tickets/index.html.haml | 3 +++ .../20170807092805_add_registration_ticket_to_tickets.rb | 5 +++++ db/schema.rb | 3 ++- 5 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20170807092805_add_registration_ticket_to_tickets.rb diff --git a/app/controllers/admin/tickets_controller.rb b/app/controllers/admin/tickets_controller.rb index c7161409..cf6e0f80 100644 --- a/app/controllers/admin/tickets_controller.rb +++ b/app/controllers/admin/tickets_controller.rb @@ -50,7 +50,7 @@ module Admin private def ticket_params - params.require(:ticket).permit(:conference, :title, :url, :description, :conference_id, :price_cents, :price_currency, :price) + params.require(:ticket).permit(:conference, :title, :url, :description, :conference_id, :price_cents, :price_currency, :price, :registration_ticket) end end end diff --git a/app/views/admin/tickets/_form.html.haml b/app/views/admin/tickets/_form.html.haml index 94a54692..11aff78d 100644 --- a/app/views/admin/tickets/_form.html.haml +++ b/app/views/admin/tickets/_form.html.haml @@ -13,5 +13,6 @@ = f.input :description, input_html: { rows: 5, data: { provide: "markdown-editable" } } = f.input :price = f.input :price_currency, as: :select, class: 'form-control', collection: ['USD', 'EUR', 'GBP', 'INR', 'CNY'], include_blank: false + = f.input :registration_ticket, hint: 'A registration ticket is with which user register for the conference.' %p.text-right = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/tickets/index.html.haml b/app/views/admin/tickets/index.html.haml index bb2804bf..b8cdb505 100644 --- a/app/views/admin/tickets/index.html.haml +++ b/app/views/admin/tickets/index.html.haml @@ -14,6 +14,7 @@ %th Price %th Sold %th Turnover + %th Registration Ticket %th Actions %tbody - @conference.tickets.each do |ticket| @@ -27,6 +28,8 @@ = ticket.tickets_sold %td = humanized_money_with_symbol ticket.tickets_turnover + %td + = ticket.registration_ticket? ? 'Yes' : 'No' %td .btn-group = link_to 'Edit', edit_admin_conference_ticket_path(@conference.short_title, ticket.id), diff --git a/db/migrate/20170807092805_add_registration_ticket_to_tickets.rb b/db/migrate/20170807092805_add_registration_ticket_to_tickets.rb new file mode 100644 index 00000000..0ee2410d --- /dev/null +++ b/db/migrate/20170807092805_add_registration_ticket_to_tickets.rb @@ -0,0 +1,5 @@ +class AddRegistrationTicketToTickets < ActiveRecord::Migration + def change + add_column :tickets, :registration_ticket, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index d49dfa03..ce680725 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: 20170721001700) do +ActiveRecord::Schema.define(version: 20170807092805) do create_table "ahoy_events", force: :cascade do |t| t.integer "visit_id" @@ -507,6 +507,7 @@ ActiveRecord::Schema.define(version: 20170721001700) do t.text "description" t.integer "price_cents", default: 0, null: false t.string "price_currency", default: "USD", null: false + t.boolean "registration_ticket", default: false end create_table "tracks", force: :cascade do |t| From bd62df14c3999b7968586d886141bc60557d99a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20Mar=C3=ADa=20Mart=C3=ADnez=20G=C3=B3mez?= Date: Thu, 20 Jul 2017 14:37:22 +0200 Subject: [PATCH 30/50] Fix vagrant broken after updating to Ruby 2.4 Ruby got updated in https://github.com/openSUSE/osem/pull/1588, But there was a repo missed, so Ruby 2.4 can be installed in our Vagrant machine. Closes https://github.com/openSUSE/osem/issues/1601 Mob-programmed by @mdeniz, @DavidKang and @Ana06. --- bootstrap.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bootstrap.sh b/bootstrap.sh index f0ac49fb..92a8d746 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -2,6 +2,8 @@ pushd /vagrant echo -e "\ninstalling required software packages...\n" +zypper -q ar -f http://download.opensuse.org/repositories/devel:/languages:/ruby/openSUSE_Leap_42.2/devel:languages:ruby.repo +zypper -q --gpg-auto-import-keys --non-interactive ref zypper -q -n install update-alternatives ruby2.4-devel make gcc gcc-c++ \ libxml2-devel libxslt-devel nodejs screen mariadb \ libmysqld-devel sqlite3-devel ImageMagick From 88e31ad902f729412a616b18f50bf2e1f38cac25 Mon Sep 17 00:00:00 2001 From: Wexpo Lyu Date: Wed, 2 Aug 2017 11:24:37 -0500 Subject: [PATCH 31/50] Expose enable_starttls_auto & openssl_verify_mode. And align `ENV` calls to keep up with codes above. My fault for using tabs. which caused a real misalignment. --- config/environments/production.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index d2b43a46..cb3a5d67 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -77,8 +77,9 @@ Osem::Application.configure do user_name: ENV['OSEM_SMTP_USERNAME'], password: ENV['OSEM_SMTP_PASSWORD'], authentication: ENV['OSEM_SMTP_AUTHENTICATION'].try(:to_sym), - domain: ENV['OSEM_SMTP_DOMAIN'], - enable_starttls_auto: true + domain: ENV['OSEM_SMTP_DOMAIN'], + enable_starttls_auto: ENV['OSEM_SMTP_ENABLE_STARTTLS_AUTO'], + openssl_verify_mode: ENV['OSEM_SMTP_OPENSSL_VERIFY_MODE'] } # Set the secret_key_base from the env, if not set by any other means From 33aee342b43d14cf3ade75a0f45ae6018982566b Mon Sep 17 00:00:00 2001 From: Wexpo Lyu Date: Wed, 2 Aug 2017 21:19:13 -0500 Subject: [PATCH 32/50] Add new envs to dotenv.example. --- dotenv.example | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dotenv.example b/dotenv.example index 0c852658..77c28e4c 100644 --- a/dotenv.example +++ b/dotenv.example @@ -58,6 +58,8 @@ OSEM_SMTP_USERNAME="" OSEM_SMTP_PASSWORD="" OSEM_SMTP_AUTHENTICATION="" OSEM_SMTP_DOMAIN="" +OSEM_SMTP_ENABLE_STARTTLS_AUTO="" +OSEM_SMTP_OPENSSL_VERIFY_MODE="" # Enable the usage of the devise ichain plugin OSEM_ICHAIN_ENABLED=false From d616c66745352e9c64e3f248e9271b5555073607 Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Wed, 12 Jul 2017 14:31:22 +0300 Subject: [PATCH 33/50] Define the track's finite state machine --- .rubocop_todo.yml | 1 + app/models/track.rb | 66 ++++++++++++++++++- spec/features/track_organizer_ability_spec.rb | 4 +- spec/models/admin_ability_spec.rb | 9 +-- 4 files changed, 72 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8d752446..e7e50f4a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -565,6 +565,7 @@ Style/PercentLiteralDelimiters: - 'app/models/subscription.rb' - 'app/uploaders/picture_uploader.rb' - 'spec/models/program_spec.rb' + - 'app/models/track.rb' # Offense count: 2 # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. diff --git a/app/models/track.rb b/app/models/track.rb index 2b37d1bb..6228ff02 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -1,4 +1,5 @@ class Track < ActiveRecord::Base + include ActiveRecord::Transitions include RevisionCount resourcify :roles, dependent: :delete_all @@ -18,12 +19,49 @@ class Track < ActiveRecord::Base uniqueness: { scope: :program } - validates :state, presence: true, if: :self_organized? + validates :state, + presence: true, + inclusion: { in: %w(new to_accept accepted confirmed to_reject rejected canceled withdrawn) }, + if: :self_organized? validates :cfp_active, inclusion: { in: [true, false] }, if: :self_organized? before_validation :capitalize_color - after_create :create_organizer_role, if: :self_organized? + state_machine initial: :pending do + state :new + state :to_accept + state :accepted + state :confirmed + state :to_reject + state :rejected + state :canceled + state :withdrawn + + event :restart do + transitions to: :new, from: [:rejected, :withdrawn, :canceled] + end + event :readiness_to_accept do + transitions to: :to_accept, from: [:new] + end + event :accept do + transitions to: :accepted, from: [:new, :to_accept], on_transition: :create_organizer_role + end + event :confirm do + transitions to: :confirmed, from: [:accepted], on_transition: :assign_role_to_submitter + end + event :readiness_to_reject do + transitions to: :to_reject, from: [:new] + end + event :reject do + transitions to: :rejected, from: [:new, :to_reject] + end + event :cancel do + transitions to: :canceled, from: [:to_accept, :to_reject, :accepted, :confirmed], on_transition: :revoke_role_and_cleanup + end + event :withdraw do + transitions to: :withdrawn, from: [:new, :to_accept, :to_reject, :accepted, :confirmed], on_transition: :revoke_role_and_cleanup + end + end def conference program.conference @@ -43,6 +81,30 @@ class Track < ActiveRecord::Base short_name end + def transition_possible?(transition) + self.class.state_machine.events_for(current_state).include?(transition) + end + + # Gives the role of the track_organizer to the submitter + def assign_role_to_submitter + submitter.add_role 'track_organizer', self + end + + # Revokes the track organizer role and removes the track from events that have it set + def revoke_role_and_cleanup + role = Role.find_by(name: 'track_organizer', resource: self) + + if role + role.users.each do |user| + user.remove_role 'track_organizer', self + end + end + + events.each do |event| + event.track = nil + end + end + private def generate_guid diff --git a/spec/features/track_organizer_ability_spec.rb b/spec/features/track_organizer_ability_spec.rb index f79eba05..49e46915 100644 --- a/spec/features/track_organizer_ability_spec.rb +++ b/spec/features/track_organizer_ability_spec.rb @@ -5,10 +5,10 @@ feature 'Has correct abilities' do let(:organization) { create(:organization) } let(:conference) { create(:full_conference, organization: organization) } let(:self_organized_track) { create(:track, :self_organized, program: conference.program) } - let(:role_track_organizer) { Role.find_by(name: 'track_organizer', resource: self_organized_track) } + let(:role_track_organizer) { Role.where(name: 'track_organizer', resource: self_organized_track).first_or_create } let(:user_track_organizer) { create(:user, role_ids: [role_track_organizer.id]) } - context 'when user is info desk' do + context 'when user is track organizer' do before do sign_in user_track_organizer end diff --git a/spec/models/admin_ability_spec.rb b/spec/models/admin_ability_spec.rb index 5398b7d2..16456a19 100644 --- a/spec/models/admin_ability_spec.rb +++ b/spec/models/admin_ability_spec.rb @@ -79,7 +79,7 @@ describe 'User with admin role' do context 'accesses track organizers' do before :each do other_self_organized_track = create(:track, :self_organized) - @other_track_organizer_role = Role.find_by(name: 'track_organizer', resource: other_self_organized_track) + @other_track_organizer_role = Role.where(name: 'track_organizer', resource: other_self_organized_track).first_or_create end it{ should_not be_able_to(:toggle_user, @other_track_organizer_role) } @@ -105,7 +105,7 @@ describe 'User with admin role' do context 'accesses track organizers' do before :each do - @track_organizer_role = Role.find_by(name: 'track_organizer', resource: my_self_organized_track) + @track_organizer_role = Role.where(name: 'track_organizer', resource: my_self_organized_track).first_or_create end if role_name == 'track_organizer' @@ -223,7 +223,7 @@ describe 'User with admin role' do context 'can manage track organizers' do before :each do - @track_organizer_role = Role.find_by(name: 'track_organizer', resource: my_self_organized_track) + @track_organizer_role = Role.where(name: 'track_organizer', resource: my_self_organized_track).first_or_create end it{ should be_able_to(:toggle_user, @track_organizer_role) } @@ -441,7 +441,8 @@ describe 'User with admin role' do end context 'when user has the role track_organizer' do - let(:role) { Role.find_by(name: 'track_organizer', resource: my_self_organized_track) } + + let(:role) { Role.where(name: 'track_organizer', resource: my_self_organized_track).first_or_create } let(:user) { create(:user, role_ids: [role.id]) } let(:new_track) { build(:track, program: my_conference.program) } From fd93b04f169685f446dd9e3a4e2395a80a53f0a6 Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Wed, 12 Jul 2017 15:56:07 +0300 Subject: [PATCH 34/50] Add room and dates to tracks They are required only for accepted and confirmed self-organized tracks --- .rubocop_todo.yml | 4 ++ app/controllers/admin/tracks_controller.rb | 2 +- app/models/room.rb | 1 + app/models/track.rb | 56 +++++++++++++++++++ app/views/admin/tracks/_form.html.haml | 8 ++- app/views/admin/tracks/index.html.haml | 18 ++++++ ...0712120556_add_room_and_dates_to_tracks.rb | 7 +++ db/schema.rb | 4 ++ spec/models/room_spec.rb | 1 + 9 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20170712120556_add_room_and_dates_to_tracks.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e7e50f4a..487a9fdb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -317,6 +317,8 @@ Metrics/BlockLength: # Offense count: 23 Metrics/CyclomaticComplexity: Max: 12 + Exclude: + - 'app/models/track.rb' # Offense count: 2353 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. @@ -339,6 +341,8 @@ Metrics/ModuleLength: # Offense count: 15 Metrics/PerceivedComplexity: Max: 16 + Exclude: + - 'app/models/track.rb' # Offense count: 20 Style/AccessorMethodName: diff --git a/app/controllers/admin/tracks_controller.rb b/app/controllers/admin/tracks_controller.rb index c229b9b8..0eed1b2d 100644 --- a/app/controllers/admin/tracks_controller.rb +++ b/app/controllers/admin/tracks_controller.rb @@ -62,7 +62,7 @@ module Admin private def track_params - params.require(:track).permit(:name, :description, :color, :short_name, :cfp_active) + params.require(:track).permit(:name, :description, :color, :short_name, :cfp_active, :start_date, :end_date, :room_id) end end end diff --git a/app/models/room.rb b/app/models/room.rb index f8150f78..8a50551d 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -2,6 +2,7 @@ class Room < ActiveRecord::Base include RevisionCount belongs_to :venue has_many :event_schedules, dependent: :destroy + has_many :tracks has_paper_trail ignore: [:guid], meta: { conference_id: :conference_id } diff --git a/app/models/track.rb b/app/models/track.rb index 6228ff02..f29babde 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -6,6 +6,7 @@ class Track < ActiveRecord::Base belongs_to :program belongs_to :submitter, class_name: 'User' + belongs_to :room has_many :events, dependent: :nullify has_paper_trail only: [:name, :description, :color], meta: { conference_id: :conference_id } @@ -24,6 +25,10 @@ class Track < ActiveRecord::Base inclusion: { in: %w(new to_accept accepted confirmed to_reject rejected canceled withdrawn) }, if: :self_organized? validates :cfp_active, inclusion: { in: [true, false] }, if: :self_organized? + validates :start_date, presence: true, if: :accepted_or_confirmed? + validates :end_date, presence: true, if: :accepted_or_confirmed? + validates :room, presence: true, if: :accepted_or_confirmed? + validate :valid_dates, if: :accepted_or_confirmed? before_validation :capitalize_color @@ -105,6 +110,33 @@ class Track < ActiveRecord::Base end end + ## + # Checks if the track is accepted + # ====Returns + # * +true+ -> If the track's state is 'accepted' + # * +false+ -> If the track's state isn't 'accepted' + def accepted? + state == 'accepted' + end + + ## + # Checks if the track is confirmed + # ====Returns + # * +true+ -> If the track's state is 'confirmed' + # * +false+ -> If the track's state isn't 'confirmed' + def confirmed? + state == 'confirmed' + end + + ## + # Checks if the track is accepted or confirmed + # ====Returns + # * +true+ -> If the track's state is 'accepted' or 'confirmed' + # * +false+ -> If the track's state is neither 'accepted' nor 'confirmed' + def accepted_or_confirmed? + accepted? || confirmed? + end + private def generate_guid @@ -128,4 +160,28 @@ class Track < ActiveRecord::Base def create_organizer_role Role.where(name: 'track_organizer', resource: self).first_or_create(description: 'For the organizers of the Track') end + + def valid_dates + return unless start_date && end_date + + if program && program.conference && program.conference.start_date && (start_date < program.conference.start_date) + errors.add(:start_date, "can't be before the conference start date (#{program.conference.end_date})") + end + + if program && program.conference && program.conference.start_date && (end_date < program.conference.start_date) + errors.add(:end_date, "can't be before the conference start date (#{program.conference.end_date})") + end + + if program && program.conference && program.conference.end_date && (start_date > program.conference.end_date) + errors.add(:start_date, "can't be after the conference end date (#{program.conference.end_date})") + end + + if program && program.conference && program.conference.end_date && (end_date > program.conference.end_date) + errors.add(:end_date, "can't be after the conference end date (#{program.conference.end_date})") + end + + if start_date > end_date + errors.add(:start_date, 'can\'t be after the end_date') + end + end end diff --git a/app/views/admin/tracks/_form.html.haml b/app/views/admin/tracks/_form.html.haml index fe7f014a..cb2e8b01 100644 --- a/app/views/admin/tracks/_form.html.haml +++ b/app/views/admin/tracks/_form.html.haml @@ -8,10 +8,16 @@ Track .row .col-md-12 - = semantic_form_for(@track, url: (@track.new_record? ? admin_conference_program_tracks_path : admin_conference_program_track_path(@conference.short_title, @track))) do |f| + = semantic_form_for(@track, url: (@track.new_record? ? admin_conference_program_tracks_path(@conference.short_title) : admin_conference_program_track_path(@conference.short_title, @track))) do |f| = f.input :name = f.input :short_name, hint: "A short and unique handle for the track, using only letters, numbers, underscores, and dashes. This will be used to identify the track in URLs etc. Example: 'my_awesome_track'", input_html: { required: 'required', pattern: '[a-zA-Z0-9_-]+', title: 'Only letters, numbers, underscores, and dashes.' } = f.input :color, input_html: {size: 6, type: 'color'}, required: true + = f.input :start_date, as: :string, input_html: { id: 'registration-period-start-datepicker', start_date: @conference.start_date, end_date: @conference.end_date, readonly: 'readonly', required: @track.self_organized_and_accepted_or_confirmed? } + = f.input :end_date, as: :string, input_html: { id: 'registration-period-end-datepicker', readonly: 'readonly', required: @track.self_organized_and_accepted_or_confirmed? } + - if @conference.venue + = f.input :room, as: :select, collection: (@conference.venue.rooms).map {|room| ["#{room.name}", room.id]}, include_blank: true, label: 'Room', input_html: { class: 'select-help-toggle', required: @track.self_organized_and_accepted_or_confirmed? } + - else + Please add a venue with rooms, if you want to select a room for the track. = f.input :description, input_html: {rows: 2, data: { provide: 'markdown-editable' } }, hint: markdown_hint - if @track.self_organized? = f.input :cfp_active, label: 'Allow event submitters to select this track for their proposal' diff --git a/app/views/admin/tracks/index.html.haml b/app/views/admin/tracks/index.html.haml index 1cda360a..82167bb8 100644 --- a/app/views/admin/tracks/index.html.haml +++ b/app/views/admin/tracks/index.html.haml @@ -15,6 +15,9 @@ %th Color %th State %th Included in the Cfp + %th Room + %th Start Date + %th End Date %th Actions %tbody - @tracks.each do |track| @@ -52,6 +55,21 @@ off_text: 'No' } - else %i.fa.fa-check + %td + - if track.room + = link_to track.room.name, admin_conference_venue_room_path(@conference.short_title, track.room.id) + - else + N/A + %td + - if track.start_date + = track.start_date.strftime('%A, %B %-d. %Y') + - else + N/A + %td + - if track.end_date + = track.end_date.strftime('%A, %B %-d. %Y') + - else + N/A %td .btn-group{role: "group"} = link_to 'Edit', edit_admin_conference_program_track_path(@conference.short_title, track), diff --git a/db/migrate/20170712120556_add_room_and_dates_to_tracks.rb b/db/migrate/20170712120556_add_room_and_dates_to_tracks.rb new file mode 100644 index 00000000..fb8a064b --- /dev/null +++ b/db/migrate/20170712120556_add_room_and_dates_to_tracks.rb @@ -0,0 +1,7 @@ +class AddRoomAndDatesToTracks < ActiveRecord::Migration + def change + add_reference :tracks, :room, index: true, foreign_key: true + add_column :tracks, :start_date, :date + add_column :tracks, :end_date, :date + end +end diff --git a/db/schema.rb b/db/schema.rb index ce680725..d3e14687 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -522,8 +522,12 @@ ActiveRecord::Schema.define(version: 20170807092805) do t.string "state" t.boolean "cfp_active" t.integer "submitter_id" + t.integer "room_id" + t.date "start_date" + t.date "end_date" end + add_index "tracks", ["room_id"], name: "index_tracks_on_room_id" add_index "tracks", ["submitter_id"], name: "index_tracks_on_submitter_id" create_table "users", force: :cascade do |t| diff --git a/spec/models/room_spec.rb b/spec/models/room_spec.rb index 469fb117..f135f91d 100644 --- a/spec/models/room_spec.rb +++ b/spec/models/room_spec.rb @@ -12,6 +12,7 @@ describe Room do describe 'association' do it { should belong_to(:venue) } it { should have_many(:event_schedules).dependent(:destroy) } + it { should have_many(:tracks) } end describe 'callback' do From 0f154d07c9abcb1bb5a954b79d67092d89e92b08 Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Sat, 15 Jul 2017 19:55:45 +0300 Subject: [PATCH 35/50] Mark track state as not null and add default value The regular tracks are marked as 'confirmed' --- app/controllers/admin/tracks_controller.rb | 1 + app/controllers/tracks_controller.rb | 1 - app/models/track.rb | 14 +++++++------- app/views/admin/tracks/index.html.haml | 2 +- ...e_track_state_not_null_and_add_default_value.rb | 14 ++++++++++++++ db/schema.rb | 8 ++++---- spec/controllers/admin/tracks_controller_spec.rb | 4 ++++ spec/factories/tracks.rb | 1 + 8 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 db/migrate/20170715131706_make_track_state_not_null_and_add_default_value.rb diff --git a/app/controllers/admin/tracks_controller.rb b/app/controllers/admin/tracks_controller.rb index 0eed1b2d..2cb6ec2b 100644 --- a/app/controllers/admin/tracks_controller.rb +++ b/app/controllers/admin/tracks_controller.rb @@ -19,6 +19,7 @@ module Admin def create @track = @program.tracks.new(track_params) + @track.state = 'confirmed' if @track.save redirect_to admin_conference_program_tracks_path(conference_id: @conference.short_title), notice: 'Track successfully created.' diff --git a/app/controllers/tracks_controller.rb b/app/controllers/tracks_controller.rb index 529767cd..59deae3c 100644 --- a/app/controllers/tracks_controller.rb +++ b/app/controllers/tracks_controller.rb @@ -18,7 +18,6 @@ class TracksController < ApplicationController def create @track = @program.tracks.new(track_params) @track.submitter = current_user - @track.state = 'new' @track.cfp_active = false if @track.save redirect_to conference_program_tracks_path(conference_id: @conference.short_title), diff --git a/app/models/track.rb b/app/models/track.rb index f29babde..a53471bc 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -25,10 +25,10 @@ class Track < ActiveRecord::Base inclusion: { in: %w(new to_accept accepted confirmed to_reject rejected canceled withdrawn) }, if: :self_organized? validates :cfp_active, inclusion: { in: [true, false] }, if: :self_organized? - validates :start_date, presence: true, if: :accepted_or_confirmed? - validates :end_date, presence: true, if: :accepted_or_confirmed? - validates :room, presence: true, if: :accepted_or_confirmed? - validate :valid_dates, if: :accepted_or_confirmed? + validates :start_date, presence: true, if: :self_organized_and_accepted_or_confirmed? + validates :end_date, presence: true, if: :self_organized_and_accepted_or_confirmed? + validates :room, presence: true, if: :self_organized_and_accepted_or_confirmed? + validate :valid_dates, if: :self_organized_and_accepted_or_confirmed? before_validation :capitalize_color @@ -129,12 +129,12 @@ class Track < ActiveRecord::Base end ## - # Checks if the track is accepted or confirmed + # Checks if a self-organized track is accepted or confirmed # ====Returns # * +true+ -> If the track's state is 'accepted' or 'confirmed' # * +false+ -> If the track's state is neither 'accepted' nor 'confirmed' - def accepted_or_confirmed? - accepted? || confirmed? + def self_organized_and_accepted_or_confirmed? + self_organized? && (accepted? || confirmed?) end private diff --git a/app/views/admin/tracks/index.html.haml b/app/views/admin/tracks/index.html.haml index 82167bb8..4da97a18 100644 --- a/app/views/admin/tracks/index.html.haml +++ b/app/views/admin/tracks/index.html.haml @@ -42,7 +42,7 @@ - if track.self_organized? = track.state - else - N/A + = track.state.humanize %td - if track.self_organized? = check_box_tag "#{@conference.short_title}_#{track.short_name}", track.id, track.cfp_active, diff --git a/db/migrate/20170715131706_make_track_state_not_null_and_add_default_value.rb b/db/migrate/20170715131706_make_track_state_not_null_and_add_default_value.rb new file mode 100644 index 00000000..3d2520cf --- /dev/null +++ b/db/migrate/20170715131706_make_track_state_not_null_and_add_default_value.rb @@ -0,0 +1,14 @@ +class MakeTrackStateNotNullAndAddDefaultValue < ActiveRecord::Migration + class TmpTrack < ActiveRecord::Base + self.table_name = 'tracks' + end + + def change + TmpTrack.where(state: nil).each do |track| + track.state = 'confirmed' + track.save! + end + + change_column :tracks, :state, :string, null: false, default: 'new' + end +end diff --git a/db/schema.rb b/db/schema.rb index d3e14687..aa2f160d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -511,15 +511,15 @@ ActiveRecord::Schema.define(version: 20170807092805) do end create_table "tracks", force: :cascade do |t| - t.string "guid", null: false - t.string "name", null: false + t.string "guid", null: false + t.string "name", null: false t.text "description" t.string "color" t.datetime "created_at" t.datetime "updated_at" t.integer "program_id" - t.string "short_name", null: false - t.string "state" + t.string "short_name", null: false + t.string "state", default: "new", null: false t.boolean "cfp_active" t.integer "submitter_id" t.integer "room_id" diff --git a/spec/controllers/admin/tracks_controller_spec.rb b/spec/controllers/admin/tracks_controller_spec.rb index 2177af2f..ed76fe68 100644 --- a/spec/controllers/admin/tracks_controller_spec.rb +++ b/spec/controllers/admin/tracks_controller_spec.rb @@ -80,6 +80,10 @@ describe Admin::TracksController do it 'creates new track' do expect(Track.find(assigns(:track).id)).to be_a Track end + + it 'the new tracks has the correct attributes' do + expect(assigns(:track).state).to eq 'confirmed' + end end context 'save fails' do diff --git a/spec/factories/tracks.rb b/spec/factories/tracks.rb index 091d8d07..d30a686e 100644 --- a/spec/factories/tracks.rb +++ b/spec/factories/tracks.rb @@ -4,6 +4,7 @@ FactoryGirl.define do description { Faker::Lorem.sentence } color { Faker::Color.hex_color } short_name { SecureRandom.urlsafe_base64(5) } + state 'confirmed' program trait :self_organized do From 2f9eb0421940bffb44837d343e35ef0d0f3fd59d Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Wed, 12 Jul 2017 16:35:09 +0300 Subject: [PATCH 36/50] Enable track requests --- .haml-lint_todo.yml | 4 +++ app/helpers/application_helper.rb | 2 +- app/models/ability.rb | 8 +++++ app/models/cfp.rb | 3 +- app/views/admin/cfps/_tracks_cfp.html.haml | 12 ++++++++ .../conferences/_call_for_tracks.html.haml | 30 +++++++++++++++++++ .../conferences/_conference_details.html.haml | 4 +++ app/views/conferences/show.html.haml | 4 +++ app/views/tracks/index.html.haml | 2 +- app/views/tracks/show.html.haml | 2 +- spec/features/cfp_ability_spec.rb | 26 ++++++++++++++-- .../organization_admin_ability_spec.rb | 26 ++++++++++++++-- spec/features/organizer_ability_spec.rb | 26 ++++++++++++++-- spec/models/program_spec.rb | 26 +++++++++------- 14 files changed, 155 insertions(+), 20 deletions(-) create mode 100644 app/views/admin/cfps/_tracks_cfp.html.haml create mode 100644 app/views/conferences/_call_for_tracks.html.haml diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index 52d5f5ca..11397297 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -180,6 +180,7 @@ linters: - "app/views/tracks/_form.html.haml" - "app/views/tracks/index.html.haml" - "app/views/tracks/show.html.haml" + - "app/views/conferences/_call_for_tracks.html.haml" # Offense count: 223 InstanceVariables: @@ -242,6 +243,8 @@ linters: - "app/views/schedules/_schedule_tabs.html.haml" - "app/views/admin/cfps/_events_cfp.html.haml" - "app/views/tracks/_form.html.haml" + - "app/views/admin/cfps/_tracks_cfp.html.haml" + - "app/views/conferences/_call_for_tracks.html.haml" # Offense count: 32 IdNames: @@ -261,6 +264,7 @@ linters: - "app/views/admin/users/show.html.haml" - "app/views/users/edit.html.haml" - "app/views/admin/cfps/_events_cfp.html.haml" + - "app/views/admin/cfps/_tracks_cfp.html.haml" # Offense count: 4 UnnecessaryInterpolation: diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0abf6088..fdef7b4a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -56,7 +56,7 @@ module ApplicationHelper end def tracks(conference) - all = conference.program.tracks.map {|t| t.name} + all = conference.program.tracks.map { |t| t.name if !t.self_organized? || t.confirmed? && t.cfp_active }.compact first = all[0...-1] last = all[-1] ts = '' diff --git a/app/models/ability.rb b/app/models/ability.rb index 0ebabfdc..e5dbd7e4 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -95,6 +95,14 @@ class Ability can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id) can [:destroy], Openid + + can [:new, :create], Track do |track| + track.new_record? && track.program.cfps.for_tracks.try(:open?) + end + + can [:index, :show, :edit, :update], Track do |track| + user == track.submitter + end end # Abilities for users with roles wandering around in non-admin views. diff --git a/app/models/cfp.rb b/app/models/cfp.rb index 97f276c9..44d8281b 100644 --- a/app/models/cfp.rb +++ b/app/models/cfp.rb @@ -1,9 +1,10 @@ # cannot delete program if there are events submitted class Cfp < ActiveRecord::Base - TYPES = %w(events booths).freeze + TYPES = %w(events booths tracks).freeze scope :for_events, (-> { find_by(cfp_type: 'events') }) + scope :for_tracks, (-> { find_by(cfp_type: 'tracks') }) has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } belongs_to :program diff --git a/app/views/admin/cfps/_tracks_cfp.html.haml b/app/views/admin/cfps/_tracks_cfp.html.haml new file mode 100644 index 00000000..e381df96 --- /dev/null +++ b/app/views/admin/cfps/_tracks_cfp.html.haml @@ -0,0 +1,12 @@ +%dt + Start Date: +%dd#start_date + = @cfp.start_date.strftime('%A, %B %-d. %Y') +%dt + End Date: +%dd#end_date + = @cfp.end_date.strftime('%A, %B %-d. %Y') +%dt + Days Left: +%dd + = pluralize(@cfp.remaining_days, 'day') diff --git a/app/views/conferences/_call_for_tracks.html.haml b/app/views/conferences/_call_for_tracks.html.haml new file mode 100644 index 00000000..1abeb956 --- /dev/null +++ b/app/views/conferences/_call_for_tracks.html.haml @@ -0,0 +1,30 @@ += content_for :splash_nav do + %li + %a.smoothscroll{ href: '#callfortracks' } Call For Tracks + +.container + .row + .col-md-12.text-center + %h2 + Call for Tracks + %p.lead + We are ready to accept requests for tracks! + .row + .col-md-6.col-md-offset-3.col-sm-10.col-sm-offset-1 + %p + The submission period for track requests has begun + %em.notranslate + = @conference.program.cfps.for_tracks.start_date.strftime('%A, %B %-d. %Y') + and closes + %em.notranslate + = @conference.program.cfps.for_tracks.end_date.strftime('%A, %B %-d. %Y.') + - if @conference.program.cfps.for_tracks.try(:open?) + That means you have only + %b.notranslate= pluralize(@conference.program.cfps.for_tracks.remaining_days, 'day') + left! + - else + The submission period for track requests is closed. + .row + .col-md-12.text-center + %p.cta-button + = link_to "Submit your request for track", conference_program_tracks_path(@conference.short_title), class: 'btn btn-success btn-lg text-center' diff --git a/app/views/conferences/_conference_details.html.haml b/app/views/conferences/_conference_details.html.haml index d5bafad4..e8ca2449 100644 --- a/app/views/conferences/_conference_details.html.haml +++ b/app/views/conferences/_conference_details.html.haml @@ -30,6 +30,10 @@ = link_to "Register", new_conference_conference_registration_path(conference.short_title), class: "btn btn-default", disabled: cannot?(:new, Registration.new(conference_id: conference.id)) - if cannot?(:new, Registration.new(conference_id: conference.id)) && conference.registration_limit_exceeded? Sorry, no places left + - if !current_user.nil? && current_user.tracks.where(program: conference.program).length > 0 + = link_to "My Track Requests", conference_program_tracks_path(conference.short_title), class: 'btn btn-default' + - elsif can? :new, conference.program.tracks.new + = link_to "Submit Track Request", new_conference_program_track_path(conference.short_title), class: 'btn btn-default' - if !current_user.nil? && current_user.proposal_count(conference) > 0 = link_to "My Proposals", conference_program_proposals_path(conference.short_title), class: 'btn btn-default' - elsif can? :new, conference.program.events.new diff --git a/app/views/conferences/show.html.haml b/app/views/conferences/show.html.haml index fb488e22..edc72726 100644 --- a/app/views/conferences/show.html.haml +++ b/app/views/conferences/show.html.haml @@ -45,6 +45,10 @@ %section#program = render 'schedule_splashpage' + - if @conference.program.cfps.for_tracks.try(:open?) && @conference.splashpage.include_cfp + %section#callfortracks + = render 'call_for_tracks' + - if @conference.program.cfp_open? and @conference.splashpage.include_cfp %section#callforpapers = render 'call_for_paper' diff --git a/app/views/tracks/index.html.haml b/app/views/tracks/index.html.haml index d4670bf4..7e16304f 100644 --- a/app/views/tracks/index.html.haml +++ b/app/views/tracks/index.html.haml @@ -32,7 +32,7 @@ %span.label{style: "background-color: #{track.color}; color: #{ contrast_color(track.color) }"} = track.color %td - = track.state + = track.state.humanize %td = link_to 'Edit', edit_conference_program_track_path(@conference.short_title, track), method: :get, class: 'btn btn-primary' diff --git a/app/views/tracks/show.html.haml b/app/views/tracks/show.html.haml index c08818eb..37c180ae 100644 --- a/app/views/tracks/show.html.haml +++ b/app/views/tracks/show.html.haml @@ -16,7 +16,7 @@ %dt State: %dd - = @track.state + = @track.state.humanize %dt Description %dd diff --git a/spec/features/cfp_ability_spec.rb b/spec/features/cfp_ability_spec.rb index d40a54a4..cd9fa3bd 100644 --- a/spec/features/cfp_ability_spec.rb +++ b/spec/features/cfp_ability_spec.rb @@ -64,29 +64,51 @@ feature 'Has correct abilities' do visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq(new_admin_conference_program_cfp_path(conference.short_title)) - # Both event and booth exists + # Event and booth cfps exist cfb = create(:cfp, cfp_type: 'booths', program: conference.program) visit new_admin_conference_program_cfp_path(conference.short_title) - expect(current_path).to eq root_path + expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) visit edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp) expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp)) + # Event, booth, track cfps exist + cft = create(:cfp, cfp_type: 'tracks', program: conference.program) + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq root_path + + # Booth and track cfps exist conference.program.cfp.destroy! visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) # Only booth exists + cft.destroy! visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq(new_admin_conference_program_cfp_path(conference.short_title)) visit edit_admin_conference_program_cfp_path(conference.short_title, cfb) expect(current_path). to eq(edit_admin_conference_program_cfp_path(conference.short_title, cfb)) + # No cfp exists cfb.destroy visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq(new_admin_conference_program_cfp_path(conference.short_title)) + # Only Tracks cfp exists + cft = create(:cfp, cfp_type: 'tracks', program: conference.program) + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) + + visit edit_admin_conference_program_cfp_path(conference.short_title, cft) + expect(current_path).to eq edit_admin_conference_program_cfp_path(conference.short_title, cft) + + # Event and track cfps exist + create(:cfp, cfp_type: 'events', program: conference.program) + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) + + cft.destroy! create(:event, program: conference.program) visit edit_admin_conference_program_event_path(conference.short_title, conference.program.events.first) expect(current_path).to eq(edit_admin_conference_program_event_path(conference.short_title, conference.program.events.first)) diff --git a/spec/features/organization_admin_ability_spec.rb b/spec/features/organization_admin_ability_spec.rb index 274d345f..12fd038b 100644 --- a/spec/features/organization_admin_ability_spec.rb +++ b/spec/features/organization_admin_ability_spec.rb @@ -106,29 +106,51 @@ feature 'Has correct abilities' do visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq(new_admin_conference_program_cfp_path(conference.short_title)) - # Both event and booth exists + # Event and booth cfps exist cfb = create(:cfp, cfp_type: 'booths', program: conference.program) visit new_admin_conference_program_cfp_path(conference.short_title) - expect(current_path).to eq root_path + expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) visit edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp) expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp)) + # Event, booth, track cfps exist + cft = create(:cfp, cfp_type: 'tracks', program: conference.program) + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq root_path + + # Booth and track cfps exist conference.program.cfp.destroy! visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) # Only booth exists + cft.destroy! visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq(new_admin_conference_program_cfp_path(conference.short_title)) visit edit_admin_conference_program_cfp_path(conference.short_title, cfb) expect(current_path). to eq(edit_admin_conference_program_cfp_path(conference.short_title, cfb)) + # No cfp exists cfb.destroy visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq(new_admin_conference_program_cfp_path(conference.short_title)) + # Only Tracks cfp exists + cft = create(:cfp, cfp_type: 'tracks', program: conference.program) + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) + + visit edit_admin_conference_program_cfp_path(conference.short_title, cft) + expect(current_path).to eq edit_admin_conference_program_cfp_path(conference.short_title, cft) + + # Event and track cfps exist + create(:cfp, cfp_type: 'events', program: conference.program) + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) + + cft.destroy! visit admin_conference_program_events_path(conference.short_title) expect(current_path).to eq(admin_conference_program_events_path(conference.short_title)) diff --git a/spec/features/organizer_ability_spec.rb b/spec/features/organizer_ability_spec.rb index 3ed6ee39..ef2b3744 100644 --- a/spec/features/organizer_ability_spec.rb +++ b/spec/features/organizer_ability_spec.rb @@ -112,29 +112,51 @@ feature 'Has correct abilities' do visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq(new_admin_conference_program_cfp_path(conference.short_title)) - # Both event and booth exists + # Event and booth cfps exist cfb = create(:cfp, cfp_type: 'booths', program: conference.program) visit new_admin_conference_program_cfp_path(conference.short_title) - expect(current_path).to eq root_path + expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) visit edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp) expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp)) + # Event, booth, track cfps exist + cft = create(:cfp, cfp_type: 'tracks', program: conference.program) + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq root_path + + # Booth and track cfps exist conference.program.cfp.destroy! visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) # Only booth exists + cft.destroy! visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq(new_admin_conference_program_cfp_path(conference.short_title)) visit edit_admin_conference_program_cfp_path(conference.short_title, cfb) expect(current_path). to eq(edit_admin_conference_program_cfp_path(conference.short_title, cfb)) + # No cfp exists cfb.destroy visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq(new_admin_conference_program_cfp_path(conference.short_title)) + # Only Tracks cfp exists + cft = create(:cfp, cfp_type: 'tracks', program: conference.program) + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) + + visit edit_admin_conference_program_cfp_path(conference.short_title, cft) + expect(current_path).to eq edit_admin_conference_program_cfp_path(conference.short_title, cft) + + # Event and track cfps exist + create(:cfp, cfp_type: 'events', program: conference.program) + visit new_admin_conference_program_cfp_path(conference.short_title) + expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) + + cft.destroy! visit admin_conference_program_events_path(conference.short_title) expect(current_path).to eq(admin_conference_program_events_path(conference.short_title)) diff --git a/spec/models/program_spec.rb b/spec/models/program_spec.rb index d81e32bc..1c8eabd9 100644 --- a/spec/models/program_spec.rb +++ b/spec/models/program_spec.rb @@ -253,28 +253,34 @@ describe Program do end describe '#remaining_cfp_types' do - it 'returns an array with the types for which a cfp doesn\'t exist, when only the Event type does' do - expect(program.remaining_cfp_types).to eq(Cfp::TYPES) + it 'returns an array without the \'events\' type, when the cfp for events exists' do create(:cfp, cfp_type: 'events', program: program) - expect(program.remaining_cfp_types).to eq(['booths']) + expect(program.remaining_cfp_types).to be_a Array + expect(program.remaining_cfp_types.include?('events')).to eq false end - it 'returns an array with the types for which a cfp doesn\'t exist, when only the Booth type does' do - expect(program.remaining_cfp_types).to eq(Cfp::TYPES) + it 'returns an array without the \'booths\' type, when the cfp for booths exists' do create(:cfp, cfp_type: 'booths', program: program) - expect(program.remaining_cfp_types).to eq(['events']) + expect(program.remaining_cfp_types).to be_a Array + expect(program.remaining_cfp_types.include?('booths')).to eq false end - it 'returns an empty array when all the cfp types exist' do - expect(program.remaining_cfp_types).to eq(Cfp::TYPES) + it 'returns an array without the \'tracks\' type, when the cfp for tracks exists' do + create(:cfp, cfp_type: 'tracks', program: program) + expect(program.remaining_cfp_types).to be_a Array + expect(program.remaining_cfp_types.include?('tracks')).to eq false + end + + it 'returns an empty array when cfps for all the types exist' do create(:cfp, cfp_type: 'events', program: program) create(:cfp, cfp_type: 'booths', program: program) + create(:cfp, cfp_type: 'tracks', program: program) expect(program.remaining_cfp_types).to eq([]) end - it 'returns all the possible cfp types when there is no existed cfp type' do + it 'returns all the possible cfp types when there is no cfp' do expect(program.remaining_cfp_types).to eq(Cfp::TYPES) - expect(program.remaining_cfp_types). to eq(%w[events booths]) + expect(program.remaining_cfp_types). to eq(%w[events booths tracks]) end end end From d9faffc96a04dacdac8472f80c9e3f106e69a2e2 Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Fri, 14 Jul 2017 15:57:34 +0300 Subject: [PATCH 37/50] Implement track request acceptance Allow track submitter to request specific dates Redirect to Tracks#edit if a track doesn't have a room or start/end date before accepting it Don't allow the submitter or the track organizers to edit the request after it has been accepted or confirmed Restrict track selection in proposals and move track selection from Proposals form to events helper Mark cfp_active of the tracks table as not null and fill in true if nil --- .haml-lint_todo.yml | 2 + app/controllers/admin/tracks_controller.rb | 46 +++ app/controllers/tracks_controller.rb | 28 +- app/helpers/application_helper.rb | 2 +- app/helpers/events_helper.rb | 8 + app/models/ability.rb | 6 +- app/models/admin_ability.rb | 4 + app/models/event.rb | 8 + app/models/track.rb | 52 ++- .../tracks/_change_state_dropdown.html.haml | 34 ++ app/views/admin/tracks/_form.html.haml | 3 +- app/views/admin/tracks/index.html.haml | 32 +- app/views/proposals/_proposal_form.html.haml | 5 +- app/views/tracks/_form.html.haml | 4 +- app/views/tracks/index.html.haml | 29 +- app/views/tracks/show.html.haml | 17 +- config/routes.rb | 15 +- ...20134353_make_track_cfp_active_not_null.rb | 14 + db/schema.rb | 2 +- .../admin/tracks_controller_spec.rb | 203 ++++++++++- spec/controllers/tracks_controller_spec.rb | 66 +++- spec/factories/tracks.rb | 4 + spec/models/ability_spec.rb | 30 ++ spec/models/admin_ability_spec.rb | 4 +- spec/models/conference_spec.rb | 4 +- spec/models/event_spec.rb | 34 ++ spec/models/track_spec.rb | 315 +++++++++++++++++- 27 files changed, 909 insertions(+), 62 deletions(-) create mode 100644 app/views/admin/tracks/_change_state_dropdown.html.haml create mode 100644 db/migrate/20170720134353_make_track_cfp_active_not_null.rb diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index 11397297..89d18c3f 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -181,6 +181,7 @@ linters: - "app/views/tracks/index.html.haml" - "app/views/tracks/show.html.haml" - "app/views/conferences/_call_for_tracks.html.haml" + - "app/views/admin/tracks/_change_state_dropdown.html.haml" # Offense count: 223 InstanceVariables: @@ -245,6 +246,7 @@ linters: - "app/views/tracks/_form.html.haml" - "app/views/admin/cfps/_tracks_cfp.html.haml" - "app/views/conferences/_call_for_tracks.html.haml" + - "app/views/admin/tracks/_change_state_dropdown.html.haml" # Offense count: 32 IdNames: diff --git a/app/controllers/admin/tracks_controller.rb b/app/controllers/admin/tracks_controller.rb index 2cb6ec2b..3d51a677 100644 --- a/app/controllers/admin/tracks_controller.rb +++ b/app/controllers/admin/tracks_controller.rb @@ -20,6 +20,7 @@ module Admin def create @track = @program.tracks.new(track_params) @track.state = 'confirmed' + @track.cfp_active = true if @track.save redirect_to admin_conference_program_tracks_path(conference_id: @conference.short_title), notice: 'Track successfully created.' @@ -60,10 +61,55 @@ module Admin end end + def restart + update_state(:restart, "Review for #{@track.name} started!") + end + + def to_accept + update_state(:to_accept, "Track #{@track.name} marked as a possible acceptance!") + end + + def accept + if @track.room && @track.start_date && @track.end_date + update_state(:accept, "Track #{@track.name} accepted!") + else + flash[:alert] = 'Please make sure that the track has a room and start/end dates before accepting it' + redirect_to edit_admin_conference_program_track_path(@conference.short_title, @track) + end + end + + def confirm + update_state(:confirm, "Track #{@track.name} confirmed!") + end + + def to_reject + update_state(:to_reject, "Track #{@track.name} marked as a possible rejection!") + end + + def reject + update_state(:reject, "Track #{@track.name} rejected!") + end + + def cancel + update_state(:cancel, "Track #{@track.name} canceled!") + end + private def track_params params.require(:track).permit(:name, :description, :color, :short_name, :cfp_active, :start_date, :end_date, :room_id) end + + def update_state(transition, notice) + errors = @track.update_state(transition) + + if errors.blank? + flash[:notice] = notice + else + flash[:error] = errors + end + + redirect_back_or_to(admin_conference_program_tracks_path(conference_id: @conference.short_title)) + end end end diff --git a/app/controllers/tracks_controller.rb b/app/controllers/tracks_controller.rb index 59deae3c..9305950e 100644 --- a/app/controllers/tracks_controller.rb +++ b/app/controllers/tracks_controller.rb @@ -4,7 +4,7 @@ class TracksController < ApplicationController load_and_authorize_resource through: :program, find_by: :short_name def index - @tracks = current_user.tracks.where(program: @program) + @tracks = @tracks.where(submitter: current_user) end def show; end @@ -38,9 +38,33 @@ class TracksController < ApplicationController end end + def restart + update_state(:restart, "Track #{@track.name} re-submitted.") + end + + def confirm + update_state(:confirm, "Track #{@track.name} confirmed.") + end + + def withdraw + update_state(:withdraw, "Track #{@track.name} withdrawn.") + end + private def track_params - params.require(:track).permit(:name, :description, :color, :short_name) + params.require(:track).permit(:name, :description, :color, :short_name, :start_date, :end_date) + end + + def update_state(transition, notice) + errors = @track.update_state(transition) + + if errors.blank? + flash[:notice] = notice + else + flash[:error] = errors + end + + redirect_back_or_to(conference_program_tracks_path(conference_id: @conference.short_title)) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fdef7b4a..040927c1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -56,7 +56,7 @@ module ApplicationHelper end def tracks(conference) - all = conference.program.tracks.map { |t| t.name if !t.self_organized? || t.confirmed? && t.cfp_active }.compact + all = conference.program.tracks.where(state: 'confirmed', cfp_active: true).pluck(:name) first = all[0...-1] last = all[-1] ts = '' diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 012bd930..dbc609ac 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -39,4 +39,12 @@ module EventsHelper content_tag :span, 'REPLACEMENT', class: (['label', 'label-info'] + label_classes) end end + + def track_selector_input(form) + if @program.tracks.any? + form.input :track_id, as: :select, + collection: @program.tracks.where(state: 'confirmed', cfp_active: true).pluck(:name, :id), + include_blank: true + end + end end diff --git a/app/models/ability.rb b/app/models/ability.rb index e5dbd7e4..63ec68dc 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -100,8 +100,10 @@ class Ability track.new_record? && track.program.cfps.for_tracks.try(:open?) end - can [:index, :show, :edit, :update], Track do |track| - user == track.submitter + can [:index, :show, :restart, :confirm, :withdraw], Track, submitter_id: user.id + + can [:edit, :update], Track do |track| + user == track.submitter && !(track.accepted? || track.confirmed?) end end diff --git a/app/models/admin_ability.rb b/app/models/admin_ability.rb index 716aecb0..b0c9d4c9 100644 --- a/app/models/admin_ability.rb +++ b/app/models/admin_ability.rb @@ -275,6 +275,10 @@ class AdminAbility can :manage, Track, id: track_ids_for_track_organizer + cannot [:edit, :update], Track do |track| + track.self_organized_and_accepted_or_confirmed? + end + # Show Roles in the admin sidebar and allow authorization of the index action can [:index, :show], Role do |role| role.resource_type == 'Conference' || role.resource_type == 'Track' diff --git a/app/models/event.rb b/app/models/event.rb index 8436aac9..682eb6c8 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -45,6 +45,7 @@ class Event < ActiveRecord::Base validates :max_attendees, numericality: { only_integer: true, greater_than_or_equal_to: 1, allow_nil: true } validate :max_attendees_no_more_than_room_size + validate :acceptable_track scope :confirmed, -> { where(state: 'confirmed') } scope :canceled, -> { where(state: 'canceled') } @@ -303,4 +304,11 @@ class Event < ActiveRecord::Base def conference_id program.conference_id end + + ## + # Allow only confirmed tracks that belong to the same program and are included in the cfp + def acceptable_track + return unless track && track.program && program + errors.add(:track, 'is invalid') unless track.confirmed? && track.cfp_active && track.program == program + end end diff --git a/app/models/track.rb b/app/models/track.rb index a53471bc..3743cd79 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -22,13 +22,13 @@ class Track < ActiveRecord::Base } validates :state, presence: true, - inclusion: { in: %w(new to_accept accepted confirmed to_reject rejected canceled withdrawn) }, - if: :self_organized? - validates :cfp_active, inclusion: { in: [true, false] }, if: :self_organized? + inclusion: { in: %w(new to_accept accepted confirmed to_reject rejected canceled withdrawn) } + validates :cfp_active, inclusion: { in: [true, false] } validates :start_date, presence: true, if: :self_organized_and_accepted_or_confirmed? validates :end_date, presence: true, if: :self_organized_and_accepted_or_confirmed? validates :room, presence: true, if: :self_organized_and_accepted_or_confirmed? - validate :valid_dates, if: :self_organized_and_accepted_or_confirmed? + validate :valid_dates + validate :valid_room, if: :self_organized_and_accepted_or_confirmed? before_validation :capitalize_color @@ -45,7 +45,7 @@ class Track < ActiveRecord::Base event :restart do transitions to: :new, from: [:rejected, :withdrawn, :canceled] end - event :readiness_to_accept do + event :to_accept do transitions to: :to_accept, from: [:new] end event :accept do @@ -54,7 +54,7 @@ class Track < ActiveRecord::Base event :confirm do transitions to: :confirmed, from: [:accepted], on_transition: :assign_role_to_submitter end - event :readiness_to_reject do + event :to_reject do transitions to: :to_reject, from: [:new] end event :reject do @@ -107,6 +107,7 @@ class Track < ActiveRecord::Base events.each do |event| event.track = nil + event.save! end end @@ -137,6 +138,19 @@ class Track < ActiveRecord::Base self_organized? && (accepted? || confirmed?) end + def update_state(transition) + error = '' + + begin + send(transition) + rescue Transitions::InvalidTransition => e + error += "State update failed. #{e.message} " + end + + error += errors.full_messages.join(', ') unless save + error + end + private def generate_guid @@ -162,26 +176,32 @@ class Track < ActiveRecord::Base end def valid_dates - return unless start_date && end_date - - if program && program.conference && program.conference.start_date && (start_date < program.conference.start_date) - errors.add(:start_date, "can't be before the conference start date (#{program.conference.end_date})") + if start_date && program && program.conference && program.conference.start_date && (start_date < program.conference.start_date) + errors.add(:start_date, "can't be before the conference start date (#{program.conference.start_date})") end - if program && program.conference && program.conference.start_date && (end_date < program.conference.start_date) - errors.add(:end_date, "can't be before the conference start date (#{program.conference.end_date})") + if end_date && program && program.conference && program.conference.start_date && (end_date < program.conference.start_date) + errors.add(:end_date, "can't be before the conference start date (#{program.conference.start_date})") end - if program && program.conference && program.conference.end_date && (start_date > program.conference.end_date) + if start_date && program && program.conference && program.conference.end_date && (start_date > program.conference.end_date) errors.add(:start_date, "can't be after the conference end date (#{program.conference.end_date})") end - if program && program.conference && program.conference.end_date && (end_date > program.conference.end_date) + if end_date && program && program.conference && program.conference.end_date && (end_date > program.conference.end_date) errors.add(:end_date, "can't be after the conference end date (#{program.conference.end_date})") end - if start_date > end_date - errors.add(:start_date, 'can\'t be after the end_date') + if start_date && end_date && (start_date > end_date) + errors.add(:start_date, 'can\'t be after the end date') + end + end + + ## + # Verify that the room is a room of the conference + def valid_room + if room && room.venue && room.venue.conference && program && program.conference && (program.conference != room.venue.conference) + errors.add(:room, "must be a room of #{program.conference.venue.name}") end end end diff --git a/app/views/admin/tracks/_change_state_dropdown.html.haml b/app/views/admin/tracks/_change_state_dropdown.html.haml new file mode 100644 index 00000000..0bbbcd7f --- /dev/null +++ b/app/views/admin/tracks/_change_state_dropdown.html.haml @@ -0,0 +1,34 @@ +- if track.transition_possible? :restart + %li= link_to 'Start review', + restart_admin_conference_program_track_path(@conference.short_title, track), + method: :patch, id: "restart_track_#{track.id}" + +- if track.transition_possible? :to_accept + %li= link_to 'Mark as possible acceptance', + to_accept_admin_conference_program_track_path(@conference.short_title, track), + method: :patch, id: "to_accept_track_#{track.id}" + +- if track.transition_possible? :accept + %li= link_to 'Accept track request', + accept_admin_conference_program_track_path(@conference.short_title, track), + method: :patch, id: "accept_track_#{track.id}" + +- if track.transition_possible? :confirm + %li= link_to 'Confirm track', + confirm_admin_conference_program_track_path(@conference.short_title, track), + method: :patch, id: "confirm_track_#{track.id}" + +- if track.transition_possible? :to_reject + %li= link_to 'Mark as possible rejection', + to_reject_admin_conference_program_track_path(@conference.short_title, track), + method: :patch, id: "to_reject_track_#{track.id}" + +- if track.transition_possible? :reject + %li= link_to 'Reject track request', + reject_admin_conference_program_track_path(@conference.short_title, track), + method: :patch, confirm: 'Are you sure?', id: "reject_track_#{track.id}" + +- if track.transition_possible? :cancel + %li= link_to 'Cancel track request', + cancel_admin_conference_program_track_path(@conference.short_title, track), + method: :patch, id: "cancel_track_#{track.id}" diff --git a/app/views/admin/tracks/_form.html.haml b/app/views/admin/tracks/_form.html.haml index cb2e8b01..eb12561b 100644 --- a/app/views/admin/tracks/_form.html.haml +++ b/app/views/admin/tracks/_form.html.haml @@ -19,6 +19,5 @@ - else Please add a venue with rooms, if you want to select a room for the track. = f.input :description, input_html: {rows: 2, data: { provide: 'markdown-editable' } }, hint: markdown_hint - - if @track.self_organized? - = f.input :cfp_active, label: 'Allow event submitters to select this track for their proposal' + = f.input :cfp_active, label: 'Allow event submitters to select this track for their proposal' = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/tracks/index.html.haml b/app/views/admin/tracks/index.html.haml index 4da97a18..0cfe0ff2 100644 --- a/app/views/admin/tracks/index.html.haml +++ b/app/views/admin/tracks/index.html.haml @@ -40,21 +40,24 @@ = track.color %td - if track.self_organized? - = track.state + .btn-group + %button{ type: 'button', class: 'btn btn-link dropdown-toggle', 'data-toggle' => 'dropdown' } + = track.state.humanize + %span.caret + %ul.dropdown-menu{ role: 'menu' } + = render 'change_state_dropdown', track: track - else = track.state.humanize %td - - if track.self_organized? - = check_box_tag "#{@conference.short_title}_#{track.short_name}", track.id, track.cfp_active, - class: 'switch-checkbox', method: :patch, - url: toggle_cfp_inclusion_admin_conference_program_track_path(@conference.short_title, id: track.short_name)+"?included=", - data: { size: 'small', - on_color: 'success', - off_color: 'warning', - on_text: 'Yes', - off_text: 'No' } - - else - %i.fa.fa-check + = check_box_tag "#{@conference.short_title}_#{track.short_name}", track.id, track.cfp_active, + class: 'switch-checkbox', method: :patch, + url: toggle_cfp_inclusion_admin_conference_program_track_path(@conference.short_title, id: track.short_name)+"?included=", + data: { size: 'small', + on_color: 'success', + off_color: 'warning', + on_text: 'Yes', + off_text: 'No' } + %td - if track.room = link_to track.room.name, admin_conference_venue_room_path(@conference.short_title, track.room.id) @@ -72,8 +75,9 @@ N/A %td .btn-group{role: "group"} - = link_to 'Edit', edit_admin_conference_program_track_path(@conference.short_title, track), - method: :get, class: 'btn btn-primary' + - if can? :edit, track + = link_to 'Edit', edit_admin_conference_program_track_path(@conference.short_title, track), + method: :get, class: 'btn btn-primary' - if can? :destroy, track = link_to 'Delete', admin_conference_program_track_path(@conference.short_title, track), method: :delete, class: 'btn btn-danger', diff --git a/app/views/proposals/_proposal_form.html.haml b/app/views/proposals/_proposal_form.html.haml index f31651a1..4b66240c 100644 --- a/app/views/proposals/_proposal_form.html.haml +++ b/app/views/proposals/_proposal_form.html.haml @@ -6,10 +6,7 @@ = speaker_selector_input f - - if @program.tracks.any? - = f.input :track_id, as: :select, - collection: @program.tracks.map {|track| ["#{track.name}", track.id] }, - include_blank: true + = track_selector_input f = f.input :event_type_id, as: :select, collection: @conference.program.event_types.map {|type| ["#{type.title} - #{show_time(type.length)}", type.id, diff --git a/app/views/tracks/_form.html.haml b/app/views/tracks/_form.html.haml index 0e48a851..2a55df5a 100644 --- a/app/views/tracks/_form.html.haml +++ b/app/views/tracks/_form.html.haml @@ -9,9 +9,11 @@ Track .row .col-md-12 - = semantic_form_for(@track, url: (@track.new_record? ? conference_program_tracks_path : conference_program_track_path(@conference.short_title, @track))) do |f| + = semantic_form_for(@track, url: (@track.new_record? ? conference_program_tracks_path(@conference.short_title) : conference_program_track_path(@conference.short_title, @track))) do |f| = f.input :name = f.input :short_name, hint: "A short and unique handle for the track, using only letters, numbers, underscores, and dashes. This will be used to identify the track in URLs etc. Example: 'my_awesome_track'", input_html: { required: 'required', pattern: '[a-zA-Z0-9_-]+', title: 'Only letters, numbers, underscores, and dashes.' } = f.input :color, input_html: {size: 6, type: 'color'}, required: true + = f.input :start_date, as: :string, input_html: { id: 'registration-period-start-datepicker', start_date: @conference.start_date, end_date: @conference.end_date, readonly: 'readonly' } + = f.input :end_date, as: :string, input_html: { id: 'registration-period-end-datepicker', readonly: 'readonly' } = f.input :description, input_html: {rows: 2, data: { provide: 'markdown-editable' } }, required: true, hint: markdown_hint = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/tracks/index.html.haml b/app/views/tracks/index.html.haml index 7e16304f..fd1235d4 100644 --- a/app/views/tracks/index.html.haml +++ b/app/views/tracks/index.html.haml @@ -16,6 +16,8 @@ %th Description %th Color %th State + %th Start Date + %th End Date %th Actions %tbody - @tracks.each do |track| @@ -34,10 +36,31 @@ %td = track.state.humanize %td - = link_to 'Edit', edit_conference_program_track_path(@conference.short_title, track), - method: :get, class: 'btn btn-primary' + - if track.start_date + = track.start_date.strftime('%A, %B %-d. %Y') + - else + N/A + %td + - if track.end_date + = track.end_date.strftime('%A, %B %-d. %Y') + - else + N/A + %td + - if track.transition_possible? :confirm + = link_to 'Confirm', confirm_conference_program_track_path(@conference.short_title, track), + method: :patch, class: 'btn btn-mini btn-success', id: "confirm_track_#{track.id}" + - if track.transition_possible? :withdraw + = link_to 'Withdraw', withdraw_conference_program_track_path(@conference.short_title, track), + method: :patch, data: { confirm: 'Are you sure you want to withdraw this track request?' }, + class: 'btn btn-mini btn-warning', id: "withdraw_track_request_#{track.id}" + - if track.transition_possible? :restart + = link_to 'Re-Submit', restart_conference_program_track_path(@conference.short_title, track), + method: :patch, class: 'btn btn-mini btn-success', id: "resubmit_track_request_#{track.id}" + - if can? :edit, track + = link_to 'Edit', edit_conference_program_track_path(@conference.short_title, track), + method: :get, class: 'btn btn-primary' .row .col-md-12 - - if can? :create, @track + - if can? :new, @program.tracks.new = link_to "New Track request", new_conference_program_track_path(@conference.short_title), class: 'btn btn-success pull-right' diff --git a/app/views/tracks/show.html.haml b/app/views/tracks/show.html.haml index 37c180ae..c5bc27e5 100644 --- a/app/views/tracks/show.html.haml +++ b/app/views/tracks/show.html.haml @@ -17,10 +17,25 @@ State: %dd = @track.state.humanize + %dt + Start date: + %dd + - if @track.start_date + = @track.start_date.strftime('%A, %B %-d. %Y') + - else + N/A + %dt + End date: + %dd + - if @track.end_date + = @track.end_date.strftime('%A, %B %-d. %Y') + - else + N/A %dt Description %dd = @track.description .row .col-md-12.text-right - = link_to 'Edit Track request', edit_conference_program_track_path(@conference.short_title, @track), class: 'btn btn-primary' + - if can? :edit, @track + = link_to 'Edit Track request', edit_conference_program_track_path(@conference.short_title, @track), class: 'btn btn-primary' diff --git a/config/routes.rb b/config/routes.rb index be507d35..d4d6d0ee 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -69,6 +69,13 @@ Osem::Application.routes.draw do resources :tracks do member do patch :toggle_cfp_inclusion + patch :restart + patch :to_accept + patch :accept + patch :confirm + patch :to_reject + patch :reject + patch :cancel end end resources :event_types @@ -149,7 +156,13 @@ Osem::Application.routes.draw do patch '/restart' => 'proposals#restart' end end - resources :tracks, except: :destroy + resources :tracks, except: :destroy do + member do + patch :restart + patch :confirm + patch :withdraw + end + end end # TODO: change conference_registrations to singular resource diff --git a/db/migrate/20170720134353_make_track_cfp_active_not_null.rb b/db/migrate/20170720134353_make_track_cfp_active_not_null.rb new file mode 100644 index 00000000..0f75d046 --- /dev/null +++ b/db/migrate/20170720134353_make_track_cfp_active_not_null.rb @@ -0,0 +1,14 @@ +class MakeTrackCfpActiveNotNull < ActiveRecord::Migration + class TmpTrack < ActiveRecord::Base + self.table_name = 'tracks' + end + + def change + TmpTrack.where(cfp_active: nil).each do |track| + track.cfp_active = true + track.save! + end + + change_column_null :tracks, :cfp_active, false + end +end diff --git a/db/schema.rb b/db/schema.rb index aa2f160d..f8cc3ddc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -520,7 +520,7 @@ ActiveRecord::Schema.define(version: 20170807092805) do t.integer "program_id" t.string "short_name", null: false t.string "state", default: "new", null: false - t.boolean "cfp_active" + t.boolean "cfp_active", null: false t.integer "submitter_id" t.integer "room_id" t.date "start_date" diff --git a/spec/controllers/admin/tracks_controller_spec.rb b/spec/controllers/admin/tracks_controller_spec.rb index ed76fe68..70ca48a1 100644 --- a/spec/controllers/admin/tracks_controller_spec.rb +++ b/spec/controllers/admin/tracks_controller_spec.rb @@ -5,7 +5,7 @@ describe Admin::TracksController do let(:conference) { create(:conference) } let!(:track) { create(:track, program: conference.program, color: '#800080') } - let!(:self_organized_track) { create(:track, :self_organized, program: conference.program) } + let!(:self_organized_track) { create(:track, :self_organized, program: conference.program, name: 'My awesome track') } before :each do sign_in(admin) @@ -83,6 +83,7 @@ describe Admin::TracksController do it 'the new tracks has the correct attributes' do expect(assigns(:track).state).to eq 'confirmed' + expect(assigns(:track).cfp_active).to eq true end end @@ -257,4 +258,204 @@ describe Admin::TracksController do end end end + + describe 'PATCH #restart' do + before :each do + self_organized_track.state = 'canceled' + self_organized_track.save! + patch :restart, conference_id: conference.short_title, id: self_organized_track.short_name + self_organized_track.reload + end + + it 'assigns the correct track' do + expect(assigns(:track)).to eq self_organized_track + end + + it 'shows message in flash notice' do + expect(flash[:notice]).to eq 'Review for My awesome track started!' + end + + it 'changes the track\'s state to new' do + expect(self_organized_track.state).to eq 'new' + end + end + + describe 'PATCH #to_accept' do + before :each do + patch :to_accept, conference_id: conference.short_title, id: self_organized_track.short_name + self_organized_track.reload + end + + it 'assigns the correct track' do + expect(assigns(:track)).to eq self_organized_track + end + + it 'shows message in flash notice' do + expect(flash[:notice]).to eq 'Track My awesome track marked as a possible acceptance!' + end + + it 'changes the track\'s state to to_accept' do + expect(self_organized_track.state).to eq 'to_accept' + end + end + + describe 'PATCH #accept' do + shared_examples 'fails to accept' do |start_date, end_date, room| + before :each do + self_organized_track.start_date = start_date ? Date.today : nil + self_organized_track.end_date = end_date ? Date.today : nil + if room + conference.venue = create(:venue) + self_organized_track.room = create(:room, venue: conference.venue) + else + self_organized_track.room = nil + end + self_organized_track.save! + + patch :accept, conference_id: conference.short_title, id: self_organized_track.short_name + self_organized_track.reload + end + + it 'redirects to Tracks#edit' do + expect(response).to redirect_to edit_admin_conference_program_track_path(conference.short_title, self_organized_track) + end + + it 'shows message in flash alert' do + expect(flash[:alert]).to eq 'Please make sure that the track has a room and start/end dates before accepting it' + end + end + + context 'has start_date, end_date and room' do + before :each do + self_organized_track.start_date = Date.today + self_organized_track.end_date = Date.today + conference.venue = create(:venue) + self_organized_track.room = create(:room, venue: conference.venue) + self_organized_track.save! + + patch :accept, conference_id: conference.short_title, id: self_organized_track.short_name + self_organized_track.reload + end + + it 'assigns the correct track' do + expect(assigns(:track)).to eq self_organized_track + end + + it 'shows message in flash notice' do + expect(flash[:notice]).to eq 'Track My awesome track accepted!' + end + + it 'changes the track\'s state to accepted' do + expect(self_organized_track.state).to eq 'accepted' + end + end + + context 'has start_date and end_date' do + it_behaves_like 'fails to accept', true, true, false + end + + context 'has start_date and room' do + it_behaves_like 'fails to accept', true, false, true + end + + context 'has start_date' do + it_behaves_like 'fails to accept', true, false, false + end + + context 'has end_date and room' do + it_behaves_like 'fails to accept', false, true, true + end + + context 'has end_date' do + it_behaves_like 'fails to accept', false, true, false + end + + context 'has room' do + it_behaves_like 'fails to accept', false, false, true + end + + context 'has non of start_date, end_date, room' do + it_behaves_like 'fails to accept', false, false, false + end + end + + describe 'PATCH #confirm' do + before :each do + self_organized_track.state = 'accepted' + self_organized_track.save! + patch :confirm, conference_id: conference.short_title, id: self_organized_track.short_name + self_organized_track.reload + end + + it 'assigns the correct track' do + expect(assigns(:track)).to eq self_organized_track + end + + it 'shows message in flash notice' do + expect(flash[:notice]).to eq 'Track My awesome track confirmed!' + end + + it 'changes the track\'s state to confirmed' do + expect(self_organized_track.state).to eq 'confirmed' + end + end + + describe 'PATCH #to_reject' do + before :each do + patch :to_reject, conference_id: conference.short_title, id: self_organized_track.short_name + self_organized_track.reload + end + + it 'assigns the correct track' do + expect(assigns(:track)).to eq self_organized_track + end + + it 'shows message in flash notice' do + expect(flash[:notice]).to eq 'Track My awesome track marked as a possible rejection!' + end + + it 'changes the track\'s state to to_reject' do + expect(self_organized_track.state).to eq 'to_reject' + end + end + + describe 'PATCH #reject' do + before :each do + patch :reject, conference_id: conference.short_title, id: self_organized_track.short_name + self_organized_track.reload + end + + it 'assigns the correct track' do + expect(assigns(:track)).to eq self_organized_track + end + + it 'shows message in flash notice' do + expect(flash[:notice]).to eq 'Track My awesome track rejected!' + end + + it 'changes the track\'s state to rejected' do + expect(self_organized_track.state).to eq 'rejected' + end + end + + describe 'PATCH #cancel' do + before :each do + self_organized_track.state = 'confirmed' + self_organized_track.save! + patch :cancel, conference_id: conference.short_title, id: self_organized_track.short_name + self_organized_track.reload + end + + it 'assigns the correct track' do + expect(assigns(:track)).to eq self_organized_track + end + + it 'shows message in flash notice' do + expect(flash[:notice]).to eq 'Track My awesome track canceled!' + end + + it 'changes the track\'s state to canceled' do + expect(self_organized_track.state).to eq 'canceled' + end + end end diff --git a/spec/controllers/tracks_controller_spec.rb b/spec/controllers/tracks_controller_spec.rb index 373435c2..0e3a0553 100644 --- a/spec/controllers/tracks_controller_spec.rb +++ b/spec/controllers/tracks_controller_spec.rb @@ -1,12 +1,11 @@ require 'spec_helper' describe TracksController do - # A regular user should be used when the track requests have been enabled let(:user) { create(:admin) } let(:conference) { create(:conference) } let!(:regular_track) { create(:track, program: conference.program) } - let!(:self_organized_track) { create(:track, :self_organized, program: conference.program, submitter: user, color: '#800080') } + let!(:self_organized_track) { create(:track, :self_organized, program: conference.program, submitter: user, name: 'My awesome track', color: '#800080') } before :each do sign_in(user) @@ -176,4 +175,67 @@ describe TracksController do end end end + + describe 'PATCH #restart' do + before :each do + self_organized_track.state = 'withdrawn' + self_organized_track.save! + patch :restart, conference_id: conference.short_title, id: self_organized_track.short_name + self_organized_track.reload + end + + it 'assigns the correct track' do + expect(assigns(:track)).to eq self_organized_track + end + + it 'shows message in flash notice' do + expect(flash[:notice]).to eq 'Track My awesome track re-submitted.' + end + + it 'changes the track\'s state to new' do + expect(self_organized_track.state).to eq 'new' + end + end + + describe 'PATCH #confirm' do + before :each do + self_organized_track.state = 'accepted' + self_organized_track.save! + patch :confirm, conference_id: conference.short_title, id: self_organized_track.short_name + self_organized_track.reload + end + + it 'assigns the correct track' do + expect(assigns(:track)).to eq self_organized_track + end + + it 'shows message in flash notice' do + expect(flash[:notice]).to eq 'Track My awesome track confirmed.' + end + + it 'changes the track\'s state to confirmed' do + expect(self_organized_track.state).to eq 'confirmed' + end + end + + describe 'PATCH #withdraw' do + before :each do + self_organized_track.state = 'confirmed' + self_organized_track.save! + patch :withdraw, conference_id: conference.short_title, id: self_organized_track.short_name + self_organized_track.reload + end + + it 'assigns the correct track' do + expect(assigns(:track)).to eq self_organized_track + end + + it 'shows message in flash notice' do + expect(flash[:notice]).to eq 'Track My awesome track withdrawn.' + end + + it 'changes the track\'s state to withdrawn' do + expect(self_organized_track.state).to eq 'withdrawn' + end + end end diff --git a/spec/factories/tracks.rb b/spec/factories/tracks.rb index d30a686e..d61c9a1b 100644 --- a/spec/factories/tracks.rb +++ b/spec/factories/tracks.rb @@ -5,12 +5,16 @@ FactoryGirl.define do color { Faker::Color.hex_color } short_name { SecureRandom.urlsafe_base64(5) } state 'confirmed' + cfp_active true program trait :self_organized do association :submitter, factory: :user state 'new' cfp_active false + start_date { Date.today } + end_date { Date.today } + room end end end diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 2144cec6..ff3f14cb 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -26,6 +26,7 @@ describe 'User' do let(:program_with_cfp) { create(:program, :with_cfp) } let(:program_without_cfp) { create(:program) } + let(:program_with_call_for_tracks) { create(:cfp, cfp_type: 'tracks').program } let(:conference_with_open_registration) { create(:conference) } let!(:open_registration_period) { create(:registration_period, conference: conference_with_open_registration, start_date: Date.current - 6.days) } let(:conference_with_closed_registration) { create(:conference) } @@ -82,6 +83,10 @@ describe 'User' do let(:user_event_with_cfp) { create(:event, users: [user], program: program_with_cfp) } let(:user_commercial) { create(:commercial, commercialable: user_event_with_cfp) } + let(:user_self_organized_track) { create(:track, :self_organized, submitter: user) } + let(:accepted_user_self_organized_track) { create(:track, :self_organized, submitter: user, state: 'accepted') } + let(:confirmed_user_self_organized_track) { create(:track, :self_organized, submitter: user, state: 'confirmed') } + let(:other_self_organized_track) { create(:track, :self_organized) } it{ should be_able_to(:manage, user) } @@ -114,6 +119,31 @@ describe 'User' do it{ should be_able_to(:create, user_event_with_cfp.commercials.new) } it{ should be_able_to(:manage, user_commercial) } it{ should_not be_able_to(:manage, commercial_event_unconfirmed) } + + it{ should be_able_to(:new, Track.new(program: program_with_call_for_tracks)) } + it{ should be_able_to(:create, Track.new(program: program_with_call_for_tracks)) } + it{ should_not be_able_to(:new, Track.new(program: program_without_cfp)) } + it{ should_not be_able_to(:create, Track.new(program: program_without_cfp)) } + + it{ should be_able_to(:index, user_self_organized_track) } + it{ should be_able_to(:show, user_self_organized_track) } + it{ should be_able_to(:restart, user_self_organized_track) } + it{ should be_able_to(:confirm, user_self_organized_track) } + it{ should be_able_to(:withdraw, user_self_organized_track) } + it{ should_not be_able_to(:index, other_self_organized_track) } + it{ should_not be_able_to(:show, other_self_organized_track) } + it{ should_not be_able_to(:restart, other_self_organized_track) } + it{ should_not be_able_to(:confirm, other_self_organized_track) } + it{ should_not be_able_to(:withdraw, other_self_organized_track) } + + it{ should be_able_to(:edit, user_self_organized_track) } + it{ should be_able_to(:update, user_self_organized_track) } + it{ should_not be_able_to(:edit, accepted_user_self_organized_track) } + it{ should_not be_able_to(:update, accepted_user_self_organized_track) } + it{ should_not be_able_to(:edit, confirmed_user_self_organized_track) } + it{ should_not be_able_to(:update, confirmed_user_self_organized_track) } + it{ should_not be_able_to(:edit, other_self_organized_track) } + it{ should_not be_able_to(:update, other_self_organized_track) } end end end diff --git a/spec/models/admin_ability_spec.rb b/spec/models/admin_ability_spec.rb index 16456a19..126d32de 100644 --- a/spec/models/admin_ability_spec.rb +++ b/spec/models/admin_ability_spec.rb @@ -44,7 +44,7 @@ describe 'User with admin role' do let!(:my_event_schedule) { create(:event_schedule, schedule: my_schedule) } let!(:other_event_schedule) { create(:event_schedule, schedule: other_schedule) } - let!(:my_self_organized_track) { create(:track, :self_organized, program: my_conference.program) } + let!(:my_self_organized_track) { create(:track, :self_organized, program: my_conference.program, state: 'confirmed') } context 'user #is_admin?' do let(:venue) { my_conference.venue } @@ -505,6 +505,8 @@ describe 'User with admin role' do it{ should be_able_to(:show, my_conference.program) } it{ should be_able_to(:update, new_track) } it{ should be_able_to(:manage, my_self_organized_track) } + it{ should_not be_able_to(:edit, my_self_organized_track) } + it{ should_not be_able_to(:update, my_self_organized_track) } it_behaves_like 'user with any role' it_behaves_like 'user with non-organizer role', 'track_organizer' diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index 91c06140..26070134 100755 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -606,8 +606,8 @@ describe Conference do describe 'tracks_distribution' do before do subject.email_settings = create(:email_settings) - @track_one = create(:track, name: 'Track One', color: '#000000') - @track_two = create(:track, name: 'Track Two', color: '#ffffff') + @track_one = create(:track, name: 'Track One', color: '#000000', program: subject.program) + @track_two = create(:track, name: 'Track Two', color: '#ffffff', program: subject.program) end describe '#tracks_distribution' do diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index b723d151..3ada61ca 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -96,6 +96,40 @@ describe Event do end end end + + describe '#acceptable_track' do + context 'is valid' do + it 'when the track belong to the same program, is confirmed and is included in the cfp' do + track = create(:track, state: 'confirmed', cfp_active: true, program: conference.program) + event = build(:event, program: conference.program, track: track) + expect(event.valid?).to eq true + end + end + + context 'is invalid' do + it 'when the track doesn\'t have the same program' do + track = create(:track, state: 'confirmed', cfp_active: true) + event = build(:event, program: conference.program, track: track) + expect(event.valid?).to eq false + expect(event.errors[:track]).to eq ['is invalid'] + end + + it 'when the track is unconfirmed' do + track = create(:track, cfp_active: true, program: conference.program) + allow(track).to receive(:confirmed?).and_return(false) + event = build(:event, program: conference.program, track: track) + expect(event.valid?).to eq false + expect(event.errors[:track]).to eq ['is invalid'] + end + + it 'when the track isn\'t included in the cfp' do + track = create(:track, state: 'confirmed', cfp_active: false, program: conference.program) + event = build(:event, program: conference.program, track: track) + expect(event.valid?).to eq false + expect(event.errors[:track]).to eq ['is invalid'] + end + end + end end describe '#comments_count' do diff --git a/spec/models/track_spec.rb b/spec/models/track_spec.rb index 840641cb..4853f31d 100644 --- a/spec/models/track_spec.rb +++ b/spec/models/track_spec.rb @@ -8,6 +8,7 @@ describe Track do describe 'association' do it { is_expected.to belong_to(:program) } it { is_expected.to belong_to(:submitter).class_name('User') } + it { is_expected.to belong_to(:room) } it { is_expected.to have_many(:events) } end @@ -23,23 +24,99 @@ describe Track do it { is_expected.to allow_value('My_track_name').for(:short_name) } it { is_expected.to_not allow_value('My track name').for(:short_name) } it { is_expected.to validate_uniqueness_of(:short_name).scoped_to(:program_id) } + it { is_expected.to validate_presence_of(:state) } + it { is_expected.to validate_inclusion_of(:state).in_array(%w[new to_accept accepted confirmed to_reject rejected canceled withdrawn]) } + it { is_expected.to validate_inclusion_of(:cfp_active).in_array([true, false]) } - context 'when self-organized' do + context 'when self_organized_and_accepted_or_confirmed? returns true' do before :each do - allow(subject).to receive(:self_organized?).and_return(true) + allow(subject).to receive(:self_organized_and_accepted_or_confirmed?).and_return(true) end - it { is_expected.to validate_presence_of(:state) } - it { is_expected.to validate_inclusion_of(:cfp_active).in_array([true, false]) } + it { is_expected.to validate_presence_of(:start_date) } + it { is_expected.to validate_presence_of(:end_date) } + it { is_expected.to validate_presence_of(:room) } end - context 'when regular' do + context 'when self_organized_and_accepted_or_confirmed? returns false' do before :each do - allow(subject).to receive(:self_organized?).and_return(false) + allow(subject).to receive(:self_organized_and_accepted_or_confirmed?).and_return(false) end - it { is_expected.to_not validate_presence_of(:state) } - it { is_expected.to_not validate_inclusion_of(:cfp_active) } + it { is_expected.to_not validate_presence_of(:start_date) } + it { is_expected.to_not validate_presence_of(:end_date) } + it { is_expected.to_not validate_presence_of(:room) } + end + + describe '#valid_dates' do + before :each do + @conference = create(:conference, start_date: 1.day.ago, end_date: 2.days.from_now) + end + + context 'is valid' do + it 'when the track\'s start date is before it\'s end date and between the conference start/end dates' do + track = build(:track, start_date: Date.today, end_date: Date.tomorrow, program: @conference.program) + expect(track.valid?).to eq true + end + end + + context 'is invalid' do + it 'when the track\'s start date is before the conference\'s start date' do + track = build(:track, start_date: 2.days.ago, end_date: Date.tomorrow, program: @conference.program) + expect(track.valid?).to eq false + expect(track.errors[:start_date]).to eq ["can't be before the conference start date (#{1.day.ago.to_date})"] + end + + it 'when the track\'s end date is before the conference\'s start date' do + track = build(:track, start_date: 3.days.ago, end_date: 2.days.ago, program: @conference.program) + expect(track.valid?).to eq false + expect(track.errors[:end_date]).to eq ["can't be before the conference start date (#{1.day.ago.to_date})"] + end + + it 'when the track\'s start date is after the conference\'s end date' do + track = build(:track, start_date: 3.days.from_now, end_date: 4.days.from_now, program: @conference.program) + expect(track.valid?).to eq false + expect(track.errors[:start_date]).to eq ["can't be after the conference end date (#{2.days.from_now.to_date})"] + end + + it 'when the track\'s end date is after the conference\'s end date' do + track = build(:track, start_date: Date.today, end_date: 3.days.from_now, program: @conference.program) + expect(track.valid?).to eq false + expect(track.errors[:end_date]).to eq ["can't be after the conference end date (#{2.days.from_now.to_date})"] + end + + it 'when the track\'s start date is after it\'s end date' do + track = build(:track, start_date: 1.day.from_now, end_date: 1.day.ago) + expect(track.valid?).to eq false + expect(track.errors[:start_date]).to eq ['can\'t be after the end date'] + end + end + end + + describe '#valid_room' do + before :each do + @conference = create(:conference) + @conference.venue = create(:venue, name: 'The venue') + end + + context 'is valid' do + it 'when the track\'s room belongs to the venue of the conference' do + room = create(:room, venue: @conference.venue) + track = build(:track, :self_organized, state: 'accepted', program: @conference.program, room: room) + expect(track.valid?).to eq true + end + end + + context 'is invalid' do + it 'when the track\'s room doesn\'t belong to the venue of the track\'s conference' do + other_conference = create(:conference) + other_conference.venue = create(:venue) + room = create(:room, venue: other_conference.venue) + track = build(:track, :self_organized, state: 'accepted', program: @conference.program, room: room) + expect(track.valid?).to eq false + expect(track.errors[:room]).to eq ['must be a room of The venue'] + end + end end end @@ -54,4 +131,226 @@ describe Track do expect(track.self_organized?).to eq false end end + + describe '#transition_possible?' do + shared_examples 'transition_possible?' do |state, transition, expected| + it "returns #{expected} for #{transition} event, when the track's state is #{state}}" do + my_self_organized_track = create(:track, :self_organized, state: state) + expect(my_self_organized_track.transition_possible?(transition.to_sym)).to eq expected + end + end + + states = [:new, :to_accept, :accepted, :confirmed, :to_reject, :rejected, :canceled, :withdrawn] + transitions = [:restart, :to_accept, :accept, :confirm, :to_reject, :reject, :cancel, :withdraw] + + states_transitions = { new: { restart: false, to_accept: true, accept: true, confirm: false, to_reject: true, reject: true, cancel: false, withdraw: true }, + to_accept: { restart: false, to_accept: false, accept: true, confirm: false, to_reject: false, reject: false, cancel: true, withdraw: true }, + accepted: { restart: false, to_accept: false, accept: false, confirm: true, to_reject: false, reject: false, cancel: true, withdraw: true }, + confirmed: { restart: false, to_accept: false, accept: false, confirm: false, to_reject: false, reject: false, cancel: true, withdraw: true }, + to_reject: { restart: false, to_accept: false, accept: false, confirm: false, to_reject: false, reject: true, cancel: true, withdraw: true }, + rejected: { restart: true, to_accept: false, accept: false, confirm: false, to_reject: false, reject: false, cancel: false, withdraw: false }, + canceled: { restart: true, to_accept: false, accept: false, confirm: false, to_reject: false, reject: false, cancel: false, withdraw: false }, + withdrawn: { restart: true, to_accept: false, accept: false, confirm: false, to_reject: false, reject: false, cancel: false, withdraw: false } } + + states.each do |state| + transitions.each do |transition| + it_behaves_like 'transition_possible?', state, transition, states_transitions[state.to_sym][transition.to_sym] + end + end + end + + describe '#assign_role_to_submitter' do + before :each do + Role.where(name: 'track_organizer', resource: self_organized_track).first_or_create + @submitter = self_organized_track.submitter + end + + it 'gives the role of the track organizer to the submitter of the track' do + expect(@submitter.has_role?(:track_organizer, self_organized_track)).to eq false + self_organized_track.assign_role_to_submitter + expect(@submitter.has_role?(:track_organizer, self_organized_track)).to eq true + end + + it 'is executed when the track is confirmed' do + self_organized_track.state = 'accepted' + self_organized_track.save! + expect(@submitter.has_role?(:track_organizer, self_organized_track)).to eq false + self_organized_track.confirm + expect(@submitter.has_role?(:track_organizer, self_organized_track)).to eq true + end + end + + describe '#revoke_role_and_cleanup' do + before :each do + Role.where(name: 'track_organizer', resource: self_organized_track).first_or_create + @a_track_organizer = create(:user) + self_organized_track.state = 'confirmed' + self_organized_track.cfp_active = true + self_organized_track.save! + @a_track_organizer.add_role 'track_organizer', self_organized_track + @an_event_of_the_track = create(:event, program: self_organized_track.program, track: self_organized_track) + end + + it 'revokes the role of the track organizer' do + expect(@a_track_organizer.has_role?(:track_organizer, self_organized_track)).to eq true + self_organized_track.revoke_role_and_cleanup + expect(@a_track_organizer.has_role?(:track_organizer, self_organized_track)).to eq false + end + + it 'removes the track from the events that have it set' do + expect(@an_event_of_the_track.track).to eq self_organized_track + self_organized_track.revoke_role_and_cleanup + @an_event_of_the_track.reload + expect(@an_event_of_the_track.track).to eq nil + end + + it 'is executed when the track is canceled' do + self_organized_track.state = 'confirmed' + self_organized_track.save! + self_organized_track.cancel + expect(@a_track_organizer.has_role?(:track_organizer, self_organized_track)).to eq false + @an_event_of_the_track.reload + expect(@an_event_of_the_track.track).to eq nil + end + + it 'is executed when the track is withdrawn' do + self_organized_track.withdraw + expect(@a_track_organizer.has_role?(:track_organizer, self_organized_track)).to eq false + @an_event_of_the_track.reload + expect(@an_event_of_the_track.track).to eq nil + end + end + + describe '#accepted?' do + context 'returns true' do + it 'when the state is "accepted"' do + self_organized_track.state = 'accepted' + self_organized_track.save! + expect(self_organized_track.accepted?).to eq true + end + end + + context 'returns false' do + %w[new to_accept confirmed to_reject rejected canceled withdrawn].each do |state| + it "when the state is \"#{state}\"" do + self_organized_track.state = state + self_organized_track.save! + expect(self_organized_track.accepted?).to eq false + end + end + end + end + + describe '#confirmed?' do + context 'returns true' do + it 'when the state is "confirmed"' do + self_organized_track.state = 'confirmed' + self_organized_track.save! + expect(self_organized_track.confirmed?).to eq true + end + end + + context 'returns false' do + %w[new to_accept accepted to_reject rejected canceled withdrawn].each do |state| + it "when the state is \"#{state}\"" do + self_organized_track.state = state + self_organized_track.save! + expect(self_organized_track.confirmed?).to eq false + end + end + end + end + + # accepted? and confirmed? are mutually exclusive (they can't be both true) + describe '#self_organized_and_accepted_or_confirmed?' do + context 'returns true' do + context 'when self_organized? returns true' do + before :each do + allow(track).to receive(:self_organized?).and_return(true) + end + + context 'accepted? returns true and confirmed? returns false' do + before :each do + allow(track).to receive(:accepted?).and_return(true) + allow(track).to receive(:confirmed?).and_return(false) + end + + it { expect(track.self_organized_and_accepted_or_confirmed?).to eq true } + end + + context 'accepted? returns false and confirmed? returns true' do + before :each do + allow(track).to receive(:accepted?).and_return(false) + allow(track).to receive(:confirmed?).and_return(true) + end + + it { expect(track.self_organized_and_accepted_or_confirmed?).to eq true } + end + end + end + + context 'returns false' do + context 'when self_organized? returns true' do + before :each do + allow(track).to receive(:self_organized?).and_return(true) + end + + context 'accepted? returns false and confirmed? returns false' do + before :each do + allow(track).to receive(:accepted?).and_return(false) + allow(track).to receive(:confirmed?).and_return(false) + end + + it { expect(track.self_organized_and_accepted_or_confirmed?).to eq false } + end + end + + context 'when self_organized? returns false' do + before :each do + allow(track).to receive(:self_organized?).and_return(false) + end + + context 'accepted? returns false and confirmed? returns false' do + before :each do + allow(track).to receive(:accepted?).and_return(false) + allow(track).to receive(:confirmed?).and_return(false) + end + + it { expect(track.self_organized_and_accepted_or_confirmed?).to eq false } + end + + context 'accepted? returns true and confirmed? returns false' do + before :each do + allow(track).to receive(:accepted?).and_return(true) + allow(track).to receive(:confirmed?).and_return(false) + end + + it { expect(track.self_organized_and_accepted_or_confirmed?).to eq false } + end + + context 'accepted? returns false and confirmed? returns true' do + before :each do + allow(track).to receive(:accepted?).and_return(false) + allow(track).to receive(:confirmed?).and_return(true) + end + + it { expect(track.self_organized_and_accepted_or_confirmed?).to eq false } + end + end + end + end + + describe '#create_organizer_role' do + it 'creates the role of the track organizer' do + expect(Role.find_by(name: 'track_organizer', resource: self_organized_track)).to eq nil + self_organized_track.send(:create_organizer_role) + expect(Role.find_by(name: 'track_organizer', resource: self_organized_track).description).to eq 'For the organizers of the Track' + end + + it 'is executed when the track is accepted' do + expect(Role.find_by(name: 'track_organizer', resource: self_organized_track)).to eq nil + self_organized_track.accept + expect(Role.find_by(name: 'track_organizer', resource: self_organized_track).description).to eq 'For the organizers of the Track' + end + end end From f9903eba16e4ff807d484874939971a7d0cddf59 Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Sun, 16 Jul 2017 20:29:03 +0300 Subject: [PATCH 38/50] Change Cfp scopes to class methods When no record matches the requested criteria a scope will return all the records In this case, if no record can be found we want the result to be nil Also, make some readability fixes in specs --- app/models/cfp.rb | 21 ++++++++++-- spec/features/cfp_ability_spec.rb | 12 +++---- .../organization_admin_ability_spec.rb | 12 +++---- spec/features/organizer_ability_spec.rb | 12 +++---- spec/models/cfp_spec.rb | 32 +++++++++++++------ 5 files changed, 59 insertions(+), 30 deletions(-) diff --git a/app/models/cfp.rb b/app/models/cfp.rb index 44d8281b..8248cd1a 100644 --- a/app/models/cfp.rb +++ b/app/models/cfp.rb @@ -3,9 +3,6 @@ class Cfp < ActiveRecord::Base TYPES = %w(events booths tracks).freeze - scope :for_events, (-> { find_by(cfp_type: 'events') }) - scope :for_tracks, (-> { find_by(cfp_type: 'tracks') }) - has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } belongs_to :program @@ -79,6 +76,24 @@ class Cfp < ActiveRecord::Base (start_date..end_date).cover?(Date.current) end + ## + # Finds the cfp for events if it exists + # + # ====Returns + # * +Cfp+ -> The cfp with type 'events' + def self.for_events + find_by(cfp_type: 'events') + end + + ## + # Finds the cfp for tracks if it exists + # + # ====Returns + # * +Cfp+ -> The cfp with type 'tracks' + def self.for_tracks + find_by(cfp_type: 'tracks') + end + private def before_end_of_conference diff --git a/spec/features/cfp_ability_spec.rb b/spec/features/cfp_ability_spec.rb index cd9fa3bd..1607401c 100644 --- a/spec/features/cfp_ability_spec.rb +++ b/spec/features/cfp_ability_spec.rb @@ -73,7 +73,7 @@ feature 'Has correct abilities' do expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp)) # Event, booth, track cfps exist - cft = create(:cfp, cfp_type: 'tracks', program: conference.program) + call_for_tracks = create(:cfp, cfp_type: 'tracks', program: conference.program) visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq root_path @@ -83,7 +83,7 @@ feature 'Has correct abilities' do expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) # Only booth exists - cft.destroy! + call_for_tracks.destroy! visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq(new_admin_conference_program_cfp_path(conference.short_title)) @@ -96,19 +96,19 @@ feature 'Has correct abilities' do expect(current_path).to eq(new_admin_conference_program_cfp_path(conference.short_title)) # Only Tracks cfp exists - cft = create(:cfp, cfp_type: 'tracks', program: conference.program) + call_for_tracks = create(:cfp, cfp_type: 'tracks', program: conference.program) visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) - visit edit_admin_conference_program_cfp_path(conference.short_title, cft) - expect(current_path).to eq edit_admin_conference_program_cfp_path(conference.short_title, cft) + visit edit_admin_conference_program_cfp_path(conference.short_title, call_for_tracks) + expect(current_path).to eq edit_admin_conference_program_cfp_path(conference.short_title, call_for_tracks) # Event and track cfps exist create(:cfp, cfp_type: 'events', program: conference.program) visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) - cft.destroy! + call_for_tracks.destroy! create(:event, program: conference.program) visit edit_admin_conference_program_event_path(conference.short_title, conference.program.events.first) expect(current_path).to eq(edit_admin_conference_program_event_path(conference.short_title, conference.program.events.first)) diff --git a/spec/features/organization_admin_ability_spec.rb b/spec/features/organization_admin_ability_spec.rb index 12fd038b..8bccd2cf 100644 --- a/spec/features/organization_admin_ability_spec.rb +++ b/spec/features/organization_admin_ability_spec.rb @@ -115,7 +115,7 @@ feature 'Has correct abilities' do expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp)) # Event, booth, track cfps exist - cft = create(:cfp, cfp_type: 'tracks', program: conference.program) + call_for_tracks = create(:cfp, cfp_type: 'tracks', program: conference.program) visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq root_path @@ -125,7 +125,7 @@ feature 'Has correct abilities' do expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) # Only booth exists - cft.destroy! + call_for_tracks.destroy! visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq(new_admin_conference_program_cfp_path(conference.short_title)) @@ -138,19 +138,19 @@ feature 'Has correct abilities' do expect(current_path).to eq(new_admin_conference_program_cfp_path(conference.short_title)) # Only Tracks cfp exists - cft = create(:cfp, cfp_type: 'tracks', program: conference.program) + call_for_tracks = create(:cfp, cfp_type: 'tracks', program: conference.program) visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) - visit edit_admin_conference_program_cfp_path(conference.short_title, cft) - expect(current_path).to eq edit_admin_conference_program_cfp_path(conference.short_title, cft) + visit edit_admin_conference_program_cfp_path(conference.short_title, call_for_tracks) + expect(current_path).to eq edit_admin_conference_program_cfp_path(conference.short_title, call_for_tracks) # Event and track cfps exist create(:cfp, cfp_type: 'events', program: conference.program) visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) - cft.destroy! + call_for_tracks.destroy! visit admin_conference_program_events_path(conference.short_title) expect(current_path).to eq(admin_conference_program_events_path(conference.short_title)) diff --git a/spec/features/organizer_ability_spec.rb b/spec/features/organizer_ability_spec.rb index ef2b3744..5345b58c 100644 --- a/spec/features/organizer_ability_spec.rb +++ b/spec/features/organizer_ability_spec.rb @@ -121,7 +121,7 @@ feature 'Has correct abilities' do expect(current_path).to eq(edit_admin_conference_program_cfp_path(conference.short_title, conference.program.cfp)) # Event, booth, track cfps exist - cft = create(:cfp, cfp_type: 'tracks', program: conference.program) + call_for_tracks = create(:cfp, cfp_type: 'tracks', program: conference.program) visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq root_path @@ -131,7 +131,7 @@ feature 'Has correct abilities' do expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) # Only booth exists - cft.destroy! + call_for_tracks.destroy! visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq(new_admin_conference_program_cfp_path(conference.short_title)) @@ -144,19 +144,19 @@ feature 'Has correct abilities' do expect(current_path).to eq(new_admin_conference_program_cfp_path(conference.short_title)) # Only Tracks cfp exists - cft = create(:cfp, cfp_type: 'tracks', program: conference.program) + call_for_tracks = create(:cfp, cfp_type: 'tracks', program: conference.program) visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) - visit edit_admin_conference_program_cfp_path(conference.short_title, cft) - expect(current_path).to eq edit_admin_conference_program_cfp_path(conference.short_title, cft) + visit edit_admin_conference_program_cfp_path(conference.short_title, call_for_tracks) + expect(current_path).to eq edit_admin_conference_program_cfp_path(conference.short_title, call_for_tracks) # Event and track cfps exist create(:cfp, cfp_type: 'events', program: conference.program) visit new_admin_conference_program_cfp_path(conference.short_title) expect(current_path).to eq new_admin_conference_program_cfp_path(conference.short_title) - cft.destroy! + call_for_tracks.destroy! visit admin_conference_program_events_path(conference.short_title) expect(current_path).to eq(admin_conference_program_events_path(conference.short_title)) diff --git a/spec/models/cfp_spec.rb b/spec/models/cfp_spec.rb index 606f5f9f..95607491 100644 --- a/spec/models/cfp_spec.rb +++ b/spec/models/cfp_spec.rb @@ -5,21 +5,35 @@ describe Cfp do let!(:conference) { create(:conference, end_date: Date.today) } let!(:cfp) { create(:cfp, start_date: Date.today - 2, end_date: Date.today - 1, program_id: conference.program.id) } - describe 'scope' do - describe '#for_events' do - it 'returns the cfp for events' do - expect(conference.program.cfps.for_events).to be_a Cfp - expect(conference.program.cfps.for_events.cfp_type).to eq('events') - end - end - end - describe 'validations' do it { is_expected.to validate_presence_of(:cfp_type) } it { is_expected.to validate_inclusion_of(:cfp_type).in_array(Cfp::TYPES) } it { is_expected.to validate_uniqueness_of(:cfp_type).scoped_to(:program_id).case_insensitive } end + describe '.for_events' do + it 'returns the cfp for events when it exists' do + expect(conference.program.cfps.for_events).to be_a Cfp + expect(conference.program.cfps.for_events.cfp_type).to eq('events') + end + + it 'returns nil when the cfp for events doesn\'t exist' do + conference.program.cfp.destroy + expect(conference.program.cfps.for_events).to eq nil + end + end + + describe '.for_tracks' do + it 'returns the cfp for tracks when it exists' do + call_for_tracks = create(:cfp, cfp_type: 'tracks', program: conference.program, end_date: Date.today) + expect(conference.program.cfps.for_tracks).to eq call_for_tracks + end + + it 'returns nil when the cfp for tracks doesn\'t exist' do + expect(conference.program.cfps.for_tracks).to eq nil + end + end + describe '#before_end_of_conference' do describe 'fails to save cfp' do it 'when cfp end_date is after conference end_date' do From 3d250ecf753c25a9968c642a248777f88876058a Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Wed, 19 Jul 2017 18:28:57 +0300 Subject: [PATCH 39/50] UI/UX changes related to tracks Add confirmed and cfp_active scopes to Track Render markdown in track's description Make the views more similar to the proposal/events views Change the sequence of columns in admin/Tracks#index Remove the short_name column from the index views Add button "My Tracks" in the user menu Fix track count in proposals Add details of track in admin/Tracks#show Use tabs to show track details and events --- .haml-lint_todo.yml | 1 + app/controllers/admin/events_controller.rb | 6 +- app/helpers/application_helper.rb | 2 +- app/models/track.rb | 3 + app/views/admin/tracks/index.html.haml | 74 ++++------ app/views/admin/tracks/show.html.haml | 135 ++++++++++++++---- .../_schedule_splashpage.html.haml | 11 +- app/views/layouts/_user_menu.html.haml | 4 + .../proposals/_encouragement_text.html.haml | 2 +- app/views/tracks/_form.html.haml | 2 +- app/views/tracks/index.html.haml | 89 +++++++----- app/views/tracks/show.html.haml | 30 ++-- spec/features/tracks_spec.rb | 2 +- spec/models/track_spec.rb | 40 ++++++ 14 files changed, 269 insertions(+), 132 deletions(-) diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index 89d18c3f..b7a18be0 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -182,6 +182,7 @@ linters: - "app/views/tracks/show.html.haml" - "app/views/conferences/_call_for_tracks.html.haml" - "app/views/admin/tracks/_change_state_dropdown.html.haml" + - "app/views/proposals/_encouragement_text.html.haml" # Offense count: 223 InstanceVariables: diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index 125d1ef1..1aa2e4bd 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -17,7 +17,7 @@ module Admin def index @events = @program.events - @tracks = @program.tracks + @tracks = @program.tracks.confirmed.cfp_active @difficulty_levels = @program.difficulty_levels @event_types = @program.event_types @tracks_distribution_confirmed = @conference.tracks_distribution(:confirmed) @@ -43,7 +43,7 @@ module Admin end def show - @tracks = @program.tracks + @tracks = @program.tracks.confirmed.cfp_active @event_types = @program.event_types @comments = @event.root_comments @comment_count = @event.comment_threads.count @@ -58,7 +58,7 @@ module Admin def edit @event_types = @program.event_types - @tracks = Track.all + @tracks = @program.tracks.confirmed.cfp_active @comments = @event.root_comments @comment_count = @event.comment_threads.count @user = @event.submitter diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 040927c1..0c460f26 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -56,7 +56,7 @@ module ApplicationHelper end def tracks(conference) - all = conference.program.tracks.where(state: 'confirmed', cfp_active: true).pluck(:name) + all = conference.program.tracks.confirmed.cfp_active.pluck(:name) first = all[0...-1] last = all[-1] ts = '' diff --git a/app/models/track.rb b/app/models/track.rb index 3743cd79..5fb37549 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -32,6 +32,9 @@ class Track < ActiveRecord::Base before_validation :capitalize_color + scope :confirmed, -> { where(state: 'confirmed') } + scope :cfp_active, -> { where(cfp_active: true) } + state_machine initial: :pending do state :new state :to_accept diff --git a/app/views/admin/tracks/index.html.haml b/app/views/admin/tracks/index.html.haml index 0cfe0ff2..5c47fe11 100644 --- a/app/views/admin/tracks/index.html.haml +++ b/app/views/admin/tracks/index.html.haml @@ -6,39 +6,46 @@ Categorize events in your conference .row .col-md-12 - %table.table.table-hover#tracks + %table.table.table-hover.table-striped.table-bordered.datatable#tracks %thead %th Name - %th Short name %th Description - %th Submitter - %th Color - %th State - %th Included in the Cfp %th Room %th Start Date %th End Date + %th Submitter + %th Included in Cfp + %th State %th Actions %tbody - @tracks.each do |track| %tr - %td - = link_to(admin_conference_program_track_path(@conference.short_title, track)) do - = track.name - %td - = track.short_name + %td{style: "padding: 15px 0px 0px 10px;"} + = link_to admin_conference_program_track_path(@conference.short_title, track), class: 'btn' do + %span.label{style: "background-color: #{track.color}; color: #{ contrast_color(track.color) }"} + = track.name %td %p - = truncate(track.description) + = markdown(truncate(track.description)) %td - - if track.self_organized? - = link_to track.submitter.name, admin_user_path(track.submitter) - - else - N/A + = track.room.try(:name) %td - %span.label{style: "background-color: #{track.color}; color: #{ contrast_color(track.color) }"} - = track.color + = track.start_date.strftime('%A, %B %-d. %Y') if track.start_date %td + = track.end_date.strftime('%A, %B %-d. %Y') if track.end_date + %td + = link_to track.submitter.name, admin_user_path(track.submitter) if track.self_organized? + %td.text-center + = check_box_tag "#{@conference.short_title}_#{track.short_name}", track.id, track.cfp_active, + class: 'switch-checkbox', method: :patch, + url: toggle_cfp_inclusion_admin_conference_program_track_path(@conference.short_title, id: track.short_name)+"?included=", + data: { size: 'small', + on_color: 'success', + off_color: 'warning', + on_text: 'Yes', + off_text: 'No' } + + %td.text-center - if track.self_organized? .btn-group %button{ type: 'button', class: 'btn btn-link dropdown-toggle', 'data-toggle' => 'dropdown' } @@ -48,39 +55,12 @@ = render 'change_state_dropdown', track: track - else = track.state.humanize - %td - = check_box_tag "#{@conference.short_title}_#{track.short_name}", track.id, track.cfp_active, - class: 'switch-checkbox', method: :patch, - url: toggle_cfp_inclusion_admin_conference_program_track_path(@conference.short_title, id: track.short_name)+"?included=", - data: { size: 'small', - on_color: 'success', - off_color: 'warning', - on_text: 'Yes', - off_text: 'No' } - - %td - - if track.room - = link_to track.room.name, admin_conference_venue_room_path(@conference.short_title, track.room.id) - - else - N/A - %td - - if track.start_date - = track.start_date.strftime('%A, %B %-d. %Y') - - else - N/A - %td - - if track.end_date - = track.end_date.strftime('%A, %B %-d. %Y') - - else - N/A %td .btn-group{role: "group"} - if can? :edit, track - = link_to 'Edit', edit_admin_conference_program_track_path(@conference.short_title, track), - method: :get, class: 'btn btn-primary' + = link_to 'Edit', edit_admin_conference_program_track_path(@conference.short_title, track), class: 'btn btn-primary' - if can? :destroy, track - = link_to 'Delete', admin_conference_program_track_path(@conference.short_title, track), - method: :delete, class: 'btn btn-danger', + = link_to 'Delete', admin_conference_program_track_path(@conference.short_title, track), method: :delete, class: 'btn btn-danger', data: { confirm: "Do you really want to delete #{track.name}? Attention: This track will be removed from all Events that have it set" } .row .col-md-12.text-right diff --git a/app/views/admin/tracks/show.html.haml b/app/views/admin/tracks/show.html.haml index 3acb8471..5e45d3a5 100644 --- a/app/views/admin/tracks/show.html.haml +++ b/app/views/admin/tracks/show.html.haml @@ -4,27 +4,114 @@ %h1 = @track.name Track - %p.text-muted - Events in this track -.row - .col-md-12 - %table.table.table-hover.datatable - %thead - %th Title - %th Type - %th Submitter - %th State - %th Time - %tbody - - @track.events.each_with_index do |event| - %tr - %td - =link_to event.title, admin_conference_program_event_path(@conference.short_title, event) - %td - = event.event_type.title - %td - =link_to event.submitter.name, admin_user_path(event.submitter) - %td - = event.state - %td - = event.time + +.tabbable + %ul.nav.nav-tabs + %li.active + = link_to 'Details', '#details', 'data-toggle' => 'tab' + %li + = link_to 'Events', '#events', 'data-toggle' => 'tab' + + .tab-content + .tab-pane.active#details + .row + .col-md-12 + .btn-group.pull-right + - if can? :edit, @track + = link_to 'Edit', edit_admin_conference_program_track_path(@conference.short_title, @track), + method: :get, class: 'btn btn-primary' + - if can? :destroy, @track + = link_to 'Delete', admin_conference_program_track_path(@conference.short_title, @track), + method: :delete, class: 'btn btn-danger', + data: { confirm: "Do you really want to delete #{@track.name}? Attention: This track will be removed from all Events that have it set" } + .row + .col-md-12 + %table.table + %tr + %td.col-md-2 + %b Color + %td + %span.label{ style: "background-color: #{@track.color}; color: #{ contrast_color(@track.color) }" } + = @track.color + %tr + %td + %b Room + %td + = @track.room.try(:name) + %tr + %td + %b Start date + %td + = @track.start_date.strftime('%A, %B %-d. %Y') if @track.start_date + %tr + %td + %b End date + %td + = @track.end_date.strftime('%A, %B %-d. %Y') if @track.end_date + - if @track.self_organized? + %tr + %td + %b Submitter + %td + = link_to @track.submitter.name, admin_user_path(@track.submitter) + - if @track.confirmed? + %tr + %td + %b Organizers + %td + - Role.find_by(name: 'track_organizer', resource: @track).users.each do |organizer| + %div + = link_to organizer.name, admin_user_path(organizer) + %tr + %td + %b Included in the Cfp? + %td + = check_box_tag "#{@conference.short_title}_#{@track.short_name}", @track.id, @track.cfp_active, + class: 'switch-checkbox', method: :patch, + url: toggle_cfp_inclusion_admin_conference_program_track_path(@conference.short_title, id: @track.short_name)+"?included=", + data: { size: 'small', + on_color: 'success', + off_color: 'warning', + on_text: 'Yes', + off_text: 'No' } + %tr + %td + %b State + %td + - if @track.self_organized? + .btn-group + %button{ type: 'button', class: 'btn btn-link dropdown-toggle', 'data-toggle' => 'dropdown' } + = @track.state.humanize + %span.caret + %ul.dropdown-menu{ role: 'menu' } + = render 'change_state_dropdown', track: @track + - else + = @track.state.humanize + %tr + %td + %b Description + %td + = markdown(@track.description) + + .tab-pane#events + .col-md-12 + %table.table.table-hover.datatable + %thead + %th Title + %th Type + %th Submitter + %th State + %th Time + %tbody + - @track.events.each_with_index do |event| + %tr + %td + =link_to event.title, admin_conference_program_event_path(@conference.short_title, event) + %td + = event.event_type.title + %td + =link_to event.submitter.name, admin_user_path(event.submitter) + %td + = event.state + %td + = event.time diff --git a/app/views/conferences/_schedule_splashpage.html.haml b/app/views/conferences/_schedule_splashpage.html.haml index 67bd52e4..defd3e4d 100644 --- a/app/views/conferences/_schedule_splashpage.html.haml +++ b/app/views/conferences/_schedule_splashpage.html.haml @@ -10,13 +10,22 @@ - if @conference.splashpage and @conference.program.tracks.any? and @conference.splashpage.include_tracks See rock-star speakers cover the topics of - if @conference.splashpage and @conference.splashpage.include_tracks - - @conference.program.tracks.each_slice(3) do |slice| + - @conference.program.tracks.confirmed.cfp_active.each_slice(3) do |slice| .row.row-centered - slice.each do |track| .col-md-4.col-sm-4.col-centered.col-top.track %h4.text-center = track.name = markdown(track.description) + - if track.start_date + %br + From: #{track.start_date.strftime('%A, %B %-d. %Y')} + - if track.end_date + %br + To: #{track.end_date.strftime('%A, %B %-d. %Y')} + - if track.room + %br + In: #{track.room.name} - if @conference.program and @conference.program.schedule_public .row diff --git a/app/views/layouts/_user_menu.html.haml b/app/views/layouts/_user_menu.html.haml index 38a96b08..fe1e9a35 100644 --- a/app/views/layouts/_user_menu.html.haml +++ b/app/views/layouts/_user_menu.html.haml @@ -12,6 +12,10 @@ = link_to(conference_program_proposals_path(@conference.short_title)) do %span.fa.fa-comment My Submissions + %li + = link_to(conference_program_tracks_path(@conference.short_title)) do + %span.fa.fa-road + My Tracks %li - if ENV['OSEM_ICHAIN_ENABLED'] == 'true' = link_to(destroy_user_ichain_session_path, method: 'delete') do diff --git a/app/views/proposals/_encouragement_text.html.haml b/app/views/proposals/_encouragement_text.html.haml index a0f513cd..c6d574d6 100644 --- a/app/views/proposals/_encouragement_text.html.haml +++ b/app/views/proposals/_encouragement_text.html.haml @@ -4,7 +4,7 @@ = "#{event_types(@conference)}." - if @program.tracks.any? Proposals should fit in one of the - = "#{pluralize(@program.tracks.count, 'track')}:" + = "#{pluralize(@program.tracks.confirmed.cfp_active.count, 'track')}:" = "#{tracks(@conference)}." - if @program.cfp_open? The submission period has begun diff --git a/app/views/tracks/_form.html.haml b/app/views/tracks/_form.html.haml index 2a55df5a..31e9deaf 100644 --- a/app/views/tracks/_form.html.haml +++ b/app/views/tracks/_form.html.haml @@ -15,5 +15,5 @@ = f.input :color, input_html: {size: 6, type: 'color'}, required: true = f.input :start_date, as: :string, input_html: { id: 'registration-period-start-datepicker', start_date: @conference.start_date, end_date: @conference.end_date, readonly: 'readonly' } = f.input :end_date, as: :string, input_html: { id: 'registration-period-end-datepicker', readonly: 'readonly' } - = f.input :description, input_html: {rows: 2, data: { provide: 'markdown-editable' } }, required: true, hint: markdown_hint + = f.input :description, input_html: {rows: 2, data: { provide: 'markdown-editable' } }, required: true, hint: "This will be public #{markdown_hint}".html_safe = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/tracks/index.html.haml b/app/views/tracks/index.html.haml index fd1235d4..31a9fe97 100644 --- a/app/views/tracks/index.html.haml +++ b/app/views/tracks/index.html.haml @@ -6,46 +6,60 @@ %span.notranslate = @conference.title + .row + .col-md-12 + %p.text-right + = link_to '#status-help', class: 'btn btn-default', "data-toggle"=>"collapse" do + Help? + .collapse#status-help + %p + %strong + What happens next with my track request? + %p + If you submit a track request, the conference organizers will review it and either accept or reject it. + %br + If your track request is accepted, the conference organizers expect you to confirm that you will be able to hold it. + Then you will gain the Track organizer role. + %br + If your track request is rejected, you can either live with that or adapt it and resubmit it for review again. + %br + If something changes and you can't organize the track any more, you should withdraw it. + - if @tracks.any? .row .col-md-12 - %table.table.table-hover#tracks - %thead - %th Name - %th Short name - %th Description - %th Color - %th State - %th Start Date - %th End Date - %th Actions - %tbody - - @tracks.each do |track| - %tr - %td - = link_to(conference_program_track_path(@conference.short_title, track)) do - = track.name - %td - = track.short_name - %td - %p - = truncate(track.description) - %td + %table.table.table-striped#tracks + - @tracks.each do |track| + %tr + %td{style: "padding:15px 0px 0px 8px;"} + - if %w(new to_accept to_reject).include? track.state + %span{ title: 'In review', class: 'fa fa-eye' } + - elsif track.state == 'accepted' + %span{ title: 'Accepted', class: 'fa fa-check text-muted' } + - elsif track.state == 'confirmed' + %spam{ title: 'Confirmed', class: 'fa fa-check text-success' } + - elsif %w(rejected withdrawn canceled).include? track.state + %span{ title: track.state.humanize, class: 'fa fa-ban'} + %td{style: "padding: 15px 0px 0px 0px;"} + = link_to conference_program_track_path(@conference.short_title, track), class: 'btn' do %span.label{style: "background-color: #{track.color}; color: #{ contrast_color(track.color) }"} - = track.color - %td - = track.state.humanize - %td - - if track.start_date - = track.start_date.strftime('%A, %B %-d. %Y') - - else - N/A - %td - - if track.end_date - = track.end_date.strftime('%A, %B %-d. %Y') - - else - N/A - %td + = track.name + %td + = markdown(truncate(track.description)) + %td + - if track.start_date + From: + = track.start_date.strftime('%A, %B %-d. %Y') + %td + - if track.end_date + To: + = track.end_date.strftime('%A, %B %-d. %Y') + %td + - if track.room + In: + = track.room.name + %td + .pull-right - if track.transition_possible? :confirm = link_to 'Confirm', confirm_conference_program_track_path(@conference.short_title, track), method: :patch, class: 'btn btn-mini btn-success', id: "confirm_track_#{track.id}" @@ -57,8 +71,7 @@ = link_to 'Re-Submit', restart_conference_program_track_path(@conference.short_title, track), method: :patch, class: 'btn btn-mini btn-success', id: "resubmit_track_request_#{track.id}" - if can? :edit, track - = link_to 'Edit', edit_conference_program_track_path(@conference.short_title, track), - method: :get, class: 'btn btn-primary' + = link_to 'Edit', edit_conference_program_track_path(@conference.short_title, track), class: 'btn btn-default' .row .col-md-12 diff --git a/app/views/tracks/show.html.haml b/app/views/tracks/show.html.haml index c5bc27e5..db437878 100644 --- a/app/views/tracks/show.html.haml +++ b/app/views/tracks/show.html.haml @@ -2,9 +2,12 @@ .row .col-md-12 .page-header - %h1 + %h2 = @track.name Track + .btn-group.pull-right + - if can? :edit, @track + = link_to 'Edit Track request', edit_conference_program_track_path(@conference.short_title, @track), class: 'btn btn-primary' .row .col-md-8 %dl.dl-horizontal @@ -16,26 +19,23 @@ %dt State: %dd - = @track.state.humanize + - if %w(new to_accept to_reject).include? @track.state + New + - else + = @track.state.humanize %dt Start date: %dd - - if @track.start_date - = @track.start_date.strftime('%A, %B %-d. %Y') - - else - N/A + = @track.start_date.strftime('%A, %B %-d. %Y') if @track.start_date %dt End date: %dd - - if @track.end_date - = @track.end_date.strftime('%A, %B %-d. %Y') - - else - N/A + = @track.end_date.strftime('%A, %B %-d. %Y') if @track.end_date + %dt + Room: + %dd + = @track.room.try(:name) %dt Description %dd - = @track.description - .row - .col-md-12.text-right - - if can? :edit, @track - = link_to 'Edit Track request', edit_conference_program_track_path(@conference.short_title, @track), class: 'btn btn-primary' + = markdown(@track.description) diff --git a/spec/features/tracks_spec.rb b/spec/features/tracks_spec.rb index 3538a6d7..91e90ee9 100644 --- a/spec/features/tracks_spec.rb +++ b/spec/features/tracks_spec.rb @@ -39,7 +39,7 @@ feature Track do within('table#tracks') do expect(page.has_content?(track.name)).to be false expect(page.has_content?(track.description)).to be false - expect(page.assert_selector('tr', count: 1)).to be true + expect(page.has_content?('No data available in table')).to eq true end end diff --git a/spec/models/track_spec.rb b/spec/models/track_spec.rb index 4853f31d..158c6140 100644 --- a/spec/models/track_spec.rb +++ b/spec/models/track_spec.rb @@ -120,6 +120,46 @@ describe Track do end end + describe 'scope' do + describe '#confirmed' do + before :each do + @program = create(:program) + end + + context 'includes' do + it 'when track is confirmed' do + confirmed_track = create(:track, state: 'confirmed', program: @program) + expect(@program.tracks.confirmed.include?(confirmed_track)).to eq true + end + end + + context 'excludes' do + %w[new to_accept accepted to_reject rejected canceled withdrawn].each do |state| + it "when track is #{state.humanize}" do + unconfirmed_track = create(:track, state: state, program: @program) + expect(@program.tracks.confirmed.include?(unconfirmed_track)).to eq false + end + end + end + end + + describe '#cfp_active' do + before :each do + @program = create(:program) + @cfp_active_track = create(:track, cfp_active: true, program: @program) + @non_cfp_active_track = create(:track, cfp_active: false, program: @program) + end + + it 'include tracks with the cfp_active flag enabled' do + expect(@program.tracks.cfp_active.include?(@cfp_active_track)).to eq true + end + + it 'excludes tracks with the cfp_active flag disabled' do + expect(@program.tracks.cfp_active.include?(@non_cfp_active_track)).to eq false + end + end + end + describe '#self_organized?' do it 'returns true when it has a submitter' do expect(self_organized_track.submitter).to be_a User From 2ff4c6d6b25078ac76085f47091104da3dedd5af Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Wed, 26 Jul 2017 14:54:10 +0300 Subject: [PATCH 40/50] Add relevance field for track requests The requester can now provide more info about the track and himself --- app/controllers/tracks_controller.rb | 2 +- app/models/track.rb | 1 + app/views/admin/tracks/show.html.haml | 6 ++++++ app/views/tracks/_form.html.haml | 1 + app/views/tracks/show.html.haml | 4 ++++ .../20170726065629_add_relevance_to_tracks.rb | 5 +++++ db/schema.rb | 1 + spec/controllers/tracks_controller_spec.rb | 8 ++++---- spec/factories/tracks.rb | 1 + spec/models/track_spec.rb | 16 ++++++++++++++++ 10 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20170726065629_add_relevance_to_tracks.rb diff --git a/app/controllers/tracks_controller.rb b/app/controllers/tracks_controller.rb index 9305950e..6b584d22 100644 --- a/app/controllers/tracks_controller.rb +++ b/app/controllers/tracks_controller.rb @@ -53,7 +53,7 @@ class TracksController < ApplicationController private def track_params - params.require(:track).permit(:name, :description, :color, :short_name, :start_date, :end_date) + params.require(:track).permit(:name, :description, :color, :short_name, :start_date, :end_date, :relevance) end def update_state(transition, notice) diff --git a/app/models/track.rb b/app/models/track.rb index 5fb37549..2b09b654 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -27,6 +27,7 @@ class Track < ActiveRecord::Base validates :start_date, presence: true, if: :self_organized_and_accepted_or_confirmed? validates :end_date, presence: true, if: :self_organized_and_accepted_or_confirmed? validates :room, presence: true, if: :self_organized_and_accepted_or_confirmed? + validates :relevance, presence: true, if: :self_organized? validate :valid_dates validate :valid_room, if: :self_organized_and_accepted_or_confirmed? diff --git a/app/views/admin/tracks/show.html.haml b/app/views/admin/tracks/show.html.haml index 5e45d3a5..a8c13d9d 100644 --- a/app/views/admin/tracks/show.html.haml +++ b/app/views/admin/tracks/show.html.haml @@ -92,6 +92,12 @@ %b Description %td = markdown(@track.description) + - if @track.self_organized? + %tr + %td + %b Relevance + %td + = markdown(@track.relevance) .tab-pane#events .col-md-12 diff --git a/app/views/tracks/_form.html.haml b/app/views/tracks/_form.html.haml index 31e9deaf..ab693dc5 100644 --- a/app/views/tracks/_form.html.haml +++ b/app/views/tracks/_form.html.haml @@ -16,4 +16,5 @@ = f.input :start_date, as: :string, input_html: { id: 'registration-period-start-datepicker', start_date: @conference.start_date, end_date: @conference.end_date, readonly: 'readonly' } = f.input :end_date, as: :string, input_html: { id: 'registration-period-end-datepicker', readonly: 'readonly' } = f.input :description, input_html: {rows: 2, data: { provide: 'markdown-editable' } }, required: true, hint: "This will be public #{markdown_hint}".html_safe + = f.input :relevance, input_html: {rows: 5, data: { provide: 'markdown-editable' } }, required: true, hint: "Please explain here how this track relates to the conference, how you are related to it's content and why we should accept it. #{markdown_hint}".html_safe = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/tracks/show.html.haml b/app/views/tracks/show.html.haml index db437878..6014f23e 100644 --- a/app/views/tracks/show.html.haml +++ b/app/views/tracks/show.html.haml @@ -39,3 +39,7 @@ Description %dd = markdown(@track.description) + %dt + Relevance + %dd + = markdown(@track.relevance) diff --git a/db/migrate/20170726065629_add_relevance_to_tracks.rb b/db/migrate/20170726065629_add_relevance_to_tracks.rb new file mode 100644 index 00000000..215200c1 --- /dev/null +++ b/db/migrate/20170726065629_add_relevance_to_tracks.rb @@ -0,0 +1,5 @@ +class AddRelevanceToTracks < ActiveRecord::Migration + def change + add_column :tracks, :relevance, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index f8cc3ddc..9e6123a3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -525,6 +525,7 @@ ActiveRecord::Schema.define(version: 20170807092805) do t.integer "room_id" t.date "start_date" t.date "end_date" + t.text "relevance" end add_index "tracks", ["room_id"], name: "index_tracks_on_room_id" diff --git a/spec/controllers/tracks_controller_spec.rb b/spec/controllers/tracks_controller_spec.rb index 0e3a0553..a555dba8 100644 --- a/spec/controllers/tracks_controller_spec.rb +++ b/spec/controllers/tracks_controller_spec.rb @@ -60,7 +60,7 @@ describe TracksController do describe 'POST #create' do context 'saves successfuly' do before :each do - post :create, track: attributes_for(:track, short_name: 'my_track'), conference_id: conference.short_title + post :create, track: attributes_for(:track, :self_organized, short_name: 'my_track'), conference_id: conference.short_title end it 'redirects to tracks index path' do @@ -86,7 +86,7 @@ describe TracksController do context 'save fails' do before :each do allow_any_instance_of(Track).to receive(:save).and_return(false) - post :create, track: attributes_for(:track, short_name: 'my_track'), conference_id: conference.short_title + post :create, track: attributes_for(:track, :self_organized, short_name: 'my_track'), conference_id: conference.short_title end it 'assigns a new track with the correct conference' do @@ -126,7 +126,7 @@ describe TracksController do describe 'PATCH #update' do context 'updates successfully' do before :each do - patch :update, track: attributes_for(:track, color: '#FF0000'), + patch :update, track: attributes_for(:track, :self_organized, color: '#FF0000'), conference_id: conference.short_title, id: self_organized_track.short_name end @@ -152,7 +152,7 @@ describe TracksController do context 'update fails' do before :each do allow_any_instance_of(Track).to receive(:save).and_return(false) - patch :update, track: attributes_for(:track, color: '#FF0000'), + patch :update, track: attributes_for(:track, :self_organized, color: '#FF0000'), conference_id: conference.short_title, id: self_organized_track.short_name end diff --git a/spec/factories/tracks.rb b/spec/factories/tracks.rb index d61c9a1b..3c0042f2 100644 --- a/spec/factories/tracks.rb +++ b/spec/factories/tracks.rb @@ -15,6 +15,7 @@ FactoryGirl.define do start_date { Date.today } end_date { Date.today } room + relevance { Faker::Hipster.paragraph(2) } end end end diff --git a/spec/models/track_spec.rb b/spec/models/track_spec.rb index 158c6140..ed058176 100644 --- a/spec/models/track_spec.rb +++ b/spec/models/track_spec.rb @@ -48,6 +48,22 @@ describe Track do it { is_expected.to_not validate_presence_of(:room) } end + context 'when self_organized? returns true' do + before :each do + allow(subject).to receive(:self_organized?).and_return(true) + end + + it { is_expected.to validate_presence_of(:relevance) } + end + + context 'when self_organized? returns false' do + before :each do + allow(subject).to receive(:self_organized?).and_return(false) + end + + it { is_expected.to_not validate_presence_of(:relevance) } + end + describe '#valid_dates' do before :each do @conference = create(:conference, start_date: 1.day.ago, end_date: 2.days.from_now) From 5f1ed7ce85122305cec73b4fd73db6ea1afc1ba4 Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Fri, 28 Jul 2017 02:05:08 +0300 Subject: [PATCH 41/50] Handle Tracks as resource_type in User#get_roles --- app/models/user.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index f3f03ab7..793db609 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -165,7 +165,11 @@ class User < ActiveRecord::Base def get_roles result = {} roles.each do |role| - resource = Conference.find(role.resource_id).short_title + resource = if role.resource_type == 'Conference' + Conference.find(role.resource_id).short_title + elsif role.resource_type == 'Track' + Track.find(role.resource_id).name + end if result[role.name].nil? result[role.name] = [resource] else From b717018b310dea45d2e02a1f69ae9f17912b538a Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Tue, 8 Aug 2017 12:41:37 +0300 Subject: [PATCH 42/50] Track related fixes Make the message in admin/Tracks form more visible by making it bold and adding links to venue and rooms Make papertrail track changes for all the track's attributes Add validation to require presence of description for self-organized tracks Add ID column to admin/Tracks#index Make the cfp inclusion column sortable Show success/error flash messages after toggling cfp inclusion --- app/assets/javascripts/osem-datatables.js | 24 +++--- app/controllers/admin/tracks_controller.rb | 11 ++- app/models/track.rb | 3 +- app/views/admin/tracks/_form.html.haml | 9 +- app/views/admin/tracks/index.html.haml | 6 +- app/views/admin/tracks/show.html.haml | 1 + .../admin/tracks/toggle_cfp_inclusion.js.erb | 8 ++ .../admin/tracks_controller_spec.rb | 82 ++++++++++++++++--- spec/models/track_spec.rb | 2 + 9 files changed, 114 insertions(+), 32 deletions(-) create mode 100644 app/views/admin/tracks/toggle_cfp_inclusion.js.erb diff --git a/app/assets/javascripts/osem-datatables.js b/app/assets/javascripts/osem-datatables.js index f950159e..a6f85c5d 100644 --- a/app/assets/javascripts/osem-datatables.js +++ b/app/assets/javascripts/osem-datatables.js @@ -1,18 +1,14 @@ $(function () { - $(document).ready(function() { - $('.datatable').DataTable({ - // ajax: ..., - stateSave: true, - autoWidth: false, - pagingType: 'full_numbers', - "lengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]] - }); + $('.datatable').DataTable({ + // ajax: ..., + stateSave: true, + autoWidth: false, + pagingType: 'full_numbers', + "lengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]], + }); - $('#versionstable').DataTable({ - pagingType: 'full_numbers', - order: [[ 0, 'desc' ]] - }); + $('#versionstable').DataTable({ + pagingType: 'full_numbers', + order: [[ 0, 'desc' ]] }); }); - - diff --git a/app/controllers/admin/tracks_controller.rb b/app/controllers/admin/tracks_controller.rb index 3d51a677..0f3940da 100644 --- a/app/controllers/admin/tracks_controller.rb +++ b/app/controllers/admin/tracks_controller.rb @@ -4,6 +4,9 @@ module Admin load_and_authorize_resource :program, through: :conference, singleton: true load_and_authorize_resource through: :program, find_by: :short_name + # Show flash message with ajax calls + after_action :prepare_unobtrusive_flash, only: :toggle_cfp_inclusion + def index; end def show @@ -55,9 +58,13 @@ module Admin def toggle_cfp_inclusion @track.cfp_active = !@track.cfp_active if @track.save - head :ok + flash[:notice] = "Successfully changed cfp inclusion of #{@track.name} to #{@track.cfp_active}" else - head :unprocessable_entity + flash[:error] = "Failed to toggle cfp inclusion of #{@track.name} to #{@track.cfp_active}" + end + + respond_to do |format| + format.js end end diff --git a/app/models/track.rb b/app/models/track.rb index 2b09b654..c624cab8 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -9,7 +9,7 @@ class Track < ActiveRecord::Base belongs_to :room has_many :events, dependent: :nullify - has_paper_trail only: [:name, :description, :color], meta: { conference_id: :conference_id } + has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } before_create :generate_guid validates :name, presence: true @@ -28,6 +28,7 @@ class Track < ActiveRecord::Base validates :end_date, presence: true, if: :self_organized_and_accepted_or_confirmed? validates :room, presence: true, if: :self_organized_and_accepted_or_confirmed? validates :relevance, presence: true, if: :self_organized? + validates :description, presence: true, if: :self_organized? validate :valid_dates validate :valid_room, if: :self_organized_and_accepted_or_confirmed? diff --git a/app/views/admin/tracks/_form.html.haml b/app/views/admin/tracks/_form.html.haml index eb12561b..9109e4f5 100644 --- a/app/views/admin/tracks/_form.html.haml +++ b/app/views/admin/tracks/_form.html.haml @@ -14,10 +14,15 @@ = f.input :color, input_html: {size: 6, type: 'color'}, required: true = f.input :start_date, as: :string, input_html: { id: 'registration-period-start-datepicker', start_date: @conference.start_date, end_date: @conference.end_date, readonly: 'readonly', required: @track.self_organized_and_accepted_or_confirmed? } = f.input :end_date, as: :string, input_html: { id: 'registration-period-end-datepicker', readonly: 'readonly', required: @track.self_organized_and_accepted_or_confirmed? } - - if @conference.venue + - if @conference.venue.try(:rooms) = f.input :room, as: :select, collection: (@conference.venue.rooms).map {|room| ["#{room.name}", room.id]}, include_blank: true, label: 'Room', input_html: { class: 'select-help-toggle', required: @track.self_organized_and_accepted_or_confirmed? } - else - Please add a venue with rooms, if you want to select a room for the track. + %b + Please add a + = link_to 'venue', admin_conference_venue_path(@conference.short_title) + with + = link_to 'rooms', admin_conference_venue_rooms_path(@conference.short_title) + , if you want to select a room for the track. = f.input :description, input_html: {rows: 2, data: { provide: 'markdown-editable' } }, hint: markdown_hint = f.input :cfp_active, label: 'Allow event submitters to select this track for their proposal' = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/tracks/index.html.haml b/app/views/admin/tracks/index.html.haml index 5c47fe11..77a7cf02 100644 --- a/app/views/admin/tracks/index.html.haml +++ b/app/views/admin/tracks/index.html.haml @@ -1,3 +1,4 @@ +.unobtrusive-flash-container .row .col-md-12 .page-header @@ -8,6 +9,7 @@ .col-md-12 %table.table.table-hover.table-striped.table-bordered.datatable#tracks %thead + %th ID %th Name %th Description %th Room @@ -20,6 +22,8 @@ %tbody - @tracks.each do |track| %tr + %td + = track.id %td{style: "padding: 15px 0px 0px 10px;"} = link_to admin_conference_program_track_path(@conference.short_title, track), class: 'btn' do %span.label{style: "background-color: #{track.color}; color: #{ contrast_color(track.color) }"} @@ -35,7 +39,7 @@ = track.end_date.strftime('%A, %B %-d. %Y') if track.end_date %td = link_to track.submitter.name, admin_user_path(track.submitter) if track.self_organized? - %td.text-center + %td.text-center{ 'id' => "cfp_switch_#{track.id}", 'data-order' => track.cfp_active.to_s } = check_box_tag "#{@conference.short_title}_#{track.short_name}", track.id, track.cfp_active, class: 'switch-checkbox', method: :patch, url: toggle_cfp_inclusion_admin_conference_program_track_path(@conference.short_title, id: track.short_name)+"?included=", diff --git a/app/views/admin/tracks/show.html.haml b/app/views/admin/tracks/show.html.haml index a8c13d9d..78f8830e 100644 --- a/app/views/admin/tracks/show.html.haml +++ b/app/views/admin/tracks/show.html.haml @@ -1,3 +1,4 @@ +.unobtrusive-flash-container .row .col-md-12 .page-header diff --git a/app/views/admin/tracks/toggle_cfp_inclusion.js.erb b/app/views/admin/tracks/toggle_cfp_inclusion.js.erb new file mode 100644 index 00000000..6ee83003 --- /dev/null +++ b/app/views/admin/tracks/toggle_cfp_inclusion.js.erb @@ -0,0 +1,8 @@ +$('.alert').remove(); + +track_id = <%= @track.id %>; +track_cfp_td = $('#cfp_switch_' + track_id); +track_cfp_value = <%= @track.cfp_active %>; + +track_cfp_td.attr('data-order', track_cfp_value); +$('#tracks').DataTable().cell(track_cfp_td).invalidate(); diff --git a/spec/controllers/admin/tracks_controller_spec.rb b/spec/controllers/admin/tracks_controller_spec.rb index 70ca48a1..795906aa 100644 --- a/spec/controllers/admin/tracks_controller_spec.rb +++ b/spec/controllers/admin/tracks_controller_spec.rb @@ -228,16 +228,45 @@ describe Admin::TracksController do before :each do self_organized_track.cfp_active = false self_organized_track.save! - patch :toggle_cfp_inclusion, conference_id: conference.short_title, id: self_organized_track.short_name - self_organized_track.reload end - it 'assigns the correct track' do - expect(assigns(:track)).to eq self_organized_track + context 'toggles successfully' do + before :each do + patch :toggle_cfp_inclusion, conference_id: conference.short_title, id: self_organized_track.short_name, format: :js + self_organized_track.reload + end + + it 'assigns the correct track' do + expect(assigns(:track)).to eq self_organized_track + end + + it 'shows success message in flash notice' do + expect(flash[:notice]).to match('Successfully changed cfp inclusion of My awesome track to true') + end + + it 'becomes true' do + expect(self_organized_track.cfp_active).to eq true + end end - it 'becomes true' do - expect(self_organized_track.cfp_active).to eq true + context 'save fails' do + before :each do + allow_any_instance_of(Track).to receive(:save).and_return(false) + patch :toggle_cfp_inclusion, conference_id: conference.short_title, id: self_organized_track.short_name, format: :js + self_organized_track.reload + end + + it 'assigns the correct track' do + expect(assigns(:track)).to eq self_organized_track + end + + it 'shows error message in flash notice' do + expect(flash[:error]).to match('Failed to toggle cfp inclusion of My awesome track to true') + end + + it 'stays false' do + expect(self_organized_track.cfp_active).to eq false + end end end @@ -245,16 +274,45 @@ describe Admin::TracksController do before :each do self_organized_track.cfp_active = true self_organized_track.save! - patch :toggle_cfp_inclusion, conference_id: conference.short_title, id: self_organized_track.short_name - self_organized_track.reload end - it 'assigns the correct track' do - expect(assigns(:track)).to eq self_organized_track + context 'toggles successfully' do + before :each do + patch :toggle_cfp_inclusion, conference_id: conference.short_title, id: self_organized_track.short_name, format: :js + self_organized_track.reload + end + + it 'assigns the correct track' do + expect(assigns(:track)).to eq self_organized_track + end + + it 'shows success message in flash notice' do + expect(flash[:notice]).to match('Successfully changed cfp inclusion of My awesome track to false') + end + + it 'becomes false' do + expect(self_organized_track.cfp_active).to eq false + end end - it 'becomes false' do - expect(self_organized_track.cfp_active).to eq false + context 'save fails' do + before :each do + allow_any_instance_of(Track).to receive(:save).and_return(false) + patch :toggle_cfp_inclusion, conference_id: conference.short_title, id: self_organized_track.short_name, format: :js + self_organized_track.reload + end + + it 'assigns the correct track' do + expect(assigns(:track)).to eq self_organized_track + end + + it 'shows error message in flash notice' do + expect(flash[:error]).to match('Failed to toggle cfp inclusion of My awesome track to false') + end + + it 'stays true' do + expect(self_organized_track.cfp_active).to eq true + end end end end diff --git a/spec/models/track_spec.rb b/spec/models/track_spec.rb index ed058176..1ad54839 100644 --- a/spec/models/track_spec.rb +++ b/spec/models/track_spec.rb @@ -54,6 +54,7 @@ describe Track do end it { is_expected.to validate_presence_of(:relevance) } + it { is_expected.to validate_presence_of(:description) } end context 'when self_organized? returns false' do @@ -62,6 +63,7 @@ describe Track do end it { is_expected.to_not validate_presence_of(:relevance) } + it { is_expected.to_not validate_presence_of(:description) } end describe '#valid_dates' do From b4be83e3a65497354044898e3548c093f6809b58 Mon Sep 17 00:00:00 2001 From: divyanshumehta Date: Wed, 9 Aug 2017 13:26:38 +0530 Subject: [PATCH 43/50] Removed delete action from abiltiy.rb and other places There was no delete action defined for proposals, but it was there in ability.rb So the ability was deleted. Fixes #1608 --- app/models/ability.rb | 2 +- app/models/admin_ability.rb | 2 +- spec/models/ability_spec.rb | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 63ec68dc..6713127c 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -87,7 +87,7 @@ class Ability event.program.cfp_open? && event.new_record? end - can [:update, :show, :delete, :index], Event do |event| + can [:update, :show, :index], Event do |event| event.users.include?(user) end diff --git a/app/models/admin_ability.rb b/app/models/admin_ability.rb index b0c9d4c9..46038d5f 100644 --- a/app/models/admin_ability.rb +++ b/app/models/admin_ability.rb @@ -39,7 +39,7 @@ class AdminAbility event.program.cfp_open? && event.new_record? end - can [:update, :show, :delete, :index], Event do |event| + can [:update, :show, :index], Event do |event| event.users.include?(user) end diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index ff3f14cb..7936ddbb 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -106,7 +106,6 @@ describe 'User' do it{ should be_able_to(:update, user_event_with_cfp) } it{ should be_able_to(:show, user_event_with_cfp) } - it{ should be_able_to(:delete, user_event_with_cfp) } it{ should_not be_able_to(:new, Event.new(program: program_without_cfp)) } it{ should_not be_able_to(:create, Event.new(program: program_without_cfp)) } # TODO: At moment it's not possible to manually add someone else as event_user From 5f9c0065c68174b110f84531cb8fedf0bd27a74b Mon Sep 17 00:00:00 2001 From: damien clochard Date: Sat, 12 Aug 2017 10:45:12 +0200 Subject: [PATCH 44/50] FIX : links --- TRANSLATION.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TRANSLATION.md b/TRANSLATION.md index 5014159f..3923584c 100644 --- a/TRANSLATION.md +++ b/TRANSLATION.md @@ -1,5 +1,5 @@ # Translation -We are using [Transifex] (https://www.transifex.com/opensuse-community/osem/) to manage our translations. +We are using [Transifex](https://www.transifex.com/opensuse-community/osem/) to manage our translations. We are also using the _Live_ feature of Transifex. That means that all strings from OSEM instances are automatically collected and are available for translating. >Automated collection only works if you use the API key (See at the end of this file) @@ -7,7 +7,7 @@ We are also using the _Live_ feature of Transifex. That means that all strings f ## 1. Translate * Start translating: - 1. Navigate to the [project's page] (https://www.transifex.com/opensuse-community/osem) + 1. Navigate to the [project's page](https://www.transifex.com/opensuse-community/osem) 2. Click **translation** button 3. Select **language** 4. Select **resource** (events.opensuse.org) @@ -27,7 +27,7 @@ Eg. Assuming you have signed up yourself as a translator for OSEM, to translate * How to request to publish translated strings - After you make sure that you have properly reviewed the newly translated strings (they need to be marked as **reviewed** otherwise they won't go live), you can open a [new issue] (https://github.com/openSUSE/osem/issues/new) with the following information: + After you make sure that you have properly reviewed the newly translated strings (they need to be marked as **reviewed** otherwise they won't go live), you can open a [new issue](https://github.com/openSUSE/osem/issues/new) with the following information: Title: [Transifex] Publish translation for EN From 7107f9a35f12838bf9d1279c4ac54c9a167d5cbd Mon Sep 17 00:00:00 2001 From: nasia Date: Wed, 2 Aug 2017 20:10:47 +0300 Subject: [PATCH 45/50] Add emails for booth's acceptance and rejection --- .haml-lint_todo.yml | 2 ++ .rubocop_todo.yml | 1 + app/controllers/admin/booths_controller.rb | 24 +++++++++++++++++-- app/controllers/admin/emails_controller.rb | 4 +++- app/mailers/mailbot.rb | 18 ++++++++++++++ app/models/email_settings.rb | 11 ++++++++- .../booths/_change_state_dropdown.html.haml | 18 ++++++++++---- app/views/admin/emails/_help.html.haml | 8 ++++++- app/views/admin/emails/index.html.haml | 22 +++++++++++++++++ ...0731161207_add_booths_to_email_settings.rb | 10 ++++++++ db/schema.rb | 6 +++++ 11 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20170731161207_add_booths_to_email_settings.rb diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index b7a18be0..4ec5de3c 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -303,6 +303,7 @@ linters: SpaceInsideHashAttributes: exclude: - "app/views/admin/conferences/_todo_list.html.haml" + - "app/views/admin/emails/index.html.haml" - "app/views/admin/questions/_form.html.haml" - "app/views/admin/questions/index.html.haml" - "app/views/admin/registrations/index.html.haml" @@ -403,6 +404,7 @@ linters: # Offense count: 14 ConsecutiveSilentScripts: exclude: + - "app/views/admin/booths/_change_state_dropdown.html.haml" - "app/views/admin/events/index.html.haml" - "app/views/admin/schedules/_day_tab.html.haml" - "app/views/admin/schedules/_event.html.haml" diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 487a9fdb..38bf269f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -450,6 +450,7 @@ Style/IfUnlessModifier: - 'app/helpers/application_helper.rb' - 'app/models/commercial.rb' - 'app/models/conference.rb' + - 'app/models/email_settings.rb' - 'app/models/ticket_purchase.rb' - 'app/models/user.rb' - 'db/migrate/20151031092713_change_conference_id_to_venue_id_in_rooms.rb' diff --git a/app/controllers/admin/booths_controller.rb b/app/controllers/admin/booths_controller.rb index e5b55552..a200e42e 100644 --- a/app/controllers/admin/booths_controller.rb +++ b/app/controllers/admin/booths_controller.rb @@ -47,7 +47,18 @@ module Admin end def accept - update_state(:accept, 'Booth accepted!') + @booth.accept! + + if @booth.save + if @conference.email_settings.send_on_booths_acceptance + Mailbot.conference_booths_acceptance_mail(@booth).deliver + end + redirect_to admin_conference_booths_path(conference_id: @conference.short_title), + notice: 'Booth successfully accepted!' + else + redirect_to admin_conference_booths_path(conference_id: @conference.short_title) + flash[:error] = "Booth could not be accepted. #{@booth.errors.full_messages.to_sentence}." + end end def to_accept @@ -59,7 +70,16 @@ module Admin end def reject - update_state(:reject, 'Booth rejected') + @booth.reject! + + if @booth.save + Mailbot.conference_booths_rejection_mail(@booth).deliver + redirect_to admin_conference_booths_path(conference_id: @conference.short_title), + notice: 'Booth successfully rejected.' + else + redirect_to admin_conference_booths_path(conference_id: @conference.short_title) + flash[:error] = "Booth could not be rejected. #{@booth.errors.full_messages.to_sentence}." + end end def restart diff --git a/app/controllers/admin/emails_controller.rb b/app/controllers/admin/emails_controller.rb index adff714a..a4d6fe04 100644 --- a/app/controllers/admin/emails_controller.rb +++ b/app/controllers/admin/emails_controller.rb @@ -30,7 +30,9 @@ module Admin :send_on_conference_registration_dates_updated, :conference_registration_dates_updated_subject, :conference_registration_dates_updated_body, :send_on_venue_updated, :venue_updated_subject, :venue_updated_body, :send_on_cfp_dates_updated, :cfp_dates_updated_subject, :cfp_dates_updated_body, - :send_on_program_schedule_public, :program_schedule_public_subject, :program_schedule_public_body) + :send_on_program_schedule_public, :program_schedule_public_subject, :program_schedule_public_body, + :send_on_booths_acceptance, :booths_acceptance_subject, :booths_acceptance_body, + :send_on_booths_rejection, :booths_rejection_subject, :booths_rejection_body) end end end diff --git a/app/mailers/mailbot.rb b/app/mailers/mailbot.rb index 837e2c1e..63f95a40 100644 --- a/app/mailers/mailbot.rb +++ b/app/mailers/mailbot.rb @@ -97,6 +97,24 @@ class Mailbot < ActionMailer::Base conference.email_settings.cfp_dates_updated_body)) end + def conference_booths_acceptance_mail(booth) + conference = booth.conference + + mail(to: booth.submitter.email, + from: conference.contact.email, + subject: conference.email_settings.booths_acceptance_subject, + body: conference.email_settings.generate_booth_mail(booth, conference.email_settings.booths_acceptance_body)) + end + + def conference_booths_rejection_mail(booth) + conference = booth.conference + + mail(to: booth.submitter.email, + from: conference.contact.email, + subject: conference.email_settings.booths_rejection_subject, + body: conference.email_settings.generate_booth_mail(booth, conference.email_settings.booths_rejection_body)) + end + def event_comment_mail(comment, user) @comment = comment @event = @comment.commentable diff --git a/app/models/email_settings.rb b/app/models/email_settings.rb index 6d6c4478..6210cf9d 100644 --- a/app/models/email_settings.rb +++ b/app/models/email_settings.rb @@ -3,7 +3,7 @@ class EmailSettings < ActiveRecord::Base has_paper_trail on: [:update], ignore: [:updated_at], meta: { conference_id: :conference_id } - def get_values(conference, user, event = nil) + def get_values(conference, user, event = nil, booth = nil) h = { 'email' => user.email, 'name' => user.name, @@ -45,6 +45,10 @@ class EmailSettings < ActiveRecord::Base h['proposalslink'] = Rails.application.routes.url_helpers.conference_program_proposals_url( conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')) end + + if booth + h['booth_title'] = booth.title + end h end @@ -58,6 +62,11 @@ class EmailSettings < ActiveRecord::Base parse_template(conf_update_template, values) end + def generate_booth_mail(booth, booth_template) + values = get_values(booth.conference, booth.submitter, nil, booth) + parse_template(booth_template, values) + end + private def parse_template(text, values) diff --git a/app/views/admin/booths/_change_state_dropdown.html.haml b/app/views/admin/booths/_change_state_dropdown.html.haml index c0418d67..8178a790 100644 --- a/app/views/admin/booths/_change_state_dropdown.html.haml +++ b/app/views/admin/booths/_change_state_dropdown.html.haml @@ -1,17 +1,25 @@ - if booth.transition_possible? :accept - %li= link_to 'Accept booth', + - if @conference.email_settings.send_on_booths_acceptance + - link = 'Accept with email' + - else + - link = 'Accept booth' + %li= link_to link, accept_admin_conference_booth_path(@conference.short_title, booth), - method: :patch, id: "accept_booth_#{booth.id}" + method: :patch ,id: "accept_booth_#{booth.id}" - if booth.transition_possible? :reject - %li= link_to 'Reject booth', + - if @conference.email_settings.send_on_booths_rejection + - link = 'Reject with email' + - else + - link = 'Reject' + %li= link_to link, reject_admin_conference_booth_path(@conference.short_title, booth), - method: :patch, confirm: 'Are you sure?', id: "reject_booth_#{booth.id}" + method: :patch, id: "reject_booth_#{booth.id}" - if booth.transition_possible? :to_reject %li= link_to 'To reject booth', to_reject_admin_conference_booth_path(@conference.short_title, booth), - method: :patch, confirm: 'Are you sure?', id: "to_reject_booth_#{booth.id}" + method: :patch, id: "to_reject_booth_#{booth.id}" - if booth.transition_possible? :restart %li= link_to 'Start review', diff --git a/app/views/admin/emails/_help.html.haml b/app/views/admin/emails/_help.html.haml index 535cd097..371bac7b 100644 --- a/app/views/admin/emails/_help.html.haml +++ b/app/views/admin/emails/_help.html.haml @@ -55,4 +55,10 @@ %tr %td {conference_splash_link} %td The link to conference splash page - + - if @conference.booths + %tr + %td {submitter_name} + %td Submitter's name + %tr + %td {booth_title} + %td Booth's title diff --git a/app/views/admin/emails/index.html.haml b/app/views/admin/emails/index.html.haml index 4b380b86..99d02130 100644 --- a/app/views/admin/emails/index.html.haml +++ b/app/views/admin/emails/index.html.haml @@ -14,6 +14,8 @@ %a{ 'aria-controls' => 'notifications', 'data-toggle' => 'tab', href: '#notifications', role: 'tab' } Update Notifications %li{ role: 'presentation' } %a{ 'aria-controls' => 'cfp', 'data-toggle' => 'tab', href: '#cfp', role: 'tab' } Call for Papers + %li{ role: 'presentation' } + %a{ 'aria-controls' => 'booths', 'data-toggle' => 'tab', href: '#booth', role: 'tab' } Booth / Tab panes .tab-content #onboarding.tab-pane.active{ role: 'tabpanel' } @@ -100,6 +102,26 @@ 'data-body-text' => "Dear {name},\n\nThe Conference Call for Papers Details of {conference} has changed.\nNew Dates : {cfp_start_date} - {cfp_end_date}.\n Link to Schedule {schedule_link} \n\nBest wishes\n\n{conference} Team" } Load Template %a.btn.btn-link.control_label.template_help_link{ 'data-name' => 'updated_cfp_help' } Show Help = render partial: 'help', locals: {id: 'updated_cfp_help', show_event_variables: false} + #booth.tab-pane{ role: 'tabpanel' } + = f.input :send_on_booths_acceptance + = f.input :booths_acceptance_subject + = f.input :booths_acceptance_body, input_html: { rows:10, cols: 20 } + %a.btn.btn-link.control_label.load_template{ 'data-subject-input-id' => 'email_settings_booths_acceptance_subject', + 'data-subject-text' => 'Your booth has been accepted!', + 'data-body-input-id' => 'email_settings_booths_acceptance_body', + 'data-body-text' => "Dear {name},\n\nWe are really pleased to inform you that your booth request {booth_title} has been accepted for the conference {conference}.\nPlease click the confirm button to let us know you can make it as soon as possible!\n\nFeel free to contact us with any questions or concerns.\n\nWe look forward to seeing you there.\n\nBest wishes\n\n{conference} Team"} Load Template + %a.btn.btn-link.control_label.template_help_link{ 'data-name' => 'booth_acceptance_help' } Show help + = render partial: 'help', locals: {id: 'booth_acceptance_help', show_event_variables: false} + = f.input :send_on_booths_rejection + = f.input :booths_rejection_subject + = f.input :booths_rejection_body, input_html: { rows:10, cols:20 } + %a.btn.btn-link.control_label.load_template{ 'data-subject-input-id' => 'email_settings_booths_rejection_subject', + 'data-subject-text' => 'Your booth request has been rejected', + 'data-body-input-id' => 'email_settings_booths_rejection_body', + 'data-body-text' => "Dear {name},\n\nThank you for your booth request {booth_title} for the conference {conference}.\n\nUnfortunately, we are sorry to inform you that your request has been rejected.\n\n\nBest wishes\n\n{conference} Team" } Load Template + %a.btn.btn-link.control_label.template_help_link{ 'data-name' => 'booth_rejection_help' } Show help + = render partial: 'help', locals: {id: 'booth_rejection_help', show_event_variables: false} + .row .col-md-12 = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/db/migrate/20170731161207_add_booths_to_email_settings.rb b/db/migrate/20170731161207_add_booths_to_email_settings.rb new file mode 100644 index 00000000..0b3a7a87 --- /dev/null +++ b/db/migrate/20170731161207_add_booths_to_email_settings.rb @@ -0,0 +1,10 @@ +class AddBoothsToEmailSettings < ActiveRecord::Migration + def change + add_column :email_settings, :send_on_booths_acceptance, :boolean, default: false + add_column :email_settings, :booths_acceptance_subject, :string + add_column :email_settings, :booths_acceptance_body, :text + add_column :email_settings, :send_on_booths_rejection, :boolean, default: false + add_column :email_settings, :booths_rejection_subject, :string + add_column :email_settings, :booths_rejection_body, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 9e6123a3..6cc32e82 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -205,6 +205,12 @@ ActiveRecord::Schema.define(version: 20170807092805) do t.string "cfp_dates_updated_subject" t.text "program_schedule_public_body" t.text "cfp_dates_updated_body" + t.boolean "send_on_booths_acceptance", default: false + t.string "booths_acceptance_subject" + t.text "booths_acceptance_body" + t.boolean "send_on_booths_rejection", default: false + t.string "booths_rejection_subject" + t.text "booths_rejection_body" end create_table "event_schedules", force: :cascade do |t| From 1391668c0f4536f6685b0b8ee4ce655a7ac58dc4 Mon Sep 17 00:00:00 2001 From: siddhantbajaj Date: Tue, 18 Jul 2017 02:57:46 +0530 Subject: [PATCH 46/50] Add routes and controller to scan Qr code Added TicketScanning controller and routes to scan qr code on PhysicalTickets. Added test for the same --- .../admin/ticket_scannings_controller.rb | 16 +++++ app/models/admin_ability.rb | 8 +++ config/routes.rb | 1 + .../admin/ticket_scannings_controller_spec.rb | 60 +++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 app/controllers/admin/ticket_scannings_controller.rb create mode 100644 spec/controllers/admin/ticket_scannings_controller_spec.rb diff --git a/app/controllers/admin/ticket_scannings_controller.rb b/app/controllers/admin/ticket_scannings_controller.rb new file mode 100644 index 00000000..488f28a1 --- /dev/null +++ b/app/controllers/admin/ticket_scannings_controller.rb @@ -0,0 +1,16 @@ +module Admin + class TicketScanningsController < Admin::BaseController + before_action :authenticate_user! + load_resource :physical_ticket, find_by: :token + # We authorize manually in these actions + skip_authorize_resource only: [:create] + + def create + @ticket_scanning = TicketScanning.new(physical_ticket: @physical_ticket) + authorize! :create, @ticket_scanning + @ticket_scanning.save + redirect_to conferences_path, + notice: "Ticket with token #{@physical_ticket.token} successfully scanned." + end + end +end diff --git a/app/models/admin_ability.rb b/app/models/admin_ability.rb index 4244d049..256262f4 100644 --- a/app/models/admin_ability.rb +++ b/app/models/admin_ability.rb @@ -145,6 +145,10 @@ class AdminAbility can :manage, Sponsor, conference_id: conf_ids can :manage, SponsorshipLevel, conference_id: conf_ids can :manage, Ticket, conference_id: conf_ids + can :create, TicketScanning do |ticket_scanning| + conf_id = ticket_scanning.physical_ticket.ticket_purchase.conference_id + conf_ids.include? conf_id + end can :index, Comment, commentable_type: 'Event', commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids).pluck(:id)).pluck(:id) @@ -220,6 +224,10 @@ class AdminAbility can :manage, Question do |question| !(question.conferences.pluck(:id) & conf_ids_for_info_desk).empty? end + can :create, TicketScanning do |ticket_scanning| + conf_id = ticket_scanning.physical_ticket.ticket_purchase.conference_id + conf_ids_for_info_desk.include? conf_id + end # Abilities for Role (Conference resource) can [:index, :show], Role do |role| diff --git a/config/routes.rb b/config/routes.rb index 5a17d314..98211087 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,6 +26,7 @@ Osem::Application.routes.draw do patch :toggle_confirmation end end + resource :ticket_scanning, only: [:create] resources :comments, only: [:index] resources :conferences do resource :contact, except: [:index, :new, :create, :show, :destroy] diff --git a/spec/controllers/admin/ticket_scannings_controller_spec.rb b/spec/controllers/admin/ticket_scannings_controller_spec.rb new file mode 100644 index 00000000..245bd885 --- /dev/null +++ b/spec/controllers/admin/ticket_scannings_controller_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + +describe Admin::TicketScanningsController do + let(:admin) { create(:admin) } + let(:conference) { create(:conference) } + let(:user) { create(:user) } + let(:paid_ticket_purchase) { create(:ticket_purchase, conference: conference, user: user) } + let(:physical_ticket) { create(:physical_ticket, ticket_purchase: paid_ticket_purchase) } + + context 'logged in as user with no role' do + before :each do + sign_in user + end + describe 'POST #create' do + it 'does not create new ticket scanning' do + expected = expect do + post :create, physical_ticket_id: physical_ticket.token + end + expected.to_not change(TicketScanning, :count) + end + + it 'redirects to root' do + post :create, physical_ticket_id: physical_ticket.token + expect(flash[:alert]).to eq('You are not authorized to access this page.') + expect(response).to redirect_to(root_path) + end + end + end + + context 'logged in as admin' do + before :each do + sign_in admin + end + describe 'POST #create' do + context 'with valid physical_ticket' do + it 'creates new ticket scanning' do + expected = expect do + post :create, physical_ticket_id: physical_ticket.token + end + expected.to change { TicketScanning.count }.by(1) + end + + it 'redirects to index' do + post :create, physical_ticket_id: physical_ticket.token + expect(flash[:notice]).to eq("Ticket with token #{physical_ticket.token} successfully scanned.") + expect(response).to redirect_to(conferences_path) + end + end + + context 'with Invalid physical_ticket' do + it 'raises exception' do + expected = expect do + post :create, physical_ticket_id: 'XXXX' + end + expected.to raise_exception(ActiveRecord::RecordNotFound) + end + end + end + end +end From 8b5ebb3dd7e283129d78f4d67cd1982f558d2a0a Mon Sep 17 00:00:00 2001 From: nasia Date: Thu, 27 Jul 2017 11:22:14 +0300 Subject: [PATCH 47/50] Add confirmed booths to splashpage --- .haml-lint_todo.yml | 1 + .../admin/splashpages_controller.rb | 3 ++- app/models/booth.rb | 2 ++ app/views/admin/splashpages/_form.html.haml | 1 + app/views/admin/splashpages/show.html.haml | 7 ++++++ app/views/conferences/_booths.html.haml | 24 +++++++++++++++++++ .../conferences/_conference_details.html.haml | 4 ++++ app/views/conferences/show.html.haml | 4 ++++ ...81731_add_include_booths_to_splashpages.rb | 5 ++++ db/schema.rb | 1 + 10 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 app/views/conferences/_booths.html.haml create mode 100644 db/migrate/20170727081731_add_include_booths_to_splashpages.rb diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index 4ec5de3c..a456dcd2 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -118,6 +118,7 @@ linters: - "app/views/conference_registrations/_registration_info.html.haml" - "app/views/conference_registrations/_volunteer.html.haml" - "app/views/conference_registrations/show.html.haml" + - "app/views/conferences/_booths.html.haml" - "app/views/conferences/_call_for_paper.html.haml" - "app/views/conferences/_conference_details.html.haml" - "app/views/conferences/_gallery.html.haml" diff --git a/app/controllers/admin/splashpages_controller.rb b/app/controllers/admin/splashpages_controller.rb index 2745cc8b..5f04a67b 100644 --- a/app/controllers/admin/splashpages_controller.rb +++ b/app/controllers/admin/splashpages_controller.rb @@ -47,7 +47,8 @@ module Admin :include_tracks, :include_program, :include_cfp, :include_venue, :include_registrations, :include_tickets, :include_lodgings, - :include_sponsors, :include_social_media) + :include_sponsors, :include_social_media, + :include_booths) end end end diff --git a/app/models/booth.rb b/app/models/booth.rb index 853bca9e..d7cc3eb2 100644 --- a/app/models/booth.rb +++ b/app/models/booth.rb @@ -25,6 +25,8 @@ class Booth < ActiveRecord::Base :submitter_relationship, presence: true + scope :confirmed, -> { where(state: 'confirmed') } + mount_uploader :picture, PictureUploader, mount_on: :logo_link state_machine initial: :new do diff --git a/app/views/admin/splashpages/_form.html.haml b/app/views/admin/splashpages/_form.html.haml index f945b2c9..c1897745 100644 --- a/app/views/admin/splashpages/_form.html.haml +++ b/app/views/admin/splashpages/_form.html.haml @@ -14,6 +14,7 @@ = f.input :include_tickets, label: 'Display tickets', input_html: { checked: params[:action] == 'new' || @splashpage.try(:include_tickets) } = f.input :include_lodgings, label: 'Display the lodgings', input_html: { checked: params[:action] == 'new' || @splashpage.try(:include_lodgings) } = f.input :include_sponsors, label: 'Display sponsors', input_html: { checked: params[:action] == 'new' || @splashpage.try(:include_sponsors) } + = f.input :include_booths, label: 'Display confirmed booths', input_html: { checked: params[:action] == 'new' || @splashpage.try(:include_booths) } = f.input :include_social_media, label: 'Display social media', input_html: { checked: params[:action] == 'new' || @splashpage.try(:include_social_media) } = f.inputs name: 'Access' do = f.input :public, label: 'Make splash page public?' diff --git a/app/views/admin/splashpages/show.html.haml b/app/views/admin/splashpages/show.html.haml index b4e5f24c..c185b119 100644 --- a/app/views/admin/splashpages/show.html.haml +++ b/app/views/admin/splashpages/show.html.haml @@ -66,6 +66,13 @@ Yes - else No + %dt + Include Booths + %dd + - if @splashpage.include_booths + Yes + - else + No %dt Include Social Media: %dd diff --git a/app/views/conferences/_booths.html.haml b/app/views/conferences/_booths.html.haml new file mode 100644 index 00000000..b40af9b8 --- /dev/null +++ b/app/views/conferences/_booths.html.haml @@ -0,0 +1,24 @@ += content_for :splash_nav do + %li + %a.smoothscroll{ href: '#booths' } Booths + +.container + .row + .col-md-12.text-center + %h2 Booths + - @conference.booths.confirmed.each_slice(3).with_index do |slice, index_for_row| + .row.row-centered + - slice.each.with_index do |booth, index_for_column| + .col-md-4.col-sm-4.col-xs-10.col-centered.col-top + .thumbnail + - if booth.logo_link + = link_to booth.website_url, class: 'thumbnail' do + = image_tag booth.picture.large.url + .caption + %h3.text-center + = booth.title + %p.text-center.text-muted + = link_to "#show_descrition_#{index_for_row}_#{index_for_column}", "data-toggle"=>"collapse" do + learn more + .collapse{ id: "show_descrition_#{index_for_row}_#{index_for_column}" } + = markdown(booth.description) diff --git a/app/views/conferences/_conference_details.html.haml b/app/views/conferences/_conference_details.html.haml index e8ca2449..f4ec7101 100644 --- a/app/views/conferences/_conference_details.html.haml +++ b/app/views/conferences/_conference_details.html.haml @@ -38,6 +38,10 @@ = link_to "My Proposals", conference_program_proposals_path(conference.short_title), class: 'btn btn-default' - elsif can? :new, conference.program.events.new = link_to "Submit Proposal", new_conference_program_proposal_path(conference.short_title), class: 'btn btn-default' + - if current_user && current_user.booths.where(conference_id: conference.id).count > 0 + = link_to 'My Booth Requests', conference_booths_path(conference.short_title), class: 'btn btn-default' + - elsif can? :new, conference.booths.new + = link_to 'Request Booth', new_conference_booth_path(conference.short_title), class: 'btn btn-default' - if current_user.nil? || !current_user.subscribed?(conference) = link_to 'Subscribe', conference_subscriptions_path(conference.short_title), method: :post, class: 'btn btn-default' - else diff --git a/app/views/conferences/show.html.haml b/app/views/conferences/show.html.haml index edc72726..afda1516 100644 --- a/app/views/conferences/show.html.haml +++ b/app/views/conferences/show.html.haml @@ -65,6 +65,10 @@ %section#tickets = render 'tickets' + - if @conference.booths.confirmed.any? and @conference.splashpage.include_booths + %section#booths + = render 'booths' + - if @conference.sponsors.any? and @conference.splashpage.include_sponsors %section#sponsors = render 'sponsors' diff --git a/db/migrate/20170727081731_add_include_booths_to_splashpages.rb b/db/migrate/20170727081731_add_include_booths_to_splashpages.rb new file mode 100644 index 00000000..da11ea8d --- /dev/null +++ b/db/migrate/20170727081731_add_include_booths_to_splashpages.rb @@ -0,0 +1,5 @@ +class AddIncludeBoothsToSplashpages < ActiveRecord::Migration + def change + add_column :splashpages, :include_booths, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 6cc32e82..6c40c572 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -451,6 +451,7 @@ ActiveRecord::Schema.define(version: 20170807092805) do t.datetime "created_at" t.datetime "updated_at" t.boolean "include_cfp", default: false + t.boolean "include_booths" end create_table "sponsors", force: :cascade do |t| From 703813248dfef66f12b2285b6ea50a664b5f160d Mon Sep 17 00:00:00 2001 From: nasia Date: Wed, 16 Aug 2017 11:42:57 +0300 Subject: [PATCH 48/50] Request a booth only when cfp is open --- app/models/ability.rb | 4 +++- app/models/cfp.rb | 9 +++++++++ spec/controllers/booths_controller_spec.rb | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 6713127c..18f9d4c4 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -75,7 +75,9 @@ class Ability can [:new, :create], Payment, user_id: user.id can [:index, :show], PhysicalTicket, user: user - can [:new, :create], Booth + can [:new, :create], Booth do |booth| + booth.new_record? && booth.conference.program.cfps.for_booths.try(:open?) + end can [:edit, :update, :index, :show], Booth do |booth| booth.users.include?(user) diff --git a/app/models/cfp.rb b/app/models/cfp.rb index 8248cd1a..17b37809 100644 --- a/app/models/cfp.rb +++ b/app/models/cfp.rb @@ -94,6 +94,15 @@ class Cfp < ActiveRecord::Base find_by(cfp_type: 'tracks') end + ## + # Finds the cfp for booths if it exists + # + # ====Returns + # * +Cfp+ -> The cfp with type 'booths' + def self.for_booths + find_by(cfp_type: 'booths') + end + private def before_end_of_conference diff --git a/spec/controllers/booths_controller_spec.rb b/spec/controllers/booths_controller_spec.rb index 243bc6e2..56f3b9d9 100644 --- a/spec/controllers/booths_controller_spec.rb +++ b/spec/controllers/booths_controller_spec.rb @@ -8,6 +8,7 @@ describe BoothsController do context 'user is signed in with submitter role' do before :each do + create(:cfp, program: conference.program, cfp_type: 'booths') sign_in booth.submitter end From e73218b5ca009ee7a159d55b99f09db320ec6951 Mon Sep 17 00:00:00 2001 From: nasia Date: Fri, 28 Jul 2017 21:46:48 +0300 Subject: [PATCH 49/50] Add booth limit --- .haml-lint_todo.yml | 2 ++ app/controllers/admin/booths_controller.rb | 23 +++++++++++-------- .../admin/conferences_controller.rb | 2 +- app/models/booth.rb | 1 + app/models/conference.rb | 9 ++++++++ .../booths/_change_state_dropdown.html.haml | 16 +++++++------ app/views/admin/booths/index.html.haml | 22 ++++++++++++++++++ app/views/admin/conferences/edit.html.haml | 3 +++ ...28182033_add_booth_limit_to_conferences.rb | 5 ++++ db/schema.rb | 1 + 10 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 db/migrate/20170728182033_add_booth_limit_to_conferences.rb diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index a456dcd2..2e4c2995 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -11,6 +11,8 @@ linters: # Offense count: 945 LineLength: exclude: + - "app/views/admin/booths/_change_state_dropdown.html.haml" + - "app/views/admin/booths/_form.html.haml" - "app/views/admin/booths/index.html.haml" - "app/views/admin/booths/show.html.haml" - "app/views/admin/campaigns/_form.html.haml" diff --git a/app/controllers/admin/booths_controller.rb b/app/controllers/admin/booths_controller.rb index a200e42e..26bacc8f 100644 --- a/app/controllers/admin/booths_controller.rb +++ b/app/controllers/admin/booths_controller.rb @@ -47,18 +47,21 @@ module Admin end def accept - @booth.accept! - if @booth.save - if @conference.email_settings.send_on_booths_acceptance - Mailbot.conference_booths_acceptance_mail(@booth).deliver + if can? :accept, @booth + @booth.accept! + + if @booth.save + if @conference.email_settings.send_on_booths_acceptance + Mailbot.conference_booths_acceptance_mail(@booth).deliver + end + redirect_to admin_conference_booths_path(conference_id: @conference.short_title), + notice: 'Booth successfully accepted!' + else + redirect_to admin_conference_booths_path(conference_id: @conference.short_title) + flash[:error] = "Booth could not be accepted. #{@booth.errors.full_messages.to_sentence}." end - redirect_to admin_conference_booths_path(conference_id: @conference.short_title), - notice: 'Booth successfully accepted!' - else - redirect_to admin_conference_booths_path(conference_id: @conference.short_title) - flash[:error] = "Booth could not be accepted. #{@booth.errors.full_messages.to_sentence}." - end + end end def to_accept diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index 6716a253..3905012c 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -211,7 +211,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, :booth_limit) end end end diff --git a/app/models/booth.rb b/app/models/booth.rb index d7cc3eb2..4e42d839 100644 --- a/app/models/booth.rb +++ b/app/models/booth.rb @@ -25,6 +25,7 @@ class Booth < ActiveRecord::Base :submitter_relationship, presence: true + scope :accepted, -> { where(state: 'accepted') } scope :confirmed, -> { where(state: 'confirmed') } mount_uploader :picture, PictureUploader, mount_on: :logo_link diff --git a/app/models/conference.rb b/app/models/conference.rb index b528d755..729db645 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -738,6 +738,15 @@ class Conference < ActiveRecord::Base (start_hour..(end_hour - 1)).cover?(current_hour) ? current_hour - start_hour : 0 end + ## + # + # ====Returns + # * +True+ -> if accepted booths are equal to the booth limit + # * +False+ -> Accepted booths have not reached the booth limit + def maximum_accepted_booths? + booth_limit > 0 && booths.accepted.count + booths.confirmed.count >= booth_limit + end + ## # Return the current conference object to be used in RevisionCount # diff --git a/app/views/admin/booths/_change_state_dropdown.html.haml b/app/views/admin/booths/_change_state_dropdown.html.haml index 8178a790..85f8b971 100644 --- a/app/views/admin/booths/_change_state_dropdown.html.haml +++ b/app/views/admin/booths/_change_state_dropdown.html.haml @@ -1,11 +1,13 @@ - if booth.transition_possible? :accept - - if @conference.email_settings.send_on_booths_acceptance - - link = 'Accept with email' - - else - - link = 'Accept booth' - %li= link_to link, - accept_admin_conference_booth_path(@conference.short_title, booth), - method: :patch ,id: "accept_booth_#{booth.id}" + - if can? :accept, @booth + - if @conference.email_settings.send_on_booths_acceptance + - link = 'Accept with email' + - else + - link = 'Accept booth' + %li= link_to link, + accept_admin_conference_booth_path(@conference.short_title, booth), + method: :patch ,id: "accept_booth_#{booth.id}", + data: (@conference.booth_limit > 0 ? { confirm: 'You are able to accept '+ pluralize(@conference.booth_limit - @conference.booths.accepted.count, 'more booth') + " (booth limit set to #{@conference.booth_limit}). Are you sure you want to accept this one?" } : nil ) - if booth.transition_possible? :reject - if @conference.email_settings.send_on_booths_rejection diff --git a/app/views/admin/booths/index.html.haml b/app/views/admin/booths/index.html.haml index 27f505ad..a7ee53cd 100644 --- a/app/views/admin/booths/index.html.haml +++ b/app/views/admin/booths/index.html.haml @@ -9,8 +9,30 @@ = link_to 'Add Booth', new_admin_conference_booth_path(@conference.short_title), class: 'button btn btn-primary' %p.text-muted All the booth requests + + .row .col-md-12 + %h4 + - if @conference.booth_limit == 0 + %p + Set the + = link_to 'Booth limit', edit_admin_conference_path(@conference.short_title) + to make sure you are not accepting more booths than you can accommodate. + - elsif !@conference.maximum_accepted_booths? + %p + You cannot accept more than + %b + = pluralize(@conference.booth_limit, 'booth') + ( + = pluralize(@conference.booths.accepted.count + @conference.booths.confirmed.count, 'accepted booth') + so far) + - else + %p + You have reached the maximum number of accepted booths. + ( + = link_to "#{@conference.booth_limit} booths", edit_admin_conference_path(@conference.short_title) + ) .margin-booth-table %table.table.table-striped.table-bordered.table-hover.datatable %thead diff --git a/app/views/admin/conferences/edit.html.haml b/app/views/admin/conferences/edit.html.haml index 2d5df126..26ae198f 100644 --- a/app/views/admin/conferences/edit.html.haml +++ b/app/views/admin/conferences/edit.html.haml @@ -26,4 +26,7 @@ = f.input :end_hour, input_html: {size: 2, type: 'number', min: 1, max: 24} = f.inputs name: 'Registrations' do = f.input :registration_limit, as: :number, in: 0..9999, hint: 'Limit the number of registrations to the conference (0 no limit). Please note that the registration limit doesn\'t apply to speakers of confirmed events (they will still be able to register even if it has been reached). You currently have ' + pluralize(@conference.registrations.count, 'registration') + = f.inputs name: 'Booths' do + = f.input :booth_limit, as: :number, in: 0..9999, + hint: 'Booth limit is the maximum number of booths that you can accept for this conference. By setting this number (0 no limit) you can be sure that you are not going to accept more booths than the conference can accommodate. You currently have ' + pluralize(@conference.booths.accepted.count, 'accepted booth') +'.' = f.action :submit, as: :button, button_html: {class: 'btn btn-primary'} diff --git a/db/migrate/20170728182033_add_booth_limit_to_conferences.rb b/db/migrate/20170728182033_add_booth_limit_to_conferences.rb new file mode 100644 index 00000000..60643784 --- /dev/null +++ b/db/migrate/20170728182033_add_booth_limit_to_conferences.rb @@ -0,0 +1,5 @@ +class AddBoothLimitToConferences < ActiveRecord::Migration + def change + add_column :conferences, :booth_limit, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 6c40c572..83499b33 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -127,6 +127,7 @@ ActiveRecord::Schema.define(version: 20170807092805) do t.integer "end_hour", default: 20 t.integer "organization_id" t.integer "ticket_layout", default: 0 + t.integer "booth_limit", default: 0 end add_index "conferences", ["organization_id"], name: "index_conferences_on_organization_id" From 52cde784fa7c8f1ddb4cae926d744bdd8a19ddfe Mon Sep 17 00:00:00 2001 From: nasia Date: Tue, 15 Aug 2017 18:02:51 +0300 Subject: [PATCH 50/50] Add :accept booth to ability --- .rubocop_todo.yml | 3 + app/controllers/admin/booths_controller.rb | 23 +++-- app/models/admin_ability.rb | 5 ++ .../booths/_change_state_dropdown.html.haml | 11 ++- app/views/admin/booths/index.html.haml | 84 +++++++++---------- app/views/admin/emails/index.html.haml | 2 +- 6 files changed, 68 insertions(+), 60 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 38bf269f..a91f2ae9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -330,6 +330,8 @@ Metrics/LineLength: # Configuration parameters: CountComments. Metrics/MethodLength: Max: 56 + Exclude: + - 'app/models/admin_ability.rb' # Offense count: 3 # Configuration parameters: CountComments. @@ -443,6 +445,7 @@ Style/HashSyntax: # Configuration parameters: MaxLineLength. Style/IfUnlessModifier: Exclude: + - 'app/controllers/admin/booths_controller.rb' - 'app/controllers/admin/events_controller.rb' - 'app/controllers/api/v1/events_controller.rb' - 'app/controllers/conference_registrations_controller.rb' diff --git a/app/controllers/admin/booths_controller.rb b/app/controllers/admin/booths_controller.rb index 26bacc8f..a200e42e 100644 --- a/app/controllers/admin/booths_controller.rb +++ b/app/controllers/admin/booths_controller.rb @@ -47,21 +47,18 @@ module Admin end def accept + @booth.accept! - if can? :accept, @booth - @booth.accept! - - if @booth.save - if @conference.email_settings.send_on_booths_acceptance - Mailbot.conference_booths_acceptance_mail(@booth).deliver - end - redirect_to admin_conference_booths_path(conference_id: @conference.short_title), - notice: 'Booth successfully accepted!' - else - redirect_to admin_conference_booths_path(conference_id: @conference.short_title) - flash[:error] = "Booth could not be accepted. #{@booth.errors.full_messages.to_sentence}." + if @booth.save + if @conference.email_settings.send_on_booths_acceptance + Mailbot.conference_booths_acceptance_mail(@booth).deliver end - end + redirect_to admin_conference_booths_path(conference_id: @conference.short_title), + notice: 'Booth successfully accepted!' + else + redirect_to admin_conference_booths_path(conference_id: @conference.short_title) + flash[:error] = "Booth could not be accepted. #{@booth.errors.full_messages.to_sentence}." + end end def to_accept diff --git a/app/models/admin_ability.rb b/app/models/admin_ability.rb index 466380cc..f742b775 100644 --- a/app/models/admin_ability.rb +++ b/app/models/admin_ability.rb @@ -74,6 +74,11 @@ class AdminAbility cannot :destroy, Track do |track| track.self_organized? end + # Can't accept a booth when booth_limit is reached + cannot :accept, Booth do |booth| + conference = booth.conference + conference.maximum_accepted_booths? + end end # Abilities for signed in users with roles diff --git a/app/views/admin/booths/_change_state_dropdown.html.haml b/app/views/admin/booths/_change_state_dropdown.html.haml index 85f8b971..12b982df 100644 --- a/app/views/admin/booths/_change_state_dropdown.html.haml +++ b/app/views/admin/booths/_change_state_dropdown.html.haml @@ -1,13 +1,17 @@ + - if booth.transition_possible? :accept - - if can? :accept, @booth + - if can? :accept, booth + - if @conference.booth_limit > 0 + - confirm_message = ' You are able to accept '+ pluralize(@conference.booth_limit - (@conference.booths.accepted.count + @conference.booths.confirmed.count), 'more booth') + " (booth limit set to #{@conference.booth_limit}). Are you sure you want to accept this one?" - if @conference.email_settings.send_on_booths_acceptance - link = 'Accept with email' + - confirm_message = "By accepting this booth, an email will be sent informing the submitter for the acceptance. You may change the state to \'To accept\' until you are completely sure." + confirm_message - else - link = 'Accept booth' %li= link_to link, accept_admin_conference_booth_path(@conference.short_title, booth), method: :patch ,id: "accept_booth_#{booth.id}", - data: (@conference.booth_limit > 0 ? { confirm: 'You are able to accept '+ pluralize(@conference.booth_limit - @conference.booths.accepted.count, 'more booth') + " (booth limit set to #{@conference.booth_limit}). Are you sure you want to accept this one?" } : nil ) + data: (confirm_message ? { confirm: confirm_message } : nil) - if booth.transition_possible? :reject - if @conference.email_settings.send_on_booths_rejection @@ -16,7 +20,8 @@ - link = 'Reject' %li= link_to link, reject_admin_conference_booth_path(@conference.short_title, booth), - method: :patch, id: "reject_booth_#{booth.id}" + method: :patch, id: "reject_booth_#{booth.id}", + data: (@conference.email_settings.send_on_booths_rejection ? { confirm: 'By rejecting this booth, an email will be sent informing the submitter about the rejection. You may change the state to \'To reject\' until you are completely sure.'} : nil) - if booth.transition_possible? :to_reject %li= link_to 'To reject booth', diff --git a/app/views/admin/booths/index.html.haml b/app/views/admin/booths/index.html.haml index a7ee53cd..fc3f3ba3 100644 --- a/app/views/admin/booths/index.html.haml +++ b/app/views/admin/booths/index.html.haml @@ -10,7 +10,6 @@ %p.text-muted All the booth requests - .row .col-md-12 %h4 @@ -33,46 +32,45 @@ ( = link_to "#{@conference.booth_limit} booths", edit_admin_conference_path(@conference.short_title) ) - .margin-booth-table - %table.table.table-striped.table-bordered.table-hover.datatable - %thead - %th - %b ID - %th - %b Logo - %th - %b Title - %th - %b Submitter - %th - %b Responsibles - %th - %b State - %th - %b Actions - - @booths.each do |booth| - %tr + %table.table.table-striped.table-bordered.table-hover.datatable + %thead + %th + %b ID + %th + %b Logo + %th + %b Title + %th + %b Submitter + %th + %b Responsibles + %th + %b State + %th + %b Actions + - @booths.each do |booth| + %tr + %td + = booth.id + %td + - if booth.logo_link + = image_tag(booth.picture.thumb.url, width: '20%') + %td + = link_to booth.title, admin_conference_booth_path(@conference.short_title, booth) + %td + = link_to booth.submitter.name, admin_user_path(booth.submitter) if booth.submitter + %td + .responsibles + - booth.responsibles.each_with_index do |responsible, i| + = link_to responsible.name, admin_user_path(responsible) + = ", " unless i == booth.responsibles.length - 1 + %td + .btn-group + %button{ type: 'button', class: 'btn btn-link dropdown-toggle', 'data-toggle' => 'dropdown' } + = booth.state.humanize + %span.caret + %ul.dropdown-menu{ role: 'menu' } + = render 'change_state_dropdown', booth: booth %td - = booth.id - %td - - if booth.logo_link - = image_tag(booth.picture.thumb.url, width: '20%') - %td - = link_to booth.title, admin_conference_booth_path(@conference.short_title, booth) - %td - = link_to booth.submitter.name, admin_user_path(booth.submitter) if booth.submitter - %td - .responsibles - - booth.responsibles.each_with_index do |responsible, i| - = link_to responsible.name, admin_user_path(responsible) - = ", " unless i == booth.responsibles.length - 1 - %td - .btn-group - %button{ type: 'button', class: 'btn btn-link dropdown-toggle', 'data-toggle' => 'dropdown' } - = booth.state.humanize - %span.caret - %ul.dropdown-menu{ role: 'menu' } - = render 'change_state_dropdown', booth: booth - %td - = link_to 'Edit', edit_admin_conference_booth_path(@conference.short_title, booth.id), - class: 'btn btn-primary' + = link_to 'Edit', edit_admin_conference_booth_path(@conference.short_title, booth.id), + class: 'btn btn-primary' diff --git a/app/views/admin/emails/index.html.haml b/app/views/admin/emails/index.html.haml index 99d02130..83ebe210 100644 --- a/app/views/admin/emails/index.html.haml +++ b/app/views/admin/emails/index.html.haml @@ -109,7 +109,7 @@ %a.btn.btn-link.control_label.load_template{ 'data-subject-input-id' => 'email_settings_booths_acceptance_subject', 'data-subject-text' => 'Your booth has been accepted!', 'data-body-input-id' => 'email_settings_booths_acceptance_body', - 'data-body-text' => "Dear {name},\n\nWe are really pleased to inform you that your booth request {booth_title} has been accepted for the conference {conference}.\nPlease click the confirm button to let us know you can make it as soon as possible!\n\nFeel free to contact us with any questions or concerns.\n\nWe look forward to seeing you there.\n\nBest wishes\n\n{conference} Team"} Load Template + 'data-body-text' => "Dear {name},\n\nWe are pleased to inform you that your booth request {booth_title} has been accepted for the conference {conference}.\nPlease click the confirm button to let us know you can make it as soon as possible!\n\nFeel free to contact us with any questions or concerns.\n\nWe are looking forward to seeing you there.\n\nBest wishes\n\n{conference} Team"} Load Template %a.btn.btn-link.control_label.template_help_link{ 'data-name' => 'booth_acceptance_help' } Show help = render partial: 'help', locals: {id: 'booth_acceptance_help', show_event_variables: false} = f.input :send_on_booths_rejection