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] Allowing blocking a user on channels #17406

Merged
merged 1 commit into from
Apr 24, 2020
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
9 changes: 6 additions & 3 deletions app/authorization/server/functions/canSendMessage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { canAccessRoomAsync } from './canAccessRoom';
import { hasPermissionAsync } from './hasPermission';
import { Subscriptions, Rooms } from '../../../models/server/raw';
import { roomTypes, RoomMemberActions } from '../../../utils/server';

const subscriptionOptions = {
projection: {
Expand All @@ -16,9 +17,11 @@ export const canSendMessageAsync = async (rid, { uid, username, type }, extraDat
throw new Error('error-not-allowed');
}

const subscription = await Subscriptions.findOneByRoomIdAndUserId(rid, uid, subscriptionOptions);
if (subscription && (subscription.blocked || subscription.blocker)) {
throw new Error('room_is_blocked');
if (roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.BLOCK)) {
const subscription = await Subscriptions.findOneByRoomIdAndUserId(rid, uid, subscriptionOptions);
if (subscription && (subscription.blocked || subscription.blocker)) {
throw new Error('room_is_blocked');
}
}

if (room.ro === true && !await hasPermissionAsync(uid, 'post-readonly', rid)) {
Expand Down
11 changes: 8 additions & 3 deletions app/lib/lib/roomTypes/private.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ChatRoom, ChatSubscription } from '../../../models';
import { openRoom } from '../../../ui-utils';
import { settings } from '../../../settings';
import { hasAtLeastOnePermission, hasPermission } from '../../../authorization';
import { getUserPreference, RoomSettingsEnum, RoomTypeConfig, RoomTypeRouteConfig, UiTextContext, roomTypes } from '../../../utils';
import { getUserPreference, RoomSettingsEnum, RoomTypeConfig, RoomTypeRouteConfig, UiTextContext, roomTypes, RoomMemberActions } from '../../../utils';
import { getRoomAvatarURL } from '../../../utils/lib/getRoomAvatarURL';
import { getAvatarURL } from '../../../utils/lib/getAvatarURL';

Expand Down Expand Up @@ -98,8 +98,13 @@ export class PrivateRoomType extends RoomTypeConfig {
}
}

allowMemberAction(/* room, action */) {
return true;
allowMemberAction(room, action) {
switch (action) {
case RoomMemberActions.BLOCK:
return false;
default:
return true;
}
}

enableMembersListProfile() {
Expand Down
11 changes: 8 additions & 3 deletions app/lib/lib/roomTypes/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { openRoom } from '../../../ui-utils';
import { ChatRoom, ChatSubscription } from '../../../models';
import { settings } from '../../../settings';
import { hasAtLeastOnePermission } from '../../../authorization';
import { getUserPreference, RoomTypeConfig, RoomTypeRouteConfig, RoomSettingsEnum, UiTextContext } from '../../../utils';
import { getUserPreference, RoomTypeConfig, RoomTypeRouteConfig, RoomSettingsEnum, UiTextContext, RoomMemberActions } from '../../../utils';
import { getAvatarURL } from '../../../utils/lib/getAvatarURL';

export class PublicRoomRoute extends RoomTypeRouteConfig {
Expand Down Expand Up @@ -113,8 +113,13 @@ export class PublicRoomType extends RoomTypeConfig {
}
}

allowMemberAction(/* room, action */) {
return true;
allowMemberAction(room, action) {
switch (action) {
case RoomMemberActions.BLOCK:
return false;
default:
return true;
}
}

getUiText(context) {
Expand Down