Skip to content

Commit

Permalink
fixes for staff apps + remove maps from libavacado
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Dec 17, 2022
1 parent 21bb7b0 commit 5a256dd
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 163 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

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

7 changes: 0 additions & 7 deletions api/process.json

This file was deleted.

1 change: 0 additions & 1 deletion api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ async fn main() -> std::io::Result<()> {
.service(routes::vote_reset_all)
.service(routes::staff_verify_fetch_api)
.service(routes::staff_verify_onboard_data_api)
.service(routes::get_current_maints)
.service(routes::get_apps_api)
.service(routes::get_interview_api)
.service(routes::get_app_list)
Expand Down
66 changes: 48 additions & 18 deletions api/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,22 +240,6 @@ pub async fn vote_reset_all(req: HttpRequest, info: web::Json<GenericRequest>) -
HttpResponse::Ok().body("")
}

/// Get all current maintenances
#[get("/maints")]
pub async fn get_current_maints(_req: HttpRequest) -> HttpResponse {
let maints = libavacado::public::maint_status();

if let Ok(maints) = maints {
return HttpResponse::Ok().json(maints);
}

HttpResponse::BadRequest().json(crate::models::APIResponse {
done: false,
reason: maints.err().unwrap().to_string(),
context: None,
})
}

#[derive(Serialize, Deserialize)]
pub struct SVQuery {
uid: String,
Expand Down Expand Up @@ -438,8 +422,53 @@ pub async fn get_apps_api(_req: HttpRequest) -> HttpResponse {

/// Returns the interview questions form
#[get("/herpes/zoster")]
pub async fn get_interview_api(_req: HttpRequest) -> HttpResponse {
HttpResponse::Ok().json(libavacado::staffapps::get_interview_questions())
pub async fn get_interview_api(req: HttpRequest, info: web::Query<GetAppQuery>) -> HttpResponse {
let data: &crate::models::AppState = req
.app_data::<web::Data<crate::models::AppState>>()
.unwrap();

let auth_default = &HeaderValue::from_str("").unwrap();
let auth = req
.headers()
.get("Authorization")
.unwrap_or(auth_default)
.to_str()
.unwrap();

let info = info.into_inner();

let check = sqlx::query!(
"SELECT api_token FROM users WHERE user_id = $1",
&info.user_id.to_string()
)
.fetch_one(&data.pool)
.await;

if check.is_err() {
return HttpResponse::Unauthorized().finish();
}

let check = check.unwrap();

if check.api_token != auth {
return HttpResponse::Unauthorized().finish();
}

let interview = libavacado::staffapps::get_app_interview(
&data.pool,
&info.user_id,
&info.app_id,
).await;

if interview.is_err() {
return HttpResponse::BadRequest().json(crate::models::APIResponse {
done: false,
reason: interview.unwrap_err().to_string(),
context: None,
});
}

HttpResponse::Ok().json(interview.unwrap())
}

/// Finalizes the application
Expand Down Expand Up @@ -483,6 +512,7 @@ pub async fn finalize_app_api(
let app = libavacado::staffapps::finalize_app(
&data.avacado_public,
&data.pool,
&info.user_id,
&info.app_id,
body.into_inner(),
)
Expand Down
1 change: 1 addition & 0 deletions bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ futures-util = "0.3"
libavacado = { path = "../libavacado" }
ring = "0.16"
data-encoding = "2.3"
indexmap = { version = "1.9.1", features = ["serde"] }

[dependencies.tokio]
version = "1"
Expand Down
7 changes: 0 additions & 7 deletions bot/process.json

This file was deleted.

16 changes: 12 additions & 4 deletions bot/src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ async fn _embed_help(
ctx: poise::FrameworkContext<'_, Data, Error>,
) -> Result<Vec<EmbedHelp>, Error> {
let mut categories =
libavacado::maps::OrderedMap::<Option<&str>, Vec<&Command<Data, Error>>>::new();
indexmap::IndexMap::<Option<&str>, Vec<&Command<Data, Error>>>::new();
for cmd in &ctx.options().commands {
categories
.get_or_insert_with(cmd.category, Vec::new)
.push(cmd);

// Check if category exists
if categories.contains_key(&cmd.category) {
categories.get_mut(&cmd.category).unwrap().push(cmd);
}

// If category doesn't exist, create it
else {
categories.insert(cmd.category, vec![cmd]);
}

}

let mut help_arr = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion libavacado/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libavacado"
version = "0.2.2"
version = "0.2.3"
edition = "2021"
build = "build.rs"

Expand Down
1 change: 0 additions & 1 deletion libavacado/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

pub mod checks;
pub mod manage;
pub mod maps;
pub mod public;
pub mod staff;
pub mod staffapps;
Expand Down
51 changes: 0 additions & 51 deletions libavacado/src/maps.rs

This file was deleted.

Loading

0 comments on commit 5a256dd

Please sign in to comment.