fix: don't display delete icons when unauthenticated
This commit is contained in:
parent
f88a880d07
commit
7df6cbcc51
5 changed files with 26 additions and 7 deletions
|
|
@ -20,6 +20,7 @@ pub struct RoastersTemplate {
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "partials/roaster_list.html")]
|
#[template(path = "partials/roaster_list.html")]
|
||||||
pub struct RoasterListTemplate {
|
pub struct RoasterListTemplate {
|
||||||
|
pub is_authenticated: bool,
|
||||||
pub roasters: Paginated<RoasterView>,
|
pub roasters: Paginated<RoasterView>,
|
||||||
pub navigator: ListNavigator<RoasterSortKey>,
|
pub navigator: ListNavigator<RoasterSortKey>,
|
||||||
}
|
}
|
||||||
|
|
@ -54,6 +55,7 @@ pub struct RoastDetailTemplate {
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "partials/roast_list.html")]
|
#[template(path = "partials/roast_list.html")]
|
||||||
pub struct RoastListTemplate {
|
pub struct RoastListTemplate {
|
||||||
|
pub is_authenticated: bool,
|
||||||
pub roasts: Paginated<RoastView>,
|
pub roasts: Paginated<RoastView>,
|
||||||
pub navigator: ListNavigator<RoastSortKey>,
|
pub navigator: ListNavigator<RoastSortKey>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,8 @@ pub(crate) async fn roasters_page(
|
||||||
let request = query.into_request::<RoasterSortKey>();
|
let request = query.into_request::<RoasterSortKey>();
|
||||||
|
|
||||||
if is_datastar_request(&headers) {
|
if is_datastar_request(&headers) {
|
||||||
return render_roaster_list_fragment(state, request)
|
let is_authenticated = crate::server::routes::auth::is_authenticated(&state, &cookies).await;
|
||||||
|
return render_roaster_list_fragment(state, request, is_authenticated)
|
||||||
.await
|
.await
|
||||||
.map_err(map_app_error);
|
.map_err(map_app_error);
|
||||||
}
|
}
|
||||||
|
|
@ -127,7 +128,7 @@ pub(crate) async fn create_roaster(
|
||||||
.map_err(AppError::from)?;
|
.map_err(AppError::from)?;
|
||||||
|
|
||||||
if is_datastar_request(&headers) {
|
if is_datastar_request(&headers) {
|
||||||
render_roaster_list_fragment(state, request)
|
render_roaster_list_fragment(state, request, true)
|
||||||
.await
|
.await
|
||||||
.map_err(ApiError::from)
|
.map_err(ApiError::from)
|
||||||
} else if matches!(source, PayloadSource::Form) {
|
} else if matches!(source, PayloadSource::Form) {
|
||||||
|
|
@ -186,7 +187,7 @@ pub(crate) async fn delete_roaster(
|
||||||
.map_err(AppError::from)?;
|
.map_err(AppError::from)?;
|
||||||
|
|
||||||
if is_datastar_request(&headers) {
|
if is_datastar_request(&headers) {
|
||||||
render_roaster_list_fragment(state, request)
|
render_roaster_list_fragment(state, request, true)
|
||||||
.await
|
.await
|
||||||
.map_err(ApiError::from)
|
.map_err(ApiError::from)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -197,10 +198,12 @@ pub(crate) async fn delete_roaster(
|
||||||
async fn render_roaster_list_fragment(
|
async fn render_roaster_list_fragment(
|
||||||
state: AppState,
|
state: AppState,
|
||||||
request: ListRequest<RoasterSortKey>,
|
request: ListRequest<RoasterSortKey>,
|
||||||
|
is_authenticated: bool,
|
||||||
) -> Result<Response, AppError> {
|
) -> Result<Response, AppError> {
|
||||||
let (roasters, navigator) = load_roaster_page(&state, request).await?;
|
let (roasters, navigator) = load_roaster_page(&state, request).await?;
|
||||||
|
|
||||||
let template = RoasterListTemplate {
|
let template = RoasterListTemplate {
|
||||||
|
is_authenticated,
|
||||||
roasters,
|
roasters,
|
||||||
navigator,
|
navigator,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,8 @@ pub(crate) async fn roasts_page(
|
||||||
let request = query.into_request::<RoastSortKey>();
|
let request = query.into_request::<RoastSortKey>();
|
||||||
|
|
||||||
if is_datastar_request(&headers) {
|
if is_datastar_request(&headers) {
|
||||||
return render_roast_list_fragment(state, request)
|
let is_authenticated = crate::server::routes::auth::is_authenticated(&state, &cookies).await;
|
||||||
|
return render_roast_list_fragment(state, request, is_authenticated)
|
||||||
.await
|
.await
|
||||||
.map_err(map_app_error);
|
.map_err(map_app_error);
|
||||||
}
|
}
|
||||||
|
|
@ -131,7 +132,7 @@ pub(crate) async fn create_roast(
|
||||||
.map_err(AppError::from)?;
|
.map_err(AppError::from)?;
|
||||||
|
|
||||||
if is_datastar_request(&headers) {
|
if is_datastar_request(&headers) {
|
||||||
render_roast_list_fragment(state, request)
|
render_roast_list_fragment(state, request, true)
|
||||||
.await
|
.await
|
||||||
.map_err(ApiError::from)
|
.map_err(ApiError::from)
|
||||||
} else if matches!(source, PayloadSource::Form) {
|
} else if matches!(source, PayloadSource::Form) {
|
||||||
|
|
@ -176,7 +177,7 @@ pub(crate) async fn delete_roast(
|
||||||
state.roast_repo.delete(id).await.map_err(AppError::from)?;
|
state.roast_repo.delete(id).await.map_err(AppError::from)?;
|
||||||
|
|
||||||
if is_datastar_request(&headers) {
|
if is_datastar_request(&headers) {
|
||||||
render_roast_list_fragment(state, request)
|
render_roast_list_fragment(state, request, true)
|
||||||
.await
|
.await
|
||||||
.map_err(ApiError::from)
|
.map_err(ApiError::from)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -266,10 +267,15 @@ impl TastingNotesInput {
|
||||||
async fn render_roast_list_fragment(
|
async fn render_roast_list_fragment(
|
||||||
state: AppState,
|
state: AppState,
|
||||||
request: ListRequest<RoastSortKey>,
|
request: ListRequest<RoastSortKey>,
|
||||||
|
is_authenticated: bool,
|
||||||
) -> Result<Response, AppError> {
|
) -> Result<Response, AppError> {
|
||||||
let (roasts, navigator) = load_roast_page(&state, request).await?;
|
let (roasts, navigator) = load_roast_page(&state, request).await?;
|
||||||
|
|
||||||
let template = RoastListTemplate { roasts, navigator };
|
let template = RoastListTemplate {
|
||||||
|
is_authenticated,
|
||||||
|
roasts,
|
||||||
|
navigator,
|
||||||
|
};
|
||||||
|
|
||||||
crate::server::routes::support::render_fragment(template, "#roast-list")
|
crate::server::routes::support::render_fragment(template, "#roast-list")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,9 @@
|
||||||
</button>
|
</button>
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-4 py-3">Notes</th>
|
<th scope="col" class="px-4 py-3">Notes</th>
|
||||||
|
{% if is_authenticated %}
|
||||||
<th scope="col" class="px-4 py-3 text-right">Actions</th>
|
<th scope="col" class="px-4 py-3 text-right">Actions</th>
|
||||||
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="divide-y divide-amber-200/70">
|
<tbody class="divide-y divide-amber-200/70">
|
||||||
|
|
@ -228,6 +230,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
{% if is_authenticated %}
|
||||||
<td class="px-4 py-3 text-right">
|
<td class="px-4 py-3 text-right">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
@ -245,6 +248,7 @@
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,9 @@
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-4 py-3">Homepage</th>
|
<th scope="col" class="px-4 py-3">Homepage</th>
|
||||||
<th scope="col" class="px-4 py-3">Notes</th>
|
<th scope="col" class="px-4 py-3">Notes</th>
|
||||||
|
{% if is_authenticated %}
|
||||||
<th scope="col" class="px-4 py-3 text-right">Actions</th>
|
<th scope="col" class="px-4 py-3 text-right">Actions</th>
|
||||||
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="divide-y divide-amber-200/70">
|
<tbody class="divide-y divide-amber-200/70">
|
||||||
|
|
@ -213,6 +215,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td class="px-4 py-3 text-sm text-stone-600">{{ roaster.notes }}</td>
|
<td class="px-4 py-3 text-sm text-stone-600">{{ roaster.notes }}</td>
|
||||||
|
{% if is_authenticated %}
|
||||||
<td class="px-4 py-3 text-right">
|
<td class="px-4 py-3 text-right">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
@ -230,6 +233,7 @@
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue