дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
Plugin API 1.21 adds Database tool window context menus for data sources, schemas/databases and columns next to database.table.context, each item receiving the selected nodes, and database.open-console / database.open-table-data, which open the IDE's Query Console (SQL filled in, not run) or a table's data grid from a command the user invoked, after checking the source exists and the database capability is granted. The plugin UI reaches the Database feature through a new DatabaseService in the workbench contributions rather than importing it. Includes SDK methods and MockHost helpers, a fixture plugin with a host integration test, UI tests, regenerated bindings, rebuilt plugin components and README notes. Co-authored-by: RuyimgByCN <[email protected]>
30 рядки
1.4 KiB
Rust
30 рядки
1.4 KiB
Rust
use openidea_plugin::{DatabaseTableRef, Error, host, mock::MockHost};
|
|
|
|
#[test]
|
|
fn open_console_and_table_data_enforce_grants_and_trust() {
|
|
let table =
|
|
DatabaseTableRef { source_id: "primary".into(), catalog: None, schema: "public".into(), table: "users".into() };
|
|
|
|
let mock = MockHost::install().with_capabilities(&["project.read"]);
|
|
mock.set_project_root(Some("/project"));
|
|
let p = host::projects().unwrap().remove(0);
|
|
assert!(matches!(p.database_open_console("primary", None, None), Err(Error::Denied(_))));
|
|
assert!(matches!(p.database_open_table_data(&table), Err(Error::Denied(_))));
|
|
|
|
let mock = MockHost::install().with_capabilities(&["database.schema", "database.query", "project.read"]);
|
|
mock.set_project_root(Some("/project"));
|
|
let p = host::projects().unwrap().remove(0);
|
|
mock.set_restricted(true);
|
|
assert!(matches!(p.database_open_console("primary", None, None), Err(Error::Denied(_))));
|
|
assert!(matches!(p.database_open_table_data(&table), Err(Error::Denied(_))));
|
|
|
|
mock.set_restricted(false);
|
|
p.database_open_console("primary", Some("SELECT 1"), Some("public")).unwrap();
|
|
p.database_open_table_data(&table).unwrap();
|
|
assert_eq!(
|
|
mock.opened_db_consoles(),
|
|
vec![("/project".into(), "primary".into(), Some("SELECT 1".into()), Some("public".into()))]
|
|
);
|
|
assert_eq!(mock.opened_db_tables(), vec![("/project".into(), table)]);
|
|
}
|