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:
parent
e18bf6e955
commit
cdfdf3ee07
8 changed files with 28 additions and 11 deletions
|
@ -24,7 +24,7 @@ pub async fn view(
|
|||
}
|
||||
|
||||
let row = upub::Query::feed(auth.my_id())
|
||||
.filter(auth.filter())
|
||||
.filter(auth.filter_activities())
|
||||
.filter(model::activity::Column::Id.eq(&aid))
|
||||
.into_model::<RichActivity>()
|
||||
.one(ctx.db())
|
||||
|
|
|
@ -20,7 +20,7 @@ pub async fn page(
|
|||
) -> crate::ApiResult<JsonLD<serde_json::Value>> {
|
||||
let uid = ctx.uid(&id);
|
||||
let filter = Condition::all()
|
||||
.add(auth.filter())
|
||||
.add(auth.filter_activities())
|
||||
.add(
|
||||
Condition::any()
|
||||
.add(model::activity::Column::Actor.eq(&uid))
|
||||
|
|
|
@ -52,7 +52,7 @@ pub async fn search(
|
|||
}
|
||||
|
||||
let filter = Condition::all()
|
||||
.add(auth.filter())
|
||||
.add(auth.filter_activities())
|
||||
.add(upub::model::object::Column::Content.like(format!("%{}%", page.q)));
|
||||
|
||||
// TODO lmao rethink this all
|
||||
|
|
|
@ -12,7 +12,7 @@ pub async fn get(
|
|||
let context = ctx.oid(&id);
|
||||
|
||||
let count = upub::Query::objects(auth.my_id())
|
||||
.filter(auth.filter())
|
||||
.filter(auth.filter_objects())
|
||||
.filter(model::object::Column::Context.eq(&context))
|
||||
.count(ctx.db())
|
||||
.await?;
|
||||
|
@ -31,7 +31,7 @@ pub async fn page(
|
|||
let offset = page.offset.unwrap_or(0);
|
||||
|
||||
let items = upub::Query::objects(auth.my_id())
|
||||
.filter(auth.filter())
|
||||
.filter(auth.filter_objects())
|
||||
.filter(model::object::Column::Context.eq(context))
|
||||
// note that this should be ASC so we get replies somewhat ordered
|
||||
.order_by(model::object::Column::Published, Order::Asc)
|
||||
|
|
|
@ -28,7 +28,7 @@ pub async fn view(
|
|||
}
|
||||
|
||||
let item = upub::Query::objects(auth.my_id())
|
||||
.filter(auth.filter())
|
||||
.filter(auth.filter_objects())
|
||||
.filter(model::object::Column::Id.eq(&oid))
|
||||
.into_model::<RichActivity>()
|
||||
.one(ctx.db())
|
||||
|
@ -45,7 +45,7 @@ pub async fn view(
|
|||
|
||||
if ctx.cfg().security.show_reply_ids {
|
||||
let replies_ids = upub::Query::objects(auth.my_id())
|
||||
.filter(auth.filter())
|
||||
.filter(auth.filter_objects())
|
||||
.filter(model::object::Column::InReplyTo.eq(oid))
|
||||
.select_only()
|
||||
.select_column(model::object::Column::Id)
|
||||
|
|
|
@ -22,7 +22,7 @@ pub async fn get(
|
|||
}
|
||||
|
||||
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)))
|
||||
.select_only()
|
||||
.select_column(model::object::Column::Id)
|
||||
|
@ -56,7 +56,7 @@ pub async fn page(
|
|||
crate::builders::paginate_feed(
|
||||
page_id,
|
||||
Condition::all()
|
||||
.add(auth.filter())
|
||||
.add(auth.filter_activities())
|
||||
.add(model::object::Column::InReplyTo.eq(oid)),
|
||||
ctx.db(),
|
||||
page,
|
||||
|
|
|
@ -25,7 +25,7 @@ pub async fn page(
|
|||
let offset = page.offset.unwrap_or(0);
|
||||
|
||||
let objects = upub::Query::hashtags()
|
||||
.filter(auth.filter())
|
||||
.filter(auth.filter_objects())
|
||||
.filter(upub::model::hashtag::Column::Name.eq(&id))
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
|
|
|
@ -20,7 +20,24 @@ pub enum 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());
|
||||
match self {
|
||||
Identity::Anonymous => base_cond,
|
||||
|
|
Loading…
Reference in a new issue