fix: user community membership checks for timelines
This commit is contained in:
parent
0272985b81
commit
50f4592de2
4 changed files with 67 additions and 17 deletions
|
@ -1,8 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
use oiseau::cache::Cache;
|
||||
use crate::config::StringBan;
|
||||
use crate::model::auth::Notification;
|
||||
use crate::model::communities::{Poll, Question};
|
||||
use crate::model::communities::{CommunityMembership, CommunityReadAccess, Poll, Question};
|
||||
use crate::model::communities_permissions::CommunityPermission;
|
||||
use crate::model::moderation::AuditLogEntry;
|
||||
use crate::model::stacks::{StackMode, StackSort, UserStack};
|
||||
|
@ -16,7 +15,7 @@ use tetratto_shared::unix_epoch_timestamp;
|
|||
use crate::{auto_method, DataManager};
|
||||
|
||||
use oiseau::{PostgresRow, cache::redis::Commands};
|
||||
use oiseau::{execute, get, query_row, query_rows, params};
|
||||
use oiseau::{execute, get, query_row, query_rows, params, cache::Cache};
|
||||
|
||||
pub type FullPost = (
|
||||
Post,
|
||||
|
@ -479,6 +478,7 @@ impl DataManager {
|
|||
let mut seen_user_follow_statuses: HashMap<(usize, usize), bool> = HashMap::new();
|
||||
let mut seen_stacks: HashMap<usize, UserStack> = HashMap::new();
|
||||
let mut replying_posts: HashMap<usize, Post> = HashMap::new();
|
||||
let mut memberships: HashMap<usize, CommunityMembership> = HashMap::new();
|
||||
|
||||
for post in posts {
|
||||
if post.is_deleted {
|
||||
|
@ -493,6 +493,30 @@ impl DataManager {
|
|||
continue;
|
||||
}
|
||||
|
||||
// check membership
|
||||
if community.read_access == CommunityReadAccess::Joined {
|
||||
if let Some(user) = user {
|
||||
if let Some(membership) = memberships.get(&community.id) {
|
||||
if !membership.role.check(CommunityPermission::MEMBER) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if let Ok(membership) = self
|
||||
.get_membership_by_owner_community_no_void(user.id, community.id)
|
||||
.await
|
||||
{
|
||||
if !membership.role.check(CommunityPermission::MEMBER) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// stack
|
||||
let (can_view, stack) = self
|
||||
.get_post_stack(
|
||||
|
@ -537,6 +561,32 @@ impl DataManager {
|
|||
continue;
|
||||
}
|
||||
|
||||
// check membership
|
||||
let community = self.get_community_by_id(community).await?;
|
||||
if community.read_access == CommunityReadAccess::Joined {
|
||||
if let Some(user) = user {
|
||||
if let Some(membership) = memberships.get(&community.id) {
|
||||
if !membership.role.check(CommunityPermission::MEMBER) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if let Ok(membership) = self
|
||||
.get_membership_by_owner_community_no_void(user.id, community.id)
|
||||
.await
|
||||
{
|
||||
memberships.insert(owner, membership.clone());
|
||||
if !membership.role.check(CommunityPermission::MEMBER) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// check relationship
|
||||
if ua.settings.private_profile && ua.id != user_id {
|
||||
if user_id == 0 {
|
||||
|
@ -587,7 +637,6 @@ impl DataManager {
|
|||
}
|
||||
|
||||
// ...
|
||||
let community = self.get_community_by_id(community).await?;
|
||||
seen_before.insert((owner, community.id), (ua.clone(), community.clone()));
|
||||
out.push((
|
||||
post.clone(),
|
||||
|
|
|
@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
|
|||
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
|
||||
use super::communities_permissions::CommunityPermission;
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Community {
|
||||
pub id: usize,
|
||||
pub created: usize,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue