$account, ); // Show one form if we're the user who owns this account if ($user->uid == $account->uid) { return ctools_build_form('drupalorg_git_gateway_user_form', $form_state); } // But show an entirely different form if we're another user (an admin). else if (user_access('administer users') || user_access('administer version control systems')) { return ctools_build_form('drupalorg_git_gateway_admin_user_form', $form_state); } else { // Or deny access. return drupal_access_denied(); } } function drupalorg_git_gateway_user_form(&$form_state) { $form = array(); $account = $form_state['account']; $form['#submit'][] = 'drupalorg_git_gateway_user_form_submit'; // Fork off to the confirm form for the username before anything else. if (!empty($form_state['storage']['chosen_username'])) { return drupalorg_git_gateway_confirm_username($form, $form_state, $account); } $form['#validate'] = array('drupalorg_git_gateway_user_form_base_validate'); $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 30); // This is somewhat naughty. $show_messages = empty($form_state['post']); // Warn the user if their account has been suspended. if ($show_messages && !empty($account->git_disabled)) { drupal_set_message(t('Your Git access has been suspended by a Drupal.org administrator. See !handbook for information about reinstating your account.', array('!handbook' => l('the handbook', 'node/1042972'))), 'error'); } // Both 'Git administrator' and 'User administrator' roles get admin powers here. if (user_access('administer users') || user_access('administer version control systems')) { $form['git_administration'] = _drupalorg_git_gateway_user_admin($account); // Tack on the submit handler for the admin portion of the form. array_unshift($form['#submit'], 'drupalorg_git_gateway_admin_user_form_submit'); } // If everything's set in the expected state, change the button text to make // clear what submitting the form does, and show configuration helper text. if (!empty($account->git_consent) && !empty($account->git_username)) { $form['submit']['#value'] = t('Update Git access agreement'); $form['git_config'] = _drupalorg_git_gateway_user_config($account); } if (!isset($account->git_username)) { $form['username'] = _drupalorg_git_gateway_username_set($account); if ($show_messages) { drupal_set_message(t('You will not be able to use Git until you have selected a Git username. A suggestion has been provided for you, based on your username. Note that once chosen, your Git username cannot be changed.'), 'warning'); } } else { $form['username'] = _drupalorg_git_gateway_username_display($account); } $form['git_tos'] = _drupalorg_git_gateway_user_tos($account); if (empty($account->git_consent)) { if ($show_messages) { drupal_set_message(t('You will not be able to use Git unless the checkbox consenting to the terms of service is checked.'), 'warning'); } // If we're just showing the ToS, make the fieldset unhide-able. $form['git_tos']['#collapsible'] = FALSE; $form['git_tos']['#collapsed'] = FALSE; return $form; } return $form; } function drupalorg_git_gateway_admin_user_form(&$form_state) { $form = array(); $account = $form_state['account']; $form['user_info'] = array( '#type' => 'fieldset', '#title' => t("%username's Git information", array('%username' => $account->name)), '#collapsible' => FALSE, '#collapsed' => FALSE, '#weight' => -20, ); if (!empty($account->git_username)) { $form['user_info']['username'] = array( '#type' => 'item', '#title' => t('Git username'), '#disabled' => TRUE, '#value' => $account->git_username, '#weight' => -20, ); } else { $form['user_info']['username'] = array( '#type' => 'item', '#title' => t('Git username'), '#disabled' => TRUE, '#value' => t('(User has not yet chosen a Git username)'), '#weight' => -20, ); } $form['user_info']['consent'] = array( '#type' => 'item', '#title' => t('Git access agreement'), '#value' => empty($account->git_consent) ? t('User has not consented to the Git agreement.') : t('User has consented to the Git agreement.'), ); $form['git_administration'] = _drupalorg_git_gateway_user_admin($account, FALSE); // Attach both the base and admin form submit handlers. $form['#submit'] = array( 'drupalorg_git_gateway_admin_user_form_submit', 'drupalorg_git_gateway_user_form_submit', ); $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 30); return $form; } function _drupalorg_git_gateway_user_tos($account) { $form = array( '#type' => 'fieldset', '#title' => t('Git access agreement'), '#collapsible' => TRUE , '#collapsed' => !empty($account->git_consent), '#weight' => 10, ); $form['terms'] = array( '#type' => 'item', '#title' => t("To use Drupal's version control systems you must agree to the following"), '#value' => theme('item_list', array( t('I will only commit !link code and resources to Drupal code repositories.', array('!link' => l('GPL V2+-licensed', 'licensing/faq', array('alias' => TRUE)))), t('I will only commit code and resources that I own or am permitted to distribute.'), t('I will cooperate with the !link as needed.', array('!link' => l('Drupal Security Team', 'security-team', array('alias' => TRUE)))), t('I have read and will adhere to the !link.', array('!link' => l('Drupal Code of Conduct', 'dcoc', array('alias' => TRUE)))), t('I agree to the !link.', array('!link' => l('Drupal Code Repository Terms of Service', 'node/1001544'))), )), ); $form['git_consent'] = array( '#type' => 'checkbox', '#title' => t('I agree to these terms'), '#default_value' => $account->git_consent, ); global $user; if ($user->uid != $account->uid) { // Even admins should never be able to change the state of whether someone // consented to our terms of service or not. $form['git_consent']['#disabled'] = TRUE; $form['git_consent']['#description'] = t('Only the account owner may opt in or out of the Git access agreement.'); } return $form; } function _drupalorg_git_gateway_username_display($account) { return array( '#type' => 'item', '#title' => t('Your Git username'), '#disabled' => TRUE, '#value' => $account->git_username, '#description' => t('You use this as your SSH username when authenticating with Git to Drupal.org. Drupal.org uses this username to generate your personalized sandbox URIs.'), '#weight' => -20, ); } function _drupalorg_git_gateway_username_set($account) { $form = array( '#type' => 'fieldset', '#title' => t('Git username'), '#collapsible' => FALSE, '#collapsed' => FALSE, '#weight' => -20, ); $form['#description'] = t('Choose a username to use for Git. This will be your SSH user when authenticating to Drupal.org with Git, and Drupal.org will use it to generate your personalized sandbox URIs. Once chosen, your Git username cannot be changed.'); $form['git_username'] = array( '#type' => 'textfield', '#title' => t('Desired Git username'), '#maxlength' => 64, '#default_value' => drupalorg_git_gateway_suggest_git_username($account->name), '#description' => t('Acceptable characters are ANSI alphanumerics (A-Z, a-z, 0-9), periods, underscores, or dashes. A suggested username is provided, based on the acceptable characters in your Drupal username and the availability of Git usernames.'), ); return $form; } function _drupalorg_git_gateway_user_config($account) { $form = array( '#type' => 'fieldset', '#title' => t('Git configuration'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#weight' => 15, ); $user_config = t('You will not be credited in commit statistics or listings unless you set the Git e-mail address to either an !multiemailadmin or the anonymized e-mail provided below. Read !handbook for a full discussion of identifying yourself to Git. We recommend:', (array('!handbook' => l('the handbook', 'node/1042972'), '!multiemailadmin' => l('address associated with your account', "user/$account->uid/edit/email-addresses")))) . "\n"; $git_config_name = empty($account->profile_full_name) ? $account->name : $account->profile_full_name; $user_config .= '
';
$user_config .= "git config --global user.name \"$git_config_name\"
";
$user_config .= "git config --global user.email $account->mail
";
$user_config .= '
git config --global user.email $anon_address