Make actor objects pass JSON-LD validation

This commit is contained in:
silverpill 2023-02-19 22:14:10 +00:00
parent 2f621201f8
commit 50176b00cc
3 changed files with 38 additions and 9 deletions

View file

@ -22,6 +22,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Changed `/api/v1/statuses/{status_id}/context` response format to match Mastodon API. - Changed `/api/v1/statuses/{status_id}/context` response format to match Mastodon API.
- Changed status code of `/api/v1/statuses` response to 200 to match Mastodon API. - Changed status code of `/api/v1/statuses` response to 200 to match Mastodon API.
### Fixed
- Fixed actor object JSON-LD validation errors.
## [1.13.1] - 2023-02-09 ## [1.13.1] - 2023-02-09
### Fixed ### Fixed

View file

@ -1,3 +1,5 @@
use std::collections::HashMap;
use serde::{ use serde::{
Deserialize, Deserialize,
Deserializer, Deserializer,
@ -15,6 +17,9 @@ use mitra_utils::{
use crate::activitypub::{ use crate::activitypub::{
constants::{ constants::{
AP_CONTEXT, AP_CONTEXT,
MASTODON_CONTEXT,
MITRA_CONTEXT,
SCHEMA_ORG_CONTEXT,
W3ID_SECURITY_CONTEXT, W3ID_SECURITY_CONTEXT,
}, },
identifiers::{ identifiers::{
@ -253,6 +258,27 @@ impl Actor {
pub type ActorKeyError = rsa::pkcs8::Error; pub type ActorKeyError = rsa::pkcs8::Error;
fn build_actor_context() -> (
&'static str,
&'static str,
HashMap<&'static str, &'static str>,
) {
(
AP_CONTEXT,
W3ID_SECURITY_CONTEXT,
HashMap::from([
("manuallyApprovesFollowers", "as:manuallyApprovesFollowers"),
("schema", SCHEMA_ORG_CONTEXT),
("PropertyValue", "schema:PropertyValue"),
("value", "schema:value"),
("toot", MASTODON_CONTEXT),
("IdentityProof", "toot:IdentityProof"),
("mitra", MITRA_CONTEXT),
("subscribers", "mitra:subscribers"),
]),
)
}
pub fn get_local_actor( pub fn get_local_actor(
user: &User, user: &User,
instance_url: &str, instance_url: &str,
@ -312,10 +338,7 @@ pub fn get_local_actor(
attachments.push(attachment); attachments.push(attachment);
}; };
let actor = Actor { let actor = Actor {
context: Some(json!([ context: Some(json!(build_actor_context())),
AP_CONTEXT.to_string(),
W3ID_SECURITY_CONTEXT.to_string(),
])),
id: actor_id.clone(), id: actor_id.clone(),
object_type: PERSON.to_string(), object_type: PERSON.to_string(),
name: user.profile.display_name.clone(), name: user.profile.display_name.clone(),
@ -351,10 +374,7 @@ pub fn get_instance_actor(
public_key_pem: public_key_pem, public_key_pem: public_key_pem,
}; };
let actor = Actor { let actor = Actor {
context: Some(json!([ context: Some(json!(build_actor_context())),
AP_CONTEXT.to_string(),
W3ID_SECURITY_CONTEXT.to_string(),
])),
id: actor_id, id: actor_id,
object_type: SERVICE.to_string(), object_type: SERVICE.to_string(),
name: Some(instance.hostname()), name: Some(instance.hostname()),

View file

@ -4,6 +4,11 @@ pub const AS_MEDIA_TYPE: &str = "application/activity+json";
// Contexts // Contexts
pub const AP_CONTEXT: &str = "https://www.w3.org/ns/activitystreams"; pub const AP_CONTEXT: &str = "https://www.w3.org/ns/activitystreams";
pub const AP_PUBLIC: &str = "https://www.w3.org/ns/activitystreams#Public";
pub const W3ID_SECURITY_CONTEXT: &str = "https://w3id.org/security/v1"; pub const W3ID_SECURITY_CONTEXT: &str = "https://w3id.org/security/v1";
pub const W3ID_DATA_INTEGRITY_CONTEXT: &str = "https://w3id.org/security/data-integrity/v1"; pub const W3ID_DATA_INTEGRITY_CONTEXT: &str = "https://w3id.org/security/data-integrity/v1";
pub const SCHEMA_ORG_CONTEXT: &str = "http://schema.org/";
pub const MASTODON_CONTEXT: &str = "http://joinmastodon.org/ns#";
pub const MITRA_CONTEXT: &str = "http://jsonld.mitra.social#";
// Misc
pub const AP_PUBLIC: &str = "https://www.w3.org/ns/activitystreams#Public";