From 501b6ba9eb9871ca303c631d166c92c6ca2f1725 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Wed, 28 Feb 2024 14:57:40 +0100 Subject: [PATCH] httpd: Add author information to assignees --- radicle-httpd/src/api/json.rs | 8 ++- radicle-httpd/src/api/v1/projects.rs | 76 +++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 3 deletions(-) diff --git a/radicle-httpd/src/api/json.rs b/radicle-httpd/src/api/json.rs index ab955e20..21ff0832 100644 --- a/radicle-httpd/src/api/json.rs +++ b/radicle-httpd/src/api/json.rs @@ -104,7 +104,9 @@ pub(crate) fn issue(id: IssueId, issue: Issue, aliases: &impl AliasStore) -> Val "author": author(&issue.author(), aliases.alias(issue.author().id())), "title": issue.title(), "state": issue.state(), - "assignees": issue.assignees().collect::>(), + "assignees": issue.assignees().map(|assignee| + author(&Author::from(*assignee.as_key()), aliases.alias(assignee)) + ).collect::>(), "discussion": issue.comments().map(|(id, c)| issue_comment(id, c, aliases)).collect::>(), "labels": issue.labels().collect::>(), }) @@ -125,7 +127,9 @@ pub(crate) fn patch( "target": patch.target(), "labels": patch.labels().collect::>(), "merges": patch.merges().map(|(nid, m)| merge(nid, m, aliases)).collect::>(), - "assignees": patch.assignees().collect::>(), + "assignees": patch.assignees().map(|assignee| + author(&Author::from(*assignee), aliases.alias(&assignee)) + ).collect::>(), "revisions": patch.revisions().map(|(id, rev)| { json!({ "id": id, diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index 160412a5..7d26dc0b 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -2310,6 +2310,78 @@ mod routes { ); } + #[tokio::test] + async fn test_projects_issues_assign() { + let tmp = tempfile::tempdir().unwrap(); + let ctx = contributor(tmp.path()); + let app = super::router(ctx.to_owned()); + + create_session(ctx).await; + + let body = serde_json::to_vec(&json!({ + "type": "assign", + "assignees": [CONTRIBUTOR_DID], + })) + .unwrap(); + + let response = patch( + &app, + format!("/projects/{CONTRIBUTOR_RID}/issues/{ISSUE_DISCUSSION_ID}"), + Some(Body::from(body)), + Some(SESSION_ID.to_string()), + ) + .await; + assert_eq!(response.status(), StatusCode::OK); + + let response = get( + &app, + format!("/projects/{CONTRIBUTOR_RID}/issues/{ISSUE_DISCUSSION_ID}"), + ) + .await; + + assert_eq!( + response.json().await, + json!({ + "id": ISSUE_DISCUSSION_ID, + "author": { + "id": CONTRIBUTOR_DID, + }, + "title": "Issue #1", + "state": { + "status": "open", + }, + "assignees": [ + { "id": CONTRIBUTOR_DID } + ], + "discussion": [ + { + "id": ISSUE_DISCUSSION_ID, + "author": { + "id": CONTRIBUTOR_DID, + }, + "body": "Change 'hello world' to 'hello everyone'", + "edits": [ + { + "author": { + "id": CONTRIBUTOR_DID, + }, + "body": "Change 'hello world' to 'hello everyone'", + "timestamp": TIMESTAMP, + "embeds": [], + }, + ], + "embeds": [], + "reactions": [], + "timestamp": TIMESTAMP, + "replyTo": null, + "resolved": false, + }, + ], + "labels": [], + }) + ); + } + #[tokio::test] async fn test_projects_issues_reply() { let tmp = tempfile::tempdir().unwrap(); @@ -2661,7 +2733,9 @@ mod routes { "target": "delegates", "labels": [], "merges": [], - "assignees": [CONTRIBUTOR_DID], + "assignees": [ + { "id": CONTRIBUTOR_DID } + ], "revisions": [ { "id": CONTRIBUTOR_PATCH_ID,