summaryrefslogtreecommitdiffstats
path: root/ui/imports/api/scheduled-scans/scheduled-scans.js
blob: 54d4565c7e16a55a049832a2e2b655b344db5bc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import { Constants } from '/imports/api/constants/constants';
import * as R from 'ramda';

export const ScheduledScans = new Mongo.Collection('scheduled_scans', { idGeneration: 'MONGO' });

export const scansOnlyFields = ['scan_only_inventory', 'scan_only_links', 'scan_only_cliques'];

let schema = new SimpleSchema({
  _id: { type: { _str: { type: String, regEx: SimpleSchema.RegEx.Id } } },
  environment: { 
    type: String 
  }, 
  object_id: {
    type: String,
    optional: true,
  },
  log_level: {
    type: String,
    defaultValue: 'warning', 
    custom: function () {
      let that = this;
      let logLevels = Constants.findOne({ name: 'log_levels' }).data;

      if (R.isNil(R.find(R.propEq('value', that.value), logLevels))) {
        return 'notAllowed';
      }
    },
  },
  clear: {
    type: Boolean,
    defaultValue: true, 
  },
  scan_only_inventory: {
    type: Boolean,
    defaultValue: true,
  },
  scan_only_links: {
    type: Boolean,
    defaultValue: false,
  },
  scan_only_cliques: {
    type: Boolean,
    defaultValue: false,
  },
  freq: {
    type: String,
    defaultValue: 'WEEKLY',
  },
  submit_timestamp: {
    type: Date,
    defaultValue: null
  },
  scheduled_timestamp: {
    type: Date,
    defaultValue: null,
    optional: true,
  }
});

schema.addValidator(function () {
  let that = this;
  let currentScansOnlyFields = 
    R.reject( f => that.field(f).value == false, scansOnlyFields);

  if(currentScansOnlyFields.length > 1) {
    throw {
      isError: true,
      type: 'conflict',
      data: currentScansOnlyFields,
      message: `Only one of the scan only fields can be selected. ${R.toString(currentScansOnlyFields)}`
    };
  }
});

ScheduledScans.schema = schema;
ScheduledScans.attachSchema(ScheduledScans.schema);

export const subsScheduledScansPageAmountSorted = 'scheduled_scans?page&amount&sortField&sortDirection';
export const subsScheduledScansPageAmountSortedCounter = `${subsScheduledScansPageAmountSorted}!counter`;

export const subsScheduledScansId = 'scheduled_scans?_id';