mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-19 03:25:29 +00:00
Fix fetch_local_site_data
This commit is contained in:
parent
53a1837f38
commit
b375b693be
@ -118,10 +118,7 @@ impl SiteOrCommunity {
|
||||
}
|
||||
}
|
||||
|
||||
async fn generate_cc(
|
||||
target: &SiteOrCommunity,
|
||||
mut conn: impl DbConn,
|
||||
) -> Result<Vec<Url>, LemmyError> {
|
||||
async fn generate_cc(target: &SiteOrCommunity, conn: impl DbConn) -> Result<Vec<Url>, LemmyError> {
|
||||
Ok(match target {
|
||||
SiteOrCommunity::Site(_) => Site::read_remote_sites(conn)
|
||||
.await?
|
||||
|
@ -33,7 +33,7 @@ pub async fn resolve_object(
|
||||
async fn convert_response(
|
||||
object: SearchableObjects,
|
||||
user_id: PersonId,
|
||||
mut conn: impl DbConn,
|
||||
conn: impl DbConn,
|
||||
) -> Result<Json<ResolveObjectResponse>, LemmyError> {
|
||||
use SearchableObjects::*;
|
||||
let removed_or_deleted;
|
||||
|
@ -9,7 +9,7 @@ use lemmy_db_schema::{
|
||||
local_site::LocalSite,
|
||||
},
|
||||
traits::Crud,
|
||||
utils::{get_conn, DbConn, DbPool},
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
use lemmy_utils::{error::LemmyError, settings::structs::Settings};
|
||||
use once_cell::sync::Lazy;
|
||||
@ -38,8 +38,7 @@ pub struct VerifyUrlData(pub DbPool);
|
||||
#[async_trait]
|
||||
impl UrlVerifier for VerifyUrlData {
|
||||
async fn verify(&self, url: &Url) -> Result<(), &'static str> {
|
||||
let mut conn = get_conn(&self.0).await.expect("get connection");
|
||||
let local_site_data = fetch_local_site_data(&mut *conn)
|
||||
let local_site_data = fetch_local_site_data(&self.0)
|
||||
.await
|
||||
.expect("read local site data");
|
||||
check_apub_id_valid(url, &local_site_data)?;
|
||||
@ -99,12 +98,12 @@ pub(crate) struct LocalSiteData {
|
||||
}
|
||||
|
||||
pub(crate) async fn fetch_local_site_data(
|
||||
mut conn: impl DbConn,
|
||||
pool: &DbPool,
|
||||
) -> Result<LocalSiteData, diesel::result::Error> {
|
||||
// LocalSite may be missing
|
||||
let local_site = LocalSite::read(&mut *conn).await.ok();
|
||||
let allowed_instances = Instance::allowlist(&mut *conn).await?;
|
||||
let blocked_instances = Instance::blocklist(&mut *conn).await?;
|
||||
let local_site = LocalSite::read(get_conn(pool).await?).await.ok();
|
||||
let allowed_instances = Instance::allowlist(get_conn(pool).await?).await?;
|
||||
let blocked_instances = Instance::blocklist(get_conn(pool).await?).await?;
|
||||
|
||||
Ok(LocalSiteData {
|
||||
local_site,
|
||||
|
@ -132,7 +132,7 @@ impl Object for ApubComment {
|
||||
verify_domains_match(note.attributed_to.inner(), note.id.inner())?;
|
||||
verify_is_public(¬e.to, ¬e.cc)?;
|
||||
let community = note.community(context).await?;
|
||||
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
|
||||
let local_site_data = fetch_local_site_data(context.pool()).await?;
|
||||
|
||||
check_apub_id_valid_with_strictness(
|
||||
note.id.inner(),
|
||||
|
@ -188,7 +188,7 @@ impl ApubCommunity {
|
||||
) -> Result<Vec<Url>, LemmyError> {
|
||||
let id = self.id;
|
||||
|
||||
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
|
||||
let local_site_data = fetch_local_site_data(context.pool()).await?;
|
||||
let follows = CommunityFollowerView::for_community(context.conn().await?, id).await?;
|
||||
let inboxes: Vec<Url> = follows
|
||||
.into_iter()
|
||||
|
@ -113,7 +113,7 @@ impl Object for ApubSite {
|
||||
expected_domain: &Url,
|
||||
data: &Data<Self::DataType>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let local_site_data = fetch_local_site_data(data.conn().await?).await?;
|
||||
let local_site_data = fetch_local_site_data(data.pool()).await?;
|
||||
|
||||
check_apub_id_valid_with_strictness(apub.id.inner(), true, &local_site_data, data.settings())?;
|
||||
verify_domains_match(expected_domain, apub.id.inner())?;
|
||||
|
@ -118,7 +118,7 @@ impl Object for ApubPerson {
|
||||
expected_domain: &Url,
|
||||
context: &Data<Self::DataType>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
|
||||
let local_site_data = fetch_local_site_data(context.pool()).await?;
|
||||
let slur_regex = &local_site_opt_to_slur_regex(&local_site_data.local_site);
|
||||
|
||||
check_slurs(&person.preferred_username, slur_regex)?;
|
||||
|
@ -143,7 +143,7 @@ impl Object for ApubPost {
|
||||
verify_is_remote_object(page.id.inner(), context.settings())?;
|
||||
};
|
||||
|
||||
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
|
||||
let local_site_data = fetch_local_site_data(context.pool()).await?;
|
||||
|
||||
let community = page.community(context).await?;
|
||||
check_apub_id_valid_with_strictness(
|
||||
|
@ -102,7 +102,7 @@ impl Object for ApubPrivateMessage {
|
||||
verify_domains_match(note.id.inner(), expected_domain)?;
|
||||
verify_domains_match(note.attributed_to.inner(), note.id.inner())?;
|
||||
|
||||
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
|
||||
let local_site_data = fetch_local_site_data(context.pool()).await?;
|
||||
|
||||
check_apub_id_valid_with_strictness(
|
||||
note.id.inner(),
|
||||
|
@ -80,7 +80,7 @@ impl Group {
|
||||
expected_domain: &Url,
|
||||
context: &LemmyContext,
|
||||
) -> Result<(), LemmyError> {
|
||||
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
|
||||
let local_site_data = fetch_local_site_data(context.pool()).await?;
|
||||
|
||||
check_apub_id_valid_with_strictness(
|
||||
self.id.inner(),
|
||||
|
Loading…
Reference in New Issue
Block a user