[FIX] Improve cloud section (#13820)
* Improve cloud section * add sync and fix i18n and a few other issues * set oauth scopes * add suggested grammar and federation hub scope * Switch to postform instead of query string to post oauth more securelypull/13925/head^2
parent
9e2a7532ab
commit
b0d71bc943
@ -0,0 +1,13 @@ |
||||
import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; |
||||
import { Settings } from '../../../models'; |
||||
|
||||
export function disconnectWorkspace() { |
||||
const { connectToCloud } = retrieveRegistrationStatus(); |
||||
if (!connectToCloud) { |
||||
return true; |
||||
} |
||||
|
||||
Settings.updateValueById('Register_Server', false); |
||||
|
||||
return true; |
||||
} |
||||
@ -0,0 +1,66 @@ |
||||
import { HTTP } from 'meteor/http'; |
||||
import { settings } from '../../../settings'; |
||||
import { Settings } from '../../../models'; |
||||
|
||||
import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; |
||||
|
||||
import { statistics } from '../../../statistics'; |
||||
|
||||
export function startRegisterWorkspace() { |
||||
const { workspaceRegistered, connectToCloud } = retrieveRegistrationStatus(); |
||||
if ((workspaceRegistered && connectToCloud) || process.env.TEST_MODE) { |
||||
return true; |
||||
} |
||||
|
||||
settings.updateById('Register_Server', true); |
||||
|
||||
if (workspaceRegistered) { |
||||
return true; |
||||
} |
||||
|
||||
const stats = statistics.get(); |
||||
|
||||
const address = settings.get('Site_Url'); |
||||
|
||||
// If we have it lets send it because likely an update
|
||||
const workspaceId = settings.get('Cloud_Workspace_Id'); |
||||
|
||||
const regInfo = { |
||||
uniqueId: stats.uniqueId, |
||||
workspaceId, |
||||
address, |
||||
contactName: stats.wizard.contactName, |
||||
contactEmail: stats.wizard.contactEmail, |
||||
accountName: stats.wizard.organizationName, |
||||
siteName: stats.wizard.siteName, |
||||
deploymentMethod: stats.deploy.method, |
||||
deploymentPlatform: stats.deploy.platform, |
||||
version: stats.version, |
||||
}; |
||||
|
||||
const cloudUrl = settings.get('Cloud_Url'); |
||||
|
||||
let result; |
||||
try { |
||||
result = HTTP.post(`${ cloudUrl }/api/v2/register/workspace`, { |
||||
data: regInfo, |
||||
}); |
||||
} catch (e) { |
||||
if (e.response && e.response.data && e.response.data.errorCode) { |
||||
console.error(`Failed to register with Rocket.Chat Cloud. ErrorCode: ${ e.response.data.errorCode }`); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
const { data } = result; |
||||
|
||||
if (!data) { |
||||
return false; |
||||
} |
||||
|
||||
Settings.updateValueById('Cloud_Workspace_Id', data.id); |
||||
|
||||
console.log(data); |
||||
|
||||
return true; |
||||
} |
||||
@ -0,0 +1,58 @@ |
||||
import { HTTP } from 'meteor/http'; |
||||
import { settings } from '../../../settings'; |
||||
|
||||
import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; |
||||
import { getWorkspaceAccessToken } from './getWorkspaceAccessToken'; |
||||
|
||||
import { statistics } from '../../../statistics'; |
||||
import { getWorkspaceLicense } from './getWorkspaceLicense'; |
||||
|
||||
export function syncWorkspace() { |
||||
const { workspaceRegistered, connectToCloud } = retrieveRegistrationStatus(); |
||||
if (!workspaceRegistered || !connectToCloud) { |
||||
return false; |
||||
} |
||||
|
||||
const stats = statistics.get(); |
||||
|
||||
const address = settings.get('Site_Url'); |
||||
|
||||
const info = { |
||||
uniqueId: stats.uniqueId, |
||||
address, |
||||
contactName: stats.wizard.contactName, |
||||
contactEmail: stats.wizard.contactEmail, |
||||
accountName: stats.wizard.organizationName, |
||||
siteName: stats.wizard.siteName, |
||||
deploymentMethod: stats.deploy.method, |
||||
deploymentPlatform: stats.deploy.platform, |
||||
version: stats.version, |
||||
}; |
||||
|
||||
const workspaceUrl = settings.get('Cloud_Workspace_Registration_Client_Uri'); |
||||
|
||||
try { |
||||
const headers = {}; |
||||
const token = getWorkspaceAccessToken(true); |
||||
|
||||
if (token) { |
||||
headers.Authorization = `Bearer ${ token }`; |
||||
} else { |
||||
return false; |
||||
} |
||||
|
||||
HTTP.post(`${ workspaceUrl }/registration`, { |
||||
data: info, |
||||
headers, |
||||
}); |
||||
|
||||
} catch (e) { |
||||
if (e.response && e.response.data && e.response.data.error) { |
||||
console.error(`Failed to sync with Rocket.Chat Cloud. Error: ${ e.response.data.error }`); |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
return getWorkspaceLicense(); |
||||
} |
||||
@ -0,0 +1,22 @@ |
||||
import { Settings } from '../../../models'; |
||||
|
||||
import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; |
||||
|
||||
export function unregisterWorkspace() { |
||||
const { workspaceRegistered } = retrieveRegistrationStatus(); |
||||
if (!workspaceRegistered) { |
||||
return true; |
||||
} |
||||
|
||||
Settings.updateValueById('Cloud_Workspace_Id', null); |
||||
Settings.updateValueById('Cloud_Workspace_Name', null); |
||||
Settings.updateValueById('Cloud_Workspace_Client_Id', null); |
||||
Settings.updateValueById('Cloud_Workspace_Client_Secret', null); |
||||
Settings.updateValueById('Cloud_Workspace_Client_Secret_Expires_At', null); |
||||
Settings.updateValueById('Cloud_Workspace_Registration_Client_Uri', null); |
||||
|
||||
// So doesn't try to register again automatically
|
||||
Settings.updateValueById('Register_Server', false); |
||||
|
||||
return true; |
||||
} |
||||
@ -0,0 +1,16 @@ |
||||
// These are the scopes we by default request access to
|
||||
export const workspaceScopes = [ |
||||
'workspace:license:read', |
||||
'workspace:client:write', |
||||
'workspace:stats:write', |
||||
'workspace:push:send', |
||||
'marketplace:read', |
||||
'marketplace:download', |
||||
'fedhub:register', |
||||
]; |
||||
|
||||
// These are the scopes we use for the user
|
||||
export const userScopes = [ |
||||
'openid', |
||||
'offline_access', |
||||
]; |
||||
Loading…
Reference in new issue