Skip to content

Conversation

@lodewiges
Copy link
Contributor

@lodewiges lodewiges commented Oct 14, 2024

required for csvalpha/amber-ui#885, they depend on eachother

fixes #437
fixes #483

Tested it by emulating a calender request event through api

i did not test if requessting a no existing category does something but that should work

Summary by CodeRabbit

Release Notes

  • New Features

    • Users can now customize which activity categories appear in their calendar exports. Selected preferences are automatically saved to their profile for future use.
  • Changes

    • Activity categories have been reorganized and streamlined for improved clarity and navigation.

@lodewiges lodewiges linked an issue Oct 14, 2024 that may be closed by this pull request
@lodewiges lodewiges marked this pull request as draft October 14, 2024 17:25
@lodewiges lodewiges self-assigned this Oct 14, 2024
@codecov
Copy link

codecov bot commented Nov 13, 2024

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.92%. Comparing base (8743725) to head (c5f7228).
⚠️ Report is 1 commits behind head on staging.

Additional details and impacted files
@@           Coverage Diff            @@
##           staging     #438   +/-   ##
========================================
  Coverage    99.92%   99.92%           
========================================
  Files          197      197           
  Lines         2658     2665    +7     
========================================
+ Hits          2656     2663    +7     
  Misses           2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lodewiges lodewiges changed the title changed name dinsdag kring and remove woensdag kring Changed name dinsdag kring and remove woensdag kring Nov 13, 2024
@lodewiges
Copy link
Contributor Author

This PR will need to be merged at the same time the accompanying pr on amber/ui is getting merged. I could also be writen in such a way that there is no need for this however this requires 2 PR and manual changing all activities instead of using a migration

@DrumsnChocolate
Copy link
Contributor

DrumsnChocolate commented Nov 21, 2024

I think you need to write csvalpha/amber-ui#876 rather than https://github.com/csvalpha/amber-ui/#876

but on top of that, you probably meant csvalpha/amber-ui#885 instead.

merging this PR has a high risk off breaking all icalender links

That sounds like a not so amazing outcome if that happens. I have not taken the time to determine how the ical links work, so I will postpone reviewing this PR until I have the time and energy to figure that out

@lodewiges
Copy link
Contributor Author

lodewiges commented Nov 21, 2024

I think you need to write csvalpha/amber-ui#876 rather than https://github.com/csvalpha/amber-ui/#876

but on top of that, you probably meant csvalpha/amber-ui#885 instead.

merging this PR has a high risk off breaking all icalender links

That sounds like a not so amazing outcome if that happens. I have not taken the time to determine how the ical links work, so I will postpone reviewing this PR until I have the time and energy to figure that out

https://csvalpha.nl/ical/activities?key=privatestuff&user_id=1&categories=algemeen,societeit,vorming,dinsdagkring,woensdagkring,choose,ifes,ozon,disputen,kiemgroepen,huizen,extern,eerstejaars,curiositates

This is an example link from icalender feature on the site you can see the "dinsdagkring,woensdagkring" part of the link, this will be replaced by "kring" with this PR. This is because the names in the link correspond with the names your able to select. This is why most likely all links are going to break.

I personally think that we should notify all members in advance and update it.

@lodewiges
Copy link
Contributor Author

I think you need to write csvalpha/amber-ui#876 rather than https://github.com/csvalpha/amber-ui/#876

but on top of that, you probably meant csvalpha/amber-ui#885 instead.

merging this PR has a high risk off breaking all icalender links

That sounds like a not so amazing outcome if that happens. I have not taken the time to determine how the ical links work, so I will postpone reviewing this PR until I have the time and energy to figure that out

bump?

@lodewiges
Copy link
Contributor Author

okay, so i did some more research this will not break all links, if people dont update the link. the only affect is that kring doesnt showup anymore

@DrumsnChocolate
Copy link
Contributor

DrumsnChocolate commented Jan 19, 2025

I personally think that we should notify all members in advance and update it.

I agree.

okay, so i did some more research this will not break all links, if people dont update the link. the only affect is that kring doesnt showup anymore

That's good to hear. But it's still important to notify people.

