mirror of
https://github.com/vrana/adminer.git
synced 2025-08-29 09:10:09 +02:00
Add support for "where" field privilege
In Elasticsearch, only indexed fields are searchable.
This commit is contained in:
@@ -380,7 +380,12 @@ if (isset($_GET["elastic"])) {
|
||||
"field" => $name,
|
||||
"full_type" => $field["type"],
|
||||
"type" => $field["type"],
|
||||
"privileges" => array("insert" => 1, "select" => 1, "update" => 1),
|
||||
"privileges" => array(
|
||||
"insert" => 1,
|
||||
"select" => 1,
|
||||
"update" => 1,
|
||||
"where" => !isset($field["index"]) || $field["index"] ?: null,
|
||||
),
|
||||
);
|
||||
if ($field["properties"]) { // only leaf fields can be edited
|
||||
unset($return[$name]["privileges"]["insert"]);
|
||||
|
@@ -463,6 +463,7 @@ if (isset($_GET["mongo"])) {
|
||||
"insert" => 1,
|
||||
"select" => 1,
|
||||
"update" => 1,
|
||||
"where" => 1,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@@ -387,7 +387,7 @@ WHERE o.schema_id = SCHEMA_ID(" . q(get_schema()) . ") AND o.type IN ('S', 'U',
|
||||
"null" => $row["is_nullable"],
|
||||
"auto_increment" => $row["is_identity"],
|
||||
"collation" => $row["collation_name"],
|
||||
"privileges" => array("insert" => 1, "select" => 1, "update" => 1),
|
||||
"privileges" => array("insert" => 1, "select" => 1, "update" => 1, "where" => 1),
|
||||
"primary" => $row["is_identity"], //! or indexes.is_primary_key
|
||||
"comment" => $comments[$row["name"]],
|
||||
);
|
||||
|
@@ -551,7 +551,7 @@ if (!defined("DRIVER")) {
|
||||
"auto_increment" => ($row["Extra"] == "auto_increment"),
|
||||
"on_update" => (preg_match('~^on update (.+)~i', $row["Extra"], $match) ? $match[1] : ""), //! available since MySQL 5.1.23
|
||||
"collation" => $row["Collation"],
|
||||
"privileges" => array_flip(preg_split('~, *~', $row["Privileges"])),
|
||||
"privileges" => array_flip(preg_split('~, *~', $row["Privileges"])) + ["where" => 1],
|
||||
"comment" => $row["Comment"],
|
||||
"primary" => ($row["Key"] == "PRI"),
|
||||
// https://mariadb.com/kb/en/library/show-columns/, https://github.com/vrana/adminer/pull/359#pullrequestreview-276677186
|
||||
|
@@ -297,7 +297,7 @@ ORDER BY 1"
|
||||
"null" => ($row["NULLABLE"] == "Y"),
|
||||
//! "auto_increment" => false,
|
||||
//! "collation" => $row["CHARACTER_SET_NAME"],
|
||||
"privileges" => array("insert" => 1, "select" => 1, "update" => 1),
|
||||
"privileges" => array("insert" => 1, "select" => 1, "update" => 1, "where" => 1),
|
||||
//! "comment" => $row["Comment"],
|
||||
//! "primary" => ($row["Key"] == "PRI"),
|
||||
);
|
||||
|
@@ -321,7 +321,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||
"full_type" => $type,
|
||||
"default" => (preg_match("~'(.*)'~", $default, $match) ? str_replace("''", "'", $match[1]) : ($default == "NULL" ? null : $default)),
|
||||
"null" => !$row["notnull"],
|
||||
"privileges" => array("select" => 1, "insert" => 1, "update" => 1),
|
||||
"privileges" => array("select" => 1, "insert" => 1, "update" => 1, "where" => 1),
|
||||
"primary" => $row["pk"],
|
||||
);
|
||||
if ($row["pk"]) {
|
||||
|
@@ -561,7 +561,8 @@ class Adminer {
|
||||
// find anywhere
|
||||
$cols = array();
|
||||
foreach ($fields as $name => $field) {
|
||||
if ((preg_match('~^[-\d.' . (preg_match('~IN$~', $val["op"]) ? ',' : '') . ']+$~', $val["val"]) || !preg_match('~' . number_type() . '|bit~', $field["type"]))
|
||||
if (isset($field["privileges"]["where"])
|
||||
&& (preg_match('~^[-\d.' . (preg_match('~IN$~', $val["op"]) ? ',' : '') . ']+$~', $val["val"]) || !preg_match('~' . number_type() . '|bit~', $field["type"]))
|
||||
&& (!preg_match("~[\x80-\xFF]~", $val["val"]) || preg_match('~char|text|enum|set~', $field["type"]))
|
||||
&& (!preg_match('~date|timestamp~', $field["type"]) || preg_match('~^\d+-\d+-\d+~', $val["val"]))
|
||||
) {
|
||||
|
@@ -1077,7 +1077,7 @@ function fields_from_edit() {
|
||||
$name = bracket_escape($key, 1); // 1 - back
|
||||
$return[$name] = array(
|
||||
"field" => $name,
|
||||
"privileges" => array("insert" => 1, "update" => 1),
|
||||
"privileges" => array("insert" => 1, "update" => 1, "where" => 1),
|
||||
"null" => 1,
|
||||
"auto_increment" => ($key == $driver->primary),
|
||||
);
|
||||
|
@@ -9,6 +9,7 @@ parse_str($_COOKIE["adminer_import"], $adminer_import);
|
||||
|
||||
$rights = array(); // privilege => 0
|
||||
$columns = array(); // selectable columns
|
||||
$search_columns = array(); // searchable columns
|
||||
$text_length = null;
|
||||
foreach ($fields as $key => $field) {
|
||||
$name = $adminer->fieldName($field);
|
||||
@@ -18,6 +19,9 @@ foreach ($fields as $key => $field) {
|
||||
$text_length = $adminer->selectLengthProcess();
|
||||
}
|
||||
}
|
||||
if (isset($field["privileges"]["where"]) && $name != "") {
|
||||
$search_columns[$key] = html_entity_decode(strip_tags($name), ENT_QUOTES);
|
||||
}
|
||||
$rights += $field["privileges"];
|
||||
}
|
||||
|
||||
@@ -245,7 +249,7 @@ if (!$columns && support("table")) {
|
||||
echo '<input type="hidden" name="select" value="' . h($TABLE) . '">';
|
||||
echo "</div>\n";
|
||||
$adminer->selectColumnsPrint($select, $columns);
|
||||
$adminer->selectSearchPrint($where, $columns, $indexes);
|
||||
$adminer->selectSearchPrint($where, $search_columns, $indexes);
|
||||
$adminer->selectOrderPrint($order, $columns, $indexes);
|
||||
$adminer->selectLimitPrint($limit);
|
||||
$adminer->selectLengthPrint($text_length);
|
||||
@@ -336,7 +340,7 @@ if (!$columns && support("table")) {
|
||||
echo apply_sql_function($val["fun"], $name) . "</a>"; //! columns looking like functions
|
||||
echo "<span class='column hidden'>";
|
||||
echo "<a href='" . h($href . $desc) . "' title='" . lang('descending') . "' class='text'> ↓</a>";
|
||||
if (!$val["fun"]) {
|
||||
if (!$val["fun"] && isset($field["privileges"]["where"])) {
|
||||
echo '<a href="#fieldset-search" title="' . lang('Search') . '" class="text jsonly"> =</a>';
|
||||
echo script("qsl('a').onclick = partial(selectSearch, '" . js_escape($key) . "');");
|
||||
}
|
||||
|
@@ -344,7 +344,7 @@ if (isset($_GET["clickhouse"])) {
|
||||
"default" => trim($row['default_expression']),
|
||||
"null" => $nullable,
|
||||
"auto_increment" => '0',
|
||||
"privileges" => array("insert" => 1, "select" => 1, "update" => 0),
|
||||
"privileges" => array("insert" => 1, "select" => 1, "update" => 0, "where" => 1),
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -250,7 +250,7 @@ ORDER BY r.RDB$FIELD_POSITION';
|
||||
"null" => (trim($row["FIELD_NOT_NULL_CONSTRAINT"]) == "YES"),
|
||||
"auto_increment" => '0',
|
||||
"collation" => trim($row["FIELD_COLLATION"]),
|
||||
"privileges" => array("insert" => 1, "select" => 1, "update" => 1),
|
||||
"privileges" => array("insert" => 1, "select" => 1, "update" => 1, "where" => 1),
|
||||
"comment" => trim($row["FIELD_DESCRIPTION"]),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user