Skip to content
Merged
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
20 changes: 16 additions & 4 deletions app/controllers/v1/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,25 @@ def generate_alias
render json: alias_response("#{mail_alias}@csvalpha.nl")
end

def ical # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def ical # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
return head :unauthorized unless authenticate_user_by_ical_secret_key

requested_categories = params[:categories].try(:split, ',')
stored_categories = @user.ical_categories

requested_categories = params[:categories]&.split(',')

permitted_categories = []

if stored_categories.empty? && requested_categories.present?
# this logic is only to store preferences on first use. this makes it so the end user doesn't notice the change
new_categories_to_store = requested_categories & Activity.categories
@user.update(ical_categories: new_categories_to_store)
permitted_categories = new_categories_to_store
else
permitted_categories = stored_categories & Activity.categories
end
permitted_categories = Activity.categories if permitted_categories.empty?

permitted_categories = (requested_categories & Activity.categories) ||
Activity.categories
activities_for_ical(permitted_categories).each do |act|
calendar.add_event(act.to_ical)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def context
def excluded_display_properties
%i[created_at updated_at deleted_at activated_at archived_at password_digest activation_token
avatar activation_token_valid_till setup_complete otp_secret_key otp_required
ical_secret_key id]
ical_secret_key ical_categories id]
end

def otp_already_required_error
Expand Down
4 changes: 2 additions & 2 deletions app/models/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class Activity < ApplicationRecord
after_save :copy_author_and_group_to_form!

def self.categories
%w[algemeen societeit vorming dinsdagkring woensdagkring
choose ifes ozon disputen kiemgroepen huizen extern eerstejaars curiositates]
%w[algemeen societeit vorming kring
choose ifes ozon disputen genootschapen huizen extern eerstejaars]
end

def full_day?
Expand Down
8 changes: 5 additions & 3 deletions app/resources/v1/user_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class V1::UserResource < V1::ApplicationResource # rubocop:disable Metrics/Class
:ifes_data_sharing_preference, :info_in_almanak, :almanak_subscription_preference,
:digtus_subscription_preference, :email, :birthday, :address, :postcode, :city,
:phone_number, :food_preferences, :vegetarian, :study, :start_study,
:picture_publication_preference, :ical_secret_key,
:picture_publication_preference, :ical_secret_key, :ical_categories,
:password, :avatar, :avatar_url, :avatar_thumb_url,
:user_details_sharing_preference, :allow_sofia_sharing, :trailer_drivers_license,
:sidekiq_access, :setup_complete
Expand Down Expand Up @@ -51,7 +51,8 @@ def fetchable_fields
# Relationships
allowed_keys += %i[groups active_groups memberships mail_aliases mandates
group_mail_aliases permissions photos user_permissions]
allowed_keys += %i[ical_secret_key] if me?
# Ical fields
allowed_keys += %i[ical_secret_key ical_categories] if me?
if update_or_me?
allowed_keys += %i[login_enabled otp_required activated_at emergency_contact
emergency_number ifes_data_sharing_preference info_in_almanak
Expand All @@ -78,7 +79,8 @@ def self.creatable_fields(context) # rubocop:disable Metrics/MethodLength
attributes += %i[otp_required password
user_details_sharing_preference allow_sofia_sharing
picture_publication_preference info_in_almanak
ifes_data_sharing_preference sidekiq_access setup_complete]
ifes_data_sharing_preference ical_categories sidekiq_access
setup_complete]
end

if user_can_create_or_update?(context)
Expand Down
19 changes: 19 additions & 0 deletions db/migrate/20251103104056_simplyfing_calender_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class SimplyfingCalenderOptions < ActiveRecord::Migration[7.2]
# rubocop:disable Rails/SkipsModelValidations
def up
add_column :users, :ical_categories, :string, array: true, default: []
Activity.where(category: 'dinsdagkring').update_all(category: 'kring')
Activity.where(category: 'woensdagkring').update_all(category: 'kring')
Activity.where(category: 'kiemgroepen').update_all(category: 'algemeen')
Activity.where(category: 'curiositates').update_all(category: 'algemeen')
end

def down
remove_column :users, :ical_categories
Activity.where(category: 'kring').update_all(category: 'dinsdagkring')
# NOTE: As mentioned before, reverting 'algemeen' to 'kiemgroepen' or 'curiositates'
# cannot be done reliably with `update_all` without additional information.
# The `down` migration here only addresses the 'kring' category.
end
# rubocop:enable Rails/SkipsModelValidations
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2025_03_10_235232) do
ActiveRecord::Schema[7.1].define(version: 2025_11_03_104056) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -562,6 +562,7 @@
t.string "nickname"
t.boolean "trailer_drivers_license", default: false, null: false
t.boolean "setup_complete", default: false, null: false
t.string "ical_categories", default: [], array: true
t.index ["deleted_at"], name: "index_users_on_deleted_at"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["login_enabled"], name: "index_users_on_login_enabled"
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/activities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
start_time { Faker::Time.between(from: 1.day.ago, to: Time.zone.today) }
end_time { Faker::Time.between(from: 1.day.from_now, to: 2.days.from_now) }
category do
%w[algemeen societeit vorming dinsdagkring woensdagkring
choose ifes ozon disputen kiemgroepen huizen extern eerstejaars curiositates].sample
%w[algemeen societeit vorming kring
choose ifes ozon disputen genootschapen huizen extern eerstejaars].sample
end
publicly_visible { false }

Expand Down
4 changes: 2 additions & 2 deletions spec/models/activity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@
context 'when it is another category' do
let(:record) do
build_stubbed(:activity,
category: %w[algemeen sociëteit vorming dinsdagkring woensdagkring
disputen kiemgroepen huizen extern curiositates].sample)
category: %w[algemeen sociëteit vorming kring
disputen genootschapen huizen extern].sample)
end

it { expect(record.humanized_category).to eq record.category.capitalize }
Expand Down
6 changes: 3 additions & 3 deletions spec/resources/v1/user_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
let(:another_user) { user }
let(:fields) do
basic_fields + update_fields +
read_fields + user_details_fields + %i[ical_secret_key]
read_fields + user_details_fields + %i[ical_secret_key ical_categories]
end

it { expect(resource.fetchable_fields).to match_array(fields) }
Expand Down Expand Up @@ -155,7 +155,7 @@
context 'when record is current user' do
let(:another_user) { user }

it { expect(creatable_fields).to match_array(basic_fields + current_user_fields) }
it { expect(creatable_fields).to match_array(basic_fields + current_user_fields + %i[ical_categories]) }
end

context 'when with create permisison' do
Expand All @@ -170,7 +170,7 @@

it {
expect(creatable_fields).to match_array(basic_fields + permissible_fields +
current_user_fields - [:login_enabled])
current_user_fields - [:login_enabled] + %i[ical_categories])
}
end
end
Expand Down
Loading