Skip to content

Commit

Permalink
Add URL filters.
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Myers <[email protected]>
  • Loading branch information
Elizafox committed Mar 12, 2024
1 parent 94fee86 commit ab89e71
Show file tree
Hide file tree
Showing 20 changed files with 559 additions and 110 deletions.
80 changes: 35 additions & 45 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ service = { path = "service" }
askama = { version = "0.12.1", features = ["with-axum", "urlencode", "mime", "mime_guess"], default-features = false }
askama_axum = { version = "0.4.0", default-features = false, features = ["urlencode"] }
async-trait = "0.1.77"
axum = { version = "0.7.4", default-features = false, features = ["form", "http1", "http2", "macros", "tokio", "tower-log"] }
axum = { version = "0.7.4", features = ["form", "http1", "http2", "macros", "tokio", "tower-log"] }
axum-client-ip = "0.5.1"
axum-login = "0.14.0"
axum-messages = "0.5.0"
Expand All @@ -71,18 +71,19 @@ password-auth = "1.0.0"
proctitle = "0.1.1"
rand="0.8.5"
rand_distr = "0.4.3"
regex = "1.10.3"
rpassword = "7.3.1"
sea-orm = { version = "1.0.0-rc.1", default-features = false, features = ["macros", "runtime-tokio-native-tls", "with-time"] }
sea-query = { version = "0.31.0-rc.4", default-features = false, features = ["thread-safe", "with-time"] }
sea-orm = { version = "1.0.0-rc.1", features = ["macros", "runtime-tokio-native-tls", "with-time"] }
sea-query = { version = "0.31.0-rc.4", features = ["thread-safe", "with-time"] }
serde = { version = "1.0.197", features = ["derive"] }
thiserror = "1.0.57"
thiserror = "1.0.58"
time = "0.3.34"
tokio = { version = "1.36.0", default-features = false, features = ["macros", "parking_lot", "rt-multi-thread", "signal", "time"] }
tokio = { version = "1.36.0", features = ["macros", "parking_lot", "rt-multi-thread", "signal", "time"] }
tracing = { version = "0.1.40", features = ["async-await", "log"] }
tracing-subscriber = { version = "0.3.18", features = ["local-time", "parking_lot", "time"] }
tower = { version = "0.4.13", features = ["timeout", "tokio"] }
tower-http = { version = "0.5.2", features = ["fs", "normalize-path", "timeout", "tokio"] }
tower-sessions = { version = "0.11.0", default-features = false, features = ["axum-core"] }
tower-sessions = { version = "0.11.0", features = ["axum-core"] }
tower-sessions-redis-store = "0.11.0"
url = "2.5.0"
validator = { version = "0.17.0", features = ["derive"] }
8 changes: 4 additions & 4 deletions entity/src/url_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ pub struct Model {
pub id: i64,
#[sea_orm(unique)]
pub filter: String,
pub reason: String,
pub reason: Option<String>,
pub created_at: DateTime,
pub user_created_id: i64,
pub user_created_id: Option<i64>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand All @@ -20,8 +20,8 @@ pub enum Relation {
belongs_to = "super::user::Entity",
from = "Column::UserCreatedId",
to = "super::user::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
on_update = "Cascade",
on_delete = "SetNull"
)]
User,
}
Expand Down
4 changes: 2 additions & 2 deletions migration/src/m20240302_082409_create_user_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ impl MigrationTrait for Migration {
.col(
ColumnDef::new(User::Id)
.big_integer()
.primary_key()
.not_null()
.auto_increment()
.primary_key(),
.auto_increment(),
)
.col(
ColumnDef::new(User::Username)
Expand Down
79 changes: 79 additions & 0 deletions migration/src/m20240312_050549_create_url_filter_table.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* SPDX-License-Identifier: CC0-1.0
*
* migration/src/m20240312_050549_create_url_filter_table.rs
*
* This file is a component of ShadyURL by Elizabeth Myers.
*
* To the extent possible under law, the person who associated CC0 with
* ShadyURL has waived all copyright and related or neighboring rights
* to ShadyURL.
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/

use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(UrlFilter::Table)
.if_not_exists()
.col(
ColumnDef::new(UrlFilter::Id)
.big_integer()
.primary_key()
.not_null()
.auto_increment(),
)
.col(string(UrlFilter::Filter).not_null().unique_key())
.col(string(UrlFilter::Reason))
.col(
ColumnDef::new(UrlFilter::CreatedAt)
.date_time()
.default(Expr::current_timestamp())
.not_null(),
)
.col(big_integer(UrlFilter::UserCreatedId))
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-url_filter-user_created")
.from(UrlFilter::Table, UrlFilter::UserCreatedId)
.to(User::Table, User::Id)
.on_update(ForeignKeyAction::Cascade)
.on_delete(ForeignKeyAction::SetNull),
)
.to_owned(),
)
.await
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(UrlFilter::Table).to_owned())
.await
}
}

#[derive(DeriveIden)]
enum UrlFilter {
Table,
Id,
Filter,
Reason,
CreatedAt,
UserCreatedId,
}

#[allow(clippy::enum_variant_names)]
#[derive(Iden)]
enum User {
Table,
Id,
}
Loading

0 comments on commit ab89e71

Please sign in to comment.