mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-61921 admin: Support XOAUTH2 for outgoing mail
This commit is contained in:
parent
44ca802d4e
commit
bc80531188
6 changed files with 121 additions and 3 deletions
|
@ -442,9 +442,35 @@ if ($hassiteconfig) {
|
|||
'CRAM-MD5' => 'CRAM-MD5',
|
||||
];
|
||||
|
||||
// Get all the issuers.
|
||||
$issuers = \core\oauth2\api::get_all_issuers();
|
||||
$enabledissuers = [];
|
||||
foreach ($issuers as $issuer) {
|
||||
// Get the enabled issuer only.
|
||||
if ($issuer->get('enabled')) {
|
||||
$enabledissuers[] = $issuer;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($enabledissuers) > 0) {
|
||||
$authtypeoptions['XOAUTH2'] = 'XOAUTH2';
|
||||
}
|
||||
|
||||
$temp->add(new admin_setting_configselect('smtpauthtype', new lang_string('smtpauthtype', 'admin'),
|
||||
new lang_string('configsmtpauthtype', 'admin'), 'LOGIN', $authtypeoptions));
|
||||
|
||||
if (count($enabledissuers) > 0) {
|
||||
$oauth2services = [
|
||||
'' => new lang_string('none', 'admin'),
|
||||
];
|
||||
foreach ($enabledissuers as $issuer) {
|
||||
$oauth2services[$issuer->get('id')] = s($issuer->get('name'));
|
||||
}
|
||||
|
||||
$temp->add(new admin_setting_configselect('smtpoauthservice', new lang_string('issuer', 'auth_oauth2'),
|
||||
new lang_string('configsmtpoauthservice', 'admin'), '', $oauth2services));
|
||||
}
|
||||
|
||||
$temp->add(new admin_setting_configtext('smtpuser', new lang_string('smtpuser', 'admin'),
|
||||
new lang_string('configsmtpuser', 'admin'), '', PARAM_NOTAGS));
|
||||
|
||||
|
|
29
admin/tests/behat/outgoing_mail.feature
Normal file
29
admin/tests/behat/outgoing_mail.feature
Normal file
|
@ -0,0 +1,29 @@
|
|||
@core @core_admin
|
||||
Feature: Outgoing mail configuration
|
||||
In order to send email from Moodle
|
||||
As a Moodle administrator
|
||||
I need to set mail configuration
|
||||
|
||||
Background:
|
||||
Given I log in as "admin"
|
||||
|
||||
Scenario: SMTP Auth Type without OAuth 2 Service setup yet
|
||||
Given I navigate to "Server > Email > Outgoing mail configuration" in site administration
|
||||
And I should not see "XOAUTH2" in the "SMTP Auth Type" "select"
|
||||
And I should see "LOGIN" in the "SMTP Auth Type" "select"
|
||||
And I should see "PLAIN" in the "SMTP Auth Type" "select"
|
||||
|
||||
Scenario: SMTP Auth Type with OAuth 2 Service setup
|
||||
Given I navigate to "Server > OAuth 2 services" in site administration
|
||||
And I press "Google"
|
||||
And I should see "Create new service: Google"
|
||||
And I set the following fields to these values:
|
||||
| Name | Testing service |
|
||||
| Client ID | thisistheclientid |
|
||||
| Client secret | supersecret |
|
||||
And I press "Save changes"
|
||||
When I navigate to "Server > Email > Outgoing mail configuration" in site administration
|
||||
Then I should see "XOAUTH2" in the "SMTP Auth Type" "select"
|
||||
And I should see "LOGIN" in the "SMTP Auth Type" "select"
|
||||
And I should see "PLAIN" in the "SMTP Auth Type" "select"
|
||||
And I should see "Testing service" in the "OAuth 2 Service" "select"
|
Loading…
Add table
Add a link
Reference in a new issue