Cargo.lock 🔗
@@ -1463,6 +1463,7 @@ dependencies = [
"base64 0.13.1",
"call",
"channel",
+ "chrono",
"clap 3.2.25",
"client",
"clock",
Max Brunsfeld and Marshall created
Co-authored-by: Marshall <marshall@zed.dev>
Cargo.lock | 1
Cargo.toml | 1
crates/assistant/Cargo.toml | 2
crates/collab/Cargo.toml | 1
crates/collab/src/api.rs | 25 +++++++++++++++++++++
crates/collab/src/db/queries/contributors.rs | 22 +++++++++++++++++++
6 files changed, 51 insertions(+), 1 deletion(-)
@@ -1463,6 +1463,7 @@ dependencies = [
"base64 0.13.1",
"call",
"channel",
+ "chrono",
"clap 3.2.25",
"client",
"clock",
@@ -93,6 +93,7 @@ resolver = "2"
anyhow = { version = "1.0.57" }
async-trait = { version = "0.1" }
async-compression = { version = "0.4", features = ["gzip", "futures-io"] }
+chrono = { version = "0.4", features = ["serde"] }
ctor = "0.2.6"
derive_more = { version = "0.99.17" }
env_logger = { version = "0.9" }
@@ -30,7 +30,7 @@ workspace = { path = "../workspace" }
uuid.workspace = true
log.workspace = true
anyhow.workspace = true
-chrono = { version = "0.4", features = ["serde"] }
+chrono.workspace = true
futures.workspace = true
indoc.workspace = true
isahc.workspace = true
@@ -27,6 +27,7 @@ axum = { version = "0.5", features = ["json", "headers", "ws"] }
axum-extra = { version = "0.3", features = ["erased-json"] }
base64 = "0.13"
clap = { version = "3.1", features = ["derive"], optional = true }
+chrono.workspace = true
dashmap = "5.4"
envy = "0.4.2"
futures.workspace = true
@@ -14,6 +14,7 @@ use axum::{
Extension, Json, Router,
};
use axum_extra::response::ErasedJson;
+use chrono::SecondsFormat;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use tower::ServiceBuilder;
@@ -26,6 +27,7 @@ pub fn routes(rpc_server: Arc<rpc::Server>, state: Arc<AppState>) -> Router<Body
.route("/panic", post(trace_panic))
.route("/rpc_server_snapshot", get(get_rpc_server_snapshot))
.route("/contributors", get(get_contributors).post(add_contributor))
+ .route("/contributor", get(check_is_contributor))
.layer(
ServiceBuilder::new()
.layer(Extension(state))
@@ -137,6 +139,29 @@ async fn get_contributors(Extension(app): Extension<Arc<AppState>>) -> Result<Js
Ok(Json(app.db.get_contributors().await?))
}
+#[derive(Debug, Deserialize)]
+struct CheckIsContributorParams {
+ github_user_id: i32,
+}
+
+#[derive(Debug, Serialize)]
+struct CheckIsContributorResponse {
+ signed_at: Option<String>,
+}
+
+async fn check_is_contributor(
+ Extension(app): Extension<Arc<AppState>>,
+ Query(params): Query<CheckIsContributorParams>,
+) -> Result<Json<CheckIsContributorResponse>> {
+ Ok(Json(CheckIsContributorResponse {
+ signed_at: app
+ .db
+ .get_contributor_sign_timestamp(params.github_user_id)
+ .await?
+ .map(|ts| ts.and_utc().to_rfc3339_opts(SecondsFormat::Millis, true)),
+ }))
+}
+
async fn add_contributor(
Json(params): Json<AuthenticatedUserParams>,
Extension(app): Extension<Arc<AppState>>,
@@ -21,6 +21,28 @@ impl Database {
.await
}
+ /// Records that a given user has signed the CLA.
+ pub async fn get_contributor_sign_timestamp(
+ &self,
+ github_user_id: i32,
+ ) -> Result<Option<DateTime>> {
+ self.transaction(|tx| async move {
+ let Some(user) = user::Entity::find()
+ .filter(user::Column::GithubUserId.eq(github_user_id))
+ .one(&*tx)
+ .await?
+ else {
+ return Ok(None);
+ };
+ let Some(contributor) = contributor::Entity::find_by_id(user.id).one(&*tx).await?
+ else {
+ return Ok(None);
+ };
+ Ok(Some(contributor.signed_at))
+ })
+ .await
+ }
+
/// Records that a given user has signed the CLA.
pub async fn add_contributor(
&self,