diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index e97ba0ad2..ad1801c78 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -32,7 +32,7 @@ def show end def create_calendar - @member = Member.find(params[:hash]) + @member = Member.find_by(calendar_id: params[:calendar_id]) events = @member.activities.map { |a| IcalendarHelper.activityToEvent(a) } IcalendarHelper.createCalendar(events).to_ical end diff --git a/config/routes.rb b/config/routes.rb index b70013a07..84f88c6c6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do - get 'calendar/:hash', to: 'calendars#show', defaults: { format: 'ics' } + get 'calendar/:calendar_id', to: 'calendars#show', defaults: { format: 'ics' } use_doorkeeper_openid_connect diff --git a/db/migrate/20240521180025_add_calendar_id_to_member.rb b/db/migrate/20240521180025_add_calendar_id_to_member.rb new file mode 100644 index 000000000..da7f4da90 --- /dev/null +++ b/db/migrate/20240521180025_add_calendar_id_to_member.rb @@ -0,0 +1,5 @@ +class AddCalendarIdToMember < ActiveRecord::Migration[6.1] + def change + add_column :members, :calendar_id, :uuid + end +end diff --git a/db/seeds/members.rb b/db/seeds/members.rb index 8b5e3ee0d..9b51941fc 100644 --- a/db/seeds/members.rb +++ b/db/seeds/members.rb @@ -18,7 +18,8 @@ student_id: "F#{ Faker::Number.number(digits: 6) }", birth_date: Faker::Date.between(from: 28.years.ago, to: 16.years.ago), join_date: Faker::Date.between(from: 6.years.ago, to: Date.today), - comments: (Faker::Boolean.boolean(true_ratio: 0.3) ? Faker::Hacker.say_something_smart : nil) + comments: (Faker::Boolean.boolean(true_ratio: 0.3) ? Faker::Hacker.say_something_smart : nil), + calendar_id: Faker::Boolean.boolean(true_ratio: 0.4) ? SecureRandom.uuid : nil ) puts(" -> #{ member.name } (#{ member.student_id })") diff --git a/db/structure.sql b/db/structure.sql index 075e5bfba..1ab61df75 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -550,7 +550,8 @@ CREATE TABLE public.members ( consent integer DEFAULT 0, consent_at date, created_at timestamp without time zone, - updated_at timestamp without time zone + updated_at timestamp without time zone, + calendar_id uuid ); @@ -1736,6 +1737,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220221195220'), ('20220406092056'), ('20220524203723'), -('20240125003700'); +('20240125003700'), +('20240521180025'); diff --git a/lib/icalendar_helper.rb b/lib/icalendar_helper.rb index 1f06e63cf..bc8e152e7 100644 --- a/lib/icalendar_helper.rb +++ b/lib/icalendar_helper.rb @@ -9,7 +9,7 @@ def IcalendarHelper.activityToEvent(activity) event.dtstart = activity.start_date event.dtend = activity.end_date event.summary = activity.name - event.description = activity.description_nl + event.description = activity.description_nl # TODO localise event.location = activity.location return event end