-Removed _most_ direct sql manipulation for invite creation
- Removed unused/irrelevant unit tests, which now have to be rebuilt for the new codebase
This commit is contained in:
parent
39a4d2a247
commit
c1ef4c6336
@ -1,9 +1,7 @@
|
|||||||
use serde_json::{Value, json};
|
use serde_json::{Value, json};
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
use mysql_async;
|
use mysql_async;
|
||||||
use mysql_async::{Conn, Pool};
|
use mysql_async::{Conn, Pool};
|
||||||
use mysql_async::error::Error;
|
|
||||||
use mysql_async::prelude::{params, Queryable};
|
use mysql_async::prelude::{params, Queryable};
|
||||||
|
|
||||||
use hyper::{Response, Body, StatusCode};
|
use hyper::{Response, Body, StatusCode};
|
||||||
@ -15,16 +13,11 @@ use std::collections::HashMap;
|
|||||||
use db::{UBigInt, BigInt};
|
use db::{UBigInt, BigInt};
|
||||||
use db::common::FromDB;
|
use db::common::FromDB;
|
||||||
use db::member::Member;
|
use db::member::Member;
|
||||||
|
use db::invites::Invite;
|
||||||
|
|
||||||
use crate::http;
|
use crate::http;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
struct Invite {
|
|
||||||
id: BigInt, // doubles as the timestamp for when it dies
|
|
||||||
uses: Option<BigInt>, // optional because some links are permanent
|
|
||||||
expires: bool,
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* Error handling:
|
* Error handling:
|
||||||
* All errors raisable from this module come from mysql_async and thus
|
* All errors raisable from this module come from mysql_async and thus
|
||||||
@ -127,21 +120,10 @@ pub async fn join(pool: &Pool, response: &mut Response<Body>, params: HashMap<&s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn insert_new_invite(pool: &Pool, invite: &Invite) -> Result<(), Error>{
|
|
||||||
let conn = pool.get_conn().await?;
|
|
||||||
conn.prep_exec(
|
|
||||||
"INSERT INTO invites (id, uses, expires)
|
|
||||||
VALUES (:id, :uses, :expires)", params!{
|
|
||||||
"id" => invite.id,
|
|
||||||
"uses" => invite.uses,
|
|
||||||
"expires" => invite.expires
|
|
||||||
}).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn process_expires_parameter(p: &Pool, exp: &Value, id: UBigInt) -> bool {
|
async fn process_expires_parameter(p: &Pool, exp: &Value, id: UBigInt) -> bool {
|
||||||
// TODO: fix this somewhat unsafe code
|
// TODO: fix this somewhat unsafe code
|
||||||
|
// TODO: BRO THIS SHIT
|
||||||
// NOTE: its unsafe because of these lazy as heck unwraps everywhere
|
// NOTE: its unsafe because of these lazy as heck unwraps everywhere
|
||||||
use crate::perms::{CREATE_PERM_INVITES, CREATE_TMP_INVITES};
|
use crate::perms::{CREATE_PERM_INVITES, CREATE_TMP_INVITES};
|
||||||
let conn = p.get_conn().await.unwrap();
|
let conn = p.get_conn().await.unwrap();
|
||||||
@ -210,13 +192,9 @@ pub async fn create(pool: &Pool, response: &mut Response<Body>, params: HashMap<
|
|||||||
};
|
};
|
||||||
|
|
||||||
// TODO: prolly add some kind option to set an expire time
|
// TODO: prolly add some kind option to set an expire time
|
||||||
let invite = Invite {
|
let invite = Invite::new(use_count, expirey_request);
|
||||||
id: (Utc::now() + chrono::Duration::minutes(30)).timestamp(),
|
|
||||||
uses: use_count,
|
|
||||||
expires: expirey_request
|
|
||||||
};
|
|
||||||
|
|
||||||
match insert_new_invite(&pool, &invite).await {
|
match invite.add(pool).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// return the id of the invite
|
// return the id of the invite
|
||||||
// Link format from here is basically hostname.io:4536/join?code=<some-code>
|
// Link format from here is basically hostname.io:4536/join?code=<some-code>
|
||||||
@ -228,21 +206,3 @@ pub async fn create(pool: &Pool, response: &mut Response<Body>, params: HashMap<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod invites_test {
|
|
||||||
/*
|
|
||||||
* INVITE CREATION
|
|
||||||
* Good - Bad - Malicious
|
|
||||||
*/
|
|
||||||
|
|
||||||
use crate::testing::{get_pool, hyper_resp};
|
|
||||||
use hyper::StatusCode;
|
|
||||||
use serde_json::Value;
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn create_invite_good() {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user