add: forges ui
TODO: forges tickets feed, posts open/closed state
This commit is contained in:
parent
5b1db42c51
commit
a6140f7c8c
40 changed files with 1664 additions and 1270 deletions
|
@ -11,14 +11,12 @@ use axum_extra::extract::CookieJar;
|
|||
use serde::Deserialize;
|
||||
use tera::Context;
|
||||
use tetratto_core::model::{
|
||||
auth::User,
|
||||
communities::{Community, CommunityReadAccess},
|
||||
communities_permissions::CommunityPermission,
|
||||
permissions::FinePermission,
|
||||
Error,
|
||||
auth::User, communities::Community, communities_permissions::CommunityPermission,
|
||||
permissions::FinePermission, Error,
|
||||
};
|
||||
|
||||
macro_rules! check_permissions {
|
||||
#[macro_export]
|
||||
macro_rules! check_community_permissions {
|
||||
($community:ident, $jar:ident, $data:ident, $user:ident) => {{
|
||||
let mut is_member: bool = false;
|
||||
let mut can_manage_pins: bool = false;
|
||||
|
@ -54,7 +52,7 @@ macro_rules! check_permissions {
|
|||
}
|
||||
|
||||
match $community.read_access {
|
||||
CommunityReadAccess::Joined => {
|
||||
tetratto_core::model::communities::CommunityReadAccess::Joined => {
|
||||
if !can_manage_communities {
|
||||
if !is_member {
|
||||
(false, can_manage_pins)
|
||||
|
@ -70,6 +68,7 @@ macro_rules! check_permissions {
|
|||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! community_context_bools {
|
||||
($data:ident, $user:ident, $community:ident) => {{
|
||||
let membership = if let Some(ref ua) = $user {
|
||||
|
@ -98,7 +97,9 @@ macro_rules! community_context_bools {
|
|||
};
|
||||
|
||||
let is_pending = if let Some(ref membership) = membership {
|
||||
membership.role.check(CommunityPermission::REQUESTED)
|
||||
membership.role.check(
|
||||
tetratto_core::model::communities_permissions::CommunityPermission::REQUESTED,
|
||||
)
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
@ -110,25 +111,27 @@ macro_rules! community_context_bools {
|
|||
};
|
||||
|
||||
let can_manage_posts = if let Some(ref membership) = membership {
|
||||
membership.role.check(CommunityPermission::MANAGE_POSTS)
|
||||
membership.role.check(
|
||||
tetratto_core::model::communities_permissions::CommunityPermission::MANAGE_POSTS,
|
||||
)
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let can_manage_community = if let Some(ref membership) = membership {
|
||||
membership.role.check(CommunityPermission::MANAGE_COMMUNITY)
|
||||
membership.role.check(tetratto_core::model::communities_permissions::CommunityPermission::MANAGE_COMMUNITY)
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let can_manage_roles = if let Some(ref membership) = membership {
|
||||
membership.role.check(CommunityPermission::MANAGE_ROLES)
|
||||
membership.role.check(tetratto_core::model::communities_permissions::CommunityPermission::MANAGE_ROLES)
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let can_manage_questions = if let Some(ref membership) = membership {
|
||||
membership.role.check(CommunityPermission::MANAGE_QUESTIONS)
|
||||
membership.role.check(tetratto_core::model::communities_permissions::CommunityPermission::MANAGE_QUESTIONS)
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
@ -389,7 +392,7 @@ pub async fn feed_request(
|
|||
}
|
||||
|
||||
// check permissions
|
||||
let (can_read, _) = check_permissions!(community, jar, data, user);
|
||||
let (can_read, _) = check_community_permissions!(community, jar, data, user);
|
||||
|
||||
// ...
|
||||
let ignore_users = crate::ignore_users_gen!(user, data);
|
||||
|
@ -487,7 +490,7 @@ pub async fn questions_request(
|
|||
}
|
||||
|
||||
// check permissions
|
||||
let (can_read, _) = check_permissions!(community, jar, data, user);
|
||||
let (can_read, _) = check_community_permissions!(community, jar, data, user);
|
||||
|
||||
// ...
|
||||
let ignore_users = crate::ignore_users_gen!(user, data);
|
||||
|
@ -724,7 +727,7 @@ pub async fn post_request(
|
|||
};
|
||||
|
||||
// check permissions
|
||||
let (can_read, can_manage_pins) = check_permissions!(community, jar, data, user);
|
||||
let (can_read, can_manage_pins) = check_community_permissions!(community, jar, data, user);
|
||||
|
||||
if !can_read {
|
||||
return Err(Html(
|
||||
|
@ -838,7 +841,7 @@ pub async fn reposts_request(
|
|||
};
|
||||
|
||||
// check permissions
|
||||
let (can_read, _) = check_permissions!(community, jar, data, user);
|
||||
let (can_read, _) = check_community_permissions!(community, jar, data, user);
|
||||
|
||||
if !can_read {
|
||||
return Err(Html(
|
||||
|
@ -989,7 +992,7 @@ pub async fn likes_request(
|
|||
};
|
||||
|
||||
// check permissions
|
||||
let (can_read, _) = check_permissions!(community, jar, data, ua);
|
||||
let (can_read, _) = check_community_permissions!(community, jar, data, ua);
|
||||
|
||||
if !can_read {
|
||||
return Err(Html(
|
||||
|
@ -1092,7 +1095,7 @@ pub async fn members_request(
|
|||
}
|
||||
|
||||
// check permissions
|
||||
let (can_read, _) = check_permissions!(community, jar, data, user);
|
||||
let (can_read, _) = check_community_permissions!(community, jar, data, user);
|
||||
|
||||
// ...
|
||||
let list = match data
|
||||
|
@ -1128,6 +1131,7 @@ pub async fn members_request(
|
|||
can_manage_questions,
|
||||
) = community_context_bools!(data, user, community);
|
||||
|
||||
context.insert("allow_for_forges", &true);
|
||||
context.insert("list", &list);
|
||||
context.insert("page", &props.page);
|
||||
context.insert("owner", &owner);
|
||||
|
@ -1187,7 +1191,7 @@ pub async fn question_request(
|
|||
};
|
||||
|
||||
// check permissions
|
||||
let (can_read, _) = check_permissions!(community, jar, data, user);
|
||||
let (can_read, _) = check_community_permissions!(community, jar, data, user);
|
||||
|
||||
if !can_read && !is_sender {
|
||||
return Err(Html(
|
||||
|
|
126
crates/app/src/routes/pages/forge.rs
Normal file
126
crates/app/src/routes/pages/forge.rs
Normal file
|
@ -0,0 +1,126 @@
|
|||
use super::{communities::community_context, render_error};
|
||||
use crate::{
|
||||
assets::initial_context, check_community_permissions, community_context_bools, get_lang,
|
||||
get_user_from_token, State,
|
||||
};
|
||||
use axum::{
|
||||
response::{Html, IntoResponse},
|
||||
extract::Path,
|
||||
Extension,
|
||||
};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{communities::Community, Error};
|
||||
|
||||
/// `/forges`
|
||||
pub async fn home_request(jar: CookieJar, Extension(data): Extension<State>) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let list = match data.0.get_memberships_by_owner(user.id).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
let mut communities: Vec<Community> = Vec::new();
|
||||
for membership in &list {
|
||||
match data
|
||||
.0
|
||||
.get_community_by_id_no_void(membership.community)
|
||||
.await
|
||||
{
|
||||
Ok(c) => {
|
||||
if c.is_forge {
|
||||
communities.push(c)
|
||||
} else {
|
||||
// we only want to show forges here
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
// delete membership; community doesn't exist
|
||||
if let Err(e) = data.0.delete_membership(membership.id, &user).await {
|
||||
return Err(Html(render_error(e, &jar, &data, &Some(user)).await));
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0.0, lang, &Some(user)).await;
|
||||
context.insert("list", &communities);
|
||||
|
||||
// return
|
||||
Ok(Html(data.1.render("forge/home.html", &context).unwrap()))
|
||||
}
|
||||
|
||||
/// `/forge/{title}`
|
||||
pub async fn info_request(
|
||||
jar: CookieJar,
|
||||
Path(title): Path<String>,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = get_user_from_token!(jar, data.0);
|
||||
|
||||
let community = match data.0.get_community_by_title(&title.to_lowercase()).await {
|
||||
Ok(ua) => ua,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
};
|
||||
|
||||
if community.id == 0 {
|
||||
// don't show page for void community
|
||||
return Err(Html(
|
||||
render_error(
|
||||
Error::GeneralNotFound("community".to_string()),
|
||||
&jar,
|
||||
&data,
|
||||
&user,
|
||||
)
|
||||
.await,
|
||||
));
|
||||
}
|
||||
|
||||
// check permissions
|
||||
let (can_read, _) = check_community_permissions!(community, jar, data, user);
|
||||
|
||||
// init context
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0.0, lang, &user).await;
|
||||
|
||||
let (
|
||||
is_owner,
|
||||
is_joined,
|
||||
is_pending,
|
||||
can_post,
|
||||
can_manage_posts,
|
||||
can_manage_community,
|
||||
can_manage_roles,
|
||||
can_manage_questions,
|
||||
) = community_context_bools!(data, user, community);
|
||||
|
||||
community_context(
|
||||
&mut context,
|
||||
&community,
|
||||
is_owner,
|
||||
is_joined,
|
||||
is_pending,
|
||||
can_post,
|
||||
can_read,
|
||||
can_manage_posts,
|
||||
can_manage_community,
|
||||
can_manage_roles,
|
||||
can_manage_questions,
|
||||
);
|
||||
|
||||
// return
|
||||
Ok(Html(data.1.render("forge/info.html", &context).unwrap()))
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
pub mod auth;
|
||||
pub mod communities;
|
||||
pub mod forge;
|
||||
pub mod misc;
|
||||
pub mod mod_panel;
|
||||
pub mod profile;
|
||||
|
@ -110,6 +111,10 @@ pub fn routes() -> Router {
|
|||
"/chats/{community}/{channel}/_channels",
|
||||
get(chats::channels_request),
|
||||
)
|
||||
// forge
|
||||
.route("/forges", get(forge::home_request))
|
||||
.route("/forge/{title}", get(forge::info_request))
|
||||
.route("/forge/{title}/members", get(communities::members_request))
|
||||
// stacks
|
||||
.route("/stacks", get(stacks::list_request))
|
||||
.route("/stacks/{id}", get(stacks::posts_request))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue