Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions packages/rocketchat-lib/server/functions/createRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ RocketChat.createRoom = function(type, name, owner, members, readOnly, extraData

for (const username of members) {
const member = RocketChat.models.Users.findOneByUsername(username, { fields: { username: 1 }});
const isTheOwner = username === owner.username;
if (!member) {
continue;
}

// make all room members muted by default, unless they have the post-readonly permission
if (readOnly === true && !RocketChat.authz.hasPermission(member._id, 'post-readonly')) {
// make all room members (Except the owner) muted by default, unless they have the post-readonly permission
if (readOnly === true && !RocketChat.authz.hasPermission(member._id, 'post-readonly') && !isTheOwner) {
RocketChat.models.Rooms.muteUsernameByRoomId(room._id, username);
}

Expand Down
78 changes: 56 additions & 22 deletions tests/end-to-end/api/05-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@
import {
getCredentials,
api,
login,
request,
credentials,
message,
log,
apiPrivateChannelName
message
} from '../../data/api-data.js';
import { adminEmail, password } from '../../data/user.js';
import supertest from 'supertest';

describe('[Chat]', function() {
this.retries(0);
Expand Down Expand Up @@ -49,7 +44,7 @@ describe('[Chat]', function() {
alias: 'Gruggy',
emoji: ':smirk:',
avatar: 'http://res.guggy.com/logo_128.png',
attachments: [{
attachments: [ {
color: '#ff0000',
text: 'Yay for gruggy!',
ts: '2016-12-09T16:53:06.761Z',
Expand All @@ -66,7 +61,7 @@ describe('[Chat]', function() {
audio_url: 'http://www.w3schools.com/tags/horse.mp3',
video_url: 'http://www.w3schools.com/tags/movie.mp4',
fields: ''
}]
} ]
})
.expect('Content-Type', 'application/json')
.expect(400)
Expand All @@ -86,7 +81,7 @@ describe('[Chat]', function() {
alias: 'Gruggy',
emoji: ':smirk:',
avatar: 'http://res.guggy.com/logo_128.png',
attachments: [{
attachments: [ {
color: '#ff0000',
text: 'Yay for gruggy!',
ts: '2016-12-09T16:53:06.761Z',
Expand All @@ -102,12 +97,12 @@ describe('[Chat]', function() {
image_url: 'http://res.guggy.com/logo_128.png',
audio_url: 'http://www.w3schools.com/tags/horse.mp3',
video_url: 'http://www.w3schools.com/tags/movie.mp4',
fields: [{
fields: [ {
short: true,
title: 12,
value: false
}]
}]
} ]
} ]
})
.expect('Content-Type', 'application/json')
.expect(400)
Expand All @@ -127,7 +122,7 @@ describe('[Chat]', function() {
alias: 'Gruggy',
emoji: ':smirk:',
avatar: 'http://res.guggy.com/logo_128.png',
attachments: [{
attachments: [ {
color: '#ff0000',
text: 'Yay for gruggy!',
ts: '2016-12-09T16:53:06.761Z',
Expand All @@ -143,16 +138,16 @@ describe('[Chat]', function() {
image_url: 'http://res.guggy.com/logo_128.png',
audio_url: 'http://www.w3schools.com/tags/horse.mp3',
video_url: 'http://www.w3schools.com/tags/movie.mp4',
fields: [{
fields: [ {
short: true,
title: 'Test',
value: 'Testing out something or other'
}, {
short: true,
title: 'Another Test',
value: '[Link](https://google.com/) something and this and that.'
}]
}]
} ]
} ]
})
.expect('Content-Type', 'application/json')
.expect(200)
Expand All @@ -163,6 +158,7 @@ describe('[Chat]', function() {
})
.end(done);
});

});

describe('/chat.getMessage', () => {
Expand Down Expand Up @@ -214,7 +210,7 @@ describe('[Chat]', function() {
alias: 'Gruggy',
emoji: ':smirk:',
avatar: 'http://res.guggy.com/logo_128.png',
attachments: [{
attachments: [ {
color: '#ff0000',
text: 'Yay for gruggy!',
ts: '2016-12-09T16:53:06.761Z',
Expand All @@ -231,7 +227,7 @@ describe('[Chat]', function() {
audio_url: 'http://www.w3schools.com/tags/horse.mp3',
video_url: 'http://www.w3schools.com/tags/movie.mp4',
fields: ''
}]
} ]
}
})
.expect('Content-Type', 'application/json')
Expand All @@ -255,7 +251,7 @@ describe('[Chat]', function() {
alias: 'Gruggy',
emoji: ':smirk:',
avatar: 'http://res.guggy.com/logo_128.png',
attachments: [{
attachments: [ {
color: '#ff0000',
text: 'Yay for gruggy!',
ts: '2016-12-09T16:53:06.761Z',
Expand All @@ -271,16 +267,16 @@ describe('[Chat]', function() {
image_url: 'http://res.guggy.com/logo_128.png',
audio_url: 'http://www.w3schools.com/tags/horse.mp3',
video_url: 'http://www.w3schools.com/tags/movie.mp4',
fields: [{
fields: [ {
short: true,
title: 'Test',
value: 'Testing out something or other'
}, {
short: true,
title: 'Another Test',
value: '[Link](https://google.com/) something and this and that.'
}]
}]
} ]
} ]
}
})
.expect('Content-Type', 'application/json')
Expand All @@ -291,6 +287,44 @@ describe('[Chat]', function() {
})
.end(done);
});

describe('Read only channel', () => {
let readOnlyChannel;

it('Creating a read-only channel', (done) => {
request.post(api('channels.create'))
.set(credentials)
.send({
name: `readonlychannel${ +new Date() }`,
readOnly: true
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
readOnlyChannel = res.body.channel;
})
.end(done);
});
it('should send a message when the user is the owner of a readonly channel', (done) => {
request.post(api('chat.sendMessage'))
.set(credentials)
.send({
message: {
rid: readOnlyChannel._id,
msg: 'Sample message'
}
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('message').and.to.be.an('object');
})
.end(done);
});
});

});

describe('/chat.update', () => {
Expand Down