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:

Signed-off-by: Sujith Haridasan <sujith.h@gmail.com>
  • Loading branch information
sharidasan committed Oct 10, 2020
1 parent 4295fe6 commit fa8a6c6
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 16 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-a8294e6281d3bd91e03f.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
64 changes: 52 additions & 12 deletions apps/settings/src/views/Users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -235,27 +235,67 @@ export default {

// Local settings
showLanguages: {
get() { return this.getLocalstorage('showLanguages') },
set(status) {
this.setLocalStorage('showLanguages', status)
get() { return this.settings.showLanguages },
async set(value) {
try {
this.$store.commit('setServerData', {
...this.settings,
showLanguages: value,
})
await axios.post(generateUrl('/settings/users/preferences/showlanguages'), { value: value ? 'yes' : 'no' })
} catch (e) {
console.error('could not update last login preference: ' + e.message, e)
} finally {
this.showConfig.showLanguages = false
}
},
},
showLastLogin: {
get() { return this.getLocalstorage('showLastLogin') },
set(status) {
this.setLocalStorage('showLastLogin', status)
get() { return this.settings.showLastLogin },
async set(value) {
try {
this.$store.commit('setServerData', {
...this.settings,
showLastLogin: value,
})
await axios.post(generateUrl('/settings/users/preferences/showlastlogin'), { value: value ? 'yes' : 'no' })
} catch (e) {
console.error('could not update last login preference: ' + e.message, e)
} finally {
this.showConfig.showLastLogin = false
}
},
},
showUserBackend: {
get() { return this.getLocalstorage('showUserBackend') },
set(status) {
this.setLocalStorage('showUserBackend', status)
get() { return this.settings.showUserBackend },
async set(value) {
try {
this.$store.commit('setServerData', {
...this.settings,
showUserBackend: value,
})
await axios.post(generateUrl('/settings/users/preferences/showuserbackend'), { value: value ? 'yes' : 'no' })
} catch (e) {
console.error('could not update last login preference: ' + e.message, e)
} finally {
this.showConfig.showUserBackend = false
}
},
},
showStoragePath: {
get() { return this.getLocalstorage('showStoragePath') },
set(status) {
this.setLocalStorage('showStoragePath', status)
get() { return this.settings.showStoragePath },
async set(value) {
try {
this.$store.commit('setServerData', {
...this.settings,
showStoragePath: value,
})
await axios.post(generateUrl('/settings/users/preferences/showstoragepath'), { value: value ? 'yes' : 'no' })
} catch (e) {
console.error('could not update last login preference: ' + e.message, e)
} finally {
this.showConfig.showStoragePath = false
}
},
},

Expand Down
19 changes: 19 additions & 0 deletions apps/settings/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,23 @@ 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]],
];
}

public function testSetPreference(string $key, string $val, $expectedResult) {
$controller = $this->getController();

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

$this->assertEquals($expectedResult['status'], $result->getStatus());
}
}

0 comments on commit fa8a6c6

Please sign in to comment.