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

[FIX] Fix Anonymous User #7444

Merged
merged 1 commit into from
Jul 14, 2017
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
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 @@ -391,11 +396,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 @@ -462,6 +473,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