mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-18 18:08:07 +03:00
Add API for retrieving the date that a contributor signed the CLA
Co-authored-by: Marshall <marshall@zed.dev>
This commit is contained in:
parent
6c937c4a90
commit
56556d71a1
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1463,6 +1463,7 @@ dependencies = [
|
|||||||
"base64 0.13.1",
|
"base64 0.13.1",
|
||||||
"call",
|
"call",
|
||||||
"channel",
|
"channel",
|
||||||
|
"chrono",
|
||||||
"clap 3.2.25",
|
"clap 3.2.25",
|
||||||
"client",
|
"client",
|
||||||
"clock",
|
"clock",
|
||||||
|
@ -93,6 +93,7 @@ resolver = "2"
|
|||||||
anyhow = { version = "1.0.57" }
|
anyhow = { version = "1.0.57" }
|
||||||
async-trait = { version = "0.1" }
|
async-trait = { version = "0.1" }
|
||||||
async-compression = { version = "0.4", features = ["gzip", "futures-io"] }
|
async-compression = { version = "0.4", features = ["gzip", "futures-io"] }
|
||||||
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
ctor = "0.2.6"
|
ctor = "0.2.6"
|
||||||
derive_more = { version = "0.99.17" }
|
derive_more = { version = "0.99.17" }
|
||||||
env_logger = { version = "0.9" }
|
env_logger = { version = "0.9" }
|
||||||
|
@ -30,7 +30,7 @@ workspace = { path = "../workspace" }
|
|||||||
uuid.workspace = true
|
uuid.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono.workspace = true
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
indoc.workspace = true
|
indoc.workspace = true
|
||||||
isahc.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"] }
|
axum-extra = { version = "0.3", features = ["erased-json"] }
|
||||||
base64 = "0.13"
|
base64 = "0.13"
|
||||||
clap = { version = "3.1", features = ["derive"], optional = true }
|
clap = { version = "3.1", features = ["derive"], optional = true }
|
||||||
|
chrono.workspace = true
|
||||||
dashmap = "5.4"
|
dashmap = "5.4"
|
||||||
envy = "0.4.2"
|
envy = "0.4.2"
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
|
@ -14,6 +14,7 @@ use axum::{
|
|||||||
Extension, Json, Router,
|
Extension, Json, Router,
|
||||||
};
|
};
|
||||||
use axum_extra::response::ErasedJson;
|
use axum_extra::response::ErasedJson;
|
||||||
|
use chrono::SecondsFormat;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tower::ServiceBuilder;
|
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("/panic", post(trace_panic))
|
||||||
.route("/rpc_server_snapshot", get(get_rpc_server_snapshot))
|
.route("/rpc_server_snapshot", get(get_rpc_server_snapshot))
|
||||||
.route("/contributors", get(get_contributors).post(add_contributor))
|
.route("/contributors", get(get_contributors).post(add_contributor))
|
||||||
|
.route("/contributor", get(check_is_contributor))
|
||||||
.layer(
|
.layer(
|
||||||
ServiceBuilder::new()
|
ServiceBuilder::new()
|
||||||
.layer(Extension(state))
|
.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?))
|
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(
|
async fn add_contributor(
|
||||||
Json(params): Json<AuthenticatedUserParams>,
|
Json(params): Json<AuthenticatedUserParams>,
|
||||||
Extension(app): Extension<Arc<AppState>>,
|
Extension(app): Extension<Arc<AppState>>,
|
||||||
|
@ -21,6 +21,28 @@ impl Database {
|
|||||||
.await
|
.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.
|
/// Records that a given user has signed the CLA.
|
||||||
pub async fn add_contributor(
|
pub async fn add_contributor(
|
||||||
&self,
|
&self,
|
||||||
|
Loading…
Reference in New Issue
Block a user