Skip to content

Commit 812e276

Browse files
authored
Changed name dinsdag kring and remove woensdag kring (#438)
* changed name dinsdag kring and remove woensdag kring * fixed lint * Made migration * added quickpost to schema.rb * Fixed Lint * Rewrote migration * Trying to store catogories on the users table * add genootschapen * fix comma missing * fix so small inconsisties * Write logic to automatilly store categories requested * fix test & lint * rewrote migration * fix lint
1 parent 8743725 commit 812e276

File tree

9 files changed

+52
-18
lines changed

9 files changed

+52
-18
lines changed

app/controllers/v1/activities_controller.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,25 @@ def generate_alias
1818
render json: alias_response("#{mail_alias}@csvalpha.nl")
1919
end
2020

21-
def ical # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
21+
def ical # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
2222
return head :unauthorized unless authenticate_user_by_ical_secret_key
2323

24-
requested_categories = params[:categories].try(:split, ',')
24+
stored_categories = @user.ical_categories
25+
26+
requested_categories = params[:categories]&.split(',')
27+
28+
permitted_categories = []
29+
30+
if stored_categories.empty? && requested_categories.present?
31+
# this logic is only to store preferences on first use. this makes it so the end user doesn't notice the change
32+
new_categories_to_store = requested_categories & Activity.categories
33+
@user.update(ical_categories: new_categories_to_store)
34+
permitted_categories = new_categories_to_store
35+
else
36+
permitted_categories = stored_categories & Activity.categories
37+
end
38+
permitted_categories = Activity.categories if permitted_categories.empty?
2539

26-
permitted_categories = (requested_categories & Activity.categories) ||
27-
Activity.categories
2840
activities_for_ical(permitted_categories).each do |act|
2941
calendar.add_event(act.to_ical)
3042
end

app/controllers/v1/users_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def context
110110
def excluded_display_properties
111111
%i[created_at updated_at deleted_at activated_at archived_at password_digest activation_token
112112
avatar activation_token_valid_till setup_complete otp_secret_key otp_required
113-
ical_secret_key id]
113+
ical_secret_key ical_categories id]
114114
end
115115

116116
def otp_already_required_error

app/models/activity.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class Activity < ApplicationRecord
3434
after_save :copy_author_and_group_to_form!
3535

3636
def self.categories
37-
%w[algemeen societeit vorming dinsdagkring woensdagkring
38-
choose ifes ozon disputen kiemgroepen huizen extern eerstejaars curiositates]
37+
%w[algemeen societeit vorming kring
38+
choose ifes ozon disputen genootschapen huizen extern eerstejaars]
3939
end
4040

4141
def full_day?

app/resources/v1/user_resource.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class V1::UserResource < V1::ApplicationResource # rubocop:disable Metrics/Class
44
:ifes_data_sharing_preference, :info_in_almanak, :almanak_subscription_preference,
55
:digtus_subscription_preference, :email, :birthday, :address, :postcode, :city,
66
:phone_number, :food_preferences, :vegetarian, :study, :start_study,
7-
:picture_publication_preference, :ical_secret_key,
7+
:picture_publication_preference, :ical_secret_key, :ical_categories,
88
:password, :avatar, :avatar_url, :avatar_thumb_url,
99
:user_details_sharing_preference, :allow_sofia_sharing, :trailer_drivers_license,
1010
:sidekiq_access, :setup_complete
@@ -51,7 +51,8 @@ def fetchable_fields
5151
# Relationships
5252
allowed_keys += %i[groups active_groups memberships mail_aliases mandates
5353
group_mail_aliases permissions photos user_permissions]
54-
allowed_keys += %i[ical_secret_key] if me?
54+
# Ical fields
55+
allowed_keys += %i[ical_secret_key ical_categories] if me?
5556
if update_or_me?
5657
allowed_keys += %i[login_enabled otp_required activated_at emergency_contact
5758
emergency_number ifes_data_sharing_preference info_in_almanak
@@ -78,7 +79,8 @@ def self.creatable_fields(context) # rubocop:disable Metrics/MethodLength
7879
attributes += %i[otp_required password
7980
user_details_sharing_preference allow_sofia_sharing
8081
picture_publication_preference info_in_almanak
81-
ifes_data_sharing_preference sidekiq_access setup_complete]
82+
ifes_data_sharing_preference ical_categories sidekiq_access
83+
setup_complete]
8284
end
8385

8486
if user_can_create_or_update?(context)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class SimplyfingCalenderOptions < ActiveRecord::Migration[7.2]
2+
# rubocop:disable Rails/SkipsModelValidations
3+
def up
4+
add_column :users, :ical_categories, :string, array: true, default: []
5+
Activity.where(category: 'dinsdagkring').update_all(category: 'kring')
6+
Activity.where(category: 'woensdagkring').update_all(category: 'kring')
7+
Activity.where(category: 'kiemgroepen').update_all(category: 'algemeen')
8+
Activity.where(category: 'curiositates').update_all(category: 'algemeen')
9+
end
10+
11+
def down
12+
remove_column :users, :ical_categories
13+
Activity.where(category: 'kring').update_all(category: 'dinsdagkring')
14+
# NOTE: As mentioned before, reverting 'algemeen' to 'kiemgroepen' or 'curiositates'
15+
# cannot be done reliably with `update_all` without additional information.
16+
# The `down` migration here only addresses the 'kring' category.
17+
end
18+
# rubocop:enable Rails/SkipsModelValidations
19+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

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

@@ -562,6 +562,7 @@
562562
t.string "nickname"
563563
t.boolean "trailer_drivers_license", default: false, null: false
564564
t.boolean "setup_complete", default: false, null: false
565+
t.string "ical_categories", default: [], array: true
565566
t.index ["deleted_at"], name: "index_users_on_deleted_at"
566567
t.index ["email"], name: "index_users_on_email", unique: true
567568
t.index ["login_enabled"], name: "index_users_on_login_enabled"

spec/factories/activities.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
start_time { Faker::Time.between(from: 1.day.ago, to: Time.zone.today) }
1111
end_time { Faker::Time.between(from: 1.day.from_now, to: 2.days.from_now) }
1212
category do
13-
%w[algemeen societeit vorming dinsdagkring woensdagkring
14-
choose ifes ozon disputen kiemgroepen huizen extern eerstejaars curiositates].sample
13+
%w[algemeen societeit vorming kring
14+
choose ifes ozon disputen genootschapen huizen extern eerstejaars].sample
1515
end
1616
publicly_visible { false }
1717

spec/models/activity_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@
179179
context 'when it is another category' do
180180
let(:record) do
181181
build_stubbed(:activity,
182-
category: %w[algemeen sociëteit vorming dinsdagkring woensdagkring
183-
disputen kiemgroepen huizen extern curiositates].sample)
182+
category: %w[algemeen sociëteit vorming kring
183+
disputen genootschapen huizen extern].sample)
184184
end
185185

186186
it { expect(record.humanized_category).to eq record.category.capitalize }

spec/resources/v1/user_resource_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
let(:another_user) { user }
100100
let(:fields) do
101101
basic_fields + update_fields +
102-
read_fields + user_details_fields + %i[ical_secret_key]
102+
read_fields + user_details_fields + %i[ical_secret_key ical_categories]
103103
end
104104

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

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

161161
context 'when with create permisison' do
@@ -170,7 +170,7 @@
170170

171171
it {
172172
expect(creatable_fields).to match_array(basic_fields + permissible_fields +
173-
current_user_fields - [:login_enabled])
173+
current_user_fields - [:login_enabled] + %i[ical_categories])
174174
}
175175
end
176176
end

0 commit comments

Comments
 (0)