From cd3445899fafee594b20ebf41f64dd742bd56ad1 Mon Sep 17 00:00:00 2001
From: Neil Drumm <drumm@delocalizedham.com>
Date: Mon, 22 Jul 2024 19:43:33 +0000
Subject: [PATCH] Issue #3301918: Always redirect new accounts to /welcome &
 ensure that page has ToS acceptance

---
 drupalorg/drupalorg.module | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/drupalorg/drupalorg.module b/drupalorg/drupalorg.module
index 4b30e2d1c..88948804b 100644
--- a/drupalorg/drupalorg.module
+++ b/drupalorg/drupalorg.module
@@ -169,7 +169,7 @@ function drupalorg_page_build(&$page) {
     }
   }
 
-  if (user_is_logged_in()) {
+  if (user_is_logged_in() && current_path() !== 'welcome') {
     $account = user_load($GLOBALS['user']->uid);
 
     // Nag about agreeing to ToS.
@@ -3235,7 +3235,7 @@ function drupalorg_form_user_profile_form_alter(&$form, &$form_state) {
 
   // Be welcoming.
   if (isset($form_state['drupalorg_welcome'])) {
-    $to_show = array(
+    $to_show = [
       'field_first_name',
       'field_last_name',
       'field_country',
@@ -3244,12 +3244,13 @@ function drupalorg_form_user_profile_form_alter(&$form, &$form_state) {
       'timezone',
       'field_demographics',
       'field_subscribe_to',
+      'field_terms_of_service',
       'actions',
       // Without these, the user won't be updated.
       'form_build_id',
       'form_token',
       'form_id',
-    );
+    ];
 
     // Hide anything that we haven't said to show.
     foreach (array_diff(element_children($form), $to_show) as $item) {
@@ -3264,16 +3265,17 @@ function drupalorg_form_user_profile_form_alter(&$form, &$form_state) {
       $group->format_settings['formatter'] = 'open';
     }
 
-    $form['#group_children'] = array(
+    $form['#group_children'] = [
       'field_country' => 'group_left',
       'field_first_name' => 'group_left',
       'field_last_name' => 'group_left',
       'field_organizations' => 'group_left',
       'field_demographics' => 'group_left',
+      'field_terms_of_service' => 'group_left',
       'picture' => 'group_right',
       'timezone' => 'group_right',
       'field_subscribe_to' => 'group_right',
-    );
+    ];
 
     // Put picture at the top.
     $form['#pre_render'][] = 'drupalorg_form_user_profile_move_picture';
@@ -7479,6 +7481,16 @@ function drupalorg_user_presave(&$edit, $account) {
   }
 }
 
+/**
+ * Implements hook_user_insert().
+ */
+function drupalorg_user_insert($edit, $account) {
+  // Always redirect new accounts to /welcome.
+  if (isset($edit['openid_connect_client'])) {
+    $_GET['destination'] = 'welcome';
+  }
+}
+
 /**
  * Implements hook_user_update().
  */
-- 
GitLab