mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
refactor: remove /users/{uid}/settings/{setting} route
@baris Also, I am now allowing the following properties to be saved in User.saveSettings: - categoryTopicSort - topicPostSort - setCategorySort - setTopicSort
This commit is contained in:
@@ -34,8 +34,6 @@ paths:
|
|||||||
$ref: 'write/users/uid.yaml'
|
$ref: 'write/users/uid.yaml'
|
||||||
/users/{uid}/settings:
|
/users/{uid}/settings:
|
||||||
$ref: 'write/users/uid/settings.yaml'
|
$ref: 'write/users/uid/settings.yaml'
|
||||||
/users/{uid}/settings/{setting}:
|
|
||||||
$ref: 'write/users/uid/settings/setting.yaml'
|
|
||||||
/users/{uid}/password:
|
/users/{uid}/password:
|
||||||
$ref: 'write/users/uid/password.yaml'
|
$ref: 'write/users/uid/password.yaml'
|
||||||
/users/{uid}/follow:
|
/users/{uid}/follow:
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
put:
|
|
||||||
tags:
|
|
||||||
- users
|
|
||||||
summary: update one user setting
|
|
||||||
parameters:
|
|
||||||
- in: path
|
|
||||||
name: uid
|
|
||||||
schema:
|
|
||||||
type: integer
|
|
||||||
required: true
|
|
||||||
description: uid of the user
|
|
||||||
example: '1'
|
|
||||||
- in: path
|
|
||||||
name: setting
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
required: true
|
|
||||||
description: name of the setting you wish to update
|
|
||||||
example: 'showemail'
|
|
||||||
requestBody:
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
value:
|
|
||||||
type: string
|
|
||||||
example: '1'
|
|
||||||
responses:
|
|
||||||
'200':
|
|
||||||
description: successfully updated user settings
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
status:
|
|
||||||
$ref: ../../../../components/schemas/Status.yaml#/Status
|
|
||||||
response:
|
|
||||||
type: object
|
|
||||||
@@ -20,9 +20,9 @@ define('sort', ['components', 'api'], function (components, api) {
|
|||||||
}
|
}
|
||||||
var newSetting = $(this).attr('data-sort');
|
var newSetting = $(this).attr('data-sort');
|
||||||
if (app.user.uid) {
|
if (app.user.uid) {
|
||||||
api.put(`/users/${app.user.uid}/settings/${field}`, {
|
const payload = { settings: {} };
|
||||||
value: newSetting,
|
payload.settings[field] = newSetting;
|
||||||
}).then(() => {
|
api.put(`/users/${app.user.uid}/settings`, payload).then(() => {
|
||||||
refresh(newSetting, utils.params());
|
refresh(newSetting, utils.params());
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -106,10 +106,6 @@ usersAPI.updateSettings = async function (caller, data) {
|
|||||||
return await user.saveSettings(data.uid, payload);
|
return await user.saveSettings(data.uid, payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
usersAPI.updateSetting = async function (caller, data) {
|
|
||||||
await user.setSetting(data.uid, data.setting, data.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
usersAPI.changePassword = async function (caller, data) {
|
usersAPI.changePassword = async function (caller, data) {
|
||||||
await user.changePassword(caller.uid, Object.assign(data, { ip: caller.ip }));
|
await user.changePassword(caller.uid, Object.assign(data, { ip: caller.ip }));
|
||||||
await events.log({
|
await events.log({
|
||||||
|
|||||||
@@ -33,11 +33,6 @@ Users.updateSettings = async (req, res) => {
|
|||||||
helpers.formatApiResponse(200, res, settings);
|
helpers.formatApiResponse(200, res, settings);
|
||||||
};
|
};
|
||||||
|
|
||||||
Users.updateSetting = async (req, res) => {
|
|
||||||
await api.users.updateSetting(req, { ...req.params, value: req.body.value });
|
|
||||||
helpers.formatApiResponse(200, res);
|
|
||||||
};
|
|
||||||
|
|
||||||
Users.changePassword = async (req, res) => {
|
Users.changePassword = async (req, res) => {
|
||||||
await api.users.changePassword(req, { ...req.body, uid: req.params.uid });
|
await api.users.changePassword(req, { ...req.body, uid: req.params.uid });
|
||||||
helpers.formatApiResponse(200, res);
|
helpers.formatApiResponse(200, res);
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ function authenticatedRoutes() {
|
|||||||
setupApiRoute(router, 'delete', '/:uid', [...middlewares, middleware.assert.user, middleware.exposePrivileges], controllers.write.users.delete);
|
setupApiRoute(router, 'delete', '/:uid', [...middlewares, middleware.assert.user, middleware.exposePrivileges], controllers.write.users.delete);
|
||||||
|
|
||||||
setupApiRoute(router, 'put', '/:uid/settings', [...middlewares, middleware.checkRequired.bind(null, ['settings'])], controllers.write.users.updateSettings);
|
setupApiRoute(router, 'put', '/:uid/settings', [...middlewares, middleware.checkRequired.bind(null, ['settings'])], controllers.write.users.updateSettings);
|
||||||
setupApiRoute(router, 'put', '/:uid/settings/:setting', [...middlewares, middleware.checkRequired.bind(null, ['value'])], controllers.write.users.updateSetting);
|
|
||||||
|
|
||||||
setupApiRoute(router, 'put', '/:uid/password', [...middlewares, middleware.checkRequired.bind(null, ['newPassword']), middleware.assert.user], controllers.write.users.changePassword);
|
setupApiRoute(router, 'put', '/:uid/password', [...middlewares, middleware.checkRequired.bind(null, ['newPassword']), middleware.assert.user], controllers.write.users.changePassword);
|
||||||
|
|
||||||
|
|||||||
@@ -121,6 +121,10 @@ module.exports = function (User) {
|
|||||||
upvoteNotifFreq: data.upvoteNotifFreq,
|
upvoteNotifFreq: data.upvoteNotifFreq,
|
||||||
bootswatchSkin: data.bootswatchSkin,
|
bootswatchSkin: data.bootswatchSkin,
|
||||||
categoryWatchState: data.categoryWatchState,
|
categoryWatchState: data.categoryWatchState,
|
||||||
|
categoryTopicSort: data.categoryTopicSort,
|
||||||
|
topicPostSort: data.topicPostSort,
|
||||||
|
setCategorySort: data.setCategorySort,
|
||||||
|
setTopicSort: data.setTopicSort,
|
||||||
};
|
};
|
||||||
const notificationTypes = await notifications.getAllNotificationTypes();
|
const notificationTypes = await notifications.getAllNotificationTypes();
|
||||||
notificationTypes.forEach(function (notificationType) {
|
notificationTypes.forEach(function (notificationType) {
|
||||||
|
|||||||
Reference in New Issue
Block a user