Skip to content

Commit

Permalink
Persist the config changes of usermanagement
Browse files Browse the repository at this point in the history
Persist the changes made to usermanagemnt like:
- Show Languages
- Show last login
- Show user backend
- Show storage path

Signed-off-by: Sujith Haridasan <[email protected]>
  • Loading branch information
sharidasan committed Oct 11, 2020
1 parent 4295fe6 commit 82eee59
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 22 deletions.
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-c3bc38d8d682cfd46ba9.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion 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', 'showlastlogin', 'no') === 'yes';
$serverData['showLanguages'] = $this->config->getAppValue('core', 'showlanguages', 'no') === 'yes';
$serverData['showUserBackend'] = $this->config->getAppValue('core', 'showuserbackend', 'no') === 'yes';
$serverData['showStoragePath'] = $this->config->getAppValue('core', 'showstoragepath', 'no') === 'yes';

return new TemplateResponse('settings', 'settings-vue', ['serverData' => $serverData]);
}
Expand All @@ -271,7 +275,7 @@ 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);
}
Expand Down
43 changes: 25 additions & 18 deletions apps/settings/src/views/Users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -237,25 +237,25 @@ export default {
showLanguages: {
get() { return this.getLocalstorage('showLanguages') },
set(status) {
this.setLocalStorage('showLanguages', status)
this.updateSettings(status, 'showLanguages', 'showlanguages')
},
},
showLastLogin: {
get() { return this.getLocalstorage('showLastLogin') },
set(status) {
this.setLocalStorage('showLastLogin', status)
this.updateSettings(status, 'showLastLogin', 'showlastlogin')
},
},
showUserBackend: {
get() { return this.getLocalstorage('showUserBackend') },
set(status) {
this.setLocalStorage('showUserBackend', status)
this.updateSettings(status, 'showUserBackend', 'showuserbackend')
},
},
showStoragePath: {
get() { return this.getLocalstorage('showStoragePath') },
set(status) {
this.setLocalStorage('showStoragePath', status)
this.updateSettings(status, 'showStoragePath', 'showstoragepath')
},
},
Expand Down Expand Up @@ -296,19 +296,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')
},
},
Expand Down Expand Up @@ -360,14 +349,32 @@ 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) {
try {
this.loadingSendMail = true
this.$store.commit('setServerData', {
...this.settings,
key: value,
})
axios.post(generateUrl('/settings/users/preferences/' + addToURL), { value: value ? 'yes' : 'no' })
} catch (e) {
console.error('could not update ' + key + ' preference: ' + e.message, e)
} finally {
if (key === 'newUserSendEmail') {
this.loadingSendMail = false
} else {
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());
}
}

0 comments on commit 82eee59

Please sign in to comment.