Skip to content

Commit

Permalink
Merge pull request #8527 from RocketChat/do-not-send-joincode-field-t…
Browse files Browse the repository at this point in the history
…o-clients

[FIX] Do not send joinCode field to clients
  • Loading branch information
rodrigok authored Oct 18, 2017
2 parents fc23133 + aa8e6c8 commit 7a7e927
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ html.rtl .flex-tab {
}
}

& .button.edit {
& .button {
display: inline-block;
visibility: hidden;

Expand Down Expand Up @@ -111,12 +111,14 @@ html.rtl .flex-tab {

font-size: 0;

display: flex;

& .loading-animation {
top: 30px;
}

&:hover {
& .button.edit {
& .button {
visibility: visible;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ <h2>{{_ "Room_Info"}}</h2>
</button>
</div>
{{else}}
{{#if $value.showHideValue room}}
<button type="button" class="button show">
<i class="{{#if showingValue $key}}icon-eye-off{{else}}icon-eye{{/if}}"></i>
</button>
{{/if}}
<button type="button" class="button edit">
<i class="icon-pencil" data-edit="{{$key}}"></i>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ Template.channelSettings.helpers({
}
});
return t(room && room.ro ? 'True' : 'False');
},
showingValue(field) {
const { showingValue } = Template.instance().settings[field];

return showingValue && showingValue.get();
}
});

Expand Down Expand Up @@ -111,10 +116,12 @@ Template.channelSettings.events({
t.saveSetting();
}
},
'click [data-edit], click .button.edit'(e, t) {
async 'click [data-edit], click .button.edit'(e, t) {
e.preventDefault();
let input = $(e.currentTarget);

await t.showValue(this.$key, true);

if (input.hasClass('button')) {
input = $(e.currentTarget).siblings('.current-setting');
}
Expand All @@ -126,6 +133,11 @@ Template.channelSettings.events({
}), 100);
}
},
'click .button.show'(e, t) {
e.preventDefault();

t.showValue(this.$key);
},
'change [type="radio"]'(e, t) {
return t.editing.set($(e.currentTarget).attr('name'));
},
Expand All @@ -135,7 +147,8 @@ Template.channelSettings.events({
},
'click .cancel'(e, t) {
e.preventDefault();
return t.editing.set();

t.cancelEditing(this.$key);
},
'click .save'(e, t) {
e.preventDefault();
Expand Down Expand Up @@ -404,14 +417,47 @@ Template.channelSettings.onCreated(function() {
joinCode: {
type: 'text',
label: 'Password',
showingValue: new ReactiveVar(false),
realValue: null,
canView(room) {
return room.t === 'c' && RocketChat.authz.hasAllPermission('edit-room', room._id);
},
canEdit(room) {
return RocketChat.authz.hasAllPermission('edit-room', room._id);
},
getValue(room) {
if (this.showingValue.get()) {
return this.realValue;
}
return room.joinCodeRequired ? '*****' : '';
},
showHideValue(room) {
return room.joinCodeRequired;
},
cancelEditing() {
this.showingValue.set(false);
this.realValue = null;
},
async showValue(room, forceShow = false) {
if (this.showingValue.get()) {
if (forceShow) {
return;
}
this.showingValue.set(false);
this.realValue = null;

return null;
}
return Meteor.call('getRoomJoinCode', room._id, (error, result) => {
if (error) {
return handleError(error);
}
this.realValue = result;
this.showingValue.set(true);
});
},
save(value, room) {
return Meteor.call('saveRoomSettings', room._id, 'joinCode', value, function(err) {
Meteor.call('saveRoomSettings', room._id, 'joinCode', value, function(err) {
if (err) {
return handleError(err);
}
Expand All @@ -421,7 +467,7 @@ Template.channelSettings.onCreated(function() {
}
}
};
return this.saveSetting = () => {
this.saveSetting = () => {
const room = ChatRoom.findOne(this.data && this.data.rid);
const field = this.editing.get();
let value;
Expand All @@ -435,6 +481,19 @@ Template.channelSettings.onCreated(function() {
if (value !== room[field]) {
this.settings[field].save(value, room);
}
return this.editing.set();

this.cancelEditing(field);
};
this.showValue = async(field, forceShow) => {
if (!this.settings[field].showValue) {
return;
}
const room = ChatRoom.findOne(this.data && this.data.rid);
return this.settings[field].showValue(room, forceShow);
};
this.cancelEditing = (field) => {
const { cancelEditing } = this.settings[field];
cancelEditing && cancelEditing.call(this.settings[field]);
this.editing.set();
};
});
1 change: 1 addition & 0 deletions packages/rocketchat-lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Package.onUse(function(api) {
api.addFiles('server/methods/filterATAllTag.js', 'server');
api.addFiles('server/methods/getChannelHistory.js', 'server');
api.addFiles('server/methods/getFullUserData.js', 'server');
api.addFiles('server/methods/getRoomJoinCode.js', 'server');
api.addFiles('server/methods/getRoomRoles.js', 'server');
api.addFiles('server/methods/getServerInfo.js', 'server');
api.addFiles('server/methods/getSingleMessage.js', 'server');
Expand Down
17 changes: 17 additions & 0 deletions packages/rocketchat-lib/server/methods/getRoomJoinCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Meteor.methods({
getRoomJoinCode(rid) {
check(rid, String);

if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getJoinCode' });
}

if (!RocketChat.authz.hasPermission(Meteor.userId(), 'view-join-code')) {
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'getJoinCode' });
}

const [ room ] = RocketChat.models.Rooms.findById(rid).fetch();

return room && room.joinCode;
}
});
2 changes: 1 addition & 1 deletion packages/rocketchat-theme/server/colors.less
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ input:-webkit-autofill {
}
}

.button.edit {
.button {
.buttonColors(lighten(@primary-font-color, 25%), @secondary-background-color);
}

Expand Down
9 changes: 1 addition & 8 deletions server/publications/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ const roomMap = (record, fields) => {
return {};
};

function getFieldsForUserId(userId) {
if (RocketChat.authz.hasPermission(userId, 'view-join-code')) {
return {
...fields,
joinCode: 1
};
}

function getFieldsForUserId(/*userId*/) {
return fields;
}

Expand Down
4 changes: 0 additions & 4 deletions server/startup/roomPublishes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ Meteor.startup(function() {
}
};

if (RocketChat.authz.hasPermission(this.userId, 'view-join-code')) {
options.fields.joinCode = 1;
}

if (RocketChat.authz.hasPermission(this.userId, 'view-c-room')) {
return RocketChat.models.Rooms.findByTypeAndName('c', identifier, options);
} else if (RocketChat.authz.hasPermission(this.userId, 'view-joined-room')) {
Expand Down

0 comments on commit 7a7e927

Please sign in to comment.