From b862ff576725c8e5783b1e1aacb7419d899a4c95 Mon Sep 17 00:00:00 2001 From: Marcos Spessatto Defendi Date: Fri, 15 Feb 2019 16:33:11 -0200 Subject: [PATCH] Remove dependency of RC namespace in root server folder - step 1 (#13390) * Remove some dependencies inside rocketchat-lib/client (#13210) * Move function to rc-utils * Change import from to export directly * Removing duplicated dependency and remove old code * Import some variables to remove dependency of RC namespace * Remove some dependencies inside rocketchat-lib/lib (#13212) * Move some functions from lib to rc-ui-utils * Move some functions from lib ro rc-utils * Remove hostname from RC namespace * Import variables to remove dependency of RC namespace * Remove some dependencies inside rocketchat-lib/server/functions (#13214) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Remove some dependencies inside rocketchat-lib/server/lib (#13217) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Remove some dependencies inside rocketchat-lib/server/methods (#13218) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Remove some dependencies inside rocketchat-lib/server/startup, publications... (#13222) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings (#13223) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export functions and lib function of rc-lib but keep it inside RC namespace (#13225) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Fix missed exports and re-add some functions to RC namespace * Import variables from functions and lib to remove RC namespace dependency (#13226) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm (#13227) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search (#13231) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search * Remove dependency of RC namespace in meteor saml (#13233) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search * Move CreadentialTokens model to rc-models * Move getUsernameSuggestion function and method from server/ to rc-lib * Remove dependency of RC namespace in meteor saml * Remove dependency of RC namespace in rc-theme (#13234) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search * Move CreadentialTokens model to rc-models * Move getUsernameSuggestion function and method from server/ to rc-lib * Remove dependency of RC namespace in meteor saml * Remove dependency of RC namespace in rc-theme * Remove dependency of RC namespace in rc-2fa (#13235) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search * Move CreadentialTokens model to rc-models * Move getUsernameSuggestion function and method from server/ to rc-lib * Remove dependency of RC namespace in meteor saml * Remove dependency of RC namespace in rc-theme * Move 2FA Users model to rc-models * Remove dependency of RC namespace in rc-2fa * Remove dependency of RC namespace in rc-action-links (#13236) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search * Move CreadentialTokens model to rc-models * Move getUsernameSuggestion function and method from server/ to rc-lib * Remove dependency of RC namespace in meteor saml * Remove dependency of RC namespace in rc-theme * Move 2FA Users model to rc-models * Remove dependency of RC namespace in rc-2fa * Remove dependency of RC namespace in rc-action-links * Add action links in the RC namespace * Remove dependency of RC namespace in rc-analytics and rc-assets (#13237) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search * Move CreadentialTokens model to rc-models * Move getUsernameSuggestion function and method from server/ to rc-lib * Remove dependency of RC namespace in meteor saml * Remove dependency of RC namespace in rc-theme * Move 2FA Users model to rc-models * Remove dependency of RC namespace in rc-2fa * Remove dependency of RC namespace in rc-action-links * Add action links in the RC namespace * Remove dependency of RC namespace in rc-analytics * Remove dependency of RC namespace in rc-assets * Add Assets in RC namespace * Rename Assets variable to avoid conflicts * Fix rename Assets * Remove dependency of RC namespace in rc-markdown, rc-autolinker and rc-autotranslate (#13240) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search * Move CreadentialTokens model to rc-models * Move getUsernameSuggestion function and method from server/ to rc-lib * Remove dependency of RC namespace in meteor saml * Remove dependency of RC namespace in rc-theme * Move 2FA Users model to rc-models * Remove dependency of RC namespace in rc-2fa * Remove dependency of RC namespace in rc-action-links * Add action links in the RC namespace * Remove dependency of RC namespace in rc-analytics * Remove dependency of RC namespace in rc-assets * Add Assets in RC namespace * Remove dependency of RC namespace in rc-autolinker * Move autotranslate models to rc-models * Partial remove dependency of Rc namespace in rc-autotranslate * Remove dependency of RC namespace in rc-markdown * Finish of remotion of RC namespace in rc-autotranslate * Import Autotranslate where it has been used * Fix lint * Rename Assets variable to avoid conflicts * Fix rename Assets * Fix wrong imports * Remove dependency of RC namespace in rc-blockstack, bot-helpers and cas (#13246) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search * Move CreadentialTokens model to rc-models * Move getUsernameSuggestion function and method from server/ to rc-lib * Remove dependency of RC namespace in meteor saml * Remove dependency of RC namespace in rc-theme * Move 2FA Users model to rc-models * Remove dependency of RC namespace in rc-2fa * Remove dependency of RC namespace in rc-action-links * Add action links in the RC namespace * Remove dependency of RC namespace in rc-analytics * Remove dependency of RC namespace in rc-assets * Add Assets in RC namespace * Remove dependency of RC namespace in rc-autolinker * Move autotranslate models to rc-models * Partial remove dependency of Rc namespace in rc-autotranslate * Remove dependency of RC namespace in rc-markdown * Finish of remotion of RC namespace in rc-autotranslate * Import Autotranslate where it has been used * Fix lint * Rename Assets variable to avoid conflicts * Fix rename Assets * Remove dependency of RC namespace in rc-blockstack * Remove RC dependency in bot-helpers * Remove RC dependency in rc-cas * Fix wrong imports * Remove dependency of RC namespace in rc-channel-settings (#13251) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search * Move CreadentialTokens model to rc-models * Move getUsernameSuggestion function and method from server/ to rc-lib * Remove dependency of RC namespace in meteor saml * Remove dependency of RC namespace in rc-theme * Move 2FA Users model to rc-models * Remove dependency of RC namespace in rc-2fa * Remove dependency of RC namespace in rc-action-links * Add action links in the RC namespace * Remove dependency of RC namespace in rc-analytics * Remove dependency of RC namespace in rc-assets * Add Assets in RC namespace * Remove dependency of RC namespace in rc-autolinker * Move autotranslate models to rc-models * Partial remove dependency of Rc namespace in rc-autotranslate * Remove dependency of RC namespace in rc-markdown * Finish of remotion of RC namespace in rc-autotranslate * Import Autotranslate where it has been used * Fix lint * Rename Assets variable to avoid conflicts * Fix rename Assets * Remove dependency of RC namespace in rc-blockstack * Remove RC dependency in bot-helpers * Remove RC dependency in rc-cas * Move some functions from tokenpass to channel settings and models * Move some function from livestream to channel settings * Remove dependency of RC namespace in rc-channel-settings * Fix wrong imports * readd saveRoomName to RC namespace * Remove dependency of RC namespace in rc-channel-mail-messages and cloud (#13254) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search * Move CreadentialTokens model to rc-models * Move getUsernameSuggestion function and method from server/ to rc-lib * Remove dependency of RC namespace in meteor saml * Remove dependency of RC namespace in rc-theme * Move 2FA Users model to rc-models * Remove dependency of RC namespace in rc-2fa * Remove dependency of RC namespace in rc-action-links * Add action links in the RC namespace * Remove dependency of RC namespace in rc-analytics * Remove dependency of RC namespace in rc-assets * Add Assets in RC namespace * Remove dependency of RC namespace in rc-autolinker * Move autotranslate models to rc-models * Partial remove dependency of Rc namespace in rc-autotranslate * Remove dependency of RC namespace in rc-markdown * Finish of remotion of RC namespace in rc-autotranslate * Import Autotranslate where it has been used * Fix lint * Rename Assets variable to avoid conflicts * Fix rename Assets * Remove dependency of RC namespace in rc-blockstack * Remove RC dependency in bot-helpers * Remove RC dependency in rc-cas * Move some functions from tokenpass to channel settings and models * Move some function from livestream to channel settings * Remove dependency of RC namespace in rc-channel-settings * Fix wrong imports * Remove dependency of RC namespace in rc-channel-mail-messages * Remove dependency of RC namespace in rc-cloud * Remove dependency of RC namespace in rc-colors, cors, crowd and dolphin (#13255) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search * Move CreadentialTokens model to rc-models * Move getUsernameSuggestion function and method from server/ to rc-lib * Remove dependency of RC namespace in meteor saml * Remove dependency of RC namespace in rc-theme * Move 2FA Users model to rc-models * Remove dependency of RC namespace in rc-2fa * Remove dependency of RC namespace in rc-action-links * Add action links in the RC namespace * Remove dependency of RC namespace in rc-analytics * Remove dependency of RC namespace in rc-assets * Add Assets in RC namespace * Remove dependency of RC namespace in rc-autolinker * Move autotranslate models to rc-models * Partial remove dependency of Rc namespace in rc-autotranslate * Remove dependency of RC namespace in rc-markdown * Finish of remotion of RC namespace in rc-autotranslate * Import Autotranslate where it has been used * Fix lint * Rename Assets variable to avoid conflicts * Fix rename Assets * Remove dependency of RC namespace in rc-blockstack * Remove RC dependency in bot-helpers * Remove RC dependency in rc-cas * Move some functions from tokenpass to channel settings and models * Move some function from livestream to channel settings * Remove dependency of RC namespace in rc-channel-settings * Fix wrong imports * Remove dependency of RC namespace in rc-channel-mail-messages * Remove dependency of RC namespace in rc-cloud * Remove dependency of RC namespace in rc-colors * Remove dependency of RC namespace in rc-cors * Remove dependency of RC namespace in rc-crowd * Remove dependency of RC namespace in rc-dolphin * Remove dependency of RC namespace in rc-emoji-custom and drupal (#13256) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search * Move CreadentialTokens model to rc-models * Move getUsernameSuggestion function and method from server/ to rc-lib * Remove dependency of RC namespace in meteor saml * Remove dependency of RC namespace in rc-theme * Move 2FA Users model to rc-models * Remove dependency of RC namespace in rc-2fa * Remove dependency of RC namespace in rc-action-links * Add action links in the RC namespace * Remove dependency of RC namespace in rc-analytics * Remove dependency of RC namespace in rc-assets * Add Assets in RC namespace * Remove dependency of RC namespace in rc-autolinker * Move autotranslate models to rc-models * Partial remove dependency of Rc namespace in rc-autotranslate * Remove dependency of RC namespace in rc-markdown * Finish of remotion of RC namespace in rc-autotranslate * Import Autotranslate where it has been used * Fix lint * Rename Assets variable to avoid conflicts * Fix rename Assets * Remove dependency of RC namespace in rc-blockstack * Remove RC dependency in bot-helpers * Remove RC dependency in rc-cas * Move some functions from tokenpass to channel settings and models * Move some function from livestream to channel settings * Remove dependency of RC namespace in rc-channel-settings * Fix wrong imports * Remove dependency of RC namespace in rc-channel-mail-messages * Remove dependency of RC namespace in rc-cloud * Remove dependency of RC namespace in rc-colors * Remove dependency of RC namespace in rc-cors * Remove dependency of RC namespace in rc-crowd * Remove dependency of RC namespace in rc-dolphin * Remove dependency of RC namespace in rc-drupal * Move Emoji custom server and client models to rc-models * Remove dependency of RC namespace in rc-emoji-custom * Remove dependency of RC namespace in rc-emojione, error-handler, gh-enterprise and gitlab (#13257) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search * Move CreadentialTokens model to rc-models * Move getUsernameSuggestion function and method from server/ to rc-lib * Remove dependency of RC namespace in meteor saml * Remove dependency of RC namespace in rc-theme * Move 2FA Users model to rc-models * Remove dependency of RC namespace in rc-2fa * Remove dependency of RC namespace in rc-action-links * Add action links in the RC namespace * Remove dependency of RC namespace in rc-analytics * Remove dependency of RC namespace in rc-assets * Add Assets in RC namespace * Remove dependency of RC namespace in rc-autolinker * Move autotranslate models to rc-models * Partial remove dependency of Rc namespace in rc-autotranslate * Remove dependency of RC namespace in rc-markdown * Finish of remotion of RC namespace in rc-autotranslate * Import Autotranslate where it has been used * Fix lint * Rename Assets variable to avoid conflicts * Fix rename Assets * Remove dependency of RC namespace in rc-blockstack * Remove RC dependency in bot-helpers * Remove RC dependency in rc-cas * Move some functions from tokenpass to channel settings and models * Move some function from livestream to channel settings * Remove dependency of RC namespace in rc-channel-settings * Fix wrong imports * Remove dependency of RC namespace in rc-channel-mail-messages * Remove dependency of RC namespace in rc-cloud * Remove dependency of RC namespace in rc-colors * Remove dependency of RC namespace in rc-cors * Remove dependency of RC namespace in rc-crowd * Remove dependency of RC namespace in rc-dolphin * Remove dependency of RC namespace in rc-drupal * Move Emoji custom server and client models to rc-models * Remove dependency of RC namespace in rc-emoji-custom * Remove dependency of RC namespace in rc-emojione * Remove dependency of RC namespace in rc-error-handler * Remove dependency of RC namespace in rc-gh-enterprise * Remove dependency of RC namespace in rc-gitlab * Remove dependency of RC namespace in rc-google-natural-language, grant, google-vision and highlight-words (#13258) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search * Move CreadentialTokens model to rc-models * Move getUsernameSuggestion function and method from server/ to rc-lib * Remove dependency of RC namespace in meteor saml * Remove dependency of RC namespace in rc-theme * Move 2FA Users model to rc-models * Remove dependency of RC namespace in rc-2fa * Remove dependency of RC namespace in rc-action-links * Add action links in the RC namespace * Remove dependency of RC namespace in rc-analytics * Remove dependency of RC namespace in rc-assets * Add Assets in RC namespace * Remove dependency of RC namespace in rc-autolinker * Move autotranslate models to rc-models * Partial remove dependency of Rc namespace in rc-autotranslate * Remove dependency of RC namespace in rc-markdown * Finish of remotion of RC namespace in rc-autotranslate * Import Autotranslate where it has been used * Fix lint * Rename Assets variable to avoid conflicts * Fix rename Assets * Remove dependency of RC namespace in rc-blockstack * Remove RC dependency in bot-helpers * Remove RC dependency in rc-cas * Move some functions from tokenpass to channel settings and models * Move some function from livestream to channel settings * Remove dependency of RC namespace in rc-channel-settings * Fix wrong imports * Remove dependency of RC namespace in rc-channel-mail-messages * Remove dependency of RC namespace in rc-cloud * Remove dependency of RC namespace in rc-colors * Remove dependency of RC namespace in rc-cors * Remove dependency of RC namespace in rc-crowd * Remove dependency of RC namespace in rc-dolphin * Remove dependency of RC namespace in rc-drupal * Move Emoji custom server and client models to rc-models * Remove dependency of RC namespace in rc-emoji-custom * Remove dependency of RC namespace in rc-emojione * Remove dependency of RC namespace in rc-error-handler * Remove dependency of RC namespace in rc-gh-enterprise * Remove dependency of RC namespace in rc-gitlab * Remove dependency of RC namespace in rc-google-natural-language * Remove dependency of RC namespace in rc-grant * Remove dependency of RC namespace in rc-highlight-words * Remove dependency of RC namespace in rc-google-vision * Fix lint * Remove dependency of RC namespace in rc-iframe-login and all imports, except hipchat-enterprise (#13259) * Move integrations models to rc-models * Move composeMessage function to rc-utils * Move PushNotifications class to push-notifications package * Import variables to remove dependency of RC namespace * Import variables to remove RC namespace dependency inside rc-lib/server/lib * Import variables to remove RC namespace inside rc-lib/server/methods * Import variables to remove dependency with RC namespace * Remove duplicated server settings located in rc-lib * Export function and lib function of rc-lib but keep it inside RC namespace * Import variables from functions and lib to remove RC namespace dependency * Remove dependency of RC namespace in rc-sandstorm * Remove dependency of RC namespace in chatpal-search * Move CreadentialTokens model to rc-models * Move getUsernameSuggestion function and method from server/ to rc-lib * Remove dependency of RC namespace in meteor saml * Remove dependency of RC namespace in rc-theme * Move 2FA Users model to rc-models * Remove dependency of RC namespace in rc-2fa * Remove dependency of RC namespace in rc-action-links * Add action links in the RC namespace * Remove dependency of RC namespace in rc-analytics * Remove dependency of RC namespace in rc-assets * Add Assets in RC namespace * Remove dependency of RC namespace in rc-autolinker * Move autotranslate models to rc-models * Partial remove dependency of Rc namespace in rc-autotranslate * Remove dependency of RC namespace in rc-markdown * Finish of remotion of RC namespace in rc-autotranslate * Import Autotranslate where it has been used * Fix lint * Rename Assets variable to avoid conflicts * Fix rename Assets * Remove dependency of RC namespace in rc-blockstack * Remove RC dependency in bot-helpers * Remove RC dependency in rc-cas * Move some functions from tokenpass to channel settings and models * Move some function from livestream to channel settings * Remove dependency of RC namespace in rc-channel-settings * Fix wrong imports * Remove dependency of RC namespace in rc-channel-mail-messages * Remove dependency of RC namespace in rc-cloud * Remove dependency of RC namespace in rc-colors * Remove dependency of RC namespace in rc-cors * Remove dependency of RC namespace in rc-crowd * Remove dependency of RC namespace in rc-dolphin * Remove dependency of RC namespace in rc-drupal * Move Emoji custom server and client models to rc-models * Remove dependency of RC namespace in rc-emoji-custom * Remove dependency of RC namespace in rc-emojione * Remove dependency of RC namespace in rc-error-handler * Remove dependency of RC namespace in rc-gh-enterprise * Remove dependency of RC namespace in rc-gitlab * Remove dependency of RC namespace in rc-google-natural-language * Remove dependency of RC namespace in rc-grant * Remove dependency of RC namespace in rc-highlight-words * Remove dependency of RC namespace in rc-google-vision * Fix lint * Remove dependency of RC namespace in rc-iframe-login * Remove dependency of RC namespace in all importes, except hipchat-enterprise * Move RestAPI client to rc-api package * Remove dependency of RC namespace in rc-api/helpers and api.js * Remove dependency of RC namespace on half of api files * Partial Remove dependency of RC namespace in rc-api * import API where it was being used by the RC namespace * Move processWebhookMessage function to rc-lib package * Remove API from RC namespace and import missing function that was being used with namespace * Remove dependency of RC namespace in rc-graphql * Fix import from wrong package * Remove dependency of RC namespace in rc-importer * Remove dependency of RC namespace in rc-issue-links * Remove dependency of RC namespace in rc-katex * Move templateVarHandler fn to rc-utils * Remove dependency of RC namespace in rc-ldap * Remove dependency of RC namespace in rc-livestream * Remove dependency of RC namespace in rc-mail-messages * Remove dependency of RC namespace in rc-mapview * Remove dependency of RC namespace in rc-mentions * Remove dependency of RC namespace in rc-mentions-flextab * Remove depedency of RC namespace in rc-message-attachements * Remove dependdency of RC namespace in rc-message-mark-as-unread * Remove dependency of RC namespace in rc-message-pin * Fix templateVarHandler that was in wrong folder * Remove namespace in the new livechat endpoint * Remove dependency of RC namespace in rc-message-snippet * Remove dependency of RC namespace in rc-message-star * Remove dependency of RC namespace in rc-oauth2 * Remove dependency of RC namespace in rc-oembed * Remove dependency of RC namespace in rc-otr * Remove dependency of RC namespace in rc-reactions * Remove dependency of RC namespace in rc-retention-policy * Remove dependency of RC namespace in rc-earch * Remove dependency of RC namespace in rc-setup-wizard * Remove dependency of RC namespace in rc-slackbridge * Remove dependency of Rc namespace in slashcommands-asciiarts * Remove depedency of RC namespace in rc-slash-archiveroom * Remove dependency of RC namespace in rc-slash-create * Remove dependency of RC namespace in rc-slash-help * Remove dependency of RC namespace in rc-slash-hide * Remove dependency of RC namespace in rc-slash-invite * Remove dependency of RC namespace in rc-slash-inviteall * Remove dependency of RC namespace in rc-slash-join * Remove dependency of RC namespace in rc-slash-kick * Remove dependency of RC namespace in rc-slash-leave * Remove dependency of RC namespace in rc-slash-me * Remove dependency of RC namespace in rc-slash-msg * Remove dependency of RC namespace in rc-slash-mute * Remove dependency of RC namespace in rc-slash-open * Remove dependency of RC namespace in rc-slash-topic * Remove dependency of RC namespace in rc-slash-unarchiveroom * Remove dependency of RC namespace in rc-smarsh-connector * Remove dependency of RC namespace in rc-sms * Remove dependency of RC namespace in rc-spotify * Remove dependency of RC namespace in rc-statistics * Move tokenpass models methods to rc-models * Remove dependency of RC namespace in rc-tokenpass * import tokenpass inside rc-lib * Remove dependency of RC namespace in rc-ui * Move webdavAccounts models to rc-model * Remove dependency of RC namespace in rc-ui-account * Remove dependency of RC namespace in rc-ui-admin * Remove dependency of RC namespace in rc-ui-clean-history * Remove dependency of RC namespace in rc-ui-flextab * Remove dependency of RC namespace in rc-ui-login * Remove dependency of RC namespace in rc-ui-master * Remove dependency of RC namespace in rc-ui-message * REmove dependency of RC namespace in rc-user-data-download * Remove dependency of RC namespace in rc-version-check * Remove dependency of RC namespace in rc-videobridge * Remove dependency of RC namespace in rc-webdav * Remove dependency of RC namespace in rc-wordpress * Remove some RC namespace use in chatpal-search * Remove dependency of RC namespace in rc-irc * Remove dependency of RC namespace in livechat/client * Move methods in common livechat models to rc-models * Remove dependency of RC namespace in rc-livechat/server/models * Remove LIvechat global variable from RC namespace * Remove dependency of RC namespace in rc-livechat/imports, lib, server/api, server/hooks and server/lib * Remove dependency of RC namespace in rc-livechat/server/methods * Fix duplicated import * Remove unused import * Remove dependency of RC namespace in rc-livechat/server/publications * MOve rc-livechat server models to rc-models * Change imports of livechat server models to rc-models package * Remove dependency of RC namespace in rc-api/helpers and api.js (#13273) * Move RestAPI client to rc-api package * Remove dependency of RC namespace in rc-api/helpers and api.js * Remove dependency of RC namespace on half of api files (#13275) * Move RestAPI client to rc-api package * Remove dependency of RC namespace in rc-api/helpers and api.js * Remove dependency of RC namespace on half of api files * Remove dependency of RC namespace in rc-integrations * Import missed functions in rc-irc * Remove dependency of RC namespace in rc-hipchat-enterprise-importer * Partial Remove dependency of RC namespace in rc-api (#13277) * Move RestAPI client to rc-api package * Remove dependency of RC namespace in rc-api/helpers and api.js * Remove dependency of RC namespace on half of api files * Partial Remove dependency of RC namespace in rc-api * Remove dependency of RC namespace in root client folder * Remove dependency of RC namespace in imports/message-read-receipt * Remove dependency of RC namespace in imports/personal-access-tokens * Remove dependency of RC namespace in rc-api (#13278) * Move RestAPI client to rc-api package * Remove dependency of RC namespace in rc-api/helpers and api.js * Remove dependency of RC namespace on half of api files * Partial Remove dependency of RC namespace in rc-api * import API where it was being used by the RC namespace * Move processWebhookMessage function to rc-lib package * Remove API from RC namespace and import missing function that was being used with namespace * Remove namespace in the new livechat endpoint * Remove dependency of RC namespace in rc-graphql (#13279) * Move RestAPI client to rc-api package * Remove dependency of RC namespace in rc-api/helpers and api.js * Remove dependency of RC namespace on half of api files * Partial Remove dependency of RC namespace in rc-api * import API where it was being used by the RC namespace * Move processWebhookMessage function to rc-lib package * Remove API from RC namespace and import missing function that was being used with namespace * Remove dependency of RC namespace in rc-graphql * Fix import from wrong package * Remove namespace in the new livechat endpoint * Remove dependency of RC namespace in root server folder - step 1 * Remove dependency of RC namespace in rc-importer (#13280) * Move RestAPI client to rc-api package * Remove dependency of RC namespace in rc-api/helpers and api.js * Remove dependency of RC namespace on half of api files * Partial Remove dependency of RC namespace in rc-api * import API where it was being used by the RC namespace * Move processWebhookMessage function to rc-lib package * Remove API from RC namespace and import missing function that was being used with namespace * Remove dependency of RC namespace in rc-graphql * Fix import from wrong package * Remove dependency of RC namespace in rc-importer * Remove namespace in the new livechat endpoint * Remove dependency of RC namespace in rc-ldap, katex and issue-links (#13281) * Move RestAPI client to rc-api package * Remove dependency of RC namespace in rc-api/helpers and api.js * Remove dependency of RC namespace on half of api files * Partial Remove dependency of RC namespace in rc-api * import API where it was being used by the RC namespace * Move processWebhookMessage function to rc-lib package * Remove API from RC namespace and import missing function that was being used with namespace * Remove dependency of RC namespace in rc-graphql * Fix import from wrong package * Remove dependency of RC namespace in rc-importer * Remove dependency of RC namespace in rc-issue-links * Remove dependency of RC namespace in rc-katex * Move templateVarHandler fn to rc-utils * Remove dependency of RC namespace in rc-ldap * Fix templateVarHandler that was in wrong folder * Remove namespace in the new livechat endpoint * Remove dependency of RC namespace in rc-livestream and rc-mail-messages (#13320) * Move RestAPI client to rc-api package * Remove dependency of RC namespace in rc-api/helpers and api.js * Remove dependency of RC namespace on half of api files * Partial Remove dependency of RC namespace in rc-api * import API where it was being used by the RC namespace * Move processWebhookMessage function to rc-lib package * Remove API from RC namespace and import missing function that was being used with namespace * Remove dependency of RC namespace in rc-graphql * Fix import from wrong package * Remove dependency of RC namespace in rc-importer * Remove dependency of RC namespace in rc-issue-links * Remove dependency of RC namespace in rc-katex * Move templateVarHandler fn to rc-utils * Remove dependency of RC namespace in rc-ldap * Remove dependency of RC namespace in rc-livestream * Remove dependency of RC namespace in rc-mail-messages * Fix templateVarHandler that was in wrong folder * Remove namespace in the new livechat endpoint --- server/configuration/accounts_meld.js | 9 ++-- server/lib/accounts.js | 50 ++++++++++++----------- server/lib/cordova.js | 40 +++++++++--------- server/lib/roomFiles.js | 7 ++-- server/methods/OEmbedCacheCleanup.js | 9 ++-- server/methods/addAllUserToRoom.js | 24 ++++++----- server/methods/addRoomLeader.js | 20 +++++---- server/methods/addRoomModerator.js | 20 +++++---- server/methods/addRoomOwner.js | 20 +++++---- server/methods/afterVerifyEmail.js | 7 ++-- server/methods/browseChannels.js | 14 ++++--- server/methods/canAccessRoom.js | 11 +++-- server/methods/channelsList.js | 32 ++++++++------- server/methods/createDirectMessage.js | 27 +++++++----- server/methods/deleteFileMessage.js | 3 +- server/methods/deleteUser.js | 9 ++-- server/methods/eraseRoom.js | 15 +++---- server/methods/getAvatarSuggestion.js | 15 +++---- server/methods/getRoomIdByNameOrId.js | 6 ++- server/methods/getRoomNameById.js | 8 ++-- server/methods/getTotalChannels.js | 3 +- server/methods/getUsersOfRoom.js | 8 ++-- server/methods/hideRoom.js | 3 +- server/methods/ignoreUser.js | 8 ++-- server/methods/loadHistory.js | 16 +++++--- server/methods/loadMissedMessages.js | 6 ++- server/methods/loadNextMessages.js | 11 +++-- server/methods/loadSurroundingMessages.js | 13 +++--- server/methods/logoutCleanUp.js | 3 +- server/methods/messageSearch.js | 12 +++--- server/methods/migrate.js | 8 ++-- server/methods/muteUserInRoom.js | 16 ++++---- server/methods/openRoom.js | 3 +- server/methods/readMessages.js | 5 ++- server/methods/registerUser.js | 28 +++++++------ 35 files changed, 285 insertions(+), 204 deletions(-) diff --git a/server/configuration/accounts_meld.js b/server/configuration/accounts_meld.js index 777840e236f..d9d14a5865f 100644 --- a/server/configuration/accounts_meld.js +++ b/server/configuration/accounts_meld.js @@ -1,5 +1,6 @@ import _ from 'underscore'; import { Accounts } from 'meteor/accounts-base'; +import { Users } from 'meteor/rocketchat:models'; const orig_updateOrCreateUserFromExternalService = Accounts.updateOrCreateUserFromExternalService; @@ -31,7 +32,7 @@ Accounts.updateOrCreateUserFromExternalService = function(serviceName, serviceDa } if (serviceData.email) { - const user = RocketChat.models.Users.findOneByEmailAddress(serviceData.email); + const user = Users.findOneByEmailAddress(serviceData.email); if (user != null) { const findQuery = { address: serviceData.email, @@ -39,11 +40,11 @@ Accounts.updateOrCreateUserFromExternalService = function(serviceName, serviceDa }; if (!_.findWhere(user.emails, findQuery)) { - RocketChat.models.Users.resetPasswordAndSetRequirePasswordChange(user._id, true, 'This_email_has_already_been_used_and_has_not_been_verified__Please_change_your_password'); + Users.resetPasswordAndSetRequirePasswordChange(user._id, true, 'This_email_has_already_been_used_and_has_not_been_verified__Please_change_your_password'); } - RocketChat.models.Users.setServiceId(user._id, serviceName, serviceData.id); - RocketChat.models.Users.setEmailVerified(user._id, serviceData.email); + Users.setServiceId(user._id, serviceName, serviceData.id); + Users.setEmailVerified(user._id, serviceData.email); } } diff --git a/server/lib/accounts.js b/server/lib/accounts.js index 1530c90c3e0..19463e3be89 100644 --- a/server/lib/accounts.js +++ b/server/lib/accounts.js @@ -5,22 +5,26 @@ import { TAPi18n } from 'meteor/tap:i18n'; import _ from 'underscore'; import s from 'underscore.string'; import * as Mailer from 'meteor/rocketchat:mailer'; +import { settings } from 'meteor/rocketchat:settings'; +import { callbacks } from 'meteor/rocketchat:callbacks'; +import { Roles, Users, Settings } from 'meteor/rocketchat:models'; +import { addUserRoles } from 'meteor/rocketchat:authorization'; const accountsConfig = { forbidClientAccountCreation: true, - loginExpirationInDays: RocketChat.settings.get('Accounts_LoginExpiration'), + loginExpirationInDays: settings.get('Accounts_LoginExpiration'), }; Accounts.config(accountsConfig); -Accounts.emailTemplates.siteName = RocketChat.settings.get('Site_Name'); +Accounts.emailTemplates.siteName = settings.get('Site_Name'); -Accounts.emailTemplates.from = `${ RocketChat.settings.get('Site_Name') } <${ RocketChat.settings.get('From_Email') }>`; +Accounts.emailTemplates.from = `${ settings.get('Site_Name') } <${ settings.get('From_Email') }>`; Accounts.emailTemplates.userToActivate = { subject() { const subject = TAPi18n.__('Accounts_Admin_Email_Approval_Needed_Subject_Default'); - const siteName = RocketChat.settings.get('Site_Name'); + const siteName = settings.get('Site_Name'); return `[${ siteName }] ${ subject }`; }, @@ -41,7 +45,7 @@ Accounts.emailTemplates.userActivated = { const activated = username ? 'Activated' : 'Approved'; const action = active ? activated : 'Deactivated'; const subject = `Accounts_Email_${ action }_Subject`; - const siteName = RocketChat.settings.get('Site_Name'); + const siteName = settings.get('Site_Name'); return `[${ siteName }] ${ TAPi18n.__(subject) }`; }, @@ -80,7 +84,7 @@ Accounts.urls.resetPassword = function(token) { Accounts.emailTemplates.resetPassword.html = Accounts.emailTemplates.resetPassword.text; Accounts.emailTemplates.enrollAccount.subject = function(user) { - const subject = RocketChat.settings.get('Accounts_Enrollment_Email_Subject'); + const subject = settings.get('Accounts_Enrollment_Email_Subject'); return Mailer.replace(subject, user); }; @@ -92,10 +96,10 @@ Accounts.emailTemplates.enrollAccount.html = function(user = {}/* , url*/) { }; Accounts.onCreateUser(function(options, user = {}) { - RocketChat.callbacks.run('beforeCreateUser', options, user); + callbacks.run('beforeCreateUser', options, user); user.status = 'offline'; - user.active = !RocketChat.settings.get('Accounts_ManuallyApproveNewUsers'); + user.active = !settings.get('Accounts_ManuallyApproveNewUsers'); if (!user.name) { if (options.profile) { @@ -129,7 +133,7 @@ Accounts.onCreateUser(function(options, user = {}) { if (!user.active) { const destinations = []; - RocketChat.models.Roles.findUsersInRole('admin').forEach((adminUser) => { + Roles.findUsersInRole('admin').forEach((adminUser) => { if (Array.isArray(adminUser.emails)) { adminUser.emails.forEach((email) => { destinations.push(`${ adminUser.name }<${ email.address }>`); @@ -139,7 +143,7 @@ Accounts.onCreateUser(function(options, user = {}) { const email = { to: destinations, - from: RocketChat.settings.get('From_Email'), + from: settings.get('From_Email'), subject: Accounts.emailTemplates.userToActivate.subject(), html: Accounts.emailTemplates.userToActivate.html(options), }; @@ -160,7 +164,7 @@ Accounts.insertUserDoc = _.wrap(Accounts.insertUserDoc, function(insertUserDoc, delete user.globalRoles; if (user.services && !user.services.password) { - const defaultAuthServiceRoles = String(RocketChat.settings.get('Accounts_Registration_AuthenticationServices_Default_Roles')).split(','); + const defaultAuthServiceRoles = String(settings.get('Accounts_Registration_AuthenticationServices_Default_Roles')).split(','); if (defaultAuthServiceRoles.length > 0) { roles = roles.concat(defaultAuthServiceRoles.map((s) => s.trim())); } @@ -185,13 +189,13 @@ Accounts.insertUserDoc = _.wrap(Accounts.insertUserDoc, function(insertUserDoc, if (user.type !== 'visitor') { Meteor.defer(function() { - return RocketChat.callbacks.run('afterCreateUser', user); + return callbacks.run('afterCreateUser', user); }); } } if (roles.length === 0) { - const hasAdmin = RocketChat.models.Users.findOne({ + const hasAdmin = Users.findOne({ roles: 'admin', type: 'user', }, { @@ -204,19 +208,19 @@ Accounts.insertUserDoc = _.wrap(Accounts.insertUserDoc, function(insertUserDoc, roles.push('user'); } else { roles.push('admin'); - if (RocketChat.settings.get('Show_Setup_Wizard') === 'pending') { - RocketChat.models.Settings.updateValueById('Show_Setup_Wizard', 'in_progress'); + if (settings.get('Show_Setup_Wizard') === 'pending') { + Settings.updateValueById('Show_Setup_Wizard', 'in_progress'); } } } - RocketChat.authz.addUserRoles(_id, roles); + addUserRoles(_id, roles); return _id; }); Accounts.validateLoginAttempt(function(login) { - login = RocketChat.callbacks.run('beforeValidateLogin', login); + login = callbacks.run('beforeValidateLogin', login); if (login.allowed !== true) { return login.allowed; @@ -238,18 +242,18 @@ Accounts.validateLoginAttempt(function(login) { }); } - if (login.user.roles.includes('admin') === false && login.type === 'password' && RocketChat.settings.get('Accounts_EmailVerification') === true) { + if (login.user.roles.includes('admin') === false && login.type === 'password' && settings.get('Accounts_EmailVerification') === true) { const validEmail = login.user.emails.filter((email) => email.verified === true); if (validEmail.length === 0) { throw new Meteor.Error('error-invalid-email', 'Invalid email __email__'); } } - login = RocketChat.callbacks.run('onValidateLogin', login); + login = callbacks.run('onValidateLogin', login); - RocketChat.models.Users.updateLastLoginById(login.user._id); + Users.updateLastLoginById(login.user._id); Meteor.defer(function() { - return RocketChat.callbacks.run('afterValidateLogin', login); + return callbacks.run('afterValidateLogin', login); }); return true; @@ -260,7 +264,7 @@ Accounts.validateNewUser(function(user) { return true; } - if (RocketChat.settings.get('Accounts_Registration_AuthenticationServices_Enabled') === false && RocketChat.settings.get('LDAP_Enable') === false && !(user.services && user.services.password)) { + if (settings.get('Accounts_Registration_AuthenticationServices_Enabled') === false && settings.get('LDAP_Enable') === false && !(user.services && user.services.password)) { throw new Meteor.Error('registration-disabled-authentication-services', 'User registration is disabled for authentication services'); } @@ -272,7 +276,7 @@ Accounts.validateNewUser(function(user) { return true; } - let domainWhiteList = RocketChat.settings.get('Accounts_AllowedDomainsList'); + let domainWhiteList = settings.get('Accounts_AllowedDomainsList'); if (_.isEmpty(s.trim(domainWhiteList))) { return true; } diff --git a/server/lib/cordova.js b/server/lib/cordova.js index 445c8327288..1c3eef13189 100644 --- a/server/lib/cordova.js +++ b/server/lib/cordova.js @@ -4,6 +4,8 @@ import { TAPi18n } from 'meteor/tap:i18n'; import { SystemLogger } from 'meteor/rocketchat:logger'; import { getWorkspaceAccessToken } from 'meteor/rocketchat:cloud'; import { Push } from 'meteor/rocketchat:push'; +import { hasRole } from 'meteor/rocketchat:authorization'; +import { settings } from 'meteor/rocketchat:settings'; Meteor.methods({ @@ -20,7 +22,7 @@ Meteor.methods({ }); } - if (!RocketChat.authz.hasRole(user._id, 'admin')) { + if (!hasRole(user._id, 'admin')) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'push_test', }); @@ -92,7 +94,7 @@ function sendPush(service, token, options, tries = 0) { data.headers.Authorization = `Bearer ${ workspaceAccesstoken }`; } - return HTTP.post(`${ RocketChat.settings.get('Push_gateway') }/push/${ service }/send`, data, function(error, response) { + return HTTP.post(`${ settings.get('Push_gateway') }/push/${ service }/send`, data, function(error, response) { if (response && response.statusCode === 406) { console.log('removing push token', token); Push.appCollection.remove({ @@ -124,38 +126,38 @@ function sendPush(service, token, options, tries = 0) { } function configurePush() { - if (RocketChat.settings.get('Push_debug')) { + if (settings.get('Push_debug')) { Push.debug = true; console.log('Push: configuring...'); } - if (RocketChat.settings.get('Push_enable') === true) { + if (settings.get('Push_enable') === true) { Push.allow({ send(userId/* , notification*/) { - return RocketChat.authz.hasRole(userId, 'admin'); + return hasRole(userId, 'admin'); }, }); let apn; let gcm; - if (RocketChat.settings.get('Push_enable_gateway') === false) { + if (settings.get('Push_enable_gateway') === false) { gcm = { - apiKey: RocketChat.settings.get('Push_gcm_api_key'), - projectNumber: RocketChat.settings.get('Push_gcm_project_number'), + apiKey: settings.get('Push_gcm_api_key'), + projectNumber: settings.get('Push_gcm_project_number'), }; apn = { - passphrase: RocketChat.settings.get('Push_apn_passphrase'), - keyData: RocketChat.settings.get('Push_apn_key'), - certData: RocketChat.settings.get('Push_apn_cert'), + passphrase: settings.get('Push_apn_passphrase'), + keyData: settings.get('Push_apn_key'), + certData: settings.get('Push_apn_cert'), }; - if (RocketChat.settings.get('Push_production') !== true) { + if (settings.get('Push_production') !== true) { apn = { - passphrase: RocketChat.settings.get('Push_apn_dev_passphrase'), - keyData: RocketChat.settings.get('Push_apn_dev_key'), - certData: RocketChat.settings.get('Push_apn_dev_cert'), + passphrase: settings.get('Push_apn_dev_passphrase'), + keyData: settings.get('Push_apn_dev_key'), + certData: settings.get('Push_apn_dev_cert'), gateway: 'gateway.sandbox.push.apple.com', }; } @@ -172,12 +174,12 @@ function configurePush() { Push.Configure({ apn, gcm, - production: RocketChat.settings.get('Push_production'), + production: settings.get('Push_production'), sendInterval: 5000, sendBatchSize: 10, }); - if (RocketChat.settings.get('Push_enable_gateway') === true) { + if (settings.get('Push_enable_gateway') === true) { Push.serverSend = function(options = { badge: 0 }) { if (options.from !== String(options.from)) { throw new Error('Push.send: option "from" not a string'); @@ -188,7 +190,7 @@ function configurePush() { if (options.text !== String(options.text)) { throw new Error('Push.send: option "text" not a string'); } - if (RocketChat.settings.get('Push_debug')) { + if (settings.get('Push_debug')) { console.log(`Push: send message "${ options.title }" via query`, options.query); } @@ -207,7 +209,7 @@ function configurePush() { }; return Push.appCollection.find(query).forEach((app) => { - if (RocketChat.settings.get('Push_debug')) { + if (settings.get('Push_debug')) { console.log('Push: send to token', app.token); } diff --git a/server/lib/roomFiles.js b/server/lib/roomFiles.js index f1f6bbbc5a7..f3544649e11 100644 --- a/server/lib/roomFiles.js +++ b/server/lib/roomFiles.js @@ -1,4 +1,5 @@ import { Meteor } from 'meteor/meteor'; +import { Users, Uploads } from 'meteor/rocketchat:models'; export const roomFiles = (pub, { rid, searchText, limit = 50 }) => { if (!pub.userId) { @@ -9,14 +10,14 @@ export const roomFiles = (pub, { rid, searchText, limit = 50 }) => { return this.ready(); } - const cursorFileListHandle = RocketChat.models.Uploads.findNotHiddenFilesOfRoom(rid, searchText, limit).observeChanges({ + const cursorFileListHandle = Uploads.findNotHiddenFilesOfRoom(rid, searchText, limit).observeChanges({ added(_id, record) { - const { username, name } = record.userId ? RocketChat.models.Users.findOneById(record.userId) : {}; + const { username, name } = record.userId ? Users.findOneById(record.userId) : {}; return pub.added('room_files', _id, { ...record, user: { username, name } }); }, changed(_id, recordChanges) { if (!recordChanges.hasOwnProperty('user') && recordChanges.userId) { - recordChanges.user = RocketChat.models.Users.findOneById(recordChanges.userId); + recordChanges.user = Users.findOneById(recordChanges.userId); } return pub.changed('room_files', _id, recordChanges); }, diff --git a/server/methods/OEmbedCacheCleanup.js b/server/methods/OEmbedCacheCleanup.js index 0b36f39621b..ff61d5253ea 100644 --- a/server/methods/OEmbedCacheCleanup.js +++ b/server/methods/OEmbedCacheCleanup.js @@ -1,17 +1,20 @@ import { Meteor } from 'meteor/meteor'; +import { OEmbedCache } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; +import { hasRole } from 'meteor/rocketchat:authorization'; Meteor.methods({ OEmbedCacheCleanup() { - if (Meteor.userId() && !RocketChat.authz.hasRole(Meteor.userId(), 'admin')) { + if (Meteor.userId() && !hasRole(Meteor.userId(), 'admin')) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'OEmbedCacheCleanup', }); } const date = new Date(); - const expirationDays = RocketChat.settings.get('API_EmbedCacheExpirationDays'); + const expirationDays = settings.get('API_EmbedCacheExpirationDays'); date.setDate(date.getDate() - expirationDays); - RocketChat.models.OEmbedCache.removeAfterDate(date); + OEmbedCache.removeAfterDate(date); return { message: 'cache_cleared', }; diff --git a/server/methods/addAllUserToRoom.js b/server/methods/addAllUserToRoom.js index c696218ec16..f33e37fa7ce 100644 --- a/server/methods/addAllUserToRoom.js +++ b/server/methods/addAllUserToRoom.js @@ -1,5 +1,9 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { hasRole } from 'meteor/rocketchat:authorization'; +import { Users, Rooms, Subscriptions, Messages } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; +import { callbacks } from 'meteor/rocketchat:callbacks'; Meteor.methods({ addAllUserToRoom(rid, activeUsersOnly = false) { @@ -7,15 +11,15 @@ Meteor.methods({ check (rid, String); check (activeUsersOnly, Boolean); - if (RocketChat.authz.hasRole(this.userId, 'admin') === true) { - const userCount = RocketChat.models.Users.find().count(); - if (userCount > RocketChat.settings.get('API_User_Limit')) { + if (hasRole(this.userId, 'admin') === true) { + const userCount = Users.find().count(); + if (userCount > settings.get('API_User_Limit')) { throw new Meteor.Error('error-user-limit-exceeded', 'User Limit Exceeded', { method: 'addAllToRoom', }); } - const room = RocketChat.models.Rooms.findOneById(rid); + const room = Rooms.findOneById(rid); if (room == null) { throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'addAllToRoom', @@ -27,15 +31,15 @@ Meteor.methods({ userFilter.active = true; } - const users = RocketChat.models.Users.find(userFilter).fetch(); + const users = Users.find(userFilter).fetch(); const now = new Date(); users.forEach(function(user) { - const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, user._id); + const subscription = Subscriptions.findOneByRoomIdAndUserId(rid, user._id); if (subscription != null) { return; } - RocketChat.callbacks.run('beforeJoinRoom', user, room); - RocketChat.models.Subscriptions.createWithRoomAndUser(room, user, { + callbacks.run('beforeJoinRoom', user, room); + Subscriptions.createWithRoomAndUser(room, user, { ts: now, open: true, alert: true, @@ -43,11 +47,11 @@ Meteor.methods({ userMentions: 1, groupMentions: 0, }); - RocketChat.models.Messages.createUserJoinWithRoomIdAndUser(rid, user, { + Messages.createUserJoinWithRoomIdAndUser(rid, user, { ts: now, }); Meteor.defer(function() {}); - return RocketChat.callbacks.run('afterJoinRoom', user, room); + return callbacks.run('afterJoinRoom', user, room); }); return true; } else { diff --git a/server/methods/addRoomLeader.js b/server/methods/addRoomLeader.js index 1c0fd31d4d1..dd7734474a5 100644 --- a/server/methods/addRoomLeader.js +++ b/server/methods/addRoomLeader.js @@ -1,5 +1,9 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Users, Subscriptions, Messages } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; +import { Notifications } from 'meteor/rocketchat:notifications'; Meteor.methods({ addRoomLeader(rid, userId) { @@ -12,13 +16,13 @@ Meteor.methods({ }); } - if (!RocketChat.authz.hasPermission(Meteor.userId(), 'set-leader', rid)) { + if (!hasPermission(Meteor.userId(), 'set-leader', rid)) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'addRoomLeader', }); } - const user = RocketChat.models.Users.findOneById(userId); + const user = Users.findOneById(userId); if (!user || !user.username) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { @@ -26,7 +30,7 @@ Meteor.methods({ }); } - const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, user._id); + const subscription = Subscriptions.findOneByRoomIdAndUserId(rid, user._id); if (!subscription) { throw new Meteor.Error('error-user-not-in-room', 'User is not in this room', { @@ -40,11 +44,11 @@ Meteor.methods({ }); } - RocketChat.models.Subscriptions.addRoleById(subscription._id, 'leader'); + Subscriptions.addRoleById(subscription._id, 'leader'); - const fromUser = RocketChat.models.Users.findOneById(Meteor.userId()); + const fromUser = Users.findOneById(Meteor.userId()); - RocketChat.models.Messages.createSubscriptionRoleAddedWithRoomIdAndUser(rid, user, { + Messages.createSubscriptionRoleAddedWithRoomIdAndUser(rid, user, { u: { _id: fromUser._id, username: fromUser.username, @@ -52,8 +56,8 @@ Meteor.methods({ role: 'leader', }); - if (RocketChat.settings.get('UI_DisplayRoles')) { - RocketChat.Notifications.notifyLogged('roles-change', { + if (settings.get('UI_DisplayRoles')) { + Notifications.notifyLogged('roles-change', { type: 'added', _id: 'leader', u: { diff --git a/server/methods/addRoomModerator.js b/server/methods/addRoomModerator.js index eaf2f5a69bc..6bc72580ba5 100644 --- a/server/methods/addRoomModerator.js +++ b/server/methods/addRoomModerator.js @@ -1,5 +1,9 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Users, Subscriptions, Messages } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; +import { Notifications } from 'meteor/rocketchat:notifications'; Meteor.methods({ addRoomModerator(rid, userId) { @@ -12,13 +16,13 @@ Meteor.methods({ }); } - if (!RocketChat.authz.hasPermission(Meteor.userId(), 'set-moderator', rid)) { + if (!hasPermission(Meteor.userId(), 'set-moderator', rid)) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'addRoomModerator', }); } - const user = RocketChat.models.Users.findOneById(userId); + const user = Users.findOneById(userId); if (!user || !user.username) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { @@ -26,7 +30,7 @@ Meteor.methods({ }); } - const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, user._id); + const subscription = Subscriptions.findOneByRoomIdAndUserId(rid, user._id); if (!subscription) { throw new Meteor.Error('error-user-not-in-room', 'User is not in this room', { @@ -40,11 +44,11 @@ Meteor.methods({ }); } - RocketChat.models.Subscriptions.addRoleById(subscription._id, 'moderator'); + Subscriptions.addRoleById(subscription._id, 'moderator'); - const fromUser = RocketChat.models.Users.findOneById(Meteor.userId()); + const fromUser = Users.findOneById(Meteor.userId()); - RocketChat.models.Messages.createSubscriptionRoleAddedWithRoomIdAndUser(rid, user, { + Messages.createSubscriptionRoleAddedWithRoomIdAndUser(rid, user, { u: { _id: fromUser._id, username: fromUser.username, @@ -52,8 +56,8 @@ Meteor.methods({ role: 'moderator', }); - if (RocketChat.settings.get('UI_DisplayRoles')) { - RocketChat.Notifications.notifyLogged('roles-change', { + if (settings.get('UI_DisplayRoles')) { + Notifications.notifyLogged('roles-change', { type: 'added', _id: 'moderator', u: { diff --git a/server/methods/addRoomOwner.js b/server/methods/addRoomOwner.js index a1507147488..fa0acf3508d 100644 --- a/server/methods/addRoomOwner.js +++ b/server/methods/addRoomOwner.js @@ -1,5 +1,9 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Users, Subscriptions, Messages } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; +import { Notifications } from 'meteor/rocketchat:notifications'; Meteor.methods({ addRoomOwner(rid, userId) { @@ -12,13 +16,13 @@ Meteor.methods({ }); } - if (!RocketChat.authz.hasPermission(Meteor.userId(), 'set-owner', rid)) { + if (!hasPermission(Meteor.userId(), 'set-owner', rid)) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'addRoomOwner', }); } - const user = RocketChat.models.Users.findOneById(userId); + const user = Users.findOneById(userId); if (!user || !user.username) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { @@ -26,7 +30,7 @@ Meteor.methods({ }); } - const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, user._id); + const subscription = Subscriptions.findOneByRoomIdAndUserId(rid, user._id); if (!subscription) { throw new Meteor.Error('error-user-not-in-room', 'User is not in this room', { @@ -40,11 +44,11 @@ Meteor.methods({ }); } - RocketChat.models.Subscriptions.addRoleById(subscription._id, 'owner'); + Subscriptions.addRoleById(subscription._id, 'owner'); - const fromUser = RocketChat.models.Users.findOneById(Meteor.userId()); + const fromUser = Users.findOneById(Meteor.userId()); - RocketChat.models.Messages.createSubscriptionRoleAddedWithRoomIdAndUser(rid, user, { + Messages.createSubscriptionRoleAddedWithRoomIdAndUser(rid, user, { u: { _id: fromUser._id, username: fromUser.username, @@ -52,8 +56,8 @@ Meteor.methods({ role: 'owner', }); - if (RocketChat.settings.get('UI_DisplayRoles')) { - RocketChat.Notifications.notifyLogged('roles-change', { + if (settings.get('UI_DisplayRoles')) { + Notifications.notifyLogged('roles-change', { type: 'added', _id: 'owner', u: { diff --git a/server/methods/afterVerifyEmail.js b/server/methods/afterVerifyEmail.js index 8419f065c68..e0504ef6569 100644 --- a/server/methods/afterVerifyEmail.js +++ b/server/methods/afterVerifyEmail.js @@ -1,4 +1,5 @@ import { Meteor } from 'meteor/meteor'; +import { Users, Roles } from 'meteor/rocketchat:models'; import _ from 'underscore'; Meteor.methods({ @@ -11,13 +12,13 @@ Meteor.methods({ }); } - const user = RocketChat.models.Users.findOneById(userId); + const user = 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'); + Roles.addUserRoles(user._id, 'user'); + Roles.removeUserRoles(user._id, 'anonymous'); } }, }); diff --git a/server/methods/browseChannels.js b/server/methods/browseChannels.js index f5af3264aae..a0115689797 100644 --- a/server/methods/browseChannels.js +++ b/server/methods/browseChannels.js @@ -1,5 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Rooms, Users } from 'meteor/rocketchat:models'; import s from 'underscore.string'; const sortChannels = function(field, direction) { @@ -57,11 +59,11 @@ Meteor.methods({ if (type === 'channels') { const sort = sortChannels(sortBy, sortDirection); - if (!RocketChat.authz.hasPermission(user._id, 'view-c-room')) { + if (!hasPermission(user._id, 'view-c-room')) { return; } return { - results: RocketChat.models.Rooms.findByNameAndType(regex, 'c', { + results: Rooms.findByNameAndType(regex, 'c', { ...options, sort, fields: { @@ -74,17 +76,17 @@ Meteor.methods({ usersCount: 1, }, }).fetch(), - total: RocketChat.models.Rooms.findByNameAndType(regex, 'c').count(), + total: Rooms.findByNameAndType(regex, 'c').count(), }; } // type === users - if (!RocketChat.authz.hasPermission(user._id, 'view-outside-room') || !RocketChat.authz.hasPermission(user._id, 'view-d-room')) { + if (!hasPermission(user._id, 'view-outside-room') || !hasPermission(user._id, 'view-d-room')) { return; } const sort = sortUsers(sortBy, sortDirection); return { - results: RocketChat.models.Users.findByActiveUsersExcept(text, [user.username], { + results: Users.findByActiveUsersExcept(text, [user.username], { ...options, sort, fields: { @@ -94,7 +96,7 @@ Meteor.methods({ emails: 1, }, }).fetch(), - total: RocketChat.models.Users.findByActiveUsersExcept(text, [user.username]).count(), + total: Users.findByActiveUsersExcept(text, [user.username]).count(), }; }, }); diff --git a/server/methods/canAccessRoom.js b/server/methods/canAccessRoom.js index 2f6f1e6a613..f011896dd95 100644 --- a/server/methods/canAccessRoom.js +++ b/server/methods/canAccessRoom.js @@ -1,5 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; +import { Users, Rooms } from 'meteor/rocketchat:models'; +import { canAccessRoom } from 'meteor/rocketchat:authorization'; +import { settings } from 'meteor/rocketchat:settings'; Meteor.methods({ canAccessRoom(rid, userId, extraData) { @@ -9,7 +12,7 @@ Meteor.methods({ let user; if (userId) { - user = RocketChat.models.Users.findOneById(userId, { + user = Users.findOneById(userId, { fields: { username: 1, }, @@ -28,16 +31,16 @@ Meteor.methods({ }); } - const room = RocketChat.models.Rooms.findOneById(rid); + const room = Rooms.findOneById(rid); if (room) { - if (RocketChat.authz.canAccessRoom.call(this, room, user, extraData)) { + if (canAccessRoom.call(this, room, user, extraData)) { if (user) { room.username = user.username; } return room; } - if (!userId && RocketChat.settings.get('Accounts_AllowAnonymousRead') === false) { + if (!userId && settings.get('Accounts_AllowAnonymousRead') === false) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'canAccessRoom', }); diff --git a/server/methods/channelsList.js b/server/methods/channelsList.js index 4e4c6dab90b..70e6f0a9fe7 100644 --- a/server/methods/channelsList.js +++ b/server/methods/channelsList.js @@ -1,5 +1,9 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Rooms, Subscriptions, Users } from 'meteor/rocketchat:models'; +import { getUserPreference } from 'meteor/rocketchat:utils'; +import { settings } from 'meteor/rocketchat:settings'; import _ from 'underscore'; import s from 'underscore.string'; @@ -51,39 +55,39 @@ Meteor.methods({ const userId = Meteor.userId(); if (channelType !== 'private') { - if (RocketChat.authz.hasPermission(userId, 'view-c-room')) { + if (hasPermission(userId, 'view-c-room')) { if (filter) { - channels = channels.concat(RocketChat.models.Rooms.findByType('c', options).fetch()); + channels = channels.concat(Rooms.findByType('c', options).fetch()); } else { - channels = channels.concat(RocketChat.models.Rooms.findByTypeAndNameContaining('c', filter, options).fetch()); + channels = channels.concat(Rooms.findByTypeAndNameContaining('c', filter, options).fetch()); } - } else if (RocketChat.authz.hasPermission(userId, 'view-joined-room')) { - const roomIds = RocketChat.models.Subscriptions.findByTypeAndUserId('c', userId, { fields: { rid: 1 } }).fetch().map((s) => s.rid); + } else if (hasPermission(userId, 'view-joined-room')) { + const roomIds = Subscriptions.findByTypeAndUserId('c', userId, { fields: { rid: 1 } }).fetch().map((s) => s.rid); if (filter) { - channels = channels.concat(RocketChat.models.Rooms.findByTypeInIds('c', roomIds, options).fetch()); + channels = channels.concat(Rooms.findByTypeInIds('c', roomIds, options).fetch()); } else { - channels = channels.concat(RocketChat.models.Rooms.findByTypeInIdsAndNameContaining('c', roomIds, filter, options).fetch()); + channels = channels.concat(Rooms.findByTypeInIdsAndNameContaining('c', roomIds, filter, options).fetch()); } } } - if (channelType !== 'public' && RocketChat.authz.hasPermission(userId, 'view-p-room')) { - const user = RocketChat.models.Users.findOne(userId, { + if (channelType !== 'public' && hasPermission(userId, 'view-p-room')) { + const user = Users.findOne(userId, { fields: { username: 1, 'settings.preferences.sidebarGroupByType': 1, }, }); - const userPref = RocketChat.getUserPreference(user, 'sidebarGroupByType'); + const userPref = getUserPreference(user, 'sidebarGroupByType'); // needs to negate globalPref because userPref represents its opposite - const groupByType = userPref !== undefined ? userPref : RocketChat.settings.get('UI_Group_Channels_By_Type'); + const groupByType = userPref !== undefined ? userPref : settings.get('UI_Group_Channels_By_Type'); if (!groupByType) { - const roomIds = RocketChat.models.Subscriptions.findByTypeAndUserId('p', userId, { fields: { rid: 1 } }).fetch().map((s) => s.rid); + const roomIds = Subscriptions.findByTypeAndUserId('p', userId, { fields: { rid: 1 } }).fetch().map((s) => s.rid); if (filter) { - channels = channels.concat(RocketChat.models.Rooms.findByTypeInIds('p', roomIds, options).fetch()); + channels = channels.concat(Rooms.findByTypeInIds('p', roomIds, options).fetch()); } else { - channels = channels.concat(RocketChat.models.Rooms.findByTypeInIdsAndNameContaining('p', roomIds, filter, options).fetch()); + channels = channels.concat(Rooms.findByTypeInIdsAndNameContaining('p', roomIds, filter, options).fetch()); } } } diff --git a/server/methods/createDirectMessage.js b/server/methods/createDirectMessage.js index 1fb380ad836..b25524bd126 100644 --- a/server/methods/createDirectMessage.js +++ b/server/methods/createDirectMessage.js @@ -1,5 +1,10 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { settings } from 'meteor/rocketchat:settings'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Users, Rooms, Subscriptions } from 'meteor/rocketchat:models'; +import { getDefaultSubscriptionPref } from 'meteor/rocketchat:utils'; +import { RateLimiter } from 'meteor/rocketchat:lib'; Meteor.methods({ createDirectMessage(username) { @@ -19,19 +24,19 @@ Meteor.methods({ }); } - if (RocketChat.settings.get('Message_AllowDirectMessagesToYourself') === false && me.username === username) { + if (settings.get('Message_AllowDirectMessagesToYourself') === false && me.username === username) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'createDirectMessage', }); } - if (!RocketChat.authz.hasPermission(Meteor.userId(), 'create-d')) { + if (!hasPermission(Meteor.userId(), 'create-d')) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'createDirectMessage', }); } - const to = RocketChat.models.Users.findOneByUsername(username); + const to = Users.findOneByUsername(username); if (!to) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { @@ -39,7 +44,7 @@ Meteor.methods({ }); } - if (!RocketChat.authz.hasPermission(to._id, 'view-d-room')) { + if (!hasPermission(to._id, 'view-d-room')) { throw new Meteor.Error('error-not-allowed', 'Target user not allowed to receive messages', { method: 'createDirectMessage', }); @@ -50,7 +55,7 @@ Meteor.methods({ const now = new Date(); // Make sure we have a room - RocketChat.models.Rooms.upsert({ + Rooms.upsert({ _id: rid, }, { $set: { @@ -64,7 +69,7 @@ Meteor.methods({ }, }); - const myNotificationPref = RocketChat.getDefaultSubscriptionPref(me); + const myNotificationPref = getDefaultSubscriptionPref(me); // Make user I have a subcription to this room const upsertSubscription = { @@ -94,14 +99,14 @@ Meteor.methods({ upsertSubscription.$set.archived = true; } - RocketChat.models.Subscriptions.upsert({ + Subscriptions.upsert({ rid, $and: [{ 'u._id': me._id }], // work around to solve problems with upsert and dot }, upsertSubscription); - const toNotificationPref = RocketChat.getDefaultSubscriptionPref(to); + const toNotificationPref = getDefaultSubscriptionPref(to); - RocketChat.models.Subscriptions.upsert({ + Subscriptions.upsert({ rid, $and: [{ 'u._id': to._id }], // work around to solve problems with upsert and dot }, { @@ -130,8 +135,8 @@ Meteor.methods({ }, }); -RocketChat.RateLimiter.limitMethod('createDirectMessage', 10, 60000, { +RateLimiter.limitMethod('createDirectMessage', 10, 60000, { userId(userId) { - return !RocketChat.authz.hasPermission(userId, 'send-many-messages'); + return !hasPermission(userId, 'send-many-messages'); }, }); diff --git a/server/methods/deleteFileMessage.js b/server/methods/deleteFileMessage.js index 6f033a29511..7c96d6ff9f6 100644 --- a/server/methods/deleteFileMessage.js +++ b/server/methods/deleteFileMessage.js @@ -1,12 +1,13 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; import { FileUpload } from 'meteor/rocketchat:file-upload'; +import { Messages } from 'meteor/rocketchat:models'; Meteor.methods({ deleteFileMessage(fileID) { check(fileID, String); - const msg = RocketChat.models.Messages.getMessageByFileId(fileID); + const msg = Messages.getMessageByFileId(fileID); if (msg) { return Meteor.call('deleteMessage', msg); diff --git a/server/methods/deleteUser.js b/server/methods/deleteUser.js index 5067c5b9ab1..b4dabda7577 100644 --- a/server/methods/deleteUser.js +++ b/server/methods/deleteUser.js @@ -1,5 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { Users } from 'meteor/rocketchat:models'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { deleteUser } from 'meteor/rocketchat:lib'; Meteor.methods({ deleteUser(userId) { @@ -11,13 +14,13 @@ Meteor.methods({ }); } - if (RocketChat.authz.hasPermission(Meteor.userId(), 'delete-user') !== true) { + if (hasPermission(Meteor.userId(), 'delete-user') !== true) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'deleteUser', }); } - const user = RocketChat.models.Users.findOneById(userId); + const user = Users.findOneById(userId); if (!user) { throw new Meteor.Error('error-invalid-user', 'Invalid user to delete', { method: 'deleteUser', @@ -35,7 +38,7 @@ Meteor.methods({ }); } - RocketChat.deleteUser(userId); + deleteUser(userId); return true; }, diff --git a/server/methods/eraseRoom.js b/server/methods/eraseRoom.js index 578bec5982f..1eee5eb8c1d 100644 --- a/server/methods/eraseRoom.js +++ b/server/methods/eraseRoom.js @@ -1,7 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { roomTypes } from 'meteor/rocketchat:utils'; import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Rooms, Messages, Subscriptions } from 'meteor/rocketchat:models'; Meteor.methods({ eraseRoom(rid) { @@ -13,7 +14,7 @@ Meteor.methods({ }); } - const room = RocketChat.models.Rooms.findOneById(rid); + const room = Rooms.findOneById(rid); if (!room) { throw new Meteor.Error('error-invalid-room', 'Invalid room', { @@ -28,16 +29,16 @@ Meteor.methods({ } } - if (!RocketChat.roomTypes.roomTypes[room.t].canBeDeleted(hasPermission, room)) { + if (!roomTypes.roomTypes[room.t].canBeDeleted(hasPermission, room)) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'eraseRoom', }); } - RocketChat.models.Messages.removeFilesByRoomId(rid); - RocketChat.models.Messages.removeByRoomId(rid); - RocketChat.models.Subscriptions.removeByRoomId(rid); - const result = RocketChat.models.Rooms.removeById(rid); + Messages.removeFilesByRoomId(rid); + Messages.removeByRoomId(rid); + Subscriptions.removeByRoomId(rid); + const result = Rooms.removeById(rid); if (Apps && Apps.isLoaded()) { Apps.getBridges().getListenerBridge().roomEvent('IPostRoomDeleted', room); diff --git a/server/methods/getAvatarSuggestion.js b/server/methods/getAvatarSuggestion.js index 7b22428b96d..af70c185786 100644 --- a/server/methods/getAvatarSuggestion.js +++ b/server/methods/getAvatarSuggestion.js @@ -2,48 +2,49 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; import { HTTP } from 'meteor/http'; import { Gravatar } from 'meteor/jparker:gravatar'; +import { settings } from 'meteor/rocketchat:settings'; function getAvatarSuggestionForUser(user) { check(user, Object); const avatars = []; - if (user.services.facebook && user.services.facebook.id && RocketChat.settings.get('Accounts_OAuth_Facebook')) { + if (user.services.facebook && user.services.facebook.id && settings.get('Accounts_OAuth_Facebook')) { avatars.push({ service: 'facebook', url: `https://graph.facebook.com/${ user.services.facebook.id }/picture?type=large`, }); } - if (user.services.google && user.services.google.picture && user.services.google.picture !== 'https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg' && RocketChat.settings.get('Accounts_OAuth_Google')) { + if (user.services.google && user.services.google.picture && user.services.google.picture !== 'https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg' && settings.get('Accounts_OAuth_Google')) { avatars.push({ service: 'google', url: user.services.google.picture, }); } - if (user.services.github && user.services.github.username && RocketChat.settings.get('Accounts_OAuth_Github')) { + if (user.services.github && user.services.github.username && settings.get('Accounts_OAuth_Github')) { avatars.push({ service: 'github', url: `https://avatars.githubusercontent.com/${ user.services.github.username }?s=200`, }); } - if (user.services.linkedin && user.services.linkedin.pictureUrl && RocketChat.settings.get('Accounts_OAuth_Linkedin')) { + if (user.services.linkedin && user.services.linkedin.pictureUrl && settings.get('Accounts_OAuth_Linkedin')) { avatars.push({ service: 'linkedin', url: user.services.linkedin.pictureUrl, }); } - if (user.services.twitter && user.services.twitter.profile_image_url_https && RocketChat.settings.get('Accounts_OAuth_Twitter')) { + if (user.services.twitter && user.services.twitter.profile_image_url_https && settings.get('Accounts_OAuth_Twitter')) { avatars.push({ service: 'twitter', url: user.services.twitter.profile_image_url_https.replace(/_normal|_bigger/, ''), }); } - if (user.services.gitlab && user.services.gitlab.avatar_url && RocketChat.settings.get('Accounts_OAuth_Gitlab')) { + if (user.services.gitlab && user.services.gitlab.avatar_url && settings.get('Accounts_OAuth_Gitlab')) { avatars.push({ service: 'gitlab', url: user.services.gitlab.avatar_url, @@ -57,7 +58,7 @@ function getAvatarSuggestionForUser(user) { }); } - if (user.services.blockstack && user.services.blockstack.image && RocketChat.settings.get('Blockstack_Enable')) { + if (user.services.blockstack && user.services.blockstack.image && settings.get('Blockstack_Enable')) { avatars.push({ service: 'blockstack', url: user.services.blockstack.image, diff --git a/server/methods/getRoomIdByNameOrId.js b/server/methods/getRoomIdByNameOrId.js index 786fbed4a05..5ea03ffecaa 100644 --- a/server/methods/getRoomIdByNameOrId.js +++ b/server/methods/getRoomIdByNameOrId.js @@ -1,6 +1,8 @@ // DEPRECATE import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { Rooms } from 'meteor/rocketchat:models'; +import { canAccessRoom } from 'meteor/rocketchat:authorization'; Meteor.methods({ getRoomIdByNameOrId(rid) { @@ -12,7 +14,7 @@ Meteor.methods({ }); } - const room = RocketChat.models.Rooms.findOneById(rid) || RocketChat.models.Rooms.findOneByName(rid); + const room = Rooms.findOneById(rid) || Rooms.findOneByName(rid); if (room == null) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { @@ -20,7 +22,7 @@ Meteor.methods({ }); } - if (!RocketChat.authz.canAccessRoom(room, Meteor.user())) { + if (!canAccessRoom(room, Meteor.user())) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getRoomIdByNameOrId', }); diff --git a/server/methods/getRoomNameById.js b/server/methods/getRoomNameById.js index 389e4c52a5d..545805a915f 100644 --- a/server/methods/getRoomNameById.js +++ b/server/methods/getRoomNameById.js @@ -1,5 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { Rooms, Subscriptions } from 'meteor/rocketchat:models'; +import { hasPermission } from 'meteor/rocketchat:authorization'; Meteor.methods({ getRoomNameById(rid) { @@ -11,7 +13,7 @@ Meteor.methods({ }); } - const room = RocketChat.models.Rooms.findOneById(rid); + const room = Rooms.findOneById(rid); if (room == null) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { @@ -19,12 +21,12 @@ Meteor.methods({ }); } - const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, userId, { fields: { _id: 1 } }); + const subscription = Subscriptions.findOneByRoomIdAndUserId(rid, userId, { fields: { _id: 1 } }); if (subscription) { return room.name; } - if (room.t !== 'c' || RocketChat.authz.hasPermission(userId, 'view-c-room') !== true) { + if (room.t !== 'c' || hasPermission(userId, 'view-c-room') !== true) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getRoomNameById', }); diff --git a/server/methods/getTotalChannels.js b/server/methods/getTotalChannels.js index bd362a67b7e..d89a202c25c 100644 --- a/server/methods/getTotalChannels.js +++ b/server/methods/getTotalChannels.js @@ -1,4 +1,5 @@ import { Meteor } from 'meteor/meteor'; +import { Rooms } from 'meteor/rocketchat:models'; Meteor.methods({ getTotalChannels() { @@ -11,6 +12,6 @@ Meteor.methods({ const query = { t: 'c', }; - return RocketChat.models.Rooms.find(query).count(); + return Rooms.find(query).count(); }, }); diff --git a/server/methods/getUsersOfRoom.js b/server/methods/getUsersOfRoom.js index d6bced8f9bc..169c0bd8880 100644 --- a/server/methods/getUsersOfRoom.js +++ b/server/methods/getUsersOfRoom.js @@ -1,4 +1,6 @@ import { Meteor } from 'meteor/meteor'; +import { Subscriptions } from 'meteor/rocketchat:models'; +import { hasPermission } from 'meteor/rocketchat:authorization'; Meteor.methods({ async getUsersOfRoom(rid, showAll) { @@ -12,15 +14,15 @@ Meteor.methods({ throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'getUsersOfRoom' }); } - if (room.broadcast && !RocketChat.authz.hasPermission(userId, 'view-broadcast-member-list', rid)) { + if (room.broadcast && !hasPermission(userId, 'view-broadcast-member-list', rid)) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getUsersOfRoom' }); } - const subscriptions = RocketChat.models.Subscriptions.findByRoomIdWhenUsernameExists(rid); + const subscriptions = Subscriptions.findByRoomIdWhenUsernameExists(rid); return { total: subscriptions.count(), - records: await RocketChat.models.Subscriptions.model.rawCollection().aggregate([ + records: await Subscriptions.model.rawCollection().aggregate([ { $match: { rid } }, { $lookup: diff --git a/server/methods/hideRoom.js b/server/methods/hideRoom.js index baa285ad3ad..3628f871ce1 100644 --- a/server/methods/hideRoom.js +++ b/server/methods/hideRoom.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { Subscriptions } from 'meteor/rocketchat:models'; Meteor.methods({ hideRoom(rid) { @@ -11,6 +12,6 @@ Meteor.methods({ }); } - return RocketChat.models.Subscriptions.hideByRoomIdAndUserId(rid, Meteor.userId()); + return Subscriptions.hideByRoomIdAndUserId(rid, Meteor.userId()); }, }); diff --git a/server/methods/ignoreUser.js b/server/methods/ignoreUser.js index a968b213e4e..30c38ea6ec4 100644 --- a/server/methods/ignoreUser.js +++ b/server/methods/ignoreUser.js @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { Subscriptions } from 'meteor/rocketchat:models'; Meteor.methods({ ignoreUser({ rid, userId: ignoredUser, ignore = true }) { @@ -15,18 +15,18 @@ Meteor.methods({ }); } - const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, userId); + const subscription = Subscriptions.findOneByRoomIdAndUserId(rid, userId); if (!subscription) { throw new Meteor.Error('error-invalid-subscription', 'Invalid subscription', { method: 'ignoreUser' }); } - const subscriptionIgnoredUser = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, ignoredUser); + const subscriptionIgnoredUser = Subscriptions.findOneByRoomIdAndUserId(rid, ignoredUser); if (!subscriptionIgnoredUser) { throw new Meteor.Error('error-invalid-subscription', 'Invalid subscription', { method: 'ignoreUser' }); } - return !!RocketChat.models.Subscriptions.ignoreUser({ _id: subscription._id, ignoredUser, ignore }); + return !!Subscriptions.ignoreUser({ _id: subscription._id, ignoredUser, ignore }); }, }); diff --git a/server/methods/loadHistory.js b/server/methods/loadHistory.js index 5b5ab09035c..5617cc7de5d 100644 --- a/server/methods/loadHistory.js +++ b/server/methods/loadHistory.js @@ -1,9 +1,13 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { Subscriptions } from 'meteor/rocketchat:models'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { settings } from 'meteor/rocketchat:settings'; +import { loadMessageHistory } from 'meteor/rocketchat:lib'; const hideMessagesOfType = []; -RocketChat.settings.get(/Message_HideType_.+/, function(key, value) { +settings.get(/Message_HideType_.+/, function(key, value) { const type = key.replace('Message_HideType_', ''); const types = type === 'mute_unmute' ? ['user-muted', 'user-unmuted'] : [type]; @@ -25,7 +29,7 @@ Meteor.methods({ this.unblock(); check(rid, String); - if (!Meteor.userId() && RocketChat.settings.get('Accounts_AllowAnonymousRead') === false) { + if (!Meteor.userId() && settings.get('Accounts_AllowAnonymousRead') === false) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'loadHistory', }); @@ -38,13 +42,13 @@ Meteor.methods({ return false; } - const canAnonymous = RocketChat.settings.get('Accounts_AllowAnonymousRead'); - const canPreview = RocketChat.authz.hasPermission(fromId, 'preview-c-room'); + const canAnonymous = settings.get('Accounts_AllowAnonymousRead'); + const canPreview = hasPermission(fromId, 'preview-c-room'); - if (room.t === 'c' && !canAnonymous && !canPreview && !RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, fromId, { fields: { _id: 1 } })) { + if (room.t === 'c' && !canAnonymous && !canPreview && !Subscriptions.findOneByRoomIdAndUserId(rid, fromId, { fields: { _id: 1 } })) { return false; } - return RocketChat.loadMessageHistory({ userId: fromId, rid, end, limit, ls }); + return loadMessageHistory({ userId: fromId, rid, end, limit, ls }); }, }); diff --git a/server/methods/loadMissedMessages.js b/server/methods/loadMissedMessages.js index af01894e5d3..f742ce0327a 100644 --- a/server/methods/loadMissedMessages.js +++ b/server/methods/loadMissedMessages.js @@ -1,5 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { Messages } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; Meteor.methods({ loadMissedMessages(rid, start) { @@ -23,12 +25,12 @@ Meteor.methods({ }, }; - if (!RocketChat.settings.get('Message_ShowEditedStatus')) { + if (!settings.get('Message_ShowEditedStatus')) { options.fields = { editedAt: 0, }; } - return RocketChat.models.Messages.findVisibleByRoomIdAfterTimestamp(rid, start, options).fetch(); + return Messages.findVisibleByRoomIdAfterTimestamp(rid, start, options).fetch(); }, }); diff --git a/server/methods/loadNextMessages.js b/server/methods/loadNextMessages.js index 5601b628ea7..1f67d27f3a3 100644 --- a/server/methods/loadNextMessages.js +++ b/server/methods/loadNextMessages.js @@ -1,5 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { Messages } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; +import { composeMessageObjectWithUser } from 'meteor/rocketchat:utils'; Meteor.methods({ loadNextMessages(rid, end, limit = 20) { @@ -25,7 +28,7 @@ Meteor.methods({ limit, }; - if (!RocketChat.settings.get('Message_ShowEditedStatus')) { + if (!settings.get('Message_ShowEditedStatus')) { options.fields = { editedAt: 0, }; @@ -33,13 +36,13 @@ Meteor.methods({ let records; if (end) { - records = RocketChat.models.Messages.findVisibleByRoomIdAfterTimestamp(rid, end, options).fetch(); + records = Messages.findVisibleByRoomIdAfterTimestamp(rid, end, options).fetch(); } else { - records = RocketChat.models.Messages.findVisibleByRoomId(rid, options).fetch(); + records = Messages.findVisibleByRoomId(rid, options).fetch(); } return { - messages: records.map((message) => RocketChat.composeMessageObjectWithUser(message, fromId)), + messages: records.map((message) => composeMessageObjectWithUser(message, fromId)), }; }, }); diff --git a/server/methods/loadSurroundingMessages.js b/server/methods/loadSurroundingMessages.js index 69db55d14fd..796b69411df 100644 --- a/server/methods/loadSurroundingMessages.js +++ b/server/methods/loadSurroundingMessages.js @@ -1,5 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { Messages } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; +import { composeMessageObjectWithUser } from 'meteor/rocketchat:utils'; Meteor.methods({ loadSurroundingMessages(message, limit = 50) { @@ -18,7 +21,7 @@ Meteor.methods({ return false; } - message = RocketChat.models.Messages.findOneById(message._id); + message = Messages.findOneById(message._id); if (!message || !message.rid) { return false; @@ -37,13 +40,13 @@ Meteor.methods({ limit: Math.ceil(limit / 2), }; - if (!RocketChat.settings.get('Message_ShowEditedStatus')) { + if (!settings.get('Message_ShowEditedStatus')) { options.fields = { editedAt: 0, }; } - const messages = RocketChat.models.Messages.findVisibleByRoomIdBeforeTimestamp(message.rid, message.ts, options).fetch(); + const messages = Messages.findVisibleByRoomIdBeforeTimestamp(message.rid, message.ts, options).fetch(); const moreBefore = messages.length === options.limit; @@ -55,13 +58,13 @@ Meteor.methods({ options.limit = Math.floor(limit / 2); - const afterMessages = RocketChat.models.Messages.findVisibleByRoomIdAfterTimestamp(message.rid, message.ts, options).fetch(); + const afterMessages = Messages.findVisibleByRoomIdAfterTimestamp(message.rid, message.ts, options).fetch(); const moreAfter = afterMessages.length === options.limit; return { messages: messages.concat(afterMessages) - .map((message) => RocketChat.composeMessageObjectWithUser(message, fromId)), + .map((message) => composeMessageObjectWithUser(message, fromId)), moreBefore, moreAfter, }; diff --git a/server/methods/logoutCleanUp.js b/server/methods/logoutCleanUp.js index 157db2896cb..40a71419470 100644 --- a/server/methods/logoutCleanUp.js +++ b/server/methods/logoutCleanUp.js @@ -1,12 +1,13 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { callbacks } from 'meteor/rocketchat:callbacks'; Meteor.methods({ logoutCleanUp(user) { check(user, Object); Meteor.defer(function() { - RocketChat.callbacks.run('afterLogoutCleanUp', user); + callbacks.run('afterLogoutCleanUp', user); }); }, }); diff --git a/server/methods/messageSearch.js b/server/methods/messageSearch.js index dd40f392928..44ade636a0a 100644 --- a/server/methods/messageSearch.js +++ b/server/methods/messageSearch.js @@ -1,5 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; +import { Subscriptions, Messages } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; import s from 'underscore.string'; Meteor.methods({ @@ -27,7 +29,7 @@ Meteor.methods({ if (!Meteor.call('canAccessRoom', rid, currentUserId)) { return result; } - } else if (RocketChat.settings.get('Search.defaultProvider.GlobalSearchEnabled') !== true) { + } else if (settings.get('Search.defaultProvider.GlobalSearchEnabled') !== true) { return result; } @@ -187,7 +189,7 @@ Meteor.methods({ $regex: r[1], $options: r[2], }; - } else if (RocketChat.settings.get('Message_AlwaysSearchRegExp')) { + } else if (settings.get('Message_AlwaysSearchRegExp')) { query.msg = { $regex: text, $options: 'i', @@ -216,19 +218,19 @@ Meteor.methods({ query.rid = rid; } else { query.rid = { - $in: RocketChat.models.Subscriptions.findByUserId(user._id) + $in: Subscriptions.findByUserId(user._id) .fetch() .map((subscription) => subscription.rid), }; } - if (!RocketChat.settings.get('Message_ShowEditedStatus')) { + if (!settings.get('Message_ShowEditedStatus')) { options.fields = { editedAt: 0, }; } - result.message.docs = RocketChat.models.Messages.find(query, options).fetch(); + result.message.docs = Messages.find(query, options).fetch(); } return result; diff --git a/server/methods/migrate.js b/server/methods/migrate.js index e46e7dc1199..938a2271fad 100644 --- a/server/methods/migrate.js +++ b/server/methods/migrate.js @@ -1,5 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { Migrations } from 'meteor/rocketchat:migrations'; +import { hasPermission } from 'meteor/rocketchat:authorization'; Meteor.methods({ migrateTo(version) { @@ -13,7 +15,7 @@ Meteor.methods({ const user = Meteor.user(); - if (!user || RocketChat.authz.hasPermission(user._id, 'run-migration') !== true) { + if (!user || hasPermission(user._id, 'run-migration') !== true) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'migrateTo', }); @@ -21,7 +23,7 @@ Meteor.methods({ this.unblock(); - RocketChat.Migrations.migrateTo(version); + Migrations.migrateTo(version); return version; }, @@ -33,6 +35,6 @@ Meteor.methods({ }); } - return RocketChat.Migrations.getVersion(); + return Migrations.getVersion(); }, }); diff --git a/server/methods/muteUserInRoom.js b/server/methods/muteUserInRoom.js index b63c3e4a172..496ea2b90aa 100644 --- a/server/methods/muteUserInRoom.js +++ b/server/methods/muteUserInRoom.js @@ -1,5 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; +import { Rooms, Subscriptions, Users, Messages } from 'meteor/rocketchat:models'; +import { hasPermission } from 'meteor/rocketchat:authorization'; Meteor.methods({ muteUserInRoom(data) { @@ -16,13 +18,13 @@ Meteor.methods({ const fromId = Meteor.userId(); - if (!RocketChat.authz.hasPermission(fromId, 'mute-user', data.rid)) { + if (!hasPermission(fromId, 'mute-user', data.rid)) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'muteUserInRoom', }); } - const room = RocketChat.models.Rooms.findOneById(data.rid); + const room = Rooms.findOneById(data.rid); if (!room) { throw new Meteor.Error('error-invalid-room', 'Invalid room', { @@ -37,20 +39,20 @@ Meteor.methods({ }); } - const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUsername(data.rid, data.username, { fields: { _id: 1 } }); + const subscription = Subscriptions.findOneByRoomIdAndUsername(data.rid, data.username, { fields: { _id: 1 } }); if (!subscription) { throw new Meteor.Error('error-user-not-in-room', 'User is not in this room', { method: 'muteUserInRoom', }); } - const mutedUser = RocketChat.models.Users.findOneByUsername(data.username); + const mutedUser = Users.findOneByUsername(data.username); - RocketChat.models.Rooms.muteUsernameByRoomId(data.rid, mutedUser.username); + Rooms.muteUsernameByRoomId(data.rid, mutedUser.username); - const fromUser = RocketChat.models.Users.findOneById(fromId); + const fromUser = Users.findOneById(fromId); - RocketChat.models.Messages.createUserMutedWithRoomIdAndUser(data.rid, mutedUser, { + Messages.createUserMutedWithRoomIdAndUser(data.rid, mutedUser, { u: { _id: fromUser._id, username: fromUser.username, diff --git a/server/methods/openRoom.js b/server/methods/openRoom.js index 2a9af14d3e0..678631e13b7 100644 --- a/server/methods/openRoom.js +++ b/server/methods/openRoom.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { Subscriptions } from 'meteor/rocketchat:models'; Meteor.methods({ openRoom(rid) { @@ -11,6 +12,6 @@ Meteor.methods({ }); } - return RocketChat.models.Subscriptions.openByRoomIdAndUserId(rid, Meteor.userId()); + return Subscriptions.openByRoomIdAndUserId(rid, Meteor.userId()); }, }); diff --git a/server/methods/readMessages.js b/server/methods/readMessages.js index 939cfc9a471..789bc40789c 100644 --- a/server/methods/readMessages.js +++ b/server/methods/readMessages.js @@ -1,6 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; import { ReadReceipt } from '../../imports/message-read-receipt/server/lib/ReadReceipt'; +import { Subscriptions } from 'meteor/rocketchat:models'; Meteor.methods({ readMessages(rid) { @@ -15,9 +16,9 @@ Meteor.methods({ } // this prevents cache from updating object reference/pointer - const userSubscription = Object.assign({}, RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, userId)); + const userSubscription = Object.assign({}, Subscriptions.findOneByRoomIdAndUserId(rid, userId)); - RocketChat.models.Subscriptions.setAsReadByRoomIdAndUserId(rid, userId); + Subscriptions.setAsReadByRoomIdAndUserId(rid, userId); Meteor.defer(() => { ReadReceipt.markMessagesAsRead(rid, userId, userSubscription.ls); diff --git a/server/methods/registerUser.js b/server/methods/registerUser.js index 660f65feac6..68ae85da63c 100644 --- a/server/methods/registerUser.js +++ b/server/methods/registerUser.js @@ -3,6 +3,10 @@ import { Match, check } from 'meteor/check'; import { Accounts } from 'meteor/accounts-base'; import s from 'underscore.string'; import * as Mailer from 'meteor/rocketchat:mailer'; +import { Users } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; +import { saveCustomFields, validateEmailDomain, passwordPolicy } from 'meteor/rocketchat:lib'; + let verifyEmailTemplate = ''; Meteor.startup(() => { Mailer.getTemplateWrapped('Verification_Email', (value) => { @@ -11,9 +15,9 @@ Meteor.startup(() => { }); Meteor.methods({ registerUser(formData) { - const AllowAnonymousRead = RocketChat.settings.get('Accounts_AllowAnonymousRead'); - const AllowAnonymousWrite = RocketChat.settings.get('Accounts_AllowAnonymousWrite'); - const manuallyApproveNewUsers = RocketChat.settings.get('Accounts_ManuallyApproveNewUsers'); + const AllowAnonymousRead = settings.get('Accounts_AllowAnonymousRead'); + const AllowAnonymousWrite = settings.get('Accounts_AllowAnonymousWrite'); + const manuallyApproveNewUsers = settings.get('Accounts_ManuallyApproveNewUsers'); if (AllowAnonymousRead === true && AllowAnonymousWrite === true && formData.email == null) { const userId = Accounts.insertUserDoc({}, { globalRoles: [ @@ -35,15 +39,15 @@ Meteor.methods({ })); } - if (RocketChat.settings.get('Accounts_RegistrationForm') === 'Disabled') { + if (settings.get('Accounts_RegistrationForm') === 'Disabled') { throw new Meteor.Error('error-user-registration-disabled', 'User registration is disabled', { method: 'registerUser' }); - } else if (RocketChat.settings.get('Accounts_RegistrationForm') === 'Secret URL' && (!formData.secretURL || formData.secretURL !== RocketChat.settings.get('Accounts_RegistrationForm_SecretURL'))) { + } else if (settings.get('Accounts_RegistrationForm') === 'Secret URL' && (!formData.secretURL || formData.secretURL !== settings.get('Accounts_RegistrationForm_SecretURL'))) { throw new Meteor.Error ('error-user-registration-secret', 'User registration is only allowed via Secret URL', { method: 'registerUser' }); } - RocketChat.passwordPolicy.validate(formData.pass); + passwordPolicy.validate(formData.pass); - RocketChat.validateEmailDomain(formData.email); + validateEmailDomain(formData.email); const userData = { email: s.trim(formData.email.toLowerCase()), @@ -53,7 +57,7 @@ Meteor.methods({ }; // Check if user has already been imported and never logged in. If so, set password and let it through - const importedUser = RocketChat.models.Users.findOneByEmailAddress(s.trim(formData.email.toLowerCase())); + const importedUser = Users.findOneByEmailAddress(s.trim(formData.email.toLowerCase())); let userId; if (importedUser && importedUser.importIds && importedUser.importIds.length && !importedUser.lastLogin) { Accounts.setPassword(importedUser._id, userData.password); @@ -62,18 +66,18 @@ Meteor.methods({ userId = Accounts.createUser(userData); } - RocketChat.models.Users.setName(userId, s.trim(formData.name)); + Users.setName(userId, s.trim(formData.name)); const reason = s.trim(formData.reason); if (manuallyApproveNewUsers && reason) { - RocketChat.models.Users.setReason(userId, reason); + Users.setReason(userId, reason); } - RocketChat.saveCustomFields(userId, formData); + saveCustomFields(userId, formData); try { - const subject = Mailer.replace(RocketChat.settings.get('Verification_Email_Subject')); + const subject = Mailer.replace(settings.get('Verification_Email_Subject')); Accounts.emailTemplates.verifyEmail.subject = () => subject; Accounts.emailTemplates.verifyEmail.html = (userModel, url) => Mailer.replace(Mailer.replacekey(verifyEmailTemplate, 'Verification_Url', url), userModel);