diff --git a/back/methods/osticket/sendToSupport.js b/back/methods/osticket/sendToSupport.js new file mode 100644 index 000000000..516313ac6 --- /dev/null +++ b/back/methods/osticket/sendToSupport.js @@ -0,0 +1,63 @@ +const smtp = require('vn-print/core/smtp'); +const config = require('vn-print/core/config'); + +module.exports = Self => { + Self.remoteMethodCtx('sendToSupport', { + description: 'Send mail to support', + accessType: 'WRITE', + accepts: [ + { + arg: 'subject', + type: 'string', + required: true, + description: 'The subject' + }, + { + arg: 'reason', + type: 'string', + description: 'The reason' + }, + { + arg: 'additionalData', + type: 'object', + required: true, + description: 'The additional data' + } + ], + returns: { + type: 'object', + root: true + }, + http: { + path: `/send-to-support`, + verb: 'POST' + } + }); + + Self.sendToSupport = async(ctx, subject, reason, additionalData) => { + const emailUser = + await Self.app.models.EmailUser.findById(ctx.req.accessToken.userId, {fields: ['email']}); + + let html = `Motivo:
${reason}
`; + for (const data in additionalData) { + tryJson(additionalData[data]); + html += `${data}:
${tryJson(additionalData[data])}
`; + } + console.log(subject, reason, additionalData); + console.log(html); + smtp.send({ + to: config.app.reportEmail, + replyTo: emailUser.email, + subject: '[Support-Salix] ' + subject, + html + }); + }; + + function tryJson(value) { + try { + return JSON.parse(value); + } catch (e) { + return value; + } + } +}; diff --git a/back/models/osticket.js b/back/models/osticket.js index 50e429160..2a4b7bbb5 100644 --- a/back/models/osticket.js +++ b/back/models/osticket.js @@ -1,4 +1,5 @@ module.exports = Self => { require('../methods/osticket/osTicketReportEmail')(Self); require('../methods/osticket/closeTicket')(Self); + require('../methods/osticket/sendToSupport')(Self); }; diff --git a/front/core/components/snackbar/snackbar.html b/front/core/components/snackbar/snackbar.html index 8ef5891bc..41ae6ddbd 100644 --- a/front/core/components/snackbar/snackbar.html +++ b/front/core/components/snackbar/snackbar.html @@ -1 +1,35 @@ -
\ No newline at end of file +
+ + +
+
Open CAU
+ + + + + + + + + + + {{'Este cau contiene más información relevante para el equipo de informática' | translate}}: + + +
+
+ + + + +
diff --git a/front/core/components/snackbar/snackbar.js b/front/core/components/snackbar/snackbar.js index e68c22f3f..19ce4ea54 100644 --- a/front/core/components/snackbar/snackbar.js +++ b/front/core/components/snackbar/snackbar.js @@ -27,6 +27,18 @@ export default class Controller extends Component { setTimeout(() => element.classList.add('shown'), 30); shape.element = element; + if (data.additionalData) { + let supportButton = document.createElement('i'); + supportButton.setAttribute('class', 'material-icons'); + supportButton.addEventListener('click', () => this.onButtonClick(this.$.supportDialog.show())); + element.appendChild(supportButton); + + let buttonIcon = 'support_agent'; + buttonIcon = document.createTextNode(buttonIcon); + supportButton.appendChild(buttonIcon); + this.$.supportDialog.additionalData = data.additionalData; + } + if (shape.type) element.classList.add(shape.type); @@ -95,7 +107,7 @@ export default class Controller extends Component { clearTimeout(shape.hideTimeout); shape.hideTimeout = setTimeout( - () => this.hide(shape), shape.timeout || 3000); + () => this.hide(shape), shape.timeout || 5000); this.lastShape = shape; } @@ -142,6 +154,23 @@ export default class Controller extends Component { else this.hide(shape); } + + sendToSupport() { + const supportDialog = this.$.supportDialog; + console.log(this.$.supportDialog.subject); + console.log(this.$.supportDialog.reason); + console.log(this.$.supportDialog.additionalData); + console.log({ + subject: supportDialog.subject, + reason: supportDialog.reason, + additionalData: supportDialog.additionalData + }); + this.$http.post('Ostickets/send-to-support', { + subject: supportDialog.subject, + reason: supportDialog.reason, + additionalData: supportDialog.additionalData + }); + } } ngModule.vnComponent('vnSnackbar', { diff --git a/front/core/components/snackbar/style.scss b/front/core/components/snackbar/style.scss index 23e8223e5..d02886fd1 100644 --- a/front/core/components/snackbar/style.scss +++ b/front/core/components/snackbar/style.scss @@ -20,11 +20,11 @@ vn-snackbar .shape { margin-bottom: 15px; color: white; padding: 12px 25px 12px 12px; - + & > .text { text-align: center; - vn-chip { + vn-chip { position: absolute; left: -16px; top: -16px; @@ -64,4 +64,4 @@ vn-snackbar .shape { top: 0; right: 0 } -} \ No newline at end of file +} diff --git a/front/core/services/app.js b/front/core/services/app.js index fb0a08777..bffdad108 100644 --- a/front/core/services/app.js +++ b/front/core/services/app.js @@ -23,9 +23,9 @@ export default class App { this.logger.showSuccess(message); } - showError(message) { + showError(message, additionalData) { if (this.logger) - this.logger.showError(message); + this.logger.showError(message, additionalData); } pushLoader() { diff --git a/front/salix/components/app/app.js b/front/salix/components/app/app.js index 97384d1e1..ca8fac751 100644 --- a/front/salix/components/app/app.js +++ b/front/salix/components/app/app.js @@ -25,15 +25,15 @@ export default class App extends Component { } showMessage(message) { - this.$.snackbar.show({message: message}); + this.$.snackbar.show({message}); } showSuccess(message) { - this.$.snackbar.showSuccess({message: message}); + this.$.snackbar.showSuccess({message}); } - showError(message) { - this.$.snackbar.showError({message: message}); + showError(message, additionalData) { + this.$.snackbar.showError({message, additionalData}); } } diff --git a/front/salix/module.js b/front/salix/module.js index 01df01a67..422c2741e 100644 --- a/front/salix/module.js +++ b/front/salix/module.js @@ -148,7 +148,13 @@ function $exceptionHandler(vnApp, $window, $state, $injector) { if (messageT) message = $translate.instant(messageT); - vnApp.showError(message); + + const additonalData = { + frontPath: $state.current.name, + httpRequest: cause.replace('Possibly unhandled rejection: ', ''), + backError: JSON.stringify(exception) + }; + vnApp.showError(message, additonalData); }; } ngModule.factory('$exceptionHandler', $exceptionHandler); diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index c0b1cc0d9..9a60f6264 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -2,6 +2,7 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const buildFilter = require('vn-loopback/util/filter').buildFilter; const mergeFilters = require('vn-loopback/util/filter').mergeFilters; +const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('filter', { @@ -88,6 +89,7 @@ module.exports = Self => { const conn = Self.dataSource.connector; const models = Self.app.models; const myOptions = {}; + throw new UserError(`You don't have enough privileges`); if (typeof options == 'object') Object.assign(myOptions, options); @@ -145,7 +147,7 @@ module.exports = Self => { const stmts = []; const stmt = new ParameterizedSQL( - `SELECT + `SELECT i.id, i.image, i.name,