-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
251 additions
and
13 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
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 |
---|---|---|
|
@@ -236,6 +236,7 @@ rocketchat:[email protected] | |
rocketchat:[email protected] | ||
rocketchat:[email protected] | ||
rocketchat:[email protected] | ||
rocketchat:[email protected] | ||
rocketchat:[email protected] | ||
rocketchat:[email protected] | ||
rocketchat:[email protected] | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* globals alerts */ | ||
|
||
Meteor.startup(function() { | ||
Tracker.autorun(() => { | ||
const user = Meteor.user(); | ||
|
||
if (user && Object.keys(user.banners || {}).length > 0) { | ||
const firstBanner = Object.values(user.banners).sort((a, b) => b.priority - a.priority)[0]; | ||
firstBanner.textArguments = firstBanner.textArguments || []; | ||
|
||
alerts.open({ | ||
title: TAPi18n.__(firstBanner.title), | ||
text: TAPi18n.__(firstBanner.text, ...firstBanner.textArguments), | ||
modifiers: firstBanner.modifiers, | ||
action() { | ||
if (firstBanner.link) { | ||
window.open(firstBanner.link, '_system'); | ||
} | ||
}, | ||
onClose() { | ||
Meteor.call('banner/dismiss', { | ||
id: firstBanner.id | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
}); |
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,19 @@ | ||
Package.describe({ | ||
name: 'rocketchat:version-check', | ||
version: '0.0.1', | ||
summary: 'Check for new avaiable versions', | ||
git: '' | ||
}); | ||
|
||
Package.onUse(function(api) { | ||
api.use([ | ||
'mongo', | ||
'ecmascript', | ||
'rocketchat:lib', | ||
'rocketchat:logger', | ||
'percolate:synced-cron' | ||
]); | ||
|
||
api.mainModule('client/client.js', 'client'); | ||
api.mainModule('server/server.js', 'server'); | ||
}); |
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,8 @@ | ||
RocketChat.settings.addGroup('General', function() { | ||
this.section('Update', function() { | ||
this.add('Update_LatestAvailableVersion', '0.0.0', { | ||
type: 'string', | ||
readonly: true | ||
}); | ||
}); | ||
}); |
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,14 @@ | ||
export default { | ||
versions: [{ | ||
version: '0.61.2', | ||
security: true, | ||
infoUrl: 'https://rocket.chat' | ||
}], | ||
alerts: [{ | ||
timestamp: '2018-02-19T22:56:23.290Z', | ||
title: 'Alert title', | ||
description: 'Alert description', | ||
infoUrl: 'https://rocket.chat', | ||
infoTitle: 'More information' | ||
}] | ||
}; |
54 changes: 54 additions & 0 deletions
54
packages/rocketchat-version-check/server/functions/checkVersionUpdate.js
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,54 @@ | ||
import semver from 'semver'; | ||
import getNewUpdates from './getNewUpdates'; | ||
import logger from '../logger'; | ||
|
||
export default () => { | ||
logger.info('Checking for version updates'); | ||
|
||
const { versions } = getNewUpdates(); | ||
|
||
const update = { | ||
exists: false, | ||
lastestVersion: null, | ||
security: false | ||
}; | ||
|
||
const lastCheckedVersion = RocketChat.settings.get('Update_LatestAvailableVersion'); | ||
versions.forEach(version => { | ||
if (semver.lte(version.version, lastCheckedVersion)) { | ||
return; | ||
} | ||
|
||
if (semver.lte(version.version, RocketChat.Info.version)) { | ||
return; | ||
} | ||
|
||
update.exists = true; | ||
update.lastestVersion = version; | ||
|
||
if (version.security === true) { | ||
update.security = true; | ||
} | ||
}); | ||
|
||
if (update.exists) { | ||
RocketChat.settings.updateById('Update_LatestAvailableVersion', update.lastestVersion.version); | ||
RocketChat.models.Roles.findUsersInRole('admin').forEach(adminUser => { | ||
const msg = { | ||
msg: `*${ TAPi18n.__('Update_your_RocketChat', adminUser.language) }*\n${ TAPi18n.__('New_version_available_(s)', update.lastestVersion.version, adminUser.language) }\n${ update.lastestVersion.infoUrl }`, | ||
rid: [adminUser._id, 'rocket.cat'].sort().join('') | ||
}; | ||
|
||
Meteor.runAsUser('rocket.cat', () => Meteor.call('sendMessage', msg)); | ||
|
||
RocketChat.models.Users.addBannerById(adminUser._id, { | ||
id: 'versionUpdate', | ||
priority: 10, | ||
title: 'Update_your_RocketChat', | ||
text: 'New_version_available_(s)', | ||
textArguments: [update.lastestVersion.version], | ||
link: update.lastestVersion.infoUrl | ||
}); | ||
}); | ||
} | ||
}; |
47 changes: 47 additions & 0 deletions
47
packages/rocketchat-version-check/server/functions/getNewUpdates.js
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,47 @@ | ||
/* global MongoInternals */ | ||
import os from 'os'; | ||
import { HTTP } from 'meteor/http'; | ||
import logger from '../logger'; | ||
// import checkUpdate from '../checkUpdate'; | ||
|
||
export default () => { | ||
try { | ||
const uniqueID = RocketChat.models.Settings.findOne('uniqueID'); | ||
const _oplogHandle = MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle; | ||
const oplogEnabled = _oplogHandle && _oplogHandle.onOplogEntry && RocketChat.settings.get('Force_Disable_OpLog_For_Cache') !== true; | ||
|
||
const data = { | ||
uniqueId: uniqueID.value, | ||
installedAt: uniqueID.createdAt, | ||
version: RocketChat.Info.version, | ||
oplogEnabled, | ||
osType: os.type(), | ||
osPlatform: os.platform(), | ||
osArch: os.arch(), | ||
osRelease: os.release(), | ||
nodeVersion: process.version, | ||
deployMethod: process.env.DEPLOY_METHOD || 'tar', | ||
deployPlatform: process.env.DEPLOY_PLATFORM || 'selfinstall' | ||
}; | ||
|
||
const result = HTTP.get('https://releases.rocket.chat/updates/check', { | ||
params: data | ||
}); | ||
|
||
// const result = { | ||
// data: { | ||
// ...checkUpdate | ||
// } | ||
// }; | ||
|
||
return result.data; | ||
} catch (error) { | ||
// console.log(error); | ||
logger.error('Failed to get version updates', error); | ||
|
||
return { | ||
versions: [], | ||
alerts: [] | ||
}; | ||
} | ||
}; |
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 @@ | ||
export default new Logger('VersionCheck'); |
11 changes: 11 additions & 0 deletions
11
packages/rocketchat-version-check/server/methods/banner_dismiss.js
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,11 @@ | ||
Meteor.methods({ | ||
'banner/dismiss'({ id }) { | ||
if (!Meteor.userId()) { | ||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'banner/dismiss' }); | ||
} | ||
|
||
RocketChat.models.Users.removeBannerById(this.userId, { | ||
id | ||
}); | ||
} | ||
}); |
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,29 @@ | ||
/* globals SyncedCron */ | ||
|
||
import checkVersionUpdate from './functions/checkVersionUpdate'; | ||
import './methods/banner_dismiss'; | ||
import './addSettings'; | ||
|
||
const jobName = 'version_check'; | ||
|
||
if (SyncedCron.nextScheduledAtDate(jobName)) { | ||
SyncedCron.remove(jobName); | ||
} | ||
|
||
SyncedCron.add({ | ||
name: jobName, | ||
schedule: parser => parser.text('at 2:00 am'), | ||
job() { | ||
checkVersionUpdate(); | ||
} | ||
}); | ||
|
||
SyncedCron.start(); | ||
|
||
Meteor.startup(() => { | ||
checkVersionUpdate(); | ||
}); | ||
|
||
// Send email to admins | ||
// Save latest alert | ||
// ENV var to disable the check for update for our cloud |
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