This whole thing makes me wonder: is there an easy way to prevent people from having to update their ical links everytime we change a category? Ideally, we would have a situation where we give the user a single link, https://csvalpha.nl/ical/activities?key=privatestuff&user_id=1
And then based on user_id we identify the user and then simply query their calendar settings from our database. We would need to add a place to store this information, but I think it would be much neater since we would never have to ask a user to update their ical links again!

@DrumsnChocolate
Copy link
Contributor

we would never have to ask a user to update their ical links again!

In fact, we would even be able to leave the current ical links as they are; simply ignore the categories parameter and only use the user_id

@lodewiges
Copy link
Contributor Author

you are correct it would be the best option, i think we should made a issue so we can do this in the future

@DrumsnChocolate
Copy link
Contributor

you are correct it would be the best option, i think we should made a issue so we can do this in the future

made one: #483

@lodewiges
Copy link
Contributor Author

lodewiges commented Feb 20, 2025

I will implement those changes in this PR, this makes sure no links break

TO DO

  • validation in ical model

@lodewiges
Copy link
Contributor Author

lodewiges commented Feb 24, 2025

i started adding #483 into this PR, I am however getting some difficulties be cause the categories that the users has selected are not stored on the server as far as I know
*edit, we could probably make a system that adds the category automatically from the URL requested so it is backwards compatible

@lodewiges
Copy link
Contributor Author

THis has more prio

@coderabbitai
Copy link

coderabbitai bot commented Nov 3, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The PR introduces persistent iCal category preferences by adding an ical_categories column to users, updating the activities controller to derive permitted categories from stored user preferences with fallback logic, and consolidating activity categories (dinsdagkring/woensdagkring → kring; kiemgroepen/curiositates → algemeen).

Changes

Cohort / File(s) Summary
Database Schema & Migration
db/schema.rb, db/migrate/20251103104056_simplyfing_calender_options.rb
Added ical_categories column (string array, default []) to users table. Migration maps existing Activity categories: dinsdagkring/woensdagkring → kring; kiemgroepen/curiositates → algemeen. Reversion only handles kring mapping.
Activity Model & Categories
app/models/activity.rb, spec/factories/activities.rb, spec/models/activity_spec.rb
Consolidated Activity.categories from dinsdagkring, woensdagkring, kiemgroepen, curiositates to streamlined set including kring and genootschapen. Updated factory and spec tests accordingly.
iCal Controller Logic
app/controllers/v1/activities_controller.rb
Rewrote ical action to derive permitted categories from @user.ical_categories when available, with first-use persistence storing intersection of requested and available categories. Fallback to all Activity.categories if computed set is empty. Added rubocop complexity disables.
User Controller & Resource
app/controllers/v1/users_controller.rb, app/resources/v1/user_resource.rb, spec/resources/v1/user_resource_spec.rb
Added ical_categories to excluded display properties, user resource attributes, fetchable fields (when current user), and creatable fields (when current user). Updated resource specs to validate new field exposure.

Sequence Diagram

sequenceDiagram
    participant Client
    participant ActivityController
    participant User
    participant Database
    
    Client->>ActivityController: GET /ical?categories=kring,agora&key=...&user_id=X
    ActivityController->>Database: Fetch User by ID
    Database-->>ActivityController: User data
    
    alt User has stored ical_categories
        ActivityController->>ActivityController: Use `@user.ical_categories`
    else First time or empty stored categories
        ActivityController->>ActivityController: permitted = requested ∩ Activity.categories
        alt permitted set not empty
            ActivityController->>Database: Store permitted to user.ical_categories
            Database-->>ActivityController: Saved
        else permitted set empty
            ActivityController->>ActivityController: permitted = Activity.categories (fallback)
        end
    end
    
    ActivityController->>Database: Fetch Activities filtered by permitted categories
    Database-->>ActivityController: Activities
    ActivityController-->>Client: iCal feed
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Activities controller ical action: Multi-variable flow with store-on-first-use, fallback logic, and increased complexity (requires careful reasoning about preference persistence and category intersection semantics)
  • Database migration: Category remapping logic for forward/backward compatibility (kring reversion implemented; algemeen reversion incomplete by design)
  • User resource changes: New attribute exposure requires verification across fetchable/creatable contexts

