mirror of
https://github.com/ViViDboarder/bitwarden_rs.git
synced 2024-12-22 11:37:45 +00:00
Add get invites endpoint
This commit is contained in:
parent
f25ab42ebb
commit
4889415cae
@ -22,6 +22,7 @@ pub fn routes() -> Vec<Route> {
|
|||||||
routes![
|
routes![
|
||||||
admin_login,
|
admin_login,
|
||||||
get_users,
|
get_users,
|
||||||
|
get_invites,
|
||||||
post_admin_login,
|
post_admin_login,
|
||||||
admin_page,
|
admin_page,
|
||||||
invite_user,
|
invite_user,
|
||||||
@ -156,6 +157,14 @@ fn invite_user(data: Json<InviteData>, _token: AdminToken, conn: DbConn) -> Empt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/invites")]
|
||||||
|
fn get_invites(_token: AdminToken, conn: DbConn) ->JsonResult {
|
||||||
|
let invites = Invitation::get_all(&conn);
|
||||||
|
let invites_json: Vec<Value> = invites.iter().map(|u| u.to_json(&conn)).collect();
|
||||||
|
|
||||||
|
Ok(Json(Value::Array(invites_json)))
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/users")]
|
#[get("/users")]
|
||||||
fn get_users(_token: AdminToken, conn: DbConn) ->JsonResult {
|
fn get_users(_token: AdminToken, conn: DbConn) ->JsonResult {
|
||||||
let users = User::get_all(&conn);
|
let users = User::get_all(&conn);
|
||||||
|
@ -239,6 +239,12 @@ impl Invitation {
|
|||||||
Self { email }
|
Self { email }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn to_json(&self, conn: &DbConn) -> Value {
|
||||||
|
json!({
|
||||||
|
"Email": self.email,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn save(&self, conn: &DbConn) -> EmptyResult {
|
pub fn save(&self, conn: &DbConn) -> EmptyResult {
|
||||||
if self.email.trim().is_empty() {
|
if self.email.trim().is_empty() {
|
||||||
err!("Invitation email can't be empty")
|
err!("Invitation email can't be empty")
|
||||||
@ -271,4 +277,8 @@ impl Invitation {
|
|||||||
None => false,
|
None => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_all(conn: &DbConn) -> Vec<Self> {
|
||||||
|
invitations::table.load::<Self>(&**conn).expect("Error loading invitations")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user