summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rust/migrations/2019-01-01-000000_init/up.sql8
-rw-r--r--rust/src/database_models.rs1
-rw-r--r--rust/src/database_schema.rs2
-rw-r--r--rust/src/editing.rs21
-rw-r--r--rust/tests/test_api_server_http.rs72
-rw-r--r--rust/tests/test_old_python_tests.rs2
6 files changed, 43 insertions, 63 deletions
diff --git a/rust/migrations/2019-01-01-000000_init/up.sql b/rust/migrations/2019-01-01-000000_init/up.sql
index ddaa60b3..a3dd13a5 100644
--- a/rust/migrations/2019-01-01-000000_init/up.sql
+++ b/rust/migrations/2019-01-01-000000_init/up.sql
@@ -23,13 +23,11 @@ CREATE TABLE editor (
is_active BOOLEAN NOT NULL DEFAULT true,
registered TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
auth_epoch TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
- wrangler_id UUID REFERENCES editor(id),
- active_editgroup_id UUID -- REFERENCES( editgroup(id) via ALTER below
+ wrangler_id UUID REFERENCES editor(id)
);
-- case-insensitive UNIQ index on username
CREATE UNIQUE INDEX editor_username_uniq_idx on editor(lower(username));
-CREATE INDEX active_editgroup_idx ON editor(active_editgroup_id);
CREATE INDEX editor_username_idx ON editor(username);
CREATE TABLE auth_oidc (
@@ -51,9 +49,7 @@ CREATE TABLE editgroup (
description TEXT
);
-ALTER TABLE editor
- ADD CONSTRAINT editor_editgroupid_fkey FOREIGN KEY (active_editgroup_id)
- REFERENCES editgroup(id);
+CREATE INDEX editgroup_created_idx ON editgroup(created);
CREATE TABLE changelog (
id BIGSERIAL PRIMARY KEY,
diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs
index 4575aeaf..0b6de130 100644
--- a/rust/src/database_models.rs
+++ b/rust/src/database_models.rs
@@ -584,7 +584,6 @@ pub struct EditorRow {
pub registered: chrono::NaiveDateTime,
pub auth_epoch: chrono::NaiveDateTime,
pub wrangler_id: Option<Uuid>,
- pub active_editgroup_id: Option<Uuid>,
}
impl EditorRow {
diff --git a/rust/src/database_schema.rs b/rust/src/database_schema.rs
index 0c553b40..ac5acec8 100644
--- a/rust/src/database_schema.rs
+++ b/rust/src/database_schema.rs
@@ -114,7 +114,6 @@ table! {
registered -> Timestamptz,
auth_epoch -> Timestamptz,
wrangler_id -> Nullable<Uuid>,
- active_editgroup_id -> Nullable<Uuid>,
}
}
@@ -406,6 +405,7 @@ joinable!(container_edit -> editgroup (editgroup_id));
joinable!(container_ident -> container_rev (rev_id));
joinable!(creator_edit -> editgroup (editgroup_id));
joinable!(creator_ident -> creator_rev (rev_id));
+joinable!(editgroup -> editor (editor_id));
joinable!(file_edit -> editgroup (editgroup_id));
joinable!(file_ident -> file_rev (rev_id));
joinable!(file_rev_release -> file_rev (file_rev));
diff --git a/rust/src/editing.rs b/rust/src/editing.rs
index b488e489..42dd013e 100644
--- a/rust/src/editing.rs
+++ b/rust/src/editing.rs
@@ -45,7 +45,7 @@ pub fn make_edit_context(
.get_result(conn)?;
FatCatId::from_uuid(&eg_row.id)
}
- (None, false) => FatCatId::from_uuid(&get_or_create_editgroup(conn, editor_id.to_uuid())?),
+ (None, false) => FatCatId::from_uuid(&create_editgroup(conn, editor_id.to_uuid())?),
};
Ok(EditContext {
editor_id,
@@ -86,20 +86,11 @@ pub fn update_editor_username(
}
/// This function should always be run within a transaction
-pub fn get_or_create_editgroup(conn: &DbConn, editor_id: Uuid) -> Result<Uuid> {
- // check for current active
- let ed_row: EditorRow = editor::table.find(editor_id).first(conn)?;
- if let Some(current) = ed_row.active_editgroup_id {
- return Ok(current);
- }
-
+pub fn create_editgroup(conn: &DbConn, editor_id: Uuid) -> Result<Uuid> {
// need to insert and update
let eg_row: EditgroupRow = diesel::insert_into(editgroup::table)
- .values((editgroup::editor_id.eq(ed_row.id),))
+ .values((editgroup::editor_id.eq(editor_id),))
.get_result(conn)?;
- diesel::update(editor::table.find(ed_row.id))
- .set(editor::active_editgroup_id.eq(eg_row.id))
- .execute(conn)?;
Ok(eg_row.id)
}
@@ -130,11 +121,5 @@ pub fn accept_editgroup(conn: &DbConn, editgroup_id: FatCatId) -> Result<Changel
.values((changelog::editgroup_id.eq(editgroup_id.to_uuid()),))
.get_result(conn)?;
- // update any editor's active editgroup
- let no_active: Option<Uuid> = None;
- diesel::update(editor::table)
- .filter(editor::active_editgroup_id.eq(editgroup_id.to_uuid()))
- .set(editor::active_editgroup_id.eq(no_active))
- .execute(conn)?;
Ok(entry)
}
diff --git a/rust/tests/test_api_server_http.rs b/rust/tests/test_api_server_http.rs
index b1fc5e87..e82037f0 100644
--- a/rust/tests/test_api_server_http.rs
+++ b/rust/tests/test_api_server_http.rs
@@ -8,7 +8,7 @@
use diesel::prelude::*;
use fatcat::database_schema::*;
-use fatcat::editing::get_or_create_editgroup;
+use fatcat::editing::create_editgroup;
use fatcat::identifiers::*;
use iron::status;
use iron_test::request;
@@ -533,10 +533,12 @@ fn test_post_creator() {
#[test]
fn test_post_file() {
let (headers, router, conn) = helpers::setup_http();
+ let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap();
+ let editgroup_id = uuid2fcid(&create_editgroup(&conn, editor_id).unwrap());
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/file",
+ &format!("http://localhost:9411/v0/file?editgroup_id={}", editgroup_id),
headers.clone(),
r#"{ }"#,
&router,
@@ -547,7 +549,7 @@ fn test_post_file() {
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/file",
+ &format!("http://localhost:9411/v0/file?editgroup_id={}", editgroup_id),
headers.clone(),
r#"{"size": 76543,
"sha1": "f0000000000000008b7eb2a93e6d0440c1f3e7f8",
@@ -570,13 +572,11 @@ fn test_post_file() {
None,
);
- let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap();
- let editgroup_id = get_or_create_editgroup(&conn, editor_id).unwrap();
helpers::check_http_response(
request::post(
&format!(
"http://localhost:9411/v0/editgroup/{}/accept",
- uuid2fcid(&editgroup_id)
+ &editgroup_id
),
headers.clone(),
"",
@@ -600,10 +600,12 @@ fn test_post_file() {
#[test]
fn test_post_fileset() {
let (headers, router, conn) = helpers::setup_http();
+ let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap();
+ let editgroup_id = uuid2fcid(&create_editgroup(&conn, editor_id).unwrap());
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/fileset",
+ &format!("http://localhost:9411/v0/fileset?editgroup_id={}", editgroup_id),
headers.clone(),
r#"{ }"#,
&router,
@@ -614,7 +616,7 @@ fn test_post_fileset() {
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/fileset",
+ &format!("http://localhost:9411/v0/fileset?editgroup_id={}", editgroup_id),
headers.clone(),
r#"{"manifest": [
{"path": "new_file.txt", "size": 12345, "sha1": "e9dd75237c94b209dc3ccd52722de6931a310ba3" },
@@ -636,13 +638,11 @@ fn test_post_fileset() {
None,
);
- let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap();
- let editgroup_id = get_or_create_editgroup(&conn, editor_id).unwrap();
helpers::check_http_response(
request::post(
&format!(
"http://localhost:9411/v0/editgroup/{}/accept",
- uuid2fcid(&editgroup_id)
+ &editgroup_id
),
headers.clone(),
"",
@@ -657,10 +657,12 @@ fn test_post_fileset() {
#[test]
fn test_post_webcapture() {
let (headers, router, conn) = helpers::setup_http();
+ let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap();
+ let editgroup_id = uuid2fcid(&create_editgroup(&conn, editor_id).unwrap());
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/webcapture",
+ &format!("http://localhost:9411/v0/webcapture?editgroup_id={}", editgroup_id),
headers.clone(),
r#"{ "original_url": "https://fatcat.wiki",
"timestamp": "2018-12-28T11:11:11Z" }"#,
@@ -672,7 +674,7 @@ fn test_post_webcapture() {
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/webcapture",
+ &format!("http://localhost:9411/v0/webcapture?editgroup_id={}", editgroup_id),
headers.clone(),
r#"{"original_url": "https://bnewbold.net/",
"timestamp": "2018-12-28T05:06:07Z",
@@ -700,13 +702,11 @@ fn test_post_webcapture() {
None,
);
- let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap();
- let editgroup_id = get_or_create_editgroup(&conn, editor_id).unwrap();
helpers::check_http_response(
request::post(
&format!(
"http://localhost:9411/v0/editgroup/{}/accept",
- uuid2fcid(&editgroup_id)
+ &editgroup_id
),
headers.clone(),
"",
@@ -720,11 +720,13 @@ fn test_post_webcapture() {
#[test]
fn test_post_release() {
- let (headers, router, _conn) = helpers::setup_http();
+ let (headers, router, conn) = helpers::setup_http();
+ let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap();
+ let editgroup_id = uuid2fcid(&create_editgroup(&conn, editor_id).unwrap());
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/release",
+ &format!("http://localhost:9411/v0/release?editgroup_id={}", editgroup_id),
headers.clone(),
// TODO: target_release_id
r#"{"title": "secret minimal paper",
@@ -740,7 +742,7 @@ fn test_post_release() {
// No work_id supplied (auto-created)
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/release",
+ &format!("http://localhost:9411/v0/release?editgroup_id={}", editgroup_id),
headers.clone(),
// TODO: target_release_id
r#"{"title": "secret minimal paper the second",
@@ -754,7 +756,7 @@ fn test_post_release() {
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/release",
+ &format!("http://localhost:9411/v0/release?editgroup_id={}", editgroup_id),
headers.clone(),
// TODO: target_release_id
r#"{"title": "secret paper",
@@ -797,7 +799,7 @@ fn test_post_release() {
/* XXX: doesn't fail
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/release",
+ &format!("http://localhost:9411/v0/release?editgroup_id={}", editgroup_id),
headers.clone(),
r#"{"title": "secret minimal paper the second",
"asdf123": "lalala"
@@ -847,7 +849,7 @@ fn test_update_work() {
);
let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap();
- let editgroup_id = get_or_create_editgroup(&conn, editor_id).unwrap();
+ let editgroup_id = create_editgroup(&conn, editor_id).unwrap();
helpers::check_http_response(
request::post(
&format!(
@@ -878,7 +880,7 @@ fn test_delete_work() {
);
let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap();
- let editgroup_id = get_or_create_editgroup(&conn, editor_id).unwrap();
+ let editgroup_id = create_editgroup(&conn, editor_id).unwrap();
helpers::check_http_response(
request::post(
&format!(
@@ -899,7 +901,7 @@ fn test_accept_editgroup() {
let (headers, router, conn) = helpers::setup_http();
let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap();
- let editgroup_id = get_or_create_editgroup(&conn, editor_id).unwrap();
+ let editgroup_id = create_editgroup(&conn, editor_id).unwrap();
let c: i64 = container_ident::table
.filter(container_ident::is_live.eq(false))
@@ -916,7 +918,7 @@ fn test_accept_editgroup() {
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/container",
+ &format!("http://localhost:9411/v0/container?editgroup_id={}", uuid2fcid(&editgroup_id)),
headers.clone(),
&format!(
"{{\"name\": \"test journal 1\", \"editgroup_id\": \"{}\"}}",
@@ -929,7 +931,7 @@ fn test_accept_editgroup() {
);
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/container",
+ &format!("http://localhost:9411/v0/container?editgroup_id={}", uuid2fcid(&editgroup_id)),
headers.clone(),
&format!(
"{{\"name\": \"test journal 2\", \"editgroup_id\": \"{}\"}}",
@@ -1193,10 +1195,12 @@ fn test_bad_external_idents() {
#[test]
fn test_abstracts() {
let (headers, router, conn) = helpers::setup_http();
+ let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap();
+ let editgroup_id = uuid2fcid(&create_editgroup(&conn, editor_id).unwrap());
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/release",
+ &format!("http://localhost:9411/v0/release?editgroup_id={}", editgroup_id),
headers.clone(),
r#"{"title": "some paper",
"doi": "10.1234/iiiiiii",
@@ -1218,7 +1222,7 @@ fn test_abstracts() {
// Same abstracts; checking that re-inserting works
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/release",
+ &format!("http://localhost:9411/v0/release?editgroup_id={}", editgroup_id),
headers.clone(),
r#"{"title": "some paper again",
"abstracts": [
@@ -1236,13 +1240,11 @@ fn test_abstracts() {
None,
);
- let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap();
- let editgroup_id = get_or_create_editgroup(&conn, editor_id).unwrap();
helpers::check_http_response(
request::post(
&format!(
"http://localhost:9411/v0/editgroup/{}/accept",
- uuid2fcid(&editgroup_id)
+ &editgroup_id
),
headers.clone(),
"",
@@ -1285,10 +1287,12 @@ fn test_abstracts() {
#[test]
fn test_contribs() {
let (headers, router, conn) = helpers::setup_http();
+ let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap();
+ let editgroup_id = uuid2fcid(&create_editgroup(&conn, editor_id).unwrap());
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/release",
+ &format!("http://localhost:9411/v0/release?editgroup_id={}", editgroup_id),
headers.clone(),
r#"{"title": "some paper",
"doi": "10.1234/iiiiiii",
@@ -1308,13 +1312,11 @@ fn test_contribs() {
None,
);
- let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap();
- let editgroup_id = get_or_create_editgroup(&conn, editor_id).unwrap();
helpers::check_http_response(
request::post(
&format!(
"http://localhost:9411/v0/editgroup/{}/accept",
- uuid2fcid(&editgroup_id)
+ &editgroup_id
),
headers.clone(),
"",
diff --git a/rust/tests/test_old_python_tests.rs b/rust/tests/test_old_python_tests.rs
index 0676a604..ac9d4112 100644
--- a/rust/tests/test_old_python_tests.rs
+++ b/rust/tests/test_old_python_tests.rs
@@ -177,8 +177,6 @@ fn test_api_rich_create() {
};
assert_eq!(fe.release_ids.unwrap()[0], release_id.clone());
- // had a test for active_editgroup here, but that's soon-to-be-deprecated
-
server.close().unwrap()
}