From 7cdb04426e87c7bbb2cab535d05108e50a33e5bf Mon Sep 17 00:00:00 2001 From: Marcos Spessatto Defendi Date: Fri, 15 Feb 2019 16:00:00 -0200 Subject: [PATCH] Remove dependency of RC namespace in rc-integrations and importer-hipchat-enterprise (#13386) * 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 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 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 --- .../package.js | 1 + .../server/importer.js | 43 ++++++++++--------- .../rocketchat-integrations/client/startup.js | 7 +-- .../client/views/integrations.js | 7 +-- .../client/views/integrationsIncoming.js | 12 +++--- .../client/views/integrationsNew.js | 4 +- .../client/views/integrationsOutgoing.js | 27 ++++++------ .../views/integrationsOutgoingHistory.js | 12 +++--- .../rocketchat-integrations/lib/rocketchat.js | 4 +- packages/rocketchat-integrations/package.js | 5 +++ .../rocketchat-integrations/server/api/api.js | 15 ++++--- .../rocketchat-integrations/server/index.js | 5 --- .../server/lib/triggerHandler.js | 42 +++++++++--------- .../server/lib/validation.js | 26 +++++------ .../server/methods/clearIntegrationHistory.js | 13 +++--- .../incoming/addIncomingIntegration.js | 19 ++++---- .../incoming/deleteIncomingIntegration.js | 13 +++--- .../incoming/updateIncomingIntegration.js | 27 ++++++------ .../outgoing/addOutgoingIntegration.js | 18 ++++---- .../outgoing/deleteOutgoingIntegration.js | 15 ++++--- .../outgoing/replayOutgoingIntegration.js | 16 ++++--- .../outgoing/updateOutgoingIntegration.js | 20 +++++---- .../server/processWebhookMessage.js | 1 - .../server/publications/integrationHistory.js | 11 ++--- .../server/publications/integrations.js | 11 ++--- .../server/triggers.js | 21 ++++----- .../rocketchat-lib/server/functions/index.js | 1 + .../server/functions/insertMessage.js | 12 +++--- 28 files changed, 217 insertions(+), 191 deletions(-) delete mode 100644 packages/rocketchat-integrations/server/processWebhookMessage.js diff --git a/packages/rocketchat-importer-hipchat-enterprise/package.js b/packages/rocketchat-importer-hipchat-enterprise/package.js index 4e04127d0e5..a6cfe8ca4f9 100644 --- a/packages/rocketchat-importer-hipchat-enterprise/package.js +++ b/packages/rocketchat-importer-hipchat-enterprise/package.js @@ -11,6 +11,7 @@ Package.onUse(function(api) { 'rocketchat:lib', 'rocketchat:importer', 'rocketchat:logger', + 'rocketchat:models', ]); api.mainModule('client/index.js', 'client'); diff --git a/packages/rocketchat-importer-hipchat-enterprise/server/importer.js b/packages/rocketchat-importer-hipchat-enterprise/server/importer.js index 2a87dd8ca17..d6a8f4b5454 100644 --- a/packages/rocketchat-importer-hipchat-enterprise/server/importer.js +++ b/packages/rocketchat-importer-hipchat-enterprise/server/importer.js @@ -9,7 +9,8 @@ import { SelectionUser, Imports, } from 'meteor/rocketchat:importer'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { Messages, Users, Subscriptions, Rooms } from 'meteor/rocketchat:models'; +import { insertMessage } from 'meteor/rocketchat:lib'; import { Readable } from 'stream'; import path from 'path'; import s from 'underscore.string'; @@ -261,7 +262,7 @@ export class HipChatEnterpriseImporter extends Base { if (!this._previewsMessagesIds) { this._previewsMessagesIds = new Set(); - await RocketChat.models.Messages.model.rawCollection().find({}, { fields: { _id: 1 } }).forEach((i) => this._previewsMessagesIds.add(i._id)); + await Messages.model.rawCollection().find({}, { fields: { _id: 1 } }).forEach((i) => this._previewsMessagesIds.add(i._id)); } } @@ -455,7 +456,7 @@ export class HipChatEnterpriseImporter extends Base { this.collection.remove({}); this.emailList = []; - this._hasAnyImportedMessage = Boolean(RocketChat.models.Messages.findOne({ _id: /hipchatenterprise\-.*/ })); + this._hasAnyImportedMessage = Boolean(Messages.findOne({ _id: /hipchatenterprise\-.*/ })); this.usersCount = 0; this.channelsCount = 0; @@ -492,7 +493,7 @@ export class HipChatEnterpriseImporter extends Base { // Check if any of the emails used are already taken if (this.emailList.length > 0) { - const conflictingUsers = RocketChat.models.Users.find({ 'emails.address': { $in: this.emailList } }); + const conflictingUsers = Users.find({ 'emails.address': { $in: this.emailList } }); const conflictingUserEmails = []; conflictingUsers.forEach((conflictingUser) => { @@ -586,7 +587,7 @@ export class HipChatEnterpriseImporter extends Base { this.collection.remove({}); this.emailList = []; - this._hasAnyImportedMessage = Boolean(RocketChat.models.Messages.findOne({ _id: /hipchatenterprise\-.*/ })); + this._hasAnyImportedMessage = Boolean(Messages.findOne({ _id: /hipchatenterprise\-.*/ })); this.usersCount = 0; this.channelsCount = 0; @@ -689,7 +690,7 @@ export class HipChatEnterpriseImporter extends Base { this._saveUserIdReference(userToImport.id, existingUserId); Meteor.runAsUser(existingUserId, () => { - RocketChat.models.Users.update({ _id: existingUserId }, { + Users.update({ _id: existingUserId }, { $push: { importIds: userToImport.id, }, @@ -709,10 +710,10 @@ export class HipChatEnterpriseImporter extends Base { _importUser(userToImport, startedByUserId) { Meteor.runAsUser(startedByUserId, () => { - let existingUser = RocketChat.models.Users.findOneByUsername(userToImport.username); + let existingUser = Users.findOneByUsername(userToImport.username); if (!existingUser) { // If there's no user with that username, but there's an imported user with the same original ID and no username, use that - existingUser = RocketChat.models.Users.findOne({ + existingUser = Users.findOne({ importIds: userToImport.id, username: { $exists: false }, }); @@ -940,7 +941,7 @@ export class HipChatEnterpriseImporter extends Base { let room; if (roomOrRoomId && typeof roomOrRoomId === 'string') { - room = RocketChat.models.Rooms.findOneByIdOrName(roomOrRoomId); + room = Rooms.findOneByIdOrName(roomOrRoomId); } else { room = roomOrRoomId; } @@ -958,21 +959,21 @@ export class HipChatEnterpriseImporter extends Base { return; } - if (RocketChat.models.Subscriptions.find({ rid: room._id, 'u._id': user._id }, { limit: 1 }).count() === 0) { + if (Subscriptions.find({ rid: room._id, 'u._id': user._id }, { limit: 1 }).count() === 0) { this.logger.info(`Creating user's subscription to room ${ room._id }, rocket.chat user is ${ user._id }, hipchat user is ${ hipchatUserId }`); - RocketChat.models.Subscriptions.createWithRoomAndUser(room, user, extra); + Subscriptions.createWithRoomAndUser(room, user, extra); } }); } _importChannel(channelToImport, startedByUserId) { Meteor.runAsUser(startedByUserId, () => { - const existingRoom = RocketChat.models.Rooms.findOneByName(s.slugify(channelToImport.name)); + const existingRoom = Rooms.findOneByName(s.slugify(channelToImport.name)); // If the room exists or the name of it is 'general', then we don't need to create it again if (existingRoom || channelToImport.name.toUpperCase() === 'GENERAL') { channelToImport.rocketId = channelToImport.name.toUpperCase() === 'GENERAL' ? 'GENERAL' : existingRoom._id; this._saveRoomIdReference(channelToImport.id, channelToImport.rocketId); - RocketChat.models.Rooms.update({ _id: channelToImport.rocketId }, { $push: { importIds: channelToImport.id } }); + Rooms.update({ _id: channelToImport.rocketId }, { $push: { importIds: channelToImport.id } }); this._createSubscriptions(channelToImport, existingRoom || 'general'); } else { @@ -991,7 +992,7 @@ export class HipChatEnterpriseImporter extends Base { }); if (channelToImport.rocketId) { - RocketChat.models.Rooms.update({ _id: channelToImport.rocketId }, { $set: { ts: channelToImport.created, topic: channelToImport.topic }, $push: { importIds: channelToImport.id } }); + Rooms.update({ _id: channelToImport.rocketId }, { $set: { ts: channelToImport.created, topic: channelToImport.topic }, $push: { importIds: channelToImport.id } }); this._createSubscriptions(channelToImport, channelToImport.rocketId); } } @@ -1052,7 +1053,7 @@ export class HipChatEnterpriseImporter extends Base { switch (msg.type) { case 'user': if (!msg.skip) { - RocketChat.insertMessage(creator, { + insertMessage(creator, { _id: msg.id, ts: msg.ts, msg: msg.text, @@ -1066,7 +1067,7 @@ export class HipChatEnterpriseImporter extends Base { } break; case 'topic': - RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser('room_changed_topic', room._id, msg.text, creator, { _id: msg.id, ts: msg.ts }); + Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser('room_changed_topic', room._id, msg.text, creator, { _id: msg.id, ts: msg.ts }); break; } }); @@ -1099,7 +1100,7 @@ export class HipChatEnterpriseImporter extends Base { return; } - const room = await RocketChat.models.Rooms.findOneById(rid, { fields: { usernames: 1, t: 1, name: 1 } }); + const room = await Rooms.findOneById(rid, { fields: { usernames: 1, t: 1, name: 1 } }); await super.updateRecord({ messagesstatus: `${ roomIdentifier }.${ list.messages.length }`, 'count.completed': this.progress.count.completed, @@ -1213,7 +1214,7 @@ export class HipChatEnterpriseImporter extends Base { const roomId = [receiver._id, sender._id].sort().join(''); if (!(roomId in roomObjects)) { - roomObjects[roomId] = RocketChat.models.Rooms.findOneById(roomId); + roomObjects[roomId] = Rooms.findOneById(roomId); } let room = roomObjects[roomId]; @@ -1222,7 +1223,7 @@ export class HipChatEnterpriseImporter extends Base { Meteor.runAsUser(sender._id, () => { const roomInfo = Meteor.call('createDirectMessage', receiver.username); - room = RocketChat.models.Rooms.findOneById(roomInfo.rid); + room = Rooms.findOneById(roomInfo.rid); roomObjects[roomId] = room; }); } @@ -1250,7 +1251,7 @@ export class HipChatEnterpriseImporter extends Base { if (!msg.skip) { this.logger.debug('Inserting DM message'); - RocketChat.insertMessage(sender, { + insertMessage(sender, { _id: msg.id, ts: msg.ts, msg: msg.text, @@ -1304,7 +1305,7 @@ export class HipChatEnterpriseImporter extends Base { return this._userDataCache[userId]; } - this._userDataCache[userId] = RocketChat.models.Users.findOneById(userId, { fields: { username: 1 } }); + this._userDataCache[userId] = Users.findOneById(userId, { fields: { username: 1 } }); return this._userDataCache[userId]; } diff --git a/packages/rocketchat-integrations/client/startup.js b/packages/rocketchat-integrations/client/startup.js index 907670156d3..795242bb080 100644 --- a/packages/rocketchat-integrations/client/startup.js +++ b/packages/rocketchat-integrations/client/startup.js @@ -1,8 +1,9 @@ -import { RocketChat } from 'meteor/rocketchat:lib'; +import { AdminBox } from 'meteor/rocketchat:ui-utils'; +import { hasAtLeastOnePermission } from 'meteor/rocketchat:authorization'; -RocketChat.AdminBox.addOption({ +AdminBox.addOption({ href: 'admin-integrations', i18nLabel: 'Integrations', icon: 'code', - permissionGranted: () => RocketChat.authz.hasAtLeastOnePermission(['manage-integrations', 'manage-own-integrations']), + permissionGranted: () => hasAtLeastOnePermission(['manage-integrations', 'manage-own-integrations']), }); diff --git a/packages/rocketchat-integrations/client/views/integrations.js b/packages/rocketchat-integrations/client/views/integrations.js index d491ea42863..c6e3fd85e33 100644 --- a/packages/rocketchat-integrations/client/views/integrations.js +++ b/packages/rocketchat-integrations/client/views/integrations.js @@ -1,12 +1,13 @@ import { Template } from 'meteor/templating'; import { TAPi18n } from 'meteor/tap:i18n'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasAtLeastOnePermission } from 'meteor/rocketchat:authorization'; +import { integrations } from '../../lib/rocketchat'; import { ChatIntegrations } from '../collections'; import moment from 'moment'; Template.integrations.helpers({ hasPermission() { - return RocketChat.authz.hasAtLeastOnePermission(['manage-integrations', 'manage-own-integrations']); + return hasAtLeastOnePermission(['manage-integrations', 'manage-own-integrations']); }, integrations() { return ChatIntegrations.find(); @@ -15,6 +16,6 @@ Template.integrations.helpers({ return moment(date).format('L LT'); }, eventTypeI18n(event) { - return TAPi18n.__(RocketChat.integrations.outgoingEvents[event].label); + return TAPi18n.__(integrations.outgoingEvents[event].label); }, }); diff --git a/packages/rocketchat-integrations/client/views/integrationsIncoming.js b/packages/rocketchat-integrations/client/views/integrationsIncoming.js index 4311aa8ba70..3abc2694375 100644 --- a/packages/rocketchat-integrations/client/views/integrationsIncoming.js +++ b/packages/rocketchat-integrations/client/views/integrationsIncoming.js @@ -4,9 +4,9 @@ import { Random } from 'meteor/random'; import { FlowRouter } from 'meteor/kadira:flow-router'; import { Template } from 'meteor/templating'; import { TAPi18n } from 'meteor/tap:i18n'; -import { RocketChat, handleError } from 'meteor/rocketchat:lib'; -import { modal } from 'meteor/rocketchat:ui'; -import { t } from 'meteor/rocketchat:utils'; +import { hasAtLeastOnePermission, hasAllPermission } from 'meteor/rocketchat:authorization'; +import { modal } from 'meteor/rocketchat:ui-utils'; +import { t, handleError } from 'meteor/rocketchat:utils'; import { ChatIntegrations } from '../collections'; import hljs from 'highlight.js'; import toastr from 'toastr'; @@ -19,7 +19,7 @@ Template.integrationsIncoming.onCreated(function _incomingIntegrationsOnCreated( Template.integrationsIncoming.helpers({ hasPermission() { - return RocketChat.authz.hasAtLeastOnePermission(['manage-integrations', 'manage-own-integrations']); + return hasAtLeastOnePermission(['manage-integrations', 'manage-own-integrations']); }, data() { @@ -27,9 +27,9 @@ Template.integrationsIncoming.helpers({ if (params && params.id) { let data; - if (RocketChat.authz.hasAllPermission('manage-integrations')) { + if (hasAllPermission('manage-integrations')) { data = ChatIntegrations.findOne({ _id: params.id }); - } else if (RocketChat.authz.hasAllPermission('manage-own-integrations')) { + } else if (hasAllPermission('manage-own-integrations')) { data = ChatIntegrations.findOne({ _id: params.id, '_createdBy._id': Meteor.userId() }); } diff --git a/packages/rocketchat-integrations/client/views/integrationsNew.js b/packages/rocketchat-integrations/client/views/integrationsNew.js index dc7994ff7eb..c869d3d24bf 100644 --- a/packages/rocketchat-integrations/client/views/integrationsNew.js +++ b/packages/rocketchat-integrations/client/views/integrationsNew.js @@ -1,8 +1,8 @@ import { Template } from 'meteor/templating'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasAtLeastOnePermission } from 'meteor/rocketchat:authorization'; Template.integrationsNew.helpers({ hasPermission() { - return RocketChat.authz.hasAtLeastOnePermission(['manage-integrations', 'manage-own-integrations']); + return hasAtLeastOnePermission(['manage-integrations', 'manage-own-integrations']); }, }); diff --git a/packages/rocketchat-integrations/client/views/integrationsOutgoing.js b/packages/rocketchat-integrations/client/views/integrationsOutgoing.js index 3d83d762bc6..574b3944f4c 100644 --- a/packages/rocketchat-integrations/client/views/integrationsOutgoing.js +++ b/packages/rocketchat-integrations/client/views/integrationsOutgoing.js @@ -4,10 +4,11 @@ import { Random } from 'meteor/random'; import { FlowRouter } from 'meteor/kadira:flow-router'; import { Template } from 'meteor/templating'; import { TAPi18n } from 'meteor/tap:i18n'; -import { RocketChat, handleError } from 'meteor/rocketchat:lib'; -import { modal } from 'meteor/rocketchat:ui'; -import { t } from 'meteor/rocketchat:utils'; +import { hasAllPermission, hasAtLeastOnePermission } from 'meteor/rocketchat:authorization'; +import { modal } from 'meteor/rocketchat:ui-utils'; +import { t, handleError } from 'meteor/rocketchat:utils'; import { ChatIntegrations } from '../collections'; +import { integrations } from '../../lib/rocketchat'; import hljs from 'highlight.js'; import toastr from 'toastr'; @@ -53,9 +54,9 @@ Template.integrationsOutgoing.onCreated(function _integrationsOutgoingOnCreated( if (sub.ready()) { let intRecord; - if (RocketChat.authz.hasAllPermission('manage-integrations')) { + if (hasAllPermission('manage-integrations')) { intRecord = ChatIntegrations.findOne({ _id: id }); - } else if (RocketChat.authz.hasAllPermission('manage-own-integrations')) { + } else if (hasAllPermission('manage-own-integrations')) { intRecord = ChatIntegrations.findOne({ _id: id, '_createdBy._id': Meteor.userId() }); } @@ -84,7 +85,7 @@ Template.integrationsOutgoing.helpers({ }, hasPermission() { - return RocketChat.authz.hasAtLeastOnePermission(['manage-integrations', 'manage-own-integrations']); + return hasAtLeastOnePermission(['manage-integrations', 'manage-own-integrations']); }, data() { @@ -96,7 +97,7 @@ Template.integrationsOutgoing.helpers({ }, eventTypes() { - return Object.values(RocketChat.integrations.outgoingEvents); + return Object.values(integrations.outgoingEvents); }, hasTypeSelected() { @@ -108,19 +109,19 @@ Template.integrationsOutgoing.helpers({ shouldDisplayChannel() { const record = Template.instance().record.get(); - return typeof record.event === 'string' && RocketChat.integrations.outgoingEvents[record.event].use.channel; + return typeof record.event === 'string' && integrations.outgoingEvents[record.event].use.channel; }, shouldDisplayTriggerWords() { const record = Template.instance().record.get(); - return typeof record.event === 'string' && RocketChat.integrations.outgoingEvents[record.event].use.triggerWords; + return typeof record.event === 'string' && integrations.outgoingEvents[record.event].use.triggerWords; }, shouldDisplayTargetRoom() { const record = Template.instance().record.get(); - return typeof record.event === 'string' && RocketChat.integrations.outgoingEvents[record.event].use.targetRoom; + return typeof record.event === 'string' && integrations.outgoingEvents[record.event].use.targetRoom; }, example() { @@ -298,7 +299,7 @@ Template.integrationsOutgoing.events({ let triggerWords; let triggerWordAnywhere; let runOnEdits; - if (RocketChat.integrations.outgoingEvents[event].use.triggerWords) { + if (integrations.outgoingEvents[event].use.triggerWords) { triggerWords = $('[name=triggerWords]').val().trim(); triggerWords = triggerWords.split(',').filter((word) => word.trim() !== ''); @@ -307,7 +308,7 @@ Template.integrationsOutgoing.events({ } let channel; - if (RocketChat.integrations.outgoingEvents[event].use.channel) { + if (integrations.outgoingEvents[event].use.channel) { channel = $('[name=channel]').val().trim(); if (!channel || channel.trim() === '') { @@ -316,7 +317,7 @@ Template.integrationsOutgoing.events({ } let targetRoom; - if (RocketChat.integrations.outgoingEvents[event].use.targetRoom) { + if (integrations.outgoingEvents[event].use.targetRoom) { targetRoom = $('[name=targetRoom]').val().trim(); if (!targetRoom || targetRoom.trim() === '') { diff --git a/packages/rocketchat-integrations/client/views/integrationsOutgoingHistory.js b/packages/rocketchat-integrations/client/views/integrationsOutgoingHistory.js index e7e67d78f9a..7ad6507cc3b 100644 --- a/packages/rocketchat-integrations/client/views/integrationsOutgoingHistory.js +++ b/packages/rocketchat-integrations/client/views/integrationsOutgoingHistory.js @@ -3,8 +3,10 @@ import { ReactiveVar } from 'meteor/reactive-var'; import { FlowRouter } from 'meteor/kadira:flow-router'; import { Template } from 'meteor/templating'; import { TAPi18n } from 'meteor/tap:i18n'; -import { RocketChat, handleError } from 'meteor/rocketchat:lib'; +import { handleError } from 'meteor/rocketchat:utils'; +import { hasAllPermission, hasAtLeastOnePermission } from 'meteor/rocketchat:authorization'; import { ChatIntegrations, ChatIntegrationHistory } from '../collections'; +import { integrations } from '../../lib/rocketchat'; import _ from 'underscore'; import hljs from 'highlight.js'; import moment from 'moment'; @@ -21,9 +23,9 @@ Template.integrationsOutgoingHistory.onCreated(function _integrationsOutgoingHis if (sub.ready()) { let intRecord; - if (RocketChat.authz.hasAllPermission('manage-integrations')) { + if (hasAllPermission('manage-integrations')) { intRecord = ChatIntegrations.findOne({ _id: id }); - } else if (RocketChat.authz.hasAllPermission('manage-own-integrations')) { + } else if (hasAllPermission('manage-own-integrations')) { intRecord = ChatIntegrations.findOne({ _id: id, '_createdBy._id': Meteor.userId() }); } @@ -48,7 +50,7 @@ Template.integrationsOutgoingHistory.onCreated(function _integrationsOutgoingHis Template.integrationsOutgoingHistory.helpers({ hasPermission() { - return RocketChat.authz.hasAtLeastOnePermission(['manage-integrations', 'manage-own-integrations']); + return hasAtLeastOnePermission(['manage-integrations', 'manage-own-integrations']); }, hasMore() { @@ -96,7 +98,7 @@ Template.integrationsOutgoingHistory.helpers({ }, eventTypei18n(event) { - return TAPi18n.__(RocketChat.integrations.outgoingEvents[event].label); + return TAPi18n.__(integrations.outgoingEvents[event].label); }, jsonStringify(data) { diff --git a/packages/rocketchat-integrations/lib/rocketchat.js b/packages/rocketchat-integrations/lib/rocketchat.js index 89c107c1240..076a008d4c6 100644 --- a/packages/rocketchat-integrations/lib/rocketchat.js +++ b/packages/rocketchat-integrations/lib/rocketchat.js @@ -1,6 +1,4 @@ -import { RocketChat } from 'meteor/rocketchat:lib'; - -RocketChat.integrations = { +export const integrations = { outgoingEvents: { sendMessage: { label: 'Integrations_Outgoing_Type_SendMessage', diff --git a/packages/rocketchat-integrations/package.js b/packages/rocketchat-integrations/package.js index 577a0ee92f3..183e470450f 100644 --- a/packages/rocketchat-integrations/package.js +++ b/packages/rocketchat-integrations/package.js @@ -16,7 +16,12 @@ Package.onUse(function(api) { 'rocketchat:authorization', 'rocketchat:theme', 'rocketchat:logger', + 'rocketchat:callbacks', + 'rocketchat:settings', 'rocketchat:utils', + 'rocketchat:models', + 'rocketchat:livechat', + 'rocketchat:ui-utils', 'kadira:flow-router', 'kadira:blaze-layout', 'nimble:restivus', diff --git a/packages/rocketchat-integrations/server/api/api.js b/packages/rocketchat-integrations/server/api/api.js index 5b8b6b4a05c..b330db9aeb5 100644 --- a/packages/rocketchat-integrations/server/api/api.js +++ b/packages/rocketchat-integrations/server/api/api.js @@ -1,11 +1,12 @@ import { Meteor } from 'meteor/meteor'; import { HTTP } from 'meteor/http'; import { Random } from 'meteor/random'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import * as Models from 'meteor/rocketchat:models'; import { Restivus } from 'meteor/nimble:restivus'; import { API } from 'meteor/rocketchat:api'; +import { Livechat } from 'meteor/rocketchat:livechat'; +import { processWebhookMessage } from 'meteor/rocketchat:lib'; import { logger } from '../logger'; -import { processWebhookMessage } from '../processWebhookMessage'; import Fiber from 'fibers'; import Future from 'fibers/future'; import _ from 'underscore'; @@ -36,7 +37,7 @@ const Api = new Restivus({ } } - this.integration = RocketChat.models.Integrations.findOne({ + this.integration = Models.Integrations.findOne({ _id: this.request.params.integrationId, token: decodeURIComponent(this.request.params.token), }); @@ -55,7 +56,7 @@ const Api = new Restivus({ }; } - const user = RocketChat.models.Users.findOne({ + const user = Models.Users.findOne({ _id: this.integration.userId, }); @@ -76,7 +77,7 @@ function buildSandbox(store = {}) { moment, Fiber, Promise, - Livechat: RocketChat.Livechat, + Livechat, Store: { set(key, val) { return store[key] = val; @@ -98,7 +99,7 @@ function buildSandbox(store = {}) { }, }; - Object.keys(RocketChat.models).filter((k) => !k.startsWith('_')).forEach((k) => sandbox[k] = RocketChat.models[k]); + Object.keys(Models).filter((k) => !k.startsWith('_')).forEach((k) => sandbox[k] = Models[k]); return { store, sandbox }; } @@ -180,7 +181,7 @@ function removeIntegration(options, user) { logger.incoming.info('Remove integration'); logger.incoming.debug(options); - const integrationToRemove = RocketChat.models.Integrations.findOne({ + const integrationToRemove = Models.Integrations.findOne({ urls: options.target_url, }); diff --git a/packages/rocketchat-integrations/server/index.js b/packages/rocketchat-integrations/server/index.js index dae9d993637..e89e043b591 100644 --- a/packages/rocketchat-integrations/server/index.js +++ b/packages/rocketchat-integrations/server/index.js @@ -14,8 +14,3 @@ import './methods/clearIntegrationHistory'; import './api/api'; import './lib/triggerHandler'; import './triggers'; -import { processWebhookMessage } from './processWebhookMessage'; - -export { - processWebhookMessage, -}; diff --git a/packages/rocketchat-integrations/server/lib/triggerHandler.js b/packages/rocketchat-integrations/server/lib/triggerHandler.js index c2a9e0b817f..967cbe31f1d 100644 --- a/packages/rocketchat-integrations/server/lib/triggerHandler.js +++ b/packages/rocketchat-integrations/server/lib/triggerHandler.js @@ -1,9 +1,11 @@ import { Meteor } from 'meteor/meteor'; import { Random } from 'meteor/random'; import { HTTP } from 'meteor/http'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import * as Models from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; +import { getRoomByNameOrIdWithOptionToJoin, processWebhookMessage } from 'meteor/rocketchat:lib'; import { logger } from '../logger'; -import { processWebhookMessage } from '../processWebhookMessage'; +import { integrations } from '../../lib/rocketchat'; import _ from 'underscore'; import s from 'underscore.string'; import moment from 'moment'; @@ -11,14 +13,14 @@ import vm from 'vm'; import Fiber from 'fibers'; import Future from 'fibers/future'; -RocketChat.integrations.triggerHandler = new class RocketChatIntegrationHandler { +integrations.triggerHandler = new class RocketChatIntegrationHandler { constructor() { this.vm = vm; this.successResults = [200, 201, 202]; this.compiledScripts = {}; this.triggers = {}; - RocketChat.models.Integrations.find({ type: 'webhook-outgoing' }).observe({ + Models.Integrations.find({ type: 'webhook-outgoing' }).observe({ added: (record) => { this.addIntegration(record); }, @@ -37,7 +39,7 @@ RocketChat.integrations.triggerHandler = new class RocketChatIntegrationHandler addIntegration(record) { logger.outgoing.debug(`Adding the integration ${ record.name } of the event ${ record.event }!`); let channels; - if (record.event && !RocketChat.integrations.outgoingEvents[record.event].use.channel) { + if (record.event && !integrations.outgoingEvents[record.event].use.channel) { logger.outgoing.debug('The integration doesnt rely on channels.'); // We don't use any channels, so it's special ;) channels = ['__any']; @@ -151,11 +153,11 @@ RocketChat.integrations.triggerHandler = new class RocketChatIntegrationHandler } if (historyId) { - RocketChat.models.IntegrationHistory.update({ _id: historyId }, { $set: history }); + Models.IntegrationHistory.update({ _id: historyId }, { $set: history }); return historyId; } else { history._createdAt = new Date(); - return RocketChat.models.IntegrationHistory.insert(Object.assign({ _id: Random.id() }, history)); + return Models.IntegrationHistory.insert(Object.assign({ _id: Random.id() }, history)); } } @@ -164,18 +166,18 @@ RocketChat.integrations.triggerHandler = new class RocketChatIntegrationHandler let user; // Try to find the user who we are impersonating if (trigger.impersonateUser) { - user = RocketChat.models.Users.findOneByUsername(data.user_name); + user = Models.Users.findOneByUsername(data.user_name); } // If they don't exist (aka the trigger didn't contain a user) then we set the user based upon the // configured username for the integration since this is required at all times. if (!user) { - user = RocketChat.models.Users.findOneByUsername(trigger.username); + user = Models.Users.findOneByUsername(trigger.username); } let tmpRoom; if (nameOrId || trigger.targetRoom || message.channel) { - tmpRoom = RocketChat.getRoomByNameOrIdWithOptionToJoin({ currentUserId: user._id, nameOrId: nameOrId || message.channel || trigger.targetRoom, errorOnEmpty: false }) || room; + tmpRoom = getRoomByNameOrIdWithOptionToJoin({ currentUserId: user._id, nameOrId: nameOrId || message.channel || trigger.targetRoom, errorOnEmpty: false }) || room; } else { tmpRoom = room; } @@ -232,8 +234,8 @@ RocketChat.integrations.triggerHandler = new class RocketChatIntegrationHandler }, }; - Object.keys(RocketChat.models).filter((k) => !k.startsWith('_')).forEach((k) => { - sandbox[k] = RocketChat.models[k]; + Object.keys(Models).filter((k) => !k.startsWith('_')).forEach((k) => { + sandbox[k] = Models[k]; }); return { store, sandbox }; @@ -600,7 +602,7 @@ RocketChat.integrations.triggerHandler = new class RocketChatIntegrationHandler let word; // Not all triggers/events support triggerWords - if (RocketChat.integrations.outgoingEvents[event].use.triggerWords) { + if (integrations.outgoingEvents[event].use.triggerWords) { if (trigger.triggerWords && trigger.triggerWords.length > 0) { for (const triggerWord of trigger.triggerWords) { if (!trigger.triggerWordAnywhere && message.msg.indexOf(triggerWord) === 0) { @@ -649,8 +651,8 @@ RocketChat.integrations.triggerHandler = new class RocketChatIntegrationHandler data, auth: undefined, npmRequestOptions: { - rejectUnauthorized: !RocketChat.settings.get('Allow_Invalid_SelfSigned_Certs'), - strictSSL: !RocketChat.settings.get('Allow_Invalid_SelfSigned_Certs'), + rejectUnauthorized: !settings.get('Allow_Invalid_SelfSigned_Certs'), + strictSSL: !settings.get('Allow_Invalid_SelfSigned_Certs'), }, headers: { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36', @@ -728,7 +730,7 @@ RocketChat.integrations.triggerHandler = new class RocketChatIntegrationHandler if (result.statusCode === 410) { this.updateHistory({ historyId, step: 'after-process-http-status-410', error: true }); logger.outgoing.error(`Disabling the Integration "${ trigger.name }" because the status code was 401 (Gone).`); - RocketChat.models.Integrations.update({ _id: trigger._id }, { $set: { enabled: false } }); + Models.Integrations.update({ _id: trigger._id }, { $set: { enabled: false } }); return; } @@ -799,13 +801,13 @@ RocketChat.integrations.triggerHandler = new class RocketChatIntegrationHandler } const { event } = history; - const message = RocketChat.models.Messages.findOneById(history.data.message_id); - const room = RocketChat.models.Rooms.findOneById(history.data.channel_id); - const user = RocketChat.models.Users.findOneById(history.data.user_id); + const message = Models.Messages.findOneById(history.data.message_id); + const room = Models.Rooms.findOneById(history.data.channel_id); + const user = Models.Users.findOneById(history.data.user_id); let owner; if (history.data.owner && history.data.owner._id) { - owner = RocketChat.models.Users.findOneById(history.data.owner._id); + owner = Models.Users.findOneById(history.data.owner._id); } this.executeTriggerUrl(history.url, integration, { event, message, room, owner, user }); diff --git a/packages/rocketchat-integrations/server/lib/validation.js b/packages/rocketchat-integrations/server/lib/validation.js index 6e101016e6a..f63405a7560 100644 --- a/packages/rocketchat-integrations/server/lib/validation.js +++ b/packages/rocketchat-integrations/server/lib/validation.js @@ -1,14 +1,16 @@ import { Meteor } from 'meteor/meteor'; import { Match } from 'meteor/check'; import { Babel } from 'meteor/babel-compiler'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { Rooms, Users, Subscriptions } from 'meteor/rocketchat:models'; +import { hasPermission, hasAllPermission } from 'meteor/rocketchat:authorization'; +import { integrations } from '../../lib/rocketchat'; import _ from 'underscore'; import s from 'underscore.string'; const scopedChannels = ['all_public_channels', 'all_private_groups', 'all_direct_messages']; const validChannelChars = ['@', '#']; function _verifyRequiredFields(integration) { - if (!integration.event || !Match.test(integration.event, String) || integration.event.trim() === '' || !RocketChat.integrations.outgoingEvents[integration.event]) { + if (!integration.event || !Match.test(integration.event, String) || integration.event.trim() === '' || !integrations.outgoingEvents[integration.event]) { throw new Meteor.Error('error-invalid-event-type', 'Invalid event type', { function: 'validateOutgoing._verifyRequiredFields' }); } @@ -16,7 +18,7 @@ function _verifyRequiredFields(integration) { throw new Meteor.Error('error-invalid-username', 'Invalid username', { function: 'validateOutgoing._verifyRequiredFields' }); } - if (RocketChat.integrations.outgoingEvents[integration.event].use.targetRoom && !integration.targetRoom) { + if (integrations.outgoingEvents[integration.event].use.targetRoom && !integration.targetRoom) { throw new Meteor.Error('error-invalid-targetRoom', 'Invalid Target Room', { function: 'validateOutgoing._verifyRequiredFields' }); } @@ -42,7 +44,7 @@ function _verifyUserHasPermissionForChannels(integration, userId, channels) { if (scopedChannels.includes(channel)) { if (channel === 'all_public_channels') { // No special permissions needed to add integration to public channels - } else if (!RocketChat.authz.hasPermission(userId, 'manage-integrations')) { + } else if (!hasPermission(userId, 'manage-integrations')) { throw new Meteor.Error('error-invalid-channel', 'Invalid Channel', { function: 'validateOutgoing._verifyUserHasPermissionForChannels' }); } } else { @@ -52,7 +54,7 @@ function _verifyUserHasPermissionForChannels(integration, userId, channels) { switch (channelType) { case '#': - record = RocketChat.models.Rooms.findOne({ + record = Rooms.findOne({ $or: [ { _id: channel }, { name: channel }, @@ -60,7 +62,7 @@ function _verifyUserHasPermissionForChannels(integration, userId, channels) { }); break; case '@': - record = RocketChat.models.Users.findOne({ + record = Users.findOne({ $or: [ { _id: channel }, { username: channel }, @@ -73,7 +75,7 @@ function _verifyUserHasPermissionForChannels(integration, userId, channels) { throw new Meteor.Error('error-invalid-room', 'Invalid room', { function: 'validateOutgoing._verifyUserHasPermissionForChannels' }); } - if (!RocketChat.authz.hasAllPermission(userId, ['manage-integrations', 'manage-own-integrations']) && !RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(record._id, userId, { fields: { _id: 1 } })) { + if (!hasAllPermission(userId, ['manage-integrations', 'manage-own-integrations']) && !Subscriptions.findOneByRoomIdAndUserId(record._id, userId, { fields: { _id: 1 } })) { throw new Meteor.Error('error-invalid-channel', 'Invalid Channel', { function: 'validateOutgoing._verifyUserHasPermissionForChannels' }); } } @@ -90,7 +92,7 @@ function _verifyRetryInformation(integration) { integration.retryDelay = !integration.retryDelay || !integration.retryDelay.trim() ? 'powers-of-ten' : integration.retryDelay.toLowerCase(); } -RocketChat.integrations.validateOutgoing = function _validateOutgoing(integration, userId) { +integrations.validateOutgoing = function _validateOutgoing(integration, userId) { if (integration.channel && Match.test(integration.channel, String) && integration.channel.trim() === '') { delete integration.channel; } @@ -99,7 +101,7 @@ RocketChat.integrations.validateOutgoing = function _validateOutgoing(integratio _verifyRequiredFields(integration); let channels = []; - if (RocketChat.integrations.outgoingEvents[integration.event].use.channel) { + if (integrations.outgoingEvents[integration.event].use.channel) { if (!Match.test(integration.channel, String)) { throw new Meteor.Error('error-invalid-channel', 'Invalid Channel', { function: 'validateOutgoing' }); } else { @@ -111,11 +113,11 @@ RocketChat.integrations.validateOutgoing = function _validateOutgoing(integratio } } } - } else if (!RocketChat.authz.hasPermission(userId, 'manage-integrations')) { + } else if (!hasPermission(userId, 'manage-integrations')) { throw new Meteor.Error('error-invalid-permissions', 'Invalid permission for required Integration creation.', { function: 'validateOutgoing' }); } - if (RocketChat.integrations.outgoingEvents[integration.event].use.triggerWords && integration.triggerWords) { + if (integrations.outgoingEvents[integration.event].use.triggerWords && integration.triggerWords) { if (!Match.test(integration.triggerWords, [String])) { throw new Meteor.Error('error-invalid-triggerWords', 'Invalid triggerWords', { function: 'validateOutgoing' }); } @@ -151,7 +153,7 @@ RocketChat.integrations.validateOutgoing = function _validateOutgoing(integratio _verifyUserHasPermissionForChannels(integration, userId, channels); _verifyRetryInformation(integration); - const user = RocketChat.models.Users.findOne({ username: integration.username }); + const user = Users.findOne({ username: integration.username }); if (!user) { throw new Meteor.Error('error-invalid-user', 'Invalid user (did you delete the `rocket.cat` user?)', { function: 'validateOutgoing' }); diff --git a/packages/rocketchat-integrations/server/methods/clearIntegrationHistory.js b/packages/rocketchat-integrations/server/methods/clearIntegrationHistory.js index 8ab439ef0a4..afb2a6fb49f 100644 --- a/packages/rocketchat-integrations/server/methods/clearIntegrationHistory.js +++ b/packages/rocketchat-integrations/server/methods/clearIntegrationHistory.js @@ -1,14 +1,15 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { IntegrationHistory, Integrations } from 'meteor/rocketchat:models'; Meteor.methods({ clearIntegrationHistory(integrationId) { let integration; - if (RocketChat.authz.hasPermission(this.userId, 'manage-integrations') || RocketChat.authz.hasPermission(this.userId, 'manage-integrations', 'bot')) { - integration = RocketChat.models.Integrations.findOne(integrationId); - } else if (RocketChat.authz.hasPermission(this.userId, 'manage-own-integrations') || RocketChat.authz.hasPermission(this.userId, 'manage-own-integrations', 'bot')) { - integration = RocketChat.models.Integrations.findOne(integrationId, { fields: { '_createdBy._id': this.userId } }); + if (hasPermission(this.userId, 'manage-integrations') || hasPermission(this.userId, 'manage-integrations', 'bot')) { + integration = Integrations.findOne(integrationId); + } else if (hasPermission(this.userId, 'manage-own-integrations') || hasPermission(this.userId, 'manage-own-integrations', 'bot')) { + integration = Integrations.findOne(integrationId, { fields: { '_createdBy._id': this.userId } }); } else { throw new Meteor.Error('not_authorized', 'Unauthorized', { method: 'clearIntegrationHistory' }); } @@ -17,7 +18,7 @@ Meteor.methods({ throw new Meteor.Error('error-invalid-integration', 'Invalid integration', { method: 'clearIntegrationHistory' }); } - RocketChat.models.IntegrationHistory.removeByIntegrationId(integrationId); + IntegrationHistory.removeByIntegrationId(integrationId); return true; }, diff --git a/packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.js b/packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.js index bf5111af47d..99448613ce6 100644 --- a/packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.js +++ b/packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.js @@ -1,14 +1,15 @@ import { Meteor } from 'meteor/meteor'; import { Random } from 'meteor/random'; import { Babel } from 'meteor/babel-compiler'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission, hasAllPermission } from 'meteor/rocketchat:authorization'; +import { Users, Rooms, Integrations, Roles, Subscriptions } from 'meteor/rocketchat:models'; import _ from 'underscore'; import s from 'underscore.string'; const validChannelChars = ['@', '#']; Meteor.methods({ addIncomingIntegration(integration) { - if (!RocketChat.authz.hasPermission(this.userId, 'manage-integrations') && !RocketChat.authz.hasPermission(this.userId, 'manage-own-integrations')) { + if (!hasPermission(this.userId, 'manage-integrations') && !hasPermission(this.userId, 'manage-own-integrations')) { throw new Meteor.Error('not_authorized', 'Unauthorized', { method: 'addIncomingIntegration' }); } @@ -52,7 +53,7 @@ Meteor.methods({ switch (channelType) { case '#': - record = RocketChat.models.Rooms.findOne({ + record = Rooms.findOne({ $or: [ { _id: channel }, { name: channel }, @@ -60,7 +61,7 @@ Meteor.methods({ }); break; case '@': - record = RocketChat.models.Users.findOne({ + record = Users.findOne({ $or: [ { _id: channel }, { username: channel }, @@ -73,12 +74,12 @@ Meteor.methods({ throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'addIncomingIntegration' }); } - if (!RocketChat.authz.hasAllPermission(this.userId, ['manage-integrations', 'manage-own-integrations']) && !RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(record._id, this.userId, { fields: { _id: 1 } })) { + if (!hasAllPermission(this.userId, ['manage-integrations', 'manage-own-integrations']) && !Subscriptions.findOneByRoomIdAndUserId(record._id, this.userId, { fields: { _id: 1 } })) { throw new Meteor.Error('error-invalid-channel', 'Invalid Channel', { method: 'addIncomingIntegration' }); } } - const user = RocketChat.models.Users.findOne({ username: integration.username }); + const user = Users.findOne({ username: integration.username }); if (!user) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'addIncomingIntegration' }); @@ -91,11 +92,11 @@ Meteor.methods({ integration.channel = channels; integration.userId = user._id; integration._createdAt = new Date(); - integration._createdBy = RocketChat.models.Users.findOne(this.userId, { fields: { username: 1 } }); + integration._createdBy = Users.findOne(this.userId, { fields: { username: 1 } }); - RocketChat.models.Roles.addUserRoles(user._id, 'bot'); + Roles.addUserRoles(user._id, 'bot'); - integration._id = RocketChat.models.Integrations.insert(integration); + integration._id = Integrations.insert(integration); return integration; }, diff --git a/packages/rocketchat-integrations/server/methods/incoming/deleteIncomingIntegration.js b/packages/rocketchat-integrations/server/methods/incoming/deleteIncomingIntegration.js index 0bad9802aec..2aa6a85042a 100644 --- a/packages/rocketchat-integrations/server/methods/incoming/deleteIncomingIntegration.js +++ b/packages/rocketchat-integrations/server/methods/incoming/deleteIncomingIntegration.js @@ -1,14 +1,15 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Integrations } from 'meteor/rocketchat:models'; Meteor.methods({ deleteIncomingIntegration(integrationId) { let integration; - if (RocketChat.authz.hasPermission(this.userId, 'manage-integrations')) { - integration = RocketChat.models.Integrations.findOne(integrationId); - } else if (RocketChat.authz.hasPermission(this.userId, 'manage-own-integrations')) { - integration = RocketChat.models.Integrations.findOne(integrationId, { fields : { '_createdBy._id': this.userId } }); + if (hasPermission(this.userId, 'manage-integrations')) { + integration = Integrations.findOne(integrationId); + } else if (hasPermission(this.userId, 'manage-own-integrations')) { + integration = Integrations.findOne(integrationId, { fields : { '_createdBy._id': this.userId } }); } else { throw new Meteor.Error('not_authorized', 'Unauthorized', { method: 'deleteIncomingIntegration' }); } @@ -17,7 +18,7 @@ Meteor.methods({ throw new Meteor.Error('error-invalid-integration', 'Invalid integration', { method: 'deleteIncomingIntegration' }); } - RocketChat.models.Integrations.remove({ _id: integrationId }); + Integrations.remove({ _id: integrationId }); return true; }, diff --git a/packages/rocketchat-integrations/server/methods/incoming/updateIncomingIntegration.js b/packages/rocketchat-integrations/server/methods/incoming/updateIncomingIntegration.js index 733b32b5116..88091735547 100644 --- a/packages/rocketchat-integrations/server/methods/incoming/updateIncomingIntegration.js +++ b/packages/rocketchat-integrations/server/methods/incoming/updateIncomingIntegration.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasAllPermission, hasPermission } from 'meteor/rocketchat:authorization'; +import { Integrations, Rooms, Users, Roles, Subscriptions } from 'meteor/rocketchat:models'; import { Babel } from 'meteor/babel-compiler'; import _ from 'underscore'; import s from 'underscore.string'; @@ -21,10 +22,10 @@ Meteor.methods({ let currentIntegration; - if (RocketChat.authz.hasPermission(this.userId, 'manage-integrations')) { - currentIntegration = RocketChat.models.Integrations.findOne(integrationId); - } else if (RocketChat.authz.hasPermission(this.userId, 'manage-own-integrations')) { - currentIntegration = RocketChat.models.Integrations.findOne({ _id: integrationId, '_createdBy._id': this.userId }); + if (hasPermission(this.userId, 'manage-integrations')) { + currentIntegration = Integrations.findOne(integrationId); + } else if (hasPermission(this.userId, 'manage-own-integrations')) { + currentIntegration = Integrations.findOne({ _id: integrationId, '_createdBy._id': this.userId }); } else { throw new Meteor.Error('not_authorized', 'Unauthorized', { method: 'updateIncomingIntegration' }); } @@ -53,7 +54,7 @@ Meteor.methods({ switch (channelType) { case '#': - record = RocketChat.models.Rooms.findOne({ + record = Rooms.findOne({ $or: [ { _id: channel }, { name: channel }, @@ -61,7 +62,7 @@ Meteor.methods({ }); break; case '@': - record = RocketChat.models.Users.findOne({ + record = Users.findOne({ $or: [ { _id: channel }, { username: channel }, @@ -74,20 +75,20 @@ Meteor.methods({ throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'updateIncomingIntegration' }); } - if (!RocketChat.authz.hasAllPermission(this.userId, ['manage-integrations', 'manage-own-integrations']) && !RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(record._id, this.userId, { fields: { _id: 1 } })) { + if (!hasAllPermission(this.userId, ['manage-integrations', 'manage-own-integrations']) && !Subscriptions.findOneByRoomIdAndUserId(record._id, this.userId, { fields: { _id: 1 } })) { throw new Meteor.Error('error-invalid-channel', 'Invalid Channel', { method: 'updateIncomingIntegration' }); } } - const user = RocketChat.models.Users.findOne({ username: currentIntegration.username }); + const user = Users.findOne({ username: currentIntegration.username }); if (!user || !user._id) { throw new Meteor.Error('error-invalid-post-as-user', 'Invalid Post As User', { method: 'updateIncomingIntegration' }); } - RocketChat.models.Roles.addUserRoles(user._id, 'bot'); + Roles.addUserRoles(user._id, 'bot'); - RocketChat.models.Integrations.update(integrationId, { + Integrations.update(integrationId, { $set: { enabled: integration.enabled, name: integration.name, @@ -100,10 +101,10 @@ Meteor.methods({ scriptCompiled: integration.scriptCompiled, scriptError: integration.scriptError, _updatedAt: new Date(), - _updatedBy: RocketChat.models.Users.findOne(this.userId, { fields: { username: 1 } }), + _updatedBy: Users.findOne(this.userId, { fields: { username: 1 } }), }, }); - return RocketChat.models.Integrations.findOne(integrationId); + return Integrations.findOne(integrationId); }, }); diff --git a/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.js b/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.js index 9fb37102145..1cccbc93c35 100644 --- a/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.js +++ b/packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.js @@ -1,20 +1,22 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Users, Integrations } from 'meteor/rocketchat:models'; +import { integrations } from '../../../lib/rocketchat'; Meteor.methods({ addOutgoingIntegration(integration) { - if (!RocketChat.authz.hasPermission(this.userId, 'manage-integrations') - && !RocketChat.authz.hasPermission(this.userId, 'manage-own-integrations') - && !RocketChat.authz.hasPermission(this.userId, 'manage-integrations', 'bot') - && !RocketChat.authz.hasPermission(this.userId, 'manage-own-integrations', 'bot')) { + if (!hasPermission(this.userId, 'manage-integrations') + && !hasPermission(this.userId, 'manage-own-integrations') + && !hasPermission(this.userId, 'manage-integrations', 'bot') + && !hasPermission(this.userId, 'manage-own-integrations', 'bot')) { throw new Meteor.Error('not_authorized'); } - integration = RocketChat.integrations.validateOutgoing(integration, this.userId); + integration = integrations.validateOutgoing(integration, this.userId); integration._createdAt = new Date(); - integration._createdBy = RocketChat.models.Users.findOne(this.userId, { fields: { username: 1 } }); - integration._id = RocketChat.models.Integrations.insert(integration); + integration._createdBy = Users.findOne(this.userId, { fields: { username: 1 } }); + integration._id = Integrations.insert(integration); return integration; }, diff --git a/packages/rocketchat-integrations/server/methods/outgoing/deleteOutgoingIntegration.js b/packages/rocketchat-integrations/server/methods/outgoing/deleteOutgoingIntegration.js index 074d7aced2a..98bb0e7720d 100644 --- a/packages/rocketchat-integrations/server/methods/outgoing/deleteOutgoingIntegration.js +++ b/packages/rocketchat-integrations/server/methods/outgoing/deleteOutgoingIntegration.js @@ -1,14 +1,15 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { IntegrationHistory, Integrations } from 'meteor/rocketchat:models'; Meteor.methods({ deleteOutgoingIntegration(integrationId) { let integration; - if (RocketChat.authz.hasPermission(this.userId, 'manage-integrations') || RocketChat.authz.hasPermission(this.userId, 'manage-integrations', 'bot')) { - integration = RocketChat.models.Integrations.findOne(integrationId); - } else if (RocketChat.authz.hasPermission(this.userId, 'manage-own-integrations') || RocketChat.authz.hasPermission(this.userId, 'manage-own-integrations', 'bot')) { - integration = RocketChat.models.Integrations.findOne(integrationId, { fields: { '_createdBy._id': this.userId } }); + if (hasPermission(this.userId, 'manage-integrations') || hasPermission(this.userId, 'manage-integrations', 'bot')) { + integration = Integrations.findOne(integrationId); + } else if (hasPermission(this.userId, 'manage-own-integrations') || hasPermission(this.userId, 'manage-own-integrations', 'bot')) { + integration = Integrations.findOne(integrationId, { fields: { '_createdBy._id': this.userId } }); } else { throw new Meteor.Error('not_authorized', 'Unauthorized', { method: 'deleteOutgoingIntegration' }); } @@ -17,8 +18,8 @@ Meteor.methods({ throw new Meteor.Error('error-invalid-integration', 'Invalid integration', { method: 'deleteOutgoingIntegration' }); } - RocketChat.models.Integrations.remove({ _id: integrationId }); - RocketChat.models.IntegrationHistory.removeByIntegrationId(integrationId); + Integrations.remove({ _id: integrationId }); + IntegrationHistory.removeByIntegrationId(integrationId); return true; }, diff --git a/packages/rocketchat-integrations/server/methods/outgoing/replayOutgoingIntegration.js b/packages/rocketchat-integrations/server/methods/outgoing/replayOutgoingIntegration.js index d426603c5b5..59a9b57bb5e 100644 --- a/packages/rocketchat-integrations/server/methods/outgoing/replayOutgoingIntegration.js +++ b/packages/rocketchat-integrations/server/methods/outgoing/replayOutgoingIntegration.js @@ -1,14 +1,16 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Integrations, IntegrationHistory } from 'meteor/rocketchat:models'; +import { integrations } from '../../../lib/rocketchat'; Meteor.methods({ replayOutgoingIntegration({ integrationId, historyId }) { let integration; - if (RocketChat.authz.hasPermission(this.userId, 'manage-integrations') || RocketChat.authz.hasPermission(this.userId, 'manage-integrations', 'bot')) { - integration = RocketChat.models.Integrations.findOne(integrationId); - } else if (RocketChat.authz.hasPermission(this.userId, 'manage-own-integrations') || RocketChat.authz.hasPermission(this.userId, 'manage-own-integrations', 'bot')) { - integration = RocketChat.models.Integrations.findOne(integrationId, { fields: { '_createdBy._id': this.userId } }); + if (hasPermission(this.userId, 'manage-integrations') || hasPermission(this.userId, 'manage-integrations', 'bot')) { + integration = Integrations.findOne(integrationId); + } else if (hasPermission(this.userId, 'manage-own-integrations') || hasPermission(this.userId, 'manage-own-integrations', 'bot')) { + integration = Integrations.findOne(integrationId, { fields: { '_createdBy._id': this.userId } }); } else { throw new Meteor.Error('not_authorized', 'Unauthorized', { method: 'replayOutgoingIntegration' }); } @@ -17,13 +19,13 @@ Meteor.methods({ throw new Meteor.Error('error-invalid-integration', 'Invalid integration', { method: 'replayOutgoingIntegration' }); } - const history = RocketChat.models.IntegrationHistory.findOneByIntegrationIdAndHistoryId(integration._id, historyId); + const history = IntegrationHistory.findOneByIntegrationIdAndHistoryId(integration._id, historyId); if (!history) { throw new Meteor.Error('error-invalid-integration-history', 'Invalid Integration History', { method: 'replayOutgoingIntegration' }); } - RocketChat.integrations.triggerHandler.replay(integration, history); + integrations.triggerHandler.replay(integration, history); return true; }, diff --git a/packages/rocketchat-integrations/server/methods/outgoing/updateOutgoingIntegration.js b/packages/rocketchat-integrations/server/methods/outgoing/updateOutgoingIntegration.js index e773e22d8a4..913de44210b 100644 --- a/packages/rocketchat-integrations/server/methods/outgoing/updateOutgoingIntegration.js +++ b/packages/rocketchat-integrations/server/methods/outgoing/updateOutgoingIntegration.js @@ -1,9 +1,11 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Integrations, Users } from 'meteor/rocketchat:models'; +import { integrations } from '../../../lib/rocketchat'; Meteor.methods({ updateOutgoingIntegration(integrationId, integration) { - integration = RocketChat.integrations.validateOutgoing(integration, this.userId); + integration = integrations.validateOutgoing(integration, this.userId); if (!integration.token || integration.token.trim() === '') { throw new Meteor.Error('error-invalid-token', 'Invalid token', { method: 'updateOutgoingIntegration' }); @@ -11,10 +13,10 @@ Meteor.methods({ let currentIntegration; - if (RocketChat.authz.hasPermission(this.userId, 'manage-integrations')) { - currentIntegration = RocketChat.models.Integrations.findOne(integrationId); - } else if (RocketChat.authz.hasPermission(this.userId, 'manage-own-integrations')) { - currentIntegration = RocketChat.models.Integrations.findOne({ _id: integrationId, '_createdBy._id': this.userId }); + if (hasPermission(this.userId, 'manage-integrations')) { + currentIntegration = Integrations.findOne(integrationId); + } else if (hasPermission(this.userId, 'manage-own-integrations')) { + currentIntegration = Integrations.findOne({ _id: integrationId, '_createdBy._id': this.userId }); } else { throw new Meteor.Error('not_authorized', 'Unauthorized', { method: 'updateOutgoingIntegration' }); } @@ -23,7 +25,7 @@ Meteor.methods({ throw new Meteor.Error('invalid_integration', '[methods] updateOutgoingIntegration -> integration not found'); } - RocketChat.models.Integrations.update(integrationId, { + Integrations.update(integrationId, { $set: { event: integration.event, enabled: integration.enabled, @@ -49,10 +51,10 @@ Meteor.methods({ triggerWordAnywhere: integration.triggerWordAnywhere, runOnEdits: integration.runOnEdits, _updatedAt: new Date(), - _updatedBy: RocketChat.models.Users.findOne(this.userId, { fields: { username: 1 } }), + _updatedBy: Users.findOne(this.userId, { fields: { username: 1 } }), }, }); - return RocketChat.models.Integrations.findOne(integrationId); + return Integrations.findOne(integrationId); }, }); diff --git a/packages/rocketchat-integrations/server/processWebhookMessage.js b/packages/rocketchat-integrations/server/processWebhookMessage.js deleted file mode 100644 index a0c36c66072..00000000000 --- a/packages/rocketchat-integrations/server/processWebhookMessage.js +++ /dev/null @@ -1 +0,0 @@ -export { processWebhookMessage } from 'meteor/rocketchat:lib'; diff --git a/packages/rocketchat-integrations/server/publications/integrationHistory.js b/packages/rocketchat-integrations/server/publications/integrationHistory.js index b5448fc4c12..1aeebdbd4fe 100644 --- a/packages/rocketchat-integrations/server/publications/integrationHistory.js +++ b/packages/rocketchat-integrations/server/publications/integrationHistory.js @@ -1,15 +1,16 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { IntegrationHistory } from 'meteor/rocketchat:models'; Meteor.publish('integrationHistory', function _integrationHistoryPublication(integrationId, limit = 25) { if (!this.userId) { return this.ready(); } - if (RocketChat.authz.hasPermission(this.userId, 'manage-integrations')) { - return RocketChat.models.IntegrationHistory.findByIntegrationId(integrationId, { sort: { _updatedAt: -1 }, limit }); - } else if (RocketChat.authz.hasPermission(this.userId, 'manage-own-integrations')) { - return RocketChat.models.IntegrationHistory.findByIntegrationIdAndCreatedBy(integrationId, this.userId, { sort: { _updatedAt: -1 }, limit }); + if (hasPermission(this.userId, 'manage-integrations')) { + return IntegrationHistory.findByIntegrationId(integrationId, { sort: { _updatedAt: -1 }, limit }); + } else if (hasPermission(this.userId, 'manage-own-integrations')) { + return IntegrationHistory.findByIntegrationIdAndCreatedBy(integrationId, this.userId, { sort: { _updatedAt: -1 }, limit }); } else { throw new Meteor.Error('not-authorized'); } diff --git a/packages/rocketchat-integrations/server/publications/integrations.js b/packages/rocketchat-integrations/server/publications/integrations.js index 2cef8abec56..28aecd2f7a9 100644 --- a/packages/rocketchat-integrations/server/publications/integrations.js +++ b/packages/rocketchat-integrations/server/publications/integrations.js @@ -1,15 +1,16 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { hasPermission } from 'meteor/rocketchat:authorization'; +import { Integrations } from 'meteor/rocketchat:models'; Meteor.publish('integrations', function _integrationPublication() { if (!this.userId) { return this.ready(); } - if (RocketChat.authz.hasPermission(this.userId, 'manage-integrations')) { - return RocketChat.models.Integrations.find(); - } else if (RocketChat.authz.hasPermission(this.userId, 'manage-own-integrations')) { - return RocketChat.models.Integrations.find({ '_createdBy._id': this.userId }); + if (hasPermission(this.userId, 'manage-integrations')) { + return Integrations.find(); + } else if (hasPermission(this.userId, 'manage-own-integrations')) { + return Integrations.find({ '_createdBy._id': this.userId }); } else { throw new Meteor.Error('not-authorized'); } diff --git a/packages/rocketchat-integrations/server/triggers.js b/packages/rocketchat-integrations/server/triggers.js index bdf2f551c26..61960e0998b 100644 --- a/packages/rocketchat-integrations/server/triggers.js +++ b/packages/rocketchat-integrations/server/triggers.js @@ -1,16 +1,17 @@ -import { RocketChat } from 'meteor/rocketchat:lib'; +import { callbacks } from 'meteor/rocketchat:callbacks'; +import { integrations } from '../lib/rocketchat'; const callbackHandler = function _callbackHandler(eventType) { return function _wrapperFunction(...args) { - return RocketChat.integrations.triggerHandler.executeTriggers(eventType, ...args); + return integrations.triggerHandler.executeTriggers(eventType, ...args); }; }; -RocketChat.callbacks.add('afterSaveMessage', callbackHandler('sendMessage'), RocketChat.callbacks.priority.LOW); -RocketChat.callbacks.add('afterCreateChannel', callbackHandler('roomCreated'), RocketChat.callbacks.priority.LOW); -RocketChat.callbacks.add('afterCreatePrivateGroup', callbackHandler('roomCreated'), RocketChat.callbacks.priority.LOW); -RocketChat.callbacks.add('afterCreateUser', callbackHandler('userCreated'), RocketChat.callbacks.priority.LOW); -RocketChat.callbacks.add('afterJoinRoom', callbackHandler('roomJoined'), RocketChat.callbacks.priority.LOW); -RocketChat.callbacks.add('afterLeaveRoom', callbackHandler('roomLeft'), RocketChat.callbacks.priority.LOW); -RocketChat.callbacks.add('afterRoomArchived', callbackHandler('roomArchived'), RocketChat.callbacks.priority.LOW); -RocketChat.callbacks.add('afterFileUpload', callbackHandler('fileUploaded'), RocketChat.callbacks.priority.LOW); +callbacks.add('afterSaveMessage', callbackHandler('sendMessage'), callbacks.priority.LOW); +callbacks.add('afterCreateChannel', callbackHandler('roomCreated'), callbacks.priority.LOW); +callbacks.add('afterCreatePrivateGroup', callbackHandler('roomCreated'), callbacks.priority.LOW); +callbacks.add('afterCreateUser', callbackHandler('userCreated'), callbacks.priority.LOW); +callbacks.add('afterJoinRoom', callbackHandler('roomJoined'), callbacks.priority.LOW); +callbacks.add('afterLeaveRoom', callbackHandler('roomLeft'), callbacks.priority.LOW); +callbacks.add('afterRoomArchived', callbackHandler('roomArchived'), callbacks.priority.LOW); +callbacks.add('afterFileUpload', callbackHandler('fileUploaded'), callbacks.priority.LOW); diff --git a/packages/rocketchat-lib/server/functions/index.js b/packages/rocketchat-lib/server/functions/index.js index 5ff75d6934f..cffd2ebf475 100644 --- a/packages/rocketchat-lib/server/functions/index.js +++ b/packages/rocketchat-lib/server/functions/index.js @@ -25,3 +25,4 @@ export { updateMessage } from './updateMessage'; export { validateCustomFields } from './validateCustomFields'; export { generateUsernameSuggestion } from './getUsernameSuggestion'; export { processWebhookMessage } from './processWebhookMessage'; +export { insertMessage } from './insertMessage'; diff --git a/packages/rocketchat-lib/server/functions/insertMessage.js b/packages/rocketchat-lib/server/functions/insertMessage.js index 6979fd0af05..3195b89ee9f 100644 --- a/packages/rocketchat-lib/server/functions/insertMessage.js +++ b/packages/rocketchat-lib/server/functions/insertMessage.js @@ -1,4 +1,6 @@ import { Match, check } from 'meteor/check'; +import { Markdown } from 'meteor/rocketchat:markdown'; +import { Messages } from 'meteor/rocketchat:models'; const objectMaybeIncluding = (types) => Match.Where((value) => { Object.keys(types).forEach((field) => { @@ -73,7 +75,7 @@ const validateAttachment = (attachment) => { const validateBodyAttachments = (attachments) => attachments.map(validateAttachment); -RocketChat.insertMessage = function(user, message, room, upsert = false) { +export const insertMessage = function(user, message, room, upsert = false) { if (!user || !message || !room._id) { return false; } @@ -112,14 +114,14 @@ RocketChat.insertMessage = function(user, message, room, upsert = false) { if (message.parseUrls !== false) { message.html = message.msg; - message = RocketChat.Markdown.code(message); + message = Markdown.code(message); const urls = message.html.match(/([A-Za-z]{3,9}):\/\/([-;:&=\+\$,\w]+@{1})?([-A-Za-z0-9\.]+)+:?(\d+)?((\/[-\+=!:~%\/\.@\,\(\)\w]*)?\??([-\+=&!:;%@\/\.\,\w]+)?(?:#([^\s\)]+))?)?/g); if (urls) { message.urls = urls.map((url) => ({ url })); } - message = RocketChat.Markdown.mountTokensBack(message, false); + message = Markdown.mountTokensBack(message, false); message.msg = message.html; delete message.html; delete message.tokens; @@ -135,13 +137,13 @@ RocketChat.insertMessage = function(user, message, room, upsert = false) { if (message._id && upsert) { const { _id } = message; delete message._id; - RocketChat.models.Messages.upsert({ + Messages.upsert({ _id, 'u._id': message.u._id, }, message); message._id = _id; } else { - message._id = RocketChat.models.Messages.insert(message); + message._id = Messages.insert(message); } message.sandstormSessionId = sandstormSessionId;