parent
67c869e3ac
commit
4ff4ce0195
@ -0,0 +1,67 @@
|
||||
---
|
||||
source: web/src/endpoints/vehicle/get_overview.rs
|
||||
expression: body
|
||||
snapshot_kind: text
|
||||
---
|
||||
<section class="section">
|
||||
<div class="container">
|
||||
<div class="level">
|
||||
<div class="level-left">
|
||||
<h3 class="title is-3">
|
||||
Fahrzeuge
|
||||
</h3>
|
||||
</div>
|
||||
<div class="level-right">
|
||||
<a class="button is-link is-light" hx-boost="true" href="/vehicles/new">
|
||||
<svg class="icon">
|
||||
<use href="/static/feather-sprite.svg#plus-circle" />
|
||||
</svg>
|
||||
<span>Neues Fahrzeug anlegen</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="box">
|
||||
<table class="table is-fullwidth">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Funkkenner</th>
|
||||
<th>Wache</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
11.49.1
|
||||
</td>
|
||||
<td>
|
||||
FF Leipzig Ost
|
||||
</td>
|
||||
<td>
|
||||
<div class="buttons is-right">
|
||||
<a class="button is-primary is-light" hx-boost="true" href="/vehicles/1">
|
||||
<svg class="icon">
|
||||
<use href="/static/feather-sprite.svg#edit" />
|
||||
</svg>
|
||||
<span>Bearbeiten</span>
|
||||
</a>
|
||||
<button class="button is-danger is-light" hx-delete="/vehicles/1" hx-target="closest tr"
|
||||
hx-swap="delete" hx-trigger="confirmed">
|
||||
<svg class="icon">
|
||||
<use href="/static/feather-sprite.svg#x-circle" />
|
||||
</svg>
|
||||
<span>Löschen</span>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</section>
|
@ -11,7 +11,7 @@ use crate::models::{Area, Role, User};
|
||||
|
||||
#[derive(Template)]
|
||||
#[cfg_attr(not(test), template(path = "area/new_or_edit.html"))]
|
||||
#[cfg_attr(test, template(path = "area/new_or_edit.html", block = "content"))]
|
||||
#[cfg_attr(test, template(path = "area/new_or_edit.html", block = "content"), allow(dead_code))]
|
||||
struct NewOrEditAreaTemplate {
|
||||
user: User,
|
||||
area: Option<Area>,
|
||||
|
@ -8,7 +8,12 @@ use crate::{
|
||||
};
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "vehicles/overview.html")]
|
||||
#[cfg_attr(not(test), template(path = "vehicles/overview.html"))]
|
||||
#[cfg_attr(
|
||||
test,
|
||||
template(path = "vehicles/overview.html", block = "content"),
|
||||
allow(dead_code)
|
||||
)]
|
||||
pub struct VehiclesOverviewTemplate {
|
||||
user: User,
|
||||
vehicles: Vec<Vehicle>,
|
||||
@ -19,7 +24,7 @@ pub async fn get(
|
||||
user: web::ReqData<User>,
|
||||
pool: web::Data<PgPool>,
|
||||
) -> Result<impl Responder, ApplicationError> {
|
||||
if user.role != Role::Admin {
|
||||
if user.role != Role::Admin && user.role != Role::AreaManager {
|
||||
return Err(ApplicationError::Unauthorized);
|
||||
}
|
||||
|
||||
@ -32,3 +37,60 @@ pub async fn get(
|
||||
|
||||
Ok(template.to_response()?)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{
|
||||
models::{Function, Role, Vehicle},
|
||||
utils::test_helper::{
|
||||
assert_snapshot, read_body, test_get, DbTestContext, RequestConfig, StatusCode,
|
||||
},
|
||||
};
|
||||
use brass_macros::db_test;
|
||||
|
||||
#[db_test]
|
||||
async fn user_cant_view_overview(context: &DbTestContext) {
|
||||
let app = context.app().await;
|
||||
|
||||
let config = RequestConfig::new("/vehicles");
|
||||
|
||||
let response = test_get(&context.db_pool, &app, &config).await;
|
||||
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||
}
|
||||
|
||||
#[db_test]
|
||||
async fn area_manager_can_view_overview(context: &DbTestContext) {
|
||||
let app = context.app().await;
|
||||
|
||||
let config = RequestConfig {
|
||||
uri: "/vehicles".to_string(),
|
||||
role: Role::AreaManager,
|
||||
function: vec![Function::Posten],
|
||||
user_area: 1,
|
||||
};
|
||||
|
||||
let response = test_get(&context.db_pool, &app, &config).await;
|
||||
assert_eq!(StatusCode::OK, response.status());
|
||||
}
|
||||
|
||||
#[db_test]
|
||||
async fn produces_template_fine_when_user_is_admin(context: &DbTestContext) {
|
||||
let app = context.app().await;
|
||||
Vehicle::create(&context.db_pool, "11.49.1", "FF Leipzig Ost")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let config = RequestConfig {
|
||||
uri: "/vehicles".to_string(),
|
||||
role: Role::Admin,
|
||||
function: vec![Function::Posten],
|
||||
user_area: 1,
|
||||
};
|
||||
|
||||
let response = test_get(&context.db_pool, &app, &config).await;
|
||||
assert_eq!(StatusCode::OK, response.status());
|
||||
|
||||
let body = read_body(response).await;
|
||||
assert_snapshot!(body);
|
||||
}
|
||||
}
|
||||
|
@ -48,11 +48,9 @@
|
||||
Veranstaltungsorte
|
||||
</a>
|
||||
|
||||
{% if user.role == Role::Admin %}
|
||||
<a href="/vehicles" class="navbar-item">
|
||||
Fahrzeuge
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user