Skip to content

Commit

Permalink
Merge pull request #7444 from RocketChat/anonymous-user-join
Browse files Browse the repository at this point in the history
[FIX] Fix Anonymous User
  • Loading branch information
rodrigok committed Jul 14, 2017
2 parents 4c75b84 + f449375 commit eeb773a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/rocketchat-ui-flextab/client/tabs/membersList.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Template.membersList.helpers({
const roomUsers = Template.instance().users.get();
const room = ChatRoom.findOne(this.rid);
const roomMuted = (room != null ? room.muted : undefined) || [];
const userUtcOffset = Meteor.user().utcOffset;
const userUtcOffset = Meteor.user() && Meteor.user().utcOffset;
let totalOnline = 0;
let users = roomUsers.map(function(user) {
let utcOffset;
Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-ui-message/client/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Template.message.helpers({
roleTags() {
const user = Meteor.user();
// test user -> settings -> preferences -> hideRoles
if (!RocketChat.settings.get('UI_DisplayRoles') || ['settings', 'preferences', 'hideRoles'].reduce((obj, field) => typeof obj !== 'undefined' && obj[field], user)) {
if (!RocketChat.settings.get('UI_DisplayRoles') || (user && ['settings', 'preferences', 'hideRoles'].reduce((obj, field) => typeof obj !== 'undefined' && obj[field], user))) {
return [];
}

Expand Down Expand Up @@ -205,7 +205,7 @@ Template.message.helpers({
return true;
},
reactions() {
const userUsername = Meteor.user().username;
const userUsername = Meteor.user() && Meteor.user().username;
return Object.keys(this.reactions||{}).map(emoji => {
const reaction = this.reactions[emoji];
const total = reaction.usernames.length;
Expand Down
24 changes: 23 additions & 1 deletion packages/rocketchat-ui-message/client/messageBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Template.messageBox.helpers({
return RocketChat.settings.get('Message_ShowFormattingTips') && (RocketChat.Markdown || RocketChat.MarkdownCode || katexSyntax());
},
canJoin() {
return RocketChat.roomTypes.verifyShowJoinLink(this._id);
return Meteor.userId() && RocketChat.roomTypes.verifyShowJoinLink(this._id);
},
joinCodeRequired() {
const code = Session.get(`roomData${ this._id }`);
Expand Down Expand Up @@ -179,6 +179,13 @@ Template.messageBox.helpers({
},
showSandstorm() {
return Meteor.settings['public'].sandstorm && !Meteor.isCordova;
},

anonymousRead() {
return (Meteor.userId() == null) && RocketChat.settings.get('Accounts_AllowAnonymousRead') === true;
},
anonymousWrite() {
return (Meteor.userId() == null) && RocketChat.settings.get('Accounts_AllowAnonymousRead') === true && RocketChat.settings.get('Accounts_AllowAnonymousWrite') === true;
}
});

Expand Down Expand Up @@ -248,6 +255,21 @@ Template.messageBox.events({
}
});
},

'click .register'(event) {
event.stopPropagation();
event.preventDefault();
return Session.set('forceLogin', true);
},
'click .register-anonymous'(event) {
event.stopPropagation();
event.preventDefault();
return Meteor.call('registerUser', {}, function(error, loginData) {
if (loginData && loginData.token) {
return Meteor.loginWithToken(loginData.token);
}
});
},
'focus .input-message'(event, instance) {
KonchatNotification.removeRoomNotification(this._id);
chatMessages[this._id].input = instance.find('.input-message');
Expand Down
14 changes: 14 additions & 0 deletions packages/rocketchat-ui/client/views/app/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,16 @@ Template.room.helpers({
return true;
}

if (RocketChat.settings.get('Accounts_AllowAnonymousRead') === true) {
return true;
}

if (RocketChat.authz.hasAllPermission('preview-c-room')) {
return true;
}

return (RocketChat.models.Subscriptions.findOne({rid: this._id}) != null);

}
});

Expand Down Expand Up @@ -405,11 +410,17 @@ Template.room.events({
},

'click .flex-tab .user-image > button'(e, instance) {
if (!Meteor.userId()) {
return;
}
instance.tabBar.open();
return instance.setUserDetail(this.user.username);
},

'click .user-card-message'(e, instance) {
if (!Meteor.userId()) {
return;
}
const roomData = Session.get(`roomData${ this._arguments[1].rid }`);

if (RocketChat.Layout.isEmbedded()) {
Expand Down Expand Up @@ -476,6 +487,9 @@ Template.room.events({
},

'click .mention-link'(e, instance) {
if (!Meteor.userId()) {
return;
}
const channel = $(e.currentTarget).data('channel');
if (channel != null) {
if (RocketChat.Layout.isEmbedded()) {
Expand Down

0 comments on commit eeb773a

Please sign in to comment.