|
| 1 | +// Script Include: QuarantineAttachmentUtils |
| 2 | +// Purpose: Utilities for quarantining attachments. |
| 3 | +// Scope: global or scoped. Client callable false. |
| 4 | + |
| 5 | +var QuarantineAttachmentUtils = Class.create(); |
| 6 | +QuarantineAttachmentUtils.prototype = { |
| 7 | + initialize: function() {}, |
| 8 | + |
| 9 | + ensureQuarantineRecord: function(table, fileName, reason, groupSysId) { |
| 10 | + var gr = new GlideRecord(table); |
| 11 | + gr.initialize(); |
| 12 | + if (gr.isValidField('short_description')) |
| 13 | + gr.short_description = 'Quarantined attachment: ' + fileName; |
| 14 | + if (gr.isValidField('description')) |
| 15 | + gr.description = 'Reason: ' + reason; |
| 16 | + if (groupSysId && gr.isValidField('assignment_group')) |
| 17 | + gr.assignment_group = groupSysId; |
| 18 | + return gr.insert(); |
| 19 | + }, |
| 20 | + |
| 21 | + copyAndDelete: function(fromTable, fromSysId, toTable, toSysId, attachSysId) { |
| 22 | + var gsa = new GlideSysAttachment(); |
| 23 | + gsa.copy(fromTable, fromSysId, toTable, toSysId, attachSysId); |
| 24 | + gsa.deleteAttachment(attachSysId); |
| 25 | + }, |
| 26 | + |
| 27 | + getExt: function(fileName) { |
| 28 | + var m = String(fileName || '').match(/\.([A-Za-z0-9]+)$/); |
| 29 | + return m ? m[1].toLowerCase() : ''; |
| 30 | + }, |
| 31 | + |
| 32 | + type: 'QuarantineAttachmentUtils' |
| 33 | +}; |
0 commit comments