WIP: complete control of new passthrough host type
This commit is contained in:
@ -206,14 +206,21 @@ const internalHost = {
|
||||
|
||||
if (existing_rows && existing_rows.length) {
|
||||
existing_rows.map(function (existing_row) {
|
||||
existing_row.domain_names.map(function (existing_hostname) {
|
||||
|
||||
function checkHostname(existing_hostname) {
|
||||
// Does this domain match?
|
||||
if (existing_hostname.toLowerCase() === hostname.toLowerCase()) {
|
||||
if (!ignore_id || ignore_id !== existing_row.id) {
|
||||
is_taken = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (existing_row.domain_names) {
|
||||
existing_row.domain_names.map(checkHostname);
|
||||
} else if (existing_row.domain_name) {
|
||||
checkHostname(existing_row.domain_name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -236,8 +236,8 @@ const internalNginx = {
|
||||
host = {
|
||||
all_passthrough_hosts: allHosts.map((host) => {
|
||||
// Replace dots in domain
|
||||
host.escaped_name = host.domain_name.replace(/\./, '_');
|
||||
host.forwarding_host = internalNginx.addIpv6Brackets(host.forwarding_host);
|
||||
return host;
|
||||
}),
|
||||
}
|
||||
} else {
|
||||
|
@ -19,20 +19,12 @@ const internalPassthroughHost = {
|
||||
create: (access, data) => {
|
||||
return access.can('ssl_passthrough_hosts:create', data)
|
||||
.then(() => {
|
||||
// Get a list of the domain names and check each of them against existing records
|
||||
let domain_name_check_promises = [];
|
||||
|
||||
data.domain_names.map(function (domain_name) {
|
||||
domain_name_check_promises.push(internalHost.isHostnameTaken(domain_name));
|
||||
});
|
||||
|
||||
return Promise.all(domain_name_check_promises)
|
||||
.then((check_results) => {
|
||||
check_results.map(function (result) {
|
||||
if (result.is_taken) {
|
||||
throw new error.ValidationError(result.hostname + ' is already in use');
|
||||
}
|
||||
});
|
||||
// Get the domain name and check it against existing records
|
||||
return internalHost.isHostnameTaken(data.domain_name)
|
||||
.then((result) => {
|
||||
if (result.is_taken) {
|
||||
throw new error.ValidationError(result.hostname + ' is already in use');
|
||||
}
|
||||
});
|
||||
}).then((/*access_data*/) => {
|
||||
data.owner_user_id = access.token.getUserId(1);
|
||||
@ -57,7 +49,7 @@ const internalPassthroughHost = {
|
||||
// Add to audit log
|
||||
return internalAuditLog.add(access, {
|
||||
action: 'created',
|
||||
object_type: 'ssl_passthrough_host',
|
||||
object_type: 'ssl-passthrough-host',
|
||||
object_id: row.id,
|
||||
meta: data
|
||||
})
|
||||
@ -76,21 +68,13 @@ const internalPassthroughHost = {
|
||||
update: (access, data) => {
|
||||
return access.can('ssl_passthrough_hosts:update', data.id)
|
||||
.then((/*access_data*/) => {
|
||||
// Get a list of the domain names and check each of them against existing records
|
||||
let domain_name_check_promises = [];
|
||||
|
||||
if (typeof data.domain_names !== 'undefined') {
|
||||
data.domain_names.map(function (domain_name) {
|
||||
domain_name_check_promises.push(internalHost.isHostnameTaken(domain_name, 'ssl_passthrough', data.id));
|
||||
});
|
||||
|
||||
return Promise.all(domain_name_check_promises)
|
||||
.then((check_results) => {
|
||||
check_results.map(function (result) {
|
||||
if (result.is_taken) {
|
||||
throw new error.ValidationError(result.hostname + ' is already in use');
|
||||
}
|
||||
});
|
||||
// Get the domain name and check it against existing records
|
||||
if (typeof data.domain_name !== 'undefined') {
|
||||
return internalHost.isHostnameTaken(data.domain_name, 'ssl_passthrough', data.id)
|
||||
.then((result) => {
|
||||
if (result.is_taken) {
|
||||
throw new error.ValidationError(result.hostname + ' is already in use');
|
||||
}
|
||||
});
|
||||
}
|
||||
}).then((/*access_data*/) => {
|
||||
@ -116,7 +100,7 @@ const internalPassthroughHost = {
|
||||
// Add to audit log
|
||||
return internalAuditLog.add(access, {
|
||||
action: 'updated',
|
||||
object_type: 'ssl_passthrough_host',
|
||||
object_type: 'ssl-passthrough-host',
|
||||
object_id: row.id,
|
||||
meta: data
|
||||
})
|
||||
@ -207,7 +191,7 @@ const internalPassthroughHost = {
|
||||
// Add to audit log
|
||||
return internalAuditLog.add(access, {
|
||||
action: 'deleted',
|
||||
object_type: 'ssl_passthrough_host',
|
||||
object_type: 'ssl-passthrough-host',
|
||||
object_id: row.id,
|
||||
meta: _.omit(row, omissions())
|
||||
});
|
||||
@ -256,7 +240,7 @@ const internalPassthroughHost = {
|
||||
// Add to audit log
|
||||
return internalAuditLog.add(access, {
|
||||
action: 'enabled',
|
||||
object_type: 'ssl_passthrough_host',
|
||||
object_type: 'ssl-passthrough-host',
|
||||
object_id: row.id,
|
||||
meta: _.omit(row, omissions())
|
||||
});
|
||||
@ -305,7 +289,7 @@ const internalPassthroughHost = {
|
||||
// Add to audit log
|
||||
return internalAuditLog.add(access, {
|
||||
action: 'disabled',
|
||||
object_type: 'ssl_passthrough_host',
|
||||
object_type: 'ssl-passthrough-host',
|
||||
object_id: row.id,
|
||||
meta: _.omit(row, omissions())
|
||||
});
|
||||
|
Reference in New Issue
Block a user