Access and entity words are core constants: access::*, entity::*
"owner"/"edit"/"view" and the entity names "note"/"label"/"attachment"/"preview" were literals at about thirty sites across store, pull and push, including match arms whose spelling had to agree with the rows a different module wrote. models::access and models::entity now name them, and push names its two ops. SQL text keeps its literals; Rust-side comparisons and writes read the constants. DRY pass #2, batch 2, F7 (#5372). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+11
-11
@@ -226,7 +226,7 @@ fn permission_of(conn: &Connection, id: &str) -> rusqlite::Result<String> {
|
||||
/// The note's text may change here: it is ours, or shared with us to edit.
|
||||
fn require_text(conn: &Connection, id: &str) -> rusqlite::Result<String> {
|
||||
let permission = permission_of(conn, id)?;
|
||||
if permission == "view" {
|
||||
if permission == access::VIEW {
|
||||
return Err(refuse(VIEW_ONLY));
|
||||
}
|
||||
Ok(permission)
|
||||
@@ -236,8 +236,8 @@ fn require_text(conn: &Connection, id: &str) -> rusqlite::Result<String> {
|
||||
/// owner.
|
||||
fn require_owner(conn: &Connection, id: &str) -> rusqlite::Result<()> {
|
||||
match permission_of(conn, id)?.as_str() {
|
||||
"owner" => Ok(()),
|
||||
"view" => Err(refuse(VIEW_ONLY)),
|
||||
access::OWNER => Ok(()),
|
||||
access::VIEW => Err(refuse(VIEW_ONLY)),
|
||||
_ => Err(refuse(OWNER_ONLY)),
|
||||
}
|
||||
}
|
||||
@@ -592,7 +592,7 @@ pub fn update_note(conn: &Connection, id: &str, changes: &Value) -> rusqlite::Re
|
||||
} else {
|
||||
permission_of(conn, id)?
|
||||
};
|
||||
let owned = permission == "owner";
|
||||
let owned = permission == access::OWNER;
|
||||
if !owned
|
||||
&& obj
|
||||
.keys()
|
||||
@@ -867,7 +867,7 @@ pub fn delete_attachment(conn: &Connection, id: &str, att_id: &str) -> rusqlite:
|
||||
// Only a file the server holds needs a tombstone; without one the next pull would
|
||||
// bring it straight back. One still waiting to upload leaves the queue with its row.
|
||||
if uploaded == Some(true) {
|
||||
record_pending_delete(conn, "attachment", att_id)?;
|
||||
record_pending_delete(conn, entity::ATTACHMENT, att_id)?;
|
||||
}
|
||||
touch(conn, id)?;
|
||||
load_note(conn, id)
|
||||
@@ -881,7 +881,7 @@ pub fn delete_preview(conn: &Connection, id: &str, preview_id: &str) -> rusqlite
|
||||
)?;
|
||||
// Previews are made by the server, so every one it has is one it would send back.
|
||||
if removed > 0 {
|
||||
record_pending_delete(conn, "preview", preview_id)?;
|
||||
record_pending_delete(conn, entity::PREVIEW, preview_id)?;
|
||||
}
|
||||
touch(conn, id)?;
|
||||
load_note(conn, id)
|
||||
@@ -932,11 +932,11 @@ pub fn delete_forever(conn: &Connection, id: &str) -> rusqlite::Result<()> {
|
||||
// is someone else's is not ours to delete.
|
||||
if permission_of(conn, id)
|
||||
.optional()?
|
||||
.is_some_and(|p| p != "owner")
|
||||
.is_some_and(|p| p != access::OWNER)
|
||||
{
|
||||
return Err(refuse(OWNER_ONLY));
|
||||
}
|
||||
record_pending_delete(conn, "note", id)?;
|
||||
record_pending_delete(conn, entity::NOTE, id)?;
|
||||
conn.execute("DELETE FROM notes WHERE id = ?1", [id])?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -990,7 +990,7 @@ pub fn revisions(conn: &Connection, id: &str) -> rusqlite::Result<Vec<NoteRevisi
|
||||
}
|
||||
|
||||
pub fn restore_revision(conn: &Connection, id: &str, rev_id: &str) -> rusqlite::Result<Note> {
|
||||
let owned = require_text(conn, id)? == "owner";
|
||||
let owned = require_text(conn, id)? == access::OWNER;
|
||||
let body: String = conn.query_row(
|
||||
"SELECT body FROM note_revisions WHERE id = ?1 AND note_id = ?2",
|
||||
params![rev_id, id],
|
||||
@@ -1105,7 +1105,7 @@ pub fn set_label_color(conn: &Connection, id: &str, color: &str) -> rusqlite::Re
|
||||
}
|
||||
|
||||
pub fn remove_label(conn: &Connection, id: &str) -> rusqlite::Result<()> {
|
||||
record_pending_delete(conn, "label", id)?;
|
||||
record_pending_delete(conn, entity::LABEL, id)?;
|
||||
conn.execute("DELETE FROM labels WHERE id = ?1", [id])?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -1129,7 +1129,7 @@ pub fn merge_labels(
|
||||
WHERE id IN (SELECT note_id FROM note_labels WHERE label_id = ?1)",
|
||||
[source_id],
|
||||
)?;
|
||||
record_pending_delete(conn, "label", source_id)?;
|
||||
record_pending_delete(conn, entity::LABEL, source_id)?;
|
||||
conn.execute("DELETE FROM labels WHERE id = ?1", [source_id])?;
|
||||
load_label(conn, target_id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user