Revive the "send email to new users" toggle for the user form

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2020-02-26 18:04:43 +01:00 committed by Gary Kim
parent 9bde542224
commit 93a8b06090
No known key found for this signature in database
GPG Key ID: 9349B59FB54594AC
8 changed files with 69 additions and 17 deletions

View File

@ -328,7 +328,7 @@ class UsersController extends AUserData {
}
// Send new user mail only if a mail is set
if ($email !== '') {
if ($email !== '' && $this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') {
$newUser->setEMailAddress($email);
try {
$emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken);

View File

@ -44,10 +44,12 @@ use OC\AppFramework\Http;
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
use OC\ForbiddenException;
use OC\Security\IdentityProof\Manager;
use OCA\Settings\AppInfo\Application;
use OCA\User_LDAP\User_Proxy;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\BackgroundJob\IJobList;
use OCP\Encryption\IManager;
@ -61,6 +63,7 @@ use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Mail\IMailer;
use OC\Settings\BackgroundJobs\VerifyUserData;
use function in_array;
/**
* @package OC\Settings\Controller
@ -255,10 +258,28 @@ class UsersController extends Controller {
$serverData['canChangePassword'] = $canChangePassword;
$serverData['newUserGenerateUserID'] = $this->config->getAppValue('core', 'newUser.generateUserID', 'no') === 'yes';
$serverData['newUserRequireEmail'] = $this->config->getAppValue('core', 'newUser.requireEmail', 'no') === 'yes';
$serverData['newUserSendEmail'] = $this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes';
return new TemplateResponse('settings', 'settings-vue', ['serverData' => $serverData]);
}
/**
* @param string $key
* @param string $value
*
* @return JSONResponse
*/
public function setPreference(string $key, string $value): JSONResponse {
$allowed = ['newUser.sendEmail'];
if (!in_array($key, $allowed, true)) {
return new JSONResponse([], Http::STATUS_FORBIDDEN);
}
$this->config->setAppValue('core', $key, $value);
return new JSONResponse([]);
}
/**
* check if the admin can change the users password
*

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -69,6 +69,7 @@ $application->registerRoutes($this, [
['name' => 'Users#getVerificationCode', 'url' => '/settings/users/{account}/verify', 'verb' => 'GET'],
['name' => 'Users#usersList', 'url' => '/settings/users', 'verb' => 'GET'],
['name' => 'Users#usersListByGroup', 'url' => '/settings/users/{group}', 'verb' => 'GET', 'requirements' => ['group' => '.+']],
['name' => 'Users#setPreference', 'url' => '/settings/users/preferences/{key}', 'verb' => 'POST'],
['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST'],
['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET'],
['name' => 'LogSettings#download', 'url' => '/settings/admin/log/download', 'verb' => 'GET'],

View File

@ -54,6 +54,14 @@
<input type="checkbox" id="showStoragePath" class="checkbox" v-model="showStoragePath">
<label for="showStoragePath">{{t('settings', 'Show storage path')}}</label>
</div>
<div>
<input id="sendWelcomeMail"
v-model="sendWelcomeMail"
:disabled="loadingSendMail"
type="checkbox"
class="checkbox">
<label for="sendWelcomeMail">{{ t('settings', 'Send email to new user') }}</label>
</div>
</AppNavigationSettings>
</AppNavigation>
<AppContent>
@ -63,6 +71,7 @@
</template>
<script>
import axios from '@nextcloud/axios'
import Vue from 'vue';
import VueLocalStorage from 'vue-localstorage'
import {
@ -96,7 +105,7 @@ export default {
},
beforeMount() {
this.$store.commit('initGroups', {
groups: this.$store.getters.getServerData.groups,
groups: this.$store.getters.getServerData.groups,
orderBy: this.$store.getters.getServerData.sortGroups,
userCount: this.$store.getters.getServerData.userCount
});
@ -122,6 +131,7 @@ export default {
externalActions: [],
showAddGroupEntry: false,
loadingAddGroup: false,
loadingSendMail: false,
showConfig: {
showStoragePath: false,
showUserBackend: false,
@ -154,7 +164,7 @@ export default {
},
removeGroup(groupid) {
let self = this;
// TODO migrate to a vue js confirm dialog component
// TODO migrate to a vue js confirm dialog component
OC.dialogs.confirm(
t('settings', 'You are about to remove the group {group}. The users will NOT be deleted.', {group: groupid}),
t('settings','Please confirm the group removal '),
@ -168,7 +178,7 @@ export default {
/**
* Dispatch default quota set request
*
*
* @param {string|Object} quota Quota in readable format '5 GB' or Object {id: '5 GB', label: '5GB'}
* @returns {string}
*/
@ -207,7 +217,7 @@ export default {
/**
* Register a new action for the user menu
*
*
* @param {string} icon the icon class
* @param {string} text the text to display
* @param {function} action the function to run
@ -223,7 +233,7 @@ export default {
/**
* Create a new group
*
*
* @param {Object} event The form submit event
*/
createGroup(event) {
@ -312,7 +322,27 @@ export default {
set: function(quota) {
this.selectedQuota = quota;
}
},
sendWelcomeMail: {
get() {
return this.settings.newUserSendEmail
},
async set(value) {
try {
this.loadingSendMail = true
this.$store.commit('setServerData', {
...this.settings,
newUserSendEmail: value,
})
await axios.post(OC.generateUrl(`/settings/users/preferences/newUser.sendEmail`), { value: value ? 'yes' : 'no' })
} catch (e) {
console.error('could not update newUser.sendEmail preference: ' + e.message, e)
} finally {
this.loadingSendMail = false
}
},
},
// BUILD APP NAVIGATION MENU OBJECT
@ -388,10 +418,10 @@ export default {
disabledGroup.text = t('settings', 'Disabled users'); // rename disabled group
disabledGroup.icon = 'icon-disabled-users'; // set icon
if (disabledGroup.utils && (
disabledGroup.utils.counter > 0 // add disabled if not empty
|| disabledGroup.utils.counter === -1) // add disabled if ldap enabled
disabledGroup.utils.counter > 0 // add disabled if not empty
|| disabledGroup.utils.counter === -1) // add disabled if ldap enabled
) {
groups.unshift(disabledGroup);
groups.unshift(disabledGroup);
if (disabledGroup.utils.counter === -1) {
// hides the counter instead of showing -1
delete disabledGroup.utils.counter