From 6bbbe1bb9a1c21d4184c7eaf11f930cc53000801 Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Wed, 19 Apr 2023 18:55:38 +0200 Subject: [PATCH 01/10] Fix id of ticket field used to check whether a comment is possible --- app/assets/javascripts/registrations.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/registrations.js b/app/assets/javascripts/registrations.js index abfe9913..66b33b47 100644 --- a/app/assets/javascripts/registrations.js +++ b/app/assets/javascripts/registrations.js @@ -39,10 +39,10 @@ $(document).on('turbolinks:load', function() { } }; - $("#registration_access_levels").on('change', function() { + $("#registration_access_level").on('change', function() { return hideCommentFieldIfNeeded($(this).val()); }); - return hideCommentFieldIfNeeded($("#registration_access_levels").val()); + return hideCommentFieldIfNeeded($("#registration_access_level").val()); -}); \ No newline at end of file +}); From 3c81d2216583d2b4184650461ffc0da5cac6002f Mon Sep 17 00:00:00 2001 From: Tom Naessens Date: Wed, 19 Apr 2023 20:19:59 +0200 Subject: [PATCH 02/10] Bump Ruby to 3.0.6 --- .ruby-version | 2 +- .tool-versions | 2 +- Dockerfile | 2 +- README.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.ruby-version b/.ruby-version index b0f2dcb3..818bd47a 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.0.4 +3.0.6 diff --git a/.tool-versions b/.tool-versions index c133be0c..d6608a7e 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -ruby 3.0.4 +ruby 3.0.6 diff --git a/Dockerfile b/Dockerfile index f2eb68c5..d051340f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:3.0.4 +FROM ruby:3.0.6 ENV RAILS_ENV=production diff --git a/README.md b/README.md index e5106921..f20a8bd3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ In short, Gandalf is a project that does everything that makes organising and managing an event a lot easier for FK-clubs of the University of Ghent. The application is written specifically for the UGent FakulteitenKonvent. It allows students to register for events and it also interacts with the FK-Enrolment database and allows members of student unions to subscribe to member-only events from their clubs. # Getting started -0. Install the prerequisites: ruby 3.0.4, preferably using [asdf](https://asdf-vm.com/), and some system libraries depending on your OS (e.g. imagemagick) +0. Install the prerequisites: ruby 3.0.6, preferably using [asdf](https://asdf-vm.com/), and some system libraries depending on your OS (e.g. imagemagick) 1. Install the ruby dependencies: `bin/bundle` 2. Start up the database, sidekiq and rails server by running `bin/dev` 3. Set up some database data using `rails db:setup` From 570be4fdd3195b88ac44bc9848f6e7806e027063 Mon Sep 17 00:00:00 2001 From: Rien Maertens Date: Wed, 19 Apr 2023 20:01:08 +0200 Subject: [PATCH 03/10] Add Nix flake for devshell --- README.md | 11 +++++++ flake.lock | 85 +++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/README.md b/README.md index f20a8bd3..1f841cfd 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,9 @@ In short, Gandalf is a project that does everything that makes organising and managing an event a lot easier for FK-clubs of the University of Ghent. The application is written specifically for the UGent FakulteitenKonvent. It allows students to register for events and it also interacts with the FK-Enrolment database and allows members of student unions to subscribe to member-only events from their clubs. # Getting started + +If you have NixOS or Nix installed, you can use the `flake.nix` to avoid the hassle of installing the right dependencies. Scroll down for more info. + 0. Install the prerequisites: ruby 3.0.6, preferably using [asdf](https://asdf-vm.com/), and some system libraries depending on your OS (e.g. imagemagick) 1. Install the ruby dependencies: `bin/bundle` 2. Start up the database, sidekiq and rails server by running `bin/dev` @@ -14,6 +17,14 @@ In short, Gandalf is a project that does everything that makes organising and ma In case you want to start the webserver in your IDE, just run `docker-compose up -d` and start Sidekiq manually (`bundle exec sidekiq`) +## Development using Nix + +- Make sure you have [Nix](https://nixos.org/download.html#download-nix) installed. +- Run `nix develop` +- Done! You have everything installed. You can now: + 1. Install Ruby dependencies with `gems:refresh` + 2. Start EVERYTHING with `server:start` + # Manually adding users to clubs / making users admin ``` diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..111ed1f5 --- /dev/null +++ b/flake.lock @@ -0,0 +1,85 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1678798690, + "narHash": "sha256-ES6PnlxlQ8ROzHhMKUzuvwmTZvoift1LXyG+LN7TBNI=", + "owner": "chvp", + "repo": "devshell", + "rev": "5f31e3757888be373af78b724982bb4018406c98", + "type": "github" + }, + "original": { + "owner": "chvp", + "repo": "devshell", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1681737997, + "narHash": "sha256-pHhjgsIkRMu80LmVe8QoKIZB6VZGRRxFmIvsC5S89k4=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "f00994e78cd39e6fc966f0c4103f908e63284780", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..144bdc2e --- /dev/null +++ b/flake.nix @@ -0,0 +1,96 @@ +{ + description = "Gandalf"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + devshell = { + url = "github:chvp/devshell"; + inputs = { + flake-utils.follows = "flake-utils"; + nixpkgs.follows = "nixpkgs"; + }; + }; + }; + + outputs = { self, nixpkgs, devshell, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; overlays = [ devshell.overlays.default ]; }; + in + { + devShells = rec { + default = gandalf; + gandalf = pkgs.devshell.mkShell { + name = "Gandalf"; + imports = [ "${devshell}/extra/language/ruby.nix" ]; + packages = with pkgs; [ + docker + nodejs + libyaml + imagemagick + ]; + language.ruby = { + package = pkgs.ruby_3_0; + nativeDeps = [ pkgs.libmysqlclient pkgs.zlib ]; + }; + env = [ + { + name = "DATABASE_ROOT_PASSWORD"; + eval = "gandalf"; + } + { + name = "TEST_DATABASE_URL"; + eval = "mysql2://root:gandalf@127.0.0.1:3306/gandalf_test"; + } + { + name = "DATABASE_URL"; + eval = "mysql2://root:gandalf@127.0.0.1:3306/gandalf"; + } + ]; + serviceGroups.server.services = { + rails = { + name = "server"; + command = "rails db:prepare && rails s -p 3000"; + }; + mysql.command = "mysql"; + redis.command = "redis-server --port 6379"; + sidekiq.command = "bundle exec sidekiq"; + }; + commands = [ + { + name = "gems:refresh"; + category = "general commands"; + help = "Install dependencies"; + command = '' + bundle install + bundle pristine + ''; + } + { + name = "mysql"; + category = "database"; + help = "Start database docker"; + command = '' + trap "systemd-run --user docker stop gandalf-db" 0 + docker run --name gandalf-db -p 3306:3306 --rm -v gandalf-db-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=$DATABASE_ROOT_PASSWORD mariadb:latest & + wait + ''; + } + { + name = "mysql-console"; + category = "database"; + help = "Open database console"; + command = '' + docker exec -i gandalf-db mysql -uroot -p"$DATABASE_ROOT_PASSWORD" + ''; + } + { + name = "redis"; + package = pkgs.redis; + } + ]; + }; + }; + } + ); +} From e532e9f545ab7ba38196981cdef56ab20157bb5b Mon Sep 17 00:00:00 2001 From: Rien Maertens Date: Wed, 19 Apr 2023 21:10:44 +0200 Subject: [PATCH 04/10] Run rubocop in pre-commit hook --- flake.nix | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 144bdc2e..18fc4df7 100644 --- a/flake.nix +++ b/flake.nix @@ -22,7 +22,16 @@ default = gandalf; gandalf = pkgs.devshell.mkShell { name = "Gandalf"; - imports = [ "${devshell}/extra/language/ruby.nix" ]; + imports = [ + "${devshell}/extra/language/ruby.nix" + "${devshell}/extra/git/hooks.nix" + ]; + git.hooks = { + enable = true; + pre-commit = { + text = "bundle exec rubocop"; + }; + }; packages = with pkgs; [ docker nodejs From 1ea856737c8720028f3afb00c450aa882dd828c5 Mon Sep 17 00:00:00 2001 From: Hannes Date: Wed, 19 Apr 2023 20:48:54 +0200 Subject: [PATCH 05/10] add ical to email --- app/actions/generate_ical.rb | 22 ++++++++++++++++++++++ app/controllers/events_controller.rb | 14 +------------- app/mailers/registration_mailer.rb | 2 ++ test/mailers/registration_mailer_test.rb | 2 +- 4 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 app/actions/generate_ical.rb diff --git a/app/actions/generate_ical.rb b/app/actions/generate_ical.rb new file mode 100644 index 00000000..aeabb03e --- /dev/null +++ b/app/actions/generate_ical.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class GenerateIcal + def initialize(event) + @event = event + end + + def call + cal = Icalendar::Calendar.new + cal.event do |e| + e.dtstart = @event.start_date + e.dtend = @event.end_date + e.location = @event.location + e.summary = @event.name + e.description = @event.website + e.organizer = "mailto:#{@event.contact_email}" + e.organizer = Icalendar::Values::CalAddress.new("mailto:#{@event.contact_email}", cn: @event.club.name) + end + cal.publish + cal.to_ical + end +end diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 45b99528..7ae9df44 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -27,19 +27,7 @@ def show respond_to do |format| format.html { render :show } - format.ics do - cal = Icalendar::Calendar.new - cal.event do |e| - e.dtstart = @event.start_date - e.dtend = @event.end_date - e.location = @event.location - e.summary = @event.name - e.organizer = "mailto:#{@event.contact_email}" - e.organizer = Icalendar::Values::CalAddress.new("mailto:#{@event.contact_email}", cn: @event.club.name) - end - cal.publish - render plain: cal.to_ical - end + format.ics { render plain: GenerateIcal.new(@event).call } end end diff --git a/app/mailers/registration_mailer.rb b/app/mailers/registration_mailer.rb index a1b5f728..be0113f1 100644 --- a/app/mailers/registration_mailer.rb +++ b/app/mailers/registration_mailer.rb @@ -13,6 +13,8 @@ def ticket(registration) barcodes = GenerateEmailBarcodes.new(@registration.barcode_data).call + attachments["event.ics"] = GenerateIcal.new(@registration.event).call + attachments.inline['barcode.png'] = barcodes.first attachments.inline['barcode-tilted.png'] = barcodes.second diff --git a/test/mailers/registration_mailer_test.rb b/test/mailers/registration_mailer_test.rb index 56a54268..31ac6038 100644 --- a/test/mailers/registration_mailer_test.rb +++ b/test/mailers/registration_mailer_test.rb @@ -33,6 +33,6 @@ class RegistrationMailerTest < ActionMailer::TestCase email = ActionMailer::Base.deliveries.last assert_match(/Ticket for/, email.subject) # We only have a html part (and 2 png parts) here - assert_match(/Een signatuur/, email.parts.first.body.to_s) + assert_match(/Een signatuur/, email.parts.first.parts.first.body.to_s) end end From 6b467c0967dfc64df1bda9a0ad5ec0f1ba2401d3 Mon Sep 17 00:00:00 2001 From: Maxim De Clercq Date: Wed, 19 Apr 2023 20:33:20 +0200 Subject: [PATCH 06/10] Fix FK Intranet integration The FK Intranet API returns capitalized internal names. Downcasing the returned value fixes the problem. --- app/actions/user/fetch_club.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/actions/user/fetch_club.rb b/app/actions/user/fetch_club.rb index 2880acd6..1fcb4aa0 100644 --- a/app/actions/user/fetch_club.rb +++ b/app/actions/user/fetch_club.rb @@ -21,8 +21,8 @@ def call private def fk_fetch_club - fk_authorized_clubs = Set['chemica', 'dentalia', 'filologica', 'fk', 'gbk', 'geografica', 'geologica', 'gfk', 'hermes', 'hilok', 'khk', - 'kmf', 'lila', 'lombrosiana', 'moeder-lies', 'oak', 'politeia', 'slavia', 'vbk', 'vdk', 'vek', 'veto', + fk_authorized_clubs = Set['chemica', 'dentalia', 'dsa', 'filologica', 'fk', 'gbk', 'geografica', 'geologica', 'gfk', 'hermes', 'hilok', + 'khk', 'kmf', 'lila', 'lombrosiana', 'moeder-lies', 'oak', 'politeia', 'slavia', 'vbk', 'vdk', 'vek', 'veto', 'vgk-fgen', 'vgk-flwi', 'vlak', 'vlk', 'vppk', 'vrg', 'vtk', 'wina'] resp = HTTParty.get( "#{Rails.application.secrets.fk_auth_url}/#{user.username}/Gandalf", @@ -35,7 +35,7 @@ def fk_fetch_club return Set.new unless resp.success? hash = JSON[resp.body] - clubs = hash['clubs'].map { |club| club['internal_name'] }.to_set + clubs = hash['clubs'].map { |club| club['internal_name'].downcase }.to_set # Only return clubs FK can manage clubs & fk_authorized_clubs end @@ -77,6 +77,8 @@ def dsa_fetch_club next return_map end + return Set.new if cas_to_dsa_associations.nil? + cas_to_dsa_associations.fetch(user.username, Set[]) end end From 4fa161f11ee3fa6dcc61b3404803c5b6d360b085 Mon Sep 17 00:00:00 2001 From: Tom Naessens Date: Wed, 19 Apr 2023 21:51:12 +0200 Subject: [PATCH 07/10] Bump rails_style and Rubocop --- .rubocop_todo.yml | 14 +++++++- Gemfile.lock | 33 ++++++++++-------- app/actions/user/fetch_club.rb | 2 +- app/controllers/access_levels_controller.rb | 18 +++++----- app/controllers/events_controller.rb | 24 ++++++------- app/controllers/partners_controller.rb | 16 ++++----- app/controllers/registrations_controller.rb | 38 ++++++++++----------- test/helpers/event_helper_test.rb | 8 ++--- 8 files changed, 84 insertions(+), 69 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 009d07eb..4cb156e5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,7 +1,19 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2022-10-08 19:18:22 UTC using RuboCop version 1.36.0. +# on 2023-04-19 19:51:02 UTC using RuboCop version 1.50.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. + +# Offense count: 5 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Include. +# Include: **/test/**/*.rb +Rails/ActionControllerTestCase: + Exclude: + - 'test/controllers/event_controller_test.rb' + - 'test/controllers/partners_controller_test.rb' + - 'test/controllers/registrations_controller_test.rb' + - 'test/controllers/users_controller_test.rb' + - 'test/controllers/welcome_controller_test.rb' diff --git a/Gemfile.lock b/Gemfile.lock index d6b30440..2177630e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ GIT GIT remote: https://github.com/ZeusWPI/rails_style.git - revision: 7101522ddc0f7e4cf13235a6e7a7318f04253443 + revision: 33ea5008e49be142ad490c5b572ef4b3f6436f23 specs: rails_style (0.0.1) bundler (>= 2.1.4) @@ -161,7 +161,7 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (2.6.2) + json (2.6.3) jwt (2.3.0) launchy (2.5.0) addressable (~> 2.7) @@ -232,8 +232,8 @@ GEM paper_trail (14.0.0) activerecord (>= 6.0) request_store (~> 1.4) - parallel (1.22.1) - parser (3.1.2.1) + parallel (1.23.0) + parser (3.2.2.0) ast (~> 2.4.1) poltergeist (1.18.1) capybara (>= 2.1, < 4) @@ -300,37 +300,40 @@ GEM actionview (>= 5) redis-client (0.14.1) connection_pool - regexp_parser (2.6.0) + regexp_parser (2.8.0) request_store (1.5.1) rack (>= 1.4) responders (3.1.0) actionpack (>= 5.2) railties (>= 5.2) rexml (3.2.5) - rubocop (1.36.0) + rubocop (1.50.2) json (~> 2.3) parallel (~> 1.10) - parser (>= 3.1.2.1) + parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.20.1, < 2.0) + rubocop-ast (>= 1.28.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.21.0) - parser (>= 3.1.1.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.28.0) + parser (>= 3.2.1.0) + rubocop-capybara (2.17.1) + rubocop (~> 1.41) rubocop-minitest (0.22.2) rubocop (>= 0.90, < 2.0) - rubocop-rails (2.16.1) + rubocop-rails (2.19.1) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) - rubocop-rspec (2.13.2) + rubocop-rspec (2.20.0) rubocop (~> 1.33) + rubocop-capybara (~> 2.17) ruby-graphviz (1.2.5) rexml ruby-ole (1.2.12.2) - ruby-progressbar (1.11.0) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) @@ -394,7 +397,7 @@ GEM concurrent-ruby (~> 1.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) - unicode-display_width (2.3.0) + unicode-display_width (2.4.2) validates_timeliness (6.0.0) activemodel (>= 6.0.0, < 7) timeliness (>= 0.3.10, < 1) diff --git a/app/actions/user/fetch_club.rb b/app/actions/user/fetch_club.rb index 1fcb4aa0..cb8e8713 100644 --- a/app/actions/user/fetch_club.rb +++ b/app/actions/user/fetch_club.rb @@ -35,7 +35,7 @@ def fk_fetch_club return Set.new unless resp.success? hash = JSON[resp.body] - clubs = hash['clubs'].map { |club| club['internal_name'].downcase }.to_set + clubs = hash['clubs'].to_set { |club| club['internal_name'].downcase } # Only return clubs FK can manage clubs & fk_authorized_clubs end diff --git a/app/controllers/access_levels_controller.rb b/app/controllers/access_levels_controller.rb index 3ebd6fe8..d9ed4a07 100644 --- a/app/controllers/access_levels_controller.rb +++ b/app/controllers/access_levels_controller.rb @@ -5,13 +5,20 @@ class AccessLevelsController < ApplicationController respond_to :html, :js + def index + @event = Event.find params.require(:event_id) + authorize! :read, @event + end + def show @access_level = AccessLevel.find params.require(:id) end - def index + def edit @event = Event.find params.require(:event_id) - authorize! :read, @event + authorize! :update, @event + @access_level = @event.access_levels.find(params.require(:id)) + respond_with @access_level end def create @@ -24,13 +31,6 @@ def create respond_with @access_level end - def edit - @event = Event.find params.require(:event_id) - authorize! :update, @event - @access_level = @event.access_levels.find(params.require(:id)) - respond_with @access_level - end - def update @event = Event.find params.require(:event_id) authorize! :update, @event diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 7ae9df44..be404756 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -35,9 +35,13 @@ def new; end def edit; end - def destroy - @event.destroy! - redirect_to action: :index + def create + authorize! :create, Event + + @event = Event.new(event_create_params) + flash.now[:success] = "Successfully created event." if @event.save + + respond_with @event end def update @@ -48,6 +52,11 @@ def update render action: :edit end + def destroy + @event.destroy! + redirect_to action: :index + end + def toggle_registration_open @event = Event.find params.require(:id) authorize! :update, @event @@ -57,15 +66,6 @@ def toggle_registration_open redirect_to action: :edit end - def create - authorize! :create, Event - - @event = Event.new(event_create_params) - flash.now[:success] = "Successfully created event." if @event.save - - respond_with @event - end - def statistics @event = Event.find params.require(:id) authorize! :view_stats, @event diff --git a/app/controllers/partners_controller.rb b/app/controllers/partners_controller.rb index 2b88f162..b84b932c 100644 --- a/app/controllers/partners_controller.rb +++ b/app/controllers/partners_controller.rb @@ -23,6 +23,14 @@ def new @partner = Partner.new end + def edit + @event = Event.find params.require(:event_id) + authorize! :update, @event + + @partner = @event.partners.find params.require(:id) + respond_with @partner + end + def create @event = Event.find params.require(:event_id) authorize! :update, @event @@ -39,14 +47,6 @@ def create respond_with @partner end - def edit - @event = Event.find params.require(:event_id) - authorize! :update, @event - - @partner = @event.partners.find params.require(:id) - respond_with @partner - end - def update @event = Event.find params.require(:event_id) authorize! :update, @event diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 9d9d0a8a..82f41e8b 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -25,25 +25,6 @@ def new @registration = Registration.new end - def destroy - @event = Event.find params.require(:event_id) - authorize! :destroy, @event - registration = Registration.find params.require(:id) - @id = registration.id - registration.destroy! - end - - def info - @registration = Registration.find params.require(:id) - authorize! :read, @registration.event - end - - def resend - @registration = Registration.find params.require(:id) - authorize! :update, @registration.event - @registration.deliver - end - def create @event = Event.find params.require(:event_id) @@ -83,6 +64,25 @@ def update respond_with @registration end + def destroy + @event = Event.find params.require(:event_id) + authorize! :destroy, @event + registration = Registration.find params.require(:id) + @id = registration.id + registration.destroy! + end + + def info + @registration = Registration.find params.require(:id) + authorize! :read, @registration.event + end + + def resend + @registration = Registration.find params.require(:id) + authorize! :update, @registration.event + @registration.deliver + end + def email @event = Event.find params.require(:event_id) authorize! :read, @event diff --git a/test/helpers/event_helper_test.rb b/test/helpers/event_helper_test.rb index b94f6714..cd591dc5 100644 --- a/test/helpers/event_helper_test.rb +++ b/test/helpers/event_helper_test.rb @@ -6,13 +6,13 @@ class EventHelperTest < ActionView::TestCase include EventHelper test "coloring" do - assert_equal "default", \ + assert_equal "default", color_for_tickets_left(access_levels(:unlimited)) - assert_equal "danger", \ + assert_equal "danger", color_for_tickets_left(access_levels(:limited0)) - assert_equal "warning", \ + assert_equal "warning", color_for_tickets_left(access_levels(:limited1)) - assert_equal "default", \ + assert_equal "default", color_for_tickets_left(access_levels(:limited2)) end end From 371b984b89e109bb69fafdef559ca1f1b9e02e58 Mon Sep 17 00:00:00 2001 From: Tom Naessens Date: Sat, 15 Oct 2022 21:47:15 +0200 Subject: [PATCH 08/10] Add ticket overview screen --- app/actions/generate_html_barcodes.rb | 17 +++++ app/assets/stylesheets/barcodes.css.scss | 4 ++ app/controllers/registrations_controller.rb | 13 +++- app/helpers/application_helper.rb | 6 +- app/models/registration.rb | 8 +++ .../access_levels/_access_level.html.erb | 2 +- app/views/access_levels/_form.html.erb | 2 +- app/views/events/_event_details.html.erb | 45 ++++++++++++++ app/views/events/show.html.erb | 46 +------------- .../confirm_registration.html.erb | 4 +- .../confirm_registration.text.erb | 4 +- .../_registration_payment_form.html.erb | 6 +- app/views/registrations/show.html.erb | 62 +++++++++++++++++++ config/routes.rb | 4 +- ...0221009173017_add_token_to_registration.rb | 17 +++++ db/schema.rb | 4 +- test/fixtures/registrations.yml | 7 +++ test/models/registration_test.rb | 2 + 18 files changed, 194 insertions(+), 59 deletions(-) create mode 100644 app/actions/generate_html_barcodes.rb create mode 100644 app/assets/stylesheets/barcodes.css.scss create mode 100644 app/views/events/_event_details.html.erb create mode 100644 app/views/registrations/show.html.erb create mode 100644 db/migrate/20221009173017_add_token_to_registration.rb diff --git a/app/actions/generate_html_barcodes.rb b/app/actions/generate_html_barcodes.rb new file mode 100644 index 00000000..4c0e5f13 --- /dev/null +++ b/app/actions/generate_html_barcodes.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'barby/barcode/ean_13' +require 'barby/outputter/html_outputter' + +class GenerateHtmlBarcodes + def initialize(barcode_data) + @barcode_data = barcode_data + end + + def call + barcode = Barby::EAN13.new(@barcode_data) + + html_outputter = Barby::HtmlOutputter.new(barcode) + html_outputter.to_html.html_safe # rubocop:disable Rails/OutputSafety + end +end diff --git a/app/assets/stylesheets/barcodes.css.scss b/app/assets/stylesheets/barcodes.css.scss new file mode 100644 index 00000000..1988ddbb --- /dev/null +++ b/app/assets/stylesheets/barcodes.css.scss @@ -0,0 +1,4 @@ +table.barby-barcode { border-spacing: 0; } +tr.barby-row {} +td.barby-cell { width: 3px; height: 70px; } +td.barby-cell.on { background: #000; } diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 82f41e8b..a4a2f2d2 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class RegistrationsController < ApplicationController - before_action :authenticate_user!, only: [:index, :destroy, :resend, :update, :email, :upload] + before_action :authenticate_user!, except: [:new, :create, :show] require 'csv' @@ -47,12 +47,21 @@ def create @registration.deliver flash[:success] = "Registration successful. Please check your mailbox for your ticket or further payment information." - respond_with @event + + redirect_to event_registration_path(@registration.event, @registration.token) else render "events/show" end end + def show + @registration = Registration.find_by(token: params[:token]) + return head(:not_found) unless @registration + + @event = @registration.event + @barcode = GenerateHtmlBarcodes.new(@registration.barcode_data).call + end + def update @registration = Registration.find params.require(:id) authorize! :update, @registration diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b9dd9933..61cd505c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -10,8 +10,12 @@ def datepicker_time(field) field.try { |d| d.strftime("%Y-%m-%d %H:%M") } end + def nice_amount(float) + number_with_precision float, precision: 2 + end + def euro(float) - "€#{number_with_precision float, precision: 2}" + number_to_currency(float, unit: '€') end # Form helpers diff --git a/app/models/registration.rb b/app/models/registration.rb index d9400908..3bb650be 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -26,6 +26,8 @@ class Registration < ApplicationRecord record.payment_code = Registration.create_payment_code if record.payment_code.nil? end + before_save :ensure_token + after_save do |record| if !record.access_level.capacity.nil? && (record.access_level.registrations.count > record.access_level.capacity) record.errors.add :access_level, "type is sold out." @@ -95,6 +97,10 @@ def deliver end end + def ensure_token + self.token ||= SecureRandom.uuid + end + private def from_cents(value) @@ -122,6 +128,7 @@ def to_cents(value) # payment_code :string(255) # price :integer # student_number :string(255) +# token :string(255) not null # created_at :datetime # updated_at :datetime # access_level_id :integer not null @@ -132,6 +139,7 @@ def to_cents(value) # index_registrations_on_access_level_id (access_level_id) # index_registrations_on_event_id (event_id) # index_registrations_on_payment_code (payment_code) UNIQUE +# index_registrations_on_token (token) # # Foreign Keys # diff --git a/app/views/access_levels/_access_level.html.erb b/app/views/access_levels/_access_level.html.erb index 6644261c..3a808e95 100644 --- a/app/views/access_levels/_access_level.html.erb +++ b/app/views/access_levels/_access_level.html.erb @@ -4,7 +4,7 @@ <%= access_level.registrations.size %> (<%= access_level.registrations.paid.size %>) / <%= access_level.capacity.presence || "∞".html_safe %> <%= "#{pluralize(access_level.tickets_left, "ticket")} left" if access_level.capacity.presence %> - € <%= number_with_precision access_level.price || "0", precision: 2 %> + €<%= nice_amount(access_level.price || "0") %> <%= translate access_level.permit %> <%= access_level.has_comment ? 'Yes' : 'No' %> <%= access_level.hidden ? 'Yes' : 'No' %> diff --git a/app/views/access_levels/_form.html.erb b/app/views/access_levels/_form.html.erb index 0c3888f2..ff826e1a 100644 --- a/app/views/access_levels/_form.html.erb +++ b/app/views/access_levels/_form.html.erb @@ -2,7 +2,7 @@ <%= form_for [object.event, object], remote: true do |f| %> <%= f.text_field :name, class: 'form-control' %> <%= f.number_field :capacity, class: 'form-control', placeholder: 0 %> - <%= f.text_field :price, value: number_with_precision(f.object.price, precision: 2), class: 'form-control', placeholder: "0.00" %> + <%= f.text_field :price, value: nice_amount(f.object.price), class: 'form-control', placeholder: "0.00" %> <%= f.collection_select :permit, AccessLevel.permits.keys, :itself, lambda {|k| translate(k)}, {}, class: 'form-control' %> diff --git a/app/views/events/_event_details.html.erb b/app/views/events/_event_details.html.erb new file mode 100644 index 00000000..db88af59 --- /dev/null +++ b/app/views/events/_event_details.html.erb @@ -0,0 +1,45 @@ +

