Removes HTML tags shown in Browser Notification

Fixes https://jira.coreos.com/browse/QUAY-956
This commit is contained in:
Sida Chen 2018-07-31 11:48:14 -04:00
parent 5e4d52f1fd
commit bf4cef4870
2 changed files with 17 additions and 3 deletions

View file

@ -3,9 +3,9 @@
* in the sidebar) and provides helper methods for working with them.
*/
angular.module('quay').factory('NotificationService',
['$rootScope', '$interval', 'UserService', 'ApiService', 'StringBuilderService', 'PlanService', 'CookieService', 'Features', 'Config', '$location', 'VulnerabilityService',
['$rootScope', '$interval', 'UserService', 'ApiService', 'StringBuilderService', 'PlanService', 'CookieService', 'Features', 'Config', '$location', 'VulnerabilityService', 'UtilService',
function($rootScope, $interval, UserService, ApiService, StringBuilderService, PlanService, CookieService, Features, Config, $location, VulnerabilityService) {
function($rootScope, $interval, UserService, ApiService, StringBuilderService, PlanService, CookieService, Features, Config, $location, VulnerabilityService, UtilService) {
var notificationService = {
'user': null,
'notifications': [],
@ -229,6 +229,16 @@ function($rootScope, $interval, UserService, ApiService, StringBuilderService, P
return StringBuilderService.buildTrustedString(kindInfo['message'], notification['metadata']);
};
notificationService.getBrowserNotificationMessage = function(notification) {
var kindInfo = notificationKinds[notification['kind']];
if (!kindInfo) {
return '(Unknown notification kind: ' + notification['kind'] + ')';
}
const unsafeHtml = StringBuilderService.buildString(kindInfo['message'], notification['metadata']);
return UtilService.removeHtmlTags(unsafeHtml);
}
notificationService.getClass = function(notification) {
var kindInfo = notificationKinds[notification['kind']];
if (!kindInfo) {
@ -294,7 +304,7 @@ function($rootScope, $interval, UserService, ApiService, StringBuilderService, P
if (newNotifications.length > 0) {
let message = 'You have unread notifications';
if (newNotifications.length === 1) {
message = notificationService.getMessage(newNotifications[0]);
message = notificationService.getBrowserNotificationMessage(newNotifications[0]);
}
new Notification(message, {

View file

@ -136,5 +136,9 @@ angular.module('quay').factory('UtilService', ['$sanitize', 'markdownConverter',
utilService.UrlBuilder = UrlBuilder;
utilService.removeHtmlTags = function(text){
return new DOMParser().parseFromString(text, 'text/html').body.textContent || text;
};
return utilService;
}]);