From 575c9dcedcf652550f90b31bdefc9d6ff032ada0 Mon Sep 17 00:00:00 2001 From: Marcos Spessatto Defendi Date: Fri, 15 Feb 2019 16:33:34 -0200 Subject: [PATCH] Remove dependency of RC namespace in root server folder - step 2 (#13397) * 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 * Remove dependency of RC namespace in root server folder - step 2 --- server/methods/removeRoomLeader.js | 20 +++--- server/methods/removeRoomModerator.js | 20 +++--- server/methods/removeRoomOwner.js | 22 +++--- server/methods/removeUserFromRoom.js | 22 +++--- server/methods/reportMessage.js | 5 +- server/methods/requestDataDownload.js | 12 ++-- server/methods/resetAvatar.js | 9 ++- server/methods/roomNameExists.js | 3 +- server/methods/saveUserPreferences.js | 21 +++--- server/methods/saveUserProfile.js | 15 ++-- server/methods/sendConfirmationEmail.js | 6 +- server/methods/sendForgotPasswordEmail.js | 8 ++- server/methods/setAvatarFromService.js | 6 +- server/methods/setUserActiveStatus.js | 16 +++-- server/methods/setUserPassword.js | 8 ++- server/methods/toogleFavorite.js | 5 +- server/methods/unmuteUserInRoom.js | 16 +++-- server/methods/userSetUtcOffset.js | 3 +- server/publications/activeUsers.js | 3 +- .../channelAndPrivateAutocomplete.js | 6 +- server/publications/fullUserData.js | 3 +- server/publications/messages.js | 14 ++-- server/publications/room.js | 33 +++++---- .../publications/roomSubscriptionsByRole.js | 6 +- server/publications/spotlight.js | 30 ++++---- server/publications/subscription.js | 16 +++-- server/publications/userAutocomplete.js | 3 +- server/publications/userChannels.js | 6 +- server/publications/userData.js | 3 +- server/startup/avatar.js | 19 +++--- server/startup/cron.js | 3 +- server/startup/i18n-validation.js | 68 ------------------- server/startup/initialData.js | 60 ++++++++-------- 33 files changed, 246 insertions(+), 244 deletions(-) delete mode 100644 server/startup/i18n-validation.js diff --git a/server/methods/removeRoomLeader.js b/server/methods/removeRoomLeader.js index 935c10966fc8..28d3a0c3df5c 100644 --- a/server/methods/removeRoomLeader.js +++ b/server/methods/removeRoomLeader.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({ removeRoomLeader(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: 'removeRoomLeader', }); } - 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.removeRoleById(subscription._id, 'leader'); + Subscriptions.removeRoleById(subscription._id, 'leader'); - const fromUser = RocketChat.models.Users.findOneById(Meteor.userId()); + const fromUser = Users.findOneById(Meteor.userId()); - RocketChat.models.Messages.createSubscriptionRoleRemovedWithRoomIdAndUser(rid, user, { + Messages.createSubscriptionRoleRemovedWithRoomIdAndUser(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: 'removed', _id: 'leader', u: { diff --git a/server/methods/removeRoomModerator.js b/server/methods/removeRoomModerator.js index bf0f09f63b0d..d5b63c90ccfe 100644 --- a/server/methods/removeRoomModerator.js +++ b/server/methods/removeRoomModerator.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({ removeRoomModerator(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: 'removeRoomModerator', }); } - 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-invalid-room', 'Invalid room', { @@ -40,11 +44,11 @@ Meteor.methods({ }); } - RocketChat.models.Subscriptions.removeRoleById(subscription._id, 'moderator'); + Subscriptions.removeRoleById(subscription._id, 'moderator'); - const fromUser = RocketChat.models.Users.findOneById(Meteor.userId()); + const fromUser = Users.findOneById(Meteor.userId()); - RocketChat.models.Messages.createSubscriptionRoleRemovedWithRoomIdAndUser(rid, user, { + Messages.createSubscriptionRoleRemovedWithRoomIdAndUser(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: 'removed', _id: 'moderator', u: { diff --git a/server/methods/removeRoomOwner.js b/server/methods/removeRoomOwner.js index a1e80af51c8f..c12c7c2afc94 100644 --- a/server/methods/removeRoomOwner.js +++ b/server/methods/removeRoomOwner.js @@ -1,5 +1,9 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { hasPermission, getUsersInRole } 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({ removeRoomOwner(rid, userId) { @@ -12,20 +16,20 @@ 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: 'removeRoomOwner', }); } - 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', { method: 'removeRoomOwner', }); } - const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, user._id); + const subscription = Subscriptions.findOneByRoomIdAndUserId(rid, user._id); if (!subscription) { throw new Meteor.Error('error-invalid-room', 'Invalid room', { @@ -39,7 +43,7 @@ Meteor.methods({ }); } - const numOwners = RocketChat.authz.getUsersInRole('owner', rid).count(); + const numOwners = getUsersInRole('owner', rid).count(); if (numOwners === 1) { throw new Meteor.Error('error-remove-last-owner', 'This is the last owner. Please set a new owner before removing this one.', { @@ -47,11 +51,11 @@ Meteor.methods({ }); } - RocketChat.models.Subscriptions.removeRoleById(subscription._id, 'owner'); + Subscriptions.removeRoleById(subscription._id, 'owner'); - const fromUser = RocketChat.models.Users.findOneById(Meteor.userId()); + const fromUser = Users.findOneById(Meteor.userId()); - RocketChat.models.Messages.createSubscriptionRoleRemovedWithRoomIdAndUser(rid, user, { + Messages.createSubscriptionRoleRemovedWithRoomIdAndUser(rid, user, { u: { _id: fromUser._id, username: fromUser.username, @@ -59,8 +63,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: 'removed', _id: 'owner', u: { diff --git a/server/methods/removeUserFromRoom.js b/server/methods/removeUserFromRoom.js index c82e7c64a22c..75e6a79cbf8e 100644 --- a/server/methods/removeUserFromRoom.js +++ b/server/methods/removeUserFromRoom.js @@ -1,5 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; +import { hasPermission, hasRole, getUsersInRole, removeUserFromRoles } from 'meteor/rocketchat:authorization'; +import { Users, Subscriptions, Rooms, Messages } from 'meteor/rocketchat:models'; Meteor.methods({ removeUserFromRoom(data) { @@ -16,13 +18,13 @@ Meteor.methods({ }); } - if (!RocketChat.authz.hasPermission(fromId, 'remove-user', data.rid)) { + if (!hasPermission(fromId, 'remove-user', data.rid)) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'removeUserFromRoom', }); } - const room = RocketChat.models.Rooms.findOneById(data.rid); + const room = Rooms.findOneById(data.rid); if (!room || room.t === 'd') { throw new Meteor.Error('error-not-allowed', 'Not allowed', { @@ -30,17 +32,17 @@ Meteor.methods({ }); } - const removedUser = RocketChat.models.Users.findOneByUsername(data.username); + const removedUser = Users.findOneByUsername(data.username); - const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(data.rid, removedUser._id, { fields: { _id: 1 } }); + const subscription = Subscriptions.findOneByRoomIdAndUserId(data.rid, removedUser._id, { fields: { _id: 1 } }); if (!subscription) { throw new Meteor.Error('error-user-not-in-room', 'User is not in this room', { method: 'removeUserFromRoom', }); } - if (RocketChat.authz.hasRole(removedUser._id, 'owner', room._id)) { - const numOwners = RocketChat.authz.getUsersInRole('owner', room._id).fetch().length; + if (hasRole(removedUser._id, 'owner', room._id)) { + const numOwners = getUsersInRole('owner', room._id).fetch().length; if (numOwners === 1) { throw new Meteor.Error('error-you-are-last-owner', 'You are the last owner. Please set new owner before leaving the room.', { @@ -49,15 +51,15 @@ Meteor.methods({ } } - RocketChat.models.Subscriptions.removeByRoomIdAndUserId(data.rid, removedUser._id); + Subscriptions.removeByRoomIdAndUserId(data.rid, removedUser._id); if (['c', 'p'].includes(room.t) === true) { - RocketChat.authz.removeUserFromRoles(removedUser._id, ['moderator', 'owner'], data.rid); + removeUserFromRoles(removedUser._id, ['moderator', 'owner'], data.rid); } - const fromUser = RocketChat.models.Users.findOneById(fromId); + const fromUser = Users.findOneById(fromId); - RocketChat.models.Messages.createUserRemovedWithRoomIdAndUser(data.rid, removedUser, { + Messages.createUserRemovedWithRoomIdAndUser(data.rid, removedUser, { u: { _id: fromUser._id, username: fromUser.username, diff --git a/server/methods/reportMessage.js b/server/methods/reportMessage.js index 90215f6a2e68..7710b5e97f38 100644 --- a/server/methods/reportMessage.js +++ b/server/methods/reportMessage.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { Messages, Reports } from 'meteor/rocketchat:models'; Meteor.methods({ reportMessage(messageId, description) { @@ -18,13 +19,13 @@ Meteor.methods({ }); } - const message = RocketChat.models.Messages.findOneById(messageId); + const message = Messages.findOneById(messageId); if (!message) { throw new Meteor.Error('error-invalid-message_id', 'Invalid message id', { method: 'reportMessage', }); } - return RocketChat.models.Reports.createWithMessageDescriptionAndUserId(message, description, Meteor.userId()); + return Reports.createWithMessageDescriptionAndUserId(message, description, Meteor.userId()); }, }); diff --git a/server/methods/requestDataDownload.js b/server/methods/requestDataDownload.js index edce06739bd7..181768005c1f 100644 --- a/server/methods/requestDataDownload.js +++ b/server/methods/requestDataDownload.js @@ -1,11 +1,13 @@ import { Meteor } from 'meteor/meteor'; +import { ExportOperations } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; import fs from 'fs'; import path from 'path'; let tempFolder = '/tmp/userData'; -if (RocketChat.settings.get('UserData_FileSystemPath') != null) { - if (RocketChat.settings.get('UserData_FileSystemPath').trim() !== '') { - tempFolder = RocketChat.settings.get('UserData_FileSystemPath'); +if (settings.get('UserData_FileSystemPath') != null) { + if (settings.get('UserData_FileSystemPath').trim() !== '') { + tempFolder = settings.get('UserData_FileSystemPath'); } } @@ -14,7 +16,7 @@ Meteor.methods({ const currentUserData = Meteor.user(); const userId = currentUserData._id; - const lastOperation = RocketChat.models.ExportOperations.findLastOperationByUser(userId, fullExport); + const lastOperation = ExportOperations.findLastOperationByUser(userId, fullExport); if (lastOperation) { const yesterday = new Date(); @@ -58,7 +60,7 @@ Meteor.methods({ fullExport, }; - RocketChat.models.ExportOperations.create(exportOperation); + ExportOperations.create(exportOperation); return { requested: true, diff --git a/server/methods/resetAvatar.js b/server/methods/resetAvatar.js index f4871d146676..bf97d48c8197 100644 --- a/server/methods/resetAvatar.js +++ b/server/methods/resetAvatar.js @@ -1,6 +1,9 @@ import { Meteor } from 'meteor/meteor'; import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; import { FileUpload } from 'meteor/rocketchat:file-upload'; +import { Users } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; +import { Notifications } from 'meteor/rocketchat:notifications'; Meteor.methods({ resetAvatar() { @@ -10,7 +13,7 @@ Meteor.methods({ }); } - if (!RocketChat.settings.get('Accounts_AllowUserAvatarChange')) { + if (!settings.get('Accounts_AllowUserAvatarChange')) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'resetAvatar', }); @@ -18,8 +21,8 @@ Meteor.methods({ const user = Meteor.user(); FileUpload.getStore('Avatars').deleteByName(user.username); - RocketChat.models.Users.unsetAvatarOrigin(user._id); - RocketChat.Notifications.notifyLogged('updateAvatar', { + Users.unsetAvatarOrigin(user._id); + Notifications.notifyLogged('updateAvatar', { username: user.username, }); }, diff --git a/server/methods/roomNameExists.js b/server/methods/roomNameExists.js index 064f7ae28546..6e621e1e8ddf 100644 --- a/server/methods/roomNameExists.js +++ b/server/methods/roomNameExists.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { Rooms } from 'meteor/rocketchat:models'; Meteor.methods({ roomNameExists(rid) { @@ -10,7 +11,7 @@ Meteor.methods({ method: 'roomExists', }); } - const room = RocketChat.models.Rooms.findOneByName(rid); + const room = Rooms.findOneByName(rid); return !!room; }, }); diff --git a/server/methods/saveUserPreferences.js b/server/methods/saveUserPreferences.js index 8b5b4ca71bdf..ff3cf8647771 100644 --- a/server/methods/saveUserPreferences.js +++ b/server/methods/saveUserPreferences.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; +import { Users, Subscriptions } from 'meteor/rocketchat:models'; Meteor.methods({ saveUserPreferences(settings) { @@ -51,11 +52,11 @@ Meteor.methods({ } = (user.settings && user.settings.preferences) || {}; if (user.settings == null) { - RocketChat.models.Users.clearSettings(user._id); + Users.clearSettings(user._id); } if (settings.language != null) { - RocketChat.models.Users.setLanguage(user._id, settings.language); + Users.setLanguage(user._id, settings.language); } // Keep compatibility with old values @@ -69,36 +70,36 @@ Meteor.methods({ throw new Meteor.Error('invalid-idle-time-limit-value', 'Invalid idleTimeLimit'); } - RocketChat.models.Users.setPreferences(user._id, settings); + Users.setPreferences(user._id, settings); // propagate changed notification preferences Meteor.defer(() => { if (settings.desktopNotifications && oldDesktopNotifications !== settings.desktopNotifications) { if (settings.desktopNotifications === 'default') { - RocketChat.models.Subscriptions.clearDesktopNotificationUserPreferences(user._id); + Subscriptions.clearDesktopNotificationUserPreferences(user._id); } else { - RocketChat.models.Subscriptions.updateDesktopNotificationUserPreferences(user._id, settings.desktopNotifications); + Subscriptions.updateDesktopNotificationUserPreferences(user._id, settings.desktopNotifications); } } if (settings.mobileNotifications && oldMobileNotifications !== settings.mobileNotifications) { if (settings.mobileNotifications === 'default') { - RocketChat.models.Subscriptions.clearMobileNotificationUserPreferences(user._id); + Subscriptions.clearMobileNotificationUserPreferences(user._id); } else { - RocketChat.models.Subscriptions.updateMobileNotificationUserPreferences(user._id, settings.mobileNotifications); + Subscriptions.updateMobileNotificationUserPreferences(user._id, settings.mobileNotifications); } } if (settings.emailNotificationMode && oldEmailNotifications !== settings.emailNotificationMode) { if (settings.emailNotificationMode === 'default') { - RocketChat.models.Subscriptions.clearEmailNotificationUserPreferences(user._id); + Subscriptions.clearEmailNotificationUserPreferences(user._id); } else { - RocketChat.models.Subscriptions.updateEmailNotificationUserPreferences(user._id, settings.emailNotificationMode); + Subscriptions.updateEmailNotificationUserPreferences(user._id, settings.emailNotificationMode); } } if (Array.isArray(settings.highlights)) { - RocketChat.models.Subscriptions.updateUserHighlights(user._id, settings.highlights); + Subscriptions.updateUserHighlights(user._id, settings.highlights); } }); diff --git a/server/methods/saveUserProfile.js b/server/methods/saveUserProfile.js index b50d17059617..8746380afb6b 100644 --- a/server/methods/saveUserProfile.js +++ b/server/methods/saveUserProfile.js @@ -1,13 +1,16 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; import { Accounts } from 'meteor/accounts-base'; +import { saveCustomFields, passwordPolicy } from 'meteor/rocketchat:lib'; +import { Users } from 'meteor/rocketchat:models'; +import { settings as rcSettings } from 'meteor/rocketchat:settings'; Meteor.methods({ saveUserProfile(settings, customFields) { check(settings, Object); check(customFields, Match.Maybe(Object)); - if (!RocketChat.settings.get('Accounts_AllowUserProfileChange')) { + if (!rcSettings.get('Accounts_AllowUserProfileChange')) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'saveUserProfile', }); @@ -19,7 +22,7 @@ Meteor.methods({ }); } - const user = RocketChat.models.Users.findOneById(Meteor.userId()); + const user = Users.findOneById(Meteor.userId()); function checkPassword(user = {}, typedPassword) { if (!(user.services && user.services.password && user.services.password.bcrypt && user.services.password.bcrypt.trim())) { @@ -56,24 +59,24 @@ Meteor.methods({ } // Should be the last check to prevent error when trying to check password for users without password - if ((settings.newPassword) && RocketChat.settings.get('Accounts_AllowPasswordChange') === true) { + if ((settings.newPassword) && rcSettings.get('Accounts_AllowPasswordChange') === true) { if (!checkPassword(user, settings.typedPassword)) { throw new Meteor.Error('error-invalid-password', 'Invalid password', { method: 'saveUserProfile', }); } - RocketChat.passwordPolicy.validate(settings.newPassword); + passwordPolicy.validate(settings.newPassword); Accounts.setPassword(Meteor.userId(), settings.newPassword, { logout: false, }); } - RocketChat.models.Users.setProfile(Meteor.userId(), {}); + Users.setProfile(Meteor.userId(), {}); if (customFields && Object.keys(customFields).length) { - RocketChat.saveCustomFields(Meteor.userId(), customFields); + saveCustomFields(Meteor.userId(), customFields); } return true; diff --git a/server/methods/sendConfirmationEmail.js b/server/methods/sendConfirmationEmail.js index b90721f3c05f..a65cbaf04882 100644 --- a/server/methods/sendConfirmationEmail.js +++ b/server/methods/sendConfirmationEmail.js @@ -2,12 +2,14 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; import { Accounts } from 'meteor/accounts-base'; import * as Mailer from 'meteor/rocketchat:mailer'; +import { Users } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; let subject = ''; let html = ''; Meteor.startup(() => { - RocketChat.settings.get('Verification_Email_Subject', function(key, value) { + settings.get('Verification_Email_Subject', function(key, value) { subject = Mailer.replace(value || ''); }); @@ -21,7 +23,7 @@ Meteor.methods({ check(to, String); const email = to.trim(); - const user = RocketChat.models.Users.findOneByEmailAddress(email); + const user = Users.findOneByEmailAddress(email); if (!user) { return false; diff --git a/server/methods/sendForgotPasswordEmail.js b/server/methods/sendForgotPasswordEmail.js index cd22b689454f..bbac968119bb 100644 --- a/server/methods/sendForgotPasswordEmail.js +++ b/server/methods/sendForgotPasswordEmail.js @@ -3,6 +3,8 @@ import { 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'; let template = ''; @@ -18,7 +20,7 @@ Meteor.methods({ let email = to.trim(); - const user = RocketChat.models.Users.findOneByEmailAddress(email); + const user = Users.findOneByEmailAddress(email); if (!user) { return false; @@ -27,7 +29,7 @@ Meteor.methods({ const regex = new RegExp(`^${ s.escapeRegExp(email) }$`, 'i'); email = (user.emails || []).map((item) => item.address).find((userEmail) => regex.test(userEmail)); - const subject = Mailer.replace(RocketChat.settings.get('Forgot_Password_Email_Subject') || '', { + const subject = Mailer.replace(settings.get('Forgot_Password_Email_Subject') || '', { name: user.name, email, }); @@ -37,7 +39,7 @@ Meteor.methods({ email, }); - Accounts.emailTemplates.from = `${ RocketChat.settings.get('Site_Name') } <${ RocketChat.settings.get('From_Email') }>`; + Accounts.emailTemplates.from = `${ settings.get('Site_Name') } <${ settings.get('From_Email') }>`; try { diff --git a/server/methods/setAvatarFromService.js b/server/methods/setAvatarFromService.js index 1bc249bd5aa4..49c239f1f8bd 100644 --- a/server/methods/setAvatarFromService.js +++ b/server/methods/setAvatarFromService.js @@ -1,6 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; +import { settings } from 'meteor/rocketchat:settings'; +import { setUserAvatar } from 'meteor/rocketchat:lib'; Meteor.methods({ setAvatarFromService(dataURI, contentType, service) { @@ -14,7 +16,7 @@ Meteor.methods({ }); } - if (!RocketChat.settings.get('Accounts_AllowUserAvatarChange')) { + if (!settings.get('Accounts_AllowUserAvatarChange')) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setAvatarFromService', }); @@ -22,7 +24,7 @@ Meteor.methods({ const user = Meteor.user(); - return RocketChat.setUserAvatar(user, dataURI, contentType, service); + return setUserAvatar(user, dataURI, contentType, service); }, }); diff --git a/server/methods/setUserActiveStatus.js b/server/methods/setUserActiveStatus.js index c2e247c22347..6a18bc6b9cab 100644 --- a/server/methods/setUserActiveStatus.js +++ b/server/methods/setUserActiveStatus.js @@ -2,6 +2,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; import { Accounts } from 'meteor/accounts-base'; import * as Mailer from 'meteor/rocketchat:mailer'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Users, Subscriptions } from 'meteor/rocketchat:models'; import { settings } from 'meteor/rocketchat:settings'; Meteor.methods({ @@ -15,28 +17,28 @@ Meteor.methods({ }); } - if (RocketChat.authz.hasPermission(Meteor.userId(), 'edit-other-user-active-status') !== true) { + if (hasPermission(Meteor.userId(), 'edit-other-user-active-status') !== true) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setUserActiveStatus', }); } - const user = RocketChat.models.Users.findOneById(userId); + const user = Users.findOneById(userId); if (!user) { return false; } - RocketChat.models.Users.setUserActive(userId, active); + Users.setUserActive(userId, active); if (user.username) { - RocketChat.models.Subscriptions.setArchivedByUsername(user.username, !active); + Subscriptions.setArchivedByUsername(user.username, !active); } if (active === false) { - RocketChat.models.Users.unsetLoginTokens(userId); + Users.unsetLoginTokens(userId); } else { - RocketChat.models.Users.unsetReason(userId); + Users.unsetReason(userId); } if (active && !settings.get('Accounts_Send_Email_When_Activating')) { return true; @@ -50,7 +52,7 @@ Meteor.methods({ const email = { to: destinations, - from: RocketChat.settings.get('From_Email'), + from: settings.get('From_Email'), subject: Accounts.emailTemplates.userActivated.subject({ active }), html: Accounts.emailTemplates.userActivated.html({ active, name: user.name, username: user.username }), }; diff --git a/server/methods/setUserPassword.js b/server/methods/setUserPassword.js index a4ee82116815..c98ef9226fc4 100644 --- a/server/methods/setUserPassword.js +++ b/server/methods/setUserPassword.js @@ -1,6 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; import { Accounts } from 'meteor/accounts-base'; +import { Users } from 'meteor/rocketchat:models'; +import { passwordPolicy } from 'meteor/rocketchat:lib'; Meteor.methods({ setUserPassword(password) { @@ -14,7 +16,7 @@ Meteor.methods({ }); } - const user = RocketChat.models.Users.findOneById(userId); + const user = Users.findOneById(userId); if (user && user.requirePasswordChange !== true) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { @@ -22,12 +24,12 @@ Meteor.methods({ }); } - RocketChat.passwordPolicy.validate(password); + passwordPolicy.validate(password); Accounts.setPassword(userId, password, { logout: false, }); - return RocketChat.models.Users.unsetRequirePasswordChange(userId); + return Users.unsetRequirePasswordChange(userId); }, }); diff --git a/server/methods/toogleFavorite.js b/server/methods/toogleFavorite.js index 4259c233cb57..4d94c9641190 100644 --- a/server/methods/toogleFavorite.js +++ b/server/methods/toogleFavorite.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; +import { Subscriptions } from 'meteor/rocketchat:models'; Meteor.methods({ toggleFavorite(rid, f) { @@ -12,7 +13,7 @@ Meteor.methods({ }); } - const userSubscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, Meteor.userId()); + const userSubscription = Subscriptions.findOneByRoomIdAndUserId(rid, Meteor.userId()); if (!userSubscription) { throw new Meteor.Error('error-invalid-subscription', 'You must be part of a room to favorite it', @@ -20,6 +21,6 @@ Meteor.methods({ ); } - return RocketChat.models.Subscriptions.setFavoriteByRoomIdAndUserId(rid, Meteor.userId(), f); + return Subscriptions.setFavoriteByRoomIdAndUserId(rid, Meteor.userId(), f); }, }); diff --git a/server/methods/unmuteUserInRoom.js b/server/methods/unmuteUserInRoom.js index 0349a0d797cd..dffe6ee9e86b 100644 --- a/server/methods/unmuteUserInRoom.js +++ b/server/methods/unmuteUserInRoom.js @@ -1,5 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Users, Subscriptions, Rooms, Messages } from 'meteor/rocketchat:models'; Meteor.methods({ unmuteUserInRoom(data) { @@ -10,13 +12,13 @@ Meteor.methods({ username: String, })); - 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: 'unmuteUserInRoom', }); } - 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', { @@ -31,20 +33,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: 'unmuteUserInRoom', }); } - const unmutedUser = RocketChat.models.Users.findOneByUsername(data.username); + const unmutedUser = Users.findOneByUsername(data.username); - RocketChat.models.Rooms.unmuteUsernameByRoomId(data.rid, unmutedUser.username); + Rooms.unmuteUsernameByRoomId(data.rid, unmutedUser.username); - const fromUser = RocketChat.models.Users.findOneById(fromId); + const fromUser = Users.findOneById(fromId); - RocketChat.models.Messages.createUserUnmutedWithRoomIdAndUser(data.rid, unmutedUser, { + Messages.createUserUnmutedWithRoomIdAndUser(data.rid, unmutedUser, { u: { _id: fromUser._id, username: fromUser.username, diff --git a/server/methods/userSetUtcOffset.js b/server/methods/userSetUtcOffset.js index 941950e0877b..abd5c5cbf655 100644 --- a/server/methods/userSetUtcOffset.js +++ b/server/methods/userSetUtcOffset.js @@ -1,6 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; +import { Users } from 'meteor/rocketchat:models'; Meteor.methods({ userSetUtcOffset(utcOffset) { @@ -12,7 +13,7 @@ Meteor.methods({ this.unblock(); - return RocketChat.models.Users.setUtcOffset(this.userId, utcOffset); + return Users.setUtcOffset(this.userId, utcOffset); }, }); diff --git a/server/publications/activeUsers.js b/server/publications/activeUsers.js index 05bdf63977cf..703cb0c212e4 100644 --- a/server/publications/activeUsers.js +++ b/server/publications/activeUsers.js @@ -1,11 +1,12 @@ import { Meteor } from 'meteor/meteor'; +import { Users } from 'meteor/rocketchat:models'; Meteor.publish('activeUsers', function() { if (!this.userId) { return this.ready(); } - return RocketChat.models.Users.findUsersNotOffline({ + return Users.findUsersNotOffline({ fields: { username: 1, name: 1, diff --git a/server/publications/channelAndPrivateAutocomplete.js b/server/publications/channelAndPrivateAutocomplete.js index 43b2333e73dc..3da5e2f9b7a9 100644 --- a/server/publications/channelAndPrivateAutocomplete.js +++ b/server/publications/channelAndPrivateAutocomplete.js @@ -1,11 +1,13 @@ import { Meteor } from 'meteor/meteor'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Rooms } from 'meteor/rocketchat:models'; Meteor.publish('channelAndPrivateAutocomplete', function(selector) { if (!this.userId) { return this.ready(); } - if (RocketChat.authz.hasPermission(this.userId, 'view-other-user-channels') !== true) { + if (hasPermission(this.userId, 'view-other-user-channels') !== true) { return this.ready(); } @@ -21,7 +23,7 @@ Meteor.publish('channelAndPrivateAutocomplete', function(selector) { }, }; - const cursorHandle = RocketChat.models.Rooms.findChannelAndPrivateByNameStarting(selector.name, options).observeChanges({ + const cursorHandle = Rooms.findChannelAndPrivateByNameStarting(selector.name, options).observeChanges({ added(_id, record) { return pub.added('autocompleteRecords', _id, record); }, diff --git a/server/publications/fullUserData.js b/server/publications/fullUserData.js index 132adea23493..d8e827a73f59 100644 --- a/server/publications/fullUserData.js +++ b/server/publications/fullUserData.js @@ -1,11 +1,12 @@ import { Meteor } from 'meteor/meteor'; +import { getFullUserData } from 'meteor/rocketchat:lib'; Meteor.publish('fullUserData', function(filter, limit) { if (!this.userId) { return this.ready(); } - const result = RocketChat.getFullUserData({ + const result = getFullUserData({ userId: this.userId, filter, limit, diff --git a/server/publications/messages.js b/server/publications/messages.js index e053e9adb9e3..6e9d0d9a8ced 100644 --- a/server/publications/messages.js +++ b/server/publications/messages.js @@ -1,5 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import { composeMessageObjectWithUser } from 'meteor/rocketchat:utils'; +import { Messages } from 'meteor/rocketchat:models'; Meteor.publish('messages', function(rid/* , start*/) { if (!this.userId) { @@ -16,7 +18,7 @@ Meteor.publish('messages', function(rid/* , start*/) { return this.ready(); } - const cursor = RocketChat.models.Messages.findVisibleByRoomId(rid, { + const cursor = Messages.findVisibleByRoomId(rid, { sort: { ts: -1, }, @@ -25,14 +27,14 @@ Meteor.publish('messages', function(rid/* , start*/) { const cursorHandle = cursor.observeChanges({ added(_id, record) { - return publication.added('rocketchat_message', _id, RocketChat.composeMessageObjectWithUser(record, publication.userId)); + return publication.added('rocketchat_message', _id, composeMessageObjectWithUser(record, publication.userId)); }, changed(_id, record) { - return publication.changed('rocketchat_message', _id, RocketChat.composeMessageObjectWithUser(record, publication.userId)); + return publication.changed('rocketchat_message', _id, composeMessageObjectWithUser(record, publication.userId)); }, }); - const cursorDelete = RocketChat.models.Messages.findInvisibleByRoomId(rid, { + const cursorDelete = Messages.findInvisibleByRoomId(rid, { fields: { _id: 1, }, @@ -85,8 +87,8 @@ Meteor.methods({ if (lastUpdate instanceof Date) { return { - updated: RocketChat.models.Messages.findForUpdates(rid, lastUpdate, options).fetch(), - deleted: RocketChat.models.Messages.trashFindDeletedAfter(lastUpdate, { rid }, { ...options, fields: { _id: 1, _deletedAt: 1 } }).fetch(), + updated: Messages.findForUpdates(rid, lastUpdate, options).fetch(), + deleted: Messages.trashFindDeletedAfter(lastUpdate, { rid }, { ...options, fields: { _id: 1, _deletedAt: 1 } }).fetch(), }; } diff --git a/server/publications/room.js b/server/publications/room.js index 3d220ca092c1..f722bf7a7781 100644 --- a/server/publications/room.js +++ b/server/publications/room.js @@ -1,4 +1,9 @@ import { Meteor } from 'meteor/meteor'; +import { roomTypes } from 'meteor/rocketchat:utils'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Rooms, Subscriptions } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; +import { Notifications } from 'meteor/rocketchat:notifications'; import _ from 'underscore'; const fields = { @@ -55,8 +60,8 @@ Meteor.methods({ let options = { fields }; if (!Meteor.userId()) { - if (RocketChat.settings.get('Accounts_AllowAnonymousRead') === true) { - return RocketChat.models.Rooms.findByDefaultAndTypes(true, ['c'], options).fetch(); + if (settings.get('Accounts_AllowAnonymousRead') === true) { + return Rooms.findByDefaultAndTypes(true, ['c'], options).fetch(); } return []; } @@ -69,24 +74,24 @@ Meteor.methods({ if (updatedAt instanceof Date) { return { - update: RocketChat.models.Rooms.findBySubscriptionUserIdUpdatedAfter(Meteor.userId(), updatedAt, options).fetch(), - remove: RocketChat.models.Rooms.trashFindDeletedAfter(updatedAt, {}, { fields: { _id: 1, _deletedAt: 1 } }).fetch(), + update: Rooms.findBySubscriptionUserIdUpdatedAfter(Meteor.userId(), updatedAt, options).fetch(), + remove: Rooms.trashFindDeletedAfter(updatedAt, {}, { fields: { _id: 1, _deletedAt: 1 } }).fetch(), }; } - return RocketChat.models.Rooms.findBySubscriptionUserId(Meteor.userId(), options).fetch(); + return Rooms.findBySubscriptionUserId(Meteor.userId(), options).fetch(); }, getRoomByTypeAndName(type, name) { const userId = Meteor.userId(); - 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: 'getRoomByTypeAndName' }); } - const roomFind = RocketChat.roomTypes.getRoomFind(type); + const roomFind = roomTypes.getRoomFind(type); - const room = roomFind ? roomFind.call(this, name) : RocketChat.models.Rooms.findByTypeAndName(type, name); + const room = roomFind ? roomFind.call(this, name) : Rooms.findByTypeAndName(type, name); if (!room) { throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'getRoomByTypeAndName' }); @@ -96,7 +101,7 @@ Meteor.methods({ throw new Meteor.Error('error-no-permission', 'No permission', { method: 'getRoomByTypeAndName' }); } - if (RocketChat.settings.get('Store_Last_Message') && !RocketChat.authz.hasPermission(userId, 'preview-c-room')) { + if (settings.get('Store_Last_Message') && !hasPermission(userId, 'preview-c-room')) { delete room.lastMessage; } @@ -106,15 +111,15 @@ Meteor.methods({ const getSubscriptions = (id) => { const fields = { 'u._id': 1 }; - return RocketChat.models.Subscriptions.trashFind({ rid: id }, { fields }); + return Subscriptions.trashFind({ rid: id }, { fields }); }; -RocketChat.models.Rooms.on('change', ({ clientAction, id, data }) => { +Rooms.on('change', ({ clientAction, id, data }) => { switch (clientAction) { case 'updated': case 'inserted': // Override data cuz we do not publish all fields - data = RocketChat.models.Rooms.findOneById(id, { fields }); + data = Rooms.findOneById(id, { fields }); break; case 'removed': @@ -125,9 +130,9 @@ RocketChat.models.Rooms.on('change', ({ clientAction, id, data }) => { if (data) { if (clientAction === 'removed') { getSubscriptions(clientAction, id).forEach(({ u }) => { - RocketChat.Notifications.notifyUserInThisInstance(u._id, 'rooms-changed', clientAction, data); + Notifications.notifyUserInThisInstance(u._id, 'rooms-changed', clientAction, data); }); } - RocketChat.Notifications.streamUser.__emit(id, clientAction, data); + Notifications.streamUser.__emit(id, clientAction, data); } }); diff --git a/server/publications/roomSubscriptionsByRole.js b/server/publications/roomSubscriptionsByRole.js index 254088183427..0d472b6ee303 100644 --- a/server/publications/roomSubscriptionsByRole.js +++ b/server/publications/roomSubscriptionsByRole.js @@ -1,15 +1,17 @@ import { Meteor } from 'meteor/meteor'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Subscriptions } from 'meteor/rocketchat:models'; Meteor.publish('roomSubscriptionsByRole', function(rid, role) { if (!this.userId) { return this.ready(); } - if (RocketChat.authz.hasPermission(this.userId, 'view-other-user-channels') !== true) { + if (hasPermission(this.userId, 'view-other-user-channels') !== true) { return this.ready(); } - return RocketChat.models.Subscriptions.findByRoomIdAndRoles(rid, role, { + return Subscriptions.findByRoomIdAndRoles(rid, role, { fields: { rid: 1, name: 1, diff --git a/server/publications/spotlight.js b/server/publications/spotlight.js index 74642e54a929..989726cb7ef8 100644 --- a/server/publications/spotlight.js +++ b/server/publications/spotlight.js @@ -1,9 +1,13 @@ import { Meteor } from 'meteor/meteor'; import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Users, Subscriptions, Rooms } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; +import { roomTypes } from 'meteor/rocketchat:utils'; import s from 'underscore.string'; function fetchRooms(userId, rooms) { - if (!RocketChat.settings.get('Store_Last_Message') || RocketChat.authz.hasPermission(userId, 'preview-c-room')) { + if (!settings.get('Store_Last_Message') || hasPermission(userId, 'preview-c-room')) { return rooms; } @@ -44,8 +48,8 @@ Meteor.methods({ }; const { userId } = this; if (userId == null) { - if (RocketChat.settings.get('Accounts_AllowAnonymousRead') === true) { - result.rooms = fetchRooms(userId, RocketChat.models.Rooms.findByNameAndTypeNotDefault(regex, 'c', roomOptions).fetch()); + if (settings.get('Accounts_AllowAnonymousRead') === true) { + result.rooms = fetchRooms(userId, Rooms.findByNameAndTypeNotDefault(regex, 'c', roomOptions).fetch()); } return result; } @@ -58,33 +62,33 @@ Meteor.methods({ }, sort: {}, }; - if (RocketChat.settings.get('UI_Use_Real_Name')) { + if (settings.get('UI_Use_Real_Name')) { userOptions.sort.name = 1; } else { userOptions.sort.username = 1; } - if (RocketChat.authz.hasPermission(userId, 'view-outside-room')) { - if (type.users === true && RocketChat.authz.hasPermission(userId, 'view-d-room')) { - result.users = RocketChat.models.Users.findByActiveUsersExcept(text, usernames, userOptions).fetch(); + if (hasPermission(userId, 'view-outside-room')) { + if (type.users === true && hasPermission(userId, 'view-d-room')) { + result.users = Users.findByActiveUsersExcept(text, usernames, userOptions).fetch(); } - if (type.rooms === true && RocketChat.authz.hasPermission(userId, 'view-c-room')) { - const searchableRoomTypes = Object.entries(RocketChat.roomTypes.roomTypes) + if (type.rooms === true && hasPermission(userId, 'view-c-room')) { + const searchableRoomTypes = Object.entries(roomTypes.roomTypes) .filter((roomType) => roomType[1].includeInRoomSearch()) .map((roomType) => roomType[0]); - const roomIds = RocketChat.models.Subscriptions.findByUserIdAndTypes(userId, searchableRoomTypes, { fields: { rid: 1 } }).fetch().map((s) => s.rid); - result.rooms = fetchRooms(userId, RocketChat.models.Rooms.findByNameAndTypesNotInIds(regex, searchableRoomTypes, roomIds, roomOptions).fetch()); + const roomIds = Subscriptions.findByUserIdAndTypes(userId, searchableRoomTypes, { fields: { rid: 1 } }).fetch().map((s) => s.rid); + result.rooms = fetchRooms(userId, Rooms.findByNameAndTypesNotInIds(regex, searchableRoomTypes, roomIds, roomOptions).fetch()); } } else if (type.users === true && rid) { - const subscriptions = RocketChat.models.Subscriptions.find({ + const subscriptions = Subscriptions.find({ rid, 'u.username': { $regex: regex, $nin: [...usernames, Meteor.user().username], }, }, { limit: userOptions.limit }).fetch().map(({ u }) => u._id); - result.users = RocketChat.models.Users.find({ _id: { $in: subscriptions } }, { + result.users = Users.find({ _id: { $in: subscriptions } }, { fields: userOptions.fields, sort: userOptions.sort, }).fetch(); diff --git a/server/publications/subscription.js b/server/publications/subscription.js index d9727f61d006..253efbf2404f 100644 --- a/server/publications/subscription.js +++ b/server/publications/subscription.js @@ -1,4 +1,6 @@ import { Meteor } from 'meteor/meteor'; +import { Subscriptions } from 'meteor/rocketchat:models'; +import { Notifications } from 'meteor/rocketchat:notifications'; const fields = { t: 1, @@ -46,14 +48,14 @@ Meteor.methods({ const options = { fields }; - const records = RocketChat.models.Subscriptions.findByUserId(Meteor.userId(), options).fetch(); + const records = Subscriptions.findByUserId(Meteor.userId(), options).fetch(); if (updatedAt instanceof Date) { return { update: records.filter(function(record) { return record._updatedAt > updatedAt; }), - remove: RocketChat.models.Subscriptions.trashFindDeletedAfter(updatedAt, { + remove: Subscriptions.trashFindDeletedAfter(updatedAt, { 'u._id': Meteor.userId(), }, { fields: { @@ -68,20 +70,20 @@ Meteor.methods({ }, }); -RocketChat.models.Subscriptions.on('change', ({ clientAction, id, data }) => { +Subscriptions.on('change', ({ clientAction, id, data }) => { switch (clientAction) { case 'inserted': case 'updated': // Override data cuz we do not publish all fields - data = RocketChat.models.Subscriptions.findOneById(id, { fields }); + data = Subscriptions.findOneById(id, { fields }); break; case 'removed': - data = RocketChat.models.Subscriptions.trashFindOneById(id, { fields: { u: 1, rid: 1 } }); + data = Subscriptions.trashFindOneById(id, { fields: { u: 1, rid: 1 } }); break; } - RocketChat.Notifications.streamUser.__emit(data.u._id, clientAction, data); + Notifications.streamUser.__emit(data.u._id, clientAction, data); - RocketChat.Notifications.notifyUserInThisInstance(data.u._id, 'subscriptions-changed', clientAction, data); + Notifications.notifyUserInThisInstance(data.u._id, 'subscriptions-changed', clientAction, data); }); diff --git a/server/publications/userAutocomplete.js b/server/publications/userAutocomplete.js index 9241013edd8f..2af767e47aaa 100644 --- a/server/publications/userAutocomplete.js +++ b/server/publications/userAutocomplete.js @@ -1,4 +1,5 @@ import { Meteor } from 'meteor/meteor'; +import { Users } from 'meteor/rocketchat:models'; import _ from 'underscore'; Meteor.publish('userAutocomplete', function(selector) { @@ -25,7 +26,7 @@ Meteor.publish('userAutocomplete', function(selector) { const pub = this; const exceptions = selector.exceptions || []; - const cursorHandle = RocketChat.models.Users.findActiveByUsernameOrNameRegexWithExceptions(selector.term, exceptions, options).observeChanges({ + const cursorHandle = Users.findActiveByUsernameOrNameRegexWithExceptions(selector.term, exceptions, options).observeChanges({ added(_id, record) { return pub.added('autocompleteRecords', _id, record); }, diff --git a/server/publications/userChannels.js b/server/publications/userChannels.js index 409235234e54..981c04742f1d 100644 --- a/server/publications/userChannels.js +++ b/server/publications/userChannels.js @@ -1,15 +1,17 @@ import { Meteor } from 'meteor/meteor'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Subscriptions } from 'meteor/rocketchat:models'; Meteor.publish('userChannels', function(userId) { if (!this.userId) { return this.ready(); } - if (RocketChat.authz.hasPermission(this.userId, 'view-other-user-channels') !== true) { + if (hasPermission(this.userId, 'view-other-user-channels') !== true) { return this.ready(); } - return RocketChat.models.Subscriptions.findByUserId(userId, { + return Subscriptions.findByUserId(userId, { fields: { rid: 1, name: 1, diff --git a/server/publications/userData.js b/server/publications/userData.js index 3bd9f8a24c63..092fd2f89f9e 100644 --- a/server/publications/userData.js +++ b/server/publications/userData.js @@ -1,11 +1,12 @@ import { Meteor } from 'meteor/meteor'; +import { Users } from 'meteor/rocketchat:models'; Meteor.publish('userData', function() { if (!this.userId) { return this.ready(); } - return RocketChat.models.Users.find(this.userId, { + return Users.find(this.userId, { fields: { name: 1, username: 1, diff --git a/server/startup/avatar.js b/server/startup/avatar.js index bb589e9aa38f..ca0aba1df74d 100644 --- a/server/startup/avatar.js +++ b/server/startup/avatar.js @@ -4,6 +4,9 @@ import _ from 'underscore'; import sharp from 'sharp'; import { Cookies } from 'meteor/ostrio:cookies'; import { FileUpload } from 'meteor/rocketchat:file-upload'; +import { getAvatarColor } from 'meteor/rocketchat:utils'; +import { Users, Avatars } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; const cookie = new Cookies(); @@ -18,7 +21,7 @@ function isUserAuthenticated(req) { rc_token = cookie.get('rc_token', headers.cookie); } - if (!rc_uid || !rc_token || !RocketChat.models.Users.findOneByIdAndLoginToken(rc_uid, rc_token)) { + if (!rc_uid || !rc_token || !Users.findOneByIdAndLoginToken(rc_uid, rc_token)) { return false; } @@ -30,7 +33,7 @@ const warnUnauthenticatedAccess = _.debounce(() => { }, 60000 * 30); // 30 minutes function userCanAccessAvatar(req) { - if (RocketChat.settings.get('Accounts_AvatarBlockUnauthenticatedAccess') === true) { + if (settings.get('Accounts_AvatarBlockUnauthenticatedAccess') === true) { return isUserAuthenticated(req); } @@ -46,7 +49,7 @@ Meteor.startup(function() { const params = { username: decodeURIComponent(req.url.replace(/^\//, '').replace(/\?.*$/, '')), }; - const cacheTime = req.query.cacheTime || RocketChat.settings.get('Accounts_AvatarCacheTime'); + const cacheTime = req.query.cacheTime || settings.get('Accounts_AvatarCacheTime'); if (_.isEmpty(params.username) || !userCanAccessAvatar(req)) { res.writeHead(403); @@ -65,7 +68,7 @@ Meteor.startup(function() { if (username[0] !== '@') { if (Meteor.settings && Meteor.settings.public && Meteor.settings.public.sandstorm) { - const user = RocketChat.models.Users.findOneByUsername(username); + const user = Users.findOneByUsername(username); if (user && user.services && user.services.sandstorm && user.services.sandstorm.picture) { res.setHeader('Location', user.services.sandstorm.picture); res.writeHead(302); @@ -73,7 +76,7 @@ Meteor.startup(function() { return; } } - file = RocketChat.models.Avatars.findOneByName(username); + file = Avatars.findOneByName(username); } if (file) { @@ -111,8 +114,8 @@ Meteor.startup(function() { } } - if (RocketChat.settings.get('UI_Use_Name_Avatar')) { - const user = RocketChat.models.Users.findOneByUsername(username, { + if (settings.get('UI_Use_Name_Avatar')) { + const user = Users.findOneByUsername(username, { fields: { name: 1, }, @@ -130,7 +133,7 @@ Meteor.startup(function() { color = '#000'; initials = username; } else { - color = RocketChat.getAvatarColor(username); + color = getAvatarColor(username); initials = username.replace(/[^A-Za-z0-9]/g, '').substr(0, 1).toUpperCase(); } diff --git a/server/startup/cron.js b/server/startup/cron.js index 5c6c14c6fa4a..c57b36e39d6c 100644 --- a/server/startup/cron.js +++ b/server/startup/cron.js @@ -4,6 +4,7 @@ import { Logger } from 'meteor/rocketchat:logger'; import { getWorkspaceAccessToken } from 'meteor/rocketchat:cloud'; import { SyncedCron } from 'meteor/littledata:synced-cron'; import { statistics } from 'meteor/rocketchat:statistics'; +import { settings } from 'meteor/rocketchat:settings'; const logger = new Logger('SyncedCron'); @@ -19,7 +20,7 @@ function generateStatistics() { cronStatistics.host = Meteor.absoluteUrl(); - if (RocketChat.settings.get('Statistics_reporting')) { + if (settings.get('Statistics_reporting')) { try { const headers = {}; const token = getWorkspaceAccessToken(); diff --git a/server/startup/i18n-validation.js b/server/startup/i18n-validation.js deleted file mode 100644 index 87fc70142389..000000000000 --- a/server/startup/i18n-validation.js +++ /dev/null @@ -1,68 +0,0 @@ -import { TAPi18next } from 'meteor/tap:i18n'; -import _ from 'underscore'; -import s from 'underscore.string'; - -function flat(obj, newObj = {}, path = '') { - for (const key of Object.keys(obj)) { - const value = obj[key]; - - if (_.isObject(value)) { - flat(value, newObj, `${ key }.`); - } else { - newObj[path + key] = value; - } - } - - return newObj; -} - -RocketChat.i18nValidation = function i18nValidation() { - const l = {}; - const keys = {}; - const errors = []; - const langs = Object.keys(TAPi18next.options.resStore); - - for (const lang of Object.keys(TAPi18next.options.resStore)) { - const value = TAPi18next.options.resStore[lang]; - - l[lang] = flat(value); - - for (const key of Object.keys(l[lang])) { - if (keys[key] == null) { - keys[key] = []; - } - keys[key].push(lang); - } - } - - let len = 0; - for (const key of Object.keys(keys)) { - const present = keys[key]; - - if (!(present.length !== langs.length)) { - continue; - } - - const error = (`${ _.difference(langs, present).join(',') }: missing translation for `).red + key.white + (`. Present in [${ present.join(',') }]`).red; - - errors.push(error); - - if (error.length > len) { - len = error.length; - } - } - - if (errors.length > 0) { - console.log('+'.red + s.rpad('', len - 28, '-').red + '+'.red); - - for (const error of errors) { - console.log('|'.red, s.rpad(`${ error }`, len).red, '|'.red); - } - - return console.log('+'.red + s.rpad('', len - 28, '-').red + '+'.red); - } -}; - -// Meteor.startup(function() { -// RocketChat.i18nValidation(); -// }); diff --git a/server/startup/initialData.js b/server/startup/initialData.js index 308764ab4cf0..22553d14cb1f 100644 --- a/server/startup/initialData.js +++ b/server/startup/initialData.js @@ -2,18 +2,22 @@ import { Meteor } from 'meteor/meteor'; import { Accounts } from 'meteor/accounts-base'; import { RocketChatFile } from 'meteor/rocketchat:file'; import { FileUpload } from 'meteor/rocketchat:file-upload'; +import { addUserRoles, getUsersInRole } from 'meteor/rocketchat:authorization'; +import { Users, Settings, Rooms } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; +import { checkUsernameAvailability, addUserToDefaultChannels } from 'meteor/rocketchat:lib'; import _ from 'underscore'; Meteor.startup(function() { Meteor.defer(() => { - if (!RocketChat.models.Rooms.findOneById('GENERAL')) { - RocketChat.models.Rooms.createWithIdTypeAndName('GENERAL', 'c', 'general', { + if (!Rooms.findOneById('GENERAL')) { + Rooms.createWithIdTypeAndName('GENERAL', 'c', 'general', { default: true, }); } - if (!RocketChat.models.Users.findOneById('rocket.cat')) { - RocketChat.models.Users.create({ + if (!Users.findOneById('rocket.cat')) { + Users.create({ _id: 'rocket.cat', name: 'Rocket.Cat', username: 'rocket.cat', @@ -24,7 +28,7 @@ Meteor.startup(function() { type: 'bot', }); - RocketChat.authz.addUserRoles('rocket.cat', 'bot'); + addUserRoles('rocket.cat', 'bot'); const rs = RocketChatFile.bufferToStream(new Buffer(Assets.getBinary('avatars/rocketcat.png'), 'utf8')); const fileStore = FileUpload.getStore('Avatars'); @@ -36,12 +40,12 @@ Meteor.startup(function() { }; Meteor.runAsUser('rocket.cat', () => { - fileStore.insert(file, rs, () => RocketChat.models.Users.setAvatarOrigin('rocket.cat', 'local')); + fileStore.insert(file, rs, () => Users.setAvatarOrigin('rocket.cat', 'local')); }); } if (process.env.ADMIN_PASS) { - if (_.isEmpty(RocketChat.authz.getUsersInRole('admin').fetch())) { + if (_.isEmpty(getUsersInRole('admin').fetch())) { console.log('Inserting admin user:'.green); const adminUser = { name: 'Administrator', @@ -62,7 +66,7 @@ Meteor.startup(function() { const re = /^[^@].*@[^@]+$/i; if (re.test(process.env.ADMIN_EMAIL)) { - if (!RocketChat.models.Users.findOneByEmailAddress(process.env.ADMIN_EMAIL)) { + if (!Users.findOneByEmailAddress(process.env.ADMIN_EMAIL)) { adminUser.emails = [{ address: process.env.ADMIN_EMAIL, verified: true, @@ -81,13 +85,13 @@ Meteor.startup(function() { let nameValidation; try { - nameValidation = new RegExp(`^${ RocketChat.settings.get('UTF8_Names_Validation') }$`); + nameValidation = new RegExp(`^${ settings.get('UTF8_Names_Validation') }$`); } catch (error) { nameValidation = new RegExp('^[0-9a-zA-Z-_.]+$'); } if (nameValidation.test(process.env.ADMIN_USERNAME)) { - if (RocketChat.checkUsernameAvailability(process.env.ADMIN_USERNAME)) { + if (checkUsernameAvailability(process.env.ADMIN_USERNAME)) { adminUser.username = process.env.ADMIN_USERNAME; } else { console.log('Username provided already exists; Ignoring environment variables ADMIN_USERNAME'.red); @@ -101,13 +105,13 @@ Meteor.startup(function() { adminUser.type = 'user'; - const id = RocketChat.models.Users.create(adminUser); + const id = Users.create(adminUser); Accounts.setPassword(id, process.env.ADMIN_PASS); console.log((`Password: ${ process.env.ADMIN_PASS }`).green); - RocketChat.authz.addUserRoles(id, 'admin'); + addUserRoles(id, 'admin'); } else { console.log('Users with admin role already exist; Ignoring environment variables ADMIN_PASS'.red); } @@ -119,33 +123,33 @@ Meteor.startup(function() { if (!initialUser._id) { console.log('No _id provided; Ignoring environment variable INITIAL_USER'.red); - } else if (!RocketChat.models.Users.findOneById(initialUser._id)) { + } else if (!Users.findOneById(initialUser._id)) { console.log('Inserting initial user:'.green); console.log(JSON.stringify(initialUser, null, 2).green); - RocketChat.models.Users.create(initialUser); + Users.create(initialUser); } } catch (e) { console.log('Error processing environment variable INITIAL_USER'.red, e); } } - if (_.isEmpty(RocketChat.authz.getUsersInRole('admin').fetch())) { - const oldestUser = RocketChat.models.Users.getOldest({ _id: 1, username: 1, name: 1 }); + if (_.isEmpty(getUsersInRole('admin').fetch())) { + const oldestUser = Users.getOldest({ _id: 1, username: 1, name: 1 }); if (oldestUser) { - RocketChat.authz.addUserRoles(oldestUser._id, 'admin'); + addUserRoles(oldestUser._id, 'admin'); console.log(`No admins are found. Set ${ oldestUser.username || oldestUser.name } as admin for being the oldest user`); } } - if (!_.isEmpty(RocketChat.authz.getUsersInRole('admin').fetch())) { - if (RocketChat.settings.get('Show_Setup_Wizard') === 'pending') { + if (!_.isEmpty(getUsersInRole('admin').fetch())) { + if (settings.get('Show_Setup_Wizard') === 'pending') { console.log('Setting Setup Wizard to "in_progress" because, at least, one admin was found'); - RocketChat.models.Settings.updateValueById('Show_Setup_Wizard', 'in_progress'); + Settings.updateValueById('Show_Setup_Wizard', 'in_progress'); } } - RocketChat.models.Users.removeById('rocketchat.internal.admin.test'); + Users.removeById('rocketchat.internal.admin.test'); if (process.env.TEST_MODE === 'true') { console.log('Inserting admin test user:'.green); @@ -172,25 +176,25 @@ Meteor.startup(function() { console.log((`Username: ${ adminUser.username }`).green); console.log((`Password: ${ adminUser._id }`).green); - if (RocketChat.models.Users.findOneByEmailAddress(adminUser.emails[0].address)) { + if (Users.findOneByEmailAddress(adminUser.emails[0].address)) { throw new Meteor.Error(`Email ${ adminUser.emails[0].address } already exists`, 'Rocket.Chat can\'t run in test mode'); } - if (!RocketChat.checkUsernameAvailability(adminUser.username)) { + if (!checkUsernameAvailability(adminUser.username)) { throw new Meteor.Error(`Username ${ adminUser.username } already exists`, 'Rocket.Chat can\'t run in test mode'); } - RocketChat.models.Users.create(adminUser); + Users.create(adminUser); Accounts.setPassword(adminUser._id, adminUser._id); - RocketChat.authz.addUserRoles(adminUser._id, 'admin'); + addUserRoles(adminUser._id, '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'); } - return RocketChat.addUserToDefaultChannels(adminUser, true); + return addUserToDefaultChannels(adminUser, true); } }); });