should next write some simple end2end test

This commit is contained in:
yenicelik 2023-01-31 15:08:46 +01:00
parent c52ac83101
commit de8d665e40
5 changed files with 26 additions and 17 deletions

@ -6,11 +6,11 @@ pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
// Add a read-only column to the table
manager
.alter_table(
Table::alter()
.table(Alias::new("login"))
.table(Login::Table)
.add_column(
ColumnDef::new(Login::ReadOnly)
.boolean()
@ -20,13 +20,12 @@ impl MigrationTrait for Migration {
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
// Drop the column from the table ...
manager
.alter_table(
Table::alter()
.table(Alias::new("login"))
.drop_column(Alias::new("read_only"))
.table(Login::Table)
.drop_column(Login::ReadOnly)
.to_owned()
).await
}

@ -6,11 +6,10 @@ pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
manager
.alter_table(
Table::alter()
.table(Alias::new("pending_login"))
.table(PendingLogin::Table)
.add_column(
ColumnDef::new(PendingLogin::ImitatingUser)
.big_unsigned()
@ -27,13 +26,12 @@ impl MigrationTrait for Migration {
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
manager
.alter_table(
Table::alter()
.table(Alias::new("pending_login"))
.table(PendingLogin::Table)
.drop_foreign_key(Alias::new("fk-pending_login-imitating_user"))
.drop_column(Alias::new("imitating_user"))
.drop_column(PendingLogin::ImitatingUser)
.to_owned()
).await
}

@ -15,6 +15,7 @@ use http::StatusCode;
use migration::sea_orm::{self, ActiveModelTrait, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter};
use log::info;
use redis_rate_limiter::redis::AsyncCommands;
use crate::frontend::errors::FrontendErrorResponse::AccessDenied;
// TODO: Add some logic to check if the operating user is an admin
// If he is, return true
@ -79,7 +80,7 @@ pub async fn query_admin_modify_usertier<'a>(
.filter(admin::Column::UserId.eq(caller_id))
.one(&db_conn)
.await?
.context("This user is not registered as an admin")?;
.ok_or(AccessDenied.into())?;
// If we are here, that means an admin was found, and we can safely proceed
@ -88,7 +89,11 @@ pub async fn query_admin_modify_usertier<'a>(
.filter(user::Column::Address.eq(user_address))
.one(&db_conn)
.await?
.context("No user with this id found as the change")?;
.ok_or(FrontendErrorResponse::StatusCode(
StatusCode::BAD_REQUEST,
"No user with this id found".to_string(),
None,
))?;
// Return early if the target user_tier_id is the same as the original user_tier_id
response_body.insert(
"user_tier_title",
@ -96,11 +101,15 @@ pub async fn query_admin_modify_usertier<'a>(
);
// Now we can modify the user's tier
let new_user_tier: user_tier::Model = user_tier::Entity::find()
let new_user_tier: user_tier::Model = !user_tier::Entity::find()
.filter(user_tier::Column::Title.eq(user_tier_title.clone()))
.one(&db_conn)
.await?
.context("No user tier found with that name")?;
.ok_or(|| FrontendErrorResponse::StatusCode(
StatusCode::BAD_REQUEST,
"User Tier name was not found".to_string(),
None,
))?;
if user.user_tier_id == new_user_tier.id {
info!("user already has that tier");

@ -71,8 +71,8 @@ pub struct Web3ProxyCli {
#[argh(subcommand)]
enum SubCommand {
ChangeUserAddress(change_user_address::ChangeUserAddressSubCommand),
ChangeUserTier(change_user_tier::ChangeUserTierSubCommand),
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),
CheckConfig(check_config::CheckConfigSubCommand),

@ -173,8 +173,11 @@ pub async fn admin_login_get(
.filter(user::Column::Address.eq(user_address))
.one(db_replica.conn())
.await?
.context("fetching admin from db by user_id")?;
.ok_or(FrontendErrorResponse::StatusCode(
StatusCode::BAD_REQUEST,
"Could not find user in db".to_string(),
None,
))?;
// Can there be two login-sessions at the same time?
// I supposed if the user logs in, the admin would be logged out and vice versa