Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add code comments around oauth `user-api-key/new` handling (#31774)

Penar Musaraj897b043f01e9
diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb
index bb19067c5f0..153967451db 100644
--- a/app/controllers/users/omniauth_callbacks_controller.rb
+++ b/app/controllers/users/omniauth_callbacks_controller.rb
@@ -87,6 +87,9 @@ class Users::OmniauthCallbacksController < ApplicationController
cookies["_bypass_cache"] = true
cookies[:authentication_data] = { value: client_hash.to_json, path: Discourse.base_path("/") }
+ # If the user account doesn't already exist, and this signup is part of a user-api-key request, direct
+ # the user to the homepage first so that signup can be completed. They'll be redirected to the user-api-key
+ # route once signup is complete. Hopefully, this can be simplified once fullscreen login/signup is everywhere.
if !current_user && @origin.start_with?("/user-api-key/new")
redirect_to path("/")
else
diff --git a/lib/auth/result.rb b/lib/auth/result.rb
index 9b25181003e..12e0906d5c1 100644
--- a/lib/auth/result.rb
+++ b/lib/auth/result.rb
@@ -124,7 +124,8 @@ class Auth::Result
AssociatedGroup.where(id: associated_group_ids).update_all("last_used = CURRENT_TIMESTAMP")
end
- Group.user_trust_level_change!(user.id, user.trust_level) if user && !user.staged
+ # refreshes automatic group membership (despite the name, it doesn't change TLs)
+ Group.user_trust_level_change!(user.id, user.trust_level) if user
end
def can_edit_name