Compare commits

..

No commits in common. "54a38255e6d2e25780a7df5c38bb46bfb3ab3a94" and "af86893acf94f49d40cc2b42ff15987cae21e16f" have entirely different histories.

2 changed files with 5 additions and 7 deletions

View File

@ -366,7 +366,7 @@ pub async fn edit_database_privileges(
let privileges_to_change = if !args.privs.is_empty() { let privileges_to_change = if !args.privs.is_empty() {
parse_privilege_tables_from_args(&args)? parse_privilege_tables_from_args(&args)?
} else { } else {
edit_privileges_with_editor(&privilege_data, args.name.as_deref())? edit_privileges_with_editor(&privilege_data)?
}; };
let diffs = diff_privileges(&privilege_data, &privileges_to_change); let diffs = diff_privileges(&privilege_data, &privileges_to_change);
@ -432,14 +432,13 @@ fn parse_privilege_tables_from_args(
fn edit_privileges_with_editor( fn edit_privileges_with_editor(
privilege_data: &[DatabasePrivilegeRow], privilege_data: &[DatabasePrivilegeRow],
database_name: Option<&str>,
) -> anyhow::Result<Vec<DatabasePrivilegeRow>> { ) -> anyhow::Result<Vec<DatabasePrivilegeRow>> {
let unix_user = User::from_uid(getuid()) let unix_user = User::from_uid(getuid())
.context("Failed to look up your UNIX username") .context("Failed to look up your UNIX username")
.and_then(|u| u.ok_or(anyhow::anyhow!("Failed to look up your UNIX username")))?; .and_then(|u| u.ok_or(anyhow::anyhow!("Failed to look up your UNIX username")))?;
let editor_content = let editor_content =
generate_editor_content_from_privilege_data(privilege_data, &unix_user.name, database_name); generate_editor_content_from_privilege_data(privilege_data, &unix_user.name);
// TODO: handle errors better here // TODO: handle errors better here
let result = Editor::new().extension("tsv").edit(&editor_content)?; let result = Editor::new().extension("tsv").edit(&editor_content)?;

View File

@ -157,10 +157,9 @@ const EDITOR_COMMENT: &str = r#"
pub fn generate_editor_content_from_privilege_data( pub fn generate_editor_content_from_privilege_data(
privilege_data: &[DatabasePrivilegeRow], privilege_data: &[DatabasePrivilegeRow],
unix_user: &str, unix_user: &str,
database_name: Option<&str>,
) -> String { ) -> String {
let example_user = format!("{}_user", unix_user); let example_user = format!("{}_user", unix_user);
let example_db = database_name.unwrap_or(&format!("{}_db", unix_user)).to_string(); let example_db = format!("{}_db", unix_user);
// NOTE: `.max()`` fails when the iterator is empty. // NOTE: `.max()`` fails when the iterator is empty.
// In this case, we know that the only fields in the // In this case, we know that the only fields in the
@ -540,7 +539,7 @@ pub fn display_privilege_diffs(diffs: &BTreeSet<DatabasePrivilegesDiff>) -> Stri
table.add_row(row![ table.add_row(row![
p.db, p.db,
p.user, p.user,
"(Previously unprivileged)\n".to_string() + &display_new_privileges_list(p) "(New user)\n".to_string() + &display_new_privileges_list(p)
]); ]);
} }
DatabasePrivilegesDiff::Modified(p) => { DatabasePrivilegesDiff::Modified(p) => {
@ -665,7 +664,7 @@ mod tests {
}, },
]; ];
let content = generate_editor_content_from_privilege_data(&permissions, "user", None); let content = generate_editor_content_from_privilege_data(&permissions, "user");
let parsed_permissions = parse_privilege_data_from_editor_content(content).unwrap(); let parsed_permissions = parse_privilege_data_from_editor_content(content).unwrap();