mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-02-23 06:06:22 +00:00
Merge branch 'main' into image-api-rework
This commit is contained in:
commit
2ec8cd3a52
113 changed files with 2788 additions and 2277 deletions
|
@ -6,7 +6,7 @@ variables:
|
||||||
# as well. Otherwise release builds can fail if Lemmy or dependencies rely on new Rust
|
# as well. Otherwise release builds can fail if Lemmy or dependencies rely on new Rust
|
||||||
# features. In particular the ARM builder image needs to be updated manually in the repo below:
|
# features. In particular the ARM builder image needs to be updated manually in the repo below:
|
||||||
# https://github.com/raskyld/lemmy-cross-toolchains
|
# https://github.com/raskyld/lemmy-cross-toolchains
|
||||||
- &rust_image "rust:1.81"
|
- &rust_image "rust:1.83"
|
||||||
- &rust_nightly_image "rustlang/rust:nightly"
|
- &rust_nightly_image "rustlang/rust:nightly"
|
||||||
- &install_pnpm "corepack enable pnpm"
|
- &install_pnpm "corepack enable pnpm"
|
||||||
- &install_binstall "wget -O- https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz | tar -xvz -C /usr/local/cargo/bin"
|
- &install_binstall "wget -O- https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz | tar -xvz -C /usr/local/cargo/bin"
|
||||||
|
|
96
Cargo.lock
generated
96
Cargo.lock
generated
|
@ -435,9 +435,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.93"
|
version = "1.0.95"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775"
|
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
]
|
]
|
||||||
|
@ -460,9 +460,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-compression"
|
name = "async-compression"
|
||||||
version = "0.4.12"
|
version = "0.4.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fec134f64e2bc57411226dfc4e52dec859ddfc7e711fc5e07b612584f000e4aa"
|
checksum = "df895a515f70646414f4b45c0b79082783b80552b373a68283012928df56f522"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"flate2",
|
"flate2",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
@ -495,15 +495,15 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atom_syndication"
|
name = "atom_syndication"
|
||||||
version = "0.12.4"
|
version = "0.12.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2a3a5ed3201df5658d1aa45060c5a57dc9dba8a8ada20d696d67cb0c479ee043"
|
checksum = "3ee79fb83c725eae67b55218870813d2fc39fd85e4f1583848ef9f4f823cfe7c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"derive_builder",
|
"derive_builder",
|
||||||
"diligent-date-parser",
|
"diligent-date-parser",
|
||||||
"never",
|
"never",
|
||||||
"quick-xml 0.36.1",
|
"quick-xml 0.37.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -514,21 +514,20 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aws-lc-rs"
|
name = "aws-lc-rs"
|
||||||
version = "1.9.0"
|
version = "1.11.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2f95446d919226d587817a7d21379e6eb099b97b45110a7f272a444ca5c54070"
|
checksum = "f47bb8cc16b669d267eeccf585aea077d0882f4777b1c1f740217885d6e6e5a3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aws-lc-sys",
|
"aws-lc-sys",
|
||||||
"mirai-annotations",
|
|
||||||
"paste",
|
"paste",
|
||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aws-lc-sys"
|
name = "aws-lc-sys"
|
||||||
version = "0.21.1"
|
version = "0.23.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "234314bd569802ec87011d653d6815c6d7b9ffb969e9fee5b8b20ef860e8dce9"
|
checksum = "a2101df3813227bbaaaa0b04cd61c534c7954b22bd68d399b440be937dc63ff7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
"cc",
|
"cc",
|
||||||
|
@ -618,9 +617,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bindgen"
|
name = "bindgen"
|
||||||
version = "0.69.4"
|
version = "0.69.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0"
|
checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.6.0",
|
"bitflags 2.6.0",
|
||||||
"cexpr",
|
"cexpr",
|
||||||
|
@ -798,9 +797,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.4.38"
|
version = "0.4.39"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
|
checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"android-tzdata",
|
"android-tzdata",
|
||||||
"iana-time-zone",
|
"iana-time-zone",
|
||||||
|
@ -844,9 +843,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.5.21"
|
version = "4.5.23"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f"
|
checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap_builder",
|
"clap_builder",
|
||||||
"clap_derive",
|
"clap_derive",
|
||||||
|
@ -854,9 +853,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_builder"
|
name = "clap_builder"
|
||||||
version = "4.5.21"
|
version = "4.5.23"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec"
|
checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
|
@ -878,9 +877,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_lex"
|
name = "clap_lex"
|
||||||
version = "0.7.2"
|
version = "0.7.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97"
|
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clearurls"
|
name = "clearurls"
|
||||||
|
@ -907,9 +906,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cmake"
|
name = "cmake"
|
||||||
version = "0.1.51"
|
version = "0.1.52"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fb1e43aa7fd152b1f968787f7dbcdeb306d1867ff373c69955211876c053f91a"
|
checksum = "c682c223677e0e5b6b7f63a64b9351844c3f1b1678a68b7ee617e30fb082620e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
@ -1374,9 +1373,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "diligent-date-parser"
|
name = "diligent-date-parser"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f6cf7fe294274a222363f84bcb63cdea762979a0443b4cf1f4f8fd17c86b1182"
|
checksum = "c8ede7d79366f419921e2e2f67889c12125726692a313bffb474bd5f37a581e9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
]
|
]
|
||||||
|
@ -1471,9 +1470,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "email-encoding"
|
name = "email-encoding"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "60d1d33cdaede7e24091f039632eb5d3c7469fe5b066a985281a34fc70fa317f"
|
checksum = "ea3d894bbbab314476b265f9b2d46bf24b123a36dd0e96b06a1b49545b9d9dcc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
@ -1599,9 +1598,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fastrand"
|
name = "fastrand"
|
||||||
version = "2.1.1"
|
version = "2.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6"
|
checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fdeflate"
|
name = "fdeflate"
|
||||||
|
@ -2685,8 +2684,10 @@ dependencies = [
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"serde_with",
|
"serde_with",
|
||||||
"serial_test",
|
"serial_test",
|
||||||
|
"test-context",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"ts-rs",
|
"ts-rs",
|
||||||
|
@ -2805,7 +2806,6 @@ dependencies = [
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"prometheus",
|
"prometheus",
|
||||||
"reqwest 0.12.8",
|
|
||||||
"reqwest-middleware",
|
"reqwest-middleware",
|
||||||
"reqwest-tracing",
|
"reqwest-tracing",
|
||||||
"rustls 0.23.16",
|
"rustls 0.23.16",
|
||||||
|
@ -2896,12 +2896,12 @@ checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libloading"
|
name = "libloading"
|
||||||
version = "0.8.5"
|
version = "0.8.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
|
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"windows-targets 0.52.6",
|
"windows-targets 0.48.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3218,12 +3218,6 @@ dependencies = [
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "mirai-annotations"
|
|
||||||
version = "1.12.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c9be0862c1b3f26a88803c4a49de6889c10e608b3ee9344e6ef5b45fb37ad3d1"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mockall"
|
name = "mockall"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
|
@ -3597,9 +3591,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pkg-config"
|
name = "pkg-config"
|
||||||
version = "0.3.30"
|
version = "0.3.31"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
|
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "plist"
|
name = "plist"
|
||||||
|
@ -3724,9 +3718,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "prettyplease"
|
name = "prettyplease"
|
||||||
version = "0.2.22"
|
version = "0.2.25"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba"
|
checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"syn 2.0.87",
|
"syn 2.0.87",
|
||||||
|
@ -3820,16 +3814,6 @@ dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quick-xml"
|
|
||||||
version = "0.36.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "96a05e2e8efddfa51a84ca47cec303fac86c8541b686d37cac5efc0e094417bc"
|
|
||||||
dependencies = [
|
|
||||||
"encoding_rs",
|
|
||||||
"memchr",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quick-xml"
|
name = "quick-xml"
|
||||||
version = "0.37.1"
|
version = "0.37.1"
|
||||||
|
@ -4323,9 +4307,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustversion"
|
name = "rustversion"
|
||||||
version = "1.0.17"
|
version = "1.0.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6"
|
checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
|
|
14
Cargo.toml
14
Cargo.toml
|
@ -103,21 +103,21 @@ diesel-async = "0.5.1"
|
||||||
serde = { version = "1.0.215", features = ["derive"] }
|
serde = { version = "1.0.215", features = ["derive"] }
|
||||||
serde_with = "3.9.0"
|
serde_with = "3.9.0"
|
||||||
actix-web = { version = "4.9.0", default-features = false, features = [
|
actix-web = { version = "4.9.0", default-features = false, features = [
|
||||||
"macros",
|
|
||||||
"rustls-0_23",
|
|
||||||
"compress-brotli",
|
"compress-brotli",
|
||||||
"compress-gzip",
|
"compress-gzip",
|
||||||
"compress-zstd",
|
"compress-zstd",
|
||||||
"cookies",
|
"cookies",
|
||||||
|
"macros",
|
||||||
|
"rustls-0_23",
|
||||||
] }
|
] }
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-actix-web = { version = "0.7.10", default-features = false }
|
tracing-actix-web = { version = "0.7.10", default-features = false }
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||||
url = { version = "2.5.3", features = ["serde"] }
|
url = { version = "2.5.3", features = ["serde"] }
|
||||||
reqwest = { version = "0.12.7", default-features = false, features = [
|
reqwest = { version = "0.12.7", default-features = false, features = [
|
||||||
"json",
|
|
||||||
"blocking",
|
"blocking",
|
||||||
"gzip",
|
"gzip",
|
||||||
|
"json",
|
||||||
"rustls-tls",
|
"rustls-tls",
|
||||||
] }
|
] }
|
||||||
reqwest-middleware = "0.3.3"
|
reqwest-middleware = "0.3.3"
|
||||||
|
@ -126,17 +126,15 @@ clokwerk = "0.4.0"
|
||||||
doku = { version = "0.21.1", features = ["url-2"] }
|
doku = { version = "0.21.1", features = ["url-2"] }
|
||||||
bcrypt = "0.15.1"
|
bcrypt = "0.15.1"
|
||||||
chrono = { version = "0.4.38", features = [
|
chrono = { version = "0.4.38", features = [
|
||||||
"serde",
|
|
||||||
"now",
|
"now",
|
||||||
|
"serde",
|
||||||
], default-features = false }
|
], default-features = false }
|
||||||
serde_json = { version = "1.0.132", features = ["preserve_order"] }
|
serde_json = { version = "1.0.132", features = ["preserve_order"] }
|
||||||
base64 = "0.22.1"
|
base64 = "0.22.1"
|
||||||
uuid = { version = "1.11.0", features = ["serde"] }
|
uuid = { version = "1.11.0", features = ["serde"] }
|
||||||
async-trait = "0.1.83"
|
async-trait = "0.1.83"
|
||||||
captcha = "0.0.9"
|
captcha = "0.0.9"
|
||||||
anyhow = { version = "1.0.93", features = [
|
anyhow = { version = "1.0.93", features = ["backtrace"] }
|
||||||
"backtrace",
|
|
||||||
] } # backtrace is on by default on nightly, but not stable rust
|
|
||||||
diesel_ltree = "0.3.1"
|
diesel_ltree = "0.3.1"
|
||||||
serial_test = "3.2.0"
|
serial_test = "3.2.0"
|
||||||
tokio = { version = "1.41.1", features = ["full"] }
|
tokio = { version = "1.41.1", features = ["full"] }
|
||||||
|
@ -149,7 +147,6 @@ futures = "0.3.31"
|
||||||
http = "1.1"
|
http = "1.1"
|
||||||
rosetta-i18n = "0.1.3"
|
rosetta-i18n = "0.1.3"
|
||||||
ts-rs = { version = "10.0.0", features = [
|
ts-rs = { version = "10.0.0", features = [
|
||||||
"serde-compat",
|
|
||||||
"chrono-impl",
|
"chrono-impl",
|
||||||
"no-serde-warnings",
|
"no-serde-warnings",
|
||||||
"url-impl",
|
"url-impl",
|
||||||
|
@ -185,7 +182,6 @@ tracing = { workspace = true }
|
||||||
tracing-actix-web = { workspace = true }
|
tracing-actix-web = { workspace = true }
|
||||||
tracing-subscriber = { workspace = true }
|
tracing-subscriber = { workspace = true }
|
||||||
url = { workspace = true }
|
url = { workspace = true }
|
||||||
reqwest = { workspace = true }
|
|
||||||
reqwest-middleware = { workspace = true }
|
reqwest-middleware = { workspace = true }
|
||||||
reqwest-tracing = { workspace = true }
|
reqwest-tracing = { workspace = true }
|
||||||
clokwerk = { workspace = true }
|
clokwerk = { workspace = true }
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
"eslint": "^9.14.0",
|
"eslint": "^9.14.0",
|
||||||
"eslint-plugin-prettier": "^5.1.3",
|
"eslint-plugin-prettier": "^5.1.3",
|
||||||
"jest": "^29.5.0",
|
"jest": "^29.5.0",
|
||||||
"lemmy-js-client": "0.20.0-image-api-rework.6",
|
"lemmy-js-client": "0.20.0-image-api-rework.7",
|
||||||
"prettier": "^3.2.5",
|
"prettier": "^3.2.5",
|
||||||
"ts-jest": "^29.1.0",
|
"ts-jest": "^29.1.0",
|
||||||
"typescript": "^5.5.4",
|
"typescript": "^5.5.4",
|
||||||
|
|
|
@ -30,8 +30,8 @@ importers:
|
||||||
specifier: ^29.5.0
|
specifier: ^29.5.0
|
||||||
version: 29.7.0(@types/node@22.9.0)
|
version: 29.7.0(@types/node@22.9.0)
|
||||||
lemmy-js-client:
|
lemmy-js-client:
|
||||||
specifier: 0.20.0-image-api-rework.5
|
specifier: 0.20.0-image-api-rework.7
|
||||||
version: 0.20.0-image-api-rework.5
|
version: 0.20.0-image-api-rework.7
|
||||||
prettier:
|
prettier:
|
||||||
specifier: ^3.2.5
|
specifier: ^3.2.5
|
||||||
version: 3.3.3
|
version: 3.3.3
|
||||||
|
@ -1167,8 +1167,8 @@ packages:
|
||||||
resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==}
|
resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
|
|
||||||
lemmy-js-client@0.20.0-image-api-rework.5:
|
lemmy-js-client@0.20.0-image-api-rework.7:
|
||||||
resolution: {integrity: sha512-fMbgLefWy7B1QtX6c7Y/CMAbV70tKpT5eDKsdnCtKhV1eB73pATKNPaFtrMuAYu9h13M6LDlry6mX7CeWuJb6Q==}
|
resolution: {integrity: sha512-zZVOu8l9ctwEof71/DDkg/pwwBercLJIJja7KT1WxYS2pG6Hng9bD0+VDesbdvacCltFDbbEvk8pgJs3ES4OIQ==}
|
||||||
|
|
||||||
leven@3.1.0:
|
leven@3.1.0:
|
||||||
resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==}
|
resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==}
|
||||||
|
@ -3077,7 +3077,7 @@ snapshots:
|
||||||
|
|
||||||
kleur@3.0.3: {}
|
kleur@3.0.3: {}
|
||||||
|
|
||||||
lemmy-js-client@0.20.0-image-api-rework.5: {}
|
lemmy-js-client@0.20.0-image-api-rework.7: {}
|
||||||
|
|
||||||
leven@3.1.0: {}
|
leven@3.1.0: {}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,9 @@ export LEMMY_TEST_FAST_FEDERATION=1 # by default, the persistent federation queu
|
||||||
|
|
||||||
# pictrs setup
|
# pictrs setup
|
||||||
if [ ! -f "api_tests/pict-rs" ]; then
|
if [ ! -f "api_tests/pict-rs" ]; then
|
||||||
curl "https://git.asonix.dog/asonix/pict-rs/releases/download/v0.5.16/pict-rs-linux-amd64" -o api_tests/pict-rs
|
# This one sometimes goes down
|
||||||
|
# curl "https://git.asonix.dog/asonix/pict-rs/releases/download/v0.5.16/pict-rs-linux-amd64" -o api_tests/pict-rs
|
||||||
|
curl "https://codeberg.org/asonix/pict-rs/releases/download/v0.5.6/pict-rs-linux-amd64" -o api_tests/pict-rs
|
||||||
chmod +x api_tests/pict-rs
|
chmod +x api_tests/pict-rs
|
||||||
fi
|
fi
|
||||||
./api_tests/pict-rs \
|
./api_tests/pict-rs \
|
||||||
|
|
|
@ -22,7 +22,6 @@ import {
|
||||||
createCommunity,
|
createCommunity,
|
||||||
registerUser,
|
registerUser,
|
||||||
reportComment,
|
reportComment,
|
||||||
listCommentReports,
|
|
||||||
randomString,
|
randomString,
|
||||||
unfollows,
|
unfollows,
|
||||||
getComments,
|
getComments,
|
||||||
|
@ -38,8 +37,15 @@ import {
|
||||||
blockCommunity,
|
blockCommunity,
|
||||||
delay,
|
delay,
|
||||||
saveUserSettings,
|
saveUserSettings,
|
||||||
|
listReports,
|
||||||
} from "./shared";
|
} from "./shared";
|
||||||
import { CommentView, CommunityView, SaveUserSettings } from "lemmy-js-client";
|
import {
|
||||||
|
CommentReportView,
|
||||||
|
CommentView,
|
||||||
|
CommunityView,
|
||||||
|
ReportCombinedView,
|
||||||
|
SaveUserSettings,
|
||||||
|
} from "lemmy-js-client";
|
||||||
|
|
||||||
let betaCommunity: CommunityView | undefined;
|
let betaCommunity: CommunityView | undefined;
|
||||||
let postOnAlphaRes: PostResponse;
|
let postOnAlphaRes: PostResponse;
|
||||||
|
@ -796,13 +802,17 @@ test("Report a comment", async () => {
|
||||||
let alphaReport = (await reportComment(alpha, alphaComment.id, reason))
|
let alphaReport = (await reportComment(alpha, alphaComment.id, reason))
|
||||||
.comment_report_view.comment_report;
|
.comment_report_view.comment_report;
|
||||||
|
|
||||||
let betaReport = (await waitUntil(
|
let betaReport = (
|
||||||
() =>
|
(await waitUntil(
|
||||||
listCommentReports(beta).then(r =>
|
() =>
|
||||||
r.comment_reports.find(rep => rep.comment_report.reason === reason),
|
listReports(beta).then(p =>
|
||||||
),
|
p.reports.find(r => {
|
||||||
e => !!e,
|
return checkCommentReportReason(r, reason);
|
||||||
))!.comment_report;
|
}),
|
||||||
|
),
|
||||||
|
e => !!e,
|
||||||
|
)!) as CommentReportView
|
||||||
|
).comment_report;
|
||||||
expect(betaReport).toBeDefined();
|
expect(betaReport).toBeDefined();
|
||||||
expect(betaReport.resolved).toBe(false);
|
expect(betaReport.resolved).toBe(false);
|
||||||
expect(betaReport.original_comment_text).toBe(
|
expect(betaReport.original_comment_text).toBe(
|
||||||
|
@ -877,3 +887,12 @@ test.skip("Fetch a deeply nested comment", async () => {
|
||||||
expect(betaComment!.comment!.comment).toBeDefined();
|
expect(betaComment!.comment!.comment).toBeDefined();
|
||||||
expect(betaComment?.comment?.post).toBeDefined();
|
expect(betaComment?.comment?.post).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function checkCommentReportReason(rcv: ReportCombinedView, reason: string) {
|
||||||
|
switch (rcv.type_) {
|
||||||
|
case "Comment":
|
||||||
|
return rcv.comment_report.reason === reason;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -572,7 +572,7 @@ test("Remote mods can edit communities", async () => {
|
||||||
communityRes.community_view.community.id,
|
communityRes.community_view.community.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
await expect(alphaCommunity.community_view.community.description).toBe(
|
expect(alphaCommunity.community_view.community.description).toBe(
|
||||||
"Example description",
|
"Example description",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,7 +27,6 @@ import {
|
||||||
followCommunity,
|
followCommunity,
|
||||||
banPersonFromCommunity,
|
banPersonFromCommunity,
|
||||||
reportPost,
|
reportPost,
|
||||||
listPostReports,
|
|
||||||
randomString,
|
randomString,
|
||||||
registerUser,
|
registerUser,
|
||||||
unfollows,
|
unfollows,
|
||||||
|
@ -37,11 +36,18 @@ import {
|
||||||
alphaUrl,
|
alphaUrl,
|
||||||
loginUser,
|
loginUser,
|
||||||
createCommunity,
|
createCommunity,
|
||||||
|
listReports,
|
||||||
getMyUser,
|
getMyUser,
|
||||||
} from "./shared";
|
} from "./shared";
|
||||||
import { PostView } from "lemmy-js-client/dist/types/PostView";
|
import { PostView } from "lemmy-js-client/dist/types/PostView";
|
||||||
import { AdminBlockInstanceParams } from "lemmy-js-client/dist/types/AdminBlockInstanceParams";
|
import { AdminBlockInstanceParams } from "lemmy-js-client/dist/types/AdminBlockInstanceParams";
|
||||||
import { EditSite, ResolveObject } from "lemmy-js-client";
|
import {
|
||||||
|
EditSite,
|
||||||
|
PostReport,
|
||||||
|
PostReportView,
|
||||||
|
ReportCombinedView,
|
||||||
|
ResolveObject,
|
||||||
|
} from "lemmy-js-client";
|
||||||
|
|
||||||
let betaCommunity: CommunityView | undefined;
|
let betaCommunity: CommunityView | undefined;
|
||||||
|
|
||||||
|
@ -687,16 +693,17 @@ test("Report a post", async () => {
|
||||||
expect(gammaReport).toBeDefined();
|
expect(gammaReport).toBeDefined();
|
||||||
|
|
||||||
// Report was federated to community instance
|
// Report was federated to community instance
|
||||||
let betaReport = (await waitUntil(
|
let betaReport = (
|
||||||
() =>
|
(await waitUntil(
|
||||||
listPostReports(beta).then(p =>
|
() =>
|
||||||
p.post_reports.find(
|
listReports(beta).then(p =>
|
||||||
r =>
|
p.reports.find(r => {
|
||||||
r.post_report.original_post_name === gammaReport.original_post_name,
|
return checkPostReportName(r, gammaReport);
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
),
|
res => !!res,
|
||||||
res => !!res,
|
))! as PostReportView
|
||||||
))!.post_report;
|
).post_report;
|
||||||
expect(betaReport).toBeDefined();
|
expect(betaReport).toBeDefined();
|
||||||
expect(betaReport.resolved).toBe(false);
|
expect(betaReport.resolved).toBe(false);
|
||||||
expect(betaReport.original_post_name).toBe(gammaReport.original_post_name);
|
expect(betaReport.original_post_name).toBe(gammaReport.original_post_name);
|
||||||
|
@ -706,16 +713,17 @@ test("Report a post", async () => {
|
||||||
await unfollowRemotes(alpha);
|
await unfollowRemotes(alpha);
|
||||||
|
|
||||||
// Report was federated to poster's instance
|
// Report was federated to poster's instance
|
||||||
let alphaReport = (await waitUntil(
|
let alphaReport = (
|
||||||
() =>
|
(await waitUntil(
|
||||||
listPostReports(alpha).then(p =>
|
() =>
|
||||||
p.post_reports.find(
|
listReports(alpha).then(p =>
|
||||||
r =>
|
p.reports.find(r => {
|
||||||
r.post_report.original_post_name === gammaReport.original_post_name,
|
return checkPostReportName(r, gammaReport);
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
),
|
res => !!res,
|
||||||
res => !!res,
|
))! as PostReportView
|
||||||
))!.post_report;
|
).post_report;
|
||||||
expect(alphaReport).toBeDefined();
|
expect(alphaReport).toBeDefined();
|
||||||
expect(alphaReport.resolved).toBe(false);
|
expect(alphaReport.resolved).toBe(false);
|
||||||
expect(alphaReport.original_post_name).toBe(gammaReport.original_post_name);
|
expect(alphaReport.original_post_name).toBe(gammaReport.original_post_name);
|
||||||
|
@ -816,3 +824,12 @@ test("Rewrite markdown links", async () => {
|
||||||
`[link](http://lemmy-alpha:8541/post/${alphaPost1.post?.post.id})`,
|
`[link](http://lemmy-alpha:8541/post/${alphaPost1.post?.post.id})`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function checkPostReportName(rcv: ReportCombinedView, report: PostReport) {
|
||||||
|
switch (rcv.type_) {
|
||||||
|
case "Post":
|
||||||
|
return rcv.post_report.original_post_name === report.original_post_name;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ import {
|
||||||
LemmyHttp,
|
LemmyHttp,
|
||||||
ListCommunityPendingFollows,
|
ListCommunityPendingFollows,
|
||||||
ListCommunityPendingFollowsResponse,
|
ListCommunityPendingFollowsResponse,
|
||||||
|
ListReports,
|
||||||
|
ListReportsResponse,
|
||||||
MyUserInfo,
|
MyUserInfo,
|
||||||
PersonId,
|
PersonId,
|
||||||
PostView,
|
PostView,
|
||||||
|
@ -74,12 +76,8 @@ import { PrivateMessagesResponse } from "lemmy-js-client/dist/types/PrivateMessa
|
||||||
import { GetPrivateMessages } from "lemmy-js-client/dist/types/GetPrivateMessages";
|
import { GetPrivateMessages } from "lemmy-js-client/dist/types/GetPrivateMessages";
|
||||||
import { PostReportResponse } from "lemmy-js-client/dist/types/PostReportResponse";
|
import { PostReportResponse } from "lemmy-js-client/dist/types/PostReportResponse";
|
||||||
import { CreatePostReport } from "lemmy-js-client/dist/types/CreatePostReport";
|
import { CreatePostReport } from "lemmy-js-client/dist/types/CreatePostReport";
|
||||||
import { ListPostReportsResponse } from "lemmy-js-client/dist/types/ListPostReportsResponse";
|
|
||||||
import { ListPostReports } from "lemmy-js-client/dist/types/ListPostReports";
|
|
||||||
import { CommentReportResponse } from "lemmy-js-client/dist/types/CommentReportResponse";
|
import { CommentReportResponse } from "lemmy-js-client/dist/types/CommentReportResponse";
|
||||||
import { CreateCommentReport } from "lemmy-js-client/dist/types/CreateCommentReport";
|
import { CreateCommentReport } from "lemmy-js-client/dist/types/CreateCommentReport";
|
||||||
import { ListCommentReportsResponse } from "lemmy-js-client/dist/types/ListCommentReportsResponse";
|
|
||||||
import { ListCommentReports } from "lemmy-js-client/dist/types/ListCommentReports";
|
|
||||||
import { GetPostsResponse } from "lemmy-js-client/dist/types/GetPostsResponse";
|
import { GetPostsResponse } from "lemmy-js-client/dist/types/GetPostsResponse";
|
||||||
import { GetPosts } from "lemmy-js-client/dist/types/GetPosts";
|
import { GetPosts } from "lemmy-js-client/dist/types/GetPosts";
|
||||||
import { GetPersonDetailsResponse } from "lemmy-js-client/dist/types/GetPersonDetailsResponse";
|
import { GetPersonDetailsResponse } from "lemmy-js-client/dist/types/GetPersonDetailsResponse";
|
||||||
|
@ -209,8 +207,8 @@ async function allowInstance(api: LemmyHttp, instance: string) {
|
||||||
// Ignore errors from duplicate allows (because setup gets called for each test file)
|
// Ignore errors from duplicate allows (because setup gets called for each test file)
|
||||||
try {
|
try {
|
||||||
await api.adminAllowInstance(params);
|
await api.adminAllowInstance(params);
|
||||||
} catch {
|
} catch (error) {
|
||||||
//console.log("Failed to allow instance");
|
// console.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -716,7 +714,6 @@ export async function saveUserSettingsBio(
|
||||||
export async function saveUserSettingsFederated(
|
export async function saveUserSettingsFederated(
|
||||||
api: LemmyHttp,
|
api: LemmyHttp,
|
||||||
): Promise<SuccessResponse> {
|
): Promise<SuccessResponse> {
|
||||||
let banner = sampleImage;
|
|
||||||
let bio = "a changed bio";
|
let bio = "a changed bio";
|
||||||
let form: SaveUserSettings = {
|
let form: SaveUserSettings = {
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
|
@ -724,7 +721,6 @@ export async function saveUserSettingsFederated(
|
||||||
default_post_sort_type: "Hot",
|
default_post_sort_type: "Hot",
|
||||||
default_listing_type: "All",
|
default_listing_type: "All",
|
||||||
interface_language: "",
|
interface_language: "",
|
||||||
banner,
|
|
||||||
display_name: "user321",
|
display_name: "user321",
|
||||||
show_avatars: false,
|
show_avatars: false,
|
||||||
send_notifications_to_email: false,
|
send_notifications_to_email: false,
|
||||||
|
@ -808,11 +804,11 @@ export async function reportPost(
|
||||||
return api.createPostReport(form);
|
return api.createPostReport(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listPostReports(
|
export async function listReports(
|
||||||
api: LemmyHttp,
|
api: LemmyHttp,
|
||||||
): Promise<ListPostReportsResponse> {
|
): Promise<ListReportsResponse> {
|
||||||
let form: ListPostReports = {};
|
let form: ListReports = {};
|
||||||
return api.listPostReports(form);
|
return api.listReports(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function reportComment(
|
export async function reportComment(
|
||||||
|
@ -839,13 +835,6 @@ export async function reportPrivateMessage(
|
||||||
return api.createPrivateMessageReport(form);
|
return api.createPrivateMessageReport(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listCommentReports(
|
|
||||||
api: LemmyHttp,
|
|
||||||
): Promise<ListCommentReportsResponse> {
|
|
||||||
let form: ListCommentReports = {};
|
|
||||||
return api.listCommentReports(form);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getPosts(
|
export function getPosts(
|
||||||
api: LemmyHttp,
|
api: LemmyHttp,
|
||||||
listingType?: ListingType,
|
listingType?: ListingType,
|
||||||
|
|
|
@ -73,6 +73,9 @@ test("Set some user settings, check that they are federated", async () => {
|
||||||
|
|
||||||
test("Delete user", async () => {
|
test("Delete user", async () => {
|
||||||
let user = await registerUser(alpha, alphaUrl);
|
let user = await registerUser(alpha, alphaUrl);
|
||||||
|
let user_profile = await getMyUser(user);
|
||||||
|
let person_id = user_profile.local_user_view.person.id;
|
||||||
|
let actor_id = user_profile.local_user_view.person.actor_id;
|
||||||
|
|
||||||
// make a local post and comment
|
// make a local post and comment
|
||||||
let alphaCommunity = (await resolveCommunity(user, "main@lemmy-alpha:8541"))
|
let alphaCommunity = (await resolveCommunity(user, "main@lemmy-alpha:8541"))
|
||||||
|
@ -100,6 +103,10 @@ test("Delete user", async () => {
|
||||||
expect(remoteComment).toBeDefined();
|
expect(remoteComment).toBeDefined();
|
||||||
|
|
||||||
await deleteUser(user);
|
await deleteUser(user);
|
||||||
|
await expect(getMyUser(user)).rejects.toStrictEqual(Error("incorrect_login"));
|
||||||
|
await expect(getPersonDetails(user, person_id)).rejects.toStrictEqual(
|
||||||
|
Error("not_found"),
|
||||||
|
);
|
||||||
|
|
||||||
// check that posts and comments are marked as deleted on other instances.
|
// check that posts and comments are marked as deleted on other instances.
|
||||||
// use get methods to avoid refetching from origin instance
|
// use get methods to avoid refetching from origin instance
|
||||||
|
@ -117,6 +124,9 @@ test("Delete user", async () => {
|
||||||
(await getComments(alpha, remoteComment.post_id)).comments[0].comment
|
(await getComments(alpha, remoteComment.post_id)).comments[0].comment
|
||||||
.deleted,
|
.deleted,
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
|
await expect(
|
||||||
|
getPersonDetails(user, remoteComment.creator_id),
|
||||||
|
).rejects.toStrictEqual(Error("not_found"));
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Requests with invalid auth should be treated as unauthenticated", async () => {
|
test("Requests with invalid auth should be treated as unauthenticated", async () => {
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
use actix_web::web::{Data, Json, Query};
|
|
||||||
use lemmy_api_common::{
|
|
||||||
comment::{ListCommentReports, ListCommentReportsResponse},
|
|
||||||
context::LemmyContext,
|
|
||||||
utils::check_community_mod_of_any_or_admin_action,
|
|
||||||
};
|
|
||||||
use lemmy_db_views::{comment_report_view::CommentReportQuery, structs::LocalUserView};
|
|
||||||
use lemmy_utils::error::LemmyResult;
|
|
||||||
|
|
||||||
/// Lists comment reports for a community if an id is supplied
|
|
||||||
/// or returns all comment reports for communities a user moderates
|
|
||||||
#[tracing::instrument(skip(context))]
|
|
||||||
pub async fn list_comment_reports(
|
|
||||||
data: Query<ListCommentReports>,
|
|
||||||
context: Data<LemmyContext>,
|
|
||||||
local_user_view: LocalUserView,
|
|
||||||
) -> LemmyResult<Json<ListCommentReportsResponse>> {
|
|
||||||
let community_id = data.community_id;
|
|
||||||
let comment_id = data.comment_id;
|
|
||||||
let unresolved_only = data.unresolved_only.unwrap_or_default();
|
|
||||||
|
|
||||||
check_community_mod_of_any_or_admin_action(&local_user_view, &mut context.pool()).await?;
|
|
||||||
|
|
||||||
let page = data.page;
|
|
||||||
let limit = data.limit;
|
|
||||||
let comment_reports = CommentReportQuery {
|
|
||||||
community_id,
|
|
||||||
comment_id,
|
|
||||||
unresolved_only,
|
|
||||||
page,
|
|
||||||
limit,
|
|
||||||
}
|
|
||||||
.list(&mut context.pool(), &local_user_view)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(Json(ListCommentReportsResponse { comment_reports }))
|
|
||||||
}
|
|
|
@ -110,7 +110,7 @@ pub async fn ban_from_community(
|
||||||
|
|
||||||
ModBanFromCommunity::create(&mut context.pool(), &form).await?;
|
ModBanFromCommunity::create(&mut context.pool(), &form).await?;
|
||||||
|
|
||||||
let person_view = PersonView::read(&mut context.pool(), data.person_id).await?;
|
let person_view = PersonView::read(&mut context.pool(), data.person_id, false).await?;
|
||||||
|
|
||||||
ActivityChannel::submit_activity(
|
ActivityChannel::submit_activity(
|
||||||
SendActivityData::BanFromCommunity {
|
SendActivityData::BanFromCommunity {
|
||||||
|
|
|
@ -33,13 +33,11 @@ use std::io::Cursor;
|
||||||
use totp_rs::{Secret, TOTP};
|
use totp_rs::{Secret, TOTP};
|
||||||
|
|
||||||
pub mod comment;
|
pub mod comment;
|
||||||
pub mod comment_report;
|
|
||||||
pub mod community;
|
pub mod community;
|
||||||
pub mod local_user;
|
pub mod local_user;
|
||||||
pub mod post;
|
pub mod post;
|
||||||
pub mod post_report;
|
|
||||||
pub mod private_message;
|
pub mod private_message;
|
||||||
pub mod private_message_report;
|
pub mod reports;
|
||||||
pub mod site;
|
pub mod site;
|
||||||
pub mod sitemap;
|
pub mod sitemap;
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ pub async fn ban_from_site(
|
||||||
|
|
||||||
ModBan::create(&mut context.pool(), &form).await?;
|
ModBan::create(&mut context.pool(), &form).await?;
|
||||||
|
|
||||||
let person_view = PersonView::read(&mut context.pool(), person.id).await?;
|
let person_view = PersonView::read(&mut context.pool(), person.id, false).await?;
|
||||||
|
|
||||||
ban_nonlocal_user_from_local_communities(
|
ban_nonlocal_user_from_local_communities(
|
||||||
&local_user_view,
|
&local_user_view,
|
||||||
|
|
|
@ -48,7 +48,7 @@ pub async fn user_block_person(
|
||||||
.with_lemmy_type(LemmyErrorType::PersonBlockAlreadyExists)?;
|
.with_lemmy_type(LemmyErrorType::PersonBlockAlreadyExists)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let person_view = PersonView::read(&mut context.pool(), target_id).await?;
|
let person_view = PersonView::read(&mut context.pool(), target_id, false).await?;
|
||||||
Ok(Json(BlockPersonResponse {
|
Ok(Json(BlockPersonResponse {
|
||||||
person_view,
|
person_view,
|
||||||
blocked: data.block,
|
blocked: data.block,
|
||||||
|
|
|
@ -4,12 +4,7 @@ use lemmy_api_common::{
|
||||||
person::{GetReportCount, GetReportCountResponse},
|
person::{GetReportCount, GetReportCountResponse},
|
||||||
utils::check_community_mod_of_any_or_admin_action,
|
utils::check_community_mod_of_any_or_admin_action,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{
|
use lemmy_db_views::structs::{LocalUserView, ReportCombinedViewInternal};
|
||||||
CommentReportView,
|
|
||||||
LocalUserView,
|
|
||||||
PostReportView,
|
|
||||||
PrivateMessageReportView,
|
|
||||||
};
|
|
||||||
use lemmy_utils::error::LemmyResult;
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
|
@ -18,29 +13,14 @@ pub async fn report_count(
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> LemmyResult<Json<GetReportCountResponse>> {
|
) -> LemmyResult<Json<GetReportCountResponse>> {
|
||||||
let person_id = local_user_view.person.id;
|
|
||||||
let admin = local_user_view.local_user.admin;
|
|
||||||
let community_id = data.community_id;
|
|
||||||
|
|
||||||
check_community_mod_of_any_or_admin_action(&local_user_view, &mut context.pool()).await?;
|
check_community_mod_of_any_or_admin_action(&local_user_view, &mut context.pool()).await?;
|
||||||
|
|
||||||
let comment_reports =
|
let count = ReportCombinedViewInternal::get_report_count(
|
||||||
CommentReportView::get_report_count(&mut context.pool(), person_id, admin, community_id)
|
&mut context.pool(),
|
||||||
.await?;
|
&local_user_view,
|
||||||
|
data.community_id,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let post_reports =
|
Ok(Json(GetReportCountResponse { count }))
|
||||||
PostReportView::get_report_count(&mut context.pool(), person_id, admin, community_id).await?;
|
|
||||||
|
|
||||||
let private_message_reports = if admin && community_id.is_none() {
|
|
||||||
Some(PrivateMessageReportView::get_report_count(&mut context.pool()).await?)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Json(GetReportCountResponse {
|
|
||||||
community_id,
|
|
||||||
comment_reports,
|
|
||||||
post_reports,
|
|
||||||
private_message_reports,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,23 +6,31 @@ use lemmy_api_common::{
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{LocalUserView, SiteView};
|
use lemmy_db_views::structs::{LocalUserView, SiteView};
|
||||||
use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn reset_password(
|
pub async fn reset_password(
|
||||||
data: Json<PasswordReset>,
|
data: Json<PasswordReset>,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> LemmyResult<Json<SuccessResponse>> {
|
) -> LemmyResult<Json<SuccessResponse>> {
|
||||||
// Fetch that email
|
|
||||||
let email = data.email.to_lowercase();
|
let email = data.email.to_lowercase();
|
||||||
let local_user_view = LocalUserView::find_by_email(&mut context.pool(), &email)
|
// For security, errors are not returned.
|
||||||
.await
|
// https://github.com/LemmyNet/lemmy/issues/5277
|
||||||
.with_lemmy_type(LemmyErrorType::IncorrectLogin)?;
|
let _ = try_reset_password(&email, &context).await;
|
||||||
|
|
||||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
|
||||||
check_email_verified(&local_user_view, &site_view)?;
|
|
||||||
|
|
||||||
// Email the pure token to the user.
|
|
||||||
send_password_reset_email(&local_user_view, &mut context.pool(), context.settings()).await?;
|
|
||||||
Ok(Json(SuccessResponse::default()))
|
Ok(Json(SuccessResponse::default()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn try_reset_password(email: &str, context: &LemmyContext) -> LemmyResult<()> {
|
||||||
|
let local_user_view = LocalUserView::find_by_email(&mut context.pool(), email).await?;
|
||||||
|
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||||
|
|
||||||
|
check_email_verified(&local_user_view, &site_view)?;
|
||||||
|
if let Err(e) =
|
||||||
|
send_password_reset_email(&local_user_view, &mut context.pool(), context.settings()).await
|
||||||
|
{
|
||||||
|
error!("Failed to send password reset email: {}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,11 @@ pub async fn verify_email(
|
||||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||||
let token = data.token.clone();
|
let token = data.token.clone();
|
||||||
let verification = EmailVerification::read_for_token(&mut context.pool(), &token).await?;
|
let verification = EmailVerification::read_for_token(&mut context.pool(), &token).await?;
|
||||||
|
let local_user_id = verification.local_user_id;
|
||||||
|
let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id).await?;
|
||||||
|
|
||||||
|
// Check if their email has already been verified once, before this
|
||||||
|
let email_already_verified = local_user_view.local_user.email_verified;
|
||||||
|
|
||||||
let form = LocalUserUpdateForm {
|
let form = LocalUserUpdateForm {
|
||||||
// necessary in case this is a new signup
|
// necessary in case this is a new signup
|
||||||
|
@ -27,18 +32,16 @@ pub async fn verify_email(
|
||||||
email: Some(Some(verification.email)),
|
email: Some(Some(verification.email)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let local_user_id = verification.local_user_id;
|
|
||||||
|
|
||||||
LocalUser::update(&mut context.pool(), local_user_id, &form).await?;
|
LocalUser::update(&mut context.pool(), local_user_id, &form).await?;
|
||||||
|
|
||||||
EmailVerification::delete_old_tokens_for_local_user(&mut context.pool(), local_user_id).await?;
|
EmailVerification::delete_old_tokens_for_local_user(&mut context.pool(), local_user_id).await?;
|
||||||
|
|
||||||
// send out notification about registration application to admins if enabled
|
// Send out notification about registration application to admins if enabled, and the user hasn't
|
||||||
if site_view.local_site.application_email_admins {
|
// already been verified.
|
||||||
let local_user = LocalUserView::read(&mut context.pool(), local_user_id).await?;
|
if site_view.local_site.application_email_admins && !email_already_verified {
|
||||||
|
|
||||||
send_new_applicant_email_to_admins(
|
send_new_applicant_email_to_admins(
|
||||||
&local_user.person.name,
|
&local_user_view.person.name,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
context.settings(),
|
context.settings(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
use actix_web::web::{Data, Json, Query};
|
|
||||||
use lemmy_api_common::{
|
|
||||||
context::LemmyContext,
|
|
||||||
post::{ListPostReports, ListPostReportsResponse},
|
|
||||||
utils::check_community_mod_of_any_or_admin_action,
|
|
||||||
};
|
|
||||||
use lemmy_db_views::{post_report_view::PostReportQuery, structs::LocalUserView};
|
|
||||||
use lemmy_utils::error::LemmyResult;
|
|
||||||
|
|
||||||
/// Lists post reports for a community if an id is supplied
|
|
||||||
/// or returns all post reports for communities a user moderates
|
|
||||||
#[tracing::instrument(skip(context))]
|
|
||||||
pub async fn list_post_reports(
|
|
||||||
data: Query<ListPostReports>,
|
|
||||||
context: Data<LemmyContext>,
|
|
||||||
local_user_view: LocalUserView,
|
|
||||||
) -> LemmyResult<Json<ListPostReportsResponse>> {
|
|
||||||
let community_id = data.community_id;
|
|
||||||
let post_id = data.post_id;
|
|
||||||
let unresolved_only = data.unresolved_only.unwrap_or_default();
|
|
||||||
|
|
||||||
check_community_mod_of_any_or_admin_action(&local_user_view, &mut context.pool()).await?;
|
|
||||||
|
|
||||||
let page = data.page;
|
|
||||||
let limit = data.limit;
|
|
||||||
let post_reports = PostReportQuery {
|
|
||||||
community_id,
|
|
||||||
post_id,
|
|
||||||
unresolved_only,
|
|
||||||
page,
|
|
||||||
limit,
|
|
||||||
}
|
|
||||||
.list(&mut context.pool(), &local_user_view)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(Json(ListPostReportsResponse { post_reports }))
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
use actix_web::web::{Data, Json, Query};
|
|
||||||
use lemmy_api_common::{
|
|
||||||
context::LemmyContext,
|
|
||||||
private_message::{ListPrivateMessageReports, ListPrivateMessageReportsResponse},
|
|
||||||
utils::is_admin,
|
|
||||||
};
|
|
||||||
use lemmy_db_views::{
|
|
||||||
private_message_report_view::PrivateMessageReportQuery,
|
|
||||||
structs::LocalUserView,
|
|
||||||
};
|
|
||||||
use lemmy_utils::error::LemmyResult;
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
|
||||||
pub async fn list_pm_reports(
|
|
||||||
data: Query<ListPrivateMessageReports>,
|
|
||||||
context: Data<LemmyContext>,
|
|
||||||
local_user_view: LocalUserView,
|
|
||||||
) -> LemmyResult<Json<ListPrivateMessageReportsResponse>> {
|
|
||||||
is_admin(&local_user_view)?;
|
|
||||||
|
|
||||||
let unresolved_only = data.unresolved_only.unwrap_or_default();
|
|
||||||
let page = data.page;
|
|
||||||
let limit = data.limit;
|
|
||||||
let private_message_reports = PrivateMessageReportQuery {
|
|
||||||
unresolved_only,
|
|
||||||
page,
|
|
||||||
limit,
|
|
||||||
}
|
|
||||||
.list(&mut context.pool())
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(Json(ListPrivateMessageReportsResponse {
|
|
||||||
private_message_reports,
|
|
||||||
}))
|
|
||||||
}
|
|
|
@ -2,8 +2,8 @@ use crate::check_report_reason;
|
||||||
use activitypub_federation::config::Data;
|
use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Json;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentReportResponse, CreateCommentReport},
|
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
reports::comment::{CommentReportResponse, CreateCommentReport},
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{
|
utils::{
|
||||||
check_comment_deleted_or_removed,
|
check_comment_deleted_or_removed,
|
|
@ -1,3 +1,2 @@
|
||||||
pub mod create;
|
pub mod create;
|
||||||
pub mod list;
|
|
||||||
pub mod resolve;
|
pub mod resolve;
|
|
@ -1,7 +1,7 @@
|
||||||
use actix_web::web::{Data, Json};
|
use actix_web::web::{Data, Json};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentReportResponse, ResolveCommentReport},
|
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
reports::comment::{CommentReportResponse, ResolveCommentReport},
|
||||||
utils::check_community_mod_action,
|
utils::check_community_mod_action,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
|
use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
|
4
crates/api/src/reports/mod.rs
Normal file
4
crates/api/src/reports/mod.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
pub mod comment_report;
|
||||||
|
pub mod post_report;
|
||||||
|
pub mod private_message_report;
|
||||||
|
pub mod report_combined;
|
|
@ -3,7 +3,7 @@ use activitypub_federation::config::Data;
|
||||||
use actix_web::web::Json;
|
use actix_web::web::Json;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{CreatePostReport, PostReportResponse},
|
reports::post::{CreatePostReport, PostReportResponse},
|
||||||
send_activity::{ActivityChannel, SendActivityData},
|
send_activity::{ActivityChannel, SendActivityData},
|
||||||
utils::{
|
utils::{
|
||||||
check_community_user_action,
|
check_community_user_action,
|
|
@ -1,3 +1,2 @@
|
||||||
pub mod create;
|
pub mod create;
|
||||||
pub mod list;
|
|
||||||
pub mod resolve;
|
pub mod resolve;
|
|
@ -1,7 +1,7 @@
|
||||||
use actix_web::web::{Data, Json};
|
use actix_web::web::{Data, Json};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{PostReportResponse, ResolvePostReport},
|
reports::post::{PostReportResponse, ResolvePostReport},
|
||||||
utils::check_community_mod_action,
|
utils::check_community_mod_action,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable};
|
use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable};
|
|
@ -2,7 +2,7 @@ use crate::check_report_reason;
|
||||||
use actix_web::web::{Data, Json};
|
use actix_web::web::{Data, Json};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
private_message::{CreatePrivateMessageReport, PrivateMessageReportResponse},
|
reports::private_message::{CreatePrivateMessageReport, PrivateMessageReportResponse},
|
||||||
utils::send_new_report_email_to_admins,
|
utils::send_new_report_email_to_admins,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
|
@ -1,3 +1,2 @@
|
||||||
pub mod create;
|
pub mod create;
|
||||||
pub mod list;
|
|
||||||
pub mod resolve;
|
pub mod resolve;
|
|
@ -1,7 +1,7 @@
|
||||||
use actix_web::web::{Data, Json};
|
use actix_web::web::{Data, Json};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
|
reports::private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
|
||||||
utils::is_admin,
|
utils::is_admin,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::private_message_report::PrivateMessageReport, traits::Reportable};
|
use lemmy_db_schema::{source::private_message_report::PrivateMessageReport, traits::Reportable};
|
41
crates/api/src/reports/report_combined/list.rs
Normal file
41
crates/api/src/reports/report_combined/list.rs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
use actix_web::web::{Data, Json, Query};
|
||||||
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
|
reports::combined::{ListReports, ListReportsResponse},
|
||||||
|
utils::check_community_mod_of_any_or_admin_action,
|
||||||
|
};
|
||||||
|
use lemmy_db_views::{report_combined_view::ReportCombinedQuery, structs::LocalUserView};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
|
/// Lists reports for a community if an id is supplied
|
||||||
|
/// or returns all reports for communities a user moderates
|
||||||
|
#[tracing::instrument(skip(context))]
|
||||||
|
pub async fn list_reports(
|
||||||
|
data: Query<ListReports>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
|
local_user_view: LocalUserView,
|
||||||
|
) -> LemmyResult<Json<ListReportsResponse>> {
|
||||||
|
let community_id = data.community_id;
|
||||||
|
let unresolved_only = data.unresolved_only;
|
||||||
|
|
||||||
|
check_community_mod_of_any_or_admin_action(&local_user_view, &mut context.pool()).await?;
|
||||||
|
|
||||||
|
// parse pagination token
|
||||||
|
let page_after = if let Some(pa) = &data.page_cursor {
|
||||||
|
Some(pa.read(&mut context.pool()).await?)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let page_back = data.page_back;
|
||||||
|
|
||||||
|
let reports = ReportCombinedQuery {
|
||||||
|
community_id,
|
||||||
|
unresolved_only,
|
||||||
|
page_after,
|
||||||
|
page_back,
|
||||||
|
}
|
||||||
|
.list(&mut context.pool(), &local_user_view)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Json(ListReportsResponse { reports }))
|
||||||
|
}
|
1
crates/api/src/reports/report_combined/mod.rs
Normal file
1
crates/api/src/reports/report_combined/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod list;
|
|
@ -67,9 +67,9 @@ urlencoding = { workspace = true }
|
||||||
mime = { version = "0.3.17", optional = true }
|
mime = { version = "0.3.17", optional = true }
|
||||||
mime_guess = "2.0.5"
|
mime_guess = "2.0.5"
|
||||||
infer = "0.16.0"
|
infer = "0.16.0"
|
||||||
webpage = { version = "2.0", default-features = false, features = [
|
webpage = { version = "2.0", default-features = false, optional = true, features = [
|
||||||
"serde",
|
"serde",
|
||||||
], optional = true }
|
] }
|
||||||
encoding_rs = { version = "0.8.35", optional = true }
|
encoding_rs = { version = "0.8.35", optional = true }
|
||||||
jsonwebtoken = { version = "9.3.0", optional = true }
|
jsonwebtoken = { version = "9.3.0", optional = true }
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommentId, CommentReportId, CommunityId, LanguageId, LocalUserId, PostId},
|
newtypes::{CommentId, CommunityId, LanguageId, LocalUserId, PostId},
|
||||||
CommentSortType,
|
CommentSortType,
|
||||||
ListingType,
|
ListingType,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{CommentReportView, CommentView, VoteView};
|
use lemmy_db_views::structs::{CommentView, VoteView};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
@ -146,60 +146,6 @@ pub struct GetCommentsResponse {
|
||||||
pub comments: Vec<CommentView>,
|
pub comments: Vec<CommentView>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// Report a comment.
|
|
||||||
pub struct CreateCommentReport {
|
|
||||||
pub comment_id: CommentId,
|
|
||||||
pub reason: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// The comment report response.
|
|
||||||
pub struct CommentReportResponse {
|
|
||||||
pub comment_report_view: CommentReportView,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// Resolve a comment report (only doable by mods).
|
|
||||||
pub struct ResolveCommentReport {
|
|
||||||
pub report_id: CommentReportId,
|
|
||||||
pub resolved: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[skip_serializing_none]
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// List comment reports.
|
|
||||||
pub struct ListCommentReports {
|
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub comment_id: Option<CommentId>,
|
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub page: Option<i64>,
|
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub limit: Option<i64>,
|
|
||||||
/// Only shows the unresolved reports
|
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub unresolved_only: Option<bool>,
|
|
||||||
/// if no community is given, it returns reports for all communities moderated by the auth user
|
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub community_id: Option<CommunityId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// The comment report list response.
|
|
||||||
pub struct ListCommentReportsResponse {
|
|
||||||
pub comment_reports: Vec<CommentReportView>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[skip_serializing_none]
|
#[skip_serializing_none]
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
|
|
@ -12,6 +12,7 @@ pub mod oauth_provider;
|
||||||
pub mod person;
|
pub mod person;
|
||||||
pub mod post;
|
pub mod post;
|
||||||
pub mod private_message;
|
pub mod private_message;
|
||||||
|
pub mod reports;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod request;
|
pub mod request;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
|
|
@ -442,12 +442,7 @@ pub struct GetReportCount {
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
/// A response for the number of reports.
|
/// A response for the number of reports.
|
||||||
pub struct GetReportCountResponse {
|
pub struct GetReportCountResponse {
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
pub count: i64,
|
||||||
pub community_id: Option<CommunityId>,
|
|
||||||
pub comment_reports: i64,
|
|
||||||
pub post_reports: i64,
|
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub private_message_reports: Option<i64>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommentId, CommunityId, DbUrl, LanguageId, PostId, PostReportId},
|
newtypes::{CommentId, CommunityId, DbUrl, LanguageId, PostId, TagId},
|
||||||
ListingType,
|
ListingType,
|
||||||
PostFeatureType,
|
PostFeatureType,
|
||||||
PostSortType,
|
PostSortType,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{PaginationCursor, PostReportView, PostView, VoteView};
|
use lemmy_db_views::structs::{PaginationCursor, PostView, VoteView};
|
||||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
|
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
|
@ -37,6 +37,8 @@ pub struct CreatePost {
|
||||||
/// Instead of fetching a thumbnail, use a custom one.
|
/// Instead of fetching a thumbnail, use a custom one.
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub custom_thumbnail: Option<String>,
|
pub custom_thumbnail: Option<String>,
|
||||||
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
|
pub tags: Option<Vec<TagId>>,
|
||||||
/// Time when this post should be scheduled. Null means publish immediately.
|
/// Time when this post should be scheduled. Null means publish immediately.
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub scheduled_publish_time: Option<i64>,
|
pub scheduled_publish_time: Option<i64>,
|
||||||
|
@ -97,6 +99,8 @@ pub struct GetPosts {
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub saved_only: Option<bool>,
|
pub saved_only: Option<bool>,
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
|
pub read_only: Option<bool>,
|
||||||
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub liked_only: Option<bool>,
|
pub liked_only: Option<bool>,
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub disliked_only: Option<bool>,
|
pub disliked_only: Option<bool>,
|
||||||
|
@ -116,6 +120,8 @@ pub struct GetPosts {
|
||||||
pub no_comments_only: Option<bool>,
|
pub no_comments_only: Option<bool>,
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub page_cursor: Option<PaginationCursor>,
|
pub page_cursor: Option<PaginationCursor>,
|
||||||
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
|
pub page_back: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[skip_serializing_none]
|
#[skip_serializing_none]
|
||||||
|
@ -164,6 +170,8 @@ pub struct EditPost {
|
||||||
/// Instead of fetching a thumbnail, use a custom one.
|
/// Instead of fetching a thumbnail, use a custom one.
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub custom_thumbnail: Option<String>,
|
pub custom_thumbnail: Option<String>,
|
||||||
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
|
pub tags: Option<Vec<TagId>>,
|
||||||
/// Time when this post should be scheduled. Null means publish immediately.
|
/// Time when this post should be scheduled. Null means publish immediately.
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub scheduled_publish_time: Option<i64>,
|
pub scheduled_publish_time: Option<i64>,
|
||||||
|
@ -247,61 +255,6 @@ pub struct SavePost {
|
||||||
pub save: bool,
|
pub save: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// Create a post report.
|
|
||||||
pub struct CreatePostReport {
|
|
||||||
pub post_id: PostId,
|
|
||||||
pub reason: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// The post report response.
|
|
||||||
pub struct PostReportResponse {
|
|
||||||
pub post_report_view: PostReportView,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// Resolve a post report (mods only).
|
|
||||||
pub struct ResolvePostReport {
|
|
||||||
pub report_id: PostReportId,
|
|
||||||
pub resolved: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[skip_serializing_none]
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// List post reports.
|
|
||||||
pub struct ListPostReports {
|
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub page: Option<i64>,
|
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub limit: Option<i64>,
|
|
||||||
/// Only shows the unresolved reports
|
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub unresolved_only: Option<bool>,
|
|
||||||
// TODO make into tagged enum at some point
|
|
||||||
/// if no community is given, it returns reports for all communities moderated by the auth user
|
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub community_id: Option<CommunityId>,
|
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub post_id: Option<PostId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// The post reports response.
|
|
||||||
pub struct ListPostReportsResponse {
|
|
||||||
pub post_reports: Vec<PostReportView>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use lemmy_db_schema::newtypes::{PersonId, PrivateMessageId, PrivateMessageReportId};
|
use lemmy_db_schema::newtypes::{PersonId, PrivateMessageId};
|
||||||
use lemmy_db_views::structs::{PrivateMessageReportView, PrivateMessageView};
|
use lemmy_db_views::structs::PrivateMessageView;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
@ -72,53 +72,3 @@ pub struct PrivateMessagesResponse {
|
||||||
pub struct PrivateMessageResponse {
|
pub struct PrivateMessageResponse {
|
||||||
pub private_message_view: PrivateMessageView,
|
pub private_message_view: PrivateMessageView,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// Create a report for a private message.
|
|
||||||
pub struct CreatePrivateMessageReport {
|
|
||||||
pub private_message_id: PrivateMessageId,
|
|
||||||
pub reason: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// A private message report response.
|
|
||||||
pub struct PrivateMessageReportResponse {
|
|
||||||
pub private_message_report_view: PrivateMessageReportView,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// Resolve a private message report.
|
|
||||||
pub struct ResolvePrivateMessageReport {
|
|
||||||
pub report_id: PrivateMessageReportId,
|
|
||||||
pub resolved: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[skip_serializing_none]
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// List private message reports.
|
|
||||||
// TODO , perhaps GetReports should be a tagged enum list too.
|
|
||||||
pub struct ListPrivateMessageReports {
|
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub page: Option<i64>,
|
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub limit: Option<i64>,
|
|
||||||
/// Only shows the unresolved reports
|
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
|
||||||
pub unresolved_only: Option<bool>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
||||||
#[cfg_attr(feature = "full", derive(TS))]
|
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
|
||||||
/// The response for list private message reports.
|
|
||||||
pub struct ListPrivateMessageReportsResponse {
|
|
||||||
pub private_message_reports: Vec<PrivateMessageReportView>,
|
|
||||||
}
|
|
||||||
|
|
32
crates/api_common/src/reports/combined.rs
Normal file
32
crates/api_common/src/reports/combined.rs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
use lemmy_db_schema::newtypes::CommunityId;
|
||||||
|
use lemmy_db_views::structs::{ReportCombinedPaginationCursor, ReportCombinedView};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_with::skip_serializing_none;
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
use ts_rs::TS;
|
||||||
|
|
||||||
|
#[skip_serializing_none]
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// List reports.
|
||||||
|
pub struct ListReports {
|
||||||
|
/// Only shows the unresolved reports
|
||||||
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
|
pub unresolved_only: Option<bool>,
|
||||||
|
/// if no community is given, it returns reports for all communities moderated by the auth user
|
||||||
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
|
pub community_id: Option<CommunityId>,
|
||||||
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
|
pub page_cursor: Option<ReportCombinedPaginationCursor>,
|
||||||
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
|
pub page_back: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// The post reports response.
|
||||||
|
pub struct ListReportsResponse {
|
||||||
|
pub reports: Vec<ReportCombinedView>,
|
||||||
|
}
|
31
crates/api_common/src/reports/comment.rs
Normal file
31
crates/api_common/src/reports/comment.rs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
use lemmy_db_schema::newtypes::{CommentId, CommentReportId};
|
||||||
|
use lemmy_db_views::structs::CommentReportView;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
use ts_rs::TS;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// Report a comment.
|
||||||
|
pub struct CreateCommentReport {
|
||||||
|
pub comment_id: CommentId,
|
||||||
|
pub reason: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// The comment report response.
|
||||||
|
pub struct CommentReportResponse {
|
||||||
|
pub comment_report_view: CommentReportView,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// Resolve a comment report (only doable by mods).
|
||||||
|
pub struct ResolveCommentReport {
|
||||||
|
pub report_id: CommentReportId,
|
||||||
|
pub resolved: bool,
|
||||||
|
}
|
4
crates/api_common/src/reports/mod.rs
Normal file
4
crates/api_common/src/reports/mod.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
pub mod combined;
|
||||||
|
pub mod comment;
|
||||||
|
pub mod post;
|
||||||
|
pub mod private_message;
|
31
crates/api_common/src/reports/post.rs
Normal file
31
crates/api_common/src/reports/post.rs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
use lemmy_db_schema::newtypes::{PostId, PostReportId};
|
||||||
|
use lemmy_db_views::structs::PostReportView;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
use ts_rs::TS;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// Create a post report.
|
||||||
|
pub struct CreatePostReport {
|
||||||
|
pub post_id: PostId,
|
||||||
|
pub reason: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// The post report response.
|
||||||
|
pub struct PostReportResponse {
|
||||||
|
pub post_report_view: PostReportView,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// Resolve a post report (mods only).
|
||||||
|
pub struct ResolvePostReport {
|
||||||
|
pub report_id: PostReportId,
|
||||||
|
pub resolved: bool,
|
||||||
|
}
|
31
crates/api_common/src/reports/private_message.rs
Normal file
31
crates/api_common/src/reports/private_message.rs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
use lemmy_db_schema::newtypes::{PrivateMessageId, PrivateMessageReportId};
|
||||||
|
use lemmy_db_views::structs::PrivateMessageReportView;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
use ts_rs::TS;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// Create a report for a private message.
|
||||||
|
pub struct CreatePrivateMessageReport {
|
||||||
|
pub private_message_id: PrivateMessageId,
|
||||||
|
pub reason: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// A private message report response.
|
||||||
|
pub struct PrivateMessageReportResponse {
|
||||||
|
pub private_message_report_view: PrivateMessageReportView,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// Resolve a private message report.
|
||||||
|
pub struct ResolvePrivateMessageReport {
|
||||||
|
pub report_id: PrivateMessageReportId,
|
||||||
|
pub resolved: bool,
|
||||||
|
}
|
|
@ -48,9 +48,11 @@ pub fn client_builder(settings: &Settings) -> ClientBuilder {
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn fetch_link_metadata(url: &Url, context: &LemmyContext) -> LemmyResult<LinkMetadata> {
|
pub async fn fetch_link_metadata(url: &Url, context: &LemmyContext) -> LemmyResult<LinkMetadata> {
|
||||||
info!("Fetching site metadata for url: {}", url);
|
info!("Fetching site metadata for url: {}", url);
|
||||||
// We only fetch the first 64kB of data in order to not waste bandwidth especially for large
|
// We only fetch the first MB of data in order to not waste bandwidth especially for large
|
||||||
// binary files
|
// binary files. This high limit is particularly needed for youtube, which includes a lot of
|
||||||
let bytes_to_fetch = 64 * 1024;
|
// javascript code before the opengraph tags. Mastodon also uses a 1 MB limit:
|
||||||
|
// https://github.com/mastodon/mastodon/blob/295ad6f19a016b3f16e1201ffcbb1b3ad6b455a2/app/lib/request.rb#L213
|
||||||
|
let bytes_to_fetch = 1024 * 1024;
|
||||||
let response = context
|
let response = context
|
||||||
.client()
|
.client()
|
||||||
.get(url.as_str())
|
.get(url.as_str())
|
||||||
|
|
|
@ -123,8 +123,6 @@ pub fn is_admin(local_user_view: &LocalUserView) -> LemmyResult<()> {
|
||||||
check_user_valid(&local_user_view.person)?;
|
check_user_valid(&local_user_view.person)?;
|
||||||
if !local_user_view.local_user.admin {
|
if !local_user_view.local_user.admin {
|
||||||
Err(LemmyErrorType::NotAnAdmin)?
|
Err(LemmyErrorType::NotAnAdmin)?
|
||||||
} else if local_user_view.person.banned {
|
|
||||||
Err(LemmyErrorType::Banned)?
|
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -554,7 +552,9 @@ pub async fn get_url_blocklist(context: &LemmyContext) -> LemmyResult<RegexSet>
|
||||||
let urls = LocalSiteUrlBlocklist::get_all(&mut context.pool()).await?;
|
let urls = LocalSiteUrlBlocklist::get_all(&mut context.pool()).await?;
|
||||||
|
|
||||||
// The urls are already validated on saving, so just escape them.
|
// The urls are already validated on saving, so just escape them.
|
||||||
let regexes = urls.iter().map(|url| escape(&url.url));
|
// If this regex creation changes it must be synced with
|
||||||
|
// lemmy_utils::utils::markdown::create_url_blocklist_test_regex_set.
|
||||||
|
let regexes = urls.iter().map(|url| format!(r"\b{}\b", escape(&url.url)));
|
||||||
|
|
||||||
let set = RegexSet::new(regexes)?;
|
let set = RegexSet::new(regexes)?;
|
||||||
Ok(set)
|
Ok(set)
|
||||||
|
|
|
@ -107,7 +107,7 @@ pub async fn create_post(
|
||||||
let scheduled_publish_time =
|
let scheduled_publish_time =
|
||||||
convert_published_time(data.scheduled_publish_time, &local_user_view, &context).await?;
|
convert_published_time(data.scheduled_publish_time, &local_user_view, &context).await?;
|
||||||
let post_form = PostInsertForm {
|
let post_form = PostInsertForm {
|
||||||
url: url.map(Into::into),
|
url,
|
||||||
body,
|
body,
|
||||||
alt_text: data.alt_text.clone(),
|
alt_text: data.alt_text.clone(),
|
||||||
nsfw: data.nsfw,
|
nsfw: data.nsfw,
|
||||||
|
|
|
@ -139,6 +139,8 @@ pub async fn update_site(
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
if let Some(url_blocklist) = data.blocked_urls.clone() {
|
if let Some(url_blocklist) = data.blocked_urls.clone() {
|
||||||
|
// If this validation changes it must be synced with
|
||||||
|
// lemmy_utils::utils::markdown::create_url_blocklist_test_regex_set.
|
||||||
let parsed_urls = check_urls_are_valid(&url_blocklist)?;
|
let parsed_urls = check_urls_are_valid(&url_blocklist)?;
|
||||||
LocalSiteUrlBlocklist::replace(&mut context.pool(), parsed_urls).await?;
|
LocalSiteUrlBlocklist::replace(&mut context.pool(), parsed_urls).await?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use actix_web::web::{Data, Json};
|
use actix_web::web::{Data, Json};
|
||||||
use lemmy_api_common::{context::LemmyContext, site::MyUserInfo};
|
use lemmy_api_common::{context::LemmyContext, site::MyUserInfo, utils::check_user_valid};
|
||||||
use lemmy_db_schema::source::{
|
use lemmy_db_schema::source::{
|
||||||
actor_language::LocalUserLanguage,
|
actor_language::LocalUserLanguage,
|
||||||
community_block::CommunityBlock,
|
community_block::CommunityBlock,
|
||||||
|
@ -15,6 +15,8 @@ pub async fn get_my_user(
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> LemmyResult<Json<MyUserInfo>> {
|
) -> LemmyResult<Json<MyUserInfo>> {
|
||||||
|
check_user_valid(&local_user_view.person)?;
|
||||||
|
|
||||||
// Build the local user with parallel queries and add it to site response
|
// Build the local user with parallel queries and add it to site response
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let local_user_id = local_user_view.local_user.id;
|
let local_user_id = local_user_view.local_user.id;
|
||||||
|
|
|
@ -152,7 +152,7 @@ impl ActivityHandler for BlockUser {
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
|
async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
|
||||||
insert_received_activity(&self.id, context).await?;
|
insert_received_activity(&self.id, context).await?;
|
||||||
let expires = self.end_time.map(Into::into);
|
let expires = self.end_time;
|
||||||
let mod_person = self.actor.dereference(context).await?;
|
let mod_person = self.actor.dereference(context).await?;
|
||||||
let blocked_person = self.object.dereference(context).await?;
|
let blocked_person = self.object.dereference(context).await?;
|
||||||
let target = self.target.dereference(context).await?;
|
let target = self.target.dereference(context).await?;
|
||||||
|
|
|
@ -100,7 +100,7 @@ impl ActivityHandler for UndoBlockUser {
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
|
async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
|
||||||
insert_received_activity(&self.id, context).await?;
|
insert_received_activity(&self.id, context).await?;
|
||||||
let expires = self.object.end_time.map(Into::into);
|
let expires = self.object.end_time;
|
||||||
let mod_person = self.actor.dereference(context).await?;
|
let mod_person = self.actor.dereference(context).await?;
|
||||||
let blocked_person = self.object.object.dereference(context).await?;
|
let blocked_person = self.object.object.dereference(context).await?;
|
||||||
match self.object.target.dereference(context).await? {
|
match self.object.target.dereference(context).await? {
|
||||||
|
|
|
@ -98,8 +98,8 @@ impl ActivityHandler for UpdateCommunity {
|
||||||
&None,
|
&None,
|
||||||
&self.object.source,
|
&self.object.source,
|
||||||
)),
|
)),
|
||||||
published: self.object.published.map(Into::into),
|
published: self.object.published,
|
||||||
updated: Some(self.object.updated.map(Into::into)),
|
updated: Some(self.object.updated),
|
||||||
nsfw: Some(self.object.sensitive.unwrap_or(false)),
|
nsfw: Some(self.object.sensitive.unwrap_or(false)),
|
||||||
actor_id: Some(self.object.id.into()),
|
actor_id: Some(self.object.id.into()),
|
||||||
public_key: Some(self.object.public_key.public_key_pem),
|
public_key: Some(self.object.public_key.public_key_pem),
|
||||||
|
|
|
@ -9,7 +9,7 @@ use actix_web::web::{Json, Query};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{GetComments, GetCommentsResponse},
|
comment::{GetComments, GetCommentsResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
utils::check_private_instance,
|
utils::{check_conflicting_like_filters, check_private_instance},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{comment::Comment, community::Community},
|
source::{comment::Comment, community::Community},
|
||||||
|
@ -19,7 +19,7 @@ use lemmy_db_views::{
|
||||||
comment_view::CommentQuery,
|
comment_view::CommentQuery,
|
||||||
structs::{LocalUserView, SiteView},
|
structs::{LocalUserView, SiteView},
|
||||||
};
|
};
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult};
|
use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn list_comments(
|
pub async fn list_comments(
|
||||||
|
@ -50,9 +50,7 @@ pub async fn list_comments(
|
||||||
|
|
||||||
let liked_only = data.liked_only;
|
let liked_only = data.liked_only;
|
||||||
let disliked_only = data.disliked_only;
|
let disliked_only = data.disliked_only;
|
||||||
if liked_only.unwrap_or_default() && disliked_only.unwrap_or_default() {
|
check_conflicting_like_filters(liked_only, disliked_only)?;
|
||||||
return Err(LemmyError::from(LemmyErrorType::ContradictingFilters));
|
|
||||||
}
|
|
||||||
|
|
||||||
let page = data.page;
|
let page = data.page;
|
||||||
let limit = data.limit;
|
let limit = data.limit;
|
||||||
|
|
|
@ -42,6 +42,7 @@ pub async fn list_posts(
|
||||||
data.community_id
|
data.community_id
|
||||||
};
|
};
|
||||||
let saved_only = data.saved_only;
|
let saved_only = data.saved_only;
|
||||||
|
let read_only = data.read_only;
|
||||||
let show_hidden = data.show_hidden;
|
let show_hidden = data.show_hidden;
|
||||||
let show_read = data.show_read;
|
let show_read = data.show_read;
|
||||||
let show_nsfw = data.show_nsfw;
|
let show_nsfw = data.show_nsfw;
|
||||||
|
@ -78,6 +79,7 @@ pub async fn list_posts(
|
||||||
sort,
|
sort,
|
||||||
community_id,
|
community_id,
|
||||||
saved_only,
|
saved_only,
|
||||||
|
read_only,
|
||||||
liked_only,
|
liked_only,
|
||||||
disliked_only,
|
disliked_only,
|
||||||
page,
|
page,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use actix_web::web::{Json, Query};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{GetPersonDetails, GetPersonDetailsResponse},
|
person::{GetPersonDetails, GetPersonDetailsResponse},
|
||||||
utils::{check_private_instance, read_site_for_actor},
|
utils::{check_private_instance, is_admin, read_site_for_actor},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::person::Person, utils::post_to_comment_sort_type};
|
use lemmy_db_schema::{source::person::Person, utils::post_to_comment_sort_type};
|
||||||
use lemmy_db_views::{
|
use lemmy_db_views::{
|
||||||
|
@ -45,7 +45,11 @@ pub async fn read_person(
|
||||||
|
|
||||||
// You don't need to return settings for the user, since this comes back with GetSite
|
// You don't need to return settings for the user, since this comes back with GetSite
|
||||||
// `my_user`
|
// `my_user`
|
||||||
let person_view = PersonView::read(&mut context.pool(), person_details_id).await?;
|
let is_admin = local_user_view
|
||||||
|
.as_ref()
|
||||||
|
.map(|l| is_admin(l).is_ok())
|
||||||
|
.unwrap_or_default();
|
||||||
|
let person_view = PersonView::read(&mut context.pool(), person_details_id, is_admin).await?;
|
||||||
|
|
||||||
let sort = data.sort;
|
let sort = data.sort;
|
||||||
let page = data.page;
|
let page = data.page;
|
||||||
|
|
|
@ -60,7 +60,7 @@ async fn convert_response(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
SearchableObjects::PersonOrCommunity(pc) => match *pc {
|
SearchableObjects::PersonOrCommunity(pc) => match *pc {
|
||||||
UserOrCommunity::User(u) => res.person = Some(PersonView::read(pool, u.id).await?),
|
UserOrCommunity::User(u) => res.person = Some(PersonView::read(pool, u.id, is_admin).await?),
|
||||||
UserOrCommunity::Community(c) => {
|
UserOrCommunity::Community(c) => {
|
||||||
res.community = Some(CommunityView::read(pool, c.id, local_user.as_ref(), is_admin).await?)
|
res.community = Some(CommunityView::read(pool, c.id, local_user.as_ref(), is_admin).await?)
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,8 @@ pub async fn markdown_rewrite_remote_links(
|
||||||
let mut local_url = local_url.to_string();
|
let mut local_url = local_url.to_string();
|
||||||
// restore title
|
// restore title
|
||||||
if let Some(extra) = extra {
|
if let Some(extra) = extra {
|
||||||
local_url = format!("{local_url} {extra}");
|
local_url.push(' ');
|
||||||
|
local_url.push_str(extra);
|
||||||
}
|
}
|
||||||
src.replace_range(start..end, local_url.as_str());
|
src.replace_range(start..end, local_url.as_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,8 +194,8 @@ impl Object for ApubComment {
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
content,
|
content,
|
||||||
removed: None,
|
removed: None,
|
||||||
published: note.published.map(Into::into),
|
published: note.published,
|
||||||
updated: note.updated.map(Into::into),
|
updated: note.updated,
|
||||||
deleted: Some(false),
|
deleted: Some(false),
|
||||||
ap_id: Some(note.id.into()),
|
ap_id: Some(note.id.into()),
|
||||||
distinguished: note.distinguished,
|
distinguished: note.distinguished,
|
||||||
|
|
|
@ -167,8 +167,8 @@ impl Object for ApubPerson {
|
||||||
deleted: Some(false),
|
deleted: Some(false),
|
||||||
avatar,
|
avatar,
|
||||||
banner,
|
banner,
|
||||||
published: person.published.map(Into::into),
|
published: person.published,
|
||||||
updated: person.updated.map(Into::into),
|
updated: person.updated,
|
||||||
actor_id: Some(person.id.into()),
|
actor_id: Some(person.id.into()),
|
||||||
bio,
|
bio,
|
||||||
local: Some(false),
|
local: Some(false),
|
||||||
|
|
|
@ -249,8 +249,8 @@ impl Object for ApubPost {
|
||||||
url: url.map(Into::into),
|
url: url.map(Into::into),
|
||||||
body,
|
body,
|
||||||
alt_text,
|
alt_text,
|
||||||
published: page.published.map(Into::into),
|
published: page.published,
|
||||||
updated: page.updated.map(Into::into),
|
updated: page.updated,
|
||||||
deleted: Some(false),
|
deleted: Some(false),
|
||||||
nsfw: page.sensitive,
|
nsfw: page.sensitive,
|
||||||
ap_id: Some(page.id.clone().into()),
|
ap_id: Some(page.id.clone().into()),
|
||||||
|
|
|
@ -166,8 +166,8 @@ impl Object for ApubPrivateMessage {
|
||||||
creator_id: creator.id,
|
creator_id: creator.id,
|
||||||
recipient_id: recipient.id,
|
recipient_id: recipient.id,
|
||||||
content,
|
content,
|
||||||
published: note.published.map(Into::into),
|
published: note.published,
|
||||||
updated: note.updated.map(Into::into),
|
updated: note.updated,
|
||||||
deleted: Some(false),
|
deleted: Some(false),
|
||||||
read: None,
|
read: None,
|
||||||
ap_id: Some(note.id.into()),
|
ap_id: Some(note.id.into()),
|
||||||
|
|
|
@ -52,8 +52,8 @@ activitypub_federation = { workspace = true, optional = true }
|
||||||
lemmy_utils = { workspace = true, optional = true }
|
lemmy_utils = { workspace = true, optional = true }
|
||||||
bcrypt = { workspace = true, optional = true }
|
bcrypt = { workspace = true, optional = true }
|
||||||
diesel = { workspace = true, features = [
|
diesel = { workspace = true, features = [
|
||||||
"postgres",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"postgres",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"uuid",
|
"uuid",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
|
@ -61,14 +61,14 @@ diesel-derive-newtype = { workspace = true, optional = true }
|
||||||
diesel-derive-enum = { workspace = true, optional = true }
|
diesel-derive-enum = { workspace = true, optional = true }
|
||||||
diesel_migrations = { workspace = true, optional = true }
|
diesel_migrations = { workspace = true, optional = true }
|
||||||
diesel-async = { workspace = true, features = [
|
diesel-async = { workspace = true, features = [
|
||||||
"postgres",
|
|
||||||
"deadpool",
|
"deadpool",
|
||||||
|
"postgres",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
regex = { workspace = true, optional = true }
|
regex = { workspace = true, optional = true }
|
||||||
diesel_ltree = { workspace = true, optional = true }
|
diesel_ltree = { workspace = true, optional = true }
|
||||||
async-trait = { workspace = true }
|
async-trait = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
deadpool = { version = "0.12.1", features = ["rt_tokio_1"], optional = true }
|
deadpool = { version = "0.12.1", optional = true, features = ["rt_tokio_1"] }
|
||||||
ts-rs = { workspace = true, optional = true }
|
ts-rs = { workspace = true, optional = true }
|
||||||
futures-util = { workspace = true }
|
futures-util = { workspace = true }
|
||||||
tokio = { workspace = true, optional = true }
|
tokio = { workspace = true, optional = true }
|
||||||
|
|
|
@ -653,3 +653,35 @@ CREATE TRIGGER change_values
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
EXECUTE FUNCTION r.private_message_change_values ();
|
EXECUTE FUNCTION r.private_message_change_values ();
|
||||||
|
|
||||||
|
-- Combined tables triggers
|
||||||
|
-- These insert (published, item_id) into X_combined tables
|
||||||
|
-- Reports (comment_report, post_report, private_message_report)
|
||||||
|
CREATE PROCEDURE r.create_report_combined_trigger (table_name text)
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $a$
|
||||||
|
BEGIN
|
||||||
|
EXECUTE replace($b$ CREATE FUNCTION r.report_combined_thing_insert ( )
|
||||||
|
RETURNS TRIGGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO report_combined (published, thing_id)
|
||||||
|
VALUES (NEW.published, NEW.id);
|
||||||
|
RETURN NEW;
|
||||||
|
END $$;
|
||||||
|
CREATE TRIGGER report_combined
|
||||||
|
AFTER INSERT ON thing
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION r.report_combined_thing_insert ( );
|
||||||
|
$b$,
|
||||||
|
'thing',
|
||||||
|
table_name);
|
||||||
|
END;
|
||||||
|
$a$;
|
||||||
|
|
||||||
|
CALL r.create_report_combined_trigger ('post_report');
|
||||||
|
|
||||||
|
CALL r.create_report_combined_trigger ('comment_report');
|
||||||
|
|
||||||
|
CALL r.create_report_combined_trigger ('private_message_report');
|
||||||
|
|
||||||
|
|
|
@ -186,26 +186,26 @@ BEGIN
|
||||||
AND pe.bot_account = FALSE
|
AND pe.bot_account = FALSE
|
||||||
UNION
|
UNION
|
||||||
SELECT
|
SELECT
|
||||||
pl.person_id,
|
pa.person_id,
|
||||||
p.community_id
|
p.community_id
|
||||||
FROM
|
FROM
|
||||||
post_like pl
|
post_actions pa
|
||||||
INNER JOIN post p ON pl.post_id = p.id
|
INNER JOIN post p ON pa.post_id = p.id
|
||||||
INNER JOIN person pe ON pl.person_id = pe.id
|
INNER JOIN person pe ON pa.person_id = pe.id
|
||||||
WHERE
|
WHERE
|
||||||
pl.published > ('now'::timestamp - i::interval)
|
pa.liked > ('now'::timestamp - i::interval)
|
||||||
AND pe.bot_account = FALSE
|
AND pe.bot_account = FALSE
|
||||||
UNION
|
UNION
|
||||||
SELECT
|
SELECT
|
||||||
cl.person_id,
|
ca.person_id,
|
||||||
p.community_id
|
p.community_id
|
||||||
FROM
|
FROM
|
||||||
comment_like cl
|
comment_actions ca
|
||||||
INNER JOIN comment c ON cl.comment_id = c.id
|
INNER JOIN comment c ON ca.comment_id = c.id
|
||||||
INNER JOIN post p ON c.post_id = p.id
|
INNER JOIN post p ON c.post_id = p.id
|
||||||
INNER JOIN person pe ON cl.person_id = pe.id
|
INNER JOIN person pe ON ca.person_id = pe.id
|
||||||
WHERE
|
WHERE
|
||||||
cl.published > ('now'::timestamp - i::interval)
|
ca.liked > ('now'::timestamp - i::interval)
|
||||||
AND pe.bot_account = FALSE) a
|
AND pe.bot_account = FALSE) a
|
||||||
GROUP BY
|
GROUP BY
|
||||||
community_id;
|
community_id;
|
||||||
|
@ -244,22 +244,22 @@ BEGIN
|
||||||
AND pe.bot_account = FALSE
|
AND pe.bot_account = FALSE
|
||||||
UNION
|
UNION
|
||||||
SELECT
|
SELECT
|
||||||
pl.person_id
|
pa.person_id
|
||||||
FROM
|
FROM
|
||||||
post_like pl
|
post_actions pa
|
||||||
INNER JOIN person pe ON pl.person_id = pe.id
|
INNER JOIN person pe ON pa.person_id = pe.id
|
||||||
WHERE
|
WHERE
|
||||||
pl.published > ('now'::timestamp - i::interval)
|
pa.liked > ('now'::timestamp - i::interval)
|
||||||
AND pe.local = TRUE
|
AND pe.local = TRUE
|
||||||
AND pe.bot_account = FALSE
|
AND pe.bot_account = FALSE
|
||||||
UNION
|
UNION
|
||||||
SELECT
|
SELECT
|
||||||
cl.person_id
|
ca.person_id
|
||||||
FROM
|
FROM
|
||||||
comment_like cl
|
comment_actions ca
|
||||||
INNER JOIN person pe ON cl.person_id = pe.id
|
INNER JOIN person pe ON ca.person_id = pe.id
|
||||||
WHERE
|
WHERE
|
||||||
cl.published > ('now'::timestamp - i::interval)
|
ca.liked > ('now'::timestamp - i::interval)
|
||||||
AND pe.local = TRUE
|
AND pe.local = TRUE
|
||||||
AND pe.bot_account = FALSE) a;
|
AND pe.bot_account = FALSE) a;
|
||||||
RETURN count_;
|
RETURN count_;
|
||||||
|
|
|
@ -35,4 +35,5 @@ pub mod private_message_report;
|
||||||
pub mod registration_application;
|
pub mod registration_application;
|
||||||
pub mod secret;
|
pub mod secret;
|
||||||
pub mod site;
|
pub mod site;
|
||||||
|
pub mod tag;
|
||||||
pub mod tagline;
|
pub mod tagline;
|
||||||
|
|
|
@ -55,13 +55,11 @@ impl OAuthProvider {
|
||||||
pub fn convert_providers_to_public(
|
pub fn convert_providers_to_public(
|
||||||
oauth_providers: Vec<OAuthProvider>,
|
oauth_providers: Vec<OAuthProvider>,
|
||||||
) -> Vec<PublicOAuthProvider> {
|
) -> Vec<PublicOAuthProvider> {
|
||||||
let mut result = Vec::<PublicOAuthProvider>::new();
|
oauth_providers
|
||||||
for oauth_provider in &oauth_providers {
|
.into_iter()
|
||||||
if oauth_provider.enabled {
|
.filter(|x| x.enabled)
|
||||||
result.push(PublicOAuthProvider(oauth_provider.clone()));
|
.map(PublicOAuthProvider)
|
||||||
}
|
.collect()
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_all_public(pool: &mut DbPool<'_>) -> Result<Vec<PublicOAuthProvider>, Error> {
|
pub async fn get_all_public(pool: &mut DbPool<'_>) -> Result<Vec<PublicOAuthProvider>, Error> {
|
||||||
|
|
53
crates/db_schema/src/impls/tag.rs
Normal file
53
crates/db_schema/src/impls/tag.rs
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
use crate::{
|
||||||
|
newtypes::TagId,
|
||||||
|
schema::{post_tag, tag},
|
||||||
|
source::tag::{PostTagInsertForm, Tag, TagInsertForm},
|
||||||
|
traits::Crud,
|
||||||
|
utils::{get_conn, DbPool},
|
||||||
|
};
|
||||||
|
use diesel::{insert_into, result::Error, QueryDsl};
|
||||||
|
use diesel_async::RunQueryDsl;
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl Crud for Tag {
|
||||||
|
type InsertForm = TagInsertForm;
|
||||||
|
|
||||||
|
type UpdateForm = TagInsertForm;
|
||||||
|
|
||||||
|
type IdType = TagId;
|
||||||
|
|
||||||
|
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
insert_into(tag::table)
|
||||||
|
.values(form)
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn update(
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
pid: TagId,
|
||||||
|
form: &Self::UpdateForm,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
diesel::update(tag::table.find(pid))
|
||||||
|
.set(form)
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PostTagInsertForm {
|
||||||
|
pub async fn insert_tag_associations(
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
tags: &[PostTagInsertForm],
|
||||||
|
) -> LemmyResult<()> {
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
insert_into(post_tag::table)
|
||||||
|
.values(tags)
|
||||||
|
.execute(conn)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
|
@ -89,19 +89,19 @@ pub struct PersonMentionId(i32);
|
||||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
/// The comment report id.
|
/// The comment report id.
|
||||||
pub struct CommentReportId(i32);
|
pub struct CommentReportId(pub i32);
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
/// The post report id.
|
/// The post report id.
|
||||||
pub struct PostReportId(i32);
|
pub struct PostReportId(pub i32);
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
/// The private message report id.
|
/// The private message report id.
|
||||||
pub struct PrivateMessageReportId(i32);
|
pub struct PrivateMessageReportId(pub i32);
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
|
||||||
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||||
|
@ -179,6 +179,11 @@ pub struct LtreeDef(pub String);
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
pub struct DbUrl(pub(crate) Box<Url>);
|
pub struct DbUrl(pub(crate) Box<Url>);
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "full", derive(DieselNewType))]
|
||||||
|
/// The report combined id
|
||||||
|
pub struct ReportCombinedId(i32);
|
||||||
|
|
||||||
impl DbUrl {
|
impl DbUrl {
|
||||||
pub fn inner(&self) -> &Url {
|
pub fn inner(&self) -> &Url {
|
||||||
&self.0
|
&self.0
|
||||||
|
@ -283,3 +288,9 @@ impl InstanceId {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(feature = "full", derive(DieselNewType, TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
/// The internal tag id.
|
||||||
|
pub struct TagId(pub i32);
|
||||||
|
|
|
@ -826,6 +826,14 @@ diesel::table! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diesel::table! {
|
||||||
|
post_tag (post_id, tag_id) {
|
||||||
|
post_id -> Int4,
|
||||||
|
tag_id -> Int4,
|
||||||
|
published -> Timestamptz,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
diesel::table! {
|
diesel::table! {
|
||||||
private_message (id) {
|
private_message (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
|
@ -881,6 +889,16 @@ diesel::table! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diesel::table! {
|
||||||
|
report_combined (id) {
|
||||||
|
id -> Int4,
|
||||||
|
published -> Timestamptz,
|
||||||
|
post_report_id -> Nullable<Int4>,
|
||||||
|
comment_report_id -> Nullable<Int4>,
|
||||||
|
private_message_report_id -> Nullable<Int4>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
diesel::table! {
|
diesel::table! {
|
||||||
secret (id) {
|
secret (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
|
@ -951,6 +969,18 @@ diesel::table! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diesel::table! {
|
||||||
|
tag (id) {
|
||||||
|
id -> Int4,
|
||||||
|
ap_id -> Text,
|
||||||
|
name -> Text,
|
||||||
|
community_id -> Int4,
|
||||||
|
published -> Timestamptz,
|
||||||
|
updated -> Nullable<Timestamptz>,
|
||||||
|
deleted -> Bool,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
diesel::table! {
|
diesel::table! {
|
||||||
tagline (id) {
|
tagline (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
|
@ -1032,13 +1062,19 @@ diesel::joinable!(post_aggregates -> instance (instance_id));
|
||||||
diesel::joinable!(post_aggregates -> person (creator_id));
|
diesel::joinable!(post_aggregates -> person (creator_id));
|
||||||
diesel::joinable!(post_aggregates -> post (post_id));
|
diesel::joinable!(post_aggregates -> post (post_id));
|
||||||
diesel::joinable!(post_report -> post (post_id));
|
diesel::joinable!(post_report -> post (post_id));
|
||||||
|
diesel::joinable!(post_tag -> post (post_id));
|
||||||
|
diesel::joinable!(post_tag -> tag (tag_id));
|
||||||
diesel::joinable!(private_message_report -> private_message (private_message_id));
|
diesel::joinable!(private_message_report -> private_message (private_message_id));
|
||||||
diesel::joinable!(registration_application -> local_user (local_user_id));
|
diesel::joinable!(registration_application -> local_user (local_user_id));
|
||||||
diesel::joinable!(registration_application -> person (admin_id));
|
diesel::joinable!(registration_application -> person (admin_id));
|
||||||
|
diesel::joinable!(report_combined -> comment_report (comment_report_id));
|
||||||
|
diesel::joinable!(report_combined -> post_report (post_report_id));
|
||||||
|
diesel::joinable!(report_combined -> private_message_report (private_message_report_id));
|
||||||
diesel::joinable!(site -> instance (instance_id));
|
diesel::joinable!(site -> instance (instance_id));
|
||||||
diesel::joinable!(site_aggregates -> site (site_id));
|
diesel::joinable!(site_aggregates -> site (site_id));
|
||||||
diesel::joinable!(site_language -> language (language_id));
|
diesel::joinable!(site_language -> language (language_id));
|
||||||
diesel::joinable!(site_language -> site (site_id));
|
diesel::joinable!(site_language -> site (site_id));
|
||||||
|
diesel::joinable!(tag -> community (community_id));
|
||||||
|
|
||||||
diesel::allow_tables_to_appear_in_same_query!(
|
diesel::allow_tables_to_appear_in_same_query!(
|
||||||
admin_allow_instance,
|
admin_allow_instance,
|
||||||
|
@ -1098,15 +1134,18 @@ diesel::allow_tables_to_appear_in_same_query!(
|
||||||
post_actions,
|
post_actions,
|
||||||
post_aggregates,
|
post_aggregates,
|
||||||
post_report,
|
post_report,
|
||||||
|
post_tag,
|
||||||
private_message,
|
private_message,
|
||||||
private_message_report,
|
private_message_report,
|
||||||
received_activity,
|
received_activity,
|
||||||
registration_application,
|
registration_application,
|
||||||
remote_image,
|
remote_image,
|
||||||
|
report_combined,
|
||||||
secret,
|
secret,
|
||||||
sent_activity,
|
sent_activity,
|
||||||
site,
|
site,
|
||||||
site_aggregates,
|
site_aggregates,
|
||||||
site_language,
|
site_language,
|
||||||
|
tag,
|
||||||
tagline,
|
tagline,
|
||||||
);
|
);
|
||||||
|
|
1
crates/db_schema/src/source/combined/mod.rs
Normal file
1
crates/db_schema/src/source/combined/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod report;
|
23
crates/db_schema/src/source/combined/report.rs
Normal file
23
crates/db_schema/src/source/combined/report.rs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
use crate::newtypes::{CommentReportId, PostReportId, PrivateMessageReportId, ReportCombinedId};
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
use crate::schema::report_combined;
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
use i_love_jesus::CursorKeysModule;
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "full",
|
||||||
|
derive(Identifiable, Queryable, Selectable, CursorKeysModule)
|
||||||
|
)]
|
||||||
|
#[cfg_attr(feature = "full", diesel(table_name = report_combined))]
|
||||||
|
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||||
|
#[cfg_attr(feature = "full", cursor_keys_module(name = report_combined_keys))]
|
||||||
|
/// A combined reports table.
|
||||||
|
pub struct ReportCombined {
|
||||||
|
pub id: ReportCombinedId,
|
||||||
|
pub published: DateTime<Utc>,
|
||||||
|
pub post_report_id: Option<PostReportId>,
|
||||||
|
pub comment_report_id: Option<CommentReportId>,
|
||||||
|
pub private_message_report_id: Option<PrivateMessageReportId>,
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ use url::Url;
|
||||||
pub mod activity;
|
pub mod activity;
|
||||||
pub mod actor_language;
|
pub mod actor_language;
|
||||||
pub mod captcha_answer;
|
pub mod captcha_answer;
|
||||||
|
pub mod combined;
|
||||||
pub mod comment;
|
pub mod comment;
|
||||||
pub mod comment_reply;
|
pub mod comment_reply;
|
||||||
pub mod comment_report;
|
pub mod comment_report;
|
||||||
|
@ -40,6 +41,7 @@ pub mod private_message_report;
|
||||||
pub mod registration_application;
|
pub mod registration_application;
|
||||||
pub mod secret;
|
pub mod secret;
|
||||||
pub mod site;
|
pub mod site;
|
||||||
|
pub mod tag;
|
||||||
pub mod tagline;
|
pub mod tagline;
|
||||||
|
|
||||||
/// Default value for columns like [community::Community.inbox_url] which are marked as serde(skip).
|
/// Default value for columns like [community::Community.inbox_url] which are marked as serde(skip).
|
||||||
|
|
57
crates/db_schema/src/source/tag.rs
Normal file
57
crates/db_schema/src/source/tag.rs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
use crate::newtypes::{CommunityId, DbUrl, PostId, TagId};
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
use crate::schema::{post_tag, tag};
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_with::skip_serializing_none;
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
use ts_rs::TS;
|
||||||
|
|
||||||
|
/// A tag that can be assigned to a post within a community.
|
||||||
|
/// The tag object is created by the community moderators.
|
||||||
|
/// The assignment happens by the post creator and can be updated by the community moderators.
|
||||||
|
///
|
||||||
|
/// A tag is a federatable object that gives additional context to another object, which can be
|
||||||
|
/// displayed and filtered on currently, we only have community post tags, which is a tag that is
|
||||||
|
/// created by post authors as well as mods of a community, to categorize a post. in the future we
|
||||||
|
/// may add more tag types, depending on the requirements, this will lead to either expansion of
|
||||||
|
/// this table (community_id optional, addition of tag_type enum) or split of this table / creation
|
||||||
|
/// of new tables.
|
||||||
|
#[skip_serializing_none]
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS, Queryable, Selectable, Identifiable))]
|
||||||
|
#[cfg_attr(feature = "full", diesel(table_name = tag))]
|
||||||
|
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
pub struct Tag {
|
||||||
|
pub id: TagId,
|
||||||
|
pub ap_id: DbUrl,
|
||||||
|
pub name: String,
|
||||||
|
/// the community that owns this tag
|
||||||
|
pub community_id: CommunityId,
|
||||||
|
pub published: DateTime<Utc>,
|
||||||
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
|
pub updated: Option<DateTime<Utc>>,
|
||||||
|
pub deleted: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
|
||||||
|
#[cfg_attr(feature = "full", diesel(table_name = tag))]
|
||||||
|
pub struct TagInsertForm {
|
||||||
|
pub ap_id: DbUrl,
|
||||||
|
pub name: String,
|
||||||
|
pub community_id: CommunityId,
|
||||||
|
// default now
|
||||||
|
pub published: Option<DateTime<Utc>>,
|
||||||
|
pub updated: Option<DateTime<Utc>>,
|
||||||
|
pub deleted: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
|
||||||
|
#[cfg_attr(feature = "full", diesel(table_name = post_tag))]
|
||||||
|
pub struct PostTagInsertForm {
|
||||||
|
pub post_id: PostId,
|
||||||
|
pub tag_id: TagId,
|
||||||
|
}
|
|
@ -547,6 +547,11 @@ pub mod functions {
|
||||||
|
|
||||||
// really this function is variadic, this just adds the two-argument version
|
// really this function is variadic, this just adds the two-argument version
|
||||||
define_sql_function!(fn coalesce<T: diesel::sql_types::SqlType + diesel::sql_types::SingleValue>(x: diesel::sql_types::Nullable<T>, y: T) -> T);
|
define_sql_function!(fn coalesce<T: diesel::sql_types::SqlType + diesel::sql_types::SingleValue>(x: diesel::sql_types::Nullable<T>, y: T) -> T);
|
||||||
|
|
||||||
|
define_sql_function! {
|
||||||
|
#[aggregate]
|
||||||
|
fn json_agg<T: diesel::sql_types::SqlType + diesel::sql_types::SingleValue>(obj: T) -> Json
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const DELETED_REPLACEMENT_TEXT: &str = "*Permanently Deleted*";
|
pub const DELETED_REPLACEMENT_TEXT: &str = "*Permanently Deleted*";
|
||||||
|
|
|
@ -35,6 +35,7 @@ diesel-async = { workspace = true, optional = true }
|
||||||
diesel_ltree = { workspace = true, optional = true }
|
diesel_ltree = { workspace = true, optional = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_with = { workspace = true }
|
serde_with = { workspace = true }
|
||||||
|
serde_json = { workspace = true }
|
||||||
tracing = { workspace = true, optional = true }
|
tracing = { workspace = true, optional = true }
|
||||||
ts-rs = { workspace = true, optional = true }
|
ts-rs = { workspace = true, optional = true }
|
||||||
actix-web = { workspace = true, optional = true }
|
actix-web = { workspace = true, optional = true }
|
||||||
|
@ -46,3 +47,4 @@ serial_test = { workspace = true }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
pretty_assertions = { workspace = true }
|
pretty_assertions = { workspace = true }
|
||||||
url = { workspace = true }
|
url = { workspace = true }
|
||||||
|
test-context = "0.3.0"
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::structs::{CommentReportView, LocalUserView};
|
use crate::structs::CommentReportView;
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::now,
|
dsl::now,
|
||||||
pg::Pg,
|
|
||||||
result::Error,
|
result::Error,
|
||||||
BoolExpressionMethods,
|
BoolExpressionMethods,
|
||||||
ExpressionMethods,
|
ExpressionMethods,
|
||||||
|
@ -12,7 +11,7 @@ use diesel::{
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aliases::{self, creator_community_actions},
|
aliases::{self, creator_community_actions},
|
||||||
newtypes::{CommentId, CommentReportId, CommunityId, PersonId},
|
newtypes::{CommentReportId, PersonId},
|
||||||
schema::{
|
schema::{
|
||||||
comment,
|
comment,
|
||||||
comment_actions,
|
comment_actions,
|
||||||
|
@ -26,26 +25,21 @@ use lemmy_db_schema::{
|
||||||
post,
|
post,
|
||||||
},
|
},
|
||||||
source::community::CommunityFollower,
|
source::community::CommunityFollower,
|
||||||
utils::{
|
utils::{actions, actions_alias, functions::coalesce, get_conn, DbPool},
|
||||||
actions,
|
|
||||||
actions_alias,
|
|
||||||
functions::coalesce,
|
|
||||||
get_conn,
|
|
||||||
limit_and_offset,
|
|
||||||
DbConn,
|
|
||||||
DbPool,
|
|
||||||
ListFn,
|
|
||||||
Queries,
|
|
||||||
ReadFn,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fn queries<'a>() -> Queries<
|
impl CommentReportView {
|
||||||
impl ReadFn<'a, CommentReportView, (CommentReportId, PersonId)>,
|
/// returns the CommentReportView for the provided report_id
|
||||||
impl ListFn<'a, CommentReportView, (CommentReportQuery, &'a LocalUserView)>,
|
///
|
||||||
> {
|
/// * `report_id` - the report id to obtain
|
||||||
let all_joins = |query: comment_report::BoxedQuery<'a, Pg>, my_person_id: PersonId| {
|
pub async fn read(
|
||||||
query
|
pool: &mut DbPool<'_>,
|
||||||
|
report_id: CommentReportId,
|
||||||
|
my_person_id: PersonId,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
comment_report::table
|
||||||
|
.find(report_id)
|
||||||
.inner_join(comment::table)
|
.inner_join(comment::table)
|
||||||
.inner_join(post::table.on(comment::post_id.eq(post::id)))
|
.inner_join(post::table.on(comment::post_id.eq(post::id)))
|
||||||
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
||||||
|
@ -117,456 +111,7 @@ fn queries<'a>() -> Queries<
|
||||||
comment_actions::like_score.nullable(),
|
comment_actions::like_score.nullable(),
|
||||||
aliases::person2.fields(person::all_columns).nullable(),
|
aliases::person2.fields(person::all_columns).nullable(),
|
||||||
))
|
))
|
||||||
};
|
.first(conn)
|
||||||
|
.await
|
||||||
let read = move |mut conn: DbConn<'a>, (report_id, my_person_id): (CommentReportId, PersonId)| async move {
|
|
||||||
all_joins(
|
|
||||||
comment_report::table.find(report_id).into_boxed(),
|
|
||||||
my_person_id,
|
|
||||||
)
|
|
||||||
.first(&mut conn)
|
|
||||||
.await
|
|
||||||
};
|
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>,
|
|
||||||
(options, user): (CommentReportQuery, &'a LocalUserView)| async move {
|
|
||||||
let mut query = all_joins(comment_report::table.into_boxed(), user.person.id);
|
|
||||||
|
|
||||||
if let Some(community_id) = options.community_id {
|
|
||||||
query = query.filter(post::community_id.eq(community_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(comment_id) = options.comment_id {
|
|
||||||
query = query.filter(comment_report::comment_id.eq(comment_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
// If viewing all reports, order by newest, but if viewing unresolved only, show the oldest
|
|
||||||
// first (FIFO)
|
|
||||||
if options.unresolved_only {
|
|
||||||
query = query
|
|
||||||
.filter(comment_report::resolved.eq(false))
|
|
||||||
.order_by(comment_report::published.asc());
|
|
||||||
} else {
|
|
||||||
query = query.order_by(comment_report::published.desc());
|
|
||||||
}
|
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
|
||||||
|
|
||||||
query = query.limit(limit).offset(offset);
|
|
||||||
|
|
||||||
// If its not an admin, get only the ones you mod
|
|
||||||
if !user.local_user.admin {
|
|
||||||
query = query.filter(community_actions::became_moderator.is_not_null());
|
|
||||||
}
|
|
||||||
|
|
||||||
query.load::<CommentReportView>(&mut conn).await
|
|
||||||
};
|
|
||||||
|
|
||||||
Queries::new(read, list)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommentReportView {
|
|
||||||
/// returns the CommentReportView for the provided report_id
|
|
||||||
///
|
|
||||||
/// * `report_id` - the report id to obtain
|
|
||||||
pub async fn read(
|
|
||||||
pool: &mut DbPool<'_>,
|
|
||||||
report_id: CommentReportId,
|
|
||||||
my_person_id: PersonId,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
queries().read(pool, (report_id, my_person_id)).await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the current unresolved comment report count for the communities you mod
|
|
||||||
pub async fn get_report_count(
|
|
||||||
pool: &mut DbPool<'_>,
|
|
||||||
my_person_id: PersonId,
|
|
||||||
admin: bool,
|
|
||||||
community_id: Option<CommunityId>,
|
|
||||||
) -> Result<i64, Error> {
|
|
||||||
use diesel::dsl::count;
|
|
||||||
|
|
||||||
let conn = &mut get_conn(pool).await?;
|
|
||||||
|
|
||||||
let mut query = comment_report::table
|
|
||||||
.inner_join(comment::table)
|
|
||||||
.inner_join(post::table.on(comment::post_id.eq(post::id)))
|
|
||||||
.filter(comment_report::resolved.eq(false))
|
|
||||||
.into_boxed();
|
|
||||||
|
|
||||||
if let Some(community_id) = community_id {
|
|
||||||
query = query.filter(post::community_id.eq(community_id))
|
|
||||||
}
|
|
||||||
|
|
||||||
// If its not an admin, get only the ones you mod
|
|
||||||
if !admin {
|
|
||||||
query
|
|
||||||
.inner_join(
|
|
||||||
community_actions::table.on(
|
|
||||||
community_actions::community_id
|
|
||||||
.eq(post::community_id)
|
|
||||||
.and(community_actions::person_id.eq(my_person_id))
|
|
||||||
.and(community_actions::became_moderator.is_not_null()),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.select(count(comment_report::id))
|
|
||||||
.first::<i64>(conn)
|
|
||||||
.await
|
|
||||||
} else {
|
|
||||||
query
|
|
||||||
.select(count(comment_report::id))
|
|
||||||
.first::<i64>(conn)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct CommentReportQuery {
|
|
||||||
pub community_id: Option<CommunityId>,
|
|
||||||
pub comment_id: Option<CommentId>,
|
|
||||||
pub page: Option<i64>,
|
|
||||||
pub limit: Option<i64>,
|
|
||||||
pub unresolved_only: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommentReportQuery {
|
|
||||||
pub async fn list(
|
|
||||||
self,
|
|
||||||
pool: &mut DbPool<'_>,
|
|
||||||
user: &LocalUserView,
|
|
||||||
) -> Result<Vec<CommentReportView>, Error> {
|
|
||||||
queries().list(pool, (self, user)).await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[expect(clippy::indexing_slicing)]
|
|
||||||
mod tests {
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
comment_report_view::{CommentReportQuery, CommentReportView},
|
|
||||||
structs::LocalUserView,
|
|
||||||
};
|
|
||||||
use lemmy_db_schema::{
|
|
||||||
aggregates::structs::CommentAggregates,
|
|
||||||
source::{
|
|
||||||
comment::{Comment, CommentInsertForm},
|
|
||||||
comment_report::{CommentReport, CommentReportForm},
|
|
||||||
community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm},
|
|
||||||
instance::Instance,
|
|
||||||
local_user::{LocalUser, LocalUserInsertForm},
|
|
||||||
local_user_vote_display_mode::LocalUserVoteDisplayMode,
|
|
||||||
person::{Person, PersonInsertForm},
|
|
||||||
post::{Post, PostInsertForm},
|
|
||||||
},
|
|
||||||
traits::{Crud, Joinable, Reportable},
|
|
||||||
utils::{build_db_pool_for_tests, RANK_DEFAULT},
|
|
||||||
CommunityVisibility,
|
|
||||||
SubscribedType,
|
|
||||||
};
|
|
||||||
use lemmy_utils::error::LemmyResult;
|
|
||||||
use pretty_assertions::assert_eq;
|
|
||||||
use serial_test::serial;
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
#[serial]
|
|
||||||
async fn test_crud() -> LemmyResult<()> {
|
|
||||||
let pool = &build_db_pool_for_tests();
|
|
||||||
let pool = &mut pool.into();
|
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
|
|
||||||
|
|
||||||
let new_person = PersonInsertForm::test_form(inserted_instance.id, "timmy_crv");
|
|
||||||
|
|
||||||
let inserted_timmy = Person::create(pool, &new_person).await?;
|
|
||||||
|
|
||||||
let new_local_user = LocalUserInsertForm::test_form(inserted_timmy.id);
|
|
||||||
let timmy_local_user = LocalUser::create(pool, &new_local_user, vec![]).await?;
|
|
||||||
let timmy_view = LocalUserView {
|
|
||||||
local_user: timmy_local_user,
|
|
||||||
local_user_vote_display_mode: LocalUserVoteDisplayMode::default(),
|
|
||||||
person: inserted_timmy.clone(),
|
|
||||||
counts: Default::default(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let new_person_2 = PersonInsertForm::test_form(inserted_instance.id, "sara_crv");
|
|
||||||
|
|
||||||
let inserted_sara = Person::create(pool, &new_person_2).await?;
|
|
||||||
|
|
||||||
// Add a third person, since new ppl can only report something once.
|
|
||||||
let new_person_3 = PersonInsertForm::test_form(inserted_instance.id, "jessica_crv");
|
|
||||||
|
|
||||||
let inserted_jessica = Person::create(pool, &new_person_3).await?;
|
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::new(
|
|
||||||
inserted_instance.id,
|
|
||||||
"test community crv".to_string(),
|
|
||||||
"nada".to_owned(),
|
|
||||||
"pubkey".to_string(),
|
|
||||||
);
|
|
||||||
let inserted_community = Community::create(pool, &new_community).await?;
|
|
||||||
|
|
||||||
// Make timmy a mod
|
|
||||||
let timmy_moderator_form = CommunityModeratorForm {
|
|
||||||
community_id: inserted_community.id,
|
|
||||||
person_id: inserted_timmy.id,
|
|
||||||
};
|
|
||||||
|
|
||||||
let _inserted_moderator = CommunityModerator::join(pool, &timmy_moderator_form).await?;
|
|
||||||
|
|
||||||
let new_post = PostInsertForm::new(
|
|
||||||
"A test post crv".into(),
|
|
||||||
inserted_timmy.id,
|
|
||||||
inserted_community.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
let inserted_post = Post::create(pool, &new_post).await?;
|
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::new(
|
|
||||||
inserted_timmy.id,
|
|
||||||
inserted_post.id,
|
|
||||||
"A test comment 32".into(),
|
|
||||||
);
|
|
||||||
let inserted_comment = Comment::create(pool, &comment_form, None).await?;
|
|
||||||
|
|
||||||
// sara reports
|
|
||||||
let sara_report_form = CommentReportForm {
|
|
||||||
creator_id: inserted_sara.id,
|
|
||||||
comment_id: inserted_comment.id,
|
|
||||||
original_comment_text: "this was it at time of creation".into(),
|
|
||||||
reason: "from sara".into(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let inserted_sara_report = CommentReport::report(pool, &sara_report_form).await?;
|
|
||||||
|
|
||||||
// jessica reports
|
|
||||||
let jessica_report_form = CommentReportForm {
|
|
||||||
creator_id: inserted_jessica.id,
|
|
||||||
comment_id: inserted_comment.id,
|
|
||||||
original_comment_text: "this was it at time of creation".into(),
|
|
||||||
reason: "from jessica".into(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let inserted_jessica_report = CommentReport::report(pool, &jessica_report_form).await?;
|
|
||||||
|
|
||||||
let agg = CommentAggregates::read(pool, inserted_comment.id).await?;
|
|
||||||
|
|
||||||
let read_jessica_report_view =
|
|
||||||
CommentReportView::read(pool, inserted_jessica_report.id, inserted_timmy.id).await?;
|
|
||||||
let expected_jessica_report_view = CommentReportView {
|
|
||||||
comment_report: inserted_jessica_report.clone(),
|
|
||||||
comment: inserted_comment.clone(),
|
|
||||||
post: inserted_post,
|
|
||||||
creator_is_moderator: true,
|
|
||||||
creator_is_admin: false,
|
|
||||||
creator_blocked: false,
|
|
||||||
subscribed: SubscribedType::NotSubscribed,
|
|
||||||
saved: false,
|
|
||||||
community: Community {
|
|
||||||
id: inserted_community.id,
|
|
||||||
name: inserted_community.name,
|
|
||||||
icon: None,
|
|
||||||
removed: false,
|
|
||||||
deleted: false,
|
|
||||||
nsfw: false,
|
|
||||||
actor_id: inserted_community.actor_id.clone(),
|
|
||||||
local: true,
|
|
||||||
title: inserted_community.title,
|
|
||||||
sidebar: None,
|
|
||||||
description: None,
|
|
||||||
updated: None,
|
|
||||||
banner: None,
|
|
||||||
hidden: false,
|
|
||||||
posting_restricted_to_mods: false,
|
|
||||||
published: inserted_community.published,
|
|
||||||
private_key: inserted_community.private_key,
|
|
||||||
public_key: inserted_community.public_key,
|
|
||||||
last_refreshed_at: inserted_community.last_refreshed_at,
|
|
||||||
followers_url: inserted_community.followers_url,
|
|
||||||
inbox_url: inserted_community.inbox_url,
|
|
||||||
moderators_url: inserted_community.moderators_url,
|
|
||||||
featured_url: inserted_community.featured_url,
|
|
||||||
instance_id: inserted_instance.id,
|
|
||||||
visibility: CommunityVisibility::Public,
|
|
||||||
},
|
|
||||||
creator: Person {
|
|
||||||
id: inserted_jessica.id,
|
|
||||||
name: inserted_jessica.name,
|
|
||||||
display_name: None,
|
|
||||||
published: inserted_jessica.published,
|
|
||||||
avatar: None,
|
|
||||||
actor_id: inserted_jessica.actor_id.clone(),
|
|
||||||
local: true,
|
|
||||||
banned: false,
|
|
||||||
deleted: false,
|
|
||||||
bot_account: false,
|
|
||||||
bio: None,
|
|
||||||
banner: None,
|
|
||||||
updated: None,
|
|
||||||
inbox_url: inserted_jessica.inbox_url.clone(),
|
|
||||||
matrix_user_id: None,
|
|
||||||
ban_expires: None,
|
|
||||||
instance_id: inserted_instance.id,
|
|
||||||
private_key: inserted_jessica.private_key,
|
|
||||||
public_key: inserted_jessica.public_key,
|
|
||||||
last_refreshed_at: inserted_jessica.last_refreshed_at,
|
|
||||||
},
|
|
||||||
comment_creator: Person {
|
|
||||||
id: inserted_timmy.id,
|
|
||||||
name: inserted_timmy.name.clone(),
|
|
||||||
display_name: None,
|
|
||||||
published: inserted_timmy.published,
|
|
||||||
avatar: None,
|
|
||||||
actor_id: inserted_timmy.actor_id.clone(),
|
|
||||||
local: true,
|
|
||||||
banned: false,
|
|
||||||
deleted: false,
|
|
||||||
bot_account: false,
|
|
||||||
bio: None,
|
|
||||||
banner: None,
|
|
||||||
updated: None,
|
|
||||||
inbox_url: inserted_timmy.inbox_url.clone(),
|
|
||||||
matrix_user_id: None,
|
|
||||||
ban_expires: None,
|
|
||||||
instance_id: inserted_instance.id,
|
|
||||||
private_key: inserted_timmy.private_key.clone(),
|
|
||||||
public_key: inserted_timmy.public_key.clone(),
|
|
||||||
last_refreshed_at: inserted_timmy.last_refreshed_at,
|
|
||||||
},
|
|
||||||
creator_banned_from_community: false,
|
|
||||||
counts: CommentAggregates {
|
|
||||||
comment_id: inserted_comment.id,
|
|
||||||
score: 0,
|
|
||||||
upvotes: 0,
|
|
||||||
downvotes: 0,
|
|
||||||
published: agg.published,
|
|
||||||
child_count: 0,
|
|
||||||
hot_rank: RANK_DEFAULT,
|
|
||||||
controversy_rank: 0.0,
|
|
||||||
report_count: 2,
|
|
||||||
unresolved_report_count: 2,
|
|
||||||
},
|
|
||||||
my_vote: None,
|
|
||||||
resolver: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_eq!(read_jessica_report_view, expected_jessica_report_view);
|
|
||||||
|
|
||||||
let mut expected_sara_report_view = expected_jessica_report_view.clone();
|
|
||||||
expected_sara_report_view.comment_report = inserted_sara_report;
|
|
||||||
expected_sara_report_view.creator = Person {
|
|
||||||
id: inserted_sara.id,
|
|
||||||
name: inserted_sara.name,
|
|
||||||
display_name: None,
|
|
||||||
published: inserted_sara.published,
|
|
||||||
avatar: None,
|
|
||||||
actor_id: inserted_sara.actor_id.clone(),
|
|
||||||
local: true,
|
|
||||||
banned: false,
|
|
||||||
deleted: false,
|
|
||||||
bot_account: false,
|
|
||||||
bio: None,
|
|
||||||
banner: None,
|
|
||||||
updated: None,
|
|
||||||
inbox_url: inserted_sara.inbox_url.clone(),
|
|
||||||
matrix_user_id: None,
|
|
||||||
ban_expires: None,
|
|
||||||
instance_id: inserted_instance.id,
|
|
||||||
private_key: inserted_sara.private_key,
|
|
||||||
public_key: inserted_sara.public_key,
|
|
||||||
last_refreshed_at: inserted_sara.last_refreshed_at,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Do a batch read of timmys reports
|
|
||||||
let reports = CommentReportQuery::default()
|
|
||||||
.list(pool, &timmy_view)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
reports,
|
|
||||||
[
|
|
||||||
expected_jessica_report_view.clone(),
|
|
||||||
expected_sara_report_view.clone(),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Make sure the counts are correct
|
|
||||||
let report_count =
|
|
||||||
CommentReportView::get_report_count(pool, inserted_timmy.id, false, None).await?;
|
|
||||||
assert_eq!(2, report_count);
|
|
||||||
|
|
||||||
// Try to resolve the report
|
|
||||||
CommentReport::resolve(pool, inserted_jessica_report.id, inserted_timmy.id).await?;
|
|
||||||
let read_jessica_report_view_after_resolve =
|
|
||||||
CommentReportView::read(pool, inserted_jessica_report.id, inserted_timmy.id).await?;
|
|
||||||
|
|
||||||
let mut expected_jessica_report_view_after_resolve = expected_jessica_report_view;
|
|
||||||
expected_jessica_report_view_after_resolve
|
|
||||||
.comment_report
|
|
||||||
.resolved = true;
|
|
||||||
expected_jessica_report_view_after_resolve
|
|
||||||
.comment_report
|
|
||||||
.resolver_id = Some(inserted_timmy.id);
|
|
||||||
expected_jessica_report_view_after_resolve
|
|
||||||
.comment_report
|
|
||||||
.updated = read_jessica_report_view_after_resolve
|
|
||||||
.comment_report
|
|
||||||
.updated;
|
|
||||||
expected_jessica_report_view_after_resolve
|
|
||||||
.counts
|
|
||||||
.unresolved_report_count = 1;
|
|
||||||
expected_sara_report_view.counts.unresolved_report_count = 1;
|
|
||||||
expected_jessica_report_view_after_resolve.resolver = Some(Person {
|
|
||||||
id: inserted_timmy.id,
|
|
||||||
name: inserted_timmy.name.clone(),
|
|
||||||
display_name: None,
|
|
||||||
published: inserted_timmy.published,
|
|
||||||
avatar: None,
|
|
||||||
actor_id: inserted_timmy.actor_id.clone(),
|
|
||||||
local: true,
|
|
||||||
banned: false,
|
|
||||||
deleted: false,
|
|
||||||
bot_account: false,
|
|
||||||
bio: None,
|
|
||||||
banner: None,
|
|
||||||
updated: None,
|
|
||||||
inbox_url: inserted_timmy.inbox_url.clone(),
|
|
||||||
private_key: inserted_timmy.private_key.clone(),
|
|
||||||
public_key: inserted_timmy.public_key.clone(),
|
|
||||||
last_refreshed_at: inserted_timmy.last_refreshed_at,
|
|
||||||
matrix_user_id: None,
|
|
||||||
ban_expires: None,
|
|
||||||
instance_id: inserted_instance.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
read_jessica_report_view_after_resolve,
|
|
||||||
expected_jessica_report_view_after_resolve
|
|
||||||
);
|
|
||||||
|
|
||||||
// Do a batch read of timmys reports
|
|
||||||
// It should only show saras, which is unresolved
|
|
||||||
let reports_after_resolve = CommentReportQuery {
|
|
||||||
unresolved_only: (true),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
.list(pool, &timmy_view)
|
|
||||||
.await?;
|
|
||||||
assert_eq!(reports_after_resolve[0], expected_sara_report_view);
|
|
||||||
assert_eq!(reports_after_resolve.len(), 1);
|
|
||||||
|
|
||||||
// Make sure the counts are correct
|
|
||||||
let report_count_after_resolved =
|
|
||||||
CommentReportView::get_report_count(pool, inserted_timmy.id, false, None).await?;
|
|
||||||
assert_eq!(1, report_count_after_resolved);
|
|
||||||
|
|
||||||
Person::delete(pool, inserted_timmy.id).await?;
|
|
||||||
Person::delete(pool, inserted_sara.id).await?;
|
|
||||||
Person::delete(pool, inserted_jessica.id).await?;
|
|
||||||
Community::delete(pool, inserted_community.id).await?;
|
|
||||||
Instance::delete(pool, inserted_instance.id).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,28 +141,25 @@ fn queries<'a>() -> Queries<
|
||||||
query.first(&mut conn).await
|
query.first(&mut conn).await
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>, (options, site): (CommentQuery<'a>, &'a Site)| async move {
|
let list = move |mut conn: DbConn<'a>, (o, site): (CommentQuery<'a>, &'a Site)| async move {
|
||||||
// The left join below will return None in this case
|
// The left join below will return None in this case
|
||||||
let local_user_id_join = options
|
let local_user_id_join = o.local_user.local_user_id().unwrap_or(LocalUserId(-1));
|
||||||
.local_user
|
|
||||||
.local_user_id()
|
|
||||||
.unwrap_or(LocalUserId(-1));
|
|
||||||
|
|
||||||
let mut query = all_joins(comment::table.into_boxed(), options.local_user.person_id());
|
let mut query = all_joins(comment::table.into_boxed(), o.local_user.person_id());
|
||||||
|
|
||||||
if let Some(creator_id) = options.creator_id {
|
if let Some(creator_id) = o.creator_id {
|
||||||
query = query.filter(comment::creator_id.eq(creator_id));
|
query = query.filter(comment::creator_id.eq(creator_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(post_id) = options.post_id {
|
if let Some(post_id) = o.post_id {
|
||||||
query = query.filter(comment::post_id.eq(post_id));
|
query = query.filter(comment::post_id.eq(post_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(parent_path) = options.parent_path.as_ref() {
|
if let Some(parent_path) = o.parent_path.as_ref() {
|
||||||
query = query.filter(comment::path.contained_by(parent_path));
|
query = query.filter(comment::path.contained_by(parent_path));
|
||||||
};
|
};
|
||||||
//filtering out removed and deleted comments from search
|
//filtering out removed and deleted comments from search
|
||||||
if let Some(search_term) = options.search_term {
|
if let Some(search_term) = o.search_term {
|
||||||
query = query.filter(
|
query = query.filter(
|
||||||
comment::content
|
comment::content
|
||||||
.ilike(fuzzy_search(&search_term))
|
.ilike(fuzzy_search(&search_term))
|
||||||
|
@ -170,13 +167,13 @@ fn queries<'a>() -> Queries<
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(community_id) = options.community_id {
|
if let Some(community_id) = o.community_id {
|
||||||
query = query.filter(post::community_id.eq(community_id));
|
query = query.filter(post::community_id.eq(community_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_subscribed = community_actions::followed.is_not_null();
|
let is_subscribed = community_actions::followed.is_not_null();
|
||||||
|
|
||||||
match options.listing_type.unwrap_or_default() {
|
match o.listing_type.unwrap_or_default() {
|
||||||
ListingType::Subscribed => query = query.filter(is_subscribed), /* TODO could be this: and(community_follower::person_id.eq(person_id_join)), */
|
ListingType::Subscribed => query = query.filter(is_subscribed), /* TODO could be this: and(community_follower::person_id.eq(person_id_join)), */
|
||||||
ListingType::Local => {
|
ListingType::Local => {
|
||||||
query = query
|
query = query
|
||||||
|
@ -190,32 +187,30 @@ fn queries<'a>() -> Queries<
|
||||||
}
|
}
|
||||||
|
|
||||||
// If its saved only, then filter, and order by the saved time, not the comment creation time.
|
// If its saved only, then filter, and order by the saved time, not the comment creation time.
|
||||||
if options.saved_only.unwrap_or_default() {
|
if o.saved_only.unwrap_or_default() {
|
||||||
query = query
|
query = query
|
||||||
.filter(comment_actions::saved.is_not_null())
|
.filter(comment_actions::saved.is_not_null())
|
||||||
.then_order_by(comment_actions::saved.desc());
|
.then_order_by(comment_actions::saved.desc());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(my_id) = options.local_user.person_id() {
|
if let Some(my_id) = o.local_user.person_id() {
|
||||||
let not_creator_filter = comment::creator_id.ne(my_id);
|
let not_creator_filter = comment::creator_id.ne(my_id);
|
||||||
if options.liked_only.unwrap_or_default() {
|
if o.liked_only.unwrap_or_default() {
|
||||||
query = query
|
query = query
|
||||||
.filter(not_creator_filter)
|
.filter(not_creator_filter)
|
||||||
.filter(comment_actions::like_score.eq(1));
|
.filter(comment_actions::like_score.eq(1));
|
||||||
} else if options.disliked_only.unwrap_or_default() {
|
} else if o.disliked_only.unwrap_or_default() {
|
||||||
query = query
|
query = query
|
||||||
.filter(not_creator_filter)
|
.filter(not_creator_filter)
|
||||||
.filter(comment_actions::like_score.eq(-1));
|
.filter(comment_actions::like_score.eq(-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !options.local_user.show_bot_accounts() {
|
if !o.local_user.show_bot_accounts() {
|
||||||
query = query.filter(person::bot_account.eq(false));
|
query = query.filter(person::bot_account.eq(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
if options.local_user.is_some()
|
if o.local_user.is_some() && o.listing_type.unwrap_or_default() != ListingType::ModeratorView {
|
||||||
&& options.listing_type.unwrap_or_default() != ListingType::ModeratorView
|
|
||||||
{
|
|
||||||
// Filter out the rows with missing languages
|
// Filter out the rows with missing languages
|
||||||
query = query.filter(exists(
|
query = query.filter(exists(
|
||||||
local_user_language::table.filter(
|
local_user_language::table.filter(
|
||||||
|
@ -232,15 +227,15 @@ fn queries<'a>() -> Queries<
|
||||||
.filter(person_actions::blocked.is_null());
|
.filter(person_actions::blocked.is_null());
|
||||||
};
|
};
|
||||||
|
|
||||||
if !options.local_user.show_nsfw(site) {
|
if !o.local_user.show_nsfw(site) {
|
||||||
query = query
|
query = query
|
||||||
.filter(post::nsfw.eq(false))
|
.filter(post::nsfw.eq(false))
|
||||||
.filter(community::nsfw.eq(false));
|
.filter(community::nsfw.eq(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
query = options.local_user.visible_communities_only(query);
|
query = o.local_user.visible_communities_only(query);
|
||||||
|
|
||||||
if !options.local_user.is_admin() {
|
if !o.local_user.is_admin() {
|
||||||
query = query.filter(
|
query = query.filter(
|
||||||
community::visibility
|
community::visibility
|
||||||
.ne(CommunityVisibility::Private)
|
.ne(CommunityVisibility::Private)
|
||||||
|
@ -249,8 +244,8 @@ fn queries<'a>() -> Queries<
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Max depth given means its a tree fetch
|
// A Max depth given means its a tree fetch
|
||||||
let (limit, offset) = if let Some(max_depth) = options.max_depth {
|
let (limit, offset) = if let Some(max_depth) = o.max_depth {
|
||||||
let depth_limit = if let Some(parent_path) = options.parent_path.as_ref() {
|
let depth_limit = if let Some(parent_path) = o.parent_path.as_ref() {
|
||||||
parent_path.0.split('.').count() as i32 + max_depth
|
parent_path.0.split('.').count() as i32 + max_depth
|
||||||
// Add one because of root "0"
|
// Add one because of root "0"
|
||||||
} else {
|
} else {
|
||||||
|
@ -261,7 +256,7 @@ fn queries<'a>() -> Queries<
|
||||||
|
|
||||||
// only order if filtering by a post id, or parent_path. DOS potential otherwise and max_depth
|
// only order if filtering by a post id, or parent_path. DOS potential otherwise and max_depth
|
||||||
// + !post_id isn't used anyways (afaik)
|
// + !post_id isn't used anyways (afaik)
|
||||||
if options.post_id.is_some() || options.parent_path.is_some() {
|
if o.post_id.is_some() || o.parent_path.is_some() {
|
||||||
// Always order by the parent path first
|
// Always order by the parent path first
|
||||||
query = query.then_order_by(subpath(comment::path, 0, -1));
|
query = query.then_order_by(subpath(comment::path, 0, -1));
|
||||||
}
|
}
|
||||||
|
@ -278,16 +273,16 @@ fn queries<'a>() -> Queries<
|
||||||
// (i64::MAX, 0)
|
// (i64::MAX, 0)
|
||||||
(300, 0)
|
(300, 0)
|
||||||
} else {
|
} else {
|
||||||
// limit_and_offset_unlimited(options.page, options.limit)
|
// limit_and_offset_unlimited(o.page, o.limit)
|
||||||
limit_and_offset(options.page, options.limit)?
|
limit_and_offset(o.page, o.limit)?
|
||||||
};
|
};
|
||||||
|
|
||||||
// distinguished comments should go first when viewing post
|
// distinguished comments should go first when viewing post
|
||||||
if options.post_id.is_some() || options.parent_path.is_some() {
|
if o.post_id.is_some() || o.parent_path.is_some() {
|
||||||
query = query.then_order_by(comment::distinguished.desc());
|
query = query.then_order_by(comment::distinguished.desc());
|
||||||
}
|
}
|
||||||
|
|
||||||
query = match options.sort.unwrap_or(CommentSortType::Hot) {
|
query = match o.sort.unwrap_or(CommentSortType::Hot) {
|
||||||
CommentSortType::Hot => query
|
CommentSortType::Hot => query
|
||||||
.then_order_by(comment_aggregates::hot_rank.desc())
|
.then_order_by(comment_aggregates::hot_rank.desc())
|
||||||
.then_order_by(comment_aggregates::score.desc()),
|
.then_order_by(comment_aggregates::score.desc()),
|
||||||
|
|
|
@ -14,6 +14,8 @@ pub mod local_user_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod post_report_view;
|
pub mod post_report_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
pub mod post_tags_view;
|
||||||
|
#[cfg(feature = "full")]
|
||||||
pub mod post_view;
|
pub mod post_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod private_message_report_view;
|
pub mod private_message_report_view;
|
||||||
|
@ -22,6 +24,8 @@ pub mod private_message_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod registration_application_view;
|
pub mod registration_application_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
pub mod report_combined_view;
|
||||||
|
#[cfg(feature = "full")]
|
||||||
pub mod site_view;
|
pub mod site_view;
|
||||||
pub mod structs;
|
pub mod structs;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::structs::{LocalUserView, PostReportView};
|
use crate::structs::PostReportView;
|
||||||
use diesel::{
|
use diesel::{
|
||||||
pg::Pg,
|
|
||||||
result::Error,
|
result::Error,
|
||||||
BoolExpressionMethods,
|
BoolExpressionMethods,
|
||||||
ExpressionMethods,
|
ExpressionMethods,
|
||||||
|
@ -11,7 +10,7 @@ use diesel::{
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aliases::{self, creator_community_actions},
|
aliases::{self, creator_community_actions},
|
||||||
newtypes::{CommunityId, PersonId, PostId, PostReportId},
|
newtypes::{PersonId, PostReportId},
|
||||||
schema::{
|
schema::{
|
||||||
community,
|
community,
|
||||||
community_actions,
|
community_actions,
|
||||||
|
@ -24,26 +23,22 @@ use lemmy_db_schema::{
|
||||||
post_report,
|
post_report,
|
||||||
},
|
},
|
||||||
source::community::CommunityFollower,
|
source::community::CommunityFollower,
|
||||||
utils::{
|
utils::{actions, actions_alias, functions::coalesce, get_conn, DbPool},
|
||||||
actions,
|
|
||||||
actions_alias,
|
|
||||||
functions::coalesce,
|
|
||||||
get_conn,
|
|
||||||
limit_and_offset,
|
|
||||||
DbConn,
|
|
||||||
DbPool,
|
|
||||||
ListFn,
|
|
||||||
Queries,
|
|
||||||
ReadFn,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fn queries<'a>() -> Queries<
|
impl PostReportView {
|
||||||
impl ReadFn<'a, PostReportView, (PostReportId, PersonId)>,
|
/// returns the PostReportView for the provided report_id
|
||||||
impl ListFn<'a, PostReportView, (PostReportQuery, &'a LocalUserView)>,
|
///
|
||||||
> {
|
/// * `report_id` - the report id to obtain
|
||||||
let all_joins = |query: post_report::BoxedQuery<'a, Pg>, my_person_id: PersonId| {
|
pub async fn read(
|
||||||
query
|
pool: &mut DbPool<'_>,
|
||||||
|
report_id: PostReportId,
|
||||||
|
my_person_id: PersonId,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
|
post_report::table
|
||||||
|
.find(report_id)
|
||||||
.inner_join(post::table)
|
.inner_join(post::table)
|
||||||
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
||||||
.inner_join(person::table.on(post_report::creator_id.eq(person::id)))
|
.inner_join(person::table.on(post_report::creator_id.eq(person::id)))
|
||||||
|
@ -104,322 +99,7 @@ fn queries<'a>() -> Queries<
|
||||||
post_aggregates::all_columns,
|
post_aggregates::all_columns,
|
||||||
aliases::person2.fields(person::all_columns.nullable()),
|
aliases::person2.fields(person::all_columns.nullable()),
|
||||||
))
|
))
|
||||||
};
|
.first(conn)
|
||||||
|
.await
|
||||||
let read = move |mut conn: DbConn<'a>, (report_id, my_person_id): (PostReportId, PersonId)| async move {
|
|
||||||
all_joins(
|
|
||||||
post_report::table.find(report_id).into_boxed(),
|
|
||||||
my_person_id,
|
|
||||||
)
|
|
||||||
.first(&mut conn)
|
|
||||||
.await
|
|
||||||
};
|
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>, (options, user): (PostReportQuery, &'a LocalUserView)| async move {
|
|
||||||
let mut query = all_joins(post_report::table.into_boxed(), user.person.id);
|
|
||||||
|
|
||||||
if let Some(community_id) = options.community_id {
|
|
||||||
query = query.filter(post::community_id.eq(community_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(post_id) = options.post_id {
|
|
||||||
query = query.filter(post::id.eq(post_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
// If viewing all reports, order by newest, but if viewing unresolved only, show the oldest
|
|
||||||
// first (FIFO)
|
|
||||||
if options.unresolved_only {
|
|
||||||
query = query
|
|
||||||
.filter(post_report::resolved.eq(false))
|
|
||||||
.order_by(post_report::published.asc());
|
|
||||||
} else {
|
|
||||||
query = query.order_by(post_report::published.desc());
|
|
||||||
}
|
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
|
||||||
|
|
||||||
query = query.limit(limit).offset(offset);
|
|
||||||
|
|
||||||
// If its not an admin, get only the ones you mod
|
|
||||||
if !user.local_user.admin {
|
|
||||||
query = query.filter(community_actions::became_moderator.is_not_null());
|
|
||||||
}
|
|
||||||
|
|
||||||
query.load::<PostReportView>(&mut conn).await
|
|
||||||
};
|
|
||||||
|
|
||||||
Queries::new(read, list)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PostReportView {
|
|
||||||
/// returns the PostReportView for the provided report_id
|
|
||||||
///
|
|
||||||
/// * `report_id` - the report id to obtain
|
|
||||||
pub async fn read(
|
|
||||||
pool: &mut DbPool<'_>,
|
|
||||||
report_id: PostReportId,
|
|
||||||
my_person_id: PersonId,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
queries().read(pool, (report_id, my_person_id)).await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// returns the current unresolved post report count for the communities you mod
|
|
||||||
pub async fn get_report_count(
|
|
||||||
pool: &mut DbPool<'_>,
|
|
||||||
my_person_id: PersonId,
|
|
||||||
admin: bool,
|
|
||||||
community_id: Option<CommunityId>,
|
|
||||||
) -> Result<i64, Error> {
|
|
||||||
use diesel::dsl::count;
|
|
||||||
let conn = &mut get_conn(pool).await?;
|
|
||||||
let mut query = post_report::table
|
|
||||||
.inner_join(post::table)
|
|
||||||
.filter(post_report::resolved.eq(false))
|
|
||||||
.into_boxed();
|
|
||||||
|
|
||||||
if let Some(community_id) = community_id {
|
|
||||||
query = query.filter(post::community_id.eq(community_id))
|
|
||||||
}
|
|
||||||
|
|
||||||
// If its not an admin, get only the ones you mod
|
|
||||||
if !admin {
|
|
||||||
query
|
|
||||||
.inner_join(
|
|
||||||
community_actions::table.on(
|
|
||||||
community_actions::community_id
|
|
||||||
.eq(post::community_id)
|
|
||||||
.and(community_actions::person_id.eq(my_person_id))
|
|
||||||
.and(community_actions::became_moderator.is_not_null()),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.select(count(post_report::id))
|
|
||||||
.first::<i64>(conn)
|
|
||||||
.await
|
|
||||||
} else {
|
|
||||||
query
|
|
||||||
.select(count(post_report::id))
|
|
||||||
.first::<i64>(conn)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct PostReportQuery {
|
|
||||||
pub community_id: Option<CommunityId>,
|
|
||||||
pub post_id: Option<PostId>,
|
|
||||||
pub page: Option<i64>,
|
|
||||||
pub limit: Option<i64>,
|
|
||||||
pub unresolved_only: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PostReportQuery {
|
|
||||||
pub async fn list(
|
|
||||||
self,
|
|
||||||
pool: &mut DbPool<'_>,
|
|
||||||
user: &LocalUserView,
|
|
||||||
) -> Result<Vec<PostReportView>, Error> {
|
|
||||||
queries().list(pool, (self, user)).await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[expect(clippy::indexing_slicing)]
|
|
||||||
mod tests {
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
post_report_view::{PostReportQuery, PostReportView},
|
|
||||||
structs::LocalUserView,
|
|
||||||
};
|
|
||||||
use lemmy_db_schema::{
|
|
||||||
aggregates::structs::PostAggregates,
|
|
||||||
assert_length,
|
|
||||||
source::{
|
|
||||||
community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm},
|
|
||||||
instance::Instance,
|
|
||||||
local_user::{LocalUser, LocalUserInsertForm},
|
|
||||||
local_user_vote_display_mode::LocalUserVoteDisplayMode,
|
|
||||||
person::{Person, PersonInsertForm},
|
|
||||||
post::{Post, PostInsertForm},
|
|
||||||
post_report::{PostReport, PostReportForm},
|
|
||||||
},
|
|
||||||
traits::{Crud, Joinable, Reportable},
|
|
||||||
utils::build_db_pool_for_tests,
|
|
||||||
};
|
|
||||||
use lemmy_utils::error::LemmyResult;
|
|
||||||
use pretty_assertions::assert_eq;
|
|
||||||
use serial_test::serial;
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
#[serial]
|
|
||||||
async fn test_crud() -> LemmyResult<()> {
|
|
||||||
let pool = &build_db_pool_for_tests();
|
|
||||||
let pool = &mut pool.into();
|
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
|
|
||||||
|
|
||||||
let new_person = PersonInsertForm::test_form(inserted_instance.id, "timmy_prv");
|
|
||||||
|
|
||||||
let inserted_timmy = Person::create(pool, &new_person).await?;
|
|
||||||
|
|
||||||
let new_local_user = LocalUserInsertForm::test_form(inserted_timmy.id);
|
|
||||||
let timmy_local_user = LocalUser::create(pool, &new_local_user, vec![]).await?;
|
|
||||||
let timmy_view = LocalUserView {
|
|
||||||
local_user: timmy_local_user,
|
|
||||||
local_user_vote_display_mode: LocalUserVoteDisplayMode::default(),
|
|
||||||
person: inserted_timmy.clone(),
|
|
||||||
counts: Default::default(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let new_person_2 = PersonInsertForm::test_form(inserted_instance.id, "sara_prv");
|
|
||||||
|
|
||||||
let inserted_sara = Person::create(pool, &new_person_2).await?;
|
|
||||||
|
|
||||||
// Add a third person, since new ppl can only report something once.
|
|
||||||
let new_person_3 = PersonInsertForm::test_form(inserted_instance.id, "jessica_prv");
|
|
||||||
|
|
||||||
let inserted_jessica = Person::create(pool, &new_person_3).await?;
|
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::new(
|
|
||||||
inserted_instance.id,
|
|
||||||
"test community prv".to_string(),
|
|
||||||
"nada".to_owned(),
|
|
||||||
"pubkey".to_string(),
|
|
||||||
);
|
|
||||||
let inserted_community = Community::create(pool, &new_community).await?;
|
|
||||||
|
|
||||||
// Make timmy a mod
|
|
||||||
let timmy_moderator_form = CommunityModeratorForm {
|
|
||||||
community_id: inserted_community.id,
|
|
||||||
person_id: inserted_timmy.id,
|
|
||||||
};
|
|
||||||
|
|
||||||
let _inserted_moderator = CommunityModerator::join(pool, &timmy_moderator_form).await?;
|
|
||||||
|
|
||||||
let new_post = PostInsertForm::new(
|
|
||||||
"A test post crv".into(),
|
|
||||||
inserted_timmy.id,
|
|
||||||
inserted_community.id,
|
|
||||||
);
|
|
||||||
let inserted_post = Post::create(pool, &new_post).await?;
|
|
||||||
|
|
||||||
// sara reports
|
|
||||||
let sara_report_form = PostReportForm {
|
|
||||||
creator_id: inserted_sara.id,
|
|
||||||
post_id: inserted_post.id,
|
|
||||||
original_post_name: "Orig post".into(),
|
|
||||||
original_post_url: None,
|
|
||||||
original_post_body: None,
|
|
||||||
reason: "from sara".into(),
|
|
||||||
};
|
|
||||||
|
|
||||||
PostReport::report(pool, &sara_report_form).await?;
|
|
||||||
|
|
||||||
let new_post_2 = PostInsertForm::new(
|
|
||||||
"A test post crv 2".into(),
|
|
||||||
inserted_timmy.id,
|
|
||||||
inserted_community.id,
|
|
||||||
);
|
|
||||||
let inserted_post_2 = Post::create(pool, &new_post_2).await?;
|
|
||||||
|
|
||||||
// jessica reports
|
|
||||||
let jessica_report_form = PostReportForm {
|
|
||||||
creator_id: inserted_jessica.id,
|
|
||||||
post_id: inserted_post_2.id,
|
|
||||||
original_post_name: "Orig post".into(),
|
|
||||||
original_post_url: None,
|
|
||||||
original_post_body: None,
|
|
||||||
reason: "from jessica".into(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let inserted_jessica_report = PostReport::report(pool, &jessica_report_form).await?;
|
|
||||||
|
|
||||||
let read_jessica_report_view =
|
|
||||||
PostReportView::read(pool, inserted_jessica_report.id, inserted_timmy.id).await?;
|
|
||||||
|
|
||||||
// Make sure the triggers are reading the aggregates correctly.
|
|
||||||
let agg_1 = PostAggregates::read(pool, inserted_post.id).await?;
|
|
||||||
let agg_2 = PostAggregates::read(pool, inserted_post_2.id).await?;
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
read_jessica_report_view.post_report,
|
|
||||||
inserted_jessica_report
|
|
||||||
);
|
|
||||||
assert_eq!(read_jessica_report_view.post, inserted_post_2);
|
|
||||||
assert_eq!(read_jessica_report_view.community.id, inserted_community.id);
|
|
||||||
assert_eq!(read_jessica_report_view.creator.id, inserted_jessica.id);
|
|
||||||
assert_eq!(read_jessica_report_view.post_creator.id, inserted_timmy.id);
|
|
||||||
assert_eq!(read_jessica_report_view.my_vote, None);
|
|
||||||
assert_eq!(read_jessica_report_view.resolver, None);
|
|
||||||
assert_eq!(agg_1.report_count, 1);
|
|
||||||
assert_eq!(agg_1.unresolved_report_count, 1);
|
|
||||||
assert_eq!(agg_2.report_count, 1);
|
|
||||||
assert_eq!(agg_2.unresolved_report_count, 1);
|
|
||||||
|
|
||||||
// Do a batch read of timmys reports
|
|
||||||
let reports = PostReportQuery::default().list(pool, &timmy_view).await?;
|
|
||||||
|
|
||||||
assert_eq!(reports[1].creator.id, inserted_sara.id);
|
|
||||||
assert_eq!(reports[0].creator.id, inserted_jessica.id);
|
|
||||||
|
|
||||||
// Make sure the counts are correct
|
|
||||||
let report_count =
|
|
||||||
PostReportView::get_report_count(pool, inserted_timmy.id, false, None).await?;
|
|
||||||
assert_eq!(2, report_count);
|
|
||||||
|
|
||||||
// Pretend the post was removed, and resolve all reports for that object.
|
|
||||||
// This is called manually in the API for post removals
|
|
||||||
PostReport::resolve_all_for_object(pool, inserted_jessica_report.post_id, inserted_timmy.id)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let read_jessica_report_view_after_resolve =
|
|
||||||
PostReportView::read(pool, inserted_jessica_report.id, inserted_timmy.id).await?;
|
|
||||||
assert!(read_jessica_report_view_after_resolve.post_report.resolved);
|
|
||||||
assert_eq!(
|
|
||||||
read_jessica_report_view_after_resolve
|
|
||||||
.post_report
|
|
||||||
.resolver_id,
|
|
||||||
Some(inserted_timmy.id)
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
read_jessica_report_view_after_resolve
|
|
||||||
.resolver
|
|
||||||
.map(|r| r.id),
|
|
||||||
Some(inserted_timmy.id)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Make sure the unresolved_post report got decremented in the trigger
|
|
||||||
let agg_2 = PostAggregates::read(pool, inserted_post_2.id).await?;
|
|
||||||
assert_eq!(agg_2.report_count, 1);
|
|
||||||
assert_eq!(agg_2.unresolved_report_count, 0);
|
|
||||||
|
|
||||||
// Make sure the other unresolved report isn't changed
|
|
||||||
let agg_1 = PostAggregates::read(pool, inserted_post.id).await?;
|
|
||||||
assert_eq!(agg_1.report_count, 1);
|
|
||||||
assert_eq!(agg_1.unresolved_report_count, 1);
|
|
||||||
|
|
||||||
// Do a batch read of timmys reports
|
|
||||||
// It should only show saras, which is unresolved
|
|
||||||
let reports_after_resolve = PostReportQuery {
|
|
||||||
unresolved_only: true,
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
.list(pool, &timmy_view)
|
|
||||||
.await?;
|
|
||||||
assert_length!(1, reports_after_resolve);
|
|
||||||
assert_eq!(reports_after_resolve[0].creator.id, inserted_sara.id);
|
|
||||||
|
|
||||||
// Make sure the counts are correct
|
|
||||||
let report_count_after_resolved =
|
|
||||||
PostReportView::get_report_count(pool, inserted_timmy.id, false, None).await?;
|
|
||||||
assert_eq!(1, report_count_after_resolved);
|
|
||||||
|
|
||||||
Person::delete(pool, inserted_timmy.id).await?;
|
|
||||||
Person::delete(pool, inserted_sara.id).await?;
|
|
||||||
Person::delete(pool, inserted_jessica.id).await?;
|
|
||||||
Community::delete(pool, inserted_community.id).await?;
|
|
||||||
Instance::delete(pool, inserted_instance.id).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
30
crates/db_views/src/post_tags_view.rs
Normal file
30
crates/db_views/src/post_tags_view.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
//! see post_view.rs for the reason for this json decoding
|
||||||
|
use crate::structs::PostTags;
|
||||||
|
use diesel::{
|
||||||
|
deserialize::FromSql,
|
||||||
|
pg::{Pg, PgValue},
|
||||||
|
serialize::ToSql,
|
||||||
|
sql_types::{self, Nullable},
|
||||||
|
};
|
||||||
|
|
||||||
|
impl FromSql<Nullable<sql_types::Json>, Pg> for PostTags {
|
||||||
|
fn from_sql(bytes: PgValue) -> diesel::deserialize::Result<Self> {
|
||||||
|
let value = <serde_json::Value as FromSql<sql_types::Json, Pg>>::from_sql(bytes)?;
|
||||||
|
Ok(serde_json::from_value::<PostTags>(value)?)
|
||||||
|
}
|
||||||
|
fn from_nullable_sql(
|
||||||
|
bytes: Option<<Pg as diesel::backend::Backend>::RawValue<'_>>,
|
||||||
|
) -> diesel::deserialize::Result<Self> {
|
||||||
|
match bytes {
|
||||||
|
Some(bytes) => Self::from_sql(bytes),
|
||||||
|
None => Ok(Self { tags: vec![] }),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToSql<Nullable<sql_types::Json>, Pg> for PostTags {
|
||||||
|
fn to_sql(&self, out: &mut diesel::serialize::Output<Pg>) -> diesel::serialize::Result {
|
||||||
|
let value = serde_json::to_value(self)?;
|
||||||
|
<serde_json::Value as ToSql<sql_types::Json, Pg>>::to_sql(&value, &mut out.reborrow())
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,76 +1,13 @@
|
||||||
use crate::structs::PrivateMessageReportView;
|
use crate::structs::PrivateMessageReportView;
|
||||||
use diesel::{
|
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, NullableExpressionMethods, QueryDsl};
|
||||||
pg::Pg,
|
|
||||||
result::Error,
|
|
||||||
ExpressionMethods,
|
|
||||||
JoinOnDsl,
|
|
||||||
NullableExpressionMethods,
|
|
||||||
QueryDsl,
|
|
||||||
};
|
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aliases,
|
aliases,
|
||||||
newtypes::PrivateMessageReportId,
|
newtypes::PrivateMessageReportId,
|
||||||
schema::{person, private_message, private_message_report},
|
schema::{person, private_message, private_message_report},
|
||||||
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
fn queries<'a>() -> Queries<
|
|
||||||
impl ReadFn<'a, PrivateMessageReportView, PrivateMessageReportId>,
|
|
||||||
impl ListFn<'a, PrivateMessageReportView, PrivateMessageReportQuery>,
|
|
||||||
> {
|
|
||||||
let all_joins =
|
|
||||||
|query: private_message_report::BoxedQuery<'a, Pg>| {
|
|
||||||
query
|
|
||||||
.inner_join(private_message::table)
|
|
||||||
.inner_join(person::table.on(private_message::creator_id.eq(person::id)))
|
|
||||||
.inner_join(
|
|
||||||
aliases::person1
|
|
||||||
.on(private_message_report::creator_id.eq(aliases::person1.field(person::id))),
|
|
||||||
)
|
|
||||||
.left_join(aliases::person2.on(
|
|
||||||
private_message_report::resolver_id.eq(aliases::person2.field(person::id).nullable()),
|
|
||||||
))
|
|
||||||
.select((
|
|
||||||
private_message_report::all_columns,
|
|
||||||
private_message::all_columns,
|
|
||||||
person::all_columns,
|
|
||||||
aliases::person1.fields(person::all_columns),
|
|
||||||
aliases::person2.fields(person::all_columns).nullable(),
|
|
||||||
))
|
|
||||||
};
|
|
||||||
|
|
||||||
let read = move |mut conn: DbConn<'a>, report_id: PrivateMessageReportId| async move {
|
|
||||||
all_joins(private_message_report::table.find(report_id).into_boxed())
|
|
||||||
.first(&mut conn)
|
|
||||||
.await
|
|
||||||
};
|
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>, options: PrivateMessageReportQuery| async move {
|
|
||||||
let mut query = all_joins(private_message_report::table.into_boxed());
|
|
||||||
|
|
||||||
// If viewing all reports, order by newest, but if viewing unresolved only, show the oldest
|
|
||||||
// first (FIFO)
|
|
||||||
if options.unresolved_only {
|
|
||||||
query = query
|
|
||||||
.filter(private_message_report::resolved.eq(false))
|
|
||||||
.order_by(private_message_report::published.asc());
|
|
||||||
} else {
|
|
||||||
query = query.order_by(private_message_report::published.desc());
|
|
||||||
}
|
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
|
||||||
|
|
||||||
query
|
|
||||||
.limit(limit)
|
|
||||||
.offset(offset)
|
|
||||||
.load::<PrivateMessageReportView>(&mut conn)
|
|
||||||
.await
|
|
||||||
};
|
|
||||||
|
|
||||||
Queries::new(read, list)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PrivateMessageReportView {
|
impl PrivateMessageReportView {
|
||||||
/// returns the PrivateMessageReportView for the provided report_id
|
/// returns the PrivateMessageReportView for the provided report_id
|
||||||
///
|
///
|
||||||
|
@ -79,118 +16,28 @@ impl PrivateMessageReportView {
|
||||||
pool: &mut DbPool<'_>,
|
pool: &mut DbPool<'_>,
|
||||||
report_id: PrivateMessageReportId,
|
report_id: PrivateMessageReportId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
queries().read(pool, report_id).await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the current unresolved post report count for the communities you mod
|
|
||||||
pub async fn get_report_count(pool: &mut DbPool<'_>) -> Result<i64, Error> {
|
|
||||||
use diesel::dsl::count;
|
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
private_message_report::table
|
private_message_report::table
|
||||||
|
.find(report_id)
|
||||||
.inner_join(private_message::table)
|
.inner_join(private_message::table)
|
||||||
.filter(private_message_report::resolved.eq(false))
|
.inner_join(person::table.on(private_message::creator_id.eq(person::id)))
|
||||||
.into_boxed()
|
.inner_join(
|
||||||
.select(count(private_message_report::id))
|
aliases::person1
|
||||||
.first::<i64>(conn)
|
.on(private_message_report::creator_id.eq(aliases::person1.field(person::id))),
|
||||||
|
)
|
||||||
|
.left_join(
|
||||||
|
aliases::person2.on(
|
||||||
|
private_message_report::resolver_id.eq(aliases::person2.field(person::id).nullable()),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.select((
|
||||||
|
private_message_report::all_columns,
|
||||||
|
private_message::all_columns,
|
||||||
|
person::all_columns,
|
||||||
|
aliases::person1.fields(person::all_columns),
|
||||||
|
aliases::person2.fields(person::all_columns).nullable(),
|
||||||
|
))
|
||||||
|
.first(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct PrivateMessageReportQuery {
|
|
||||||
pub page: Option<i64>,
|
|
||||||
pub limit: Option<i64>,
|
|
||||||
pub unresolved_only: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PrivateMessageReportQuery {
|
|
||||||
pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<PrivateMessageReportView>, Error> {
|
|
||||||
queries().list(pool, self).await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[expect(clippy::indexing_slicing)]
|
|
||||||
mod tests {
|
|
||||||
|
|
||||||
use crate::private_message_report_view::PrivateMessageReportQuery;
|
|
||||||
use lemmy_db_schema::{
|
|
||||||
assert_length,
|
|
||||||
source::{
|
|
||||||
instance::Instance,
|
|
||||||
person::{Person, PersonInsertForm},
|
|
||||||
private_message::{PrivateMessage, PrivateMessageInsertForm},
|
|
||||||
private_message_report::{PrivateMessageReport, PrivateMessageReportForm},
|
|
||||||
},
|
|
||||||
traits::{Crud, Reportable},
|
|
||||||
utils::build_db_pool_for_tests,
|
|
||||||
};
|
|
||||||
use lemmy_utils::error::LemmyResult;
|
|
||||||
use pretty_assertions::assert_eq;
|
|
||||||
use serial_test::serial;
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
#[serial]
|
|
||||||
async fn test_crud() -> LemmyResult<()> {
|
|
||||||
let pool = &build_db_pool_for_tests();
|
|
||||||
let pool = &mut pool.into();
|
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
|
|
||||||
|
|
||||||
let new_person_1 = PersonInsertForm::test_form(inserted_instance.id, "timmy_mrv");
|
|
||||||
let inserted_timmy = Person::create(pool, &new_person_1).await?;
|
|
||||||
|
|
||||||
let new_person_2 = PersonInsertForm::test_form(inserted_instance.id, "jessica_mrv");
|
|
||||||
let inserted_jessica = Person::create(pool, &new_person_2).await?;
|
|
||||||
|
|
||||||
// timmy sends private message to jessica
|
|
||||||
let pm_form = PrivateMessageInsertForm::new(
|
|
||||||
inserted_timmy.id,
|
|
||||||
inserted_jessica.id,
|
|
||||||
"something offensive".to_string(),
|
|
||||||
);
|
|
||||||
let pm = PrivateMessage::create(pool, &pm_form).await?;
|
|
||||||
|
|
||||||
// jessica reports private message
|
|
||||||
let pm_report_form = PrivateMessageReportForm {
|
|
||||||
creator_id: inserted_jessica.id,
|
|
||||||
original_pm_text: pm.content.clone(),
|
|
||||||
private_message_id: pm.id,
|
|
||||||
reason: "its offensive".to_string(),
|
|
||||||
};
|
|
||||||
let pm_report = PrivateMessageReport::report(pool, &pm_report_form).await?;
|
|
||||||
|
|
||||||
let reports = PrivateMessageReportQuery::default().list(pool).await?;
|
|
||||||
assert_length!(1, reports);
|
|
||||||
assert!(!reports[0].private_message_report.resolved);
|
|
||||||
assert_eq!(inserted_timmy.name, reports[0].private_message_creator.name);
|
|
||||||
assert_eq!(inserted_jessica.name, reports[0].creator.name);
|
|
||||||
assert_eq!(pm_report.reason, reports[0].private_message_report.reason);
|
|
||||||
assert_eq!(pm.content, reports[0].private_message.content);
|
|
||||||
|
|
||||||
let new_person_3 = PersonInsertForm::test_form(inserted_instance.id, "admin_mrv");
|
|
||||||
let inserted_admin = Person::create(pool, &new_person_3).await?;
|
|
||||||
|
|
||||||
// admin resolves the report (after taking appropriate action)
|
|
||||||
PrivateMessageReport::resolve(pool, pm_report.id, inserted_admin.id).await?;
|
|
||||||
|
|
||||||
let reports = PrivateMessageReportQuery {
|
|
||||||
unresolved_only: (false),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
.list(pool)
|
|
||||||
.await?;
|
|
||||||
assert_length!(1, reports);
|
|
||||||
assert!(reports[0].private_message_report.resolved);
|
|
||||||
assert!(reports[0].resolver.is_some());
|
|
||||||
assert_eq!(
|
|
||||||
Some(&inserted_admin.name),
|
|
||||||
reports[0].resolver.as_ref().map(|r| &r.name)
|
|
||||||
);
|
|
||||||
|
|
||||||
Instance::delete(pool, inserted_instance.id).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -53,8 +53,7 @@ fn queries<'a>() -> Queries<
|
||||||
.await
|
.await
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>,
|
let list = move |mut conn: DbConn<'a>, (o, recipient_id): (PrivateMessageQuery, PersonId)| async move {
|
||||||
(options, recipient_id): (PrivateMessageQuery, PersonId)| async move {
|
|
||||||
let mut query = all_joins(private_message::table.into_boxed())
|
let mut query = all_joins(private_message::table.into_boxed())
|
||||||
.select(selection)
|
.select(selection)
|
||||||
// Dont show replies from blocked users
|
// Dont show replies from blocked users
|
||||||
|
@ -63,9 +62,9 @@ fn queries<'a>() -> Queries<
|
||||||
.filter(instance_actions::blocked.is_null());
|
.filter(instance_actions::blocked.is_null());
|
||||||
|
|
||||||
// If its unread, I only want the ones to me
|
// If its unread, I only want the ones to me
|
||||||
if options.unread_only {
|
if o.unread_only {
|
||||||
query = query.filter(private_message::read.eq(false));
|
query = query.filter(private_message::read.eq(false));
|
||||||
if let Some(i) = options.creator_id {
|
if let Some(i) = o.creator_id {
|
||||||
query = query.filter(private_message::creator_id.eq(i))
|
query = query.filter(private_message::creator_id.eq(i))
|
||||||
}
|
}
|
||||||
query = query.filter(private_message::recipient_id.eq(recipient_id));
|
query = query.filter(private_message::recipient_id.eq(recipient_id));
|
||||||
|
@ -77,7 +76,7 @@ fn queries<'a>() -> Queries<
|
||||||
.eq(recipient_id)
|
.eq(recipient_id)
|
||||||
.or(private_message::creator_id.eq(recipient_id)),
|
.or(private_message::creator_id.eq(recipient_id)),
|
||||||
);
|
);
|
||||||
if let Some(i) = options.creator_id {
|
if let Some(i) = o.creator_id {
|
||||||
query = query.filter(
|
query = query.filter(
|
||||||
private_message::creator_id
|
private_message::creator_id
|
||||||
.eq(i)
|
.eq(i)
|
||||||
|
@ -86,7 +85,7 @@ fn queries<'a>() -> Queries<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
let (limit, offset) = limit_and_offset(o.page, o.limit)?;
|
||||||
|
|
||||||
query = query
|
query = query
|
||||||
.filter(private_message::deleted.eq(false))
|
.filter(private_message::deleted.eq(false))
|
||||||
|
|
|
@ -53,12 +53,12 @@ fn queries<'a>() -> Queries<
|
||||||
query.first(&mut conn).await
|
query.first(&mut conn).await
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>, options: RegistrationApplicationQuery| async move {
|
let list = move |mut conn: DbConn<'a>, o: RegistrationApplicationQuery| async move {
|
||||||
let mut query = all_joins(registration_application::table.into_boxed());
|
let mut query = all_joins(registration_application::table.into_boxed());
|
||||||
|
|
||||||
// If viewing all applications, order by newest, but if viewing unresolved only, show the oldest
|
// If viewing all applications, order by newest, but if viewing unresolved only, show the oldest
|
||||||
// first (FIFO)
|
// first (FIFO)
|
||||||
if options.unread_only {
|
if o.unread_only {
|
||||||
query = query
|
query = query
|
||||||
.filter(registration_application::admin_id.is_null())
|
.filter(registration_application::admin_id.is_null())
|
||||||
.order_by(registration_application::published.asc());
|
.order_by(registration_application::published.asc());
|
||||||
|
@ -66,11 +66,11 @@ fn queries<'a>() -> Queries<
|
||||||
query = query.order_by(registration_application::published.desc());
|
query = query.order_by(registration_application::published.desc());
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.verified_email_only {
|
if o.verified_email_only {
|
||||||
query = query.filter(local_user::email_verified.eq(true))
|
query = query.filter(local_user::email_verified.eq(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
let (limit, offset) = limit_and_offset(o.page, o.limit)?;
|
||||||
|
|
||||||
query = query.limit(limit).offset(offset);
|
query = query.limit(limit).offset(offset);
|
||||||
|
|
||||||
|
|
967
crates/db_views/src/report_combined_view.rs
Normal file
967
crates/db_views/src/report_combined_view.rs
Normal file
|
@ -0,0 +1,967 @@
|
||||||
|
use crate::structs::{
|
||||||
|
CommentReportView,
|
||||||
|
LocalUserView,
|
||||||
|
PostReportView,
|
||||||
|
PrivateMessageReportView,
|
||||||
|
ReportCombinedPaginationCursor,
|
||||||
|
ReportCombinedView,
|
||||||
|
ReportCombinedViewInternal,
|
||||||
|
};
|
||||||
|
use diesel::{
|
||||||
|
result::Error,
|
||||||
|
BoolExpressionMethods,
|
||||||
|
ExpressionMethods,
|
||||||
|
JoinOnDsl,
|
||||||
|
NullableExpressionMethods,
|
||||||
|
PgExpressionMethods,
|
||||||
|
QueryDsl,
|
||||||
|
SelectableHelper,
|
||||||
|
};
|
||||||
|
use diesel_async::RunQueryDsl;
|
||||||
|
use i_love_jesus::PaginatedQueryBuilder;
|
||||||
|
use lemmy_db_schema::{
|
||||||
|
aliases::{self, creator_community_actions},
|
||||||
|
newtypes::CommunityId,
|
||||||
|
schema::{
|
||||||
|
comment,
|
||||||
|
comment_actions,
|
||||||
|
comment_aggregates,
|
||||||
|
comment_report,
|
||||||
|
community,
|
||||||
|
community_actions,
|
||||||
|
local_user,
|
||||||
|
person,
|
||||||
|
person_actions,
|
||||||
|
post,
|
||||||
|
post_actions,
|
||||||
|
post_aggregates,
|
||||||
|
post_report,
|
||||||
|
private_message,
|
||||||
|
private_message_report,
|
||||||
|
report_combined,
|
||||||
|
},
|
||||||
|
source::{
|
||||||
|
combined::report::{report_combined_keys as key, ReportCombined},
|
||||||
|
community::CommunityFollower,
|
||||||
|
},
|
||||||
|
utils::{actions, actions_alias, functions::coalesce, get_conn, DbPool, ReverseTimestampKey},
|
||||||
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
|
impl ReportCombinedViewInternal {
|
||||||
|
/// returns the current unresolved report count for the communities you mod
|
||||||
|
pub async fn get_report_count(
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
user: &LocalUserView,
|
||||||
|
community_id: Option<CommunityId>,
|
||||||
|
) -> Result<i64, Error> {
|
||||||
|
use diesel::dsl::count;
|
||||||
|
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
let my_person_id = user.local_user.person_id;
|
||||||
|
|
||||||
|
let mut query = report_combined::table
|
||||||
|
.left_join(post_report::table)
|
||||||
|
.left_join(comment_report::table)
|
||||||
|
.left_join(private_message_report::table)
|
||||||
|
// Need to join to comment and post to get the community
|
||||||
|
.left_join(comment::table.on(comment_report::comment_id.eq(comment::id)))
|
||||||
|
// The post
|
||||||
|
.left_join(
|
||||||
|
post::table.on(
|
||||||
|
post_report::post_id
|
||||||
|
.eq(post::id)
|
||||||
|
.or(comment::post_id.eq(post::id)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.left_join(community::table.on(post::community_id.eq(community::id)))
|
||||||
|
.left_join(actions(
|
||||||
|
community_actions::table,
|
||||||
|
Some(my_person_id),
|
||||||
|
post::community_id,
|
||||||
|
))
|
||||||
|
.filter(
|
||||||
|
post_report::resolved
|
||||||
|
.or(comment_report::resolved)
|
||||||
|
.or(private_message_report::resolved)
|
||||||
|
.is_distinct_from(true),
|
||||||
|
)
|
||||||
|
.into_boxed();
|
||||||
|
|
||||||
|
if let Some(community_id) = community_id {
|
||||||
|
query = query.filter(post::community_id.eq(community_id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// If its not an admin, get only the ones you mod
|
||||||
|
if !user.local_user.admin {
|
||||||
|
query = query.filter(community_actions::became_moderator.is_not_null());
|
||||||
|
}
|
||||||
|
|
||||||
|
query
|
||||||
|
.select(count(report_combined::id))
|
||||||
|
.first::<i64>(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReportCombinedPaginationCursor {
|
||||||
|
// get cursor for page that starts immediately after the given post
|
||||||
|
pub fn after_post(view: &ReportCombinedView) -> ReportCombinedPaginationCursor {
|
||||||
|
let (prefix, id) = match view {
|
||||||
|
ReportCombinedView::Comment(v) => ('C', v.comment_report.id.0),
|
||||||
|
ReportCombinedView::Post(v) => ('P', v.post_report.id.0),
|
||||||
|
ReportCombinedView::PrivateMessage(v) => ('M', v.private_message_report.id.0),
|
||||||
|
};
|
||||||
|
// hex encoding to prevent ossification
|
||||||
|
ReportCombinedPaginationCursor(format!("{prefix}{id:x}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn read(&self, pool: &mut DbPool<'_>) -> Result<PaginationCursorData, Error> {
|
||||||
|
let err_msg = || Error::QueryBuilderError("Could not parse pagination token".into());
|
||||||
|
let mut query = report_combined::table
|
||||||
|
.select(ReportCombined::as_select())
|
||||||
|
.into_boxed();
|
||||||
|
let (prefix, id_str) = self.0.split_at_checked(1).ok_or_else(err_msg)?;
|
||||||
|
let id = i32::from_str_radix(id_str, 16).map_err(|_err| err_msg())?;
|
||||||
|
query = match prefix {
|
||||||
|
"C" => query.filter(report_combined::comment_report_id.eq(id)),
|
||||||
|
"P" => query.filter(report_combined::post_report_id.eq(id)),
|
||||||
|
"M" => query.filter(report_combined::private_message_report_id.eq(id)),
|
||||||
|
_ => return Err(err_msg()),
|
||||||
|
};
|
||||||
|
let token = query.first(&mut get_conn(pool).await?).await?;
|
||||||
|
|
||||||
|
Ok(PaginationCursorData(token))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct PaginationCursorData(ReportCombined);
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct ReportCombinedQuery {
|
||||||
|
pub community_id: Option<CommunityId>,
|
||||||
|
pub unresolved_only: Option<bool>,
|
||||||
|
pub page_after: Option<PaginationCursorData>,
|
||||||
|
pub page_back: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReportCombinedQuery {
|
||||||
|
pub async fn list(
|
||||||
|
self,
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
user: &LocalUserView,
|
||||||
|
) -> LemmyResult<Vec<ReportCombinedView>> {
|
||||||
|
let my_person_id = user.local_user.person_id;
|
||||||
|
let item_creator = aliases::person1.field(person::id);
|
||||||
|
|
||||||
|
let resolver = aliases::person2.field(person::id).nullable();
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
|
// Notes: since the post_report_id and comment_report_id are optional columns,
|
||||||
|
// many joins must use an OR condition.
|
||||||
|
// For example, the report creator must be the person table joined to either:
|
||||||
|
// - post_report.creator_id
|
||||||
|
// - comment_report.creator_id
|
||||||
|
let mut query = report_combined::table
|
||||||
|
.left_join(post_report::table)
|
||||||
|
.left_join(comment_report::table)
|
||||||
|
.left_join(private_message_report::table)
|
||||||
|
// The report creator
|
||||||
|
.inner_join(
|
||||||
|
person::table.on(
|
||||||
|
post_report::creator_id
|
||||||
|
.eq(person::id)
|
||||||
|
.or(comment_report::creator_id.eq(person::id))
|
||||||
|
.or(private_message_report::creator_id.eq(person::id)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
// The comment
|
||||||
|
.left_join(comment::table.on(comment_report::comment_id.eq(comment::id)))
|
||||||
|
// The private message
|
||||||
|
.left_join(
|
||||||
|
private_message::table
|
||||||
|
.on(private_message_report::private_message_id.eq(private_message::id)),
|
||||||
|
)
|
||||||
|
// The post
|
||||||
|
.left_join(
|
||||||
|
post::table.on(
|
||||||
|
post_report::post_id
|
||||||
|
.eq(post::id)
|
||||||
|
.or(comment::post_id.eq(post::id)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
// The item creator (`item_creator` is the id of this person)
|
||||||
|
.inner_join(
|
||||||
|
aliases::person1.on(
|
||||||
|
post::creator_id
|
||||||
|
.eq(item_creator)
|
||||||
|
.or(comment::creator_id.eq(item_creator))
|
||||||
|
.or(private_message::creator_id.eq(item_creator)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
// The community
|
||||||
|
.left_join(community::table.on(post::community_id.eq(community::id)))
|
||||||
|
.left_join(actions_alias(
|
||||||
|
creator_community_actions,
|
||||||
|
item_creator,
|
||||||
|
post::community_id,
|
||||||
|
))
|
||||||
|
.left_join(
|
||||||
|
local_user::table.on(
|
||||||
|
item_creator
|
||||||
|
.eq(local_user::person_id)
|
||||||
|
.and(local_user::admin.eq(true)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.left_join(actions(
|
||||||
|
community_actions::table,
|
||||||
|
Some(my_person_id),
|
||||||
|
post::community_id,
|
||||||
|
))
|
||||||
|
.left_join(actions(post_actions::table, Some(my_person_id), post::id))
|
||||||
|
.left_join(actions(
|
||||||
|
person_actions::table,
|
||||||
|
Some(my_person_id),
|
||||||
|
item_creator,
|
||||||
|
))
|
||||||
|
.left_join(post_aggregates::table.on(post_report::post_id.eq(post_aggregates::post_id)))
|
||||||
|
.left_join(
|
||||||
|
comment_aggregates::table.on(comment_report::comment_id.eq(comment_aggregates::comment_id)),
|
||||||
|
)
|
||||||
|
// The resolver
|
||||||
|
.left_join(
|
||||||
|
aliases::person2.on(
|
||||||
|
private_message_report::resolver_id
|
||||||
|
.eq(resolver)
|
||||||
|
.or(post_report::resolver_id.eq(resolver))
|
||||||
|
.or(comment_report::resolver_id.eq(resolver)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.left_join(actions(
|
||||||
|
comment_actions::table,
|
||||||
|
Some(my_person_id),
|
||||||
|
comment_report::comment_id,
|
||||||
|
))
|
||||||
|
.select((
|
||||||
|
// Post-specific
|
||||||
|
post_report::all_columns.nullable(),
|
||||||
|
post::all_columns.nullable(),
|
||||||
|
post_aggregates::all_columns.nullable(),
|
||||||
|
coalesce(
|
||||||
|
post_aggregates::comments.nullable() - post_actions::read_comments_amount.nullable(),
|
||||||
|
post_aggregates::comments,
|
||||||
|
)
|
||||||
|
.nullable(),
|
||||||
|
post_actions::saved.nullable().is_not_null(),
|
||||||
|
post_actions::read.nullable().is_not_null(),
|
||||||
|
post_actions::hidden.nullable().is_not_null(),
|
||||||
|
post_actions::like_score.nullable(),
|
||||||
|
// Comment-specific
|
||||||
|
comment_report::all_columns.nullable(),
|
||||||
|
comment::all_columns.nullable(),
|
||||||
|
comment_aggregates::all_columns.nullable(),
|
||||||
|
comment_actions::saved.nullable().is_not_null(),
|
||||||
|
comment_actions::like_score.nullable(),
|
||||||
|
// Private-message-specific
|
||||||
|
private_message_report::all_columns.nullable(),
|
||||||
|
private_message::all_columns.nullable(),
|
||||||
|
// Shared
|
||||||
|
person::all_columns,
|
||||||
|
aliases::person1.fields(person::all_columns),
|
||||||
|
community::all_columns.nullable(),
|
||||||
|
CommunityFollower::select_subscribed_type(),
|
||||||
|
aliases::person2.fields(person::all_columns.nullable()),
|
||||||
|
local_user::admin.nullable().is_not_null(),
|
||||||
|
creator_community_actions
|
||||||
|
.field(community_actions::received_ban)
|
||||||
|
.nullable()
|
||||||
|
.is_not_null(),
|
||||||
|
creator_community_actions
|
||||||
|
.field(community_actions::became_moderator)
|
||||||
|
.nullable()
|
||||||
|
.is_not_null(),
|
||||||
|
person_actions::blocked.nullable().is_not_null(),
|
||||||
|
))
|
||||||
|
.into_boxed();
|
||||||
|
|
||||||
|
if let Some(community_id) = self.community_id {
|
||||||
|
query = query.filter(community::id.eq(community_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If its not an admin, get only the ones you mod
|
||||||
|
if !user.local_user.admin {
|
||||||
|
query = query.filter(community_actions::became_moderator.is_not_null());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut query = PaginatedQueryBuilder::new(query);
|
||||||
|
|
||||||
|
let page_after = self.page_after.map(|c| c.0);
|
||||||
|
|
||||||
|
if self.page_back.unwrap_or_default() {
|
||||||
|
query = query.before(page_after).limit_and_offset_from_end();
|
||||||
|
} else {
|
||||||
|
query = query.after(page_after);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If viewing all reports, order by newest, but if viewing unresolved only, show the oldest
|
||||||
|
// first (FIFO)
|
||||||
|
if self.unresolved_only.unwrap_or_default() {
|
||||||
|
query = query
|
||||||
|
.filter(
|
||||||
|
post_report::resolved
|
||||||
|
.or(comment_report::resolved)
|
||||||
|
.or(private_message_report::resolved)
|
||||||
|
.is_distinct_from(true),
|
||||||
|
)
|
||||||
|
// TODO: when a `then_asc` method is added, use it here, make the id sort direction match,
|
||||||
|
// and remove the separate index; unless additional columns are added to this sort
|
||||||
|
.then_desc(ReverseTimestampKey(key::published));
|
||||||
|
} else {
|
||||||
|
query = query.then_desc(key::published);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tie breaker
|
||||||
|
query = query.then_desc(key::id);
|
||||||
|
|
||||||
|
let res = query.load::<ReportCombinedViewInternal>(conn).await?;
|
||||||
|
|
||||||
|
// Map the query results to the enum
|
||||||
|
let out = res.into_iter().filter_map(map_to_enum).collect();
|
||||||
|
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Maps the combined DB row to an enum
|
||||||
|
fn map_to_enum(view: ReportCombinedViewInternal) -> Option<ReportCombinedView> {
|
||||||
|
// Use for a short alias
|
||||||
|
let v = view;
|
||||||
|
|
||||||
|
if let (Some(post_report), Some(post), Some(community), Some(unread_comments), Some(counts)) = (
|
||||||
|
v.post_report,
|
||||||
|
v.post.clone(),
|
||||||
|
v.community.clone(),
|
||||||
|
v.post_unread_comments,
|
||||||
|
v.post_counts,
|
||||||
|
) {
|
||||||
|
Some(ReportCombinedView::Post(PostReportView {
|
||||||
|
post_report,
|
||||||
|
post,
|
||||||
|
community,
|
||||||
|
unread_comments,
|
||||||
|
counts,
|
||||||
|
creator: v.report_creator,
|
||||||
|
post_creator: v.item_creator,
|
||||||
|
creator_banned_from_community: v.item_creator_banned_from_community,
|
||||||
|
creator_is_moderator: v.item_creator_is_moderator,
|
||||||
|
creator_is_admin: v.item_creator_is_admin,
|
||||||
|
creator_blocked: v.item_creator_blocked,
|
||||||
|
subscribed: v.subscribed,
|
||||||
|
saved: v.post_saved,
|
||||||
|
read: v.post_read,
|
||||||
|
hidden: v.post_hidden,
|
||||||
|
my_vote: v.my_post_vote,
|
||||||
|
resolver: v.resolver,
|
||||||
|
}))
|
||||||
|
} else if let (Some(comment_report), Some(comment), Some(counts), Some(post), Some(community)) = (
|
||||||
|
v.comment_report,
|
||||||
|
v.comment,
|
||||||
|
v.comment_counts,
|
||||||
|
v.post.clone(),
|
||||||
|
v.community.clone(),
|
||||||
|
) {
|
||||||
|
Some(ReportCombinedView::Comment(CommentReportView {
|
||||||
|
comment_report,
|
||||||
|
comment,
|
||||||
|
counts,
|
||||||
|
post,
|
||||||
|
community,
|
||||||
|
creator: v.report_creator,
|
||||||
|
comment_creator: v.item_creator,
|
||||||
|
creator_banned_from_community: v.item_creator_banned_from_community,
|
||||||
|
creator_is_moderator: v.item_creator_is_moderator,
|
||||||
|
creator_is_admin: v.item_creator_is_admin,
|
||||||
|
creator_blocked: v.item_creator_blocked,
|
||||||
|
subscribed: v.subscribed,
|
||||||
|
saved: v.comment_saved,
|
||||||
|
my_vote: v.my_comment_vote,
|
||||||
|
resolver: v.resolver,
|
||||||
|
}))
|
||||||
|
} else if let (Some(private_message_report), Some(private_message)) =
|
||||||
|
(v.private_message_report, v.private_message)
|
||||||
|
{
|
||||||
|
Some(ReportCombinedView::PrivateMessage(
|
||||||
|
PrivateMessageReportView {
|
||||||
|
private_message_report,
|
||||||
|
private_message,
|
||||||
|
creator: v.report_creator,
|
||||||
|
private_message_creator: v.item_creator,
|
||||||
|
resolver: v.resolver,
|
||||||
|
},
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[expect(clippy::indexing_slicing)]
|
||||||
|
mod tests {
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
report_combined_view::ReportCombinedQuery,
|
||||||
|
structs::{
|
||||||
|
CommentReportView,
|
||||||
|
LocalUserView,
|
||||||
|
PostReportView,
|
||||||
|
ReportCombinedView,
|
||||||
|
ReportCombinedViewInternal,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
use lemmy_db_schema::{
|
||||||
|
aggregates::structs::{CommentAggregates, PostAggregates},
|
||||||
|
assert_length,
|
||||||
|
source::{
|
||||||
|
comment::{Comment, CommentInsertForm},
|
||||||
|
comment_report::{CommentReport, CommentReportForm},
|
||||||
|
community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm},
|
||||||
|
instance::Instance,
|
||||||
|
local_user::{LocalUser, LocalUserInsertForm},
|
||||||
|
local_user_vote_display_mode::LocalUserVoteDisplayMode,
|
||||||
|
person::{Person, PersonInsertForm},
|
||||||
|
post::{Post, PostInsertForm},
|
||||||
|
post_report::{PostReport, PostReportForm},
|
||||||
|
private_message::{PrivateMessage, PrivateMessageInsertForm},
|
||||||
|
private_message_report::{PrivateMessageReport, PrivateMessageReportForm},
|
||||||
|
},
|
||||||
|
traits::{Crud, Joinable, Reportable},
|
||||||
|
utils::{build_db_pool_for_tests, DbPool},
|
||||||
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
use pretty_assertions::assert_eq;
|
||||||
|
use serial_test::serial;
|
||||||
|
|
||||||
|
struct Data {
|
||||||
|
instance: Instance,
|
||||||
|
timmy: Person,
|
||||||
|
sara: Person,
|
||||||
|
jessica: Person,
|
||||||
|
timmy_view: LocalUserView,
|
||||||
|
admin_view: LocalUserView,
|
||||||
|
community: Community,
|
||||||
|
post: Post,
|
||||||
|
post_2: Post,
|
||||||
|
comment: Comment,
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn init_data(pool: &mut DbPool<'_>) -> LemmyResult<Data> {
|
||||||
|
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
|
||||||
|
|
||||||
|
let timmy_form = PersonInsertForm::test_form(inserted_instance.id, "timmy_rcv");
|
||||||
|
let inserted_timmy = Person::create(pool, &timmy_form).await?;
|
||||||
|
let timmy_local_user_form = LocalUserInsertForm::test_form(inserted_timmy.id);
|
||||||
|
let timmy_local_user = LocalUser::create(pool, &timmy_local_user_form, vec![]).await?;
|
||||||
|
let timmy_view = LocalUserView {
|
||||||
|
local_user: timmy_local_user,
|
||||||
|
local_user_vote_display_mode: LocalUserVoteDisplayMode::default(),
|
||||||
|
person: inserted_timmy.clone(),
|
||||||
|
counts: Default::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Make an admin, to be able to see private message reports.
|
||||||
|
let admin_form = PersonInsertForm::test_form(inserted_instance.id, "admin_rcv");
|
||||||
|
let inserted_admin = Person::create(pool, &admin_form).await?;
|
||||||
|
let admin_local_user_form = LocalUserInsertForm::test_form_admin(inserted_admin.id);
|
||||||
|
let admin_local_user = LocalUser::create(pool, &admin_local_user_form, vec![]).await?;
|
||||||
|
let admin_view = LocalUserView {
|
||||||
|
local_user: admin_local_user,
|
||||||
|
local_user_vote_display_mode: LocalUserVoteDisplayMode::default(),
|
||||||
|
person: inserted_admin.clone(),
|
||||||
|
counts: Default::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let sara_form = PersonInsertForm::test_form(inserted_instance.id, "sara_rcv");
|
||||||
|
let inserted_sara = Person::create(pool, &sara_form).await?;
|
||||||
|
|
||||||
|
let jessica_form = PersonInsertForm::test_form(inserted_instance.id, "jessica_mrv");
|
||||||
|
let inserted_jessica = Person::create(pool, &jessica_form).await?;
|
||||||
|
|
||||||
|
let community_form = CommunityInsertForm::new(
|
||||||
|
inserted_instance.id,
|
||||||
|
"test community crv".to_string(),
|
||||||
|
"nada".to_owned(),
|
||||||
|
"pubkey".to_string(),
|
||||||
|
);
|
||||||
|
let inserted_community = Community::create(pool, &community_form).await?;
|
||||||
|
|
||||||
|
// Make timmy a mod
|
||||||
|
let timmy_moderator_form = CommunityModeratorForm {
|
||||||
|
community_id: inserted_community.id,
|
||||||
|
person_id: inserted_timmy.id,
|
||||||
|
};
|
||||||
|
CommunityModerator::join(pool, &timmy_moderator_form).await?;
|
||||||
|
|
||||||
|
let post_form = PostInsertForm::new(
|
||||||
|
"A test post crv".into(),
|
||||||
|
inserted_timmy.id,
|
||||||
|
inserted_community.id,
|
||||||
|
);
|
||||||
|
let inserted_post = Post::create(pool, &post_form).await?;
|
||||||
|
|
||||||
|
let new_post_2 = PostInsertForm::new(
|
||||||
|
"A test post crv 2".into(),
|
||||||
|
inserted_timmy.id,
|
||||||
|
inserted_community.id,
|
||||||
|
);
|
||||||
|
let inserted_post_2 = Post::create(pool, &new_post_2).await?;
|
||||||
|
|
||||||
|
// Timmy creates a comment
|
||||||
|
let comment_form = CommentInsertForm::new(
|
||||||
|
inserted_timmy.id,
|
||||||
|
inserted_post.id,
|
||||||
|
"A test comment rv".into(),
|
||||||
|
);
|
||||||
|
let inserted_comment = Comment::create(pool, &comment_form, None).await?;
|
||||||
|
|
||||||
|
Ok(Data {
|
||||||
|
instance: inserted_instance,
|
||||||
|
timmy: inserted_timmy,
|
||||||
|
sara: inserted_sara,
|
||||||
|
jessica: inserted_jessica,
|
||||||
|
admin_view,
|
||||||
|
timmy_view,
|
||||||
|
community: inserted_community,
|
||||||
|
post: inserted_post,
|
||||||
|
post_2: inserted_post_2,
|
||||||
|
comment: inserted_comment,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn cleanup(data: Data, pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
||||||
|
Instance::delete(pool, data.instance.id).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[serial]
|
||||||
|
async fn test_combined() -> LemmyResult<()> {
|
||||||
|
let pool = &build_db_pool_for_tests();
|
||||||
|
let pool = &mut pool.into();
|
||||||
|
let data = init_data(pool).await?;
|
||||||
|
|
||||||
|
// sara reports the post
|
||||||
|
let sara_report_post_form = PostReportForm {
|
||||||
|
creator_id: data.sara.id,
|
||||||
|
post_id: data.post.id,
|
||||||
|
original_post_name: "Orig post".into(),
|
||||||
|
original_post_url: None,
|
||||||
|
original_post_body: None,
|
||||||
|
reason: "from sara".into(),
|
||||||
|
};
|
||||||
|
let inserted_post_report = PostReport::report(pool, &sara_report_post_form).await?;
|
||||||
|
|
||||||
|
// Sara reports the comment
|
||||||
|
let sara_report_comment_form = CommentReportForm {
|
||||||
|
creator_id: data.sara.id,
|
||||||
|
comment_id: data.comment.id,
|
||||||
|
original_comment_text: "A test comment rv".into(),
|
||||||
|
reason: "from sara".into(),
|
||||||
|
};
|
||||||
|
CommentReport::report(pool, &sara_report_comment_form).await?;
|
||||||
|
|
||||||
|
// Timmy creates a private message
|
||||||
|
let pm_form = PrivateMessageInsertForm::new(
|
||||||
|
data.timmy.id,
|
||||||
|
data.sara.id,
|
||||||
|
"something offensive crv".to_string(),
|
||||||
|
);
|
||||||
|
let inserted_pm = PrivateMessage::create(pool, &pm_form).await?;
|
||||||
|
|
||||||
|
// sara reports private message
|
||||||
|
let pm_report_form = PrivateMessageReportForm {
|
||||||
|
creator_id: data.sara.id,
|
||||||
|
original_pm_text: inserted_pm.content.clone(),
|
||||||
|
private_message_id: inserted_pm.id,
|
||||||
|
reason: "its offensive".to_string(),
|
||||||
|
};
|
||||||
|
PrivateMessageReport::report(pool, &pm_report_form).await?;
|
||||||
|
|
||||||
|
// Do a batch read of admins reports
|
||||||
|
let reports = ReportCombinedQuery::default()
|
||||||
|
.list(pool, &data.admin_view)
|
||||||
|
.await?;
|
||||||
|
assert_eq!(3, reports.len());
|
||||||
|
|
||||||
|
// Make sure the report types are correct
|
||||||
|
if let ReportCombinedView::Post(v) = &reports[2] {
|
||||||
|
assert_eq!(data.post.id, v.post.id);
|
||||||
|
assert_eq!(data.sara.id, v.creator.id);
|
||||||
|
assert_eq!(data.timmy.id, v.post_creator.id);
|
||||||
|
} else {
|
||||||
|
panic!("wrong type");
|
||||||
|
}
|
||||||
|
if let ReportCombinedView::Comment(v) = &reports[1] {
|
||||||
|
assert_eq!(data.comment.id, v.comment.id);
|
||||||
|
assert_eq!(data.post.id, v.post.id);
|
||||||
|
assert_eq!(data.timmy.id, v.comment_creator.id);
|
||||||
|
} else {
|
||||||
|
panic!("wrong type");
|
||||||
|
}
|
||||||
|
if let ReportCombinedView::PrivateMessage(v) = &reports[0] {
|
||||||
|
assert_eq!(inserted_pm.id, v.private_message.id);
|
||||||
|
} else {
|
||||||
|
panic!("wrong type");
|
||||||
|
}
|
||||||
|
|
||||||
|
let report_count_admin =
|
||||||
|
ReportCombinedViewInternal::get_report_count(pool, &data.admin_view, None).await?;
|
||||||
|
assert_eq!(3, report_count_admin);
|
||||||
|
|
||||||
|
// Timmy should only see 2 reports, since they're not an admin,
|
||||||
|
// but they do mod the community
|
||||||
|
let reports = ReportCombinedQuery::default()
|
||||||
|
.list(pool, &data.timmy_view)
|
||||||
|
.await?;
|
||||||
|
assert_eq!(2, reports.len());
|
||||||
|
|
||||||
|
// Make sure the report types are correct
|
||||||
|
if let ReportCombinedView::Post(v) = &reports[1] {
|
||||||
|
assert_eq!(data.post.id, v.post.id);
|
||||||
|
assert_eq!(data.sara.id, v.creator.id);
|
||||||
|
assert_eq!(data.timmy.id, v.post_creator.id);
|
||||||
|
} else {
|
||||||
|
panic!("wrong type");
|
||||||
|
}
|
||||||
|
if let ReportCombinedView::Comment(v) = &reports[0] {
|
||||||
|
assert_eq!(data.comment.id, v.comment.id);
|
||||||
|
assert_eq!(data.post.id, v.post.id);
|
||||||
|
assert_eq!(data.timmy.id, v.comment_creator.id);
|
||||||
|
} else {
|
||||||
|
panic!("wrong type");
|
||||||
|
}
|
||||||
|
|
||||||
|
let report_count_timmy =
|
||||||
|
ReportCombinedViewInternal::get_report_count(pool, &data.timmy_view, None).await?;
|
||||||
|
assert_eq!(2, report_count_timmy);
|
||||||
|
|
||||||
|
// Resolve the post report
|
||||||
|
PostReport::resolve(pool, inserted_post_report.id, data.timmy.id).await?;
|
||||||
|
|
||||||
|
// Do a batch read of timmys reports
|
||||||
|
// It should only show saras, which is unresolved
|
||||||
|
let reports_after_resolve = ReportCombinedQuery {
|
||||||
|
unresolved_only: Some(true),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.list(pool, &data.timmy_view)
|
||||||
|
.await?;
|
||||||
|
assert_length!(1, reports_after_resolve);
|
||||||
|
|
||||||
|
// Make sure the counts are correct
|
||||||
|
let report_count_after_resolved =
|
||||||
|
ReportCombinedViewInternal::get_report_count(pool, &data.timmy_view, None).await?;
|
||||||
|
assert_eq!(1, report_count_after_resolved);
|
||||||
|
|
||||||
|
cleanup(data, pool).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[serial]
|
||||||
|
async fn test_private_message_reports() -> LemmyResult<()> {
|
||||||
|
let pool = &build_db_pool_for_tests();
|
||||||
|
let pool = &mut pool.into();
|
||||||
|
let data = init_data(pool).await?;
|
||||||
|
|
||||||
|
// timmy sends private message to jessica
|
||||||
|
let pm_form = PrivateMessageInsertForm::new(
|
||||||
|
data.timmy.id,
|
||||||
|
data.jessica.id,
|
||||||
|
"something offensive".to_string(),
|
||||||
|
);
|
||||||
|
let pm = PrivateMessage::create(pool, &pm_form).await?;
|
||||||
|
|
||||||
|
// jessica reports private message
|
||||||
|
let pm_report_form = PrivateMessageReportForm {
|
||||||
|
creator_id: data.jessica.id,
|
||||||
|
original_pm_text: pm.content.clone(),
|
||||||
|
private_message_id: pm.id,
|
||||||
|
reason: "its offensive".to_string(),
|
||||||
|
};
|
||||||
|
let pm_report = PrivateMessageReport::report(pool, &pm_report_form).await?;
|
||||||
|
|
||||||
|
let reports = ReportCombinedQuery::default()
|
||||||
|
.list(pool, &data.admin_view)
|
||||||
|
.await?;
|
||||||
|
assert_length!(1, reports);
|
||||||
|
if let ReportCombinedView::PrivateMessage(v) = &reports[0] {
|
||||||
|
assert!(!v.private_message_report.resolved);
|
||||||
|
assert_eq!(data.timmy.name, v.private_message_creator.name);
|
||||||
|
assert_eq!(data.jessica.name, v.creator.name);
|
||||||
|
assert_eq!(pm_report.reason, v.private_message_report.reason);
|
||||||
|
assert_eq!(pm.content, v.private_message.content);
|
||||||
|
} else {
|
||||||
|
panic!("wrong type");
|
||||||
|
}
|
||||||
|
|
||||||
|
// admin resolves the report (after taking appropriate action)
|
||||||
|
PrivateMessageReport::resolve(pool, pm_report.id, data.admin_view.person.id).await?;
|
||||||
|
|
||||||
|
let reports = ReportCombinedQuery::default()
|
||||||
|
.list(pool, &data.admin_view)
|
||||||
|
.await?;
|
||||||
|
assert_length!(1, reports);
|
||||||
|
if let ReportCombinedView::PrivateMessage(v) = &reports[0] {
|
||||||
|
assert!(v.private_message_report.resolved);
|
||||||
|
assert!(v.resolver.is_some());
|
||||||
|
assert_eq!(
|
||||||
|
Some(&data.admin_view.person.name),
|
||||||
|
v.resolver.as_ref().map(|r| &r.name)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
panic!("wrong type");
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup(data, pool).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[serial]
|
||||||
|
async fn test_post_reports() -> LemmyResult<()> {
|
||||||
|
let pool = &build_db_pool_for_tests();
|
||||||
|
let pool = &mut pool.into();
|
||||||
|
let data = init_data(pool).await?;
|
||||||
|
|
||||||
|
// sara reports
|
||||||
|
let sara_report_form = PostReportForm {
|
||||||
|
creator_id: data.sara.id,
|
||||||
|
post_id: data.post.id,
|
||||||
|
original_post_name: "Orig post".into(),
|
||||||
|
original_post_url: None,
|
||||||
|
original_post_body: None,
|
||||||
|
reason: "from sara".into(),
|
||||||
|
};
|
||||||
|
|
||||||
|
PostReport::report(pool, &sara_report_form).await?;
|
||||||
|
|
||||||
|
// jessica reports
|
||||||
|
let jessica_report_form = PostReportForm {
|
||||||
|
creator_id: data.jessica.id,
|
||||||
|
post_id: data.post_2.id,
|
||||||
|
original_post_name: "Orig post".into(),
|
||||||
|
original_post_url: None,
|
||||||
|
original_post_body: None,
|
||||||
|
reason: "from jessica".into(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let inserted_jessica_report = PostReport::report(pool, &jessica_report_form).await?;
|
||||||
|
|
||||||
|
let read_jessica_report_view =
|
||||||
|
PostReportView::read(pool, inserted_jessica_report.id, data.timmy.id).await?;
|
||||||
|
|
||||||
|
// Make sure the triggers are reading the aggregates correctly.
|
||||||
|
let agg_1 = PostAggregates::read(pool, data.post.id).await?;
|
||||||
|
let agg_2 = PostAggregates::read(pool, data.post_2.id).await?;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
read_jessica_report_view.post_report,
|
||||||
|
inserted_jessica_report
|
||||||
|
);
|
||||||
|
assert_eq!(read_jessica_report_view.post, data.post_2);
|
||||||
|
assert_eq!(read_jessica_report_view.community.id, data.community.id);
|
||||||
|
assert_eq!(read_jessica_report_view.creator.id, data.jessica.id);
|
||||||
|
assert_eq!(read_jessica_report_view.post_creator.id, data.timmy.id);
|
||||||
|
assert_eq!(read_jessica_report_view.my_vote, None);
|
||||||
|
assert_eq!(read_jessica_report_view.resolver, None);
|
||||||
|
assert_eq!(agg_1.report_count, 1);
|
||||||
|
assert_eq!(agg_1.unresolved_report_count, 1);
|
||||||
|
assert_eq!(agg_2.report_count, 1);
|
||||||
|
assert_eq!(agg_2.unresolved_report_count, 1);
|
||||||
|
|
||||||
|
// Do a batch read of timmys reports
|
||||||
|
let reports = ReportCombinedQuery::default()
|
||||||
|
.list(pool, &data.timmy_view)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if let ReportCombinedView::Post(v) = &reports[1] {
|
||||||
|
assert_eq!(v.creator.id, data.sara.id);
|
||||||
|
} else {
|
||||||
|
panic!("wrong type");
|
||||||
|
}
|
||||||
|
if let ReportCombinedView::Post(v) = &reports[0] {
|
||||||
|
assert_eq!(v.creator.id, data.jessica.id);
|
||||||
|
} else {
|
||||||
|
panic!("wrong type");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the counts are correct
|
||||||
|
let report_count =
|
||||||
|
ReportCombinedViewInternal::get_report_count(pool, &data.timmy_view, None).await?;
|
||||||
|
assert_eq!(2, report_count);
|
||||||
|
|
||||||
|
// Pretend the post was removed, and resolve all reports for that object.
|
||||||
|
// This is called manually in the API for post removals
|
||||||
|
PostReport::resolve_all_for_object(pool, inserted_jessica_report.post_id, data.timmy.id)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let read_jessica_report_view_after_resolve =
|
||||||
|
PostReportView::read(pool, inserted_jessica_report.id, data.timmy.id).await?;
|
||||||
|
assert!(read_jessica_report_view_after_resolve.post_report.resolved);
|
||||||
|
assert_eq!(
|
||||||
|
read_jessica_report_view_after_resolve
|
||||||
|
.post_report
|
||||||
|
.resolver_id,
|
||||||
|
Some(data.timmy.id)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
read_jessica_report_view_after_resolve
|
||||||
|
.resolver
|
||||||
|
.map(|r| r.id),
|
||||||
|
Some(data.timmy.id)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Make sure the unresolved_post report got decremented in the trigger
|
||||||
|
let agg_2 = PostAggregates::read(pool, data.post_2.id).await?;
|
||||||
|
assert_eq!(agg_2.report_count, 1);
|
||||||
|
assert_eq!(agg_2.unresolved_report_count, 0);
|
||||||
|
|
||||||
|
// Make sure the other unresolved report isn't changed
|
||||||
|
let agg_1 = PostAggregates::read(pool, data.post.id).await?;
|
||||||
|
assert_eq!(agg_1.report_count, 1);
|
||||||
|
assert_eq!(agg_1.unresolved_report_count, 1);
|
||||||
|
|
||||||
|
// Do a batch read of timmys reports
|
||||||
|
// It should only show saras, which is unresolved
|
||||||
|
let reports_after_resolve = ReportCombinedQuery {
|
||||||
|
unresolved_only: Some(true),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.list(pool, &data.timmy_view)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if let ReportCombinedView::Post(v) = &reports_after_resolve[0] {
|
||||||
|
assert_length!(1, reports_after_resolve);
|
||||||
|
assert_eq!(v.creator.id, data.sara.id);
|
||||||
|
} else {
|
||||||
|
panic!("wrong type");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the counts are correct
|
||||||
|
let report_count_after_resolved =
|
||||||
|
ReportCombinedViewInternal::get_report_count(pool, &data.timmy_view, None).await?;
|
||||||
|
assert_eq!(1, report_count_after_resolved);
|
||||||
|
|
||||||
|
cleanup(data, pool).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[serial]
|
||||||
|
async fn test_comment_reports() -> LemmyResult<()> {
|
||||||
|
let pool = &build_db_pool_for_tests();
|
||||||
|
let pool = &mut pool.into();
|
||||||
|
let data = init_data(pool).await?;
|
||||||
|
|
||||||
|
// sara reports
|
||||||
|
let sara_report_form = CommentReportForm {
|
||||||
|
creator_id: data.sara.id,
|
||||||
|
comment_id: data.comment.id,
|
||||||
|
original_comment_text: "this was it at time of creation".into(),
|
||||||
|
reason: "from sara".into(),
|
||||||
|
};
|
||||||
|
|
||||||
|
CommentReport::report(pool, &sara_report_form).await?;
|
||||||
|
|
||||||
|
// jessica reports
|
||||||
|
let jessica_report_form = CommentReportForm {
|
||||||
|
creator_id: data.jessica.id,
|
||||||
|
comment_id: data.comment.id,
|
||||||
|
original_comment_text: "this was it at time of creation".into(),
|
||||||
|
reason: "from jessica".into(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let inserted_jessica_report = CommentReport::report(pool, &jessica_report_form).await?;
|
||||||
|
|
||||||
|
let agg = CommentAggregates::read(pool, data.comment.id).await?;
|
||||||
|
assert_eq!(agg.report_count, 2);
|
||||||
|
|
||||||
|
let read_jessica_report_view =
|
||||||
|
CommentReportView::read(pool, inserted_jessica_report.id, data.timmy.id).await?;
|
||||||
|
assert_eq!(read_jessica_report_view.counts.unresolved_report_count, 2);
|
||||||
|
|
||||||
|
// Do a batch read of timmys reports
|
||||||
|
let reports = ReportCombinedQuery::default()
|
||||||
|
.list(pool, &data.timmy_view)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if let ReportCombinedView::Comment(v) = &reports[0] {
|
||||||
|
assert_eq!(v.creator.id, data.jessica.id);
|
||||||
|
} else {
|
||||||
|
panic!("wrong type");
|
||||||
|
}
|
||||||
|
if let ReportCombinedView::Comment(v) = &reports[1] {
|
||||||
|
assert_eq!(v.creator.id, data.sara.id);
|
||||||
|
} else {
|
||||||
|
panic!("wrong type");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the counts are correct
|
||||||
|
let report_count =
|
||||||
|
ReportCombinedViewInternal::get_report_count(pool, &data.timmy_view, None).await?;
|
||||||
|
assert_eq!(2, report_count);
|
||||||
|
|
||||||
|
// Resolve the report
|
||||||
|
CommentReport::resolve(pool, inserted_jessica_report.id, data.timmy.id).await?;
|
||||||
|
let read_jessica_report_view_after_resolve =
|
||||||
|
CommentReportView::read(pool, inserted_jessica_report.id, data.timmy.id).await?;
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
read_jessica_report_view_after_resolve
|
||||||
|
.comment_report
|
||||||
|
.resolved
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
read_jessica_report_view_after_resolve
|
||||||
|
.comment_report
|
||||||
|
.resolver_id,
|
||||||
|
Some(data.timmy.id)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
read_jessica_report_view_after_resolve
|
||||||
|
.resolver
|
||||||
|
.map(|r| r.id),
|
||||||
|
Some(data.timmy.id)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Do a batch read of timmys reports
|
||||||
|
// It should only show saras, which is unresolved
|
||||||
|
let reports_after_resolve = ReportCombinedQuery {
|
||||||
|
unresolved_only: Some(true),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.list(pool, &data.timmy_view)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if let ReportCombinedView::Comment(v) = &reports_after_resolve[0] {
|
||||||
|
assert_length!(1, reports_after_resolve);
|
||||||
|
assert_eq!(v.creator.id, data.sara.id);
|
||||||
|
} else {
|
||||||
|
panic!("wrong type");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the counts are correct
|
||||||
|
let report_count_after_resolved =
|
||||||
|
ReportCombinedViewInternal::get_report_count(pool, &data.timmy_view, None).await?;
|
||||||
|
assert_eq!(1, report_count_after_resolved);
|
||||||
|
|
||||||
|
cleanup(data, pool).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
use diesel::Queryable;
|
use diesel::Queryable;
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
use diesel::{deserialize::FromSqlRow, expression::AsExpression, sql_types};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::{CommentAggregates, PersonAggregates, PostAggregates, SiteAggregates},
|
aggregates::structs::{CommentAggregates, PersonAggregates, PostAggregates, SiteAggregates},
|
||||||
source::{
|
source::{
|
||||||
|
@ -20,6 +22,7 @@ use lemmy_db_schema::{
|
||||||
private_message_report::PrivateMessageReport,
|
private_message_report::PrivateMessageReport,
|
||||||
registration_application::RegistrationApplication,
|
registration_application::RegistrationApplication,
|
||||||
site::Site,
|
site::Site,
|
||||||
|
tag::Tag,
|
||||||
},
|
},
|
||||||
SubscribedType,
|
SubscribedType,
|
||||||
};
|
};
|
||||||
|
@ -126,6 +129,12 @@ pub struct PostReportView {
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
pub struct PaginationCursor(pub String);
|
pub struct PaginationCursor(pub String);
|
||||||
|
|
||||||
|
/// like PaginationCursor but for the report_combined table
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "full", derive(ts_rs::TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
pub struct ReportCombinedPaginationCursor(pub String);
|
||||||
|
|
||||||
#[skip_serializing_none]
|
#[skip_serializing_none]
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
|
||||||
#[cfg_attr(feature = "full", derive(TS, Queryable))]
|
#[cfg_attr(feature = "full", derive(TS, Queryable))]
|
||||||
|
@ -151,6 +160,7 @@ pub struct PostView {
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub my_vote: Option<i16>,
|
pub my_vote: Option<i16>,
|
||||||
pub unread_comments: i64,
|
pub unread_comments: i64,
|
||||||
|
pub tags: PostTags,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
||||||
|
@ -237,3 +247,58 @@ pub struct LocalImageView {
|
||||||
pub local_image: LocalImage,
|
pub local_image: LocalImage,
|
||||||
pub person: Person,
|
pub person: Person,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(Queryable))]
|
||||||
|
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||||
|
/// A combined report view
|
||||||
|
pub struct ReportCombinedViewInternal {
|
||||||
|
// Post-specific
|
||||||
|
pub post_report: Option<PostReport>,
|
||||||
|
pub post: Option<Post>,
|
||||||
|
pub post_counts: Option<PostAggregates>,
|
||||||
|
pub post_unread_comments: Option<i64>,
|
||||||
|
pub post_saved: bool,
|
||||||
|
pub post_read: bool,
|
||||||
|
pub post_hidden: bool,
|
||||||
|
pub my_post_vote: Option<i16>,
|
||||||
|
// Comment-specific
|
||||||
|
pub comment_report: Option<CommentReport>,
|
||||||
|
pub comment: Option<Comment>,
|
||||||
|
pub comment_counts: Option<CommentAggregates>,
|
||||||
|
pub comment_saved: bool,
|
||||||
|
pub my_comment_vote: Option<i16>,
|
||||||
|
// Private-message-specific
|
||||||
|
pub private_message_report: Option<PrivateMessageReport>,
|
||||||
|
pub private_message: Option<PrivateMessage>,
|
||||||
|
// Shared
|
||||||
|
pub report_creator: Person,
|
||||||
|
pub item_creator: Person,
|
||||||
|
pub community: Option<Community>,
|
||||||
|
pub subscribed: SubscribedType,
|
||||||
|
pub resolver: Option<Person>,
|
||||||
|
pub item_creator_is_admin: bool,
|
||||||
|
pub item_creator_banned_from_community: bool,
|
||||||
|
pub item_creator_is_moderator: bool,
|
||||||
|
pub item_creator_blocked: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
// Use serde's internal tagging, to work easier with javascript libraries
|
||||||
|
#[serde(tag = "type_")]
|
||||||
|
pub enum ReportCombinedView {
|
||||||
|
Post(PostReportView),
|
||||||
|
Comment(CommentReportView),
|
||||||
|
PrivateMessage(PrivateMessageReportView),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, serde::Serialize, serde::Deserialize, Debug, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "full", derive(TS, FromSqlRow, AsExpression))]
|
||||||
|
#[serde(transparent)]
|
||||||
|
#[cfg_attr(feature = "full", diesel(sql_type = Nullable<sql_types::Json>))]
|
||||||
|
/// we wrap this in a struct so we can implement FromSqlRow<Json> for it
|
||||||
|
pub struct PostTags {
|
||||||
|
pub tags: Vec<Tag>,
|
||||||
|
}
|
||||||
|
|
|
@ -26,13 +26,13 @@ full = [
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lemmy_db_schema = { workspace = true }
|
lemmy_db_schema = { workspace = true }
|
||||||
diesel = { workspace = true, features = [
|
diesel = { workspace = true, features = [
|
||||||
"postgres",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"postgres",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
diesel-async = { workspace = true, features = [
|
diesel-async = { workspace = true, features = [
|
||||||
"postgres",
|
|
||||||
"deadpool",
|
"deadpool",
|
||||||
|
"postgres",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_with = { workspace = true }
|
serde_with = { workspace = true }
|
||||||
|
|
|
@ -113,24 +113,24 @@ fn queries<'a>() -> Queries<
|
||||||
.await
|
.await
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>, options: CommentReplyQuery| async move {
|
let list = move |mut conn: DbConn<'a>, o: CommentReplyQuery| async move {
|
||||||
// These filters need to be kept in sync with the filters in
|
// These filters need to be kept in sync with the filters in
|
||||||
// CommentReplyView::get_unread_replies()
|
// CommentReplyView::get_unread_replies()
|
||||||
let mut query = all_joins(comment_reply::table.into_boxed(), options.my_person_id);
|
let mut query = all_joins(comment_reply::table.into_boxed(), o.my_person_id);
|
||||||
|
|
||||||
if let Some(recipient_id) = options.recipient_id {
|
if let Some(recipient_id) = o.recipient_id {
|
||||||
query = query.filter(comment_reply::recipient_id.eq(recipient_id));
|
query = query.filter(comment_reply::recipient_id.eq(recipient_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.unread_only {
|
if o.unread_only {
|
||||||
query = query.filter(comment_reply::read.eq(false));
|
query = query.filter(comment_reply::read.eq(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !options.show_bot_accounts {
|
if !o.show_bot_accounts {
|
||||||
query = query.filter(not(person::bot_account));
|
query = query.filter(not(person::bot_account));
|
||||||
};
|
};
|
||||||
|
|
||||||
query = match options.sort.unwrap_or(CommentSortType::New) {
|
query = match o.sort.unwrap_or(CommentSortType::New) {
|
||||||
CommentSortType::Hot => query.then_order_by(comment_aggregates::hot_rank.desc()),
|
CommentSortType::Hot => query.then_order_by(comment_aggregates::hot_rank.desc()),
|
||||||
CommentSortType::Controversial => {
|
CommentSortType::Controversial => {
|
||||||
query.then_order_by(comment_aggregates::controversy_rank.desc())
|
query.then_order_by(comment_aggregates::controversy_rank.desc())
|
||||||
|
@ -143,7 +143,7 @@ fn queries<'a>() -> Queries<
|
||||||
// Don't show replies from blocked persons
|
// Don't show replies from blocked persons
|
||||||
query = query.filter(person_actions::blocked.is_null());
|
query = query.filter(person_actions::blocked.is_null());
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
let (limit, offset) = limit_and_offset(o.page, o.limit)?;
|
||||||
|
|
||||||
query
|
query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
|
|
@ -90,17 +90,17 @@ fn queries<'a>() -> Queries<
|
||||||
query.first(&mut conn).await
|
query.first(&mut conn).await
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>, (options, site): (CommunityQuery<'a>, &'a Site)| async move {
|
let list = move |mut conn: DbConn<'a>, (o, site): (CommunityQuery<'a>, &'a Site)| async move {
|
||||||
use CommunitySortType::*;
|
use CommunitySortType::*;
|
||||||
|
|
||||||
let mut query = all_joins(community::table.into_boxed(), options.local_user).select(selection);
|
let mut query = all_joins(community::table.into_boxed(), o.local_user).select(selection);
|
||||||
|
|
||||||
if let Some(search_term) = options.search_term {
|
if let Some(search_term) = o.search_term {
|
||||||
let searcher = fuzzy_search(&search_term);
|
let searcher = fuzzy_search(&search_term);
|
||||||
let name_filter = community::name.ilike(searcher.clone());
|
let name_filter = community::name.ilike(searcher.clone());
|
||||||
let title_filter = community::title.ilike(searcher.clone());
|
let title_filter = community::title.ilike(searcher.clone());
|
||||||
let description_filter = community::description.ilike(searcher.clone());
|
let description_filter = community::description.ilike(searcher.clone());
|
||||||
query = if options.title_only.unwrap_or_default() {
|
query = if o.title_only.unwrap_or_default() {
|
||||||
query.filter(name_filter.or(title_filter))
|
query.filter(name_filter.or(title_filter))
|
||||||
} else {
|
} else {
|
||||||
query.filter(name_filter.or(title_filter.or(description_filter)))
|
query.filter(name_filter.or(title_filter.or(description_filter)))
|
||||||
|
@ -108,7 +108,7 @@ fn queries<'a>() -> Queries<
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide deleted and removed for non-admins or mods
|
// Hide deleted and removed for non-admins or mods
|
||||||
if !options.is_mod_or_admin {
|
if !o.is_mod_or_admin {
|
||||||
query = query.filter(not_removed_or_deleted).filter(
|
query = query.filter(not_removed_or_deleted).filter(
|
||||||
community::hidden
|
community::hidden
|
||||||
.eq(false)
|
.eq(false)
|
||||||
|
@ -116,7 +116,7 @@ fn queries<'a>() -> Queries<
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
match options.sort.unwrap_or(Hot) {
|
match o.sort.unwrap_or(Hot) {
|
||||||
Hot | Active | Scaled => query = query.order_by(community_aggregates::hot_rank.desc()),
|
Hot | Active | Scaled => query = query.order_by(community_aggregates::hot_rank.desc()),
|
||||||
NewComments | TopDay | TopTwelveHour | TopSixHour | TopHour => {
|
NewComments | TopDay | TopTwelveHour | TopSixHour | TopHour => {
|
||||||
query = query.order_by(community_aggregates::users_active_day.desc())
|
query = query.order_by(community_aggregates::users_active_day.desc())
|
||||||
|
@ -137,7 +137,7 @@ fn queries<'a>() -> Queries<
|
||||||
NameDesc => query = query.order_by(lower(community::name).desc()),
|
NameDesc => query = query.order_by(lower(community::name).desc()),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(listing_type) = options.listing_type {
|
if let Some(listing_type) = o.listing_type {
|
||||||
query = match listing_type {
|
query = match listing_type {
|
||||||
ListingType::Subscribed => {
|
ListingType::Subscribed => {
|
||||||
query.filter(community_actions::follow_state.eq(Some(CommunityFollowerState::Accepted)))
|
query.filter(community_actions::follow_state.eq(Some(CommunityFollowerState::Accepted)))
|
||||||
|
@ -151,13 +151,13 @@ fn queries<'a>() -> Queries<
|
||||||
// also hidden (based on profile setting)
|
// also hidden (based on profile setting)
|
||||||
query = query.filter(instance_actions::blocked.is_null());
|
query = query.filter(instance_actions::blocked.is_null());
|
||||||
query = query.filter(community_actions::blocked.is_null());
|
query = query.filter(community_actions::blocked.is_null());
|
||||||
if !(options.local_user.show_nsfw(site) || options.show_nsfw) {
|
if !(o.local_user.show_nsfw(site) || o.show_nsfw) {
|
||||||
query = query.filter(community::nsfw.eq(false));
|
query = query.filter(community::nsfw.eq(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
query = options.local_user.visible_communities_only(query);
|
query = o.local_user.visible_communities_only(query);
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
let (limit, offset) = limit_and_offset(o.page, o.limit)?;
|
||||||
query
|
query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
|
@ -188,7 +188,7 @@ impl CommunityView {
|
||||||
let is_mod =
|
let is_mod =
|
||||||
CommunityModeratorView::check_is_community_moderator(pool, community_id, person_id).await;
|
CommunityModeratorView::check_is_community_moderator(pool, community_id, person_id).await;
|
||||||
if is_mod.is_ok()
|
if is_mod.is_ok()
|
||||||
|| PersonView::read(pool, person_id)
|
|| PersonView::read(pool, person_id, false)
|
||||||
.await
|
.await
|
||||||
.is_ok_and(|t| t.is_admin)
|
.is_ok_and(|t| t.is_admin)
|
||||||
{
|
{
|
||||||
|
@ -206,7 +206,7 @@ impl CommunityView {
|
||||||
let is_mod_of_any =
|
let is_mod_of_any =
|
||||||
CommunityModeratorView::is_community_moderator_of_any(pool, person_id).await;
|
CommunityModeratorView::is_community_moderator_of_any(pool, person_id).await;
|
||||||
if is_mod_of_any.is_ok()
|
if is_mod_of_any.is_ok()
|
||||||
|| PersonView::read(pool, person_id)
|
|| PersonView::read(pool, person_id, false)
|
||||||
.await
|
.await
|
||||||
.is_ok_and(|t| t.is_admin)
|
.is_ok_and(|t| t.is_admin)
|
||||||
{
|
{
|
||||||
|
|
|
@ -113,24 +113,24 @@ fn queries<'a>() -> Queries<
|
||||||
.await
|
.await
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>, options: PersonMentionQuery| async move {
|
let list = move |mut conn: DbConn<'a>, o: PersonMentionQuery| async move {
|
||||||
// These filters need to be kept in sync with the filters in
|
// These filters need to be kept in sync with the filters in
|
||||||
// PersonMentionView::get_unread_mentions()
|
// PersonMentionView::get_unread_mentions()
|
||||||
let mut query = all_joins(person_mention::table.into_boxed(), options.my_person_id);
|
let mut query = all_joins(person_mention::table.into_boxed(), o.my_person_id);
|
||||||
|
|
||||||
if let Some(recipient_id) = options.recipient_id {
|
if let Some(recipient_id) = o.recipient_id {
|
||||||
query = query.filter(person_mention::recipient_id.eq(recipient_id));
|
query = query.filter(person_mention::recipient_id.eq(recipient_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.unread_only {
|
if o.unread_only {
|
||||||
query = query.filter(person_mention::read.eq(false));
|
query = query.filter(person_mention::read.eq(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !options.show_bot_accounts {
|
if !o.show_bot_accounts {
|
||||||
query = query.filter(not(person::bot_account));
|
query = query.filter(not(person::bot_account));
|
||||||
};
|
};
|
||||||
|
|
||||||
query = match options.sort.unwrap_or(CommentSortType::Hot) {
|
query = match o.sort.unwrap_or(CommentSortType::Hot) {
|
||||||
CommentSortType::Hot => query.then_order_by(comment_aggregates::hot_rank.desc()),
|
CommentSortType::Hot => query.then_order_by(comment_aggregates::hot_rank.desc()),
|
||||||
CommentSortType::Controversial => {
|
CommentSortType::Controversial => {
|
||||||
query.then_order_by(comment_aggregates::controversy_rank.desc())
|
query.then_order_by(comment_aggregates::controversy_rank.desc())
|
||||||
|
@ -143,7 +143,7 @@ fn queries<'a>() -> Queries<
|
||||||
// Don't show mentions from blocked persons
|
// Don't show mentions from blocked persons
|
||||||
query = query.filter(person_actions::blocked.is_null());
|
query = query.filter(person_actions::blocked.is_null());
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
let (limit, offset) = limit_and_offset(o.page, o.limit)?;
|
||||||
|
|
||||||
query
|
query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
|
|
@ -58,12 +58,11 @@ fn post_to_person_sort_type(sort: PostSortType) -> PersonSortType {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn queries<'a>(
|
fn queries<'a>(
|
||||||
) -> Queries<impl ReadFn<'a, PersonView, PersonId>, impl ListFn<'a, PersonView, ListMode>> {
|
) -> Queries<impl ReadFn<'a, PersonView, (PersonId, bool)>, impl ListFn<'a, PersonView, ListMode>> {
|
||||||
let all_joins = move |query: person::BoxedQuery<'a, Pg>| {
|
let all_joins = move |query: person::BoxedQuery<'a, Pg>| {
|
||||||
query
|
query
|
||||||
.inner_join(person_aggregates::table)
|
.inner_join(person_aggregates::table)
|
||||||
.left_join(local_user::table)
|
.left_join(local_user::table)
|
||||||
.filter(person::deleted.eq(false))
|
|
||||||
.select((
|
.select((
|
||||||
person::all_columns,
|
person::all_columns,
|
||||||
person_aggregates::all_columns,
|
person_aggregates::all_columns,
|
||||||
|
@ -71,14 +70,17 @@ fn queries<'a>(
|
||||||
))
|
))
|
||||||
};
|
};
|
||||||
|
|
||||||
let read = move |mut conn: DbConn<'a>, person_id: PersonId| async move {
|
let read = move |mut conn: DbConn<'a>, params: (PersonId, bool)| async move {
|
||||||
all_joins(person::table.find(person_id).into_boxed())
|
let (person_id, is_admin) = params;
|
||||||
.first(&mut conn)
|
let mut query = all_joins(person::table.find(person_id).into_boxed());
|
||||||
.await
|
if !is_admin {
|
||||||
|
query = query.filter(person::deleted.eq(false));
|
||||||
|
}
|
||||||
|
query.first(&mut conn).await
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>, mode: ListMode| async move {
|
let list = move |mut conn: DbConn<'a>, mode: ListMode| async move {
|
||||||
let mut query = all_joins(person::table.into_boxed());
|
let mut query = all_joins(person::table.into_boxed()).filter(person::deleted.eq(false));
|
||||||
match mode {
|
match mode {
|
||||||
ListMode::Admins => {
|
ListMode::Admins => {
|
||||||
query = query
|
query = query
|
||||||
|
@ -97,15 +99,15 @@ fn queries<'a>(
|
||||||
)
|
)
|
||||||
.filter(person::deleted.eq(false));
|
.filter(person::deleted.eq(false));
|
||||||
}
|
}
|
||||||
ListMode::Query(options) => {
|
ListMode::Query(o) => {
|
||||||
if let Some(search_term) = options.search_term {
|
if let Some(search_term) = o.search_term {
|
||||||
let searcher = fuzzy_search(&search_term);
|
let searcher = fuzzy_search(&search_term);
|
||||||
query = query
|
query = query
|
||||||
.filter(person::name.ilike(searcher.clone()))
|
.filter(person::name.ilike(searcher.clone()))
|
||||||
.or_filter(person::display_name.ilike(searcher));
|
.or_filter(person::display_name.ilike(searcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
let sort = options.sort.map(post_to_person_sort_type);
|
let sort = o.sort.map(post_to_person_sort_type);
|
||||||
query = match sort.unwrap_or(PersonSortType::CommentScore) {
|
query = match sort.unwrap_or(PersonSortType::CommentScore) {
|
||||||
PersonSortType::New => query.order_by(person::published.desc()),
|
PersonSortType::New => query.order_by(person::published.desc()),
|
||||||
PersonSortType::Old => query.order_by(person::published.asc()),
|
PersonSortType::Old => query.order_by(person::published.asc()),
|
||||||
|
@ -115,10 +117,10 @@ fn queries<'a>(
|
||||||
PersonSortType::PostCount => query.order_by(person_aggregates::post_count.desc()),
|
PersonSortType::PostCount => query.order_by(person_aggregates::post_count.desc()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(options.page, options.limit)?;
|
let (limit, offset) = limit_and_offset(o.page, o.limit)?;
|
||||||
query = query.limit(limit).offset(offset);
|
query = query.limit(limit).offset(offset);
|
||||||
|
|
||||||
if let Some(listing_type) = options.listing_type {
|
if let Some(listing_type) = o.listing_type {
|
||||||
query = match listing_type {
|
query = match listing_type {
|
||||||
// return nothing as its not possible to follow users
|
// return nothing as its not possible to follow users
|
||||||
ListingType::Subscribed => query.limit(0),
|
ListingType::Subscribed => query.limit(0),
|
||||||
|
@ -135,8 +137,12 @@ fn queries<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PersonView {
|
impl PersonView {
|
||||||
pub async fn read(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Self, Error> {
|
pub async fn read(
|
||||||
queries().read(pool, person_id).await
|
pool: &mut DbPool<'_>,
|
||||||
|
person_id: PersonId,
|
||||||
|
is_admin: bool,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
queries().read(pool, (person_id, is_admin)).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn admins(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
|
pub async fn admins(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
|
||||||
|
@ -243,9 +249,13 @@ mod tests {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let read = PersonView::read(pool, data.alice.id).await;
|
let read = PersonView::read(pool, data.alice.id, false).await;
|
||||||
assert!(read.is_err());
|
assert!(read.is_err());
|
||||||
|
|
||||||
|
// only admin can view deleted users
|
||||||
|
let read = PersonView::read(pool, data.alice.id, true).await;
|
||||||
|
assert!(read.is_ok());
|
||||||
|
|
||||||
let list = PersonQuery {
|
let list = PersonQuery {
|
||||||
sort: Some(PostSortType::New),
|
sort: Some(PostSortType::New),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -303,10 +313,10 @@ mod tests {
|
||||||
assert_length!(1, list);
|
assert_length!(1, list);
|
||||||
assert_eq!(list[0].person.id, data.alice.id);
|
assert_eq!(list[0].person.id, data.alice.id);
|
||||||
|
|
||||||
let is_admin = PersonView::read(pool, data.alice.id).await?.is_admin;
|
let is_admin = PersonView::read(pool, data.alice.id, false).await?.is_admin;
|
||||||
assert!(is_admin);
|
assert!(is_admin);
|
||||||
|
|
||||||
let is_admin = PersonView::read(pool, data.bob.id).await?.is_admin;
|
let is_admin = PersonView::read(pool, data.bob.id, false).await?.is_admin;
|
||||||
assert!(!is_admin);
|
assert!(!is_admin);
|
||||||
|
|
||||||
cleanup(data, pool).await
|
cleanup(data, pool).await
|
||||||
|
|
|
@ -20,13 +20,13 @@ full = ["lemmy_db_schema/full", "diesel", "diesel-async", "ts-rs"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lemmy_db_schema = { workspace = true }
|
lemmy_db_schema = { workspace = true }
|
||||||
diesel = { workspace = true, features = [
|
diesel = { workspace = true, features = [
|
||||||
"postgres",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"postgres",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
diesel-async = { workspace = true, features = [
|
diesel-async = { workspace = true, features = [
|
||||||
"postgres",
|
|
||||||
"deadpool",
|
"deadpool",
|
||||||
|
"postgres",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_with = { workspace = true }
|
serde_with = { workspace = true }
|
||||||
|
|
|
@ -25,7 +25,7 @@ activitypub_federation.workspace = true
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
chrono.workspace = true
|
chrono.workspace = true
|
||||||
diesel = { workspace = true, features = ["postgres", "chrono", "serde_json"] }
|
diesel = { workspace = true, features = ["chrono", "postgres", "serde_json"] }
|
||||||
diesel-async = { workspace = true, features = ["deadpool", "postgres"] }
|
diesel-async = { workspace = true, features = ["deadpool", "postgres"] }
|
||||||
reqwest.workspace = true
|
reqwest.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
|
|
|
@ -454,7 +454,6 @@ fn build_item(
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> LemmyResult<Item> {
|
) -> LemmyResult<Item> {
|
||||||
// TODO add images
|
// TODO add images
|
||||||
let author_url = format!("{protocol_and_hostname}/u/{creator_name}");
|
|
||||||
let guid = Some(Guid {
|
let guid = Some(Guid {
|
||||||
permalink: true,
|
permalink: true,
|
||||||
value: url.to_owned(),
|
value: url.to_owned(),
|
||||||
|
@ -464,7 +463,8 @@ fn build_item(
|
||||||
Ok(Item {
|
Ok(Item {
|
||||||
title: Some(format!("Reply from {creator_name}")),
|
title: Some(format!("Reply from {creator_name}")),
|
||||||
author: Some(format!(
|
author: Some(format!(
|
||||||
"/u/{creator_name} <a href=\"{author_url}\">(link)</a>"
|
"/u/{creator_name} <a href=\"{}\">(link)</a>",
|
||||||
|
format_args!("{protocol_and_hostname}/u/{creator_name}")
|
||||||
)),
|
)),
|
||||||
pub_date: Some(published.to_rfc2822()),
|
pub_date: Some(published.to_rfc2822()),
|
||||||
comments: Some(url.to_owned()),
|
comments: Some(url.to_owned()),
|
||||||
|
|
|
@ -65,10 +65,10 @@ anyhow = { workspace = true, optional = true }
|
||||||
reqwest-middleware = { workspace = true, optional = true }
|
reqwest-middleware = { workspace = true, optional = true }
|
||||||
strum = { workspace = true }
|
strum = { workspace = true }
|
||||||
futures = { workspace = true, optional = true }
|
futures = { workspace = true, optional = true }
|
||||||
diesel = { workspace = true, features = ["chrono"], optional = true }
|
diesel = { workspace = true, optional = true, features = ["chrono"] }
|
||||||
http = { workspace = true, optional = true }
|
http = { workspace = true, optional = true }
|
||||||
doku = { workspace = true, features = ["url-2"], optional = true }
|
doku = { workspace = true, features = ["url-2"], optional = true }
|
||||||
uuid = { workspace = true, features = ["serde", "v4"], optional = true }
|
uuid = { workspace = true, optional = true, features = ["v4"] }
|
||||||
rosetta-i18n = { workspace = true, optional = true }
|
rosetta-i18n = { workspace = true, optional = true }
|
||||||
tokio = { workspace = true, optional = true }
|
tokio = { workspace = true, optional = true }
|
||||||
urlencoding = { workspace = true, optional = true }
|
urlencoding = { workspace = true, optional = true }
|
||||||
|
@ -77,9 +77,8 @@ deser-hjson = { version = "2.2.4", optional = true }
|
||||||
smart-default = { version = "0.7.1", optional = true }
|
smart-default = { version = "0.7.1", optional = true }
|
||||||
lettre = { version = "0.11.10", default-features = false, features = [
|
lettre = { version = "0.11.10", default-features = false, features = [
|
||||||
"builder",
|
"builder",
|
||||||
"tokio1",
|
|
||||||
"tokio1-rustls-tls",
|
|
||||||
"smtp-transport",
|
"smtp-transport",
|
||||||
|
"tokio1-rustls-tls",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
markdown-it = { version = "0.6.1", optional = true }
|
markdown-it = { version = "0.6.1", optional = true }
|
||||||
ts-rs = { workspace = true, optional = true }
|
ts-rs = { workspace = true, optional = true }
|
||||||
|
|
|
@ -114,7 +114,6 @@ pub enum LemmyErrorType {
|
||||||
SystemErrLogin,
|
SystemErrLogin,
|
||||||
CouldntSetAllRegistrationsAccepted,
|
CouldntSetAllRegistrationsAccepted,
|
||||||
CouldntSetAllEmailVerified,
|
CouldntSetAllEmailVerified,
|
||||||
Banned,
|
|
||||||
BlockedUrl,
|
BlockedUrl,
|
||||||
CouldntGetComments,
|
CouldntGetComments,
|
||||||
CouldntGetPosts,
|
CouldntGetPosts,
|
||||||
|
@ -329,9 +328,9 @@ cfg_if! {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserializes_no_message() -> LemmyResult<()> {
|
fn deserializes_no_message() -> LemmyResult<()> {
|
||||||
let err = LemmyError::from(LemmyErrorType::Banned).error_response();
|
let err = LemmyError::from(LemmyErrorType::BlockedUrl).error_response();
|
||||||
let json = String::from_utf8(err.into_body().try_into_bytes().unwrap_or_default().to_vec())?;
|
let json = String::from_utf8(err.into_body().try_into_bytes().unwrap_or_default().to_vec())?;
|
||||||
assert_eq!(&json, "{\"error\":\"banned\"}");
|
assert_eq!(&json, "{\"error\":\"blocked_url\"}");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,8 @@ pub fn markdown_rewrite_image_links(mut src: String) -> (String, Vec<Url>) {
|
||||||
);
|
);
|
||||||
// restore custom emoji format
|
// restore custom emoji format
|
||||||
if let Some(extra) = extra {
|
if let Some(extra) = extra {
|
||||||
proxied = format!("{proxied} {extra}");
|
proxied.push(' ');
|
||||||
|
proxied.push_str(extra);
|
||||||
}
|
}
|
||||||
src.replace_range(start..end, &proxied);
|
src.replace_range(start..end, &proxied);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,10 @@ pub fn markdown_check_for_blocked_urls(text: &str, blocklist: &RegexSet) -> Lemm
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::utils::validation::check_urls_are_valid;
|
||||||
use image_links::markdown_rewrite_image_links;
|
use image_links::markdown_rewrite_image_links;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
use regex::escape;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_basic_markdown() {
|
fn test_basic_markdown() {
|
||||||
|
@ -191,9 +193,20 @@ mod tests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This replicates the logic when saving url blocklist patterns and querying them.
|
||||||
|
// Refer to lemmy_api_crud::site::update::update_site and
|
||||||
|
// lemmy_api_common::utils::get_url_blocklist().
|
||||||
|
fn create_url_blocklist_test_regex_set(patterns: Vec<&str>) -> LemmyResult<RegexSet> {
|
||||||
|
let url_blocklist = patterns.iter().map(|&s| s.to_string()).collect();
|
||||||
|
let valid_urls = check_urls_are_valid(&url_blocklist)?;
|
||||||
|
let regexes = valid_urls.iter().map(|p| format!(r"\b{}\b", escape(p)));
|
||||||
|
let set = RegexSet::new(regexes)?;
|
||||||
|
Ok(set)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_url_blocking() -> LemmyResult<()> {
|
fn test_url_blocking() -> LemmyResult<()> {
|
||||||
let set = RegexSet::new(vec![r"(https://)?example\.com/?"])?;
|
let set = create_url_blocklist_test_regex_set(vec!["example.com/"])?;
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
markdown_check_for_blocked_urls(&String::from("[](https://example.com)"), &set).is_err()
|
markdown_check_for_blocked_urls(&String::from("[](https://example.com)"), &set).is_err()
|
||||||
|
@ -221,37 +234,42 @@ mod tests {
|
||||||
)
|
)
|
||||||
.is_err());
|
.is_err());
|
||||||
|
|
||||||
let set = RegexSet::new(vec![r"(https://)?example\.com/spam\.jpg"])?;
|
let set = create_url_blocklist_test_regex_set(vec!["example.com/spam.jpg"])?;
|
||||||
assert!(markdown_check_for_blocked_urls(
|
assert!(markdown_check_for_blocked_urls("", &set).is_err());
|
||||||
&String::from(""),
|
assert!(markdown_check_for_blocked_urls("", &set).is_ok());
|
||||||
&set
|
// TODO: the following should not be matched, scunthorpe problem.
|
||||||
)
|
assert!(
|
||||||
.is_err());
|
markdown_check_for_blocked_urls("", &set).is_err()
|
||||||
|
);
|
||||||
|
|
||||||
let set = RegexSet::new(vec![
|
let set = create_url_blocklist_test_regex_set(vec![
|
||||||
r"(https://)?quo\.example\.com/?",
|
r"quo.example.com/",
|
||||||
r"(https://)?foo\.example\.com/?",
|
r"foo.example.com/",
|
||||||
r"(https://)?bar\.example\.com/?",
|
r"bar.example.com/",
|
||||||
])?;
|
])?;
|
||||||
|
|
||||||
assert!(
|
assert!(markdown_check_for_blocked_urls("https://baz.example.com", &set).is_ok());
|
||||||
markdown_check_for_blocked_urls(&String::from("https://baz.example.com"), &set).is_ok()
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(
|
assert!(markdown_check_for_blocked_urls("https://bar.example.com", &set).is_err());
|
||||||
markdown_check_for_blocked_urls(&String::from("https://bar.example.com"), &set).is_err()
|
|
||||||
);
|
|
||||||
|
|
||||||
let set = RegexSet::new(vec![r"(https://)?example\.com/banned_page"])?;
|
let set = create_url_blocklist_test_regex_set(vec!["example.com/banned_page"])?;
|
||||||
|
|
||||||
assert!(
|
assert!(markdown_check_for_blocked_urls("https://example.com/page", &set).is_ok());
|
||||||
markdown_check_for_blocked_urls(&String::from("https://example.com/page"), &set).is_ok()
|
|
||||||
);
|
|
||||||
|
|
||||||
let set = RegexSet::new(vec![r"(https://)?ex\.mple\.com/?"])?;
|
let set = create_url_blocklist_test_regex_set(vec!["ex.mple.com/"])?;
|
||||||
|
|
||||||
assert!(markdown_check_for_blocked_urls("example.com", &set).is_ok());
|
assert!(markdown_check_for_blocked_urls("example.com", &set).is_ok());
|
||||||
|
|
||||||
|
let set = create_url_blocklist_test_regex_set(vec!["rt.com/"])?;
|
||||||
|
|
||||||
|
assert!(markdown_check_for_blocked_urls("deviantart.com", &set).is_ok());
|
||||||
|
assert!(markdown_check_for_blocked_urls("art.com.example.com", &set).is_ok());
|
||||||
|
assert!(markdown_check_for_blocked_urls("https://rt.com/abc", &set).is_err());
|
||||||
|
assert!(markdown_check_for_blocked_urls("go to rt.com.", &set).is_err());
|
||||||
|
assert!(markdown_check_for_blocked_urls("check out rt.computer", &set).is_ok());
|
||||||
|
// TODO: the following should not be matched, scunthorpe problem.
|
||||||
|
assert!(markdown_check_for_blocked_urls("rt.com.example.com", &set).is_err());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# syntax=docker/dockerfile:1.10
|
# syntax=docker/dockerfile:1.12
|
||||||
ARG RUST_VERSION=1.81
|
ARG RUST_VERSION=1.81
|
||||||
ARG CARGO_BUILD_FEATURES=default
|
ARG CARGO_BUILD_FEATURES=default
|
||||||
ARG RUST_RELEASE_MODE=debug
|
ARG RUST_RELEASE_MODE=debug
|
||||||
|
|
|
@ -53,7 +53,7 @@ services:
|
||||||
|
|
||||||
lemmy-ui:
|
lemmy-ui:
|
||||||
# use "image" to pull down an already compiled lemmy-ui. make sure to comment out "build".
|
# use "image" to pull down an already compiled lemmy-ui. make sure to comment out "build".
|
||||||
image: dessalines/lemmy-ui:0.19.6
|
image: dessalines/lemmy-ui:0.19.8
|
||||||
# platform: linux/x86_64 # no arm64 support. uncomment platform if using m1.
|
# platform: linux/x86_64 # no arm64 support. uncomment platform if using m1.
|
||||||
# use "build" to build your local lemmy ui image for development. make sure to comment out "image".
|
# use "build" to build your local lemmy ui image for development. make sure to comment out "image".
|
||||||
# run: docker compose up --build
|
# run: docker compose up --build
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue