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)]
|
||||
#[template(path = "partials/roaster_list.html")]
|
||||
pub struct RoasterListTemplate {
|
||||
pub is_authenticated: bool,
|
||||
pub roasters: Paginated<RoasterView>,
|
||||
pub navigator: ListNavigator<RoasterSortKey>,
|
||||
}
|
||||
|
|
@ -54,6 +55,7 @@ pub struct RoastDetailTemplate {
|
|||
#[derive(Template)]
|
||||
#[template(path = "partials/roast_list.html")]
|
||||
pub struct RoastListTemplate {
|
||||
pub is_authenticated: bool,
|
||||
pub roasts: Paginated<RoastView>,
|
||||
pub navigator: ListNavigator<RoastSortKey>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,8 @@ pub(crate) async fn roasters_page(
|
|||
let request = query.into_request::<RoasterSortKey>();
|
||||
|
||||
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
|
||||
.map_err(map_app_error);
|
||||
}
|
||||
|
|
@ -127,7 +128,7 @@ pub(crate) async fn create_roaster(
|
|||
.map_err(AppError::from)?;
|
||||
|
||||
if is_datastar_request(&headers) {
|
||||
render_roaster_list_fragment(state, request)
|
||||
render_roaster_list_fragment(state, request, true)
|
||||
.await
|
||||
.map_err(ApiError::from)
|
||||
} else if matches!(source, PayloadSource::Form) {
|
||||
|
|
@ -186,7 +187,7 @@ pub(crate) async fn delete_roaster(
|
|||
.map_err(AppError::from)?;
|
||||
|
||||
if is_datastar_request(&headers) {
|
||||
render_roaster_list_fragment(state, request)
|
||||
render_roaster_list_fragment(state, request, true)
|
||||
.await
|
||||
.map_err(ApiError::from)
|
||||
} else {
|
||||
|
|
@ -197,10 +198,12 @@ pub(crate) async fn delete_roaster(
|
|||
async fn render_roaster_list_fragment(
|
||||
state: AppState,
|
||||
request: ListRequest<RoasterSortKey>,
|
||||
is_authenticated: bool,
|
||||
) -> Result<Response, AppError> {
|
||||
let (roasters, navigator) = load_roaster_page(&state, request).await?;
|
||||
|
||||
let template = RoasterListTemplate {
|
||||
is_authenticated,
|
||||
roasters,
|
||||
navigator,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -49,7 +49,8 @@ pub(crate) async fn roasts_page(
|
|||
let request = query.into_request::<RoastSortKey>();
|
||||
|
||||
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
|
||||
.map_err(map_app_error);
|
||||
}
|
||||
|
|
@ -131,7 +132,7 @@ pub(crate) async fn create_roast(
|
|||
.map_err(AppError::from)?;
|
||||
|
||||
if is_datastar_request(&headers) {
|
||||
render_roast_list_fragment(state, request)
|
||||
render_roast_list_fragment(state, request, true)
|
||||
.await
|
||||
.map_err(ApiError::from)
|
||||
} 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)?;
|
||||
|
||||
if is_datastar_request(&headers) {
|
||||
render_roast_list_fragment(state, request)
|
||||
render_roast_list_fragment(state, request, true)
|
||||
.await
|
||||
.map_err(ApiError::from)
|
||||
} else {
|
||||
|
|
@ -266,10 +267,15 @@ impl TastingNotesInput {
|
|||
async fn render_roast_list_fragment(
|
||||
state: AppState,
|
||||
request: ListRequest<RoastSortKey>,
|
||||
is_authenticated: bool,
|
||||
) -> Result<Response, AppError> {
|
||||
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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,7 +183,9 @@
|
|||
</button>
|
||||
</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>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-amber-200/70">
|
||||
|
|
@ -228,6 +230,7 @@
|
|||
</ul>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% if is_authenticated %}
|
||||
<td class="px-4 py-3 text-right">
|
||||
<button
|
||||
type="button"
|
||||
|
|
@ -245,6 +248,7 @@
|
|||
</svg>
|
||||
</button>
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
|||
|
|
@ -163,7 +163,9 @@
|
|||
</th>
|
||||
<th scope="col" class="px-4 py-3">Homepage</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>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-amber-200/70">
|
||||
|
|
@ -213,6 +215,7 @@
|
|||
{% endif %}
|
||||
</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">
|
||||
<button
|
||||
type="button"
|
||||
|
|
@ -230,6 +233,7 @@
|
|||
</svg>
|
||||
</button>
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
|||
Loading…
Reference in a new issue