Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist the config changes of usermanagement #23333

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/settings/js/vue-settings-apps-users-management.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-apps-users-management.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions apps/settings/js/vue-settings-users-a0b198417ac7b9cdc361.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions apps/settings/js/vue-settings-users-f1523b80ef7dae06edd8.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions apps/settings/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ public function usersList() {
$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';
$serverData['showLastLogin'] = $this->config->getAppValue('core', 'users-showlastlogin', 'no') === 'yes';
Copy link
Member

@juliushaertl juliushaertl Nov 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to have those stored in the 'settings' app instead of 'core', the other one make sense for core since core sends out the email and generates the user id, but the show* settings are really only settings app relevant.

$serverData['showLanguages'] = $this->config->getAppValue('core', 'users-showlanguages', 'no') === 'yes';
$serverData['showUserBackend'] = $this->config->getAppValue('core', 'users-showuserbackend', 'no') === 'yes';
$serverData['showStoragePath'] = $this->config->getAppValue('core', 'users-showstoragepath', 'no') === 'yes';

return new TemplateResponse('settings', 'settings-vue', ['serverData' => $serverData]);
}
Expand All @@ -271,12 +275,12 @@ public function usersList() {
* @return JSONResponse
*/
public function setPreference(string $key, string $value): JSONResponse {
$allowed = ['newUser.sendEmail'];
$allowed = ['newUser.sendEmail', 'showlastlogin', 'showlanguages', 'showuserbackend', 'showstoragepath'];
if (!in_array($key, $allowed, true)) {
return new JSONResponse([], Http::STATUS_FORBIDDEN);
}

$this->config->setAppValue('core', $key, $value);
$this->config->setAppValue('core', 'users-'.$key, $value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we could introduce them as user values so that each admin user has their own setting for 'showlastlogin', 'showlanguages', 'showuserbackend', 'showstoragepath' using setUserValue instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also wouldn't this basically break the existing newUser.sendMail setting since the key would now be prefixed with 'users-' ?


return new JSONResponse([]);
}
Expand Down
53 changes: 35 additions & 18 deletions apps/settings/src/views/Users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,31 @@
<div>
<input id="showLanguages"
v-model="showLanguages"
:disabled="loadingShowLanguages"
type="checkbox"
class="checkbox">
<label for="showLanguages">{{ t('settings', 'Show Languages') }}</label>
</div>
<div>
<input id="showLastLogin"
v-model="showLastLogin"
:disabled="loadingShowLastLogin"
type="checkbox"
class="checkbox">
<label for="showLastLogin">{{ t('settings', 'Show last login') }}</label>
</div>
<div>
<input id="showUserBackend"
v-model="showUserBackend"
:disabled="loadingShowUserBackend"
type="checkbox"
class="checkbox">
<label for="showUserBackend">{{ t('settings', 'Show user backend') }}</label>
</div>
<div>
<input id="showStoragePath"
v-model="showStoragePath"
:disabled="loadingShowStoragePath"
type="checkbox"
class="checkbox">
<label for="showStoragePath">{{ t('settings', 'Show storage path') }}</label>
Expand Down Expand Up @@ -207,6 +211,10 @@ export default {
externalActions: [],
loadingAddGroup: false,
loadingSendMail: false,
loadingShowLanguages: false,
loadingShowLastLogin: false,
loadingShowStoragePath: false,
loadingShowUserBackend: false,
showConfig: {
showStoragePath: false,
showUserBackend: false,
Expand Down Expand Up @@ -237,25 +245,25 @@ export default {
showLanguages: {
get() { return this.getLocalstorage('showLanguages') },
set(status) {
this.setLocalStorage('showLanguages', status)
this.updateSettings(status, 'showLanguages', 'showlanguages', 'loadingShowLanguages')
},
},
showLastLogin: {
get() { return this.getLocalstorage('showLastLogin') },
set(status) {
this.setLocalStorage('showLastLogin', status)
this.updateSettings(status, 'showLastLogin', 'showlastlogin', 'loadingShowLastLogin')
},
},
showUserBackend: {
get() { return this.getLocalstorage('showUserBackend') },
set(status) {
this.setLocalStorage('showUserBackend', status)
this.updateSettings(status, 'showUserBackend', 'showuserbackend', 'loadingShowUserBackend')
},
},
showStoragePath: {
get() { return this.getLocalstorage('showStoragePath') },
set(status) {
this.setLocalStorage('showStoragePath', status)
this.updateSettings(status, 'showStoragePath', 'showstoragepath', 'loadingShowStoragePath')
},
},
Expand Down Expand Up @@ -296,19 +304,8 @@ export default {
get() {
return this.settings.newUserSendEmail
},
async set(value) {
try {
this.loadingSendMail = true
this.$store.commit('setServerData', {
...this.settings,
newUserSendEmail: value,
})
await axios.post(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
}
set(value) {
this.updateSettings(value, 'newUserSendEmail', 'newUser.sendEmail', 'loadingSendMail')
},
},
Expand Down Expand Up @@ -360,14 +357,34 @@ export default {
// force initialization
const localConfig = this.$localStorage.get(key)
// if localstorage is null, fallback to original values
this.showConfig[key] = localConfig !== null ? localConfig === 'true' : this.showConfig[key]
this.showConfig[key] = localConfig !== null ? localConfig === 'true' : this.settings[key]
return this.showConfig[key]
},
setLocalStorage(key, status) {
this.showConfig[key] = status
this.$localStorage.set(key, status)
return status
},
updateSettings(value, key, addToURL, loadingData) {
let shouldUpdate = true
try {
this[loadingData] = true
axios.post(generateUrl('/settings/users/preferences/' + addToURL), { value: value ? 'yes' : 'no' })
} catch (e) {
document.getElementById(key).checked = !value
shouldUpdate = false
} finally {
this[loadingData] = false
if (shouldUpdate) {
this.$store.commit('setServerData', {
...this.settings,
key: value,
})
this.setLocalStorage(key, value)
}
}
},
removeGroup(groupid) {
const self = this
// TODO migrate to a vue js confirm dialog component
Expand Down
25 changes: 25 additions & 0 deletions apps/settings/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,29 @@ public function dataTestCanAdminChangeUserPasswords() {
[false, false, false, true],
];
}

public function dataSetPreference() {
return [
['newUser.sendEmail', 'yes', ['status' => 200]],
['showlastlogin', 'yes', ['status' => 200]],
['showlanguages', 'yes', ['status' => 200]],
['showuserbackend', 'yes', ['status' => 200]],
['showuserbackend', 'yes', ['status' => 200]],
['foobar', 'yes', ['status' => 403]],
];
}

/**
* @dataProvider dataSetPreference
* @param string $key the key to store the value for appconfig
* @param string $val the value associated with the key
* @param array $expectedResult the status result is stored in this array
*/
public function testSetPreference(string $key, string $val, array $expectedResult) {
$controller = $this->getController();

$result = $controller->setPreference($key, $val);

$this->assertEquals($expectedResult['status'], $result->getStatus());
}
}
2 changes: 1 addition & 1 deletion core/js/dist/login.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/login.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/main.js.map

Large diffs are not rendered by default.