add: individual topic write permissions

This commit is contained in:
trisua 2025-08-04 13:23:27 -04:00
parent 3738a5cd1f
commit 8c779b2f2e
6 changed files with 80 additions and 9 deletions

View file

@ -686,12 +686,12 @@
(div
("class" "flex flex_col gap_1")
(label
("for" "description")
("for" "{{ id }}-description")
(str (text "communities:label.description")))
(input
("type" "text")
("name" "description")
("id" "description")
("id" "{{ id }}-description")
("placeholder" "description")
("value" "{{ topic.description }}")
("required" "")
@ -700,12 +700,12 @@
(div
("class" "flex flex_col gap_1")
(label
("for" "color")
("for" "{{ id }}-color")
(str (text "communities:label.color")))
(input
("type" "color")
("name" "color")
("id" "color")
("id" "{{ id }}-color")
("placeholder" "color")
("required" "")
("value" "{{ topic.color }}")
@ -713,17 +713,37 @@
(div
("class" "flex flex_col gap_1")
(label
("for" "position")
("for" "{{ id }}-position")
(str (text "communities:label.position")))
(input
("type" "number")
("name" "position")
("id" "position")
("id" "{{ id }}-position")
("placeholder" "position")
("required" "")
("value" "{{ topic.position }}")
("min" "0")
("max" "256")))
(div
("class" "flex flex_col gap_1")
(label
("for" "{{ id }}-write_access")
(text "Post permission"))
(select
("name" "write_access")
("id" "{{ id }}-write_access")
(option
("value" "Everybody")
("selected" "{% if topic.write_access == 'Everybody' -%}true{% else %}false{%- endif %}")
(text "Everybody"))
(option
("value" "Joined")
("selected" "{% if topic.write_access == 'Joined' -%}true{% else %}false{%- endif %}")
(text "Joined"))
(option
("value" "Owner")
("selected" "{% if topic.write_access == 'Owner' -%}true{% else %}false{%- endif %}")
(text "Owner only"))))
(button
(icon (text "check"))
(str (text "general:action.save")))))))
@ -794,6 +814,7 @@
description: e.target.description.value,
color: e.target.color.value,
position: Number.parseInt(e.target.position.value),
write_access: e.target.write_access.selectedOptions[0].value,
}),
})
.then((res) => res.json())

View file

@ -9,6 +9,7 @@
(text "{{ components::topic_display(id=topic_id, topic=topic, community=community, show_description=false) }}")
(div
("class" "flex gap_2")
(text "{% if can_post -%}")
(a
("href" "/communities/intents/post?community={{ community.id }}&topic={{ topic_id }}&sig=true")
("class" "button small lowered")
@ -16,6 +17,7 @@
(icon (text "plus"))
(span
(str (text "general:action.post"))))
(text "{%- endif %}")
(a
("href" "/community/{{ community.title }}")
("class" "button lowered small")

View file

@ -560,7 +560,13 @@ pub async fn add_topic_request(
}
// ...
let (topic_id, topic) = ForumTopic::new(req.title, req.description, req.color, req.position);
let (topic_id, topic) = ForumTopic::new(
req.title,
req.description,
req.color,
req.position,
community.write_access,
);
community.topics.insert(topic_id, topic);
match data
@ -616,6 +622,7 @@ pub async fn update_topic_request(
description: req.description,
color: req.color,
position: req.position,
write_access: req.write_access,
};
community.topics.insert(topic_id, topic);

View file

@ -797,6 +797,8 @@ pub struct AddTopic {
pub color: String,
#[serde(default)]
pub position: i32,
#[serde(default)]
pub write_access: CommunityWriteAccess,
}
#[derive(Deserialize)]