Possibly related PRs

  • Changed name dinsdag kring and remove woensdag kring #438: Makes identical code-level changes including adding ical_categories column, updating activities_controller with stored preference derivation and fallbacks, and consolidating Activity.categories (dinsdagkring/woensdagkring → kring; kiemgroepen/curiositates → algemeen).

Suggested reviewers

  • ToMaarton
  • DrumsnChocolate

Poem

🐰 Whiskers twitching with glee:
Calendar choices now persist with grace,
No more links to chase!
Kring and agora find their space,
User preferences, forever in place. ✨📅

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description lacks required sections (checklist items, detailed summary) and missing critical information about database migration testing and deployment notes. Complete the checklist by confirming database migrations are merged and tested from staging. Add detailed summary explaining the category consolidation, backward-compatibility approach, and mention the dependency on amber-ui PR #885. Include deployment considerations for iCal link handling.
Out of Scope Changes check ❓ Inconclusive Changes to Activity.categories, user resource fields, and migrations are all within scope of the category consolidation objective, though a TODO item about converting 'curiositas' and 'kiemgroep' to 'algemeen' remains incomplete. Clarify whether the incomplete TODO (converting curiositas/kiemgroep to algemeen) should be completed in this PR or deferred to a separate issue to ensure scope is fully defined.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main changes: renaming 'dinsdag kring' and removing 'woensdag kring', matching the objective to consolidate kring categories.
Linked Issues check ✅ Passed The PR consolidates 'dinsdag kring' and 'woensdag kring' into a single 'kring' category, directly addressing issue #437's requirement to simplify agenda category options.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3d557c7 and c5f7228.