Description

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Organisation<%= event.club.name %>
Location<%= event.location %>
Start date<%= nice_time event.start_date %>
End date<%= nice_time event.end_date %>
+ <%= event.description.html_safe %> +
Website<%= link_to event.website, event.website %>
Contact e-mail<%= mail_to event.contact_email, event.contact_email %>
+ +<% unless event.access_levels.blank? %> +

Tickets

+
+
+
    + <% event.access_levels.public?.each do |al| %> + <%= render partial: "events/ticket", locals: {al: al} %> + <% end %> +
+
+
+<% end %> diff --git a/app/views/events/show.html.erb b/app/views/events/show.html.erb index e2420c67..9f74d137 100644 --- a/app/views/events/show.html.erb +++ b/app/views/events/show.html.erb @@ -2,51 +2,7 @@
-

Description

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Organisation<%= @event.club.name %>
Location<%= @event.location %>
Start date<%= nice_time @event.start_date %>
End date<%= nice_time @event.end_date %>
- <%= @event.description.html_safe %> -
Website<%= link_to @event.website, @event.website %>
Contact e-mail<%= mail_to @event.contact_email, @event.contact_email %>
- - <% unless @event.access_levels.blank? %> -

Tickets

-
-
-
    - <% @event.access_levels.public?.each do |al| %> - <%= render partial: "events/ticket", locals: {al: al} %> - <% end %> -
