diff --git a/src/client/components/NoticeBanner/index.jsx b/src/client/components/NoticeBanner/index.jsx
index 42e9729ea..1534f5b6c 100644
--- a/src/client/components/NoticeBanner/index.jsx
+++ b/src/client/components/NoticeBanner/index.jsx
@@ -27,6 +27,7 @@ class NoticeBanner extends React.Component {
return (
({
+ socket: state.shared.socket
+})
+
+export default connect(mapStateToProps, { hideModal })(ViewAllNotificationsModal)
diff --git a/src/client/containers/Notice/NoticeContainer.jsx b/src/client/containers/Notice/NoticeContainer.jsx
index ebea7ebe7..1696258d2 100644
--- a/src/client/containers/Notice/NoticeContainer.jsx
+++ b/src/client/containers/Notice/NoticeContainer.jsx
@@ -7,6 +7,8 @@ import axios from 'axios'
import { fetchNotices, deleteNotice, unloadNotices } from 'actions/notices'
import { showModal } from 'actions/common'
+import { NOTICE_SHOW, NOTICE_CLEAR } from 'serverSocket/socketEventConsts'
+
import PageTitle from 'components/PageTitle'
import PageContent from 'components/PageContent'
import Table from 'components/Table'
@@ -17,7 +19,6 @@ import ButtonGroup from 'components/ButtonGroup'
import Button from 'components/Button'
import helpers from 'lib/helpers'
-import socket from 'lib/socket'
import UIKit from 'uikit'
class NoticeContainer extends React.Component {
@@ -46,7 +47,7 @@ class NoticeContainer extends React.Component {
axios
.put('/api/v2/notices/' + noticeId + '/activate', { active: true })
.then(() => {
- socket.ui.setShowNotice(noticeId)
+ this.props.socket.emit(NOTICE_SHOW, { noticeId })
})
.catch(err => {
Log.error(err)
@@ -58,7 +59,7 @@ class NoticeContainer extends React.Component {
axios
.get('/api/v1/notices/clearactive')
.then(() => {
- socket.ui.setClearNotice()
+ this.props.socket.emit(NOTICE_CLEAR)
helpers.UI.showSnackbar('Notice has been deactivated', false)
})
@@ -195,6 +196,7 @@ class NoticeContainer extends React.Component {
}
NoticeContainer.propTypes = {
+ socket: PropTypes.object.isRequired,
notices: PropTypes.object.isRequired,
loading: PropTypes.bool.isRequired,
@@ -205,6 +207,7 @@ NoticeContainer.propTypes = {
}
const mapStateToProps = state => ({
+ socket: state.shared.socket,
notices: state.noticesState.notices,
loading: state.noticesState.loading
})
diff --git a/src/models/user.js b/src/models/user.js
index 6097195ac..df820ae72 100644
--- a/src/models/user.js
+++ b/src/models/user.js
@@ -12,19 +12,19 @@
* Copyright (c) 2014-2019. All rights reserved.
*/
-var async = require('async')
-var mongoose = require('mongoose')
-var winston = require('winston')
-var bcrypt = require('bcrypt')
-var _ = require('lodash')
-var Chance = require('chance')
+const async = require('async')
+const mongoose = require('mongoose')
+const winston = require('winston')
+const bcrypt = require('bcrypt')
+const _ = require('lodash')
+const Chance = require('chance')
const utils = require('../helpers/utils')
// Required for linkage
require('./role')
-var SALT_FACTOR = 10
-var COLLECTION = 'accounts'
+const SALT_FACTOR = 10
+const COLLECTION = 'accounts'
/**
* User Schema
@@ -79,7 +79,8 @@ var userSchema = mongoose.Schema({
preferences: {
tourCompleted: { type: Boolean, default: false },
autoRefreshTicketGrid: { type: Boolean, default: true },
- openChatWindows: [{ type: String, default: [] }]
+ openChatWindows: [{ type: String, default: [] }],
+ keyboardShortcuts: { type: Boolean, default: true }
},
deleted: { type: Boolean, default: false }
@@ -87,7 +88,7 @@ var userSchema = mongoose.Schema({
userSchema.set('toObject', { getters: true })
-var autoPopulateRole = function (next) {
+const autoPopulateRole = function (next) {
this.populate('role', 'name description normalized _id')
next()
}
@@ -95,7 +96,7 @@ var autoPopulateRole = function (next) {
userSchema.pre('findOne', autoPopulateRole).pre('find', autoPopulateRole)
userSchema.pre('save', function (next) {
- var user = this
+ const user = this
user.username = utils.applyMaxShortTextLength(utils.sanitizeFieldPlainText(user.username.toLowerCase().trim()))
user.email = utils.sanitizeFieldPlainText(user.email.trim())
diff --git a/src/socketio/noticeSocket.js b/src/socketio/noticeSocket.js
index e4e880bd7..5d1f3f212 100644
--- a/src/socketio/noticeSocket.js
+++ b/src/socketio/noticeSocket.js
@@ -12,11 +12,13 @@
* Copyright (c) 2014-2019. All rights reserved.
*/
-var winston = require('winston')
-var utils = require('../helpers/utils')
-var noticeSchema = require('../models/notice')
+const winston = require('winston')
+const utils = require('../helpers/utils')
+const noticeSchema = require('../models/notice')
-var events = {}
+const socketEventConst = require('../socketio/socketEventConsts')
+
+const events = {}
function register (socket) {
events.onShowNotice(socket)
@@ -26,7 +28,7 @@ function register (socket) {
function eventLoop () {}
events.onShowNotice = function (socket) {
- socket.on('setShowNotice', function (noticeId) {
+ socket.on(socketEventConst.NOTICE_SHOW, function ({ noticeId }) {
noticeSchema.getNotice(noticeId, function (err, notice) {
if (err) return true
notice.activeDate = new Date()
@@ -36,15 +38,15 @@ events.onShowNotice = function (socket) {
return true
}
- utils.sendToAllConnectedClients(io, '$trudesk:notice:show', notice)
+ utils.sendToAllConnectedClients(io, socketEventConst.NOTICE_UI_SHOW, notice)
})
})
})
}
events.onClearNotice = function (socket) {
- socket.on('setClearNotice', function () {
- utils.sendToAllConnectedClients(io, 'updateClearNotice')
+ socket.on(socketEventConst.NOTICE_CLEAR, function () {
+ utils.sendToAllConnectedClients(io, socketEventConst.NOTICE_UI_CLEAR)
})
}