Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ tokio-util = { version = "0.7.19", features = [ "io", "compat" ] }
toml = "1.1.6"
topcoat = { version = "0.10.0", default-features = false, features = [
"asset",
"discover",
"router",
"runtime",
"serve",
Expand Down
6 changes: 5 additions & 1 deletion crates/server/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{ffi::OsString, net::SocketAddr, path::PathBuf, sync::Arc};
use circus_common::Database;
use circus_config::Config;
use clap::Parser;
use color_eyre::eyre::WrapErr;
use tokio::net::TcpListener;

use crate::{
Expand Down Expand Up @@ -207,7 +208,10 @@ where
// Drain in-memory cache-serving counters into the cache_traffic table.
state.spawn_cache_traffic_flush();

let app = routes::router(state, &config);
let app = routes::router(state, &config).wrap_err(
"loading dashboard assets, bundle them with --bundle-assets or set \
ui.dashboard = false",
)?;

let bind_addr = format!("{host}:{port}");
tracing::info!(
Expand Down
45 changes: 22 additions & 23 deletions crates/server/src/routes/dashboard/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,15 @@ use super::{
shared::{
ApiKeyView,
DashboardContext,
DashboardPage,
LinkedIdentityView,
PageError,
Pagination,
RenderExt,
UserView,
enforce_page_access,
},
templates::{
AdminTemplate,
AgentView,
NewsTemplate,
NotificationTaskView,
NotificationsTemplate,
PinnedOutputView,
Expand Down Expand Up @@ -707,26 +704,6 @@ pub(super) async fn user_unlink(
Redirect::to("/users").into_response()
}

/// Render the news page at `/news`: list of recent announcements plus,
/// for admins, the form to publish a new one.
pub(super) async fn news_page(
State(state): State<AppState>,
ctx: DashboardContext,
) -> Result<Html<String>, PageError> {
enforce_page_access(&state.config, &ctx, DashboardPage::News)?;
let items = circus_common::repo::news::list(&state.pool, 50, 0)
.await
.unwrap_or_default();
let tmpl = NewsTemplate {
ui: ui_config(&state),
items,
is_admin: ctx.is_admin,
auth_name: ctx.auth_name.clone(),
csrf_token: ctx.csrf_token.clone(),
};
tmpl.render_html_or_500()
}

#[derive(serde::Deserialize)]
pub(super) struct NewsCreateForm {
title: String,
Expand Down Expand Up @@ -782,6 +759,28 @@ pub(super) async fn news_delete(
Redirect::to("/news").into_response()
}

/// `POST /starred/{id}/delete` removes a job from the viewer's own stars.
pub(super) async fn starred_delete(
State(state): State<AppState>,
Path(id): Path<Uuid>,
ctx: DashboardContext,
Form(form): Form<CsrfOnlyForm>,
) -> Response {
let Some(user_id) = ctx.viewer_user_id else {
return StatusCode::UNAUTHORIZED.into_response();
};
if let Err(e) = ctx.check_csrf(&form.csrf_token) {
return e.into_response();
}
if let Err(e) =
circus_common::repo::starred_jobs::delete_for_user(&state.pool, user_id, id)
.await
{
tracing::warn!(id = %id, "Failed to unstar job: {e}");
}
Redirect::to("/starred").into_response()
}

/// Form payload for `POST /project/{id}/notifications`: the kind of
/// notification (webhook, email, ...) and a JSON blob holding the
/// kind-specific configuration.
Expand Down
Loading
Loading