mirror of https://github.com/LemmyNet/lemmy
Merge `/site_inbox` into `/inbox`, remove unique constraint for inboxes (#4138)
* Merge /site_inbox into /inbox (fixes #4137) Get rid of different inboxes, only use /inbox Remove shared_inbox_url db columns add code migration move to db migration, fixes machete fix sql drop inbox url unique constraints Dont create auth cookie in backend (#4136) dont change individual inboxes to shared inbox Dont send comment reply to user who has community blocked. Fixes #3684 (#4096) * Dont send comment reply to user who has community blocked. Fixes #3684 * Adding source instance block check. * Adding api test. * Addressing PR comments. * move site inbox rewrite to db * fix test * clippy * clippy 2 * fix testpull/4168/head^2
parent
a53892d2bb
commit
a00313e680
@ -1,77 +0,0 @@
|
||||
use crate::{
|
||||
activities::{generate_activity_id, send_lemmy_activity, verify_is_public, verify_person},
|
||||
insert_received_activity,
|
||||
objects::person::ApubPerson,
|
||||
protocol::activities::deletion::delete_user::DeleteUser,
|
||||
};
|
||||
use activitypub_federation::{
|
||||
config::Data,
|
||||
kinds::{activity::DeleteType, public},
|
||||
protocol::verification::verify_urls_match,
|
||||
traits::{ActivityHandler, Actor},
|
||||
};
|
||||
use lemmy_api_common::{context::LemmyContext, utils::purge_user_account};
|
||||
use lemmy_db_schema::source::{activity::ActivitySendTargets, person::Person};
|
||||
use lemmy_utils::error::LemmyError;
|
||||
use url::Url;
|
||||
|
||||
pub async fn delete_user(
|
||||
person: Person,
|
||||
delete_content: bool,
|
||||
context: Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let actor: ApubPerson = person.into();
|
||||
|
||||
let id = generate_activity_id(
|
||||
DeleteType::Delete,
|
||||
&context.settings().get_protocol_and_hostname(),
|
||||
)?;
|
||||
let delete = DeleteUser {
|
||||
actor: actor.id().into(),
|
||||
to: vec![public()],
|
||||
object: actor.id().into(),
|
||||
kind: DeleteType::Delete,
|
||||
id: id.clone(),
|
||||
cc: vec![],
|
||||
remove_data: Some(delete_content),
|
||||
};
|
||||
|
||||
let inboxes = ActivitySendTargets::to_all_instances();
|
||||
|
||||
send_lemmy_activity(&context, delete, &actor, inboxes, true).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// This can be separate from Delete activity because it doesn't need to be handled in shared inbox
|
||||
/// (cause instance actor doesn't have shared inbox).
|
||||
#[async_trait::async_trait]
|
||||
impl ActivityHandler for DeleteUser {
|
||||
type DataType = LemmyContext;
|
||||
type Error = LemmyError;
|
||||
|
||||
fn id(&self) -> &Url {
|
||||
&self.id
|
||||
}
|
||||
|
||||
fn actor(&self) -> &Url {
|
||||
self.actor.inner()
|
||||
}
|
||||
|
||||
async fn verify(&self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
|
||||
insert_received_activity(&self.id, context).await?;
|
||||
verify_is_public(&self.to, &[])?;
|
||||
verify_person(&self.actor, context).await?;
|
||||
verify_urls_match(self.actor.inner(), self.object.inner())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
|
||||
let actor = self.actor.dereference(context).await?;
|
||||
if self.remove_data.unwrap_or(false) {
|
||||
purge_user_account(actor.id, context).await?;
|
||||
} else {
|
||||
Person::delete_account(&mut context.pool(), actor.id).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
ALTER TABLE person
|
||||
ADD CONSTRAINT idx_person_inbox_url UNIQUE (inbox_url);
|
||||
|
||||
ALTER TABLE community
|
||||
ADD CONSTRAINT idx_community_inbox_url UNIQUE (inbox_url);
|
||||
|
||||
UPDATE
|
||||
site
|
||||
SET
|
||||
inbox_url = inbox_query.inbox
|
||||
FROM (
|
||||
SELECT
|
||||
format('https://%s/site_inbox', DOMAIN) AS inbox
|
||||
FROM
|
||||
instance,
|
||||
site,
|
||||
local_site
|
||||
WHERE
|
||||
instance.id = site.instance_id
|
||||
AND local_site.id = site.id) AS inbox_query,
|
||||
instance,
|
||||
local_site
|
||||
WHERE
|
||||
instance.id = site.instance_id
|
||||
AND local_site.id = site.id;
|
||||
|
@ -0,0 +1,30 @@
|
||||
-- drop unique constraints for inbox columns
|
||||
ALTER TABLE person
|
||||
DROP CONSTRAINT idx_person_inbox_url;
|
||||
|
||||
ALTER TABLE community
|
||||
DROP CONSTRAINT idx_community_inbox_url;
|
||||
|
||||
-- change site inbox path from /inbox to /site_inbox
|
||||
-- we dont have any way here to set the correct protocol (http or https) according to tls_enabled, or set
|
||||
-- the correct port in case of debugging
|
||||
UPDATE
|
||||
site
|
||||
SET
|
||||
inbox_url = inbox_query.inbox
|
||||
FROM (
|
||||
SELECT
|
||||
format('https://%s/inbox', DOMAIN) AS inbox
|
||||
FROM
|
||||
instance,
|
||||
site,
|
||||
local_site
|
||||
WHERE
|
||||
instance.id = site.instance_id
|
||||
AND local_site.id = site.id) AS inbox_query,
|
||||
instance,
|
||||
local_site
|
||||
WHERE
|
||||
instance.id = site.instance_id
|
||||
AND local_site.id = site.id;
|
||||
|
Loading…
Reference in New Issue