continue rebase
This commit is contained in:
parent
34131c93f2
commit
bbe9061402
@ -2,7 +2,6 @@
|
||||
|
||||
pub mod prelude;
|
||||
|
||||
pub mod credits;
|
||||
pub mod admin;
|
||||
pub mod login;
|
||||
pub mod pending_login;
|
||||
|
@ -9,5 +9,4 @@ pub use super::secondary_user::Entity as SecondaryUser;
|
||||
pub use super::user::Entity as User;
|
||||
pub use super::user_tier::Entity as UserTier;
|
||||
pub use super::referral::Entity as Referral;
|
||||
pub use super::credits::Entity as Credits;
|
||||
pub use super::rpc_request::Entity as RpcRequest;
|
||||
|
@ -14,6 +14,7 @@ use hashbrown::HashMap;
|
||||
use http::StatusCode;
|
||||
use migration::sea_orm::{self, ActiveModelTrait, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter};
|
||||
use log::info;
|
||||
use redis_rate_limiter::redis::AsyncCommands;
|
||||
|
||||
|
||||
pub async fn query_admin_modify_usertier<'a>(
|
||||
@ -110,6 +111,9 @@ pub async fn query_admin_modify_usertier<'a>(
|
||||
|
||||
// Finally, remove the user from redis
|
||||
// TODO: Also remove the user from the redis
|
||||
// redis_conn.zrem();
|
||||
// redis_conn.get::<_, u64>(&user.) // TODO: Where do i find the bearer token ...
|
||||
|
||||
|
||||
Ok(Json(&response_body).into_response())
|
||||
|
||||
|
@ -0,0 +1,64 @@
|
||||
use anyhow::Context;
|
||||
use argh::FromArgs;
|
||||
use entities::{admin, user};
|
||||
use ethers::types::Address;
|
||||
use log::{debug, info};
|
||||
use migration::sea_orm::{
|
||||
self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, ModelTrait, IntoActiveModel,
|
||||
QueryFilter,
|
||||
};
|
||||
|
||||
/// change a user's admin status. eiter they are an admin, or they aren't
|
||||
#[derive(FromArgs, PartialEq, Eq, Debug)]
|
||||
#[argh(subcommand, name = "change_admin_status")]
|
||||
pub struct ChangeUserAdminStatusSubCommand {
|
||||
/// the address of the user whose admin status you want to modify
|
||||
#[argh(positional)]
|
||||
address: String,
|
||||
|
||||
/// true if the user should be an admin, false otherwise
|
||||
#[argh(positional)]
|
||||
should_be_admin: bool,
|
||||
}
|
||||
|
||||
impl ChangeUserAdminStatusSubCommand {
|
||||
pub async fn main(self, db_conn: &DatabaseConnection) -> anyhow::Result<()> {
|
||||
let address: Address = self.address.parse()?;
|
||||
let should_be_admin: bool = self.should_be_admin;
|
||||
|
||||
let address: Vec<u8> = address.to_fixed_bytes().into();
|
||||
|
||||
// Find user in database
|
||||
let user = user::Entity::find()
|
||||
.filter(user::Column::Address.eq(address.clone()))
|
||||
.one(db_conn)
|
||||
.await?
|
||||
.context("No user found with that address")?;
|
||||
|
||||
// Check if there is a record in the database
|
||||
let mut admin = admin::Entity::find()
|
||||
.filter(admin::Column::UserId.eq(address))
|
||||
.all(db_conn)
|
||||
.await?;
|
||||
|
||||
debug!("user: {:#?}", user);
|
||||
|
||||
match admin.pop() {
|
||||
None if should_be_admin => {
|
||||
// User is not an admin yet, but should be
|
||||
let new_admin = admin::ActiveModel {
|
||||
user_id: sea_orm::Set(user.id),
|
||||
..Default::default()
|
||||
};
|
||||
new_admin.insert(db_conn).await?;
|
||||
},
|
||||
Some(old_admin) if !should_be_admin => {
|
||||
// User is already an admin, but shouldn't be
|
||||
old_admin.delete(db_conn).await?;
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
mod change_user_address;
|
||||
mod change_user_admin_status;
|
||||
mod change_user_tier;
|
||||
mod change_user_tier_by_address;
|
||||
mod change_user_tier_by_key;
|
||||
@ -71,6 +72,7 @@ pub struct Web3ProxyCli {
|
||||
enum SubCommand {
|
||||
ChangeUserAddress(change_user_address::ChangeUserAddressSubCommand),
|
||||
ChangeUserTier(change_user_tier::ChangeUserTierSubCommand),
|
||||
ChangeUserAdminStatus(change_user_admin_status::ChangeUserAdminStatusSubCommand),
|
||||
ChangeUserTierByAddress(change_user_tier_by_address::ChangeUserTierByAddressSubCommand),
|
||||
ChangeUserTierByKey(change_user_tier_by_key::ChangeUserTierByKeySubCommand),
|
||||
CheckConfig(check_config::CheckConfigSubCommand),
|
||||
@ -286,6 +288,15 @@ fn main() -> anyhow::Result<()> {
|
||||
|
||||
x.main(&db_conn).await
|
||||
}
|
||||
SubCommand::ChangeUserAdminStatus(x) => {
|
||||
let db_url = cli_config
|
||||
.db_url
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run change user admin status");
|
||||
|
||||
let db_conn = get_db(db_url, 1, 1).await?;
|
||||
|
||||
x.main(&db_conn).await
|
||||
}
|
||||
SubCommand::ChangeUserTier(x) => {
|
||||
let db_url = cli_config
|
||||
.db_url
|
||||
|
Loading…
Reference in New Issue
Block a user