diff options
Diffstat (limited to 'rust')
-rw-r--r-- | rust/src/database_models.rs | 6 | ||||
-rw-r--r-- | rust/src/database_schema.rs | 16 | ||||
-rw-r--r-- | rust/src/editing.rs | 60 | ||||
-rw-r--r-- | rust/src/endpoint_handlers.rs | 7 | ||||
-rw-r--r-- | rust/src/endpoints.rs | 181 | ||||
-rw-r--r-- | rust/src/lib.rs | 2 |
6 files changed, 224 insertions, 48 deletions
diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs index 0b6de130..4e83afdb 100644 --- a/rust/src/database_models.rs +++ b/rust/src/database_models.rs @@ -554,6 +554,8 @@ pub struct EditgroupRow { pub id: Uuid, pub editor_id: Uuid, pub created: chrono::NaiveDateTime, + pub submitted: Option<chrono::NaiveDateTime>, + pub is_accepted: bool, pub extra_json: Option<serde_json::Value>, pub description: Option<String>, } @@ -565,8 +567,12 @@ impl EditgroupRow { Editgroup { editgroup_id: Some(uuid2fcid(&self.id)), editor_id: Some(uuid2fcid(&self.editor_id)), + submitted: self + .submitted + .map(|v| chrono::DateTime::from_utc(v, chrono::Utc)), description: self.description, extra: self.extra_json, + annotations: None, edits: None, } } diff --git a/rust/src/database_schema.rs b/rust/src/database_schema.rs index ac5acec8..b82e776f 100644 --- a/rust/src/database_schema.rs +++ b/rust/src/database_schema.rs @@ -98,12 +98,25 @@ table! { id -> Uuid, editor_id -> Uuid, created -> Timestamptz, + submitted -> Nullable<Timestamptz>, + is_accepted -> Bool, extra_json -> Nullable<Jsonb>, description -> Nullable<Text>, } } table! { + editgroup_annotation (id) { + id -> Uuid, + editgroup_id -> Uuid, + editor_id -> Uuid, + created -> Timestamptz, + comment_markdown -> Nullable<Text>, + extra_json -> Nullable<Jsonb>, + } +} + +table! { editor (id) { id -> Uuid, username -> Text, @@ -406,6 +419,8 @@ 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!(editgroup_annotation -> editgroup (editgroup_id)); +joinable!(editgroup_annotation -> editor (editor_id)); joinable!(file_edit -> editgroup (editgroup_id)); joinable!(file_ident -> file_rev (rev_id)); joinable!(file_rev_release -> file_rev (file_rev)); @@ -447,6 +462,7 @@ allow_tables_to_appear_in_same_query!( creator_ident, creator_rev, editgroup, + editgroup_annotation, editor, file_edit, file_ident, diff --git a/rust/src/editing.rs b/rust/src/editing.rs index 4fca30d6..2feff837 100644 --- a/rust/src/editing.rs +++ b/rust/src/editing.rs @@ -60,45 +60,6 @@ pub fn make_edit_context( }) } -pub fn create_editor( - conn: &DbConn, - username: String, - is_admin: bool, - is_bot: bool, -) -> Result<EditorRow> { - check_username(&username)?; - let ed: EditorRow = diesel::insert_into(editor::table) - .values(( - editor::username.eq(username), - editor::is_admin.eq(is_admin), - editor::is_bot.eq(is_bot), - )) - .get_result(conn)?; - Ok(ed) -} - -pub fn update_editor_username( - conn: &DbConn, - editor_id: FatcatId, - username: String, -) -> Result<EditorRow> { - check_username(&username)?; - diesel::update(editor::table.find(editor_id.to_uuid())) - .set(editor::username.eq(username)) - .execute(conn)?; - let editor: EditorRow = editor::table.find(editor_id.to_uuid()).get_result(conn)?; - Ok(editor) -} - -/// This function should always be run within a transaction -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(editor_id),)) - .get_result(conn)?; - Ok(eg_row.id) -} - /// This function should always be run within a transaction pub fn accept_editgroup(conn: &DbConn, editgroup_id: FatcatId) -> Result<ChangelogRow> { // check that we haven't accepted already (in changelog) @@ -128,3 +89,24 @@ pub fn accept_editgroup(conn: &DbConn, editgroup_id: FatcatId) -> Result<Changel Ok(entry) } + +pub fn create_editgroup(conn: &DbConn, editor_id: Uuid) -> Result<Uuid> { + unimplemented!() +} + +pub fn create_editor( + conn: &DbConn, + username: String, + is_admin: bool, + is_bot: bool, +) -> Result<EditorRow> { + unimplemented!() +} + +pub fn update_editor_username( + conn: &DbConn, + editor_id: FatcatId, + username: String, +) -> Result<EditorRow> { + unimplemented!() +} diff --git a/rust/src/endpoint_handlers.rs b/rust/src/endpoint_handlers.rs index 01b5eb5c..79da2dbe 100644 --- a/rust/src/endpoint_handlers.rs +++ b/rust/src/endpoint_handlers.rs @@ -387,6 +387,8 @@ impl Server { conn: &DbConn, entity: models::Editgroup, ) -> Result<Editgroup> { + unimplemented!() + /* let row: EditgroupRow = insert_into(editgroup::table) .values(( editgroup::editor_id.eq(FatcatId::from_str(&entity.editor_id.unwrap())?.to_uuid()), @@ -402,6 +404,7 @@ impl Server { edits: None, extra: row.extra_json, }) + */ } pub fn get_editgroup_handler( @@ -470,6 +473,9 @@ impl Server { ), }; + unimplemented!(); + // XXX: + /* let eg = Editgroup { editgroup_id: Some(uuid2fcid(&row.id)), editor_id: Some(uuid2fcid(&row.editor_id)), @@ -478,6 +484,7 @@ impl Server { extra: row.extra_json, }; Ok(eg) + */ } pub fn get_editor_handler(&self, conn: &DbConn, editor_id: FatcatId) -> Result<Editor> { diff --git a/rust/src/endpoints.rs b/rust/src/endpoints.rs index 3a95f746..f6d73bbb 100644 --- a/rust/src/endpoints.rs +++ b/rust/src/endpoints.rs @@ -619,11 +619,6 @@ impl Api for Server { GetCreatorReleasesResponse ); wrap_fcid_handler!(get_editor, get_editor_handler, GetEditorResponse); - wrap_fcid_handler!( - get_editor_changelog, - get_editor_changelog_handler, - GetEditorChangelogResponse - ); fn lookup_file( &self, @@ -737,6 +732,50 @@ impl Api for Server { Box::new(futures::done(Ok(ret))) } + fn get_editor_editgroups( + &self, + editor_id: String, + limit: Option<i64>, + before: Option<chrono::DateTime<chrono::Utc>>, + since: Option<chrono::DateTime<chrono::Utc>>, + _context: &Context, + ) -> Box<Future<Item = GetEditorEditgroupsResponse, Error = ApiError> + Send> { + let conn = self.db_pool.get().expect("db_pool error"); + let ret = match conn + .transaction(|| { + let editor_id = FatcatId::from_str(&editor_id)?; + unimplemented!() + }) + .map_err(|e: Error| FatcatError::from(e)) + { + Ok(editgroups) => GetEditorEditgroupsResponse::Found(editgroups), + Err(fe) => generic_err_responses!(fe, GetEditorEditgroupsResponse), + }; + Box::new(futures::done(Ok(ret))) + } + + fn get_editor_annotations( + &self, + editor_id: String, + limit: Option<i64>, + before: Option<chrono::DateTime<chrono::Utc>>, + since: Option<chrono::DateTime<chrono::Utc>>, + _context: &Context, + ) -> Box<Future<Item = GetEditorAnnotationsResponse, Error = ApiError> + Send> { + let conn = self.db_pool.get().expect("db_pool error"); + let ret = match conn + .transaction(|| { + let editor_id = FatcatId::from_str(&editor_id)?; + unimplemented!() + }) + .map_err(|e: Error| FatcatError::from(e)) + { + Ok(editgroups) => GetEditorAnnotationsResponse::Success(editgroups), + Err(fe) => generic_err_responses!(fe, GetEditorAnnotationsResponse), + }; + Box::new(futures::done(Ok(ret))) + } + fn accept_editgroup( &self, editgroup_id: String, @@ -789,6 +828,46 @@ impl Api for Server { Box::new(futures::done(Ok(ret))) } + fn get_editgroup_annotations( + &self, + editgroup_id: String, + expand: Option<String>, + _context: &Context, + ) -> Box<Future<Item = GetEditgroupAnnotationsResponse, 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)?; + unimplemented!() + // TODO: let expand_flags = ExpandFlags::from_str(¶m)?; + }) + .map_err(|e: Error| FatcatError::from(e)) + { + Ok(annotations) => GetEditgroupAnnotationsResponse::Success(annotations), + Err(fe) => generic_err_responses!(fe, GetEditgroupAnnotationsResponse), + }; + Box::new(futures::done(Ok(ret))) + } + + fn get_editgroups_reviewable( + &self, + expand: Option<String>, + limit: Option<i64>, + before: Option<chrono::DateTime<chrono::Utc>>, + since: Option<chrono::DateTime<chrono::Utc>>, + _context: &Context, + ) -> Box<Future<Item = GetEditgroupsReviewableResponse, Error = ApiError> + Send> { + let conn = self.db_pool.get().expect("db_pool error"); + let ret = match conn + .transaction(|| unimplemented!()) + .map_err(|e: Error| FatcatError::from(e)) + { + Ok(editgroups) => GetEditgroupsReviewableResponse::Found(editgroups), + Err(fe) => generic_err_responses!(fe, GetEditgroupsReviewableResponse), + }; + Box::new(futures::done(Ok(ret))) + } + fn create_editgroup( &self, entity: models::Editgroup, @@ -823,7 +902,7 @@ impl Api for Server { Ok(eg) => { self.metrics.incr("editgroup.created").ok(); CreateEditgroupResponse::SuccessfullyCreated(eg) - }, + } Err(fe) => match fe { NotFound(_, _) => CreateEditgroupResponse::NotFound(fe.into()), DatabaseError(_) | InternalError(_) => { @@ -837,6 +916,92 @@ impl Api for Server { Box::new(futures::done(Ok(ret))) } + fn update_editgroup( + &self, + editgroup_id: String, + editgroup: models::Editgroup, + submit: Option<bool>, + context: &Context, + ) -> Box<Future<Item = UpdateEditgroupResponse, 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)?; + if Some(editgroup_id.to_string()) != editgroup.editgroup_id { + return Err(FatcatError::OtherBadRequest( + "editgroup_id doesn't match".to_string(), + ) + .into()); + } + let auth_context = self.auth_confectionary.require_auth( + &conn, + &context.auth_data, + Some("update_editgroup"), + )?; + unimplemented!(); // submit + // XXX let existing = Editgroup::db_get(&conn, editgroup_id)?; + /* + if existing.editor_id == auth_context.editor_id.to_uuid() { + // self edit of editgroup allowed + auth_context.require_role(FatcatRole::Editor)?; + } else { + // admin can update any editgroup + auth_context.require_role(FatcatRole::Admin)?; + }; + editgroup + .db_update(&conn, editgroup_id) + .map(|e| e.into_model()) + */ + }) + .map_err(|e: Error| FatcatError::from(e)) + { + Ok(editgroup) => UpdateEditgroupResponse::UpdatedEditgroup(editgroup), + Err(fe) => generic_err_responses!(fe, UpdateEditgroupResponse), + }; + Box::new(futures::done(Ok(ret))) + } + + fn create_editgroup_annotation( + &self, + editgroup_id: String, + annotation: models::EditgroupAnnotation, + context: &Context, + ) -> Box<Future<Item = CreateEditgroupAnnotationResponse, Error = ApiError> + Send> { + let conn = self.db_pool.get().expect("db_pool error"); + let ret = match conn + .transaction(|| { + let auth_context = self.auth_confectionary.require_auth( + &conn, + &context.auth_data, + Some("create_editgroup_annotation"), + )?; + auth_context.require_role(FatcatRole::Editor)?; + let editgroup_id = FatcatId::from_str(&editgroup_id)?; + let mut annotation = annotation.clone(); + annotation.editgroup_id = Some(editgroup_id.to_string()); + match annotation.editor_id.clone() { + Some(editor_id) => { + if editor_id != auth_context.editor_id.to_string() + && !auth_context.has_role(FatcatRole::Superuser) + { + bail!("not authorized to annotate in others' names"); + } + } + None => { + annotation.editor_id = Some(auth_context.editor_id.to_string()); + } + }; + unimplemented!(); + // TODO: self.create_editgroup_annotation_handler(&conn, annotation) + }) + .map_err(|e: Error| FatcatError::from(e)) + { + Ok(annotation) => CreateEditgroupAnnotationResponse::Created(annotation), + Err(fe) => generic_auth_err_responses!(fe, CreateEditgroupAnnotationResponse), + }; + Box::new(futures::done(Ok(ret))) + } + fn get_changelog( &self, limit: Option<i64>, @@ -906,11 +1071,11 @@ impl Api for Server { Ok((result, true)) => { self.metrics.incr("account.signup").ok(); AuthOidcResponse::Created(result) - }, + } Ok((result, false)) => { self.metrics.incr("account.login").ok(); AuthOidcResponse::Found(result) - }, + } Err(fe) => match fe { DatabaseError(_) | InternalError(_) => { error!("{}", fe); diff --git a/rust/src/lib.rs b/rust/src/lib.rs index b7661334..b4e5d17a 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -14,7 +14,7 @@ pub mod auth; pub mod database_models; pub mod database_schema; // only public for tests pub mod editing; -pub mod editing_crud; +//pub mod editing_crud; mod endpoint_handlers; mod endpoints; pub mod entity_crud; |