-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feat/setup-wizard-register-offline
- Loading branch information
Showing
34 changed files
with
561 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
"@rocket.chat/meteor": minor | ||
"@rocket.chat/core-typings": minor | ||
--- | ||
|
||
Added `push` statistic, containing three bits. Each bit represents a boolean: | ||
``` | ||
1 1 1 | ||
| | | | ||
| | +- push enabled = 0b1 = 1 | ||
| +--- push gateway enabled = 0b10 = 2 | ||
+----- push gateway changed = 0b100 = 4 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@rocket.chat/meteor': patch | ||
--- | ||
|
||
Search users using full name too on share message modal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
apps/meteor/app/cloud/server/functions/syncWorkspace/announcementSync.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { type Cloud, type Serialized } from '@rocket.chat/core-typings'; | ||
import { serverFetch as fetch } from '@rocket.chat/server-fetch'; | ||
import { v, compile } from 'suretype'; | ||
|
||
import { CloudWorkspaceAccessError } from '../../../../../lib/errors/CloudWorkspaceAccessError'; | ||
import { CloudWorkspaceConnectionError } from '../../../../../lib/errors/CloudWorkspaceConnectionError'; | ||
import { CloudWorkspaceRegistrationError } from '../../../../../lib/errors/CloudWorkspaceRegistrationError'; | ||
import { SystemLogger } from '../../../../../server/lib/logger/system'; | ||
import { settings } from '../../../../settings/server'; | ||
import { buildWorkspaceRegistrationData } from '../buildRegistrationData'; | ||
import { getWorkspaceAccessToken } from '../getWorkspaceAccessToken'; | ||
import { retrieveRegistrationStatus } from '../retrieveRegistrationStatus'; | ||
import { handleAnnouncementsOnWorkspaceSync, handleNpsOnWorkspaceSync } from './handleCommsSync'; | ||
import { legacySyncWorkspace } from './legacySyncWorkspace'; | ||
|
||
const workspaceCommPayloadSchema = v.object({ | ||
workspaceId: v.string().required(), | ||
publicKey: v.string(), | ||
nps: v.object({ | ||
id: v.string().required(), | ||
startAt: v.string().format('date-time').required(), | ||
expireAt: v.string().format('date-time').required(), | ||
}), | ||
announcements: v.object({ | ||
create: v.array( | ||
v.object({ | ||
_id: v.string().required(), | ||
_updatedAt: v.string().format('date-time').required(), | ||
selector: v.object({ | ||
roles: v.array(v.string()), | ||
}), | ||
platform: v.array(v.string().enum('web', 'mobile')).required(), | ||
expireAt: v.string().format('date-time').required(), | ||
startAt: v.string().format('date-time').required(), | ||
createdBy: v.string().enum('cloud', 'system').required(), | ||
createdAt: v.string().format('date-time').required(), | ||
dictionary: v.object({}).additional(v.object({}).additional(v.string())), | ||
view: v.any(), | ||
surface: v.string().enum('banner', 'modal').required(), | ||
}), | ||
), | ||
delete: v.array(v.string()), | ||
}), | ||
}); | ||
|
||
const assertWorkspaceCommPayload = compile(workspaceCommPayloadSchema); | ||
|
||
const fetchCloudAnnouncementsSync = async ({ | ||
token, | ||
data, | ||
}: { | ||
token: string; | ||
data: Cloud.WorkspaceSyncRequestPayload; | ||
}): Promise<Serialized<Cloud.WorkspaceCommsResponsePayload>> => { | ||
const cloudUrl = settings.get<string>('Cloud_Url'); | ||
const response = await fetch(`${cloudUrl}/api/v3/comms/workspace`, { | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
body: data, | ||
}); | ||
|
||
if (!response.ok) { | ||
try { | ||
const { error } = await response.json(); | ||
throw new CloudWorkspaceConnectionError(`Failed to connect to Rocket.Chat Cloud: ${error}`); | ||
} catch (error) { | ||
throw new CloudWorkspaceConnectionError(`Failed to connect to Rocket.Chat Cloud: ${response.statusText}`); | ||
} | ||
} | ||
|
||
const payload = await response.json(); | ||
|
||
assertWorkspaceCommPayload(payload); | ||
return payload; | ||
}; | ||
|
||
export async function announcementSync() { | ||
try { | ||
const { workspaceRegistered } = await retrieveRegistrationStatus(); | ||
if (!workspaceRegistered) { | ||
throw new CloudWorkspaceRegistrationError('Workspace is not registered'); | ||
} | ||
|
||
const token = await getWorkspaceAccessToken(true); | ||
if (!token) { | ||
throw new CloudWorkspaceAccessError('Workspace does not have a valid access token'); | ||
} | ||
|
||
const workspaceRegistrationData = await buildWorkspaceRegistrationData(undefined); | ||
|
||
const { nps, announcements } = await fetchCloudAnnouncementsSync({ | ||
token, | ||
data: workspaceRegistrationData, | ||
}); | ||
|
||
if (nps) { | ||
await handleNpsOnWorkspaceSync(nps); | ||
} | ||
|
||
if (announcements) { | ||
await handleAnnouncementsOnWorkspaceSync(announcements); | ||
} | ||
|
||
return true; | ||
} catch (err) { | ||
SystemLogger.error({ | ||
msg: 'Failed to sync with Rocket.Chat Cloud', | ||
url: '/sync', | ||
err, | ||
}); | ||
} | ||
|
||
await legacySyncWorkspace(); | ||
} |
65 changes: 65 additions & 0 deletions
65
apps/meteor/app/cloud/server/functions/syncWorkspace/handleCommsSync.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { NPS, Banner } from '@rocket.chat/core-services'; | ||
import { type Cloud, type Serialized } from '@rocket.chat/core-typings'; | ||
import { CloudAnnouncements } from '@rocket.chat/models'; | ||
|
||
import { getAndCreateNpsSurvey } from '../../../../../server/services/nps/getAndCreateNpsSurvey'; | ||
|
||
export const handleNpsOnWorkspaceSync = async (nps: Exclude<Serialized<Cloud.WorkspaceSyncPayload>['nps'], undefined>) => { | ||
const { id: npsId, expireAt } = nps; | ||
|
||
const startAt = new Date(nps.startAt); | ||
|
||
await NPS.create({ | ||
npsId, | ||
startAt, | ||
expireAt: new Date(expireAt), | ||
createdBy: { | ||
_id: 'rocket.cat', | ||
username: 'rocket.cat', | ||
}, | ||
}); | ||
|
||
const now = new Date(); | ||
|
||
if (startAt.getFullYear() === now.getFullYear() && startAt.getMonth() === now.getMonth() && startAt.getDate() === now.getDate()) { | ||
await getAndCreateNpsSurvey(npsId); | ||
} | ||
}; | ||
|
||
export const handleBannerOnWorkspaceSync = async (banners: Exclude<Serialized<Cloud.WorkspaceSyncPayload>['banners'], undefined>) => { | ||
for await (const banner of banners) { | ||
const { createdAt, expireAt, startAt, inactivedAt, _updatedAt, ...rest } = banner; | ||
|
||
await Banner.create({ | ||
...rest, | ||
createdAt: new Date(createdAt), | ||
expireAt: new Date(expireAt), | ||
startAt: new Date(startAt), | ||
...(inactivedAt && { inactivedAt: new Date(inactivedAt) }), | ||
}); | ||
} | ||
}; | ||
|
||
const deserializeAnnouncement = (announcement: Serialized<Cloud.Announcement>): Cloud.Announcement => ({ | ||
...announcement, | ||
_updatedAt: new Date(announcement._updatedAt), | ||
expireAt: new Date(announcement.expireAt), | ||
startAt: new Date(announcement.startAt), | ||
createdAt: new Date(announcement.createdAt), | ||
}); | ||
|
||
export const handleAnnouncementsOnWorkspaceSync = async ( | ||
announcements: Exclude<Serialized<Cloud.WorkspaceCommsResponsePayload>['announcements'], undefined>, | ||
) => { | ||
const { create, delete: deleteIds } = announcements; | ||
|
||
if (deleteIds) { | ||
await CloudAnnouncements.deleteMany({ _id: { $in: deleteIds } }); | ||
} | ||
|
||
for await (const announcement of create.map(deserializeAnnouncement)) { | ||
const { _id, ...rest } = announcement; | ||
|
||
await CloudAnnouncements.updateOne({ _id }, { $set: rest }, { upsert: true }); | ||
} | ||
}; |
4 changes: 2 additions & 2 deletions
4
apps/meteor/app/cloud/server/functions/syncWorkspace/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.