Update profile page URL template to match mitra-web

This commit is contained in:
silverpill 2023-03-21 13:47:31 +00:00
parent 848a0685de
commit cdb304a8b7
6 changed files with 24 additions and 15 deletions

View file

@ -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

View file

@ -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);

View file

@ -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);

View file

@ -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();

View file

@ -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),
)
}

View file

@ -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]