-
-
- <% end %> + <%= render partial: 'events/event_details', locals: { event: @event } %>
diff --git a/app/views/registration_mailer/confirm_registration.html.erb b/app/views/registration_mailer/confirm_registration.html.erb index e9741ae3..5276a583 100644 --- a/app/views/registration_mailer/confirm_registration.html.erb +++ b/app/views/registration_mailer/confirm_registration.html.erb @@ -9,7 +9,7 @@

Bedankt voor het bestellen van een ticket voor <%= @registration.event.name %> van <%= @registration.event.club.name %>. Als u zich niet opgegeven hebt voor dit ticket, dan heeft iemand anders uw e-mailadres gebruikt om dit te registreren. Mocht dit het geval zijn, mag u deze e-mail negeren.

-

Om uw ticket te ontvangen via e-mail, schrijft u <%= number_with_precision @registration.to_pay, precision: 2 %> euro over op het rekeningnummer <%= @registration.event.bank_number || "our bank account" %>. Plaats de code "<%= @registration.payment_code %>" in de mededeling van de overschrijving (zonder aanhalingstekens). Als u de code vergeet mee te geven of niet correct vermeldt in de beschrijving, dan kunnen wij uw betaling niet verwerken en zal u uw ticket niet ontvangen. U mag maximaal één code ingeven per overschrijving.

