fix: make journal and note titles lowercase add: remove journal index
route
This commit is contained in:
parent
1b1c1c0bea
commit
eb5a0d146f
7 changed files with 85 additions and 7 deletions
|
@ -65,7 +65,7 @@
|
|||
|
||||
(a
|
||||
("class" "flush")
|
||||
("href" "{% if view_mode -%} /@{{ owner.username }}/{{ journal.title }}/index {%- else -%} /journals/{{ journal.id }}/0 {%- endif %}")
|
||||
("href" "{% if view_mode -%} /@{{ owner.username }}/{{ journal.title }} {%- else -%} /journals/{{ journal.id }}/0 {%- endif %}")
|
||||
(b (text "{{ journal.title }}")))
|
||||
|
||||
(text "{% if note -%}")
|
||||
|
@ -83,7 +83,7 @@
|
|||
(icon (text "pencil")))
|
||||
(a
|
||||
("class" "{% if view_mode -%}active{%- endif %}")
|
||||
("href" "/@{{ user.username }}/{{ journal.title }}/{% if note -%} {{ note.title }} {%- else -%} index {%- endif %}")
|
||||
("href" "/@{{ user.username }}/{{ journal.title }}{% if note -%} /{{ note.title }} {%- endif %}")
|
||||
(icon (text "eye"))))
|
||||
(text "{%- endif %}"))
|
||||
(text "{%- endif %}")
|
||||
|
|
|
@ -102,7 +102,7 @@ pub async fn update_title_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
props.title = props.title.replace(" ", "_");
|
||||
props.title = props.title.replace(" ", "_").to_lowercase();
|
||||
|
||||
// check name
|
||||
let regex = regex::RegexBuilder::new(NAME_REGEX)
|
||||
|
|
|
@ -138,7 +138,7 @@ pub async fn update_title_request(
|
|||
Err(e) => return Json(e.into()),
|
||||
};
|
||||
|
||||
props.title = props.title.replace(" ", "_");
|
||||
props.title = props.title.replace(" ", "_").to_lowercase();
|
||||
|
||||
// check name
|
||||
let regex = regex::RegexBuilder::new(NAME_REGEX)
|
||||
|
|
|
@ -207,3 +207,81 @@ pub async fn view_request(
|
|||
// return
|
||||
Ok(Html(data.1.render("journals/app.html", &context).unwrap()))
|
||||
}
|
||||
|
||||
/// `/@{owner}/{journal}`
|
||||
pub async fn index_view_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path((owner, selected_journal)): Path<(String, String)>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => Some(ua),
|
||||
None => None,
|
||||
};
|
||||
|
||||
// get owner
|
||||
let owner = match data.0.get_user_by_username(&owner).await {
|
||||
Ok(ua) => ua,
|
||||
Err(e) => {
|
||||
return Err(Html(render_error(e, &jar, &data, &user).await));
|
||||
}
|
||||
};
|
||||
|
||||
check_user_blocked_or_private!(user, owner, data, jar);
|
||||
|
||||
// get journal and check privacy settings
|
||||
let journal = match data
|
||||
.0
|
||||
.get_journal_by_owner_title(owner.id, &selected_journal)
|
||||
.await
|
||||
{
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
return Err(Html(render_error(e, &jar, &data, &user).await));
|
||||
}
|
||||
};
|
||||
|
||||
if journal.privacy == JournalPrivacyPermission::Private {
|
||||
if let Some(ref user) = user {
|
||||
if user.id != journal.owner {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &Some(user.to_owned())).await,
|
||||
));
|
||||
}
|
||||
} else {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &user).await,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
let notes = match data.0.get_notes_by_journal(journal.id).await {
|
||||
Ok(p) => Some(p),
|
||||
Err(e) => {
|
||||
return Err(Html(render_error(e, &jar, &data, &user).await));
|
||||
}
|
||||
};
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0.0, lang, &user).await;
|
||||
|
||||
if selected_journal.is_empty() {
|
||||
context.insert("selected_journal", &0);
|
||||
} else {
|
||||
context.insert("selected_journal", &selected_journal);
|
||||
}
|
||||
|
||||
context.insert("selected_note", &0);
|
||||
context.insert("journal", &journal);
|
||||
|
||||
context.insert("owner", &owner);
|
||||
context.insert("notes", ¬es);
|
||||
|
||||
context.insert("view_mode", &true);
|
||||
context.insert("is_editor", &false);
|
||||
|
||||
// return
|
||||
Ok(Html(data.1.render("journals/app.html", &context).unwrap()))
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ pub fn routes() -> Router {
|
|||
// journals
|
||||
.route("/journals", get(journals::redirect_request))
|
||||
.route("/journals/{journal}/{note}", get(journals::app_request))
|
||||
.route("/@{owner}/{journal}", get(journals::view_request))
|
||||
.route("/@{owner}/{journal}", get(journals::index_view_request))
|
||||
.route("/@{owner}/{journal}/{note}", get(journals::view_request))
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ impl DataManager {
|
|||
return Err(Error::DataTooLong("title".to_string()));
|
||||
}
|
||||
|
||||
data.title = data.title.replace(" ", "_");
|
||||
data.title = data.title.replace(" ", "_").to_lowercase();
|
||||
|
||||
// check name
|
||||
let regex = regex::RegexBuilder::new(NAME_REGEX)
|
||||
|
|
|
@ -83,7 +83,7 @@ impl DataManager {
|
|||
return Err(Error::DataTooLong("content".to_string()));
|
||||
}
|
||||
|
||||
data.title = data.title.replace(" ", "_");
|
||||
data.title = data.title.replace(" ", "_").to_lowercase();
|
||||
|
||||
// check name
|
||||
let regex = regex::RegexBuilder::new(NAME_REGEX)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue