fix: split again auth filter

i hate having to do this, but if i don't include `activity.actor` column
we can't see our own activities (likes, announces, follows), and if i do
all queries which don't bring up activities break. so it's necessary to
split these two in order to manually include the extra filter when
needed
This commit is contained in:
əlemi 2024-12-10 23:21:52 +01:00
parent e18bf6e955
commit cdfdf3ee07
Signed by: alemi
GPG key ID: A4895B84D311642C
8 changed files with 28 additions and 11 deletions

View file

@ -24,7 +24,7 @@ pub async fn view(
} }
let row = upub::Query::feed(auth.my_id()) let row = upub::Query::feed(auth.my_id())
.filter(auth.filter()) .filter(auth.filter_activities())
.filter(model::activity::Column::Id.eq(&aid)) .filter(model::activity::Column::Id.eq(&aid))
.into_model::<RichActivity>() .into_model::<RichActivity>()
.one(ctx.db()) .one(ctx.db())

View file

@ -20,7 +20,7 @@ pub async fn page(
) -> crate::ApiResult<JsonLD<serde_json::Value>> { ) -> crate::ApiResult<JsonLD<serde_json::Value>> {
let uid = ctx.uid(&id); let uid = ctx.uid(&id);
let filter = Condition::all() let filter = Condition::all()
.add(auth.filter()) .add(auth.filter_activities())
.add( .add(
Condition::any() Condition::any()
.add(model::activity::Column::Actor.eq(&uid)) .add(model::activity::Column::Actor.eq(&uid))

View file

@ -52,7 +52,7 @@ pub async fn search(
} }
let filter = Condition::all() let filter = Condition::all()
.add(auth.filter()) .add(auth.filter_activities())
.add(upub::model::object::Column::Content.like(format!("%{}%", page.q))); .add(upub::model::object::Column::Content.like(format!("%{}%", page.q)));
// TODO lmao rethink this all // TODO lmao rethink this all

View file

@ -12,7 +12,7 @@ pub async fn get(
let context = ctx.oid(&id); let context = ctx.oid(&id);
let count = upub::Query::objects(auth.my_id()) let count = upub::Query::objects(auth.my_id())
.filter(auth.filter()) .filter(auth.filter_objects())
.filter(model::object::Column::Context.eq(&context)) .filter(model::object::Column::Context.eq(&context))
.count(ctx.db()) .count(ctx.db())
.await?; .await?;
@ -31,7 +31,7 @@ pub async fn page(
let offset = page.offset.unwrap_or(0); let offset = page.offset.unwrap_or(0);
let items = upub::Query::objects(auth.my_id()) let items = upub::Query::objects(auth.my_id())
.filter(auth.filter()) .filter(auth.filter_objects())
.filter(model::object::Column::Context.eq(context)) .filter(model::object::Column::Context.eq(context))
// note that this should be ASC so we get replies somewhat ordered // note that this should be ASC so we get replies somewhat ordered
.order_by(model::object::Column::Published, Order::Asc) .order_by(model::object::Column::Published, Order::Asc)

View file

@ -28,7 +28,7 @@ pub async fn view(
} }
let item = upub::Query::objects(auth.my_id()) let item = upub::Query::objects(auth.my_id())
.filter(auth.filter()) .filter(auth.filter_objects())
.filter(model::object::Column::Id.eq(&oid)) .filter(model::object::Column::Id.eq(&oid))
.into_model::<RichActivity>() .into_model::<RichActivity>()
.one(ctx.db()) .one(ctx.db())
@ -45,7 +45,7 @@ pub async fn view(
if ctx.cfg().security.show_reply_ids { if ctx.cfg().security.show_reply_ids {
let replies_ids = upub::Query::objects(auth.my_id()) let replies_ids = upub::Query::objects(auth.my_id())
.filter(auth.filter()) .filter(auth.filter_objects())
.filter(model::object::Column::InReplyTo.eq(oid)) .filter(model::object::Column::InReplyTo.eq(oid))
.select_only() .select_only()
.select_column(model::object::Column::Id) .select_column(model::object::Column::Id)

View file

@ -22,7 +22,7 @@ pub async fn get(
} }
let replies_ids = upub::Query::objects(auth.my_id()) let replies_ids = upub::Query::objects(auth.my_id())
.filter(auth.filter()) .filter(auth.filter_objects())
.filter(model::object::Column::InReplyTo.eq(ctx.oid(&id))) .filter(model::object::Column::InReplyTo.eq(ctx.oid(&id)))
.select_only() .select_only()
.select_column(model::object::Column::Id) .select_column(model::object::Column::Id)
@ -56,7 +56,7 @@ pub async fn page(
crate::builders::paginate_feed( crate::builders::paginate_feed(
page_id, page_id,
Condition::all() Condition::all()
.add(auth.filter()) .add(auth.filter_activities())
.add(model::object::Column::InReplyTo.eq(oid)), .add(model::object::Column::InReplyTo.eq(oid)),
ctx.db(), ctx.db(),
page, page,

View file

@ -25,7 +25,7 @@ pub async fn page(
let offset = page.offset.unwrap_or(0); let offset = page.offset.unwrap_or(0);
let objects = upub::Query::hashtags() let objects = upub::Query::hashtags()
.filter(auth.filter()) .filter(auth.filter_objects())
.filter(upub::model::hashtag::Column::Name.eq(&id)) .filter(upub::model::hashtag::Column::Name.eq(&id))
.limit(limit) .limit(limit)
.offset(offset) .offset(offset)

View file

@ -20,7 +20,24 @@ pub enum Identity {
} }
impl Identity { impl Identity {
pub fn filter(&self) -> Condition { // TODO i hate having to do this, but if i don't include `activity.actor` column
// we can't see our own activities (likes, announces, follows), and if i do
// all queries which don't bring up activities break. so it's necessary to
// split these two in order to manually include the extra filter when
// needed
pub fn filter_objects(&self) -> Condition {
let base_cond = Condition::any().add(upub::model::addressing::Column::Actor.is_null());
match self {
Identity::Anonymous => base_cond,
Identity::Remote { internal, .. } => base_cond.add(upub::model::addressing::Column::Instance.eq(*internal)),
Identity::Local { internal, id } => base_cond
.add(upub::model::addressing::Column::Actor.eq(*internal))
.add(upub::model::object::Column::AttributedTo.eq(id))
}
}
pub fn filter_activities(&self) -> Condition {
let base_cond = Condition::any().add(upub::model::addressing::Column::Actor.is_null()); let base_cond = Condition::any().add(upub::model::addressing::Column::Actor.is_null());
match self { match self {
Identity::Anonymous => base_cond, Identity::Anonymous => base_cond,