+

Om uw ticket te ontvangen via e-mail, schrijft u <%= nice_amount @registration.to_pay %> euro over op het rekeningnummer <%= @registration.event.bank_number || "our bank account" %>. Plaats de code "<%= @registration.payment_code %>" in de mededeling van de overschrijving (zonder aanhalingstekens). Als u de code vergeet mee te geven of niet correct vermeldt in de beschrijving, dan kunnen wij uw betaling niet verwerken en zal u uw ticket niet ontvangen. U mag maximaal één code ingeven per overschrijving.

Gelieve ten laatste 3 dagen voor het evenement te betalen. Indien dit niet meer lukt, gelieve ons te contacteren via <%= mail_to @registration.event.contact_email, @registration.event.contact_email %> om een andere betalingswijze af te spreken. Eens we uw betaling verwerkt hebben, zal u uw ticket via e-mail ontvangen.

@@ -27,7 +27,7 @@

Thank you for buying a ticket for <%= @registration.event.name %> of <%= @registration.event.club.name %>. If you did not register for this ticket, someone else used your email address to register. If this is the case, please ignore this email.

-

To receive your ticket by mail, please transfer <%= number_with_precision @registration.to_pay, precision: 2 %> euro to <%= @registration.event.bank_number || "our bank account" %>. Place "<%= @registration.payment_code %>" in the description of your transfer (without the quotation marks). If you forget this code or you do not copy it correctly, we cannot process your payment and you will not receive your ticket. You are only allowed to enter one code per transfer.

