Finish single api tken

This commit is contained in:
eraden 2024-02-10 15:56:11 +01:00
parent c406b5af6f
commit 694d89bcd5
12 changed files with 46 additions and 29 deletions

View File

@ -438,9 +438,9 @@ pub mod password {
pub mod magic_link {
use actix_web::web::Data;
use squadron_contract::*;
use rand::prelude::*;
use redis::AsyncCommands;
use squadron_contract::*;
use crate::http::AuthError;
use crate::models::Error;

View File

@ -3,9 +3,10 @@ use actix_web::web::{Data, Path, ServiceConfig};
use actix_web::{get, HttpResponse};
use entities::api_tokens::*;
use entities::prelude::ApiTokens;
use squadron_contract::{ApiTokenId, WorkspaceSlug};
use reqwest::StatusCode;
use sea_orm::prelude::*;
use sea_orm::*;
use squadron_contract::{ApiTokenId, WorkspaceSlug};
use tracing::error;
use crate::extractors::RequireInstanceConfigured;
@ -38,20 +39,27 @@ async fn single_api_token(
match ApiTokens::find()
.join(
JoinType::Join,
Relation::Workspaces1.def().on_condition(move |_left, right| {
use sea_query::*;
Relation::Workspaces1
.def()
.on_condition(move |_left, right| {
use sea_query::*;
Expr::col((right, entities::workspaces::Column::Slug))
.eq(slug.clone())
.into_condition()
}),
Expr::col((right, entities::workspaces::Column::Slug))
.eq(slug.clone())
.into_condition()
}),
)
.filter(Column::UserId.eq(user.id).and(Column::Id.eq(*id)))
.one(&**db)
.await
{
Ok(Some(token)) => Ok(HttpResponse::Ok().json(&token)),
Ok(None) => todo!(),
Err(e) => todo!(),
Ok(None) => {
Err(JsonError::new("API Token does not exists").with_status(StatusCode::NOT_FOUND))
}
Err(e) => {
error!("Failed to load single api token: {e}");
return Err(Error::DatabaseError)?;
}
}
}

View File

@ -103,9 +103,9 @@ mod tests {
use actix_web::http::header::ContentType;
use actix_web::web::Data;
use actix_web::{test, App};
use squadron_contract::deadpool_redis;
use reqwest::{Method, StatusCode};
use sea_orm::Database;
use squadron_contract::deadpool_redis;
use tracing_test::traced_test;
use uuid::Uuid;
@ -114,7 +114,10 @@ mod tests {
macro_rules! create_app {
($app: ident, $session_storage: ident, $db: ident) => {
std::env::set_var("DATABASE_URL", "postgres://postgres@0.0.0.0:5432/squadron_test");
std::env::set_var(
"DATABASE_URL",
"postgres://postgres@0.0.0.0:5432/squadron_test",
);
let redis = deadpool_redis::Config::from_url("redis://0.0.0.0:6379")
.create_pool(Some(deadpool_redis::Runtime::Tokio1))
.expect("Can't connect to redis");

View File

@ -3,11 +3,11 @@ use actix_web::web::{Data, Json};
use actix_web::{post, HttpRequest, HttpResponse};
use entities::prelude::WorkspaceMemberInvites;
use entities::users::Model as User;
use squadron_contract::event_bus::SignInMedium;
use sea_orm::prelude::*;
use sea_orm::{DatabaseConnection, DatabaseTransaction, EntityTrait, QueryFilter};
use serde::{Deserialize, Serialize};
use serde_email::Email;
use squadron_contract::event_bus::SignInMedium;
use super::{AuthError, PublishError};
use crate::config::ApplicationConfig;

View File

@ -1,9 +1,9 @@
use actix_web::web::Json;
use actix_web::{post, HttpRequest, HttpResponse};
use entities::users::Column;
use squadron_contract::event_bus::{EmailMsg, Topic};
use serde::{Deserialize, Serialize};
use serde_json::json;
use squadron_contract::event_bus::{EmailMsg, Topic};
use tracing::*;
use super::*;
@ -108,10 +108,10 @@ mod tests {
use actix_web::body::to_bytes;
use actix_web::web::Data;
use actix_web::{test, App};
use squadron_contract::deadpool_redis;
use reqwest::{Method, StatusCode};
use sea_orm::Database;
use serde_json::json;
use squadron_contract::deadpool_redis;
use tracing_test::traced_test;
use uuid::Uuid;
@ -122,7 +122,10 @@ mod tests {
macro_rules! create_app {
($app: ident, $session_storage: ident, $db: ident) => {
std::env::set_var("DATABASE_URL", "postgres://postgres@0.0.0.0:5432/squadron_test");
std::env::set_var(
"DATABASE_URL",
"postgres://postgres@0.0.0.0:5432/squadron_test",
);
let redis = deadpool_redis::Config::from_url("redis://0.0.0.0:6379")
.create_pool(Some(deadpool_redis::Runtime::Tokio1))
.expect("Can't connect to redis");

View File

@ -1,10 +1,10 @@
use actix_web::web::{Data, Json};
use actix_web::{post, HttpRequest, HttpResponse};
use squadron_contract::event_bus::{EmailMsg, Topic};
use sea_orm::prelude::*;
use sea_orm::{DatabaseConnection, DatabaseTransaction};
use serde::Deserialize;
use serde_json::json;
use squadron_contract::event_bus::{EmailMsg, Topic};
use tracing::{error, warn};
use super::{create_user, random_password};

View File

@ -1,13 +1,13 @@
use actix_jwt_session::SessionStorage;
use actix_web::web::{Data, Json};
use actix_web::{post, HttpRequest, HttpResponse};
use squadron_contract::event_bus::{Msg, SignInMedium, Topic, UserMsg};
use squadron_contract::redis::AsyncCommands;
use reqwest::StatusCode;
use rumqttc::QoS;
use sea_orm::prelude::*;
use sea_orm::*;
use serde::Deserialize;
use squadron_contract::event_bus::{Msg, SignInMedium, Topic, UserMsg};
use squadron_contract::redis::AsyncCommands;
use super::auth_http_response;
use crate::extractors::RequireInstanceConfigured;

View File

@ -121,9 +121,9 @@ mod tests {
use actix_web::http::header::ContentType;
use actix_web::web::Data;
use actix_web::{test, App};
use squadron_contract::deadpool_redis;
use reqwest::{Method, StatusCode};
use sea_orm::Database;
use squadron_contract::deadpool_redis;
use tracing_test::traced_test;
use uuid::Uuid;
@ -135,7 +135,10 @@ mod tests {
macro_rules! create_app {
($app: ident, $session_storage: ident, $db: ident) => {
std::env::set_var("DATABASE_URL", "postgres://postgres@0.0.0.0:5432/squadron_test");
std::env::set_var(
"DATABASE_URL",
"postgres://postgres@0.0.0.0:5432/squadron_test",
);
let redis = deadpool_redis::Config::from_url("redis://0.0.0.0:6379")
.create_pool(Some(deadpool_redis::Runtime::Tokio1))
.expect("Can't connect to redis");

View File

@ -3,11 +3,11 @@ use actix_web::web::{Data, Json};
use actix_web::{post, HttpRequest, HttpResponse};
use entities::prelude::Users;
use entities::users::ActiveModel as UserModel;
use squadron_contract::event_bus::{Msg, SignInMedium, Topic, UserMsg};
use squadron_contract::UserId;
use reqwest::StatusCode;
use rumqttc::QoS;
use sea_orm::*;
use squadron_contract::event_bus::{Msg, SignInMedium, Topic, UserMsg};
use squadron_contract::UserId;
use validators::prelude::*;
use super::EmailAllowComment;

View File

@ -3,11 +3,11 @@ use actix_web::web::{Data, Json};
use actix_web::{post, HttpRequest, HttpResponse, ResponseError};
use entities::prelude::Users;
use entities::users::ActiveModel as UserModel;
use squadron_contract::event_bus::{Msg, SignInMedium, Topic, UserMsg};
use squadron_contract::UserId;
use reqwest::StatusCode;
use rumqttc::QoS;
use sea_orm::{DatabaseConnection, *};
use squadron_contract::event_bus::{Msg, SignInMedium, Topic, UserMsg};
use squadron_contract::UserId;
use validators::prelude::*;
use super::EmailAllowComment;

View File

@ -4,8 +4,6 @@ use actix_web::web::{self, Data, ServiceConfig};
use actix_web::{get, HttpRequest, HttpResponse};
use entities::users::ActiveModel as UserModel;
use http_api_isahc_client::IsahcClient;
use squadron_contract::event_bus::{Msg, SignInMedium, Topic, UserMsg};
use squadron_contract::UserId;
use oauth2_amazon::{
AmazonExtensionsBuilder, AmazonProviderWithWebServices, AmazonScope, AmazonTokenUrlRegion,
};
@ -23,6 +21,8 @@ use reqwest::header::LOCATION;
use reqwest::StatusCode;
use sea_orm::ActiveValue::NotSet;
use sea_orm::{ActiveModelTrait, DatabaseConnection, DatabaseTransaction, Set};
use squadron_contract::event_bus::{Msg, SignInMedium, Topic, UserMsg};
use squadron_contract::UserId;
use tracing::{debug, error, warn};
use super::{auth_http_response, AuthError};

View File

@ -3,10 +3,10 @@ use std::env;
use actix_jwt_session::*;
use actix_web::web::Data;
use actix_web::{App, HttpServer};
pub use squadron_contract::event_bus::Client as EventBusClient;
pub use squadron_contract::{deadpool_redis, redis, RedisClient};
use models::PasswordResetSecret;
pub use sea_orm::{Database, DatabaseConnection};
pub use squadron_contract::event_bus::Client as EventBusClient;
pub use squadron_contract::{deadpool_redis, redis, RedisClient};
pub mod config;
pub mod events;