only show public quotes to logged out users
This commit is contained in:
@@ -113,6 +113,20 @@ impl Quote {
|
|||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn get_newest_public(conn: &Connection) -> Result<Option<Quote>, QuoteError> {
|
||||||
|
let id: Option<Uuid> = conn
|
||||||
|
.query_row(
|
||||||
|
"SELECT id FROM quotes ORDER BY id DESC LIMIT 1 WHERE public = 1",
|
||||||
|
(),
|
||||||
|
|r| r.get(0),
|
||||||
|
)
|
||||||
|
.optional()?;
|
||||||
|
|
||||||
|
match id {
|
||||||
|
Some(id) => Ok(Some(Self::get_by_id(conn, id)?)),
|
||||||
|
None => Ok(None),
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn get_chronological_offset(
|
pub fn get_chronological_offset(
|
||||||
conn: &Connection,
|
conn: &Connection,
|
||||||
offset: i64,
|
offset: i64,
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ pub async fn page(req: Request) -> Result<Markup, CompositeError> {
|
|||||||
let u = User::authenticate(req.headers()).ok().flatten();
|
let u = User::authenticate(req.headers()).ok().flatten();
|
||||||
let conn = database::conn()?;
|
let conn = database::conn()?;
|
||||||
|
|
||||||
let newest_quote = Quote::get_newest(&conn)?;
|
let newest_quote = match u {
|
||||||
|
Some(_) => Quote::get_newest(&conn)?,
|
||||||
|
None => Quote::get_newest_public(&conn)?,
|
||||||
|
};
|
||||||
|
|
||||||
Ok(base(
|
Ok(base(
|
||||||
"Dashboard | Mnemosyne",
|
"Dashboard | Mnemosyne",
|
||||||
|
|||||||
Reference in New Issue
Block a user