-
Notifications
You must be signed in to change notification settings - Fork 273
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
feat(xo-server/rest-api): ability to update group and its users #8278
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -940,6 +940,29 @@ export default class RestApi { | |||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
collections.groups.actions = { | ||||||||||||||||||||||||||||||||||||||||||||||||
update: withParams( | ||||||||||||||||||||||||||||||||||||||||||||||||
async ({ id, name, userIds }, req) => { | ||||||||||||||||||||||||||||||||||||||||||||||||
const group = await app.getGroup(id) | ||||||||||||||||||||||||||||||||||||||||||||||||
if (group.provider !== undefined) { | ||||||||||||||||||||||||||||||||||||||||||||||||
throw new Error('Cannot edit synchronized group') | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
if (name !== undefined) { | ||||||||||||||||||||||||||||||||||||||||||||||||
await app.updateGroup(id, { name }) | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+946
to
+953
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid adding business logic into the REST API code. @fbeauchamp What do you think? |
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
if (Array.isArray(userIds)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
await app.setGroupUsers(id, userIds) | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||
id: { type: 'string' }, | ||||||||||||||||||||||||||||||||||||||||||||||||
name: { type: 'string', optional: true }, | ||||||||||||||||||||||||||||||||||||||||||||||||
userIds: { type: 'array', items: { type: 'string' }, optional: true }, | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+943
to
+965
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't create action like that. Same as: #8276 (comment)
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
collections.restore = {} | ||||||||||||||||||||||||||||||||||||||||||||||||
collections.tasks = { | ||||||||||||||||||||||||||||||||||||||||||||||||
async getObject(id, req) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -1514,6 +1537,15 @@ export default class RestApi { | |||||||||||||||||||||||||||||||||||||||||||||||
res.sendStatus(200) | ||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
api.patch( | ||||||||||||||||||||||||||||||||||||||||||||||||
'/groups/update/:id', | ||||||||||||||||||||||||||||||||||||||||||||||||
json(), | ||||||||||||||||||||||||||||||||||||||||||||||||
wrap(async (req, res) => { | ||||||||||||||||||||||||||||||||||||||||||||||||
await collections.groups.actions.update(req.body, req) | ||||||||||||||||||||||||||||||||||||||||||||||||
res.sendStatus(200) | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you try to update a group with an ID that doesn't exist, does it return an error code? |
||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+1541
to
+1548
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO this can be split into 2 routes.
Add user to group:
First route we update a property of the |
||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
registerRestApi(spec, base = '/') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this message is clear enough. It can be confusing, for example: "you can update the properties of users in the group".
this PR expose the possibility to ADD a user in a group
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about "Allow updating a group's name and manage its users list (add/remove users)" ?