📒 Files selected for processing (7)
  • app/controllers/v1/activities_controller.rb (1 hunks)
  • app/controllers/v1/users_controller.rb (1 hunks)
  • app/resources/v1/user_resource.rb (3 hunks)
  • db/migrate/20251103104056_simplyfing_calender_options.rb (1 hunks)
  • db/schema.rb (2 hunks)
  • spec/models/activity_spec.rb (1 hunks)
  • spec/resources/v1/user_resource_spec.rb (3 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@lodewiges lodewiges marked this pull request as ready for review November 3, 2025 20:43
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fad27de and 9b1f834.

📒 Files selected for processing (8)
  • app/controllers/v1/activities_controller.rb (1 hunks)
  • app/controllers/v1/users_controller.rb (1 hunks)
  • app/models/activity.rb (1 hunks)
  • app/resources/v1/user_resource.rb (3 hunks)
  • db/migrate/20241113104056_simplyfing_calender_options.rb (1 hunks)
  • db/schema.rb (1 hunks)
  • spec/factories/activities.rb (1 hunks)
  • spec/models/activity_spec.rb (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
app/resources/v1/user_resource.rb (1)
app/policies/user_policy.rb (1)
  • me? (58-60)
🪛 GitHub Actions: Continuous Integration
app/resources/v1/user_resource.rb

[error] 8-8: SyntaxError: unexpected ',', likely missing a trailing comma on the previous line in attributes list (V1::UserResource).

🔇 Additional comments (6)
app/models/activity.rb (1)

36-39: LGTM: Category consolidation implemented correctly.

The streamlined category list properly replaces the separate "dinsdagkring" and "woensdagkring" entries with a single "kring" category, aligning with the PR objectives and migration logic.

db/schema.rb (1)

563-563: LGTM: Schema change reflects migration correctly.

The new ical_categories column is properly defined as a string array with an appropriate default value.

app/controllers/v1/users_controller.rb (1)

109-113: LGTM: Properly excludes ical_categories from batch import responses.

Adding ical_categories to the exclusion list is consistent with the existing pattern for user-specific configuration fields.

spec/factories/activities.rb (1)

12-15: LGTM: Test factory updated to match new categories.

The factory correctly reflects the streamlined category list from the Activity model.

spec/models/activity_spec.rb (1)

179-187: LGTM: Test data updated for new category set.

The test correctly uses the streamlined category list, ensuring proper coverage of the humanized_category method.

app/resources/v1/user_resource.rb (1)

78-84: Verify: Should ical_secret_key be user-creatable?

Adding ical_secret_key to creatable_fields allows users to set their own iCal secret keys. Typically, secret keys should be auto-generated by the system for security reasons to ensure sufficient entropy and uniqueness.

Please verify this is the intended behavior. If users need to regenerate their keys, consider providing a separate "regenerate" endpoint instead of allowing arbitrary values.

If this was added unintentionally, apply this diff:

     if me?(context)
       attributes += %i[otp_required password
                        user_details_sharing_preference allow_sofia_sharing
                        picture_publication_preference info_in_almanak
-                       ifes_data_sharing_preference ical_secret_key sidekiq_access 
+                       ifes_data_sharing_preference sidekiq_access
                        setup_complete]
     end

@@ -0,0 +1,19 @@
class SimplyfingCalenderOptions < ActiveRecord::Migration[7.0]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix typos in migration class name.

The class name contains typos: "Simplyfing" should be "Simplifying" and "Calender" should be "Calendar".

Apply this diff:

-class SimplyfingCalenderOptions < ActiveRecord::Migration[7.0]
+class SimplifyingCalendarOptions < ActiveRecord::Migration[7.0]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
class SimplyfingCalenderOptions < ActiveRecord::Migration[7.0]
class SimplifyingCalendarOptions < ActiveRecord::Migration[7.0]
🤖 Prompt for AI Agents
In db/migrate/20241113104056_simplyfing_calender_options.rb around line 1, the
migration class name contains typos ("Simplyfing" -> "Simplifying" and
"Calender" -> "Calendar"); rename the class to match Rails migration naming
conventions (class SimplifyingCalendarOptions < ActiveRecord::Migration[7.0])
and update the filename if you want it to reflect the corrected class name, then
run rails db:migrate:status or the test suite to ensure the migration loads with
the corrected class name.

Comment on lines 4 to 10
Activity.where(category: 'dinsdagkring').find_each do |activity|
activity.update(category: 'kring')
end

Activity.where(category: 'woensdagkring').find_each do |activity|
activity.update(category: 'kring')
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Use update_all for better performance and avoid validation issues.

Using .update in migrations has several drawbacks:

  • Triggers validations and callbacks, which can fail unexpectedly during migration
  • Significantly slower for large datasets due to individual updates
  • Can cause issues if model validations change over time

Apply this diff to use update_all instead:

-    Activity.where(category: 'dinsdagkring').find_each do |activity|
-      activity.update(category: 'kring')
-    end
-
-    Activity.where(category: 'woensdagkring').find_each do |activity|
-      activity.update(category: 'kring')
-    end
+    Activity.where(category: 'dinsdagkring').update_all(category: 'kring')
+    Activity.where(category: 'woensdagkring').update_all(category: 'kring')
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Activity.where(category: 'dinsdagkring').find_each do |activity|
activity.update(category: 'kring')
end
Activity.where(category: 'woensdagkring').find_each do |activity|
activity.update(category: 'kring')
end
Activity.where(category: 'dinsdagkring').update_all(category: 'kring')
Activity.where(category: 'woensdagkring').update_all(category: 'kring')
🤖 Prompt for AI Agents
In db/migrate/20241113104056_simplyfing_calender_options.rb around lines 4 to
10, the migration uses Activity.find_each with activity.update which triggers
validations/callbacks and is slow; replace those per-record updates with a
single relation-level update_all call (e.g., Activity.where(category:
'dinsdagkring').update_all(category: 'kring') and similarly for 'woensdagkring')
so the change runs in a single SQL UPDATE and bypasses model
validations/callbacks.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
app/resources/v1/user_resource.rb (2)

54-54: Remove extra blank line.

This blank line was flagged in the previous review and should be removed for consistency.

Apply this diff:

-    
     allowed_keys += %i[ical_secret_key ical_categories] if me?

60-60: Remove duplicate ical_secret_key.

The previous review flagged that :ical_secret_key is added to allowed_keys on line 55 when me? is true, and again here in the update_or_me? block. Since me? is a subset of update_or_me? (line 153 confirms this), this creates redundant entries.

Apply this diff:

       allowed_keys += %i[login_enabled otp_required activated_at emergency_contact
                          emergency_number ifes_data_sharing_preference info_in_almanak
                          almanak_subscription_preference digtus_subscription_preference
-                         user_details_sharing_preference allow_sofia_sharing ical_secret_key
+                         user_details_sharing_preference allow_sofia_sharing
                          sidekiq_access setup_complete]
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b1f834 and f779643.

📒 Files selected for processing (2)
  • app/resources/v1/user_resource.rb (3 hunks)
  • db/schema.rb (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • db/schema.rb
🧰 Additional context used
🧬 Code graph analysis (1)
app/resources/v1/user_resource.rb (1)
app/policies/user_policy.rb (1)
  • me? (58-60)
🪛 GitHub Check: Lint
app/resources/v1/user_resource.rb

[failure] 82-82:
[Correctable] Layout/TrailingWhitespace: Trailing whitespace detected. (https://rubystyle.guide#no-trailing-whitespace)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test
🔇 Additional comments (2)
app/resources/v1/user_resource.rb (2)

7-7: Syntax error fixed - comma now present.

The missing comma after :ical_categories that was flagged in the previous review has been corrected.


55-55: LGTM - ical_categories correctly exposed for own data.

The addition of :ical_categories alongside :ical_secret_key when me? is true properly exposes the new calendar categories field when users view their own data.

@csvalpha csvalpha deleted a comment from coderabbitai bot Nov 3, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/controllers/v1/activities_controller.rb (1)

43-43: Inconsistent behavior: birthdays uses URL parameters while activities use stored preferences.

Line 43 calls ical_add_birthdays?(requested_categories), which checks the URL parameter, while activity categories use stored_categories (line 35). This creates inconsistent behavior:

Example:

  • User has stored categories: ["kring", "algemeen"]
  • User changes URL to: ?categories=societeit (without "birthdays")
  • Result: Gets kring + algemeen activities (from stored), but birthdays inclusion changes based on URL

For consistency, birthdays should also use stored preferences, or both should respect URL parameters.

Option 1: Store birthdays preference with categories

# In the storage logic
if stored_categories.empty? && requested_categories.present?
  # Store whether birthdays was included
  @user.update(
    ical_categories: requested_categories & Activity.categories,
    ical_include_birthdays: requested_categories.include?('birthdays')
  )
end

# Later
if @user.ical_include_birthdays
  # add birthdays
end

Option 2: Always respect URL parameters for both

if requested_categories.present?
  permitted_categories = requested_categories & Activity.categories
else
  permitted_categories = @user.ical_categories & Activity.categories
end

# birthdays also respects URL or stored
if ical_add_birthdays?(requested_categories || @user.ical_categories)
  # add birthdays
end
🧹 Nitpick comments (1)
app/controllers/v1/activities_controller.rb (1)

25-25: Remove extra blank lines for consistency.

Lines 25 and 38 have extra blank lines that don't add to readability.

Apply this diff:

     stored_categories = @user.ical_categories
-    
     requested_categories = params[:categories]&.split(',')
     permitted_categories = Activity.categories if permitted_categories.empty?
-                
     activities_for_ical(permitted_categories).each do |act|

Also applies to: 38-38

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9405292 and 3d557c7.

📒 Files selected for processing (2)
  • app/controllers/v1/activities_controller.rb (1 hunks)
  • app/resources/v1/user_resource.rb (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
app/resources/v1/user_resource.rb (1)
app/policies/user_policy.rb (1)
  • me? (58-60)
app/controllers/v1/activities_controller.rb (1)
app/models/activity.rb (1)
  • categories (36-39)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test
  • GitHub Check: Lint
🔇 Additional comments (1)
app/resources/v1/user_resource.rb (1)

7-7: No action required—ical_categories is properly updatable.

The parent class ApplicationResource defines updatable_fields(context) to return creatable_fields(context). Since ical_categories is included in creatable_fields when me?(context), it is automatically updatable. The codebase confirms this pattern is working: app/controllers/v1/activities_controller.rb line 32 actively updates the field with @user.update(ical_categories: ...).

@lodewiges lodewiges merged commit 812e276 into staging Nov 10, 2025
1 of 2 checks passed
@lodewiges lodewiges deleted the feature/agenda-clean branch November 10, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create database model for calendar selection cleaning up alpha agenda options

3 participants