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 <sujith.h@gmail.com>
  • Loading branch information
sharidasan committed Oct 14, 2020
1 parent 42fcc74 commit af74889
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 27 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-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';
$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);

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.

0 comments on commit af74889

Please sign in to comment.