From b0ef948585967ecdb7334bad39338e503993756b Mon Sep 17 00:00:00 2001 From: Tim Raymond Date: Wed, 14 Jun 2017 16:30:47 -0400 Subject: [PATCH] Remove system databases from "Write Data" dropdown Users should not write to _internal, or generally any other database preceeded with an '_', as we take that to mean a system-internal database of some kind. This filters the list of databases to remove those with names preceeded by a '_' character. Also 'SHOW DATABASES' can return an error if users are not authorized to do that, so it's important to throw that so it can be properly handled / displayed to the user. --- ui/src/shared/components/DatabaseDropdown.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ui/src/shared/components/DatabaseDropdown.js b/ui/src/shared/components/DatabaseDropdown.js index 7f9fdf135..d9d9efea0 100644 --- a/ui/src/shared/components/DatabaseDropdown.js +++ b/ui/src/shared/components/DatabaseDropdown.js @@ -43,12 +43,18 @@ class DatabaseDropdown extends Component { const proxy = source.links.proxy try { const {data} = await showDatabases(proxy) - const {databases} = showDatabasesParser(data) + const {databases, errors} = showDatabasesParser(data) + if (errors.length > 0) { + throw errors[0] // only one error can come back from this, but it's returned as an array + } - this.setState({databases}) - const selectedDatabaseText = databases.includes(database) + // system databases are those preceded with an '_' + const nonSystemDatabases = databases.filter((name) => name[0] !== '_') + + this.setState({databases: nonSystemDatabases}) + const selectedDatabaseText = nonSystemDatabases.includes(database) ? database - : databases[0] || 'No databases' + : nonSystemDatabases[0] || 'No databases' onSelectDatabase({text: selectedDatabaseText}) } catch (error) { console.error(error)