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![
|
||||
admin_login,
|
||||
get_users,
|
||||
get_invites,
|
||||
post_admin_login,
|
||||
admin_page,
|
||||
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")]
|
||||
fn get_users(_token: AdminToken, conn: DbConn) ->JsonResult {
|
||||
let users = User::get_all(&conn);
|
||||
|
@ -239,6 +239,12 @@ impl Invitation {
|
||||
Self { email }
|
||||
}
|
||||
|
||||
pub fn to_json(&self, conn: &DbConn) -> Value {
|
||||
json!({
|
||||
"Email": self.email,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn save(&self, conn: &DbConn) -> EmptyResult {
|
||||
if self.email.trim().is_empty() {
|
||||
err!("Invitation email can't be empty")
|
||||
@ -271,4 +277,8 @@ impl Invitation {
|
||||
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