Merge branch 'staging' into 'main'
scheckbuch can't see logbuch See merge request PhilippHofer/rot!43
This commit is contained in:
commit
83394a2284
@ -59,6 +59,7 @@ pub enum LoginError {
|
||||
NotAnAdmin,
|
||||
NotACox,
|
||||
NotATech,
|
||||
GuestNotAllowed,
|
||||
NoPasswordSet(User),
|
||||
DeserializationError,
|
||||
}
|
||||
@ -464,6 +465,39 @@ impl<'r> FromRequest<'r> for AdminUser {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct NonGuestUser {
|
||||
pub(crate) user: User,
|
||||
}
|
||||
|
||||
impl TryFrom<User> for NonGuestUser {
|
||||
type Error = LoginError;
|
||||
|
||||
fn try_from(user: User) -> Result<Self, Self::Error> {
|
||||
if user.is_guest {
|
||||
Err(LoginError::GuestNotAllowed)
|
||||
} else {
|
||||
Ok(NonGuestUser { user })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'r> FromRequest<'r> for NonGuestUser {
|
||||
type Error = LoginError;
|
||||
|
||||
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
||||
match User::from_request(req).await {
|
||||
Outcome::Success(user) => match user.try_into() {
|
||||
Ok(user) => Outcome::Success(user),
|
||||
Err(_) => Outcome::Failure((Status::Unauthorized, LoginError::NotAnAdmin)),
|
||||
},
|
||||
Outcome::Failure(f) => Outcome::Failure(f),
|
||||
Outcome::Forward(f) => Outcome::Forward(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::testdb;
|
||||
|
@ -23,7 +23,7 @@ use crate::model::{
|
||||
LogbookUpdateError,
|
||||
},
|
||||
logtype::LogType,
|
||||
user::{User, UserWithWaterStatus},
|
||||
user::{NonGuestUser, User, UserWithWaterStatus},
|
||||
};
|
||||
|
||||
pub struct KioskCookie(String);
|
||||
@ -80,7 +80,7 @@ async fn index(db: &State<SqlitePool>, flash: Option<FlashMessage<'_>>, user: Us
|
||||
}
|
||||
|
||||
#[get("/show", rank = 2)]
|
||||
async fn show(db: &State<SqlitePool>, user: User) -> Template {
|
||||
async fn show(db: &State<SqlitePool>, user: NonGuestUser) -> Template {
|
||||
let logs = Logbook::completed(db).await;
|
||||
|
||||
Template::render("log.completed", context!(logs, loggedin_user: &user))
|
||||
|
@ -23,9 +23,11 @@
|
||||
<a href="/log" class="block w-100 py-2 hover:text-primary-600">
|
||||
Ausfahrt eintragen
|
||||
</a>
|
||||
{% if not loggedin_user.is_guest %}
|
||||
<a href="/log/show" class="block w-100 py-2 hover:text-primary-600 border-t">
|
||||
Logbuch
|
||||
</a>
|
||||
{% endif %}
|
||||
<a href="/stat" class="block w-100 py-2 hover:text-primary-600 border-t">
|
||||
Statistik
|
||||
</a>
|
||||
|
Loading…
Reference in New Issue
Block a user