Webcal keys not generated for Events Plugin

Environment

Discourse Version: 7eef10c6d7167e700cda4af1a26938891236eb35

Plugin Commit: 48c0dec68294477162626c684474e5505c9c414d

Other Plugins
discourse-calendar

Steps to Reproduce

User settings—Webcal keys—Generate
Nothing happens, error log is generated

Example


private forum

Logs

Message

ActiveRecord::AssociationTypeMismatch (UserApiKeyScope(#70110497121100) expected, got "calendar_events" which is an instance of String(#70110520770020))
app/controllers/application_controller.rb:354:in `block in with_resolved_locale'
app/controllers/application_controller.rb:354:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:68:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:354:in `call'
config/initializers/100-quiet_logger.rb:23:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/enforce_hostname.rb:22:in `call'
lib/middleware/request_tracker.rb:176:in `call'

Backtrace

activerecord (6.0.3.3) lib/active_record/associations/association.rb:283:in `raise_on_type_mismatch!'
activerecord (6.0.3.3) lib/active_record/associations/collection_association.rb:245:in `block in replace'
activerecord (6.0.3.3) lib/active_record/associations/collection_association.rb:245:in `each'
activerecord (6.0.3.3) lib/active_record/associations/collection_association.rb:245:in `replace'
activerecord (6.0.3.3) lib/active_record/associations/collection_association.rb:41:in `writer'
activerecord (6.0.3.3) lib/active_record/associations/builder/association.rb:108:in `scopes='
activemodel (6.0.3.3) lib/active_model/attribute_assignment.rb:50:in `public_send'
activemodel (6.0.3.3) lib/active_model/attribute_assignment.rb:50:in `_assign_attribute'
activemodel (6.0.3.3) lib/active_model/attribute_assignment.rb:43:in `block in _assign_attributes'
activemodel (6.0.3.3) lib/active_model/attribute_assignment.rb:42:in `each'
1 Like

Update: after the recent commit 5db237d by @angus the REQUEST_URI /c/category/subcategory/l/calendar.ics?user_api_key=api_key&client_id=client_id now fails with the following log trace (webcal was syncing successfully before this commit):

Message (5 copies reported)

NoMethodError (undefined method `with_allowed_param_values' for [:get, "list#calendar_ics"]:Array)
app/models/user_api_key_scope.rb:28:in `block in permits?'
app/models/user_api_key_scope.rb:28:in `any?'
app/models/user_api_key_scope.rb:28:in `permits?'
app/models/user_api_key.rb:50:in `block in allow?'
app/models/user_api_key.rb:50:in `allow?'
lib/auth/default_current_user_provider.rb:312:in `lookup_user_api_user_and_update_key'
lib/auth/default_current_user_provider.rb:151:in `current_user'
lib/current_user.rb:36:in `current_user'
app/controllers/application_controller.rb:440:in `guardian'
app/controllers/application_controller.rb:392:in `resolve_safe_mode'
app/controllers/application_controller.rb:405:in `handle_theme'
lib/middleware/omniauth_bypass_middleware.rb:68:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:352:in `call'
config/initializers/100-quiet_logger.rb:23:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/enforce_hostname.rb:22:in `call'
lib/middleware/request_tracker.rb:176:in `call'

Backtrace

app/models/user_api_key_scope.rb:28:in `block in permits?'
app/models/user_api_key_scope.rb:28:in `any?'
app/models/user_api_key_scope.rb:28:in `permits?'
app/models/user_api_key.rb:50:in `block in allow?'
activerecord (6.0.3.3) lib/active_record/relation/delegation.rb:87:in `each'
activerecord (6.0.3.3) lib/active_record/relation/delegation.rb:87:in `each'
activerecord (6.0.3.3) lib/active_record/relation.rb:278:in `any?'
activerecord (6.0.3.3) lib/active_record/relation.rb:278:in `any?'
app/models/user_api_key.rb:50:in `allow?'
lib/auth/default_current_user_provider.rb:312:in `lookup_user_api_user_and_update_key'
1 Like

Assigning myself. I’ll take a look at this.

1 Like

@md-misko
Discourse has now opened up an API to systematically add custom scopes to the user api key.
Doesn’t apply to our case.
This new standard isn’t useful for genrating user api keys.

@md-misko
Thanks for the report. Here’s a PR fixing the issue. Branch webcal-api


If you can confirm, I’ll merge it quickly.

Hm,

- git clone -b webcal-api https://github.com/paviliondev/discourse-events.git

is not working for me

        1: from /var/www/discourse/lib/plugin/instance.rb:417:in `block in notify_after_initialize'
/var/www/discourse/plugins/discourse-events/plugin.rb:190:in `block in activate!': uninitialized constant #<Class:0x000055759d2ba968>::SCOPES
Did you mean?  Sprockets (NameError)

** INCOMPATIBLE PLUGIN **

You are unable to build Discourse due to errors in the plugin at
/var/www/discourse/plugins/discourse-events

Please try removing this plugin and rebuilding again!
1 Like

Are you sure you’re on latest tests-passed of discourse?

Absolutely sure, the master branch of the plugin builds successfully, only your branch reports an error.

My bad, I wasn’t on the latest. I’ll push an update quickly.

1 Like

@md-misko
There’s a big change in discourse which affects how the user api keys and generated and used. I’m still looking at this.

p.s.

I’ve pushed the changes to the webcal-api branch. Just make sure to generate a new api key. Previous user api keys won’t work.

@angus
Requested your review on this PR. You can ignore the code formatting. I’ll run rubocop and prettier through out the plugin in the next PR.

Done. There are no more errors in the log, webcal link successfully downloads the .ics file.

1 Like

Is this ready for merge?

1 Like

@fzngagan @angus can you please give an ETA for this fix.

1 Like

@md-misko
Ok, its.merged now. Do get back if any issues remain. Thanks for the nudge.

1 Like

Unfortunately, it seems that the plugin is now in conflict with a recent core change that was implemented since I last tested it two weeks ago, resulting in a blank page and with no errors in the log.

Commenting the plugin and rebuilding fixes the issue (luckily I remembered to upgrade on staging first :wink:).

1 Like

The support period is still on so, I’ll take a look again.

1 Like