-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[FIX] channels.convertToTeam endpoint doesn't work when only the channelName param is provided
#26858
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
[FIX] channels.convertToTeam endpoint doesn't work when only the channelName param is provided
#26858
Changes from 6 commits
811a951
1d13bd4
09f0b1b
105444f
f8997ad
0bf369b
fb24acf
2133c0f
d7df939
0f1ddd6
35605b4
1879101
1e14d94
a52871d
36210b0
971f37c
80fa434
aaebe90
7400c8b
ad9a658
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 |
|---|---|---|
|
|
@@ -1922,7 +1922,7 @@ describe('[Channels]', function () { | |
| }); | ||
| }); | ||
|
|
||
| it('should successfully convert a channel to a team', (done) => { | ||
| it(`should successfully convert a channel to a team when the channel's id is sent as parameter`, (done) => { | ||
| updatePermission('create-team', ['admin']).then(() => { | ||
| updatePermission('edit-room', ['admin']).then(() => { | ||
| request | ||
|
|
@@ -1938,6 +1938,61 @@ describe('[Channels]', function () { | |
| }); | ||
| }); | ||
|
|
||
| it(`should successfully convert a channel to a team when the channel's name is sent as parameter`, (done) => { | ||
| updatePermission('create-team', ['admin']).then(() => { | ||
| updatePermission('edit-room', ['admin']).then(() => { | ||
|
Member
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. there is no need to update permissions.. looking the previous test, this is the current state already. |
||
| request | ||
| .post(api('teams.convertToChannel')) | ||
| .set(credentials) | ||
| .send({ teamName: this.newChannel.name }) | ||
| .expect(200) | ||
| .expect((res) => { | ||
| expect(res.body).to.have.a.property('success', true); | ||
| }) | ||
| .then(() => { | ||
| request | ||
|
Member
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. this Promise nesting and the previous one with the permissions update is wrong in so many levels 🙈 I see this has been the "standard" on this particular file, but we shouldn't propagate bad code even if it is the current "standard".. this is conceptually wrong since the updatePermission()
.then(() => updatePermission())
.then(() => request
.post(api('teams.convertToChannel'))
.set(credentials)
// ....
).then(() => request
.post(api('teams.convertToTeam'))
.set(credentials)
// ....
)as you can see, everything is done in a single level of nesting. BUT, you should also not do this, since |
||
| .post(api('channels.convertToTeam')) | ||
| .set(credentials) | ||
| .send({ channelName: this.newChannel.name }) | ||
| .expect(200) | ||
| .expect((res) => { | ||
| expect(res.body).to.have.a.property('success', true); | ||
| }) | ||
| .end(done); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| it(`should successfully convert a channel to a team when the channel's name and id are sent as parameter`, (done) => { | ||
| updatePermission('create-team', ['admin']).then(() => { | ||
| updatePermission('edit-room', ['admin']).then(() => { | ||
| request | ||
| .post(api('teams.convertToChannel')) | ||
| .set(credentials) | ||
| .send({ teamName: this.newChannel.name }) | ||
| .expect(200) | ||
| .expect((res) => { | ||
| expect(res.body).to.have.a.property('success', true); | ||
| }) | ||
| .then(() => { | ||
| request | ||
| .post(api('channels.convertToTeam')) | ||
| .set(credentials) | ||
| .send({ | ||
| channelName: this.newChannel.name, | ||
| channelId: this.newChannel._id, | ||
| }) | ||
| .expect(200) | ||
| .expect((res) => { | ||
| expect(res.body).to.have.a.property('success', true); | ||
| }) | ||
| .end(done); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| it('should fail to convert channel without the required parameters', (done) => { | ||
| request.post(api('channels.convertToTeam')).set(credentials).send({}).expect(400).end(done); | ||
| }); | ||
|
|
||
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.
The function will have to check each field any way. No need to do it again here.
Uh oh!
There was an error while loading. Please reload this page.
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.
This endpoint is not working when only the
channelNameparam is provided, so I added this change to fix it. Without these changes, the validation'roomId' in paramsinfindChannelByIdOrNamewould always return true.Another way to fix it would be to replace
'roomId' in paramsbyparams.roomId, but this would cause some typing issues in this method 🤔Still, it's better to change the
findChannelByIdOrNamemethod instead, though