Removes HTML tags shown in Browser Notification
Fixes https://jira.coreos.com/browse/QUAY-956
This commit is contained in:
parent
5e4d52f1fd
commit
bf4cef4870
2 changed files with 17 additions and 3 deletions
|
@ -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, {
|
||||
|
|
|
@ -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;
|
||||
}]);
|
||||
|
|
Reference in a new issue