Skip to content

Commit

Permalink
fix(notices): unable to deactivate notice through socket
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Jul 7, 2022
1 parent 002411b commit a2d9103
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/client/components/NoticeBanner/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class NoticeBanner extends React.Component {

return (
<div
id={'notice-banner'}
style={{
width: '100%',
height: '30px',
Expand Down
14 changes: 10 additions & 4 deletions src/client/containers/Modals/ViewAllNotificationsModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import { makeObservable, observable } from 'mobx'
import axios from 'axios'
import Log from '../../logger'

import { NOTIFICATIONS_MARK_READ } from 'serverSocket/socketEventConsts'

import { hideModal } from 'actions/common'

import BaseModal from 'containers/Modals/BaseModal'
import Button from 'components/Button'

import helpers from 'lib/helpers'
import socket from 'lib/socket'

@observer
class ViewAllNotificationsModal extends React.Component {
Expand Down Expand Up @@ -55,7 +56,7 @@ class ViewAllNotificationsModal extends React.Component {
if (!notification || !notification.data || !notification.data.ticket || !notification.data.ticket.uid) return false

this.props.hideModal()
socket.socket.emit('markNotificationRead', notification._id)
this.props.socket.emit(NOTIFICATIONS_MARK_READ, notification._id)
History.pushState(null, null, `/tickets/${notification.data.ticket.uid}`)
}

Expand Down Expand Up @@ -113,7 +114,12 @@ class ViewAllNotificationsModal extends React.Component {
}

ViewAllNotificationsModal.propTypes = {
hideModal: PropTypes.func.isRequired
hideModal: PropTypes.func.isRequired,
socket: PropTypes.object.isRequired
}

export default connect(null, { hideModal })(ViewAllNotificationsModal)
const mapStateToProps = state => ({
socket: state.shared.socket
})

export default connect(mapStateToProps, { hideModal })(ViewAllNotificationsModal)
9 changes: 6 additions & 3 deletions src/client/containers/Notice/NoticeContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
})
Expand Down Expand Up @@ -195,6 +196,7 @@ class NoticeContainer extends React.Component {
}

NoticeContainer.propTypes = {
socket: PropTypes.object.isRequired,
notices: PropTypes.object.isRequired,
loading: PropTypes.bool.isRequired,

Expand All @@ -205,6 +207,7 @@ NoticeContainer.propTypes = {
}

const mapStateToProps = state => ({
socket: state.shared.socket,
notices: state.noticesState.notices,
loading: state.noticesState.loading
})
Expand Down
23 changes: 12 additions & 11 deletions src/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,23 +79,24 @@ 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 }
})

userSchema.set('toObject', { getters: true })

var autoPopulateRole = function (next) {
const autoPopulateRole = function (next) {
this.populate('role', 'name description normalized _id')
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())
Expand Down
18 changes: 10 additions & 8 deletions src/socketio/noticeSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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)
})
}

Expand Down

0 comments on commit a2d9103

Please sign in to comment.