+

To receive your ticket by mail, please transfer <%= nice_amount @registration.to_pay %> euro to <%= @registration.event.bank_number || "our bank account" %>. Place "<%= @registration.payment_code %>" in the description of your transfer (without the quotation marks). If you forget this code or you do not copy it correctly, we cannot process your payment and you will not receive your ticket. You are only allowed to enter one code per transfer.

Please pay at least 3 days before the event. If this is no longer possible, please contact us via <%= mail_to @registration.event.contact_email, @registration.event.contact_email %> to agree upon a different payment method. You will receive your ticket by mail once we processed your payment.

diff --git a/app/views/registration_mailer/confirm_registration.text.erb b/app/views/registration_mailer/confirm_registration.text.erb index 5d736475..70880f26 100644 --- a/app/views/registration_mailer/confirm_registration.text.erb +++ b/app/views/registration_mailer/confirm_registration.text.erb @@ -4,7 +4,7 @@ Beste <%= @registration.name %>, Bedankt voor het bestellen van een ticket voor <%= @registration.event.name %> van <%= @registration.event.club.name %>. Als u zich niet opgegeven hebt voor dit ticket, dan heeft iemand anders uw e-mailadres gebruikt om dit te registreren. Mocht dit het geval zijn, mag u deze e-mail negeren. -Om uw ticket te ontvangen via e-mail, schrijft u <%= number_with_precision @registration.to_pay, precision: 2 %> euro over op het rekeningnummer <%= @registration.event.bank_number || "our bank account" %>. Plaats de code "<%= @registration.payment_code %>" in de mededeling van de overschrijving (zonder aanhalingstekens). Als u de code vergeet mee te geven of niet correct vermeldt in de beschrijving, dan kunnen wij uw betaling niet verwerken en zal u uw ticket niet ontvangen. U mag maximaal 1 code ingeven per overschrijving. +Om uw ticket te ontvangen via e-mail, schrijft u <%= nice_amount @registration.to_pay %> euro over op het rekeningnummer <%= @registration.event.bank_number || "our bank account" %>. Plaats de code "<%= @registration.payment_code %>" in de mededeling van de overschrijving (zonder aanhalingstekens). Als u de code vergeet mee te geven of niet correct vermeldt in de beschrijving, dan kunnen wij uw betaling niet verwerken en zal u uw ticket niet ontvangen. U mag maximaal 1 code ingeven per overschrijving. Gelieve ten laatste 3 dagen voor het evenement te betalen. Indien dit niet meer lukt, gelieve ons te contacteren via <%= @registration.event.contact_email %> om een andere betalingswijze af te spreken. Eens we uw betaling verwerkt hebben, zal u uw ticket via e-mail ontvangen. @@ -23,7 +23,7 @@ Dear <%= @registration.name %>, Thank you for buying a ticket for <%= @registration.event.name %> of <%= @registration.event.club.name %>. If you did not register for this ticket, someone else used your email address to register. If this is the case, please ignore this email. -To receive your ticket by mail, please transfer <%= number_with_precision @registration.to_pay, precision: 2 %> euro to <%= @registration.event.bank_number || "our bank account" %>. Place "<%= @registration.payment_code %>" in the description of your transfer (without the quotation marks). If you forget this code or you do not copy it correctly, we cannot process your payment and you will not receive your ticket. You are only allowed to enter one code per transfer. +To receive your ticket by mail, please transfer <%= nice_amount @registration.to_pay %> euro to <%= @registration.event.bank_number || "our bank account" %>. Place "<%= @registration.payment_code %>" in the description of your transfer (without the quotation marks). If you forget this code or you do not copy it correctly, we cannot process your payment and you will not receive your ticket. You are only allowed to enter one code per transfer. Please pay at least 3 days before the event. If this is no longer possible, please contact us via <%= @registration.event.contact_email %> to agree upon a different payment method. You will receive your ticket by mail once we processed your payment. diff --git a/app/views/registrations/_registration_payment_form.html.erb b/app/views/registrations/_registration_payment_form.html.erb index 22d0b84b..ab61ab7b 100644 --- a/app/views/registrations/_registration_payment_form.html.erb +++ b/app/views/registrations/_registration_payment_form.html.erb @@ -1,8 +1,8 @@ <%= form_for [registration.event, registration], method: :patch, remote: true, html: { class: 'form-inline' } do |f| %>
-
- <%= f.text_field :to_pay, value: number_with_precision(f.object.to_pay, precision: 2), disabled: true, class: 'disabling registration-paid form-control' %> - <%= f.hidden_field :price, value: number_with_precision(f.object.price, precision: 2), disabled: true, class: 'registration-price' %> +
+ <%= f.text_field :to_pay, value: nice_amount(f.object.to_pay), disabled: true, class: 'disabling registration-paid form-control' %> + <%= f.hidden_field :price, value: nice_amount(f.object.price), disabled: true, class: 'registration-price' %>
<%= check_box_tag 'is_paid', '1', f.object.paid?, class: 'disabling registration-box input-append', disabled: true %>
diff --git a/app/views/registrations/show.html.erb b/app/views/registrations/show.html.erb new file mode 100644 index 00000000..f6ed03f2 --- /dev/null +++ b/app/views/registrations/show.html.erb @@ -0,0 +1,62 @@ +
+
+ <%= render partial: 'events/event_details', locals: { event: @event } %> +

