Skip to content

Commit 424ccce

Browse files
committed
Added disable/enable to remaining objects
1 parent ad41cc9 commit 424ccce

26 files changed

+659
-32
lines changed

src/backend/internal/dead-host.js

+102-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const internalDeadHost = {
103103
/**
104104
* @param {Access} access
105105
* @param {Object} data
106-
* @param {Integer} data.id
106+
* @param {Number} data.id
107107
* @return {Promise}
108108
*/
109109
update: (access, data) => {
@@ -201,7 +201,7 @@ const internalDeadHost = {
201201
/**
202202
* @param {Access} access
203203
* @param {Object} data
204-
* @param {Integer} data.id
204+
* @param {Number} data.id
205205
* @param {Array} [data.expand]
206206
* @param {Array} [data.omit]
207207
* @return {Promise}
@@ -248,7 +248,7 @@ const internalDeadHost = {
248248
/**
249249
* @param {Access} access
250250
* @param {Object} data
251-
* @param {Integer} data.id
251+
* @param {Number} data.id
252252
* @param {String} [data.reason]
253253
* @returns {Promise}
254254
*/
@@ -290,6 +290,104 @@ const internalDeadHost = {
290290
});
291291
},
292292

293+
/**
294+
* @param {Access} access
295+
* @param {Object} data
296+
* @param {Number} data.id
297+
* @param {String} [data.reason]
298+
* @returns {Promise}
299+
*/
300+
enable: (access, data) => {
301+
return access.can('dead_hosts:update', data.id)
302+
.then(() => {
303+
return internalDeadHost.get(access, {
304+
id: data.id,
305+
expand: ['certificate', 'owner']
306+
});
307+
})
308+
.then(row => {
309+
if (!row) {
310+
throw new error.ItemNotFoundError(data.id);
311+
} else if (row.enabled) {
312+
throw new error.ValidationError('Host is already enabled');
313+
}
314+
315+
row.enabled = 1;
316+
317+
return deadHostModel
318+
.query()
319+
.where('id', row.id)
320+
.patch({
321+
enabled: 1
322+
})
323+
.then(() => {
324+
// Configure nginx
325+
return internalNginx.configure(deadHostModel, 'dead_host', row);
326+
})
327+
.then(() => {
328+
// Add to audit log
329+
return internalAuditLog.add(access, {
330+
action: 'enabled',
331+
object_type: 'dead-host',
332+
object_id: row.id,
333+
meta: _.omit(row, omissions())
334+
});
335+
});
336+
})
337+
.then(() => {
338+
return true;
339+
});
340+
},
341+
342+
/**
343+
* @param {Access} access
344+
* @param {Object} data
345+
* @param {Number} data.id
346+
* @param {String} [data.reason]
347+
* @returns {Promise}
348+
*/
349+
disable: (access, data) => {
350+
return access.can('dead_hosts:update', data.id)
351+
.then(() => {
352+
return internalDeadHost.get(access, {id: data.id});
353+
})
354+
.then(row => {
355+
if (!row) {
356+
throw new error.ItemNotFoundError(data.id);
357+
} else if (!row.enabled) {
358+
throw new error.ValidationError('Host is already disabled');
359+
}
360+
361+
row.enabled = 0;
362+
363+
return deadHostModel
364+
.query()
365+
.where('id', row.id)
366+
.patch({
367+
enabled: 0
368+
})
369+
.then(() => {
370+
// Delete Nginx Config
371+
return internalNginx.deleteConfig('dead_host', row)
372+
.then(() => {
373+
return internalNginx.reload();
374+
});
375+
})
376+
.then(() => {
377+
// Add to audit log
378+
return internalAuditLog.add(access, {
379+
action: 'disabled',
380+
object_type: 'dead-host',
381+
object_id: row.id,
382+
meta: _.omit(row, omissions())
383+
});
384+
});
385+
})
386+
.then(() => {
387+
return true;
388+
});
389+
},
390+
293391
/**
294392
* All Hosts
295393
*
@@ -338,7 +436,7 @@ const internalDeadHost = {
338436
/**
339437
* Report use
340438
*
341-
* @param {Integer} user_id
439+
* @param {Number} user_id
342440
* @param {String} visibility
343441
* @returns {Promise}
344442
*/

src/backend/internal/redirection-host.js

+102-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const internalRedirectionHost = {
103103
/**
104104
* @param {Access} access
105105
* @param {Object} data
106-
* @param {Integer} data.id
106+
* @param {Number} data.id
107107
* @return {Promise}
108108
*/
109109
update: (access, data) => {
@@ -201,7 +201,7 @@ const internalRedirectionHost = {
201201
/**
202202
* @param {Access} access
203203
* @param {Object} data
204-
* @param {Integer} data.id
204+
* @param {Number} data.id
205205
* @param {Array} [data.expand]
206206
* @param {Array} [data.omit]
207207
* @return {Promise}
@@ -248,7 +248,7 @@ const internalRedirectionHost = {
248248
/**
249249
* @param {Access} access
250250
* @param {Object} data
251-
* @param {Integer} data.id
251+
* @param {Number} data.id
252252
* @param {String} [data.reason]
253253
* @returns {Promise}
254254
*/
@@ -290,6 +290,104 @@ const internalRedirectionHost = {
290290
});
291291
},
292292

293+
/**
294+
* @param {Access} access
295+
* @param {Object} data
296+
* @param {Number} data.id
297+
* @param {String} [data.reason]
298+
* @returns {Promise}
299+
*/
300+
enable: (access, data) => {
301+
return access.can('redirection_hosts:update', data.id)
302+
.then(() => {
303+
return internalRedirectionHost.get(access, {
304+
id: data.id,
305+
expand: ['certificate', 'owner']
306+
});
307+
})
308+
.then(row => {
309+
if (!row) {
310+
throw new error.ItemNotFoundError(data.id);
311+
} else if (row.enabled) {
312+
throw new error.ValidationError('Host is already enabled');
313+
}
314+
315+
row.enabled = 1;
316+
317+
return redirectionHostModel
318+
.query()
319+
.where('id', row.id)
320+
.patch({
321+
enabled: 1
322+
})
323+
.then(() => {
324+
// Configure nginx
325+
return internalNginx.configure(redirectionHostModel, 'redirection_host', row);
326+
})
327+
.then(() => {
328+
// Add to audit log
329+
return internalAuditLog.add(access, {
330+
action: 'enabled',
331+
object_type: 'redirection-host',
332+
object_id: row.id,
333+
meta: _.omit(row, omissions())
334+
});
335+
});
336+
})
337+
.then(() => {
338+
return true;
339+
});
340+
},
341+
342+
/**
343+
* @param {Access} access
344+
* @param {Object} data
345+
* @param {Number} data.id
346+
* @param {String} [data.reason]
347+
* @returns {Promise}
348+
*/
349+
disable: (access, data) => {
350+
return access.can('redirection_hosts:update', data.id)
351+
.then(() => {
352+
return internalRedirectionHost.get(access, {id: data.id});
353+
})
354+
.then(row => {
355+
if (!row) {
356+
throw new error.ItemNotFoundError(data.id);
357+
} else if (!row.enabled) {
358+
throw new error.ValidationError('Host is already disabled');
359+
}
360+
361+
row.enabled = 0;
362+
363+
return redirectionHostModel
364+
.query()
365+
.where('id', row.id)
366+
.patch({
367+
enabled: 0
368+
})
369+
.then(() => {
370+
// Delete Nginx Config
371+
return internalNginx.deleteConfig('redirection_host', row)
372+
.then(() => {
373+
return internalNginx.reload();
374+
});
375+
})
376+
.then(() => {
377+
// Add to audit log
378+
return internalAuditLog.add(access, {
379+
action: 'disabled',
380+
object_type: 'redirection-host',
381+
object_id: row.id,
382+
meta: _.omit(row, omissions())
383+
});
384+
});
385+
})
386+
.then(() => {
387+
return true;
388+
});
389+
},
390+
293391
/**
294392
* All Hosts
295393
*
@@ -338,7 +436,7 @@ const internalRedirectionHost = {
338436
/**
339437
* Report use
340438
*
341-
* @param {Integer} user_id
439+
* @param {Number} user_id
342440
* @param {String} visibility
343441
* @returns {Promise}
344442
*/

0 commit comments

Comments
 (0)