Skip to content

Add Submissions #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 6, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
# https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
strategy:
matrix:
msrv: ["1.80"]
msrv: ["1.81"]
name: ubuntu / ${{ matrix.msrv }}
steps:
- uses: actions/checkout@v4
Expand Down
39 changes: 28 additions & 11 deletions Cargo.lock

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

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@ resolver = "2"
[workspace.package]
edition = "2021"
version = "0.1.0"
rust-version = "1.80"
rust-version = "1.81"

[workspace.dependencies]
anyhow = "1.0.95"
argon2 = { version = "0.5.3", features = ["password-hash"] }
async-tempfile = "0.6.0"
axum-extra = { version = "0.10.0", features = ["typed-header"] }
axum = { version = "0.8.1", features = ["macros", "ws"] }
bedrock = { git = "https://github.com/basalt-rs/bedrock.git", rev = "52ff607", features = ["tokio"] }
bedrock = { git = "https://github.com/basalt-rs/bedrock.git", rev = "4a35c85", features = ["tokio"] }
clap = { version = "4.5.23", features = ["derive"] }
dashmap = "6.1.0"
derive_more = { version = "2.0.1", features = ["debug", "from", "deref"] }
derive_more = { version = "2.0.1", features = ["debug", "from", "deref", "into", "from_str"] }
directories = "6.0.0"
erudite = { git = "https://github.com/basalt-rs/erudite.git", rev = "7de318e", features = ["serde"] }
lazy_static = "1.5.0"
leucite = "0.2.0"
rand = "0.8.5"
redact = { version = "0.1.10", features = ["serde"] }
scopeguard = "1.2.0"
serde_json = "1.0.138"
serde = { version = "1.0.217", features = ["derive"] }
sqlx = { version = "0.8.3", features = ["sqlite", "runtime-tokio-native-tls"] }
sqlx = { version = "0.8.3", features = ["sqlite", "runtime-tokio-native-tls", "time"] }
thiserror = "2.0.11"
time = { version = "0.3.40", features = ["serde"] }
tokio = { version = "1.43.0", features = ["full"] }
tower-http = { version = "0.6.2", features = ["cors", "trace"] }
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
Expand Down
2 changes: 2 additions & 0 deletions basalt-server-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dashmap.workspace = true
derive_more.workspace = true
directories.workspace = true
erudite.workspace = true
lazy_static.workspace = true
leucite.workspace = true
rand.workspace = true
redact.workspace = true
Expand All @@ -26,6 +27,7 @@ serde_json.workspace = true
serde.workspace = true
sqlx.workspace = true
thiserror.workspace = true
time.workspace = true
tokio.workspace = true
tower-http.workspace = true
tracing.workspace = true
Expand Down
23 changes: 22 additions & 1 deletion basalt-server-lib/migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,25 @@ CREATE TABLE IF NOT EXISTS sessions (
username TEXT NOT NULL,
expires_at INTEGER NOT NULL,
FOREIGN KEY (username) REFERENCES users(username)
)
);

CREATE TABLE IF NOT EXISTS submission_history (
id VARCHAR(32) NOT NULL PRIMARY KEY,
submitter VARCHAR(32) NOT NULL REFERENCES users(username),
time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
compile_fail BOOLEAN NOT NULL,
code TEXT NOT NULL,
question_index INTEGER NOT NULL,
score FLOAT NOT NULL,
success BOOLEAN NOT NULL
);

-- History of tests that have been run on submissions
CREATE TABLE IF NOT EXISTS submission_test_history (
submission VARCHAR(32) NOT NULL REFERENCES submission_history(id),
test_index INTEGER NOT NULL,
result VARCHAR(32) NOT NULL,
stdout TEXT,
stderr TEXT,
exit_status INTEGER NOT NULL
);
2 changes: 1 addition & 1 deletion basalt-server-lib/src/extractors/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async fn extract(parts: &mut Parts, state: &Arc<AppState>) -> Result<Option<Auth
trace!("token expired");
AuthError::ExpiredToken
})?;
trace!(user.username, "resolved user");
trace!(?user.username, "resolved user");

Ok(Some(AuthUser {
user,
Expand Down
1 change: 1 addition & 0 deletions basalt-server-lib/src/repositories/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod session;
pub mod submissions;
pub mod users;
6 changes: 3 additions & 3 deletions basalt-server-lib/src/repositories/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use sqlx::prelude::FromRow;

use crate::{repositories::users::Role, storage::SqliteLayer};

use super::users::User;
use super::users::{User, Username};

#[derive(Debug, FromRow, Serialize, Deserialize)]
pub struct Session {
pub username: String,
pub username: Username,
#[serde(serialize_with = "expose_secret")]
pub password_hash: Secret<String>,
pub role: i64,
Expand Down Expand Up @@ -70,7 +70,7 @@ pub async fn get_user_from_session(
// #[sqlx(flatten)]
// user: User
// ```
username: String,
username: Username,
password_hash: Secret<String>,
role: Role,
}
Expand Down
Loading