+ <%= link_to "Register another ticket", event_path(@registration.event) %> +

+
+ +
+

Your ticket

+ + + + + + + + + + + + + +
Name<%= @registration.name %>
Email<%= @registration.email %>
Ticket<%= @registration.access_level.name %>
+ + <% if @registration.paid? %> +
+ <%= @barcode %> +
+
+
+ <%= @barcode %> +
+
+ <% else %> +

Payment

+ + + + + + + + + + + + + +
Price<%= euro @registration.access_level.price %>
Already paid- <%= euro @registration.paid %>
Remaining<%= euro @registration.to_pay %>
+ +

+ Om uw ticket te ontvangen via e-mail, schrijft u <%= nice_amount @registration.to_pay %> euro + over op het rekeningnummer <%= @registration.event.bank_number || "our bank account" %>. Plaats de code + "<%= @registration.payment_code %>" in de mededeling van de overschrijving (zonder aanhalingstekens).
+ Als u de + code vergeet mee te geven of niet correct vermeldt in de beschrijving, dan kunnen wij uw betaling niet verwerken + en zal u uw ticket niet ontvangen. U mag maximaal één code ingeven per overschrijving. +

+ <% end %> +
+
diff --git a/config/routes.rb b/config/routes.rb index 59487927..cf950167 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -38,7 +38,8 @@ end end resources :role_names - resources :registrations do + + resources :registrations, except: [:show] do member do get 'resend' get 'info' @@ -49,6 +50,7 @@ post 'email' end end + resources :registrations, only: [:show], param: :token member do get 'statistics' diff --git a/db/migrate/20221009173017_add_token_to_registration.rb b/db/migrate/20221009173017_add_token_to_registration.rb new file mode 100644 index 00000000..d8b0bdfb --- /dev/null +++ b/db/migrate/20221009173017_add_token_to_registration.rb @@ -0,0 +1,17 @@ +class AddTokenToRegistration < ActiveRecord::Migration[6.1] + def up + # To be converted to UUID type when there's support for it in Rails+MySQL + add_column :registrations, :token, :string, null: true + Registration.find_each do |r| + r.update_column(:token, SecureRandom.uuid) + end + change_column_null :registrations, :token, false + + add_index :registrations, :token + end + + def down + remove_index :registrations, :token + remove_column :registrations, :token + end +end diff --git a/db/schema.rb b/db/schema.rb index 5c65dc5b..5b3def57 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.define(version: 2022_10_09_134241) do +ActiveRecord::Schema.define(version: 2022_10_09_173017) do create_table "access_levels", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "name" @@ -142,9 +142,11 @@ t.string "barcode_data" t.string "payment_code" t.integer "access_level_id", null: false + t.string "token", null: false t.index ["access_level_id"], name: "index_registrations_on_access_level_id" t.index ["event_id"], name: "index_registrations_on_event_id" t.index ["payment_code"], name: "index_registrations_on_payment_code", unique: true + t.index ["token"], name: "index_registrations_on_token" end create_table "users", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| diff --git a/test/fixtures/registrations.yml b/test/fixtures/registrations.yml index e3bcb2c5..06195e0f 100644 --- a/test/fixtures/registrations.yml +++ b/test/fixtures/registrations.yml @@ -12,6 +12,7 @@ one: price: 0 payment_code: <%= Registration.create_payment_code %> access_level_id: 1 + token: <%= SecureRandom.uuid %> two: id: 2 @@ -25,6 +26,7 @@ two: price: 10 payment_code: <%= Registration.create_payment_code %> access_level_id: 2 + token: <%= SecureRandom.uuid %> three: id: 3 @@ -38,6 +40,7 @@ three: price: 20 payment_code: GAN7539840256920891 access_level_id: 1 + token: <%= SecureRandom.uuid %> four: id: 4 @@ -51,6 +54,7 @@ four: price: 10 payment_code: <%= Registration.create_payment_code %> access_level_id: 1 + token: <%= SecureRandom.uuid %> <% 9.times do |n| %> capacity_registration_<%= n %>: @@ -64,6 +68,7 @@ capacity_registration_<%= n %>: student_number: <%= 100 + n %> payment_code: <%= Registration.create_payment_code %> access_level_id: <%= 100 + (n % 3) %> + token: <%= SecureRandom.uuid %> <% end %> # == Schema Information @@ -81,6 +86,7 @@ capacity_registration_<%= n %>: # payment_code :string(255) # price :integer # student_number :string(255) +# token :string(255) not null # created_at :datetime # updated_at :datetime # access_level_id :integer not null @@ -91,6 +97,7 @@ capacity_registration_<%= n %>: # index_registrations_on_access_level_id (access_level_id) # index_registrations_on_event_id (event_id) # index_registrations_on_payment_code (payment_code) UNIQUE +# index_registrations_on_token (token) # # Foreign Keys # diff --git a/test/models/registration_test.rb b/test/models/registration_test.rb index 8f123bc7..0adbf851 100644 --- a/test/models/registration_test.rb +++ b/test/models/registration_test.rb @@ -79,6 +79,7 @@ def teardown # payment_code :string(255) # price :integer # student_number :string(255) +# token :string(255) not null # created_at :datetime # updated_at :datetime # access_level_id :integer not null @@ -89,6 +90,7 @@ def teardown # index_registrations_on_access_level_id (access_level_id) # index_registrations_on_event_id (event_id) # index_registrations_on_payment_code (payment_code) UNIQUE +# index_registrations_on_token (token) # # Foreign Keys # From e393438f084c945b8f8dc92ceaed95509b8a4e6c Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Wed, 19 Apr 2023 21:53:33 +0200 Subject: [PATCH 09/10] Add event registration url to email --- app/views/registration_mailer/confirm_registration.html.erb | 4 ++++ config/environments/development.rb | 2 +- config/environments/test.rb | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/views/registration_mailer/confirm_registration.html.erb b/app/views/registration_mailer/confirm_registration.html.erb index 5276a583..158f4737 100644 --- a/app/views/registration_mailer/confirm_registration.html.erb +++ b/app/views/registration_mailer/confirm_registration.html.erb @@ -13,6 +13,8 @@

