add: finish forge stuff
This commit is contained in:
parent
53fb4d5778
commit
68071b96c8
21 changed files with 329 additions and 18 deletions
|
@ -1,11 +1,11 @@
|
|||
use super::{communities::community_context, render_error};
|
||||
use super::{communities::community_context, render_error, PaginatedQuery};
|
||||
use crate::{
|
||||
assets::initial_context, check_community_permissions, community_context_bools, get_lang,
|
||||
get_user_from_token, State,
|
||||
};
|
||||
use axum::{
|
||||
extract::{Path, Query},
|
||||
response::{Html, IntoResponse},
|
||||
extract::Path,
|
||||
Extension,
|
||||
};
|
||||
use axum_extra::extract::CookieJar;
|
||||
|
@ -124,3 +124,93 @@ pub async fn info_request(
|
|||
// return
|
||||
Ok(Html(data.1.render("forge/info.html", &context).unwrap()))
|
||||
}
|
||||
|
||||
/// `/forge/{title}/tickets`
|
||||
pub async fn tickets_request(
|
||||
jar: CookieJar,
|
||||
Path(title): Path<String>,
|
||||
Query(props): Query<PaginatedQuery>,
|
||||
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);
|
||||
|
||||
// ...
|
||||
let ignore_users = crate::ignore_users_gen!(user, data);
|
||||
|
||||
let feed = match data
|
||||
.0
|
||||
.get_posts_by_community(community.id, 12, props.page)
|
||||
.await
|
||||
{
|
||||
Ok(p) => match data.0.fill_posts(p, &ignore_users, &user).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
},
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
};
|
||||
|
||||
// let pinned = match data.0.get_pinned_posts_by_community(community.id).await {
|
||||
// Ok(p) => match data.0.fill_posts(p, &ignore_users, &user).await {
|
||||
// Ok(p) => p,
|
||||
// Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
// },
|
||||
// Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
// };
|
||||
|
||||
// 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);
|
||||
|
||||
context.insert("feed", &feed);
|
||||
// context.insert("pinned", &pinned);
|
||||
context.insert("page", &props.page);
|
||||
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/tickets.html", &context).unwrap()))
|
||||
}
|
||||
|
|
|
@ -114,6 +114,7 @@ pub fn routes() -> Router {
|
|||
// forge
|
||||
.route("/forges", get(forge::home_request))
|
||||
.route("/forge/{title}", get(forge::info_request))
|
||||
.route("/forge/{title}/tickets", get(forge::tickets_request))
|
||||
.route("/forge/{title}/members", get(communities::members_request))
|
||||
// stacks
|
||||
.route("/stacks", get(stacks::list_request))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue