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] Anonymous chat read #14717

Merged
merged 5 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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 app/emoji/client/emojiPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getEmojiElement = (emoji, image) => image && `<li class="emoji-${ emoji }

const createEmojiList = (category, actualTone) => {
const html = Object.values(emoji.packages).map((emojiPackage) => {
if (!emojiPackage.emojisByCategory[category]) {
if (!emojiPackage.emojisByCategory || !emojiPackage.emojisByCategory[category]) {
return;
}

Expand Down
4 changes: 0 additions & 4 deletions app/lib/server/methods/getSingleMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ Meteor.methods({
getSingleMessage(msgId) {
check(msgId, String);

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

const msg = Messages.findOneById(msgId);

if (!msg || !msg.rid) {
Expand Down
2 changes: 1 addition & 1 deletion app/ui-master/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Template.main.helpers({
const user = Meteor.user();

// User is already using 2fa
if (user.services.totp !== undefined && user.services.totp.enabled) {
if (!user || (user.services.totp !== undefined && user.services.totp.enabled)) {
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions app/ui-sidenav/client/roomList.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ Template.roomList.helpers({

noSubscriptionText() {
const instance = Template.instance();
if (instance.data.anonymous) {
return 'No_channels_yet';
}
return roomTypes.roomTypes[instance.data.identifier].getUiText(UiTextContext.NO_ROOMS_SUBSCRIBED) || 'No_channels_yet';
},

Expand Down
2 changes: 1 addition & 1 deletion app/ui-utils/client/lib/messageContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AutoTranslate } from '../../../autotranslate/client';
export function messageContext({ rid } = Template.instance()) {
const uid = Meteor.userId();
return {
u: Users.findOne({ _id: uid }, { fields: { name: 1, username: 1 } }),
u: Users.findOne({ _id: uid }, { fields: { name: 1, username: 1 } }) || {},
room: Rooms.findOne({ _id: rid }, {
reactive: false,
fields: {
Expand Down
10 changes: 9 additions & 1 deletion server/methods/browseChannels.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import s from 'underscore.string';
import { hasPermission } from '../../app/authorization';
import { Rooms, Users } from '../../app/models';
import { Federation } from '../../app/federation/server';
import { settings } from '../../app/settings/server';

const sortChannels = function(field, direction) {
switch (field) {
Expand Down Expand Up @@ -57,11 +58,13 @@ Meteor.methods({
limit,
};

const canViewAnonymous = settings.get('Accounts_AllowAnonymousRead') === true;

const user = Meteor.user();

if (type === 'channels') {
const sort = sortChannels(sortBy, sortDirection);
if (!hasPermission(user._id, 'view-c-room')) {
if ((!user && !canViewAnonymous) || (user && !hasPermission(user._id, 'view-c-room'))) {
return;
}

Expand All @@ -85,6 +88,11 @@ Meteor.methods({
};
}

// non-logged id user
if (!user) {
return;
}

// type === users
if (!hasPermission(user._id, 'view-outside-room') || !hasPermission(user._id, 'view-d-room')) {
return;
Expand Down