change_admin_status script fixes
This commit is contained in:
parent
5695c1b06e
commit
b2016190e1
@ -2,7 +2,7 @@ use anyhow::Context;
|
||||
use argh::FromArgs;
|
||||
use entities::{admin, login, user};
|
||||
use ethers::types::Address;
|
||||
use log::debug;
|
||||
use log::{debug, info};
|
||||
use migration::sea_orm::{
|
||||
self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, ModelTrait, QueryFilter,
|
||||
};
|
||||
@ -10,7 +10,7 @@ use migration::sea_orm::{
|
||||
/// 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 {
|
||||
pub struct ChangeAdminStatusSubCommand {
|
||||
/// the address of the user whose admin status you want to modify
|
||||
#[argh(positional)]
|
||||
address: String,
|
||||
@ -20,7 +20,7 @@ pub struct ChangeUserAdminStatusSubCommand {
|
||||
should_be_admin: bool,
|
||||
}
|
||||
|
||||
impl ChangeUserAdminStatusSubCommand {
|
||||
impl ChangeAdminStatusSubCommand {
|
||||
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;
|
||||
@ -34,17 +34,18 @@ impl ChangeUserAdminStatusSubCommand {
|
||||
.await?
|
||||
.context(format!("No user with this id found {:?}", address))?;
|
||||
|
||||
debug!("user: {:#?}", user);
|
||||
debug!("user: {}", serde_json::to_string_pretty(&user)?);
|
||||
|
||||
// Check if there is a record in the database
|
||||
match admin::Entity::find()
|
||||
.filter(admin::Column::UserId.eq(address))
|
||||
.filter(admin::Column::UserId.eq(user.id))
|
||||
.one(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?;
|
||||
info!("revoked admin status");
|
||||
}
|
||||
None if should_be_admin => {
|
||||
// User is not an admin yet, but should be
|
||||
@ -53,11 +54,11 @@ impl ChangeUserAdminStatusSubCommand {
|
||||
..Default::default()
|
||||
};
|
||||
new_admin.insert(db_conn).await?;
|
||||
info!("granted admin status");
|
||||
}
|
||||
_ => {
|
||||
// Do nothing in this case
|
||||
debug!("no change needed for: {:#?}", user);
|
||||
// Early return
|
||||
info!("no change needed for: {:#?}", user);
|
||||
// Since no change happened, we do not want to delete active logins. Return now.
|
||||
return Ok(());
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
mod change_admin_status;
|
||||
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;
|
||||
@ -67,8 +67,8 @@ pub struct Web3ProxyCli {
|
||||
#[derive(FromArgs, PartialEq, Debug)]
|
||||
#[argh(subcommand)]
|
||||
enum SubCommand {
|
||||
ChangeAdminStatus(change_admin_status::ChangeAdminStatusSubCommand),
|
||||
ChangeUserAddress(change_user_address::ChangeUserAddressSubCommand),
|
||||
ChangeUserAdminStatus(change_user_admin_status::ChangeUserAdminStatusSubCommand),
|
||||
ChangeUserTier(change_user_tier::ChangeUserTierSubCommand),
|
||||
ChangeUserTierByAddress(change_user_tier_by_address::ChangeUserTierByAddressSubCommand),
|
||||
ChangeUserTierByKey(change_user_tier_by_key::ChangeUserTierByKeySubCommand),
|
||||
@ -278,19 +278,19 @@ fn main() -> anyhow::Result<()> {
|
||||
|
||||
rt.block_on(async {
|
||||
match cli_config.sub_command {
|
||||
SubCommand::ChangeUserAddress(x) => {
|
||||
let db_url = cli_config
|
||||
.db_url
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run proxyd");
|
||||
SubCommand::ChangeAdminStatus(x) => {
|
||||
let db_url = cli_config.db_url.expect(
|
||||
"'--config' (with a db) or '--db-url' is required to run change_admin_status",
|
||||
);
|
||||
|
||||
let db_conn = get_db(db_url, 1, 1).await?;
|
||||
|
||||
x.main(&db_conn).await
|
||||
}
|
||||
SubCommand::ChangeUserAdminStatus(x) => {
|
||||
SubCommand::ChangeUserAddress(x) => {
|
||||
let db_url = cli_config
|
||||
.db_url
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run change_user_admin_status");
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run change_user_addres");
|
||||
|
||||
let db_conn = get_db(db_url, 1, 1).await?;
|
||||
|
||||
@ -299,16 +299,16 @@ fn main() -> anyhow::Result<()> {
|
||||
SubCommand::ChangeUserTier(x) => {
|
||||
let db_url = cli_config
|
||||
.db_url
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run proxyd");
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run change_user_tier");
|
||||
|
||||
let db_conn = get_db(db_url, 1, 1).await?;
|
||||
|
||||
x.main(&db_conn).await
|
||||
}
|
||||
SubCommand::ChangeUserTierByAddress(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_url = cli_config.db_url.expect(
|
||||
"'--config' (with a db) or '--db-url' is required to run change_user_tier_by_address",
|
||||
);
|
||||
|
||||
let db_conn = get_db(db_url, 1, 1).await?;
|
||||
|
||||
@ -317,7 +317,7 @@ fn main() -> anyhow::Result<()> {
|
||||
SubCommand::ChangeUserTierByKey(x) => {
|
||||
let db_url = cli_config
|
||||
.db_url
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run proxyd");
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run change_user_tier_by_key");
|
||||
|
||||
let db_conn = get_db(db_url, 1, 1).await?;
|
||||
|
||||
@ -336,7 +336,7 @@ fn main() -> anyhow::Result<()> {
|
||||
SubCommand::CreateUser(x) => {
|
||||
let db_url = cli_config
|
||||
.db_url
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run proxyd");
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run create_user");
|
||||
|
||||
let db_conn = get_migrated_db(db_url, 1, 1).await?;
|
||||
|
||||
@ -345,7 +345,7 @@ fn main() -> anyhow::Result<()> {
|
||||
SubCommand::CountUsers(x) => {
|
||||
let db_url = cli_config
|
||||
.db_url
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run proxyd");
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run count_users");
|
||||
|
||||
let db_conn = get_db(db_url, 1, 1).await?;
|
||||
|
||||
@ -361,9 +361,9 @@ fn main() -> anyhow::Result<()> {
|
||||
SubCommand::DropMigrationLock(x) => {
|
||||
let db_url = cli_config
|
||||
.db_url
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run proxyd");
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run drop_migration_lock");
|
||||
|
||||
// very intentionally, do NOT run migrations here
|
||||
// very intentionally, do NOT run migrations here. that would wait forever if the migration lock is abandoned
|
||||
let db_conn = get_db(db_url, 1, 1).await?;
|
||||
|
||||
x.main(&db_conn).await
|
||||
@ -376,9 +376,7 @@ fn main() -> anyhow::Result<()> {
|
||||
x.main(pagerduty_async, top_config).await
|
||||
}
|
||||
SubCommand::PopularityContest(x) => x.main().await,
|
||||
SubCommand::SearchKafka(x) => {
|
||||
x.main(top_config.unwrap()).await
|
||||
},
|
||||
SubCommand::SearchKafka(x) => x.main(top_config.unwrap()).await,
|
||||
SubCommand::Sentryd(x) => {
|
||||
if cli_config.sentry_url.is_none() {
|
||||
warn!("sentry_url is not set! Logs will only show in this console");
|
||||
@ -389,7 +387,7 @@ fn main() -> anyhow::Result<()> {
|
||||
SubCommand::RpcAccounting(x) => {
|
||||
let db_url = cli_config
|
||||
.db_url
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run proxyd");
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run rpc_accounting");
|
||||
|
||||
let db_conn = get_migrated_db(db_url, 1, 1).await?;
|
||||
|
||||
@ -398,7 +396,7 @@ fn main() -> anyhow::Result<()> {
|
||||
SubCommand::TransferKey(x) => {
|
||||
let db_url = cli_config
|
||||
.db_url
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run proxyd");
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run transfer_key");
|
||||
let db_conn = get_db(db_url, 1, 1).await?;
|
||||
|
||||
x.main(&db_conn).await
|
||||
@ -406,7 +404,7 @@ fn main() -> anyhow::Result<()> {
|
||||
SubCommand::UserExport(x) => {
|
||||
let db_url = cli_config
|
||||
.db_url
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run proxyd");
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run user_export");
|
||||
|
||||
let db_conn = get_migrated_db(db_url, 1, 1).await?;
|
||||
|
||||
@ -415,7 +413,7 @@ fn main() -> anyhow::Result<()> {
|
||||
SubCommand::UserImport(x) => {
|
||||
let db_url = cli_config
|
||||
.db_url
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run proxyd");
|
||||
.expect("'--config' (with a db) or '--db-url' is required to run user_import");
|
||||
|
||||
let db_conn = get_migrated_db(db_url, 1, 1).await?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user