mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Added the list_topics and list_nodes role flags, Filtered the nodes listed by the roles
- `list_topics` / `list_nodes`: listing answers every topic, every node with messages, without reading any (`query` gives both). - Without them, listing nodes only answers those with messages in the topics the roles may read (every node until now). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -473,20 +473,41 @@ async fn get_messages(shared: &Arc<Shared>, peer: &Peer, get: GetMessages) -> Pa
|
||||
}
|
||||
|
||||
/// Topics: those with messages (pushed here or replicated) that it may
|
||||
/// push to or read, every one if it may query (queries read everything).
|
||||
/// Nodes: every one with messages.
|
||||
/// push to or read; every one with `list_topics` or `query`. Nodes: those
|
||||
/// with messages in the topics it may read; every one with `list_nodes`
|
||||
/// or `query`.
|
||||
async fn list_names(shared: &Arc<Shared>, peer: &Peer, list: ListNames) -> Packet {
|
||||
let permissions = &peer.permissions;
|
||||
let found = match list.kind {
|
||||
NameKind::Topic => shared.read(|reader| reader.topics()).await,
|
||||
NameKind::Node => shared.read(|reader| reader.nodes()).await,
|
||||
NameKind::Topic => shared
|
||||
.read(|reader| reader.topics())
|
||||
.await
|
||||
.map(|mut topics| {
|
||||
if !permissions.lists_every_topic() {
|
||||
topics
|
||||
.retain(|topic| permissions.can_push(topic) || permissions.can_read(topic));
|
||||
}
|
||||
topics
|
||||
}),
|
||||
NameKind::Node if permissions.lists_every_node() => {
|
||||
shared.read(|reader| reader.nodes()).await
|
||||
}
|
||||
NameKind::Node => shared.read(|reader| reader.heads()).await.map(|heads| {
|
||||
let mut nodes: Vec<String> = heads
|
||||
.into_iter()
|
||||
.filter(|head| permissions.can_read(&head.topic))
|
||||
.map(|head| head.node)
|
||||
.collect();
|
||||
// As `reader.nodes()` answers them: in order, none twice.
|
||||
nodes.sort_by_cached_key(|node| node.to_ascii_lowercase());
|
||||
nodes.dedup_by(|a, b| names_equal(a, b));
|
||||
nodes
|
||||
}),
|
||||
};
|
||||
let mut names = match found {
|
||||
Ok(names) => names,
|
||||
Err(refused) => return refused.into(),
|
||||
};
|
||||
if list.kind == NameKind::Topic && !peer.permissions.can_query() {
|
||||
names.retain(|topic| peer.permissions.can_push(topic) || peer.permissions.can_read(topic));
|
||||
}
|
||||
let truncated = names.len() > MAX_NAMES_LIST_ENTRIES;
|
||||
names.truncate(MAX_NAMES_LIST_ENTRIES);
|
||||
NamesList {
|
||||
|
||||
Reference in New Issue
Block a user