Skip to content
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

chore!: Remove upsert users capability through the users.update endpoint #31889

Merged
merged 18 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/four-snakes-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": major
"@rocket.chat/rest-typings": major
---

Removed upsert behavior on `users.update` endpoint (`joinDefaultChannels` param or empty `userId` are not allowed anymore)
36 changes: 36 additions & 0 deletions apps/meteor/tests/end-to-end/api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,42 @@ describe('[Users]', () => {
.end(done);
});

it('should return an error when trying to upsert a user by sending an empty userId', () => {
return request
.post(api('users.update'))
.set(credentials)
.send({
userId: '',
data: {},
})
.expect('Content-Type', 'application/json')
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('errorType', 'invalid-params');
expect(res.body).to.have.property('error', 'must NOT have fewer than 1 characters [invalid-params]');
});
});

it('should return an error when trying to use the joinDefaultChannels param, which is not intended for updates', () => {
return request
.post(api('users.update'))
.set(credentials)
.send({
userId: targetUser._id,
data: {
joinDefaultChannels: true,
},
})
.expect('Content-Type', 'application/json')
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('errorType', 'invalid-params');
expect(res.body).to.have.property('error', 'must NOT have additional properties [invalid-params]');
});
});

it("should update a bot's email", (done) => {
void request
.post(api('users.update'))
Expand Down
6 changes: 1 addition & 5 deletions packages/rest-typings/src/v1/users/UsersUpdateParamsPOST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export type UsersUpdateParamsPOST = {
nickname?: string;
statusText?: string;
roles?: string[];
joinDefaultChannels?: boolean;
requirePasswordChange?: boolean;
setRandomPassword?: boolean;
sendWelcomeEmail?: boolean;
Expand All @@ -32,6 +31,7 @@ const UsersUpdateParamsPostSchema = {
properties: {
userId: {
type: 'string',
minLength: 1,
},
confirmRelinquish: {
type: 'boolean',
Expand Down Expand Up @@ -78,10 +78,6 @@ const UsersUpdateParamsPostSchema = {
},
nullable: true,
},
joinDefaultChannels: {
type: 'boolean',
nullable: true,
},
requirePasswordChange: {
type: 'boolean',
nullable: true,
Expand Down
Loading