From cdb304a8b7c14774454aca7c5d1a4ce6c6ccc7db Mon Sep 17 00:00:00 2001 From: silverpill Date: Tue, 21 Mar 2023 13:47:31 +0000 Subject: [PATCH] Update profile page URL template to match mitra-web --- CHANGELOG.md | 1 + src/activitypub/actors/attachments.rs | 15 ++++++--------- src/activitypub/actors/types.rs | 2 +- src/activitypub/views.rs | 5 ++++- src/web_client/urls.rs | 8 ++++---- src/webfinger/types.rs | 8 ++++++++ 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b10e532..8118650 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Documented valid role names for `set-role` command. - Granted `delete_any_post` and `delete_any_profile` permissions to admin role. +- Updated profile page URL template to match mitra-web. ### Fixed diff --git a/src/activitypub/actors/attachments.rs b/src/activitypub/actors/attachments.rs index 54531ea..fa67ee6 100644 --- a/src/activitypub/actors/attachments.rs +++ b/src/activitypub/actors/attachments.rs @@ -1,5 +1,3 @@ -use uuid::Uuid; - use mitra_utils::did::Did; use crate::activitypub::vocabulary::{ @@ -101,7 +99,7 @@ pub fn parse_identity_proof( pub fn attach_payment_option( instance_url: &str, - user_id: &Uuid, + username: &str, payment_option: PaymentOption, ) -> ActorAttachment { let (name, href) = match payment_option { @@ -109,12 +107,12 @@ pub fn attach_payment_option( PaymentOption::Link(_) => unimplemented!(), PaymentOption::EthereumSubscription(_) => { let name = "EthereumSubscription".to_string(); - let href = get_subscription_page_url(instance_url, user_id); + let href = get_subscription_page_url(instance_url, username); (name, href) }, PaymentOption::MoneroSubscription(_) => { let name = "MoneroSubscription".to_string(); - let href = get_subscription_page_url(instance_url, user_id); + let href = get_subscription_page_url(instance_url, username); (name, href) }, }; @@ -177,7 +175,6 @@ pub fn parse_extra_field( mod tests { use mitra_utils::{ caip2::ChainId, - id::generate_ulid, }; use super::*; @@ -200,14 +197,14 @@ mod tests { #[test] fn test_payment_option() { - let user_id = generate_ulid(); + let username = "testuser"; let payment_option = PaymentOption::ethereum_subscription(ChainId::ethereum_mainnet()); let subscription_page_url = - format!("https://example.com/profile/{}/subscription", user_id); + "https://example.com/@testuser/subscription"; let attachment = attach_payment_option( INSTANCE_URL, - &user_id, + username, payment_option, ); assert_eq!(attachment.object_type, LINK); diff --git a/src/activitypub/actors/types.rs b/src/activitypub/actors/types.rs index 1b36a58..483d842 100644 --- a/src/activitypub/actors/types.rs +++ b/src/activitypub/actors/types.rs @@ -329,7 +329,7 @@ pub fn get_local_actor( for payment_option in user.profile.payment_options.clone().into_inner() { let attachment = attach_payment_option( instance_url, - &user.id, + &user.profile.username, payment_option, ); attachments.push(attachment); diff --git a/src/activitypub/views.rs b/src/activitypub/views.rs index b5e6b4f..4496787 100644 --- a/src/activitypub/views.rs +++ b/src/activitypub/views.rs @@ -84,7 +84,10 @@ async fn actor_view( let db_client = &**get_database_client(&db_pool).await?; let user = get_user_by_name(db_client, &username).await?; if !is_activitypub_request(request.headers()) { - let page_url = get_profile_page_url(&config.instance_url(), &user.id); + let page_url = get_profile_page_url( + &config.instance_url(), + &user.profile.username, + ); let response = HttpResponse::Found() .append_header((http_header::LOCATION, page_url)) .finish(); diff --git a/src/web_client/urls.rs b/src/web_client/urls.rs index 2cfcb36..be8f4f3 100644 --- a/src/web_client/urls.rs +++ b/src/web_client/urls.rs @@ -2,8 +2,8 @@ use uuid::Uuid; // Assuming frontend is on the same host as backend -pub fn get_profile_page_url(instance_url: &str, profile_id: &Uuid) -> String { - format!("{}/profile/{}", instance_url, profile_id) +pub fn get_profile_page_url(instance_url: &str, username: &str) -> String { + format!("{}/@{}", instance_url, username) } pub fn get_post_page_url(instance_url: &str, post_id: &Uuid) -> String { @@ -14,9 +14,9 @@ pub fn get_tag_page_url(instance_url: &str, tag_name: &str) -> String { format!("{}/tag/{}", instance_url, tag_name) } -pub fn get_subscription_page_url(instance_url: &str, profile_id: &Uuid) -> String { +pub fn get_subscription_page_url(instance_url: &str, username: &str) -> String { format!( "{}/subscription", - get_profile_page_url(instance_url, profile_id), + get_profile_page_url(instance_url, username), ) } diff --git a/src/webfinger/types.rs b/src/webfinger/types.rs index cec6cb1..56aa9b8 100644 --- a/src/webfinger/types.rs +++ b/src/webfinger/types.rs @@ -115,6 +115,10 @@ mod tests { actor_address.to_string(), "user@example.com", ); + assert_eq!( + actor_address.acct(local_hostname), + local_profile.acct, + ); } #[test] @@ -138,6 +142,10 @@ mod tests { actor_address.to_string(), remote_profile.acct, ); + assert_eq!( + actor_address.acct(local_hostname), + remote_profile.acct, + ); } #[test]