Skip to content

Commit

Permalink
feat: add settins/manage page
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitea committed Mar 17, 2024
1 parent fb390a2 commit f6fab7d
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 55 deletions.
64 changes: 32 additions & 32 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ authors = ["fuxiaohei <[email protected]>"]

[workspace.dependencies]
anyhow = "1.0.81"
async-trait = "0.1.77"
async-trait = "0.1.78"
axum = "0.7.4"
base64 = "0.22.0"
chrono = "0.4.35"
Expand Down
4 changes: 3 additions & 1 deletion crates/dao/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod migration;
/// models are generated by sea-orm-cli with Entity and Relation definitions.
pub mod models;

pub mod deploy_task;
/// All tables operation mod
pub mod deployment;
pub mod playground;
Expand All @@ -17,8 +18,9 @@ pub mod storage;
pub mod user_info;
pub mod user_token;
pub mod worker;
pub mod deploy_task;

fn now_time() -> NaiveDateTime {
chrono::Utc::now().naive_utc()
}

pub type DateTimeUTC = chrono::DateTime<chrono::Utc>;
2 changes: 1 addition & 1 deletion crates/dao/src/user_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum Status {
Deleted,
}

#[derive(strum::Display, PartialEq)]
#[derive(strum::Display, PartialEq, strum::EnumString)]
#[strum(serialize_all = "lowercase")]
pub enum Usage {
Session, // web page session token
Expand Down
14 changes: 13 additions & 1 deletion crates/dao/src/worker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::{models::worker, now_time, DB};
use anyhow::Result;
use sea_orm::{sea_query::Expr, ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, Set};
use sea_orm::{
sea_query::Expr, ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, QueryOrder, Set,
};

#[derive(strum::Display)]
#[strum(serialize_all = "lowercase")]
Expand All @@ -19,6 +21,16 @@ pub async fn list_online() -> Result<Vec<worker::Model>> {
Ok(workers)
}

/// list_all returns all workers
pub async fn list_all() -> Result<Vec<worker::Model>> {
let db = DB.get().unwrap();
let workers = worker::Entity::find()
.order_by_desc(worker::Column::UpdatedAt)
.all(db)
.await?;
Ok(workers)
}

/// set_offline set worker offline by id
pub async fn set_offline(id: i32) -> Result<()> {
worker::Entity::update_many()
Expand Down
5 changes: 3 additions & 2 deletions crates/kernel/src/cron/gen_deploys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ pub async fn cron() {
return;
}
info!(
"Done, cost:{:?}ms, checksum:{}",
"Done, cost:{:?}ms, checksum:{}, items:{}",
start_time.elapsed().as_millis(),
data.checksum
data.checksum,
data.items.len(),
);

*old = data;
Expand Down
2 changes: 1 addition & 1 deletion crates/sdk-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = { workspace = true }
anyhow = { workspace = true }
http = { workspace = true }
quote = "1.0.35"
syn = { version = "2.0.51", features = ["full"] }
syn = { version = "2.0.53", features = ["full"] }

[lib]
proc-macro = true
Expand Down
3 changes: 2 additions & 1 deletion deploy/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
proxy:
platform: linux/amd64
image: traefik:v3.0
command: --api.insecure=true --providers.docker=true --providers.docker.exposedByDefault=false --accesslog=true
command: --api.insecure=true --providers.docker=true --providers.docker.exposedByDefault=false --accesslog=true --providers.file.filename=/data/runtime-land/traefik.yaml
restart: always
ports:
- "80:80"
Expand All @@ -25,6 +25,7 @@ services:
environment:
- LAND_SERVER_TOKEN=${LAND_SERVER_TOKEN}
- LAND_SERVICE_NAME=land-worker
- LAND_DATA_DIR=/data/runtime-land
ports:
- "8866:8866"
networks:
Expand Down
7 changes: 7 additions & 0 deletions land-server/src/server/dash/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ pub async fn middleware(mut request: Request, next: Next) -> Result<Response, St
gravatar: user.gravatar,
is_admin: user.role == user_info::Role::Admin.to_string(),
};

// /settings/manage need admin role
if path.starts_with("/settings/manage") && !session_user.is_admin {
warn!(path = path, "Session is not admin: {}", session_value);
return Ok(redirect_response("/overview").into_response());
}

// debug!(path = path, "Session is valid: {}", session_value);
request.extensions_mut().insert(session_user);
Ok(next.run(request).await)
Expand Down
1 change: 1 addition & 0 deletions land-server/src/server/dash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub fn router(assets_dir: &str) -> Result<Router> {
.route("/playground/:name/check", get(playground::check))
.route("/settings", get(settings::index))
.route("/settings/create-token", post(settings::create_token))
.route("/settings/manage", get(settings::manage))
.nest_service("/static", ServeDir::new(static_assets_dir))
.layer(CsrfLayer::new(config))
.with_state(Engine::from(hbs))
Expand Down
Loading

0 comments on commit f6fab7d

Please sign in to comment.