| 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281 |
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
3x
1x
1x
| import Model from 'ampersand-model';
import storageMixin from 'storage-mixin';
import get from 'lodash.get';
import { format } from 'util';
import { remote } from 'electron';
/**
* The network features.
*/
const NETWORK_FEATURES = [
'enableMaps',
'trackErrors',
'enableFeedbackPanel',
'trackUsageStatistics',
'autoUpdates'
];
/**
* Represents preferences in Compass.
*/
const Preferences = Model.extend(storageMixin, {
props: {
/**
* String identifier for this set of preferences. Default is `General`.
* @type {String}
*/
id: {
type: 'string',
default: 'General',
required: true
},
/**
* Stores the last version app was run as, e.g. `1.0.5`
* @type {String}
*/
lastKnownVersion: {
type: 'string',
required: false
},
/**
* Stores whether or not the feature tour should be presented to the
* user. This is set in the migration step (./migrations/index.js).
* @type {Boolean}
*/
showFeatureTour: {
type: 'string',
required: false,
default: undefined
},
/**
* Stores whether or not the network opt-in screen has been shown to
* the user already.
* @type {String}
*/
showedNetworkOptIn: {
type: 'boolean',
required: true,
default: false
},
/**
* Stores a unique anonymous user ID (uuid) for the current user
* @type {String}
*/
currentUserId: {
type: 'string',
required: true,
default: ''
},
/** Master switch to disable all network traffic, which includes
* - Google maps
* - Bugsnag
* - Intercom
* - Google Analytics
* - Auto-updates
* @type {Boolean}
*/
networkTraffic: {
type: 'boolean',
required: true,
default: true
},
/**
* Switch to enable/disable maps rendering
* @type {Boolean}
*/
enableMaps: {
type: 'boolean',
required: true,
default: false
},
/**
* Switch to enable/disable error reports (renamed from `bugsnag`)
* @type {Boolean}
*/
trackErrors: {
type: 'boolean',
required: true,
default: false
},
/**
* Switch to enable/disable Intercom panel (renamed from `intercom`)
* @type {Boolean}
*/
enableFeedbackPanel: {
type: 'boolean',
required: true,
default: false
},
/**
* Switch to enable/disable usage statistics collection
* (renamed from `googleAnalytics`)
*
* @type {Boolean}
*/
trackUsageStatistics: {
type: 'boolean',
required: true,
default: false
},
/**
* Switch to enable/disable automatic updates
*
* @type {Boolean}
*/
autoUpdates: {
type: 'boolean',
required: true,
default: false
},
/**
* Switch to enable/disable index creation/dropping
*
* @type {Boolean}
*/
indexDDL: {
type: 'boolean',
required: true,
default: false
},
/**
* Switch to enable/disable showing the update banner notification, this
* is independent of the autoUpdates flag and will not prevent checking for
* and downloading the new versions.
*
* @type {Boolean}
*/
showAutoUpdateBanner: {
type: 'boolean',
required: true,
default: false
},
/**
* Switch to enable/disable the graphical query builder code
* @type {Boolean}
*/
queryBuilder: {
type: 'boolean',
required: true,
default: true
},
/**
* Switch to enable/disable the "Explain Plan" tab on the collection level
* @type {Boolean}
*/
showExplainPlanTab: {
type: 'boolean',
required: true,
default: false
},
/**
* Allow single document CRUD.
*/
singleDocumentCrud: {
type: 'boolean',
required: true,
default: false
},
/**
* Allow server stats.
* @type {Boolean}
*/
serverStats: {
type: 'boolean',
required: true,
default: false
},
/**
* Allow chart view.
* @type {Boolean}
*/
chartView: {
type: 'boolean',
required: true,
default: false
},
/**
* Switches to enable/disable various authentication / ssl types
*
* Warning: currently not hooked into the code, see INT-859.
*
* @type {Boolean}
*/
authMongodb: {
type: 'boolean',
required: true,
default: true
},
authKerberos: {
type: 'boolean',
required: true,
default: true
},
authLdap: {
type: 'boolean',
required: true,
default: true
},
authX509: {
type: 'boolean',
required: true,
default: false
},
sslUnvalidated: {
type: 'boolean',
required: true,
default: true
},
sslServer: {
type: 'boolean',
required: true,
default: true
},
sslAll: {
type: 'boolean',
required: true,
default: true
}
},
extraProperties: 'ignore',
idAttribute: 'id',
namespace: 'AppPreferences',
storage: {
backend: 'disk',
basepath: remote.app.getPath('userData')
},
/**
* returns whether or not a given feature is enabled. In most cases, it just
* passes through whatever property is asked for, but some checks are more
* complex, like the `disableNetworkTraffic` master switch, which overwrites
* other feature flags.
*
* @param {String} feature check for this feature
* @return {Boolean} enabled = true, disabled = false
*
* @example
* ```
* app.isFeatureEnabled('authWithKerberos')
* ```
* returns either true or false
*/
isFeatureEnabled: function(feature) {
// master network switch overwrites all network related features
if (NETWORK_FEATURES.indexOf(feature) !== -1) {
return this.networkTraffic && get(this, feature);
}
const res = get(this, feature, null);
// don't allow asking for unknown features to prevent bugs
if (res === null) {
if (feature === 'chartView') {
// COMPASS-1340 disable chartView error until moved to its own product...
return false;
}
throw new Error(format('Feature %s unknown.', feature));
}
return res;
}
});
export default Preferences;
export { Preferences };
|