From a9d56cb202772eecaebb52cae7b031674be34c22 Mon Sep 17 00:00:00 2001 From: Warren Huang Date: Mon, 4 Mar 2024 17:08:59 -0800 Subject: [PATCH 01/10] Update the mass load to .csv restrict --- .../admin/commercials_controller.rb | 2 +- app/models/commercial.rb | 24 ++++++++++++++----- app/views/admin/events/index.html.haml | 8 +++---- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/commercials_controller.rb b/app/controllers/admin/commercials_controller.rb index 073e135e4..ee4e07eee 100644 --- a/app/controllers/admin/commercials_controller.rb +++ b/app/controllers/admin/commercials_controller.rb @@ -55,7 +55,7 @@ def render_commercial # Received a file from user # Reads file and creates commercial for event # File content example: - # EventID:MyURL + # EventID, Title, URL def mass_upload errors = Commercial.read_file(params[:file]) if params[:file] diff --git a/app/models/commercial.rb b/app/models/commercial.rb index d5ac9a463..5e6deb75f 100644 --- a/app/models/commercial.rb +++ b/app/models/commercial.rb @@ -46,17 +46,29 @@ def self.read_file(file) errors[:no_event] = [] errors[:validation_errors] = [] + # Check if the file has a .csv extension + unless File.extname(file.original_filename).casecmp('.csv').zero? + errors[:validation_errors] << 'File must be a CSV.' + return errors + end + file.read.each_line do |line| - # Get the event id (text before :) - id = line.match(/:/).pre_match.to_i - # Get the commercial url (text after :) - url = line.match(/:/).post_match + # Split the line by comma + elements = line.strip.split(',') + id, title, url = elements[0].to_i, elements[1], elements[2] + + # Validate presence of all parts + if elements.size != 3 + errors[:validation_errors] << "Line format is incorrect. Should be ID, Title, URL." + next + end + event = Event.find_by(id: id) - # Go to next event, if the event is not found + # Go to next event if the event is not found (errors[:no_event] << id) && next unless event - commercial = event.commercials.new(url: url) + commercial = event.commercials.new(title: title, url: url) unless commercial.save errors[:validation_errors] << ("Could not create materials for event with ID #{event.id} (" + commercial.errors.full_messages.to_sentence + ')') end diff --git a/app/views/admin/events/index.html.haml b/app/views/admin/events/index.html.haml index 46429af29..2fe477909 100644 --- a/app/views/admin/events/index.html.haml +++ b/app/views/admin/events/index.html.haml @@ -35,12 +35,12 @@ .form-group = f.file_field 'file', as: :file %span.help-block - Upload your file with data in the following format: - %b Event_ID:Commercial_Link + Upload your file.csv with data in the following format: + %b Event_ID, Title, Commercial_Link for instance: %pre - 11:https://youtube.com/myvideo - 23:https://vimeo.com/myvideo + 1, title, https://youtube.com/myvideo + 2, title, https://vimeo.com/myvideo .modal-footer = f.submit nil, class: 'btn btn-primary' .row From e3819e8bc371eb7554664cd984d2f8a1f34094dc Mon Sep 17 00:00:00 2001 From: Warren Huang Date: Sun, 10 Mar 2024 15:08:52 -0700 Subject: [PATCH 02/10] Update mass upload to use csv parser --- app/models/commercial.rb | 18 ++++++++---------- app/views/admin/events/index.html.haml | 7 ++++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/models/commercial.rb b/app/models/commercial.rb index 5e6deb75f..fd55c3589 100644 --- a/app/models/commercial.rb +++ b/app/models/commercial.rb @@ -14,6 +14,9 @@ # commercial_id :string # commercialable_id :integer # +require 'csv' + + class Commercial < ApplicationRecord require 'oembed' @@ -52,16 +55,11 @@ def self.read_file(file) return errors end - file.read.each_line do |line| - # Split the line by comma - elements = line.strip.split(',') - id, title, url = elements[0].to_i, elements[1], elements[2] - - # Validate presence of all parts - if elements.size != 3 - errors[:validation_errors] << "Line format is incorrect. Should be ID, Title, URL." - next - end + CSV.foreach(file.path, headers: true) do |row| + # You can access columns by their names if headers are included in the file + id = row['Event_ID'].to_i + title = row['Title'] + url = row['URL'] event = Event.find_by(id: id) diff --git a/app/views/admin/events/index.html.haml b/app/views/admin/events/index.html.haml index 2fe477909..93c369c79 100644 --- a/app/views/admin/events/index.html.haml +++ b/app/views/admin/events/index.html.haml @@ -36,11 +36,12 @@ = f.file_field 'file', as: :file %span.help-block Upload your file.csv with data in the following format: - %b Event_ID, Title, Commercial_Link + %b Event_ID,Title,URL for instance: %pre - 1, title, https://youtube.com/myvideo - 2, title, https://vimeo.com/myvideo + Event_ID,Title,URL + 1,title,https://youtube.com/myvideo + 2,title,https://vimeo.com/myvideo .modal-footer = f.submit nil, class: 'btn btn-primary' .row From 853899564833b2a9f95c751220a6b5d0b6d44d8d Mon Sep 17 00:00:00 2001 From: Warren Huang Date: Mon, 18 Mar 2024 18:12:32 -0700 Subject: [PATCH 03/10] Handle 4 kbyte error cap for upload materias --- .../admin/commercials_controller.rb | 30 +++++++++++++------ app/models/commercial.rb | 1 - 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/controllers/admin/commercials_controller.rb b/app/controllers/admin/commercials_controller.rb index ee4e07eee..0b7c8af3f 100644 --- a/app/controllers/admin/commercials_controller.rb +++ b/app/controllers/admin/commercials_controller.rb @@ -61,22 +61,34 @@ def mass_upload if !params[:file] flash[:error] = 'Empty file detected while adding materials to Event' - elsif errors.all? { |_k, v| v.blank? } - flash[:notice] = 'Successfully added materials.' - else - errors_text = '' - errors_text += 'Unable to find event with ID: ' + errors[:no_event].join(', ') + '. ' if errors[:no_event].any? - if errors[:validation_errors].any? - errors_text += 'There were some errors: ' + errors[:validation_errors].join('. ') - end + elsif errors.present? + errors_text = aggregate_errors(errors) + flash[:notice] = if errors_text.length > 4096 + 'Errors are too long to be displayed. Please check the logs.' + else + errors_text + end - flash[:error] = errors_text + else + flash[:notice] = 'Successfully added materials.' end redirect_back(fallback_location: root_path) end private + # Aggregate errors and ensure that they do not exceed 4 KB in total size + def aggregate_errors(errors) + errors_text = '' + if errors[:no_event].any? + errors_text += 'Unable to find events with IDs: ' + errors[:no_event].join(', ') + '. ' + end + if errors[:validation_errors].any? + errors_text += 'Validation errors: ' + errors[:validation_errors].join('. ') + end + errors_text + end + def commercial_params params.require(:commercial).permit(:title, :url) end diff --git a/app/models/commercial.rb b/app/models/commercial.rb index fd55c3589..1fcc0a45a 100644 --- a/app/models/commercial.rb +++ b/app/models/commercial.rb @@ -16,7 +16,6 @@ # require 'csv' - class Commercial < ApplicationRecord require 'oembed' From b1375b577a76e007d6580a2db208ddce06df3fe7 Mon Sep 17 00:00:00 2001 From: tiffanylamm Date: Mon, 1 Apr 2024 16:22:51 -0700 Subject: [PATCH 04/10] added enable_public_submission to event_types model need to implement in views --- .../admin/event_types_controller.rb | 2 +- app/controllers/proposals_controller.rb | 6 ++++ app/helpers/event_types_helper.rb | 2 +- app/models/event_type.rb | 29 ++++++++++++------- app/views/admin/event_types/_form.html.haml | 5 ++++ app/views/admin/event_types/index.html.haml | 5 +++- ...enable_public_submission_to_event_types.rb | 5 ++++ db/schema.rb | 3 +- spec/factories/event_types.rb | 24 ++++++++------- spec/models/event_type_spec.rb | 23 ++++++++------- 10 files changed, 67 insertions(+), 37 deletions(-) create mode 100644 db/migrate/20240318164346_add_enable_public_submission_to_event_types.rb diff --git a/app/controllers/admin/event_types_controller.rb b/app/controllers/admin/event_types_controller.rb index 0cd2eed20..f0d7656d9 100644 --- a/app/controllers/admin/event_types_controller.rb +++ b/app/controllers/admin/event_types_controller.rb @@ -50,7 +50,7 @@ def destroy def event_type_params params.require(:event_type).permit(:title, :length, :minimum_abstract_length, :maximum_abstract_length, - :submission_template, :color, :conference_id, :description) + :submission_template, :color, :conference_id, :description, :enable_public_submission) end end end diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 48d62c817..9608a1b4a 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -31,6 +31,12 @@ def new @url = conference_program_proposals_path(@conference.short_title) @languages = @program.languages_list @superevents = @program.super_events + + if current_user.is_admin? + @event_types = @program.event_types + else + @event_types = @program.event_types.available_for_public + end end def edit diff --git a/app/helpers/event_types_helper.rb b/app/helpers/event_types_helper.rb index ca7c3e511..1aa439ed8 100644 --- a/app/helpers/event_types_helper.rb +++ b/app/helpers/event_types_helper.rb @@ -15,7 +15,7 @@ def event_type_select_options(event_types = {}) { data: { min_words: type.minimum_abstract_length, max_words: type.maximum_abstract_length, - instructions: type.submission_template + template: type.submission_template } } ] end diff --git a/app/models/event_type.rb b/app/models/event_type.rb index 0d2943dc9..198016a10 100644 --- a/app/models/event_type.rb +++ b/app/models/event_type.rb @@ -4,17 +4,18 @@ # # Table name: event_types # -# id :bigint not null, primary key -# color :string -# description :string -# length :integer default(30) -# maximum_abstract_length :integer default(500) -# minimum_abstract_length :integer default(0) -# submission_template :text -# title :string not null -# created_at :datetime -# updated_at :datetime -# program_id :integer +# id :bigint not null, primary key +# color :string +# description :string +# enable_public_submission :boolean default(TRUE), not null +# length :integer default(30) +# maximum_abstract_length :integer default(500) +# minimum_abstract_length :integer default(0) +# submission_template :text +# title :string not null +# created_at :datetime +# updated_at :datetime +# program_id :integer # class EventType < ApplicationRecord belongs_to :program, touch: true @@ -34,6 +35,8 @@ class EventType < ApplicationRecord alias_attribute :name, :title + scope :available_for_public, -> { where(enable_public_submission: true) } + private ## @@ -53,4 +56,8 @@ def capitalize_color def conference_id program.conference_id end + + # def self.available_for_public_submission + # is_admin? all : available_for_public + # end end diff --git a/app/views/admin/event_types/_form.html.haml b/app/views/admin/event_types/_form.html.haml index d0a2739c1..6426a38ab 100644 --- a/app/views/admin/event_types/_form.html.haml +++ b/app/views/admin/event_types/_form.html.haml @@ -15,6 +15,11 @@ = f.label :description = f.text_area :description, class: 'form-control', rows: 5, data: { provide: 'markdown' } .help-block= markdown_hint + .form-group + = f.label "Allow public submission?", for: :enable_public_submission + = f.check_box :enable_public_submission, class: 'switch-checkbox' + .help-block + Do we need description for explanation? .form-group = f.label :minimum_abstract_length %abbr{title: 'This field is required'} * diff --git a/app/views/admin/event_types/index.html.haml b/app/views/admin/event_types/index.html.haml index 56411fb78..b4784b446 100644 --- a/app/views/admin/event_types/index.html.haml +++ b/app/views/admin/event_types/index.html.haml @@ -11,7 +11,8 @@ %tr %th Title %th Description - %th Instructions + %th Enable Public Submission + %th Template %th Length %th Abstract Length %th Color @@ -23,6 +24,8 @@ = event_type.title %td = markdown(event_type.description) + %td + = event_type.enable_public_submission ? 'Yes' : 'No' %td = markdown(event_type.submission_template) %td diff --git a/db/migrate/20240318164346_add_enable_public_submission_to_event_types.rb b/db/migrate/20240318164346_add_enable_public_submission_to_event_types.rb new file mode 100644 index 000000000..f653893c8 --- /dev/null +++ b/db/migrate/20240318164346_add_enable_public_submission_to_event_types.rb @@ -0,0 +1,5 @@ +class AddEnablePublicSubmissionToEventTypes < ActiveRecord::Migration[7.0] + def change + add_column :event_types, :enable_public_submission, :boolean, default: true, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index d8361a539..eae662993 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_02_26_175634) do +ActiveRecord::Schema[7.0].define(version: 2024_03_18_164346) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "plpgsql" @@ -234,6 +234,7 @@ t.datetime "created_at", precision: nil t.datetime "updated_at", precision: nil t.text "submission_template" + t.boolean "enable_public_submission", default: true, null: false end create_table "event_users", force: :cascade do |t| diff --git a/spec/factories/event_types.rb b/spec/factories/event_types.rb index e3801ca14..d8e3ee758 100644 --- a/spec/factories/event_types.rb +++ b/spec/factories/event_types.rb @@ -4,17 +4,18 @@ # # Table name: event_types # -# id :bigint not null, primary key -# color :string -# description :string -# length :integer default(30) -# maximum_abstract_length :integer default(500) -# minimum_abstract_length :integer default(0) -# submission_template :text -# title :string not null -# created_at :datetime -# updated_at :datetime -# program_id :integer +# id :bigint not null, primary key +# color :string +# description :string +# enable_public_submission :boolean default(TRUE), not null +# length :integer default(30) +# maximum_abstract_length :integer default(500) +# minimum_abstract_length :integer default(0) +# submission_template :text +# title :string not null +# created_at :datetime +# updated_at :datetime +# program_id :integer # FactoryBot.define do @@ -22,6 +23,7 @@ title { 'Example Event Type' } length { 30 } description { 'Example Event Description\nThis event type is an example.' } + enable_public_submission { true } minimum_abstract_length { 0 } maximum_abstract_length { 500 } submission_template { 'Example Event Template _with_ **markdown**' } diff --git a/spec/models/event_type_spec.rb b/spec/models/event_type_spec.rb index 2c30203c2..8a97d8cfe 100644 --- a/spec/models/event_type_spec.rb +++ b/spec/models/event_type_spec.rb @@ -4,17 +4,18 @@ # # Table name: event_types # -# id :bigint not null, primary key -# color :string -# description :string -# length :integer default(30) -# maximum_abstract_length :integer default(500) -# minimum_abstract_length :integer default(0) -# submission_template :text -# title :string not null -# created_at :datetime -# updated_at :datetime -# program_id :integer +# id :bigint not null, primary key +# color :string +# description :string +# enable_public_submission :boolean default(TRUE), not null +# length :integer default(30) +# maximum_abstract_length :integer default(500) +# minimum_abstract_length :integer default(0) +# submission_template :text +# title :string not null +# created_at :datetime +# updated_at :datetime +# program_id :integer # require 'spec_helper' From b3543681df4e632dbc77b548d866ad498865405e Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Thu, 4 Apr 2024 17:17:08 -0700 Subject: [PATCH 05/10] Minor tweak to example text --- app/views/admin/events/index.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/events/index.html.haml b/app/views/admin/events/index.html.haml index 93c369c79..6f68faee1 100644 --- a/app/views/admin/events/index.html.haml +++ b/app/views/admin/events/index.html.haml @@ -40,8 +40,8 @@ for instance: %pre Event_ID,Title,URL - 1,title,https://youtube.com/myvideo - 2,title,https://vimeo.com/myvideo + 1,Session Recording,https://youtube.com/myvideo + 2,Demo Video,https://vimeo.com/myvideo .modal-footer = f.submit nil, class: 'btn btn-primary' .row From 784d50fff11ea1dbb0dcc789bdf80d8ca165f89b Mon Sep 17 00:00:00 2001 From: tiffanylamm Date: Thu, 4 Apr 2024 21:20:40 -0700 Subject: [PATCH 06/10] admin vs non-admin dropdown and descriptions event types working --- app/controllers/proposals_controller.rb | 11 +++++------ app/helpers/application_helper.rb | 12 ++++++++++-- app/views/proposals/_encouragement_text.html.haml | 2 +- .../proposals/_submission_type_content_form.haml | 4 ++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 9608a1b4a..fc31e02f7 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -3,6 +3,7 @@ class ProposalsController < ApplicationController include ConferenceHelper before_action :authenticate_user!, except: %i[show new create] + before_action :set_is_admin load_resource :conference, find_by: :short_title load_resource :program, through: :conference, singleton: true load_and_authorize_resource :event, parent: false, through: :program @@ -31,12 +32,6 @@ def new @url = conference_program_proposals_path(@conference.short_title) @languages = @program.languages_list @superevents = @program.super_events - - if current_user.is_admin? - @event_types = @program.event_types - else - @event_types = @program.event_types.available_for_public - end end def edit @@ -224,4 +219,8 @@ def event_params def user_params params.require(:user).permit(:email, :password, :password_confirmation, :username) end + + def set_is_admin + @is_admin = current_user.is_admin + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6edc74c84..4e3ad1fdb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -122,8 +122,16 @@ def volunteer_links(event) end, ', ') end - def event_types_sentence(conference) - conference.event_types.map { |et| et.title.pluralize }.to_sentence + def event_types_sentence(conference, is_admin = true) + if is_admin + conference.event_types.map { |et| et.title.pluralize }.to_sentence + else + conference.event_types.available_for_public.map { |et| et.title.pluralize }.to_sentence + end + end + + def event_types_dropdown(conference, is_admin = true) + is_admin ? conference.event_types : conference.event_types.available_for_public end def sign_in_path diff --git a/app/views/proposals/_encouragement_text.html.haml b/app/views/proposals/_encouragement_text.html.haml index f7f6033f0..224f90f2a 100644 --- a/app/views/proposals/_encouragement_text.html.haml +++ b/app/views/proposals/_encouragement_text.html.haml @@ -1,7 +1,7 @@ %p.lead - if @program.event_types.any? You can submit proposals for - = "#{event_types_sentence(@conference)}." + = "#{event_types_sentence(@conference, @is_admin)}." - if @program.tracks.confirmed.cfp_active.any? Proposals should fit in one of the = "#{pluralize(@program.tracks.confirmed.cfp_active.count, 'track')}:" diff --git a/app/views/proposals/_submission_type_content_form.haml b/app/views/proposals/_submission_type_content_form.haml index 6a66fa5a1..5d9e634b1 100644 --- a/app/views/proposals/_submission_type_content_form.haml +++ b/app/views/proposals/_submission_type_content_form.haml @@ -2,8 +2,8 @@ %p Please select a submission type, then fill in the abstract and extended details. .form-group - = f.label :event_type_id, 'Type' - = f.select :event_type_id, event_type_select_options(@conference.program.event_types), { include_blank: false }, { class: 'select-help-toggle form-control' } + = f.label :event_type_id, "Type" + = f.select :event_type_id, event_type_select_options(event_types_dropdown(@conference, @is_admin)), { include_blank: false }, { class: 'select-help-toggle form-control' } - program.event_types.each do |event_type| .help-block.event_event_type_id.collapse{ id: "#{dom_id(event_type)}-help" } From a988487b1232a9194d913269242b1a0261479287 Mon Sep 17 00:00:00 2001 From: tiffanylamm Date: Fri, 12 Apr 2024 14:17:54 -0700 Subject: [PATCH 07/10] finished applying enable-public-submission plus tests --- app/controllers/proposals_controller.rb | 8 ++------ app/helpers/application_helper.rb | 4 ---- app/models/event_type.rb | 7 ++++--- app/views/admin/event_types/_form.html.haml | 2 -- .../proposals/_encouragement_text.html.haml | 2 +- .../_submission_type_content_form.haml | 5 ++++- spec/helpers/application_helper_spec.rb | 18 +++++++++++++++++ spec/models/event_type_spec.rb | 20 +++++++++++++++++++ 8 files changed, 49 insertions(+), 17 deletions(-) diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index fc31e02f7..3c63782a8 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -3,7 +3,6 @@ class ProposalsController < ApplicationController include ConferenceHelper before_action :authenticate_user!, except: %i[show new create] - before_action :set_is_admin load_resource :conference, find_by: :short_title load_resource :program, through: :conference, singleton: true load_and_authorize_resource :event, parent: false, through: :program @@ -50,6 +49,7 @@ def create authorize! :create, @user if @user.save sign_in(@user) + set_is_admin else flash.now[:error] = "Could not save user: #{@user.errors.full_messages.join(', ')}" render action: 'new' @@ -217,10 +217,6 @@ def event_params end def user_params - params.require(:user).permit(:email, :password, :password_confirmation, :username) + params.require(:user).permit(:email, :password, :password_confirmation, :username, :is_admin) end - - def set_is_admin - @is_admin = current_user.is_admin - end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4e3ad1fdb..86507220e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -130,10 +130,6 @@ def event_types_sentence(conference, is_admin = true) end end - def event_types_dropdown(conference, is_admin = true) - is_admin ? conference.event_types : conference.event_types.available_for_public - end - def sign_in_path if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) == 'true' new_user_ichain_session_path diff --git a/app/models/event_type.rb b/app/models/event_type.rb index 198016a10..9f2c3d72e 100644 --- a/app/models/event_type.rb +++ b/app/models/event_type.rb @@ -32,6 +32,7 @@ class EventType < ApplicationRecord validates :color, format: /\A#[0-9A-F]{6}\z/ before_validation :capitalize_color + before_validation :strip_title alias_attribute :name, :title @@ -57,7 +58,7 @@ def conference_id program.conference_id end - # def self.available_for_public_submission - # is_admin? all : available_for_public - # end + def strip_title + self.title = title.strip unless title.nil? + end end diff --git a/app/views/admin/event_types/_form.html.haml b/app/views/admin/event_types/_form.html.haml index 6426a38ab..234d50293 100644 --- a/app/views/admin/event_types/_form.html.haml +++ b/app/views/admin/event_types/_form.html.haml @@ -18,8 +18,6 @@ .form-group = f.label "Allow public submission?", for: :enable_public_submission = f.check_box :enable_public_submission, class: 'switch-checkbox' - .help-block - Do we need description for explanation? .form-group = f.label :minimum_abstract_length %abbr{title: 'This field is required'} * diff --git a/app/views/proposals/_encouragement_text.html.haml b/app/views/proposals/_encouragement_text.html.haml index 224f90f2a..dc39f56b8 100644 --- a/app/views/proposals/_encouragement_text.html.haml +++ b/app/views/proposals/_encouragement_text.html.haml @@ -1,7 +1,7 @@ %p.lead - if @program.event_types.any? You can submit proposals for - = "#{event_types_sentence(@conference, @is_admin)}." + = "#{event_types_sentence(@conference, current_user.is_admin)}." - if @program.tracks.confirmed.cfp_active.any? Proposals should fit in one of the = "#{pluralize(@program.tracks.confirmed.cfp_active.count, 'track')}:" diff --git a/app/views/proposals/_submission_type_content_form.haml b/app/views/proposals/_submission_type_content_form.haml index 5d9e634b1..1f82ee5e2 100644 --- a/app/views/proposals/_submission_type_content_form.haml +++ b/app/views/proposals/_submission_type_content_form.haml @@ -3,7 +3,10 @@ .form-group = f.label :event_type_id, "Type" - = f.select :event_type_id, event_type_select_options(event_types_dropdown(@conference, @is_admin)), { include_blank: false }, { class: 'select-help-toggle form-control' } + - if current_user.is_admin + = f.select :event_type_id, event_type_select_options(@conference.program.event_types), { include_blank: false }, { class: 'select-help-toggle form-control' } + - else + = f.select :event_type_id, event_type_select_options(@conference.program.event_types.available_for_public), { include_blank: false }, { class: 'select-help-toggle form-control' } - program.event_types.each do |event_type| .help-block.event_event_type_id.collapse{ id: "#{dom_id(event_type)}-help" } diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 9e4108337..14ffd3f16 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -155,4 +155,22 @@ expect(conference_logo_url(conference2)).to include('2.png') end end + + describe '#event_type_sentence' do + before do + create(:event_type, title: 'Keynote', program: conference.program, enable_public_submission: false) + end + + context 'when a user is an admin' do + it 'returns a sentence with all event types' do + expect(helper.event_types_sentence(conference, true)).to eq 'Talks, Workshops, and Keynotes' + end + end + + context 'when a user is not an admin' do + it 'returns a sentence only event types that allow public submission' do + expect(helper.event_types_sentence(conference, false)).to eq 'Talks and Workshops' + end + end + end end diff --git a/spec/models/event_type_spec.rb b/spec/models/event_type_spec.rb index 8a97d8cfe..a3cd693c2 100644 --- a/spec/models/event_type_spec.rb +++ b/spec/models/event_type_spec.rb @@ -62,5 +62,25 @@ expect(build(:event_type, program: conference.program, length: 37)).not_to be_valid end end + + describe 'title' do + it 'removes leading and trailing whitespace from title' do + event_type = EventType.new(title: ' Movie ') + event_type.valid? + expect(event_type.title).to eq('Movie') + end + end end + + describe 'scope :available_for_public' do + it 'includes event types with enable_public_submission set to true' do + public_event_type = create(:event_type, program: conference.program, enable_public_submission: true) + expect(EventType.available_for_public).to include(public_event_type) + end + + it 'excludes event types with enable_public_submission set to false' do + non_public_event_type = create(:event_type, program: conference.program, enable_public_submission: false) + expect(EventType.available_for_public).not_to include(non_public_event_type) + end + end end From 8a8f9de7f62d4399cde73bfb2a49a21385eec7d5 Mon Sep 17 00:00:00 2001 From: tiffanylamm Date: Mon, 15 Apr 2024 09:20:08 -0700 Subject: [PATCH 08/10] proposals work for not signed in user --- app/controllers/proposals_controller.rb | 1 - app/helpers/application_helper.rb | 4 ++-- app/helpers/event_types_helper.rb | 6 ++--- app/views/admin/cfps/_events_cfp.html.haml | 2 +- app/views/admin/programs/show.html.haml | 2 +- .../proposals/_encouragement_text.html.haml | 2 +- .../_submission_type_content_form.haml | 2 +- spec/helpers/application_helper_spec.rb | 24 +++++++++---------- spec/models/event_type_spec.rb | 14 +++++------ 9 files changed, 28 insertions(+), 29 deletions(-) diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 3c63782a8..23087362d 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -49,7 +49,6 @@ def create authorize! :create, @user if @user.save sign_in(@user) - set_is_admin else flash.now[:error] = "Could not save user: #{@user.errors.full_messages.join(', ')}" render action: 'new' diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 86507220e..492c98a7f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -122,10 +122,10 @@ def volunteer_links(event) end, ', ') end - def event_types_sentence(conference, is_admin = true) + def event_types_sentence(conference, is_admin) if is_admin conference.event_types.map { |et| et.title.pluralize }.to_sentence - else + else conference.event_types.available_for_public.map { |et| et.title.pluralize }.to_sentence end end diff --git a/app/helpers/event_types_helper.rb b/app/helpers/event_types_helper.rb index 1aa439ed8..f1306cfec 100644 --- a/app/helpers/event_types_helper.rb +++ b/app/helpers/event_types_helper.rb @@ -13,9 +13,9 @@ def event_type_select_options(event_types = {}) "#{type.title} - #{show_time(type.length)}", type.id, { data: { - min_words: type.minimum_abstract_length, - max_words: type.maximum_abstract_length, - template: type.submission_template + min_words: type.minimum_abstract_length, + max_words: type.maximum_abstract_length, + template: type.submission_template } } ] end diff --git a/app/views/admin/cfps/_events_cfp.html.haml b/app/views/admin/cfps/_events_cfp.html.haml index 6e8066b4a..e04020cd4 100644 --- a/app/views/admin/cfps/_events_cfp.html.haml +++ b/app/views/admin/cfps/_events_cfp.html.haml @@ -21,7 +21,7 @@ %dt Event types: %dd - = event_types_sentence(conference) + = event_types_sentence(conference, true) %dt Tracks: %dd diff --git a/app/views/admin/programs/show.html.haml b/app/views/admin/programs/show.html.haml index db1e91ffb..f2c1949fa 100644 --- a/app/views/admin/programs/show.html.haml +++ b/app/views/admin/programs/show.html.haml @@ -22,7 +22,7 @@ %dt Event types: %dd - = event_types_sentence(@conference) + = event_types_sentence(@conference, true) %dt Tracks: %dd diff --git a/app/views/proposals/_encouragement_text.html.haml b/app/views/proposals/_encouragement_text.html.haml index dc39f56b8..8f831582f 100644 --- a/app/views/proposals/_encouragement_text.html.haml +++ b/app/views/proposals/_encouragement_text.html.haml @@ -1,7 +1,7 @@ %p.lead - if @program.event_types.any? You can submit proposals for - = "#{event_types_sentence(@conference, current_user.is_admin)}." + = "#{event_types_sentence(@conference, current_user&.is_admin || false)}." - if @program.tracks.confirmed.cfp_active.any? Proposals should fit in one of the = "#{pluralize(@program.tracks.confirmed.cfp_active.count, 'track')}:" diff --git a/app/views/proposals/_submission_type_content_form.haml b/app/views/proposals/_submission_type_content_form.haml index 1f82ee5e2..c7b947e25 100644 --- a/app/views/proposals/_submission_type_content_form.haml +++ b/app/views/proposals/_submission_type_content_form.haml @@ -3,7 +3,7 @@ .form-group = f.label :event_type_id, "Type" - - if current_user.is_admin + - if current_user&.is_admin = f.select :event_type_id, event_type_select_options(@conference.program.event_types), { include_blank: false }, { class: 'select-help-toggle form-control' } - else = f.select :event_type_id, event_type_select_options(@conference.program.event_types.available_for_public), { include_blank: false }, { class: 'select-help-toggle form-control' } diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 14ffd3f16..808a2827d 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -156,21 +156,21 @@ end end - describe '#event_type_sentence' do - before do + describe '#event_type_sentence' do + before do create(:event_type, title: 'Keynote', program: conference.program, enable_public_submission: false) - end + end - context 'when a user is an admin' do - it 'returns a sentence with all event types' do + context 'when a user is an admin' do + it 'returns a sentence with all event types' do expect(helper.event_types_sentence(conference, true)).to eq 'Talks, Workshops, and Keynotes' - end - end + end + end - context 'when a user is not an admin' do - it 'returns a sentence only event types that allow public submission' do + context 'when a user is not an admin' do + it 'returns a sentence only event types that allow public submission' do expect(helper.event_types_sentence(conference, false)).to eq 'Talks and Workshops' - end - end - end + end + end + end end diff --git a/spec/models/event_type_spec.rb b/spec/models/event_type_spec.rb index a3cd693c2..840e84da8 100644 --- a/spec/models/event_type_spec.rb +++ b/spec/models/event_type_spec.rb @@ -63,24 +63,24 @@ end end - describe 'title' do - it 'removes leading and trailing whitespace from title' do + describe 'title' do + it 'removes leading and trailing whitespace from title' do event_type = EventType.new(title: ' Movie ') event_type.valid? expect(event_type.title).to eq('Movie') - end - end + end + end end describe 'scope :available_for_public' do it 'includes event types with enable_public_submission set to true' do public_event_type = create(:event_type, program: conference.program, enable_public_submission: true) expect(EventType.available_for_public).to include(public_event_type) - end + end it 'excludes event types with enable_public_submission set to false' do non_public_event_type = create(:event_type, program: conference.program, enable_public_submission: false) expect(EventType.available_for_public).not_to include(non_public_event_type) - end - end + end + end end From ecba0fbb4afed3660b724ef3548075393c76c548 Mon Sep 17 00:00:00 2001 From: Warren Huang <62491485+warrenlet@users.noreply.github.com> Date: Mon, 15 Apr 2024 17:00:38 -0700 Subject: [PATCH 09/10] Update .rubocop_todo.yml adjust PerceivedComplexity limit by 1 to accommodate the adding committee boolean in conference controller --- .rubocop_todo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 48a9a2252..2d6689045 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -87,7 +87,7 @@ Metrics/ModuleLength: # Offense count: 25 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: - Max: 17 + Max: 18 # Offense count: 13 Naming/AccessorMethodName: From a41141f4fbddea6646dfb6806367ed15b48713a2 Mon Sep 17 00:00:00 2001 From: Warren Huang <62491485+warrenlet@users.noreply.github.com> Date: Mon, 15 Apr 2024 17:26:19 -0700 Subject: [PATCH 10/10] Update .rubocop_todo.yml Revert to the previous setting --- .rubocop_todo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2d6689045..48a9a2252 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -87,7 +87,7 @@ Metrics/ModuleLength: # Offense count: 25 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: - Max: 18 + Max: 17 # Offense count: 13 Naming/AccessorMethodName: