Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,6 @@ Rails/HelperInstanceVariable:
Exclude:
- 'app/helpers/email_helper.rb'

# Offense count: 2
# Configuration parameters: IgnoreScopes.
Rails/InverseOf:
Exclude:
- 'app/models/member.rb'
- 'app/models/workshop_invitation.rb'

# Offense count: 2
Rails/LexicallyScopedActionFilter:
Exclude:
- 'app/controllers/concerns/admin/sponsor_concerns.rb'

# Offense count: 2
Rails/OutputSafety:
Exclude:
- 'app/helpers/application_helper.rb'
- 'app/presenters/address_presenter.rb'

# Offense count: 9
# Configuration parameters: ForbiddenMethods, AllowedMethods.
# ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all
Expand Down
43 changes: 41 additions & 2 deletions app/controllers/admin/workshops_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class Admin::WorkshopsController < Admin::ApplicationController
include Admin::SponsorConcerns
include Admin::WorkshopConcerns
include Admin::WorkshopConcerns

before_action :set_workshop_by_id, only: %i[show edit destroy update]
before_action :set_and_decorate_workshop, only: %i[attendees_checklist attendees_emails send_invites changes]
before_action :set_workshop, only: %i[sponsor destroy_sponsor host destroy_host]
before_action :set_sponsor, only: %i[sponsor host]

WORKSHOP_DELETION_TIME_FRAME_SINCE_CREATION = 4.hours

Expand Down Expand Up @@ -114,6 +115,36 @@ def changes
@student_invitations = invitations.to_students
end

def sponsor
flash[:notice] = if workshop_sponsors.save
'Sponsor added successfully'
else
workshop_sponsors.errors.full_messages.to_s
end
redirect_back fallback_location: root_path
end

def destroy_sponsor
@sponsor = Sponsor.find(params[:sponsor_id])
@workshop.workshop_sponsors.find_by(sponsor: @sponsor).destroy
redirect_back fallback_location: root_path
end

def host
set_sponsor
@workshop_sponsor = WorkshopSponsor.find_or_create_by(workshop: @workshop, sponsor: @sponsor)
@workshop_sponsor.update(host: true)
flash[:notice] = 'Host set successfully'

redirect_back fallback_location: root_path
end

def destroy_host
@workshop.workshop_sponsors.find_by(host: true).update(host: false)

redirect_back fallback_location: root_path
end

private

def workshop_params
Expand Down Expand Up @@ -202,4 +233,12 @@ def update_workshop_details
assign_organisers(organiser_ids)
assign_host(host_id)
end

def set_sponsor
@sponsor = Sponsor.find(params[:workshop][:sponsor_ids])
end

def workshop_sponsor(host = false)
@workshop_sponsor ||= WorkshopSponsor.new(workshop: @workshop, sponsor: @sponsor, host: host)
end
end
56 changes: 0 additions & 56 deletions app/controllers/concerns/admin/sponsor_concerns.rb

This file was deleted.

3 changes: 3 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def retrieve_title
end

def dot_markdown(text)
# Commonmarker sanitises raw HTML; `.html_safe` prevents Rails double-escaping the result
# rubocop:disable Rails/OutputSafety
Commonmarker.to_html(text).html_safe
# rubocop:enable Rails/OutputSafety
end

def belongs_to_group?(group)
Expand Down
2 changes: 1 addition & 1 deletion app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Member < ApplicationRecord
has_many :workshop_invitations
has_many :invitations
has_many :auth_services
has_many :feedbacks, foreign_key: :coach_id
has_many :feedbacks, foreign_key: :coach_id, inverse_of: :coach
has_many :subscriptions
has_many :groups, through: :subscriptions
has_many :member_notes
Expand Down
2 changes: 1 addition & 1 deletion app/models/workshop_invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class WorkshopInvitation < ApplicationRecord
belongs_to :workshop
belongs_to :member
belongs_to :overrider, foreign_key: :last_overridden_by_id, class_name: 'Member', inverse_of: false, optional: true
has_one :waiting_list, foreign_key: :invitation_id
has_one :waiting_list, foreign_key: :invitation_id, inverse_of: :invitation

validates :workshop, :member, presence: true
validates :member_id, uniqueness: { scope: %i[workshop_id role] }
Expand Down
3 changes: 3 additions & 0 deletions app/presenters/address_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ def to_html
city_and_postal_code = [model.city, model.postal_code].delete_if(&:empty?)
.join(', ')

# Every element is html_escape'd; `.html_safe` prevents Rails double-escaping the joined string
# rubocop:disable Rails/OutputSafety
[model.flat, model.street, city_and_postal_code, lat, lng]
.delete_if(&:empty?)
.map { |line| ERB::Util.html_escape(line) }
.join('<br/>').html_safe
# rubocop:enable Rails/OutputSafety
end

def for_map
Expand Down