Gelieve ten laatste 3 dagen voor het evenement te betalen. Indien dit niet meer lukt, gelieve ons te contacteren via <%= mail_to @registration.event.contact_email, @registration.event.contact_email %> om een andere betalingswijze af te spreken. Eens we uw betaling verwerkt hebben, zal u uw ticket via e-mail ontvangen.

+

U kan deze informatie ook altijd herbekijken op deze pagina. +

Mocht er zich eender welk probleem voordoen, kan u ons altijd via e-mail contacteren: <%= mail_to @registration.event.contact_email, @registration.event.contact_email %>

Met vriendelijke groet,
<%= @registration.event.club.name %>

@@ -31,6 +33,8 @@

Please pay at least 3 days before the event. If this is no longer possible, please contact us via <%= mail_to @registration.event.contact_email, @registration.event.contact_email %> to agree upon a different payment method. You will receive your ticket by mail once we processed your payment.

+

You can always view this information on this page. +

If you have any problems, you can contact us via mail: <%= mail_to @registration.event.contact_email, @registration.event.contact_email %>

Kind regards,
<%= @registration.event.club.name %>

diff --git a/config/environments/development.rb b/config/environments/development.rb index 848d5b70..24ffd573 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -36,7 +36,7 @@ config.action_mailer.perform_deliveries = true # Set base URL because emails don't have the Host header context - config.action_mailer.default_url_options = { :host => 'https://localhost:3000' } + config.action_mailer.default_url_options = { :host => 'http://localhost:3000' } # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log diff --git a/config/environments/test.rb b/config/environments/test.rb index 470dee4b..7c87f89d 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -35,6 +35,9 @@ config.action_mailer.perform_caching = false + # Set base URL because emails don't have the Host header context + config.action_mailer.default_url_options = { :host => 'http://example.com' } + # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. From de595f2927442c5683c894e279322cff29599f66 Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Wed, 19 Apr 2023 22:04:04 +0200 Subject: [PATCH 10/10] Rubocop --- app/controllers/registrations_controller.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index a4a2f2d2..c8e7e756 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -20,6 +20,14 @@ def index @registrations = @registrations.paginate(page: params[:page], per_page: 25) end + def show + @registration = Registration.find_by(token: params[:token]) + return head(:not_found) unless @registration + + @event = @registration.event + @barcode = GenerateHtmlBarcodes.new(@registration.barcode_data).call + end + def new @event = Event.find params.require(:event_id) @registration = Registration.new @@ -54,14 +62,6 @@ def create end end - def show - @registration = Registration.find_by(token: params[:token]) - return head(:not_found) unless @registration - - @event = @registration.event - @barcode = GenerateHtmlBarcodes.new(@registration.barcode_data).call - end - def update @registration = Registration.find params.require(:id) authorize! :update, @registration