summaryrefslogtreecommitdiffstats
path: root/rust/src
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/auth.rs16
-rw-r--r--rust/src/bin/fatcat-auth.rs8
-rw-r--r--rust/src/bin/fatcat-export.rs8
-rw-r--r--rust/src/editing.rs18
-rw-r--r--rust/src/endpoint_handlers.rs32
-rw-r--r--rust/src/endpoints.rs34
-rw-r--r--rust/src/entity_crud.rs130
-rw-r--r--rust/src/identifiers.rs29
8 files changed, 137 insertions, 138 deletions
diff --git a/rust/src/auth.rs b/rust/src/auth.rs
index 07dfb4f6..d86e5ba8 100644
--- a/rust/src/auth.rs
+++ b/rust/src/auth.rs
@@ -32,7 +32,7 @@ pub enum FatcatRole {
#[derive(Clone)]
pub struct AuthContext {
- pub editor_id: FatCatId,
+ pub editor_id: FatcatId,
editor_row: EditorRow,
}
@@ -66,7 +66,7 @@ impl AuthContext {
}
}
- pub fn require_editgroup(&self, conn: &DbConn, editgroup_id: FatCatId) -> Result<()> {
+ pub fn require_editgroup(&self, conn: &DbConn, editgroup_id: FatcatId) -> Result<()> {
if self.has_role(FatcatRole::Admin) {
return Ok(());
}
@@ -214,7 +214,7 @@ impl AuthConfectionary {
pub fn create_token(
&self,
- editor_id: FatCatId,
+ editor_id: FatcatId,
duration: Option<chrono::Duration>,
) -> Result<String> {
let mut mac = Macaroon::create(&self.location, &self.key, &self.identifier)
@@ -264,10 +264,10 @@ impl AuthConfectionary {
}
};
let mut verifier = Verifier::new();
- let mut editor_id: Option<FatCatId> = None;
+ let mut editor_id: Option<FatcatId> = None;
for caveat in mac.first_party_caveats() {
if caveat.predicate().starts_with("editor_id = ") {
- editor_id = Some(FatCatId::from_str(caveat.predicate().get(12..).unwrap())?);
+ editor_id = Some(FatcatId::from_str(caveat.predicate().get(12..).unwrap())?);
break;
}
}
@@ -391,7 +391,7 @@ impl AuthConfectionary {
};
let editor_row = self.parse_macaroon_token(conn, &token, endpoint)?;
Ok(Some(AuthContext {
- editor_id: FatCatId::from_uuid(&editor_row.id),
+ editor_id: FatcatId::from_uuid(&editor_row.id),
editor_row,
}))
}
@@ -436,7 +436,7 @@ pub fn create_key() -> String {
BASE64.encode(&key)
}
-pub fn revoke_tokens(conn: &DbConn, editor_id: FatCatId) -> Result<()> {
+pub fn revoke_tokens(conn: &DbConn, editor_id: FatcatId) -> Result<()> {
diesel::update(editor::table.filter(editor::id.eq(&editor_id.to_uuid())))
.set(editor::auth_epoch.eq(Utc::now()))
.execute(conn)?;
@@ -459,7 +459,7 @@ pub fn print_editors(conn: &DbConn) -> Result<()> {
for e in all_editors {
println!(
"{}\t{}/{}/{}\t{}\t{}\t{:?}",
- FatCatId::from_uuid(&e.id).to_string(),
+ FatcatId::from_uuid(&e.id).to_string(),
e.is_superuser,
e.is_admin,
e.is_bot,
diff --git a/rust/src/bin/fatcat-auth.rs b/rust/src/bin/fatcat-auth.rs
index 7e2a7c39..9efd47ed 100644
--- a/rust/src/bin/fatcat-auth.rs
+++ b/rust/src/bin/fatcat-auth.rs
@@ -5,7 +5,7 @@ use clap::{App, SubCommand};
use fatcat::auth;
use fatcat::editing;
use fatcat::errors::*;
-use fatcat::identifiers::FatCatId;
+use fatcat::identifiers::FatcatId;
use fatcat::server::*;
use std::process;
use std::str::FromStr;
@@ -82,17 +82,17 @@ fn main() -> Result<()> {
subm.is_present("bot"),
)?;
//println!("{:?}", editor);
- println!("{}", FatCatId::from_uuid(&editor.id).to_string());
+ println!("{}", FatcatId::from_uuid(&editor.id).to_string());
}
("create-token", Some(subm)) => {
- let editor_id = FatCatId::from_str(subm.value_of("editor-id").unwrap())?;
+ let editor_id = FatcatId::from_str(subm.value_of("editor-id").unwrap())?;
println!("{}", confectionary.create_token(editor_id, None)?);
}
("inspect-token", Some(subm)) => {
confectionary.inspect_token(&db_conn, subm.value_of("token").unwrap())?;
}
("revoke-tokens", Some(subm)) => {
- let editor_id = FatCatId::from_str(subm.value_of("editor-id").unwrap())?;
+ let editor_id = FatcatId::from_str(subm.value_of("editor-id").unwrap())?;
fatcat::auth::revoke_tokens(&db_conn, editor_id)?;
println!("success!");
}
diff --git a/rust/src/bin/fatcat-export.rs b/rust/src/bin/fatcat-export.rs
index 157070e5..d438c00a 100644
--- a/rust/src/bin/fatcat-export.rs
+++ b/rust/src/bin/fatcat-export.rs
@@ -44,9 +44,9 @@ arg_enum! {
}
struct IdentRow {
- ident_id: FatCatId,
+ ident_id: FatcatId,
rev_id: Option<Uuid>,
- redirect_id: Option<FatCatId>,
+ redirect_id: Option<FatcatId>,
}
macro_rules! generic_loop_work {
@@ -116,14 +116,14 @@ fn parse_line(s: &str) -> Result<IdentRow> {
bail!("Invalid input line");
}
Ok(IdentRow {
- ident_id: FatCatId::from_uuid(&Uuid::from_str(&fields[0])?),
+ ident_id: FatcatId::from_uuid(&Uuid::from_str(&fields[0])?),
rev_id: match fields[1].as_ref() {
"" => None,
val => Some(Uuid::from_str(&val)?),
},
redirect_id: match fields[2].as_ref() {
"" => None,
- val => Some(FatCatId::from_uuid(&Uuid::from_str(&val)?)),
+ val => Some(FatcatId::from_uuid(&Uuid::from_str(&val)?)),
},
})
}
diff --git a/rust/src/editing.rs b/rust/src/editing.rs
index 42dd013e..6a2495c5 100644
--- a/rust/src/editing.rs
+++ b/rust/src/editing.rs
@@ -10,8 +10,8 @@ use fatcat_api_spec::models::*;
use uuid::Uuid;
pub struct EditContext {
- pub editor_id: FatCatId,
- pub editgroup_id: FatCatId,
+ pub editor_id: FatcatId,
+ pub editgroup_id: FatcatId,
pub extra_json: Option<serde_json::Value>,
pub autoaccept: bool,
}
@@ -32,20 +32,20 @@ impl EditContext {
pub fn make_edit_context(
conn: &DbConn,
- editor_id: FatCatId,
- editgroup_id: Option<FatCatId>,
+ editor_id: FatcatId,
+ editgroup_id: Option<FatcatId>,
autoaccept: bool,
) -> Result<EditContext> {
- let editgroup_id: FatCatId = match (editgroup_id, autoaccept) {
+ let editgroup_id: FatcatId = match (editgroup_id, autoaccept) {
(Some(eg), _) => eg,
// If autoaccept and no editgroup_id passed, always create a new one for this transaction
(None, true) => {
let eg_row: EditgroupRow = diesel::insert_into(editgroup::table)
.values((editgroup::editor_id.eq(editor_id.to_uuid()),))
.get_result(conn)?;
- FatCatId::from_uuid(&eg_row.id)
+ FatcatId::from_uuid(&eg_row.id)
}
- (None, false) => FatCatId::from_uuid(&create_editgroup(conn, editor_id.to_uuid())?),
+ (None, false) => FatcatId::from_uuid(&create_editgroup(conn, editor_id.to_uuid())?),
};
Ok(EditContext {
editor_id,
@@ -74,7 +74,7 @@ pub fn create_editor(
pub fn update_editor_username(
conn: &DbConn,
- editor_id: FatCatId,
+ editor_id: FatcatId,
username: String,
) -> Result<EditorRow> {
check_username(&username)?;
@@ -95,7 +95,7 @@ pub fn create_editgroup(conn: &DbConn, editor_id: Uuid) -> Result<Uuid> {
}
/// This function should always be run within a transaction
-pub fn accept_editgroup(conn: &DbConn, editgroup_id: FatCatId) -> Result<ChangelogRow> {
+pub fn accept_editgroup(conn: &DbConn, editgroup_id: FatcatId) -> Result<ChangelogRow> {
// check that we haven't accepted already (in changelog)
// NB: could leave this to a UNIQUE constraint
// TODO: redundant with check_edit_context
diff --git a/rust/src/endpoint_handlers.rs b/rust/src/endpoint_handlers.rs
index ff49f3d1..4dc528bd 100644
--- a/rust/src/endpoint_handlers.rs
+++ b/rust/src/endpoint_handlers.rs
@@ -23,8 +23,8 @@ macro_rules! entity_batch_handler {
conn: &DbConn,
entity_list: &[models::$model],
autoaccept: bool,
- editor_id: FatCatId,
- editgroup_id: Option<FatCatId>,
+ editor_id: FatcatId,
+ editgroup_id: Option<FatcatId>,
) -> Result<Vec<EntityEdit>> {
let edit_context = make_edit_context(conn, editor_id, editgroup_id, autoaccept)?;
@@ -44,7 +44,7 @@ macro_rules! entity_batch_handler {
pub fn get_release_files(
conn: &DbConn,
- ident: FatCatId,
+ ident: FatcatId,
hide_flags: HideFlags,
) -> Result<Vec<FileEntity>> {
let rows: Vec<(FileRevRow, FileIdentRow, FileRevReleaseRow)> = file_rev::table
@@ -62,7 +62,7 @@ pub fn get_release_files(
pub fn get_release_filesets(
conn: &DbConn,
- ident: FatCatId,
+ ident: FatcatId,
hide_flags: HideFlags,
) -> Result<Vec<FilesetEntity>> {
let rows: Vec<(FilesetRevRow, FilesetIdentRow, FilesetRevReleaseRow)> = fileset_rev::table
@@ -80,7 +80,7 @@ pub fn get_release_filesets(
pub fn get_release_webcaptures(
conn: &DbConn,
- ident: FatCatId,
+ ident: FatcatId,
hide_flags: HideFlags,
) -> Result<Vec<WebcaptureEntity>> {
let rows: Vec<(
@@ -178,7 +178,7 @@ impl Server {
pub fn get_creator_releases_handler(
&self,
conn: &DbConn,
- ident: FatCatId,
+ ident: FatcatId,
hide_flags: HideFlags,
) -> Result<Vec<ReleaseEntity>> {
// TODO: some kind of unique or group-by?
@@ -326,7 +326,7 @@ impl Server {
pub fn get_release_files_handler(
&self,
conn: &DbConn,
- ident: FatCatId,
+ ident: FatcatId,
hide_flags: HideFlags,
) -> Result<Vec<FileEntity>> {
get_release_files(conn, ident, hide_flags)
@@ -335,7 +335,7 @@ impl Server {
pub fn get_release_filesets_handler(
&self,
conn: &DbConn,
- ident: FatCatId,
+ ident: FatcatId,
hide_flags: HideFlags,
) -> Result<Vec<FilesetEntity>> {
get_release_filesets(conn, ident, hide_flags)
@@ -344,7 +344,7 @@ impl Server {
pub fn get_release_webcaptures_handler(
&self,
conn: &DbConn,
- ident: FatCatId,
+ ident: FatcatId,
hide_flags: HideFlags,
) -> Result<Vec<WebcaptureEntity>> {
get_release_webcaptures(conn, ident, hide_flags)
@@ -353,7 +353,7 @@ impl Server {
pub fn get_work_releases_handler(
&self,
conn: &DbConn,
- ident: FatCatId,
+ ident: FatcatId,
hide_flags: HideFlags,
) -> Result<Vec<ReleaseEntity>> {
let rows: Vec<(ReleaseRevRow, ReleaseIdentRow)> = release_rev::table
@@ -368,7 +368,7 @@ impl Server {
.collect()
}
- pub fn accept_editgroup_handler(&self, conn: &DbConn, editgroup_id: FatCatId) -> Result<()> {
+ pub fn accept_editgroup_handler(&self, conn: &DbConn, editgroup_id: FatcatId) -> Result<()> {
accept_editgroup(conn, editgroup_id)?;
Ok(())
}
@@ -380,7 +380,7 @@ impl Server {
) -> Result<Editgroup> {
let row: EditgroupRow = insert_into(editgroup::table)
.values((
- editgroup::editor_id.eq(FatCatId::from_str(&entity.editor_id.unwrap())?.to_uuid()),
+ editgroup::editor_id.eq(FatcatId::from_str(&entity.editor_id.unwrap())?.to_uuid()),
editgroup::description.eq(entity.description),
editgroup::extra_json.eq(entity.extra),
))
@@ -398,7 +398,7 @@ impl Server {
pub fn get_editgroup_handler(
&self,
conn: &DbConn,
- editgroup_id: FatCatId,
+ editgroup_id: FatcatId,
) -> Result<Editgroup> {
let row: EditgroupRow = editgroup::table.find(editgroup_id.to_uuid()).first(conn)?;
@@ -471,7 +471,7 @@ impl Server {
Ok(eg)
}
- pub fn get_editor_handler(&self, conn: &DbConn, editor_id: FatCatId) -> Result<Editor> {
+ pub fn get_editor_handler(&self, conn: &DbConn, editor_id: FatcatId) -> Result<Editor> {
let row: EditorRow = editor::table.find(editor_id.to_uuid()).first(conn)?;
Ok(row.into_model())
}
@@ -479,7 +479,7 @@ impl Server {
pub fn get_editor_changelog_handler(
&self,
conn: &DbConn,
- editor_id: FatCatId,
+ editor_id: FatcatId,
) -> Result<Vec<ChangelogEntry>> {
// TODO: single query
let editor: EditorRow = editor::table.find(editor_id.to_uuid()).first(conn)?;
@@ -528,7 +528,7 @@ impl Server {
pub fn get_changelog_entry_handler(&self, conn: &DbConn, index: i64) -> Result<ChangelogEntry> {
let cl_row: ChangelogRow = changelog::table.find(index).first(conn)?;
let editgroup =
- self.get_editgroup_handler(conn, FatCatId::from_uuid(&cl_row.editgroup_id))?;
+ self.get_editgroup_handler(conn, FatcatId::from_uuid(&cl_row.editgroup_id))?;
let mut entry = cl_row.into_model();
entry.editgroup = Some(editgroup);
diff --git a/rust/src/endpoints.rs b/rust/src/endpoints.rs
index f7f2d948..a66f5d51 100644
--- a/rust/src/endpoints.rs
+++ b/rust/src/endpoints.rs
@@ -48,7 +48,7 @@ macro_rules! wrap_entity_handlers {
let conn = self.db_pool.get().expect("db_pool error");
// No transaction for GET
let ret = match (|| {
- let entity_id = FatCatId::from_str(&ident)?;
+ let entity_id = FatcatId::from_str(&ident)?;
let hide_flags = match hide {
None => HideFlags::none(),
Some(param) => HideFlags::from_str(&param)?,
@@ -96,7 +96,7 @@ macro_rules! wrap_entity_handlers {
) -> Box<Future<Item = $post_resp, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
let ret = match conn.transaction(|| {
- let editgroup_id = FatCatId::from_str(&editgroup_id)?;
+ let editgroup_id = FatcatId::from_str(&editgroup_id)?;
let auth_context = self.auth_confectionary.require_auth(&conn, &context.auth_data, Some(stringify!($post_fn)))?;
auth_context.require_role(FatcatRole::Editor)?;
auth_context.require_editgroup(&conn, editgroup_id)?;
@@ -150,7 +150,7 @@ macro_rules! wrap_entity_handlers {
let auth_context = self.auth_confectionary.require_auth(&conn, &context.auth_data, Some(stringify!($post_batch_fn)))?;
auth_context.require_role(FatcatRole::Editor)?;
let editgroup_id = if let Some(s) = editgroup_id {
- let eg_id = FatCatId::from_str(&s)?;
+ let eg_id = FatcatId::from_str(&s)?;
auth_context.require_editgroup(&conn, eg_id)?;
Some(eg_id)
} else { None };
@@ -199,10 +199,10 @@ macro_rules! wrap_entity_handlers {
) -> Box<Future<Item = $update_resp, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
let ret = match conn.transaction(|| {
- let editgroup_id = FatCatId::from_str(&editgroup_id)?;
+ let editgroup_id = FatcatId::from_str(&editgroup_id)?;
let auth_context = self.auth_confectionary.require_auth(&conn, &context.auth_data, Some(stringify!($update_fn)))?;
auth_context.require_role(FatcatRole::Editor)?;
- let entity_id = FatCatId::from_str(&ident)?;
+ let entity_id = FatcatId::from_str(&ident)?;
auth_context.require_editgroup(&conn, editgroup_id)?;
let edit_context = make_edit_context(&conn, auth_context.editor_id, Some(editgroup_id), false)?;
edit_context.check(&conn)?;
@@ -253,10 +253,10 @@ macro_rules! wrap_entity_handlers {
) -> Box<Future<Item = $delete_resp, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
let ret = match conn.transaction(|| {
- let editgroup_id = FatCatId::from_str(&editgroup_id)?;
+ let editgroup_id = FatcatId::from_str(&editgroup_id)?;
let auth_context = self.auth_confectionary.require_auth(&conn, &context.auth_data, Some(stringify!($delete_fn)))?;
auth_context.require_role(FatcatRole::Editor)?;
- let entity_id = FatCatId::from_str(&ident)?;
+ let entity_id = FatcatId::from_str(&ident)?;
auth_context.require_editgroup(&conn, editgroup_id)?;
let edit_context = make_edit_context(&conn, auth_context.editor_id, Some(editgroup_id), false)?;
edit_context.check(&conn)?;
@@ -304,7 +304,7 @@ macro_rules! wrap_entity_handlers {
let conn = self.db_pool.get().expect("db_pool error");
// No transaction for GET?
let ret = match (|| {
- let entity_id = FatCatId::from_str(&ident)?;
+ let entity_id = FatcatId::from_str(&ident)?;
$model::db_get_history(&conn, entity_id, limit)
})() {
Ok(history) =>
@@ -409,7 +409,7 @@ macro_rules! wrap_entity_handlers {
let auth_context = self.auth_confectionary.require_auth(&conn, &context.auth_data, Some(stringify!($delete_edit_fn)))?;
auth_context.require_role(FatcatRole::Editor)?;
let edit = $model::db_get_edit(&conn, edit_id)?;
- auth_context.require_editgroup(&conn, FatCatId::from_uuid(&edit.editgroup_id))?;
+ auth_context.require_editgroup(&conn, FatcatId::from_uuid(&edit.editgroup_id))?;
$model::db_delete_edit(&conn, edit_id)
}) {
Ok(()) =>
@@ -446,8 +446,8 @@ macro_rules! wrap_entity_handlers {
let conn = self.db_pool.get().expect("db_pool error");
// No transaction for GET?
let ret = match (|| {
- let entity_id = FatCatId::from_str(&ident)?;
- let redirects: Vec<FatCatId> = $model::db_get_redirects(&conn, entity_id)?;
+ let entity_id = FatcatId::from_str(&ident)?;
+ let redirects: Vec<FatcatId> = $model::db_get_redirects(&conn, entity_id)?;
Ok(redirects.into_iter().map(|fcid| fcid.to_string()).collect())
})() {
Ok(redirects) =>
@@ -528,7 +528,7 @@ macro_rules! wrap_fcid_handler {
let conn = self.db_pool.get().expect("db_pool error");
// No transaction for GET
let ret = match (|| {
- let fcid = FatCatId::from_str(&id)?;
+ let fcid = FatcatId::from_str(&id)?;
self.$get_handler(&conn, fcid)
})() {
Ok(entity) =>
@@ -563,7 +563,7 @@ macro_rules! wrap_fcid_hide_handler {
let conn = self.db_pool.get().expect("db_pool error");
// No transaction for GET
let ret = match (|| {
- let fcid = FatCatId::from_str(&id)?;
+ let fcid = FatcatId::from_str(&id)?;
let hide_flags = match hide {
None => HideFlags::none(),
Some(param) => HideFlags::from_str(&param)?,
@@ -962,7 +962,7 @@ impl Api for Server {
&context.auth_data,
Some("update_editor"),
)?;
- let editor_id = FatCatId::from_str(&editor_id)?;
+ let editor_id = FatcatId::from_str(&editor_id)?;
// DANGER! these permissions are for username updates only!
if editor_id == auth_context.editor_id {
// self edit of username allowed
@@ -1041,7 +1041,7 @@ impl Api for Server {
) -> Box<Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
let ret = match conn.transaction(|| {
- let editgroup_id = FatCatId::from_str(&editgroup_id)?;
+ let editgroup_id = FatcatId::from_str(&editgroup_id)?;
let auth_context = self.auth_confectionary.require_auth(
&conn,
&context.auth_data,
@@ -1100,7 +1100,7 @@ impl Api for Server {
) -> Box<Future<Item = GetEditgroupResponse, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
let ret = match conn.transaction(|| {
- let editgroup_id = FatCatId::from_str(&editgroup_id)?;
+ let editgroup_id = FatcatId::from_str(&editgroup_id)?;
self.get_editgroup_handler(&conn, editgroup_id)
}) {
Ok(entity) => GetEditgroupResponse::Found(entity),
@@ -1247,7 +1247,7 @@ impl Api for Server {
let (editor, created) = self.auth_oidc_handler(&conn, params)?;
// create an auth token with 31 day duration
let token = self.auth_confectionary.create_token(
- FatCatId::from_str(&editor.editor_id.clone().unwrap())?,
+ FatcatId::from_str(&editor.editor_id.clone().unwrap())?,
Some(chrono::Duration::days(31)),
)?;
let result = AuthOidcResult { editor, token };
diff --git a/rust/src/entity_crud.rs b/rust/src/entity_crud.rs
index 81b359da..618bd2ff 100644
--- a/rust/src/entity_crud.rs
+++ b/rust/src/entity_crud.rs
@@ -49,7 +49,7 @@ where
// Generic Methods
fn from_deleted_row(ident_row: Self::IdentRow) -> Result<Self>;
- fn db_get(conn: &DbConn, ident: FatCatId, hide: HideFlags) -> Result<Self>;
+ fn db_get(conn: &DbConn, ident: FatcatId, hide: HideFlags) -> Result<Self>;
fn db_get_rev(conn: &DbConn, rev_id: Uuid, hide: HideFlags) -> Result<Self>;
fn db_expand(&mut self, conn: &DbConn, expand: ExpandFlags) -> Result<()>;
fn db_create(&self, conn: &DbConn, edit_context: &EditContext) -> Result<Self::EditRow>;
@@ -62,22 +62,22 @@ where
&self,
conn: &DbConn,
edit_context: &EditContext,
- ident: FatCatId,
+ ident: FatcatId,
) -> Result<Self::EditRow>;
fn db_delete(
conn: &DbConn,
edit_context: &EditContext,
- ident: FatCatId,
+ ident: FatcatId,
) -> Result<Self::EditRow>;
fn db_get_history(
conn: &DbConn,
- ident: FatCatId,
+ ident: FatcatId,
limit: Option<i64>,
) -> Result<Vec<EntityHistoryEntry>>;
fn db_get_edit(conn: &DbConn, edit_id: Uuid) -> Result<Self::EditRow>;
fn db_delete_edit(conn: &DbConn, edit_id: Uuid) -> Result<()>;
- fn db_get_redirects(conn: &DbConn, ident: FatCatId) -> Result<Vec<FatCatId>>;
- fn db_accept_edits(conn: &DbConn, editgroup_id: FatCatId) -> Result<u64>;
+ fn db_get_redirects(conn: &DbConn, ident: FatcatId) -> Result<Vec<FatcatId>>;
+ fn db_accept_edits(conn: &DbConn, editgroup_id: FatcatId) -> Result<u64>;
// Entity-specific Methods
fn db_from_row(
@@ -260,7 +260,7 @@ fn test_hide_flags() {
macro_rules! generic_db_get {
($ident_table:ident, $rev_table:ident) => {
- fn db_get(conn: &DbConn, ident: FatCatId, hide: HideFlags) -> Result<Self> {
+ fn db_get(conn: &DbConn, ident: FatcatId, hide: HideFlags) -> Result<Self> {
let res: Option<(Self::IdentRow, Self::RevRow)> = $ident_table::table
.find(ident.to_uuid())
.inner_join($rev_table::table)
@@ -378,7 +378,7 @@ macro_rules! generic_db_create_batch {
macro_rules! generic_db_update {
($ident_table: ident, $edit_table: ident) => {
- fn db_update(&self, conn: &DbConn, edit_context: &EditContext, ident: FatCatId) -> Result<Self::EditRow> {
+ fn db_update(&self, conn: &DbConn, edit_context: &EditContext, ident: FatcatId) -> Result<Self::EditRow> {
let current: Self::IdentRow = $ident_table::table.find(ident.to_uuid()).first(conn)?;
let no_redirect: Option<Uuid> = None;
// TODO: is this actually true? or should we allow updates in the same editgroup?
@@ -400,7 +400,7 @@ macro_rules! generic_db_update {
}
// special case: redirect to another entity
if let Some(ref redirect_ident) = self.redirect {
- let redirect_ident = FatCatId::from_str(&redirect_ident)?.to_uuid();
+ let redirect_ident = FatcatId::from_str(&redirect_ident)?.to_uuid();
if Some(redirect_ident) == current.redirect_id {
return Err(ErrorKind::OtherBadRequest(
"redundantly redirecting entity to it's current target currently isn't supported".to_string()).into());
@@ -472,7 +472,7 @@ macro_rules! generic_db_delete {
fn db_delete(
conn: &DbConn,
edit_context: &EditContext,
- ident: FatCatId,
+ ident: FatcatId,
) -> Result<Self::EditRow> {
let current: Self::IdentRow = $ident_table::table.find(ident.to_uuid()).first(conn)?;
if current.is_live != true {
@@ -508,7 +508,7 @@ macro_rules! generic_db_get_history {
($edit_table:ident) => {
fn db_get_history(
conn: &DbConn,
- ident: FatCatId,
+ ident: FatcatId,
limit: Option<i64>,
) -> Result<Vec<EntityHistoryEntry>> {
let limit = limit.unwrap_or(50); // TODO: make a static
@@ -569,12 +569,12 @@ macro_rules! generic_db_delete_edit {
macro_rules! generic_db_get_redirects {
($ident_table:ident) => {
- fn db_get_redirects(conn: &DbConn, ident: FatCatId) -> Result<Vec<FatCatId>> {
+ fn db_get_redirects(conn: &DbConn, ident: FatcatId) -> Result<Vec<FatcatId>> {
let res: Vec<Uuid> = $ident_table::table
.select($ident_table::id)
.filter($ident_table::redirect_id.eq(ident.to_uuid()))
.get_results(conn)?;
- Ok(res.iter().map(|u| FatCatId::from_uuid(u)).collect())
+ Ok(res.iter().map(|u| FatcatId::from_uuid(u)).collect())
}
};
}
@@ -619,7 +619,7 @@ macro_rules! generic_db_get_redirects {
#[allow(unused_macros)]
macro_rules! generic_db_accept_edits_batch {
($entity_name_str:expr, $ident_table:ident, $edit_table:ident) => {
- fn db_accept_edits(conn: &DbConn, editgroup_id: FatCatId) -> Result<u64> {
+ fn db_accept_edits(conn: &DbConn, editgroup_id: FatcatId) -> Result<u64> {
// NOTE: the checks and redirects can be skipped for accepts that are all inserts
// (which I guess we only know for batch inserts with auto-accept?)
@@ -701,7 +701,7 @@ macro_rules! generic_db_accept_edits_batch {
#[allow(unused_macros)]
macro_rules! generic_db_accept_edits_each {
($ident_table:ident, $edit_table:ident) => {
- fn db_accept_edits(conn: &DbConn, editgroup_id: FatCatId) -> Result<u64> {
+ fn db_accept_edits(conn: &DbConn, editgroup_id: FatcatId) -> Result<u64> {
// 1. select edit rows (in sql)
let edit_rows: Vec<Self::EditRow> = $edit_table::table
.filter($edit_table::editgroup_id.eq(&editgroup_id.to_uuid()))
@@ -777,11 +777,11 @@ impl EntityCrud for ContainerEntity {
abbrev: None,
coden: None,
state: Some(ident_row.state().unwrap().shortname()),
- ident: Some(FatCatId::from_uuid(&ident_row.id).to_string()),
+ ident: Some(FatcatId::from_uuid(&ident_row.id).to_string()),
revision: ident_row.rev_id.map(|u| u.to_string()),
redirect: ident_row
.redirect_id
- .map(|u| FatCatId::from_uuid(&u).to_string()),
+ .map(|u| FatcatId::from_uuid(&u).to_string()),
extra: None,
edit_extra: None,
})
@@ -796,8 +796,8 @@ impl EntityCrud for ContainerEntity {
let (state, ident_id, redirect_id) = match ident_row {
Some(i) => (
Some(i.state().unwrap().shortname()),
- Some(FatCatId::from_uuid(&i.id).to_string()),
- i.redirect_id.map(|u| FatCatId::from_uuid(&u).to_string()),
+ Some(FatcatId::from_uuid(&i.id).to_string()),
+ i.redirect_id.map(|u| FatcatId::from_uuid(&u).to_string()),
),
None => (None, None, None),
};
@@ -892,11 +892,11 @@ impl EntityCrud for CreatorEntity {
orcid: None,
wikidata_qid: None,
state: Some(ident_row.state().unwrap().shortname()),
- ident: Some(FatCatId::from_uuid(&ident_row.id).to_string()),
+ ident: Some(FatcatId::from_uuid(&ident_row.id).to_string()),
revision: ident_row.rev_id.map(|u| u.to_string()),
redirect: ident_row
.redirect_id
- .map(|u| FatCatId::from_uuid(&u).to_string()),
+ .map(|u| FatcatId::from_uuid(&u).to_string()),
})
}
@@ -909,8 +909,8 @@ impl EntityCrud for CreatorEntity {
let (state, ident_id, redirect_id) = match ident_row {
Some(i) => (
Some(i.state().unwrap().shortname()),
- Some(FatCatId::from_uuid(&i.id).to_string()),
- i.redirect_id.map(|u| FatCatId::from_uuid(&u).to_string()),
+ Some(FatcatId::from_uuid(&i.id).to_string()),
+ i.redirect_id.map(|u| FatcatId::from_uuid(&u).to_string()),
),
None => (None, None, None),
};
@@ -1002,11 +1002,11 @@ impl EntityCrud for FileEntity {
mimetype: None,
release_ids: None,
state: Some(ident_row.state().unwrap().shortname()),
- ident: Some(FatCatId::from_uuid(&ident_row.id).to_string()),
+ ident: Some(FatcatId::from_uuid(&ident_row.id).to_string()),
revision: ident_row.rev_id.map(|u| u.to_string()),
redirect: ident_row
.redirect_id
- .map(|u| FatCatId::from_uuid(&u).to_string()),
+ .map(|u| FatcatId::from_uuid(&u).to_string()),
extra: None,
edit_extra: None,
})
@@ -1021,8 +1021,8 @@ impl EntityCrud for FileEntity {
let (state, ident_id, redirect_id) = match ident_row {
Some(i) => (
Some(i.state().unwrap().shortname()),
- Some(FatCatId::from_uuid(&i.id).to_string()),
- i.redirect_id.map(|u| FatCatId::from_uuid(&u).to_string()),
+ Some(FatcatId::from_uuid(&i.id).to_string()),
+ i.redirect_id.map(|u| FatcatId::from_uuid(&u).to_string()),
),
None => (None, None, None),
};
@@ -1037,11 +1037,11 @@ impl EntityCrud for FileEntity {
})
.collect();
- let release_ids: Vec<FatCatId> = file_rev_release::table
+ let release_ids: Vec<FatcatId> = file_rev_release::table
.filter(file_rev_release::file_rev.eq(rev_row.id))
.get_results(conn)?
.into_iter()
- .map(|r: FileRevReleaseRow| FatCatId::from_uuid(&r.target_release_ident_id))
+ .map(|r: FileRevReleaseRow| FatcatId::from_uuid(&r.target_release_ident_id))
.collect();
Ok(FileEntity {
@@ -1104,7 +1104,7 @@ impl EntityCrud for FileEntity {
.map(|r| {
Ok(FileRevReleaseRow {
file_rev: *rev_id,
- target_release_ident_id: FatCatId::from_str(r)?.to_uuid(),
+ target_release_ident_id: FatcatId::from_str(r)?.to_uuid(),
})
})
.collect();
@@ -1175,11 +1175,11 @@ impl EntityCrud for FilesetEntity {
urls: None,
release_ids: None,
state: Some(ident_row.state().unwrap().shortname()),
- ident: Some(FatCatId::from_uuid(&ident_row.id).to_string()),
+ ident: Some(FatcatId::from_uuid(&ident_row.id).to_string()),
revision: ident_row.rev_id.map(|u| u.to_string()),
redirect: ident_row
.redirect_id
- .map(|u| FatCatId::from_uuid(&u).to_string()),
+ .map(|u| FatcatId::from_uuid(&u).to_string()),
extra: None,
edit_extra: None,
})
@@ -1194,8 +1194,8 @@ impl EntityCrud for FilesetEntity {
let (state, ident_id, redirect_id) = match ident_row {
Some(i) => (
Some(i.state().unwrap().shortname()),
- Some(FatCatId::from_uuid(&i.id).to_string()),
- i.redirect_id.map(|u| FatCatId::from_uuid(&u).to_string()),
+ Some(FatcatId::from_uuid(&i.id).to_string()),
+ i.redirect_id.map(|u| FatcatId::from_uuid(&u).to_string()),
),
None => (None, None, None),
};
@@ -1224,11 +1224,11 @@ impl EntityCrud for FilesetEntity {
})
.collect();
- let release_ids: Vec<FatCatId> = fileset_rev_release::table
+ let release_ids: Vec<FatcatId> = fileset_rev_release::table
.filter(fileset_rev_release::fileset_rev.eq(rev_row.id))
.get_results(conn)?
.into_iter()
- .map(|r: FilesetRevReleaseRow| FatCatId::from_uuid(&r.target_release_ident_id))
+ .map(|r: FilesetRevReleaseRow| FatcatId::from_uuid(&r.target_release_ident_id))
.collect();
Ok(FilesetEntity {
@@ -1321,7 +1321,7 @@ impl EntityCrud for FilesetEntity {
.map(|r| {
Ok(FilesetRevReleaseRow {
fileset_rev: *rev_id,
- target_release_ident_id: FatCatId::from_str(r)?.to_uuid(),
+ target_release_ident_id: FatcatId::from_str(r)?.to_uuid(),
})
})
.collect();
@@ -1385,11 +1385,11 @@ impl EntityCrud for WebcaptureEntity {
timestamp: None,
release_ids: None,
state: Some(ident_row.state().unwrap().shortname()),
- ident: Some(FatCatId::from_uuid(&ident_row.id).to_string()),
+ ident: Some(FatcatId::from_uuid(&ident_row.id).to_string()),
revision: ident_row.rev_id.map(|u| u.to_string()),
redirect: ident_row
.redirect_id
- .map(|u| FatCatId::from_uuid(&u).to_string()),
+ .map(|u| FatcatId::from_uuid(&u).to_string()),
extra: None,
edit_extra: None,
})
@@ -1404,8 +1404,8 @@ impl EntityCrud for WebcaptureEntity {
let (state, ident_id, redirect_id) = match ident_row {
Some(i) => (
Some(i.state().unwrap().shortname()),
- Some(FatCatId::from_uuid(&i.id).to_string()),
- i.redirect_id.map(|u| FatCatId::from_uuid(&u).to_string()),
+ Some(FatcatId::from_uuid(&i.id).to_string()),
+ i.redirect_id.map(|u| FatcatId::from_uuid(&u).to_string()),
),
None => (None, None, None),
};
@@ -1435,11 +1435,11 @@ impl EntityCrud for WebcaptureEntity {
})
.collect();
- let release_ids: Vec<FatCatId> = webcapture_rev_release::table
+ let release_ids: Vec<FatcatId> = webcapture_rev_release::table
.filter(webcapture_rev_release::webcapture_rev.eq(rev_row.id))
.get_results(conn)?
.into_iter()
- .map(|r: WebcaptureRevReleaseRow| FatCatId::from_uuid(&r.target_release_ident_id))
+ .map(|r: WebcaptureRevReleaseRow| FatcatId::from_uuid(&r.target_release_ident_id))
.collect();
Ok(WebcaptureEntity {
@@ -1539,7 +1539,7 @@ impl EntityCrud for WebcaptureEntity {
.map(|r| {
Ok(WebcaptureRevReleaseRow {
webcapture_rev: *rev_id,
- target_release_ident_id: FatCatId::from_str(r)?.to_uuid(),
+ target_release_ident_id: FatcatId::from_str(r)?.to_uuid(),
})
})
.collect();
@@ -1621,11 +1621,11 @@ impl EntityCrud for ReleaseEntity {
abstracts: None,
state: Some(ident_row.state().unwrap().shortname()),
- ident: Some(FatCatId::from_uuid(&ident_row.id).to_string()),
+ ident: Some(FatcatId::from_uuid(&ident_row.id).to_string()),
revision: ident_row.rev_id.map(|u| u.to_string()),
redirect: ident_row
.redirect_id
- .map(|u| FatCatId::from_uuid(&u).to_string()),
+ .map(|u| FatcatId::from_uuid(&u).to_string()),
extra: None,
edit_extra: None,
})
@@ -1645,8 +1645,8 @@ impl EntityCrud for ReleaseEntity {
Some(ident) => match &self.redirect {
// If we're a redirect, then expand for the *target* identifier, not *our*
// identifier. Tricky!
- None => FatCatId::from_str(&ident)?,
- Some(redir) => FatCatId::from_str(&redir)?,
+ None => FatcatId::from_str(&ident)?,
+ Some(redir) => FatcatId::from_str(&redir)?,
},
};
self.files = Some(get_release_files(conn, ident, HideFlags::none())?);
@@ -1655,7 +1655,7 @@ impl EntityCrud for ReleaseEntity {
if let Some(ref cid) = self.container_id {
self.container = Some(ContainerEntity::db_get(
conn,
- FatCatId::from_str(&cid)?,
+ FatcatId::from_str(&cid)?,
HideFlags::none(),
)?);
}
@@ -1666,7 +1666,7 @@ impl EntityCrud for ReleaseEntity {
if let Some(ref creator_id) = contrib.creator_id {
contrib.creator = Some(CreatorEntity::db_get(
conn,
- FatCatId::from_str(creator_id)?,
+ FatcatId::from_str(creator_id)?,
HideFlags::none(),
)?);
}
@@ -1731,7 +1731,7 @@ impl EntityCrud for ReleaseEntity {
let mut model = (*model).clone();
if model.work_id.is_none() {
model.work_id =
- Some(FatCatId::from_uuid(&new_work_ids.pop().unwrap()).to_string())
+ Some(FatcatId::from_uuid(&new_work_ids.pop().unwrap()).to_string())
}
model
})
@@ -1782,8 +1782,8 @@ impl EntityCrud for ReleaseEntity {
let (state, ident_id, redirect_id) = match ident_row {
Some(i) => (
Some(i.state().unwrap().shortname()),
- Some(FatCatId::from_uuid(&i.id).to_string()),
- i.redirect_id.map(|u| FatCatId::from_uuid(&u).to_string()),
+ Some(FatcatId::from_uuid(&i.id).to_string()),
+ i.redirect_id.map(|u| FatcatId::from_uuid(&u).to_string()),
),
None => (None, None, None),
};
@@ -1806,7 +1806,7 @@ impl EntityCrud for ReleaseEntity {
locator: r.locator,
target_release_id: r
.target_release_ident_id
- .map(|v| FatCatId::from_uuid(&v).to_string()),
+ .map(|v| FatcatId::from_uuid(&v).to_string()),
})
.collect(),
),
@@ -1830,7 +1830,7 @@ impl EntityCrud for ReleaseEntity {
extra: c.extra_json,
creator_id: c
.creator_ident_id
- .map(|v| FatCatId::from_uuid(&v).to_string()),
+ .map(|v| FatcatId::from_uuid(&v).to_string()),
creator: None,
})
.collect(),
@@ -1879,10 +1879,10 @@ impl EntityCrud for ReleaseEntity {
container: None,
container_id: rev_row
.container_ident_id
- .map(|u| FatCatId::from_uuid(&u).to_string()),
+ .map(|u| FatcatId::from_uuid(&u).to_string()),
publisher: rev_row.publisher,
language: rev_row.language,
- work_id: Some(FatCatId::from_uuid(&rev_row.work_ident_id).to_string()),
+ work_id: Some(FatcatId::from_uuid(&rev_row.work_ident_id).to_string()),
refs,
contribs,
abstracts,
@@ -1951,11 +1951,11 @@ impl EntityCrud for ReleaseEntity {
pages: model.pages.clone(),
work_ident_id: match model.work_id.clone() {
None => bail!("release_revs must have a work_id by the time they are inserted; this is an internal soundness error"),
- Some(s) => FatCatId::from_str(&s)?.to_uuid(),
+ Some(s) => FatcatId::from_str(&s)?.to_uuid(),
},
container_ident_id: match model.container_id.clone() {
None => None,
- Some(s) => Some(FatCatId::from_str(&s)?.to_uuid()),
+ Some(s) => Some(FatcatId::from_str(&s)?.to_uuid()),
},
publisher: model.publisher.clone(),
language: model.language.clone(),
@@ -1983,7 +1983,7 @@ impl EntityCrud for ReleaseEntity {
release_rev: *rev_id,
target_release_ident_id: match r.target_release_id.clone() {
None => None,
- Some(v) => Some(FatCatId::from_str(&v)?.to_uuid()),
+ Some(v) => Some(FatcatId::from_str(&v)?.to_uuid()),
},
index_val: r.index.map(|v| v as i32),
key: r.key.clone(),
@@ -2009,7 +2009,7 @@ impl EntityCrud for ReleaseEntity {
release_rev: *rev_id,
creator_ident_id: match c.creator_id.clone() {
None => None,
- Some(v) => Some(FatCatId::from_str(&v)?.to_uuid()),
+ Some(v) => Some(FatcatId::from_str(&v)?.to_uuid()),
},
raw_name: c.raw_name.clone(),
index_val: c.index.map(|v| v as i32),
@@ -2111,11 +2111,11 @@ impl EntityCrud for WorkEntity {
Ok(WorkEntity {
state: Some(ident_row.state().unwrap().shortname()),
- ident: Some(FatCatId::from_uuid(&ident_row.id).to_string()),
+ ident: Some(FatcatId::from_uuid(&ident_row.id).to_string()),
revision: ident_row.rev_id.map(|u| u.to_string()),
redirect: ident_row
.redirect_id
- .map(|u| FatCatId::from_uuid(&u).to_string()),
+ .map(|u| FatcatId::from_uuid(&u).to_string()),
extra: None,
edit_extra: None,
})
@@ -2130,8 +2130,8 @@ impl EntityCrud for WorkEntity {
let (state, ident_id, redirect_id) = match ident_row {
Some(i) => (
Some(i.state().unwrap().shortname()),
- Some(FatCatId::from_uuid(&i.id).to_string()),
- i.redirect_id.map(|u| FatCatId::from_uuid(&u).to_string()),
+ Some(FatcatId::from_uuid(&i.id).to_string()),
+ i.redirect_id.map(|u| FatcatId::from_uuid(&u).to_string()),
),
None => (None, None, None),
};
diff --git a/rust/src/identifiers.rs b/rust/src/identifiers.rs
index e107d16f..073464aa 100644
--- a/rust/src/identifiers.rs
+++ b/rust/src/identifiers.rs
@@ -3,51 +3,50 @@ use data_encoding::BASE32_NOPAD;
use regex::Regex;
use serde_json;
use std::str::FromStr;
+use std::{convert, fmt};
use uuid::Uuid;
-use std::{fmt, convert};
-
#[derive(Clone, Copy, PartialEq, Debug)]
-pub struct FatCatId(Uuid);
+pub struct FatcatId(Uuid);
-impl fmt::Display for FatCatId {
+impl fmt::Display for FatcatId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", uuid2fcid(&self.to_uuid()))
}
}
-impl FromStr for FatCatId {
+impl FromStr for FatcatId {
type Err = Error;
- fn from_str(s: &str) -> Result<FatCatId> {
- fcid2uuid(s).map(FatCatId)
+ fn from_str(s: &str) -> Result<FatcatId> {
+ fcid2uuid(s).map(FatcatId)
}
}
-impl convert::AsRef<Uuid> for FatCatId {
+impl convert::AsRef<Uuid> for FatcatId {
fn as_ref(&self) -> &Uuid {
&self.0
}
}
-impl convert::Into<Uuid> for FatCatId {
+impl convert::Into<Uuid> for FatcatId {
fn into(self) -> Uuid {
self.0
}
}
-impl convert::From<Uuid> for FatCatId {
- fn from(u: Uuid) -> FatCatId {
- FatCatId(u)
+impl convert::From<Uuid> for FatcatId {
+ fn from(u: Uuid) -> FatcatId {
+ FatcatId(u)
}
}
-impl FatCatId {
+impl FatcatId {
pub fn to_uuid(&self) -> Uuid {
self.0
}
// TODO: make it possible to just pass 'Uuid' in addition to '&Uuid'
- pub fn from_uuid(u: &Uuid) -> FatCatId {
- FatCatId(*u)
+ pub fn from_uuid(u: &Uuid) -> FatcatId {
+ FatcatId(*u)
}
}