diff --git a/packages/rocketchat-authorization/server/functions/canAccessRoom.js b/packages/rocketchat-authorization/server/functions/canAccessRoom.js index faf4164698f58ea4dc6a54315244ea84f3656f74..82a6b761c1bbaf9dee841f0f28946da859a5a37f 100644 --- a/packages/rocketchat-authorization/server/functions/canAccessRoom.js +++ b/packages/rocketchat-authorization/server/functions/canAccessRoom.js @@ -2,7 +2,7 @@ RocketChat.authz.roomAccessValidators = [ function(room, user = {}) { if (room.t === 'c') { - if (!user._id && RocketChat.settings.get('Accounts_AllowAnonymousAccess') === true) { + if (!user._id && RocketChat.settings.get('Accounts_AllowAnonymousRead') === true) { return true; } diff --git a/packages/rocketchat-authorization/server/startup.js b/packages/rocketchat-authorization/server/startup.js index cf4ac5c7bd7224f2b9c91d5ab924212a3b86ce32..8715666f4eebce43b8258a97c3dd4f97ff796c66 100644 --- a/packages/rocketchat-authorization/server/startup.js +++ b/packages/rocketchat-authorization/server/startup.js @@ -46,20 +46,20 @@ Meteor.startup(function() { { _id: 'set-moderator', roles : ['admin', 'owner'] }, { _id: 'set-owner', roles : ['admin', 'owner'] }, { _id: 'unarchive-room', roles : ['admin'] }, - { _id: 'view-c-room', roles : ['admin', 'user', 'bot'] }, - { _id: 'view-d-room', roles : ['admin', 'user', 'bot'] }, + { _id: 'view-c-room', roles : ['admin', 'user', 'bot', 'anonymous'] }, + { _id: 'view-d-room', roles : ['admin', 'user', 'bot', 'anonymous'] }, { _id: 'view-full-other-user-info', roles : ['admin'] }, - { _id: 'view-history', roles : ['admin', 'user'] }, + { _id: 'view-history', roles : ['admin', 'user', 'anonymous'] }, { _id: 'view-joined-room', roles : ['guest', 'bot'] }, { _id: 'view-join-code', roles : ['admin'] }, { _id: 'view-logs', roles : ['admin'] }, { _id: 'view-other-user-channels', roles : ['admin'] }, - { _id: 'view-p-room', roles : ['admin', 'user'] }, + { _id: 'view-p-room', roles : ['admin', 'user', 'anonymous'] }, { _id: 'view-privileged-setting', roles : ['admin'] }, { _id: 'view-room-administration', roles : ['admin'] }, { _id: 'view-statistics', roles : ['admin'] }, { _id: 'view-user-administration', roles : ['admin'] }, - { _id: 'preview-c-room', roles : ['admin', 'user'] } + { _id: 'preview-c-room', roles : ['admin', 'user', 'anonymous'] } ]; for (const permission of permissions) { @@ -74,7 +74,8 @@ Meteor.startup(function() { { name: 'owner', scope: 'Subscriptions', description: 'Owner' }, { name: 'user', scope: 'Users', description: '' }, { name: 'bot', scope: 'Users', description: '' }, - { name: 'guest', scope: 'Users', description: '' } + { name: 'guest', scope: 'Users', description: '' }, + { name: 'anonymous', scope: 'Users', description: '' } ]; for (const role of defaultRoles) { diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 3c3fef7b1187238dbf4815cfbf3398308cf1fdf8..c21b26ab854306a3985d383bf3c4710977a7eeaf 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -17,7 +17,8 @@ "Accessing_permissions": "Accessing permissions", "Account_SID": "Account SID", "Accounts": "Accounts", - "Accounts_AllowAnonymousAccess": "Allow anonymous access", + "Accounts_AllowAnonymousRead": "Allow anonymous read", + "Accounts_AllowAnonymousWrite": "Allow anonymous write", "Accounts_AllowDeleteOwnAccount": "Allow users to delete own account", "Accounts_AllowedDomainsList": "Allowed Domains List", "Accounts_AllowedDomainsList_Description": "Comma-separated list of allowed domains", @@ -35,6 +36,7 @@ "Accounts_BlockedUsernameList": "Blocked Username List", "Accounts_BlockedUsernameList_Description": "Comma-separated list of blocked usernames (case-insensitive)", "Accounts_CustomFields_Description": "Should be a valid JSON where keys are the field names containing a dictionary of field settings. Example:<br/><code>{\n \"role\": {\n  \"type\": \"select\",\n  \"defaultValue\": \"student\",\n  \"options\": [\"teacher\", \"student\"],\n  \"required\": true,\n  \"modifyRecordField\": {\n   \"array\": true,\n   \"field\": \"roles\"\n  }\n },\n \"twitter\": {\n  \"type\": \"text\",\n  \"required\": true,\n  \"minLength\": 2,\n  \"maxLength\": 10\n }\n}</code> ", + "Accounts_DefaultUsernamePrefixSuggestion": "Default username prefix suggestion", "Accounts_denyUnverifiedEmail": "Deny unverified email", "Accounts_EmailVerification": "Email Verification", "Accounts_EmailVerification_Description": "Make sure you have correct SMTP settings to use this feature", @@ -1124,6 +1126,7 @@ "or": "or", "Open_your_authentication_app_and_enter_the_code": "Open your authentication app and enter the code. You can also use one of your backup codes.", "Order": "Order", + "Or_talk_as_anonymous": "Or talk as anonymous", "OS_Arch": "OS Arch", "OS_Cpus": "OS CPU Count", "OS_Freemem": "OS Free Memory", @@ -1228,7 +1231,6 @@ "Register": "Register a new account", "Registration": "Registration", "Registration_Succeeded": "Registration Succeeded", - "Register_or_login_to_send_messages": "Register or login to send messages", "Registration_via_Admin": "Registration via Admin", "Regular_Expressions": "Regular Expressions", "Release": "Release", @@ -1363,6 +1365,7 @@ "Showing_archived_results": "<p>Showing <b>%s</b> archived results</p>", "Showing_online_users": "Showing: <b>__total_showing__</b>, Online: __online__, Total: __total__ users", "Showing_results": "<p>Showing <b>%s</b> results</p>", + "Sign_in_to_start_talking": "Sign in to start talking", "since_creation": "since %s", "Site_Name": "Site Name", "Site_Url": "Site URL", diff --git a/packages/rocketchat-lib/client/lib/openRoom.coffee b/packages/rocketchat-lib/client/lib/openRoom.coffee index 33e023abf9c97482f2c8a36f7eff1c08522e03d0..3130cd82a3e0f41ead8b19fd979e576125d94623 100644 --- a/packages/rocketchat-lib/client/lib/openRoom.coffee +++ b/packages/rocketchat-lib/client/lib/openRoom.coffee @@ -6,7 +6,7 @@ currentTracker = undefined Meteor.defer -> currentTracker = Tracker.autorun (c) -> user = Meteor.user() - if (user? and not user.username?) or (not user? and RocketChat.settings.get('Accounts_AllowAnonymousAccess') is false) + if (user? and not user.username?) or (not user? and RocketChat.settings.get('Accounts_AllowAnonymousRead') is false) BlazeLayout.render 'main' return diff --git a/packages/rocketchat-lib/server/methods/getRoomRoles.js b/packages/rocketchat-lib/server/methods/getRoomRoles.js index e35fdb3e33e96c1d93fbef85c6a9f653811a6dfe..4c7dc6c105f3e68e7544997fed42056d1bbc89c8 100644 --- a/packages/rocketchat-lib/server/methods/getRoomRoles.js +++ b/packages/rocketchat-lib/server/methods/getRoomRoles.js @@ -3,7 +3,7 @@ Meteor.methods({ check(rid, String); - if (!Meteor.userId() && RocketChat.settings.get('Accounts_AllowAnonymousAccess') === false) { + if (!Meteor.userId() && RocketChat.settings.get('Accounts_AllowAnonymousRead') === false) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getRoomRoles' }); } diff --git a/packages/rocketchat-lib/server/startup/settings.js b/packages/rocketchat-lib/server/startup/settings.js index b67af0cd860ffa1d1d8b1640c0f720b5907c47ec..f222176bb388af3e33fd09fd9ab7809bd5e3622a 100644 --- a/packages/rocketchat-lib/server/startup/settings.js +++ b/packages/rocketchat-lib/server/startup/settings.js @@ -8,10 +8,18 @@ RocketChat.settings.add('uniqueID', process.env.DEPLOYMENT_ID || Random.id(), { // if you add a node to the i18n.json with the same setting name but with `_Description` it will automatically work. RocketChat.settings.addGroup('Accounts', function() { - this.add('Accounts_AllowAnonymousAccess', false, { + this.add('Accounts_AllowAnonymousRead', false, { type: 'boolean', public: true }); + this.add('Accounts_AllowAnonymousWrite', false, { + type: 'boolean', + public: true, + enableQuery: { + _id: 'Accounts_AllowAnonymousRead', + value: true + } + }); this.add('Accounts_AllowDeleteOwnAccount', false, { type: 'boolean', 'public': true, @@ -62,7 +70,11 @@ RocketChat.settings.addGroup('Accounts', function() { type: 'boolean', 'public': true }); + this.section('Registration', function() { + this.add('Accounts_DefaultUsernamePrefixSuggestion', 'user', { + type: 'string' + }); this.add('Accounts_RequireNameForSignUp', true, { type: 'boolean', 'public': true @@ -145,6 +157,7 @@ RocketChat.settings.addGroup('Accounts', function() { i18nLabel: 'Custom_Fields' }); }); + this.section('Avatar', function() { this.add('Accounts_AvatarResize', true, { type: 'boolean' diff --git a/packages/rocketchat-lib/startup/defaultRoomTypes.js b/packages/rocketchat-lib/startup/defaultRoomTypes.js index 692ddb8765284bb94e760d9c2c1c6760df209af1..40fe79c9daf12417d55d6102592f5fc557f7f05b 100644 --- a/packages/rocketchat-lib/startup/defaultRoomTypes.js +++ b/packages/rocketchat-lib/startup/defaultRoomTypes.js @@ -28,7 +28,7 @@ RocketChat.roomTypes.add('c', 10, { }, condition() { - return RocketChat.authz.hasAtLeastOnePermission(['view-c-room', 'view-joined-room']) || RocketChat.settings.get('Accounts_AllowAnonymousAccess') === true; + return RocketChat.authz.hasAtLeastOnePermission(['view-c-room', 'view-joined-room']) || RocketChat.settings.get('Accounts_AllowAnonymousRead') === true; }, showJoinLink(roomId) { diff --git a/packages/rocketchat-ui-master/client/main.js b/packages/rocketchat-ui-master/client/main.js index ba187b5e968688c9a3c04bfb68820d774b7b5ba7..9e91eea36872af81eab8b181c983ef637197b076 100644 --- a/packages/rocketchat-ui-master/client/main.js +++ b/packages/rocketchat-ui-master/client/main.js @@ -110,7 +110,7 @@ Template.main.helpers({ return RocketChat.settings.get('Site_Name'); }, logged() { - if (Meteor.userId() != null || (RocketChat.settings.get('Accounts_AllowAnonymousAccess') === true && Session.get('forceLogin') !== true)) { + if (Meteor.userId() != null || (RocketChat.settings.get('Accounts_AllowAnonymousRead') === true && Session.get('forceLogin') !== true)) { $('html').addClass('noscroll').removeClass('scroll'); return true; } else { @@ -134,7 +134,7 @@ Template.main.helpers({ return ready; }, hasUsername() { - return (Meteor.userId() != null && Meteor.user().username != null) || (Meteor.userId() == null && RocketChat.settings.get('Accounts_AllowAnonymousAccess') === true); + return (Meteor.userId() != null && Meteor.user().username != null) || (Meteor.userId() == null && RocketChat.settings.get('Accounts_AllowAnonymousRead') === true); }, requirePasswordChange() { const user = Meteor.user(); diff --git a/packages/rocketchat-ui-message/client/messageBox.coffee b/packages/rocketchat-ui-message/client/messageBox.coffee index 0052f3046146981a2e81895ecaec7b6f854b9b29..2587fda0c301ecbd128e41861c4d0fd4e683bed1 100644 --- a/packages/rocketchat-ui-message/client/messageBox.coffee +++ b/packages/rocketchat-ui-message/client/messageBox.coffee @@ -124,8 +124,11 @@ Template.messageBox.helpers showSandstorm: -> return Meteor.settings.public.sandstorm && !Meteor.isCordova - isAnonymous: -> - return not Meteor.userId()? and RocketChat.settings.get('Accounts_AllowAnonymousAccess') is true + anonymousRead: -> + return not Meteor.userId()? and RocketChat.settings.get('Accounts_AllowAnonymousRead') is true + + anonymousWrite: -> + return not Meteor.userId()? and RocketChat.settings.get('Accounts_AllowAnonymousRead') is true and RocketChat.settings.get('Accounts_AllowAnonymousWrite') is true firefoxPasteUpload = (fn) -> user = navigator.userAgent.match(/Firefox\/(\d+)\.\d/) @@ -186,6 +189,15 @@ Template.messageBox.events event.preventDefault() Session.set('forceLogin', true) + 'click .register-anonymous': (event) -> + event.stopPropagation() + event.preventDefault() + + Meteor.call 'registerUser', {}, (error, loginData) -> + if loginData && loginData.token + Meteor.loginWithToken loginData.token + + 'focus .input-message': (event, instance) -> KonchatNotification.removeRoomNotification @_id chatMessages[@_id].input = instance.find('.input-message') diff --git a/packages/rocketchat-ui-message/client/messageBox.html b/packages/rocketchat-ui-message/client/messageBox.html index 02e98fe5a1072bbbcf279385ab5004ff0a8dd038..d8f6c14df52208a1db06d2f7f28347a61793892d 100644 --- a/packages/rocketchat-ui-message/client/messageBox.html +++ b/packages/rocketchat-ui-message/client/messageBox.html @@ -143,9 +143,12 @@ <button class="button join"><span><i class="icon-login"></i> {{_ "join"}}</span></button> </div> {{/if}} - {{#if isAnonymous}} + {{#if anonymousRead}} <div> - <button class="button register"><span><i class="icon-login"></i> {{_ "Register_or_login_to_send_messages"}}</span></button> + <button class="button register"><span>{{_ "Sign_in_to_start_talking"}}</span></button> + {{#if anonymousWrite}} + <button class="button register-anonymous"><span>{{_ "Or_talk_as_anonymous"}}</span></button> + {{/if}} </div> {{/if}} {{/with}} diff --git a/packages/rocketchat-ui-sidenav/client/accountBox.js b/packages/rocketchat-ui-sidenav/client/accountBox.js index d8dacd1406b2ab4408aa904f5410f1aa0f6a5e49..aecbaea264a4d3a0b89438b7db8fca1ea795fead 100644 --- a/packages/rocketchat-ui-sidenav/client/accountBox.js +++ b/packages/rocketchat-ui-sidenav/client/accountBox.js @@ -1,6 +1,6 @@ Template.accountBox.helpers({ myUserInfo() { - if (Meteor.user() == null && RocketChat.settings.get('Accounts_AllowAnonymousAccess')) { + if (Meteor.user() == null && RocketChat.settings.get('Accounts_AllowAnonymousRead')) { return { name: t('Anonymous'), status: 'online', @@ -50,7 +50,7 @@ Template.accountBox.events({ }, 'click .account-box'() { - if (Meteor.userId() == null && RocketChat.settings.get('Accounts_AllowAnonymousAccess')) { + if (Meteor.userId() == null && RocketChat.settings.get('Accounts_AllowAnonymousRead')) { return; } diff --git a/packages/rocketchat-ui/client/lib/accounts.js b/packages/rocketchat-ui/client/lib/accounts.js index 8d220aefcd8140538f81c5458fcf6c45ebb28ebd..5045fbff9dccef2d6b019959464fec6bd73cd9af 100644 --- a/packages/rocketchat-ui/client/lib/accounts.js +++ b/packages/rocketchat-ui/client/lib/accounts.js @@ -3,6 +3,7 @@ Accounts.onEmailVerificationLink(function(token, done) { Accounts.verifyEmail(token, function(error) { if (error == null) { toastr.success(t('Email_verified')); + Meteor.call('afterVerifyEmail'); } return done(); }); diff --git a/packages/rocketchat-ui/client/lib/collections.js b/packages/rocketchat-ui/client/lib/collections.js index 06b777c5ee6ce25be22d4c0d17ab8c807d07b393..3d95243fbce0653d373cbb94a9534095436fb176 100644 --- a/packages/rocketchat-ui/client/lib/collections.js +++ b/packages/rocketchat-ui/client/lib/collections.js @@ -17,7 +17,7 @@ RocketChat.models.Messages = _.extend({}, RocketChat.models.Messages, this.ChatM Meteor.startup(() => { Tracker.autorun(() => { - if (!Meteor.userId() && RocketChat.settings.get('Accounts_AllowAnonymousAccess') === true) { + if (!Meteor.userId() && RocketChat.settings.get('Accounts_AllowAnonymousRead') === true) { this.CachedChatRoom.init(); this.CachedChatSubscription.ready.set(true); } diff --git a/packages/rocketchat-ui/client/views/app/room.coffee b/packages/rocketchat-ui/client/views/app/room.coffee index 05f1646ef9ce023abf9a20278b2fd7e39625a9a0..edd6c1b8a5dc159718a37d7c0c5df6738a96ec65 100644 --- a/packages/rocketchat-ui/client/views/app/room.coffee +++ b/packages/rocketchat-ui/client/views/app/room.coffee @@ -181,7 +181,7 @@ Template.room.helpers if room.t isnt 'c' return true - if RocketChat.settings.get('Accounts_AllowAnonymousAccess') is true + if RocketChat.settings.get('Accounts_AllowAnonymousRead') is true return true if RocketChat.authz.hasAllPermission('preview-c-room') diff --git a/server/methods/afterVerifyEmail.js b/server/methods/afterVerifyEmail.js new file mode 100644 index 0000000000000000000000000000000000000000..7b92f596167bb016ec8df36ede3bee8d8f40cd06 --- /dev/null +++ b/server/methods/afterVerifyEmail.js @@ -0,0 +1,20 @@ +Meteor.methods({ + afterVerifyEmail() { + const userId = Meteor.userId(); + + if (!userId) { + throw new Meteor.Error('error-invalid-user', 'Invalid user', { + method: 'afterVerifyEmail' + }); + } + + const user = RocketChat.models.Users.findOneById(userId); + + const verifiedEmail = _.find(user.emails, (email) => email.verified); + + if (verifiedEmail) { + RocketChat.models.Roles.addUserRoles(user._id, 'user'); + RocketChat.models.Roles.removeUserRoles(user._id, 'anonymous'); + } + } +}); diff --git a/server/methods/canAccessRoom.js b/server/methods/canAccessRoom.js index 8c4a04ad98a97e31fd6907f00879ec05de5b0641..dbb1d468b448a67a6dfac2a5c72b648996756b66 100644 --- a/server/methods/canAccessRoom.js +++ b/server/methods/canAccessRoom.js @@ -5,7 +5,7 @@ Meteor.methods({ let user; - if (!userId && RocketChat.settings.get('Accounts_AllowAnonymousAccess') === false) { + if (!userId && RocketChat.settings.get('Accounts_AllowAnonymousRead') === false) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'canAccessRoom' }); diff --git a/server/methods/getUsernameSuggestion.js b/server/methods/getUsernameSuggestion.js index 30440f1513975c99ca3d758d6f4da27efb97bad3..265342330055420b71f316b1068329a233129faf 100644 --- a/server/methods/getUsernameSuggestion.js +++ b/server/methods/getUsernameSuggestion.js @@ -92,7 +92,7 @@ function generateSuggestion(user) { } if (usernames.length === 0 || usernames[0].length === 0) { - usernames.push('user'); + usernames.push(RocketChat.settings.get('Accounts_DefaultUsernamePrefixSuggestion')); } let index = 0; diff --git a/server/methods/loadHistory.js b/server/methods/loadHistory.js index 82f9d01590bb2cd8e8c0c1c9787ea2d67f28851d..01d1720ec5c0d85b759ae4f32c31baecc91d35b6 100644 --- a/server/methods/loadHistory.js +++ b/server/methods/loadHistory.js @@ -21,7 +21,7 @@ Meteor.methods({ loadHistory(rid, end, limit = 20, ls) { check(rid, String); - if (!Meteor.userId() && RocketChat.settings.get('Accounts_AllowAnonymousAccess') === false) { + if (!Meteor.userId() && RocketChat.settings.get('Accounts_AllowAnonymousRead') === false) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'loadHistory' }); @@ -34,7 +34,7 @@ Meteor.methods({ return false; } - const canAnonymous = RocketChat.settings.get('Accounts_AllowAnonymousAccess'); + const canAnonymous = RocketChat.settings.get('Accounts_AllowAnonymousRead'); const canPreview = RocketChat.authz.hasPermission(fromId, 'preview-c-room'); if (room.t === 'c' && !canAnonymous && !canPreview && room.usernames.indexOf(room.username) === -1) { return false; diff --git a/server/methods/registerUser.js b/server/methods/registerUser.js index a4e45bf0fa871bcf5ff7f6b9cae90ec716367751..17c0ceb71b149548bce2379f44efd857692ab760 100644 --- a/server/methods/registerUser.js +++ b/server/methods/registerUser.js @@ -1,11 +1,25 @@ Meteor.methods({ registerUser(formData) { - check(formData, Match.ObjectIncluding({ - email: String, - pass: String, - name: String, - secretURL: Match.Optional(String) - })); + const AllowAnonymousRead = RocketChat.settings.get('Accounts_AllowAnonymousRead'); + const AllowAnonymousWrite = RocketChat.settings.get('Accounts_AllowAnonymousWrite'); + if (AllowAnonymousRead === true && AllowAnonymousWrite === true && formData.email == null) { + const userId = Accounts.insertUserDoc({}, { + globalRoles: [ + 'anonymous' + ] + }); + + const { id, token } = Accounts._loginUser(this, userId); + + return { id, token }; + } else { + check(formData, Match.ObjectIncluding({ + email: String, + pass: String, + name: String, + secretURL: Match.Optional(String) + })); + } if (RocketChat.settings.get('Accounts_RegistrationForm') === 'Disabled') { throw new Meteor.Error('error-user-registration-disabled', 'User registration is disabled', { method: 'registerUser' }); diff --git a/server/methods/saveUserProfile.js b/server/methods/saveUserProfile.js index a70d7aab30f521a45c23302c785036ef1f7ba7a8..7f78f1c99e399c142121f52807efd991316c58aa 100644 --- a/server/methods/saveUserProfile.js +++ b/server/methods/saveUserProfile.js @@ -31,17 +31,6 @@ Meteor.methods({ } return true; } - if ((settings.newPassword) && RocketChat.settings.get('Accounts_AllowPasswordChange') === true) { - if (!checkPassword(user, settings.typedPassword)) { - throw new Meteor.Error('error-invalid-password', 'Invalid password', { - method: 'saveUserProfile' - }); - } - - Accounts.setPassword(Meteor.userId(), settings.newPassword, { - logout: false - }); - } if (settings.realname) { RocketChat.setRealName(Meteor.userId(), settings.realname); @@ -61,6 +50,19 @@ Meteor.methods({ Meteor.call('setEmail', settings.email); } + // Should be the last chack to prevent error when trying to check password for users without password + if ((settings.newPassword) && RocketChat.settings.get('Accounts_AllowPasswordChange') === true) { + if (!checkPassword(user, settings.typedPassword)) { + throw new Meteor.Error('error-invalid-password', 'Invalid password', { + method: 'saveUserProfile' + }); + } + + Accounts.setPassword(Meteor.userId(), settings.newPassword, { + logout: false + }); + } + RocketChat.models.Users.setProfile(Meteor.userId(), {}); RocketChat.saveCustomFields(Meteor.userId(), customFields); diff --git a/server/publications/room.js b/server/publications/room.js index 8ca4f3248a97d30264116aa1873220e1963fcd46..76a2f29ed1b841cb8978a884574b8363902ef1a0 100644 --- a/server/publications/room.js +++ b/server/publications/room.js @@ -40,7 +40,7 @@ const roomMap = (record) => { Meteor.methods({ 'rooms/get'(updatedAt) { if (!Meteor.userId()) { - if (RocketChat.settings.get('Accounts_AllowAnonymousAccess') === true) { + if (RocketChat.settings.get('Accounts_AllowAnonymousRead') === true) { return RocketChat.models.Rooms.findByDefaultAndTypes(true, ['c'], options).fetch(); } return []; @@ -59,7 +59,7 @@ Meteor.methods({ }, getRoomByTypeAndName(type, name) { - if (!Meteor.userId() && RocketChat.settings.get('Accounts_AllowAnonymousAccess') === false) { + if (!Meteor.userId() && RocketChat.settings.get('Accounts_AllowAnonymousRead') === false) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getRoomByTypeAndName' }); } diff --git a/server/publications/spotlight.js b/server/publications/spotlight.js index ceccb8f4c9e62b36e679cc3c5463ac24e6d6846f..babbe04290c01aa51d517110d8f6af10b63f755f 100644 --- a/server/publications/spotlight.js +++ b/server/publications/spotlight.js @@ -19,7 +19,7 @@ Meteor.methods({ const regex = new RegExp(s.trim(s.escapeRegExp(text)), 'i'); if (this.userId == null) { - if (RocketChat.settings.get('Accounts_AllowAnonymousAccess') === true) { + if (RocketChat.settings.get('Accounts_AllowAnonymousRead') === true) { result.rooms = RocketChat.models.Rooms.findByNameAndTypeNotDefault(regex, 'c', roomOptions).fetch(); } return result; diff --git a/server/startup/migrations/v093.js b/server/startup/migrations/v093.js new file mode 100644 index 0000000000000000000000000000000000000000..4ee2ed8f34b3f186045e94945267e309df6e9e62 --- /dev/null +++ b/server/startup/migrations/v093.js @@ -0,0 +1,12 @@ +RocketChat.Migrations.add({ + version: 93, + up() { + + if (RocketChat && RocketChat.models && RocketChat.models.Settings) { + const setting = RocketChat.models.Settings.findOne({ _id: 'Accounts_AllowAnonymousAccess' }); + if (setting && setting.value === true) { + RocketChat.models.Settings.update({ _id: 'Accounts_AllowAnonymousRead' }, { $set: { value: setting.value } }); + } + } + } +});