commit 1c2b376ca24f156311d15c1553f52e7482b36c05
parent 746ce2afb49fb1bb1d3c87c6f1419fb11418d06d
Author: Daniel GarcĂa <dani-garcia@users.noreply.github.com>
Date: Wed, 12 May 2021 23:05:20 +0200
Merge pull request #1663 from dongcarl/2021-05-invite_user-return
admin: Return newly-created user in invite_user
Diffstat:
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/src/api/admin.rs b/src/api/admin.rs
@@ -12,7 +12,7 @@ use rocket::{
use rocket_contrib::json::Json;
use crate::{
- api::{ApiResult, EmptyResult, NumberOrString},
+ api::{ApiResult, EmptyResult, JsonResult, NumberOrString},
auth::{decode_admin, encode_jwt, generate_admin_claims, ClientIp},
config::ConfigBuilder,
db::{backup_database, get_sql_server_version, models::*, DbConn, DbConnType},
@@ -30,6 +30,7 @@ pub fn routes() -> Vec<Route> {
routes![
admin_login,
get_users_json,
+ get_user_json,
post_admin_login,
admin_page,
invite_user,
@@ -279,7 +280,7 @@ struct InviteData {
}
#[post("/invite", data = "<data>")]
-fn invite_user(data: Json<InviteData>, _token: AdminToken, conn: DbConn) -> EmptyResult {
+fn invite_user(data: Json<InviteData>, _token: AdminToken, conn: DbConn) -> JsonResult {
let data: InviteData = data.into_inner();
let email = data.email.clone();
if User::find_by_mail(&data.email, &conn).is_some() {
@@ -287,14 +288,16 @@ fn invite_user(data: Json<InviteData>, _token: AdminToken, conn: DbConn) -> Empt
}
let mut user = User::new(email);
- user.save(&conn)?;
if CONFIG.mail_enabled() {
- mail::send_invite(&user.email, &user.uuid, None, None, &CONFIG.invitation_org_name(), None)
+ mail::send_invite(&user.email, &user.uuid, None, None, &CONFIG.invitation_org_name(), None)?;
} else {
let invitation = Invitation::new(data.email);
- invitation.save(&conn)
+ invitation.save(&conn)?;
}
+
+ user.save(&conn)?;
+ Ok(Json(user.to_json(&conn)))
}
#[post("/test/smtp", data = "<data>")]
@@ -347,6 +350,13 @@ fn users_overview(_token: AdminToken, conn: DbConn) -> ApiResult<Html<String>> {
Ok(Html(text))
}
+#[get("/users/<uuid>")]
+fn get_user_json(uuid: String, _token: AdminToken, conn: DbConn) -> JsonResult {
+ let user = User::find_by_uuid(&uuid, &conn).map_res("User doesn't exist")?;
+
+ Ok(Json(user.to_json(&conn)))
+}
+
#[post("/users/<uuid>/delete")]
fn delete_user(uuid: String, _token: AdminToken, conn: DbConn) -> EmptyResult {
let user = User::find_by_uuid(&uuid, &conn).map_res("User doesn't exist")?;