forked from GladysAssistant/Gladys
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GladysAssistant#301 : Gladys now send a notification when a modul…
…e is updated
- Loading branch information
1 parent
999c30d
commit 43e6d12
Showing
8 changed files
with
67 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const semver = require('semver') | ||
const Promise = require('bluebird'); | ||
|
||
module.exports = function checkUpdate() { | ||
|
||
// get the list of modules installed | ||
return gladys.module.get() | ||
.then((modulesInstalled) => { | ||
return Promise.map(modulesInstalled, (moduleInstalled) => { | ||
|
||
return gladys.utils.request({ | ||
method: 'GET', | ||
url: sails.config.update.getModuleBySlugUrl + moduleInstalled.slug | ||
}) | ||
.then((moduleOnStore) => { | ||
if (semver.valid(moduleOnStore.version) && semver.valid(moduleInstalled.version)) { | ||
if (semver.gt(moduleOnStore.version, moduleInstalled.version) === true) { | ||
return sendNotificationAdmins(moduleOnStore, moduleInstalled); | ||
} | ||
} | ||
}) | ||
}, { concurrency: 1 }); | ||
}); | ||
}; | ||
|
||
function sendNotificationAdmins(moduleOnStore, moduleInstalled) { | ||
return gladys.user.getAdmin() | ||
.then((admins) => { | ||
return Promise.map(admins, (admin) => { | ||
|
||
// we create a new notification | ||
var notification = { | ||
title: sails.__({ | ||
phrase: 'notification-update-available-title', | ||
locale: admin.language.substr(0, 2) | ||
}) + ` ${moduleOnStore.version}`, | ||
text: `${moduleInstalled.name} ` + sails.__({ | ||
phrase: 'notification-update-module-available-text', | ||
locale: admin.language.substr(0, 2) | ||
}) + ` ${moduleOnStore.version}`, | ||
icon: 'fa fa-cloud-download', | ||
iconColor: 'blue', | ||
link: '/dashboard/module', | ||
priority: 0, | ||
user: admin.id, | ||
}; | ||
|
||
// and send it only if we hadn't done it before | ||
return gladys.notification.createIfNotExist(notification); | ||
}); | ||
}); | ||
} |
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
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