Skip to content

Commit

Permalink
Merge pull request #6 from mixini/migrate
Browse files Browse the repository at this point in the history
migrate to latest versions of libraries
  • Loading branch information
fairingrey authored Apr 8, 2022
2 parents 782dac7 + 3a88758 commit f698b78
Show file tree
Hide file tree
Showing 8 changed files with 554 additions and 220 deletions.
703 changes: 498 additions & 205 deletions Cargo.lock

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ edition = "2021"
members = [".", "entity"]

[dependencies]
anyhow = "1.0.53"
axum = { version = "0.4.5", features = ["headers", "http2", "multipart"] }
anyhow = "1.0.56"
axum = { version = "0.5.1", features = ["headers", "http2", "multipart"] }
chrono = { version = "0.4.19", features = ["serde"] }
dotenv = "0.15.0"
entity = { path = "entity" }
fieldfilter = "0.1.0"
lazy_static = "1.4.0"
lettre = { version = "0.10.0-rc.4", features = [
lettre = { version = "0.10.0-rc.5", features = [
"tokio1",
"tokio1-native-tls",
"tracing",
"serde",
] }
libreauth = "0.14.1"
libreauth = "0.15.0"
oso = { git = "https://github.com/fairingrey/oso", branch = "rust-addl-interface", features = [
"uuid-07",
] }
Expand All @@ -35,8 +35,8 @@ redis = { version = "0.21.5", features = [
"tokio-comp",
"connection-manager",
], default-features = false }
regex = "1.5.4"
sea-orm = { version = "0.6.0", features = [
regex = "1.5.5"
sea-orm = { version = "0.7.1", features = [
"macros",
"debug-print",
"runtime-tokio-native-tls",
Expand All @@ -47,13 +47,16 @@ serde_json = "1.0.79"
thiserror = "1.0.30"
tokio = { version = "1.17.0", features = ["rt-multi-thread", "macros", "sync"] }
tower = "0.4.12"
tower-http = { version = "0.2.2", features = [
tower-http = { version = "0.2.5", features = [
"add-extension",
"trace",
"cors",
] }
tracing = "0.1.31"
tracing-subscriber = { version = "0.3.9", features = ["env-filter"] }
tracing = "0.1.32"
tracing-subscriber = { version = "0.3.10", features = ["env-filter"] }
ulid = { version = "0.5.0", features = ["serde", "uuid"] }
uuid = { version = "0.8.2", features = ["serde", "v4"] }
validator = { version = "0.14.0", features = ["derive"] }

[patch.crates-io]
sea-orm = { git = "https://github.com/fairingrey/sea-orm", branch = "changeset-like" }
2 changes: 1 addition & 1 deletion entity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ redis = { version = "0.21.5", features = [
"tokio-comp",
"connection-manager",
], default-features = false }
sea-orm = { version = "0.6.0", features = [
sea-orm = { version = "0.7.1", features = [
"macros",
"debug-print",
"runtime-tokio-native-tls",
Expand Down
15 changes: 14 additions & 1 deletion entity/src/sea_orm_active_enums.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.6.0
use oso::PolarClass;
use sea_orm::entity::prelude::*;
use sea_orm::{
entity::prelude::*,
ActiveValue::{self, NotSet},
IntoActiveValue, Set,
};
use serde::{Deserialize, Serialize};

#[derive(
Expand All @@ -22,3 +26,12 @@ pub enum UserRole {
#[sea_orm(string_value = "moderator")]
Moderator,
}

impl IntoActiveValue<UserRole> for Option<UserRole> {
fn into_active_value(self) -> ActiveValue<UserRole> {
match self {
Some(value) => Set(value),
None => NotSet,
}
}
}
15 changes: 15 additions & 0 deletions entity/src/user_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ pub struct Model {
pub verified: bool,
}

#[derive(Debug, DeriveIntoActiveModel)]
pub struct NewUserAccount {
pub id: Uuid,
pub name: String,
pub email: String,
pub password: String,
}

#[derive(Debug, DeriveIntoActiveModel)]
pub struct UpdateUserAccount {
pub name: Option<String>,
pub email: Option<String>,
pub role: Option<UserRole>,
}

#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {}

Expand Down
12 changes: 11 additions & 1 deletion src/actions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! CRUD action-like resources
use anyhow::Result;
use entity::sea_orm_active_enums::UserRole;
use entity::{sea_orm_active_enums::UserRole, user_account};
use oso::{Oso, PolarClass};
use serde::Deserialize;
use validator::Validate;
Expand Down Expand Up @@ -41,6 +41,16 @@ pub struct UpdateUser {
pub role: Option<UserRole>,
}

impl From<UpdateUser> for user_account::UpdateUserAccount {
fn from(update: UpdateUser) -> Self {
Self {
name: update.name,
email: update.email,
role: update.role,
}
}
}

/// Attempt to create a new oso instance for managing authorization schemes.
pub fn try_register_oso() -> Result<Oso> {
let mut oso = Oso::new();
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl IntoResponse for MixiniError {
}
},
MixiniError::ValidationError(_) => {
let message = format!("Input validation error: [{}]", self).replace("\n", ", ");
let message = format!("Input validation error: [{}]", self).replace('\n', ", ");
(StatusCode::BAD_REQUEST, message)
}
MixiniError::OtherError(e) => {
Expand Down
4 changes: 2 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use axum::{
routing::{get, post},
AddExtensionLayer, Router,
Extension, Router,
};
use lettre::{
transport::smtp::authentication::{Credentials, Mechanism},
Expand Down Expand Up @@ -94,7 +94,7 @@ async fn try_app() -> Result<Router> {

let middleware_stack = ServiceBuilder::new()
.layer(TraceLayer::new_for_http())
.layer(AddExtensionLayer::new(state))
.layer(Extension(state))
.layer(try_cors_layer()?);

Ok(Router::new()
Expand Down

0 comments on commit f698b78

Please sign in to comment.