Improve room types usage (#16753)

pull/17076/head
Guilherme Gazzo 6 years ago committed by GitHub
parent 6914d1141a
commit 0ace4aa328
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/api/server/v1/im.js
  2. 24
      app/channel-settings/client/views/channelSettings.js
  3. 2
      app/channel-settings/server/functions/saveRoomName.js
  4. 5
      app/channel-settings/server/functions/saveRoomType.js
  5. 3
      app/channel-settings/server/methods/saveRoomSettings.js
  6. 3
      app/e2e/client/rocketchat.e2e.room.js
  7. 4
      app/file-upload/server/lib/FileUpload.js
  8. 5
      app/lib/lib/roomTypes/direct.js
  9. 4
      app/lib/lib/roomTypes/private.js
  10. 4
      app/lib/lib/roomTypes/public.js
  11. 7
      app/lib/server/functions/getDirectMessageByNameOrIdWithOptionToJoin.js
  12. 5
      app/lib/server/functions/processWebhookMessage.js
  13. 9
      app/lib/server/methods/archiveRoom.js
  14. 5
      app/lib/server/methods/joinRoom.js
  15. 7
      app/lib/server/methods/leaveRoom.js
  16. 3
      app/slashcommands-unarchiveroom/server/server.js
  17. 2
      app/ui-admin/client/rooms/adminRooms.js
  18. 16
      app/ui-flextab/client/tabs/membersList.js
  19. 36
      app/ui-flextab/client/tabs/userActions.js
  20. 2
      app/ui-sidenav/client/roomList.js
  21. 4
      app/ui-utils/client/lib/ChannelActions.js
  22. 4
      app/ui/client/views/app/createChannel.js
  23. 2
      app/ui/client/views/app/room.js
  24. 2
      app/utils/client/index.js
  25. 19
      app/utils/lib/RoomTypeConfig.js
  26. 2
      app/utils/server/index.js
  27. 2
      server/methods/eraseRoom.js
  28. 7
      server/methods/muteUserInRoom.js
  29. 3
      server/methods/removeUserFromRoom.js
  30. 3
      server/methods/unmuteUserInRoom.js

@ -1,26 +1,25 @@
import { Meteor } from 'meteor/meteor';
import { getRoomByNameOrIdWithOptionToJoin } from '../../../lib';
import { Subscriptions, Uploads, Users, Messages, Rooms } from '../../../models';
import { hasPermission } from '../../../authorization';
import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser';
import { settings } from '../../../settings';
import { API } from '../api';
import { getDirectMessageByNameOrIdWithOptionToJoin } from '../../../lib/server/functions/getDirectMessageByNameOrIdWithOptionToJoin';
function findDirectMessageRoom(params, user) {
if ((!params.roomId || !params.roomId.trim()) && (!params.username || !params.username.trim())) {
throw new Meteor.Error('error-room-param-not-provided', 'Body param "roomId" or "username" is required');
}
const room = getRoomByNameOrIdWithOptionToJoin({
const room = getDirectMessageByNameOrIdWithOptionToJoin({
currentUserId: user._id,
nameOrId: params.username || params.roomId,
type: 'd',
});
const canAccess = Meteor.call('canAccessRoom', room._id, user._id);
if (!canAccess || !room || room.t !== 'd') {
throw new Meteor.Error('error-room-not-found', 'The required "roomId" or "username" param provided does not match any dirct message');
throw new Meteor.Error('error-room-not-found', 'The required "roomId" or "username" param provided does not match any direct message');
}
const subscription = Subscriptions.findOneByRoomIdAndUserId(room._id, user._id);

@ -29,7 +29,7 @@ const common = {
});
const roomType = room && room.t;
return roomType && roomTypes.roomTypes[roomType].canBeDeleted(hasPermission, room);
return roomType && roomTypes.getConfig(roomType).canBeDeleted(hasPermission, room);
},
canEditRoom() {
const { _id } = Template.instance().room;
@ -223,7 +223,7 @@ Template.channelSettingsEditing.onCreated(function() {
type: 'text',
label: 'Name',
canView() {
return roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.NAME);
return roomTypes.getConfig(room.t).allowRoomSettingChange(room, RoomSettingsEnum.NAME);
},
canEdit() {
return hasAllPermission('edit-room', room._id);
@ -270,7 +270,7 @@ Template.channelSettingsEditing.onCreated(function() {
type: 'markdown',
label: 'Topic',
canView() {
return roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.TOPIC);
return roomTypes.getConfig(room.t).allowRoomSettingChange(room, RoomSettingsEnum.TOPIC);
},
canEdit() {
return hasAllPermission('edit-room', room._id);
@ -289,7 +289,7 @@ Template.channelSettingsEditing.onCreated(function() {
return Template.instance().room.announcement;
},
canView() {
return roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.ANNOUNCEMENT);
return roomTypes.getConfig(room.t).allowRoomSettingChange(room, RoomSettingsEnum.ANNOUNCEMENT);
},
canEdit() {
return hasAllPermission('edit-room', room._id);
@ -305,7 +305,7 @@ Template.channelSettingsEditing.onCreated(function() {
type: 'text',
label: 'Description',
canView() {
return roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.DESCRIPTION);
return roomTypes.getConfig(room.t).allowRoomSettingChange(room, RoomSettingsEnum.DESCRIPTION);
},
canEdit() {
return hasAllPermission('edit-room', room._id);
@ -386,7 +386,7 @@ Template.channelSettingsEditing.onCreated(function() {
isToggle: true,
processing: new ReactiveVar(false),
canView() {
return roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.READ_ONLY);
return roomTypes.getConfig(room.t).allowRoomSettingChange(room, RoomSettingsEnum.READ_ONLY);
},
canEdit() {
return !room.broadcast && hasAllPermission('set-readonly', room._id);
@ -401,7 +401,7 @@ Template.channelSettingsEditing.onCreated(function() {
isToggle: true,
processing: new ReactiveVar(false),
canView() {
return roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.REACT_WHEN_READ_ONLY);
return roomTypes.getConfig(room.t).allowRoomSettingChange(room, RoomSettingsEnum.REACT_WHEN_READ_ONLY);
},
canEdit() {
return !room.broadcast && hasAllPermission('set-react-when-readonly', room._id);
@ -418,7 +418,7 @@ Template.channelSettingsEditing.onCreated(function() {
isToggle: true,
processing: new ReactiveVar(false),
canView() {
return roomTypes.roomTypes[room.t].allowRoomSettingChange(
return roomTypes.getConfig(room.t).allowRoomSettingChange(
room,
RoomSettingsEnum.SYSTEM_MESSAGES,
);
@ -460,7 +460,7 @@ Template.channelSettingsEditing.onCreated(function() {
isToggle: true,
processing: new ReactiveVar(false),
canView() {
return roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.ARCHIVE_OR_UNARCHIVE);
return roomTypes.getConfig(room.t).allowRoomSettingChange(room, RoomSettingsEnum.ARCHIVE_OR_UNARCHIVE);
},
canEdit() {
return hasAtLeastOnePermission(['archive-room', 'unarchive-room'], room._id);
@ -501,7 +501,7 @@ Template.channelSettingsEditing.onCreated(function() {
isToggle: true,
processing: new ReactiveVar(false),
canView() {
return roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.BROADCAST);
return roomTypes.getConfig(room.t).allowRoomSettingChange(room, RoomSettingsEnum.BROADCAST);
},
canEdit() {
return false;
@ -516,7 +516,7 @@ Template.channelSettingsEditing.onCreated(function() {
showingValue: new ReactiveVar(false),
realValue: null,
canView() {
return roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.JOIN_CODE) && hasAllPermission('edit-room', room._id);
return roomTypes.getConfig(room.t).allowRoomSettingChange(room, RoomSettingsEnum.JOIN_CODE) && hasAllPermission('edit-room', room._id);
},
canEdit() {
return hasAllPermission('edit-room', room._id);
@ -679,7 +679,7 @@ Template.channelSettingsEditing.onCreated(function() {
isToggle: true,
processing: new ReactiveVar(false),
canView() {
return roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.E2E);
return roomTypes.getConfig(room.t).allowRoomSettingChange(room, RoomSettingsEnum.E2E);
},
canEdit() {
return hasAllPermission('edit-room', room._id);

@ -14,7 +14,7 @@ const updateRoomName = (rid, displayName, isDiscussion) => {
export const saveRoomName = function(rid, displayName, user, sendMessage = true) {
const room = Rooms.findOneById(rid);
if (roomTypes.roomTypes[room.t].preventRenaming()) {
if (roomTypes.getConfig(room.t).preventRenaming()) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
function: 'RocketChat.saveRoomdisplayName',
});

@ -4,6 +4,7 @@ import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { Rooms, Subscriptions, Messages } from '../../../models';
import { settings } from '../../../settings';
import { roomTypes, RoomSettingsEnum } from '../../../utils';
export const saveRoomType = function(rid, roomType, user, sendMessage = true) {
if (!Match.test(rid, String)) {
@ -24,11 +25,13 @@ export const saveRoomType = function(rid, roomType, user, sendMessage = true) {
_id: rid,
});
}
if (room.t === 'd') {
if (!roomTypes.getConfig(room.t).allowRoomSettingChange(room, RoomSettingsEnum.TYPE)) {
throw new Meteor.Error('error-direct-room', 'Can\'t change type of direct rooms', {
function: 'RocketChat.saveRoomType',
});
}
const result = Rooms.setTypeById(rid, roomType) && Subscriptions.updateTypeByRoomId(rid, roomType);
if (result && sendMessage) {
let message;

@ -15,6 +15,7 @@ import { saveReactWhenReadOnly } from '../functions/saveReactWhenReadOnly';
import { saveRoomSystemMessages } from '../functions/saveRoomSystemMessages';
import { saveRoomTokenpass } from '../functions/saveRoomTokens';
import { saveStreamingOptions } from '../functions/saveStreamingOptions';
import { RoomSettingsEnum, roomTypes } from '../../../utils';
const fields = ['roomName', 'roomTopic', 'roomAnnouncement', 'roomCustomFields', 'roomDescription', 'roomType', 'readOnly', 'reactWhenReadOnly', 'systemMessages', 'default', 'joinCode', 'tokenpass', 'streamingOptions', 'retentionEnabled', 'retentionMaxAge', 'retentionExcludePinned', 'retentionFilesOnly', 'retentionOverrideGlobal', 'encrypted'];
Meteor.methods({
@ -90,7 +91,7 @@ Meteor.methods({
action: 'Change_Room_Type',
});
}
if (setting === 'encrypted' && value !== room.encrypted && (room.t !== 'd' && room.t !== 'p')) {
if (setting === 'encrypted' && value !== room.encrypted && !roomTypes.getConfig(room.t).allowRoomSettingChange(room, RoomSettingsEnum.E2E)) {
throw new Meteor.Error('error-action-not-allowed', 'Only groups or direct channels can enable encryption', {
method: 'saveRoomSettings',
action: 'Change_Room_Encrypted',

@ -25,6 +25,7 @@ import {
import { Notifications } from '../../notifications';
import { Rooms, Subscriptions } from '../../models';
import { call } from '../../ui-utils';
import { roomTypes, RoomSettingsEnum } from '../../utils';
export class E2ERoom {
constructor(userId, roomId, t) {
@ -97,7 +98,7 @@ export class E2ERoom {
}
isSupportedRoomType(type) {
return ['d', 'p'].includes(type);
return roomTypes.getConfig(type).allowRoomSettingChange({}, RoomSettingsEnum.E2E);
}
async importGroupKey(groupKey) {

@ -64,7 +64,7 @@ export const FileUpload = {
const user = file.userId ? Meteor.users.findOne(file.userId) : null;
const room = Rooms.findOneById(file.rid);
const directMessageAllow = settings.get('FileUpload_Enabled_Direct');
const directMessageAllowed = settings.get('FileUpload_Enabled_Direct');
const fileUploadAllowed = settings.get('FileUpload_Enabled');
if (canAccessRoom(room, user, file) !== true) {
return false;
@ -75,7 +75,7 @@ export const FileUpload = {
throw new Meteor.Error('error-file-upload-disabled', reason);
}
if (!directMessageAllow && room.t === 'd') {
if (!directMessageAllowed && room.t === 'd') {
const reason = TAPi18n.__('File_not_allowed_direct_messages', language);
throw new Meteor.Error('error-direct-message-file-upload-not-allowed', reason);
}

@ -103,6 +103,7 @@ export class DirectMessageRoomType extends RoomTypeConfig {
allowRoomSettingChange(room, setting) {
switch (setting) {
case RoomSettingsEnum.TYPE:
case RoomSettingsEnum.NAME:
case RoomSettingsEnum.SYSTEM_MESSAGES:
case RoomSettingsEnum.DESCRIPTION:
@ -118,6 +119,10 @@ export class DirectMessageRoomType extends RoomTypeConfig {
}
}
allowMemberAction(/* room, action */) {
return false;
}
enableMembersListProfile() {
return true;
}

@ -98,6 +98,10 @@ export class PrivateRoomType extends RoomTypeConfig {
}
}
allowMemberAction(/* room, action */) {
return true;
}
enableMembersListProfile() {
return true;
}

@ -113,6 +113,10 @@ export class PublicRoomType extends RoomTypeConfig {
}
}
allowMemberAction(/* room, action */) {
return true;
}
getUiText(context) {
switch (context) {
case UiTextContext.HIDE_WARNING:

@ -0,0 +1,7 @@
import { getRoomByNameOrIdWithOptionToJoin } from './getRoomByNameOrIdWithOptionToJoin';
export const getDirectMessageByNameOrIdWithOptionToJoin = (args) =>
getRoomByNameOrIdWithOptionToJoin({ ...args, type: 'd' });
export const getDirectMessageByIdWithOptionToJoin = (args) =>
getDirectMessageByNameOrIdWithOptionToJoin({ ...args, tryDirectByUserIdOnly: true });

@ -5,6 +5,7 @@ import s from 'underscore.string';
import { getRoomByNameOrIdWithOptionToJoin } from './getRoomByNameOrIdWithOptionToJoin';
import { sendMessage } from './sendMessage';
import { Subscriptions } from '../../../models';
import { getDirectMessageByIdWithOptionToJoin, getDirectMessageByNameOrIdWithOptionToJoin } from './getDirectMessageByNameOrIdWithOptionToJoin';
export const processWebhookMessage = function(messageObj, user, defaultValues = { channel: '', alias: '', avatar: '', emoji: '' }, mustBeJoined = false) {
const sentData = [];
@ -21,7 +22,7 @@ export const processWebhookMessage = function(messageObj, user, defaultValues =
room = getRoomByNameOrIdWithOptionToJoin({ currentUserId: user._id, nameOrId: channelValue, joinChannel: true });
break;
case '@':
room = getRoomByNameOrIdWithOptionToJoin({ currentUserId: user._id, nameOrId: channelValue, type: 'd' });
room = getDirectMessageByNameOrIdWithOptionToJoin({ currentUserId: user._id, nameOrId: channelValue });
break;
default:
channelValue = channelType + channelValue;
@ -33,7 +34,7 @@ export const processWebhookMessage = function(messageObj, user, defaultValues =
}
// We didn't get a room, let's try finding direct messages
room = getRoomByNameOrIdWithOptionToJoin({ currentUserId: user._id, nameOrId: channelValue, type: 'd', tryDirectByUserIdOnly: true });
room = getDirectMessageByIdWithOptionToJoin({ currentUserId: user._id, nameOrId: channelValue });
if (room) {
break;
}

@ -4,6 +4,7 @@ import { check } from 'meteor/check';
import { Rooms } from '../../../models';
import { hasPermission } from '../../../authorization';
import { archiveRoom } from '../functions';
import { roomTypes, RoomMemberActions } from '../../../utils/server';
Meteor.methods({
archiveRoom(rid) {
@ -19,12 +20,12 @@ Meteor.methods({
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'archiveRoom' });
}
if (!hasPermission(Meteor.userId(), 'archive-room', room._id)) {
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'archiveRoom' });
if (!roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.ARCHIVE)) {
throw new Meteor.Error('error-direct-message-room', `rooms type: ${ room.t } can not be archived`, { method: 'archiveRoom' });
}
if (room.t === 'd') {
throw new Meteor.Error('error-direct-message-room', 'Direct Messages can not be archived', { method: 'archiveRoom' });
if (!hasPermission(Meteor.userId(), 'archive-room', room._id)) {
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'archiveRoom' });
}
return archiveRoom(rid);

@ -5,6 +5,7 @@ import { hasPermission, canAccessRoom } from '../../../authorization';
import { Rooms } from '../../../models';
import { Tokenpass, updateUserTokenpassBalances } from '../../../tokenpass/server';
import { addUserToRoom } from '../functions';
import { roomTypes, RoomMemberActions } from '../../../utils/server';
Meteor.methods({
joinRoom(rid, code) {
@ -20,6 +21,10 @@ Meteor.methods({
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'joinRoom' });
}
if (!roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.JOIN)) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'joinRoom' });
}
// TODO we should have a 'beforeJoinRoom' call back so external services can do their own validations
const user = Meteor.user();
if (room.tokenpass && user && user.services && user.services.tokenpass) {

@ -4,6 +4,7 @@ import { check } from 'meteor/check';
import { hasPermission, hasRole, getUsersInRole } from '../../../authorization';
import { Subscriptions, Rooms } from '../../../models';
import { removeUserFromRoom } from '../functions';
import { roomTypes, RoomMemberActions } from '../../../utils/server';
Meteor.methods({
leaveRoom(rid) {
@ -16,7 +17,11 @@ Meteor.methods({
const room = Rooms.findOneById(rid);
const user = Meteor.user();
if (room.t === 'd' || (room.t === 'c' && !hasPermission(user._id, 'leave-c')) || (room.t === 'p' && !hasPermission(user._id, 'leave-p'))) {
if (!roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.LEAVE)) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'leaveRoom' });
}
if ((room.t === 'c' && !hasPermission(user._id, 'leave-c')) || (room.t === 'p' && !hasPermission(user._id, 'leave-p'))) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'leaveRoom' });
}

@ -6,6 +6,7 @@ import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { Rooms, Messages } from '../../models';
import { slashCommands } from '../../utils';
import { Notifications } from '../../notifications';
import { roomTypes, RoomMemberActions } from '../../utils/server';
function Unarchive(command, params, item) {
if (command !== 'unarchive' || !Match.test(params, String)) {
@ -38,7 +39,7 @@ function Unarchive(command, params, item) {
}
// You can not archive direct messages.
if (room.t === 'd') {
if (!roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.ARCHIVE)) {
return;
}

@ -40,7 +40,7 @@ Template.adminRooms.helpers({
return Template.instance().rooms.get().length;
},
type() {
return TAPi18n.__(roomTypes.roomTypes[this.t].label);
return TAPi18n.__(roomTypes.getConfig(this.t).label);
},
'default'() {
if (this.default) {

@ -23,7 +23,7 @@ Template.membersList.helpers({
isGroupChat() {
const room = ChatRoom.findOne(this.rid, { reactive: false });
return roomTypes.roomTypes[room.t].isGroupChat();
return roomTypes.getConfig(room.t).isGroupChat();
},
isDirectChat() {
@ -98,7 +98,7 @@ Template.membersList.helpers({
canAddUser() {
const roomData = Session.get(`roomData${ this._id }`);
if (!roomData) { return ''; }
return (() => roomTypes.roomTypes[roomData.t].canAddUser(roomData))();
return (() => roomTypes.getConfig(roomData.t).canAddUser(roomData))();
},
canInviteUser() {
@ -123,10 +123,10 @@ Template.membersList.helpers({
tabBar: Template.currentData().tabBar,
username: Template.instance().userDetail.get(),
clear: Template.instance().clearUserDetail,
showAll: roomTypes.roomTypes[room.t].userDetailShowAll(room) || false,
hideAdminControls: roomTypes.roomTypes[room.t].userDetailShowAdmin(room) || false,
showAll: roomTypes.getConfig(room.t).userDetailShowAll(room) || false,
hideAdminControls: roomTypes.getConfig(room.t).userDetailShowAdmin(room) || false,
video: ['d'].includes(room && room.t),
showBackButton: roomTypes.roomTypes[room.t].isGroupChat(),
showBackButton: roomTypes.getConfig(room.t).isGroupChat(),
};
},
displayName() {
@ -183,8 +183,8 @@ Template.membersList.events({
const room = Session.get(`roomData${ instance.data.rid }`);
const _actions = getActions({
user: this.user.user,
hideAdminControls: roomTypes.roomTypes[room.t].userDetailShowAdmin(room) || false,
directActions: roomTypes.roomTypes[room.t].userDetailShowAll(room) || false,
hideAdminControls: roomTypes.getConfig(room.t).userDetailShowAdmin(room) || false,
directActions: roomTypes.getConfig(room.t).userDetailShowAll(room) || false,
})
.map((action) => (typeof action === 'function' ? action.call(this) : action))
.filter((action) => action && (!action.condition || action.condition.call(this)));
@ -235,7 +235,7 @@ Template.membersList.events({
'autocompleteselect #user-add-search'(event, template, doc) {
const roomData = Session.get(`roomData${ template.data.rid }`);
if (roomTypes.roomTypes[roomData.t].canAddUser(roomData)) {
if (roomTypes.getConfig(roomData.t).canAddUser(roomData)) {
return Meteor.call('addUserToRoom', { rid: roomData._id, username: doc.username }, function(error) {
if (error) {
return handleError(error);

@ -11,6 +11,7 @@ import { modal } from '../../../ui-utils';
import { t, handleError, roomTypes } from '../../../utils';
import { settings } from '../../../settings';
import { hasPermission, hasAllPermission, userHasAllPermission } from '../../../authorization';
import { RoomMemberActions } from '../../../utils/client';
const canSetLeader = () => hasAllPermission('set-leader', Session.get('openedRoom'));
@ -47,14 +48,10 @@ export const getActions = ({ user, directActions, hideAdminControls }) => {
user && user._id && !!RoomRoles.findOne({ rid: Session.get('openedRoom'), 'u._id': user._id, roles: 'owner' });
const isModerator = () =>
user && user._id && !!RoomRoles.findOne({ rid: Session.get('openedRoom'), 'u._id': user._id, roles: 'moderator' });
const isInDirectMessageRoom = () => {
const room = ChatRoom.findOne(Session.get('openedRoom'));
return (room && room.t) === 'd';
};
const isMuted = () => {
const room = ChatRoom.findOne(Session.get('openedRoom'));
const room = ChatRoom.findOne(Session.get('openedRoom'));
const isMuted = () => {
if (room && room.ro) {
if (_.isArray(room.unmuted) && room.unmuted.indexOf(user && user.username) !== -1) {
return false;
@ -188,7 +185,10 @@ export const getActions = ({ user, directActions, hideAdminControls }) => {
},
};
}, function() {
if (!directActions || !isInDirectMessageRoom() || isSelf(this.username)) {
if (!directActions || isSelf(this.username)) {
return;
}
if (!room || !roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.BLOCK)) {
return;
}
if (canBlockUser()) {
@ -208,6 +208,9 @@ export const getActions = ({ user, directActions, hideAdminControls }) => {
if (!directActions || !canSetOwner()) {
return;
}
if (!room || !roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.SET_AS_OWNER)) {
return;
}
if (isOwner()) {
return {
group: 'channel',
@ -243,6 +246,9 @@ export const getActions = ({ user, directActions, hideAdminControls }) => {
if (!directActions || !canSetLeader()) {
return;
}
if (!room || !roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.SET_AS_LEADER)) {
return;
}
if (isLeader()) {
return {
group: 'channel',
@ -279,6 +285,9 @@ export const getActions = ({ user, directActions, hideAdminControls }) => {
if (!directActions || !canSetModerator()) {
return;
}
if (!room || !roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.SET_AS_MODERATOR)) {
return;
}
if (isModerator()) {
return {
group: 'channel',
@ -315,6 +324,9 @@ export const getActions = ({ user, directActions, hideAdminControls }) => {
if (!directActions || user._id === Meteor.userId()) {
return;
}
if (!room || !roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.IGNORE)) {
return;
}
if (isIgnored()) {
return {
group: 'channel',
@ -333,6 +345,9 @@ export const getActions = ({ user, directActions, hideAdminControls }) => {
if (!directActions || !canMuteUser()) {
return;
}
if (!room || !roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.MUTE)) {
return;
}
if (isMuted()) {
return {
group: 'channel',
@ -412,7 +427,12 @@ export const getActions = ({ user, directActions, hideAdminControls }) => {
return this.instance.clear();
})));
}),
condition: () => directActions && canRemoveUser(),
condition: () => {
if (!room || !roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.REMOVE_USER)) {
return;
}
return directActions && canRemoveUser();
},
}, {
icon: 'edit',
name: 'Edit',

@ -128,7 +128,7 @@ Template.roomList.helpers({
if (instance.data.anonymous) {
return 'No_channels_yet';
}
return roomTypes.roomTypes[instance.data.identifier].getUiText(UiTextContext.NO_ROOMS_SUBSCRIBED) || 'No_channels_yet';
return roomTypes.getConfig(instance.data.identifier).getUiText(UiTextContext.NO_ROOMS_SUBSCRIBED) || 'No_channels_yet';
},
});

@ -7,7 +7,7 @@ import { RoomManager } from './RoomManager';
import { t, UiTextContext, roomTypes, handleError } from '../../../utils';
export function hide(type, rid, name) {
const warnText = roomTypes.roomTypes[type].getUiText(UiTextContext.HIDE_WARNING);
const warnText = roomTypes.getConfig(type).getUiText(UiTextContext.HIDE_WARNING);
modal.open({
title: t('Are_you_sure'),
@ -37,7 +37,7 @@ export function hide(type, rid, name) {
}
export async function leave(type, rid, name) {
const warnText = roomTypes.roomTypes[type].getUiText(UiTextContext.LEAVE_WARNING);
const warnText = roomTypes.getConfig(type).getUiText(UiTextContext.LEAVE_WARNING);
modal.open({
title: t('Are_you_sure'),

@ -157,7 +157,7 @@ Template.createChannel.helpers({
return roomTypes.roomTypesOrder.filter(
(roomTypeOrder) => roomTypeOrder.order < orderLow,
).map(
(roomTypeOrder) => roomTypes.roomTypes[roomTypeOrder.identifier],
(roomTypeOrder) => roomTypes.getConfig(roomTypeOrder.identifier),
).filter((roomType) => roomType.creationTemplate);
},
roomTypesAfterStandard() {
@ -165,7 +165,7 @@ Template.createChannel.helpers({
return roomTypes.roomTypesOrder.filter(
(roomTypeOrder) => roomTypeOrder.order > orderHigh,
).map(
(roomTypeOrder) => roomTypes.roomTypes[roomTypeOrder.identifier],
(roomTypeOrder) => roomTypes.getConfig(roomTypeOrder.identifier),
).filter((roomType) => roomType.creationTemplate);
},
});

@ -59,7 +59,7 @@ const openProfileTab = (e, instance, username) => {
}
const roomData = Session.get(`roomData${ RoomManager.openedRoom }`);
if (roomTypes.roomTypes[roomData.t].enableMembersListProfile()) {
if (roomTypes.getConfig(roomData.t).enableMembersListProfile()) {
instance.userDetail.set(username);
}

@ -6,7 +6,7 @@ export { handleError } from './lib/handleError';
export { getUserPreference } from '../lib/getUserPreference';
export { fileUploadMediaWhiteList, fileUploadIsValidContentType } from '../lib/fileUploadRestrictions';
export { roomTypes } from './lib/roomTypes';
export { RoomTypeRouteConfig, RoomTypeConfig, RoomSettingsEnum, UiTextContext } from '../lib/RoomTypeConfig';
export { RoomTypeRouteConfig, RoomTypeConfig, RoomSettingsEnum, RoomMemberActions, UiTextContext } from '../lib/RoomTypeConfig';
export { RoomTypesCommon } from '../lib/RoomTypesCommon';
export { getUserAvatarURL } from '../lib/getUserAvatarURL';
export { slashCommands } from '../lib/slashCommand';

@ -11,6 +11,7 @@ if (Meteor.isServer) {
}
export const RoomSettingsEnum = {
TYPE: 'type',
NAME: 'roomName',
TOPIC: 'roomTopic',
ANNOUNCEMENT: 'roomAnnouncement',
@ -24,6 +25,20 @@ export const RoomSettingsEnum = {
E2E: 'encrypted',
};
export const RoomMemberActions = {
ARCHIVE: 'archive',
IGNORE: 'ignore',
BLOCK: 'block',
MUTE: 'mute',
SET_AS_OWNER: 'setAsOwner',
SET_AS_LEADER: 'setAsLeader',
SET_AS_MODERATOR: 'setAsModerator',
LEAVE: 'leave',
REMOVE_USER: 'removeUser',
JOIN: 'join',
INVITE: 'invite',
};
export const UiTextContext = {
CLOSE_WARNING: 'closeWarning',
HIDE_WARNING: 'hideWarning',
@ -154,6 +169,10 @@ export class RoomTypeConfig {
return true;
}
allowMemberAction(/* room, action */) {
return false;
}
/**
* Return a room's name
*

@ -4,7 +4,7 @@ export { Info } from '../rocketchat.info';
export { getUserPreference } from '../lib/getUserPreference';
export { fileUploadMediaWhiteList, fileUploadIsValidContentType } from '../lib/fileUploadRestrictions';
export { roomTypes } from './lib/roomTypes';
export { RoomTypeRouteConfig, RoomTypeConfig, RoomSettingsEnum, UiTextContext } from '../lib/RoomTypeConfig';
export { RoomTypeRouteConfig, RoomTypeConfig, RoomSettingsEnum, RoomMemberActions, UiTextContext } from '../lib/RoomTypeConfig';
export { RoomTypesCommon } from '../lib/RoomTypesCommon';
export { isDocker } from './functions/isDocker';
export { getMongoInfo } from './functions/getMongoInfo';

@ -25,7 +25,7 @@ Meteor.methods({
});
}
if (!roomTypes.roomTypes[room.t].canBeDeleted(hasPermission, room)) {
if (!roomTypes.getConfig(room.t).canBeDeleted(hasPermission, room)) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'eraseRoom',
});

@ -4,6 +4,7 @@ import { Match, check } from 'meteor/check';
import { Rooms, Subscriptions, Users, Messages } from '../../app/models';
import { hasPermission } from '../../app/authorization';
import { callbacks } from '../../app/callbacks';
import { roomTypes, RoomMemberActions } from '../../app/utils/server';
Meteor.methods({
muteUserInRoom(data) {
@ -34,7 +35,7 @@ Meteor.methods({
});
}
if (['c', 'p'].includes(room.t) === false) {
if (!roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.MUTE)) {
throw new Meteor.Error('error-invalid-room-type', `${ room.t } is not a valid room type`, {
method: 'muteUserInRoom',
type: room.t,
@ -63,9 +64,7 @@ Meteor.methods({
},
});
Meteor.defer(function() {
callbacks.run('afterMuteUser', { mutedUser, fromUser }, room);
});
callbacks.run('afterMuteUser', { mutedUser, fromUser }, room);
return true;
},

@ -4,6 +4,7 @@ import { Match, check } from 'meteor/check';
import { hasPermission, hasRole, getUsersInRole, removeUserFromRoles } from '../../app/authorization';
import { Users, Subscriptions, Rooms, Messages } from '../../app/models';
import { callbacks } from '../../app/callbacks';
import { roomTypes, RoomMemberActions } from '../../app/utils/server';
Meteor.methods({
removeUserFromRoom(data) {
@ -28,7 +29,7 @@ Meteor.methods({
const room = Rooms.findOneById(data.rid);
if (!room || room.t === 'd') {
if (!room || !roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.REMOVE_USER)) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'removeUserFromRoom',
});

@ -4,6 +4,7 @@ import { Match, check } from 'meteor/check';
import { hasPermission } from '../../app/authorization';
import { callbacks } from '../../app/callbacks';
import { Rooms, Subscriptions, Users, Messages } from '../../app/models';
import { RoomMemberActions, roomTypes } from '../../app/utils/server';
Meteor.methods({
unmuteUserInRoom(data) {
@ -28,7 +29,7 @@ Meteor.methods({
});
}
if (['c', 'p'].includes(room.t) === false) {
if (!roomTypes.getConfig(room.t).allowMemberAction(room, RoomMemberActions.MUTE)) {
throw new Meteor.Error('error-invalid-room-type', `${ room.t } is not a valid room type`, {
method: 'unmuteUserInRoom',
type: room.t,

Loading…
Cancel
Save