mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 05:26:59 +00:00
feat: add admin account enable route
Signed-off-by: İspik <ispik@ispik.dev>
This commit is contained in:
@@ -327,6 +327,7 @@ auto_derived! {
|
||||
DisableAccount,
|
||||
EmailChange,
|
||||
EmailVerify,
|
||||
EnableAccount,
|
||||
|
||||
// Channels
|
||||
DeleteChannel,
|
||||
@@ -383,6 +384,7 @@ impl AdminAuditItemActions {
|
||||
AdminAuditItemActions::DisableAccount => true,
|
||||
AdminAuditItemActions::EmailChange => true,
|
||||
AdminAuditItemActions::EmailVerify => true,
|
||||
AdminAuditItemActions::EnableAccount => true,
|
||||
AdminAuditItemActions::DeleteChannel => true,
|
||||
AdminAuditItemActions::EditChannel => true,
|
||||
AdminAuditItemActions::WipeChannel => true,
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
use crate::routes::admin::util::{
|
||||
create_audit_action, flatten_authorized_user, user_has_permission,
|
||||
};
|
||||
use revolt_database::{util::reference::Reference, AdminAuthorization, Database};
|
||||
use revolt_models::v0;
|
||||
use revolt_result::{create_error, Result};
|
||||
use rocket::State;
|
||||
use rocket_empty::EmptyResponse;
|
||||
|
||||
/// Enable an account. Requires ManageAccounts permissions
|
||||
#[openapi(tag = "Admin")]
|
||||
#[post("/accounts/enable/<target>?<case>")]
|
||||
pub async fn admin_account_enable(
|
||||
db: &State<Database>,
|
||||
auth: AdminAuthorization,
|
||||
target: Reference<'_>,
|
||||
case: Option<&str>,
|
||||
) -> Result<EmptyResponse> {
|
||||
let user = flatten_authorized_user(&auth);
|
||||
if !user_has_permission(user, v0::AdminUserPermissionFlags::ManageAccounts) {
|
||||
return Err(create_error!(MissingPermission {
|
||||
permission: "ManageAccounts".to_string()
|
||||
}));
|
||||
}
|
||||
|
||||
let target = target.as_user(db).await?;
|
||||
|
||||
if target.privileged {
|
||||
return Err(create_error!(PrivilegedAccount));
|
||||
}
|
||||
|
||||
let admin = db.admin_user_fetch(&target.id).await.ok();
|
||||
|
||||
if let Some(admin) = admin {
|
||||
if user_has_permission(&admin, v0::AdminUserPermissionFlags::ManageAccounts) {
|
||||
return Err(create_error!(PrivilegedAccount));
|
||||
}
|
||||
}
|
||||
|
||||
let mut account = db.fetch_account(&target.id).await?;
|
||||
|
||||
account.disabled = false;
|
||||
|
||||
account.save(db).await?;
|
||||
|
||||
create_audit_action(
|
||||
db,
|
||||
&user.id,
|
||||
v0::AdminAuditItemActions::EnableAccount,
|
||||
case,
|
||||
Some(&target.id),
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(EmptyResponse)
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ pub fn routes() -> (Vec<Route>, OpenApi) {
|
||||
accounts::account_disable::admin_account_disable,
|
||||
accounts::account_email_change::admin_account_email_change,
|
||||
accounts::account_email_verify::admin_account_email_verify,
|
||||
accounts::account_enable::admin_account_enable,
|
||||
channels::actions::channel_delete::admin_delete_channel,
|
||||
channels::actions::channel_edit::admin_channel_edit,
|
||||
channels::actions::channel_wipe::admin_channel_wipe,
|
||||
|
||||
Reference in New Issue
Block a user