lemmy/crates/db_schema/src/impls/community.rs

553 lines
16 KiB
Rust
Raw Normal View History

2021-10-16 13:33:38 +00:00
use crate::{
newtypes::{CommunityId, DbUrl, PersonId},
Reduce amount of columns selected (#3755) * PostAggregatesNotInPost * CommentAggregatesNotInComment * CommunityPersonBanAdditionalInfo (partial) * Revert "CommunityPersonBanAdditionalInfo (partial)" This reverts commit 158f7f0cd9a07392fb1f457ac43c8d7c57e4190d. * Replace some nullable parts of selection with id::nullable().is_not_null() * CommunityFollower::select_subscribed_type * WithoutId * Add WithoutId derives * Update Cargo.toml * rerun ci * Fix syntatx errors * rerun ci * Add missing "|" in private_message_report_view.rs * rerun ci * cargo fmt * rerun ci * Only derive WithoutId for Community with "full" feature * rerun ci * Fix attribute filtering in WithoutId macro * rerun ci * Update without_id.rs * rerun ci * Update without_id.rs * rerun ci * Fix errors * rerun ci * cargo fmt * Fix errors * rerun ci * Move WithoutId to lib.rs * rerun ci * Remove macro_use for paste * rerun ci * Update comment_reply_view.rs * rerun ci * Update registration_application_view.rs * rerun ci * Revert "Update registration_application_view.rs" This reverts commit 2e98e4bb8385b4630ed2d1dfdd8da9a35c0126b2. * Revert "Update comment_reply_view.rs" This reverts commit 857bf9f5a2413ff0e6e6c95e1157e8ce6bf9c0c3. * Revert "Remove macro_use for paste" This reverts commit 13247279ed9090f2d3c5c6525b9611529217d605. * Revert "Move WithoutId to lib.rs" This reverts commit 0c23e5213be1366bb64029e2007e97194e126676. * Revert "Fix errors" This reverts commit a283d155e5622bba0b6df8b07649fc246df8bb77. * Revert "cargo fmt" This reverts commit 36a5210352809b3ca417ec3b869ae4baaca17e16. * Revert "Fix errors" This reverts commit c9102c14f466a5d6175732625e74183579ee2be5. * Revert "Update without_id.rs" This reverts commit 19adb2fcc805f92f6720a439f3b2c80a2b866938. * Revert "Update without_id.rs" This reverts commit e26107a2fe30cc2ec81797830e3a34a1676619e4. * Revert "Fix attribute filtering in WithoutId macro" This reverts commit acaa4902b0e7e33205c5d287cd22b83732a1a401. * Revert "Only derive WithoutId for Community with "full" feature" This reverts commit de0e9c6fdc3c9344998d9d72e5e361a7f009c829. * Revert "cargo fmt" This reverts commit 5e1bd1ce58e997e9431f212fd2ee0283faaf6da3. * Revert "Add missing "|" in private_message_report_view.rs" This reverts commit c7ae9f1cd50dfead0fbc363d93692f82274ff870. * Revert "Fix syntatx errors" This reverts commit d942f099de8128b5a02fe74f5af43a4453a06350. * Revert "Update Cargo.toml" This reverts commit 23cdb6f6d3df6d2db06173f066c117a0c96dd8e1. * Revert "Add WithoutId derives" This reverts commit 06006d6ad338e946410962f4276f67fe5096ad5a. * Revert "WithoutId" This reverts commit 5e86922b0fd5bf08d114a8eee5d1e10b2ea534ee. * Revert "CommentAggregatesNotInComment" This reverts commit 603aede7cecacd246664f7f3f0047202f80d9938. * Revert "PostAggregatesNotInPost" This reverts commit 1ee3fcaeab8705e4e0e849ae6b93b45716aa9cc0. * Restore original position of options.saved_only filter * rerun ci * Update post_view.rs * rerun ci
2023-08-08 09:41:10 +00:00
schema::{community, community_follower, instance},
source::{
actor_language::CommunityLanguage,
community::{
Community,
CommunityFollower,
CommunityFollowerForm,
CommunityInsertForm,
CommunityModerator,
CommunityModeratorForm,
CommunityPersonBan,
CommunityPersonBanForm,
CommunityUpdateForm,
},
post::Post,
2020-12-21 12:28:12 +00:00
},
traits::{ApubActor, Bannable, Crud, Followable, Joinable},
2022-11-09 10:05:00 +00:00
utils::{functions::lower, get_conn, DbPool},
SubscribedType,
};
Reduce amount of columns selected (#3755) * PostAggregatesNotInPost * CommentAggregatesNotInComment * CommunityPersonBanAdditionalInfo (partial) * Revert "CommunityPersonBanAdditionalInfo (partial)" This reverts commit 158f7f0cd9a07392fb1f457ac43c8d7c57e4190d. * Replace some nullable parts of selection with id::nullable().is_not_null() * CommunityFollower::select_subscribed_type * WithoutId * Add WithoutId derives * Update Cargo.toml * rerun ci * Fix syntatx errors * rerun ci * Add missing "|" in private_message_report_view.rs * rerun ci * cargo fmt * rerun ci * Only derive WithoutId for Community with "full" feature * rerun ci * Fix attribute filtering in WithoutId macro * rerun ci * Update without_id.rs * rerun ci * Update without_id.rs * rerun ci * Fix errors * rerun ci * cargo fmt * Fix errors * rerun ci * Move WithoutId to lib.rs * rerun ci * Remove macro_use for paste * rerun ci * Update comment_reply_view.rs * rerun ci * Update registration_application_view.rs * rerun ci * Revert "Update registration_application_view.rs" This reverts commit 2e98e4bb8385b4630ed2d1dfdd8da9a35c0126b2. * Revert "Update comment_reply_view.rs" This reverts commit 857bf9f5a2413ff0e6e6c95e1157e8ce6bf9c0c3. * Revert "Remove macro_use for paste" This reverts commit 13247279ed9090f2d3c5c6525b9611529217d605. * Revert "Move WithoutId to lib.rs" This reverts commit 0c23e5213be1366bb64029e2007e97194e126676. * Revert "Fix errors" This reverts commit a283d155e5622bba0b6df8b07649fc246df8bb77. * Revert "cargo fmt" This reverts commit 36a5210352809b3ca417ec3b869ae4baaca17e16. * Revert "Fix errors" This reverts commit c9102c14f466a5d6175732625e74183579ee2be5. * Revert "Update without_id.rs" This reverts commit 19adb2fcc805f92f6720a439f3b2c80a2b866938. * Revert "Update without_id.rs" This reverts commit e26107a2fe30cc2ec81797830e3a34a1676619e4. * Revert "Fix attribute filtering in WithoutId macro" This reverts commit acaa4902b0e7e33205c5d287cd22b83732a1a401. * Revert "Only derive WithoutId for Community with "full" feature" This reverts commit de0e9c6fdc3c9344998d9d72e5e361a7f009c829. * Revert "cargo fmt" This reverts commit 5e1bd1ce58e997e9431f212fd2ee0283faaf6da3. * Revert "Add missing "|" in private_message_report_view.rs" This reverts commit c7ae9f1cd50dfead0fbc363d93692f82274ff870. * Revert "Fix syntatx errors" This reverts commit d942f099de8128b5a02fe74f5af43a4453a06350. * Revert "Update Cargo.toml" This reverts commit 23cdb6f6d3df6d2db06173f066c117a0c96dd8e1. * Revert "Add WithoutId derives" This reverts commit 06006d6ad338e946410962f4276f67fe5096ad5a. * Revert "WithoutId" This reverts commit 5e86922b0fd5bf08d114a8eee5d1e10b2ea534ee. * Revert "CommentAggregatesNotInComment" This reverts commit 603aede7cecacd246664f7f3f0047202f80d9938. * Revert "PostAggregatesNotInPost" This reverts commit 1ee3fcaeab8705e4e0e849ae6b93b45716aa9cc0. * Restore original position of options.saved_only filter * rerun ci * Update post_view.rs * rerun ci
2023-08-08 09:41:10 +00:00
use diesel::{
deserialize,
dsl,
dsl::{exists, insert_into},
Reduce amount of columns selected (#3755) * PostAggregatesNotInPost * CommentAggregatesNotInComment * CommunityPersonBanAdditionalInfo (partial) * Revert "CommunityPersonBanAdditionalInfo (partial)" This reverts commit 158f7f0cd9a07392fb1f457ac43c8d7c57e4190d. * Replace some nullable parts of selection with id::nullable().is_not_null() * CommunityFollower::select_subscribed_type * WithoutId * Add WithoutId derives * Update Cargo.toml * rerun ci * Fix syntatx errors * rerun ci * Add missing "|" in private_message_report_view.rs * rerun ci * cargo fmt * rerun ci * Only derive WithoutId for Community with "full" feature * rerun ci * Fix attribute filtering in WithoutId macro * rerun ci * Update without_id.rs * rerun ci * Update without_id.rs * rerun ci * Fix errors * rerun ci * cargo fmt * Fix errors * rerun ci * Move WithoutId to lib.rs * rerun ci * Remove macro_use for paste * rerun ci * Update comment_reply_view.rs * rerun ci * Update registration_application_view.rs * rerun ci * Revert "Update registration_application_view.rs" This reverts commit 2e98e4bb8385b4630ed2d1dfdd8da9a35c0126b2. * Revert "Update comment_reply_view.rs" This reverts commit 857bf9f5a2413ff0e6e6c95e1157e8ce6bf9c0c3. * Revert "Remove macro_use for paste" This reverts commit 13247279ed9090f2d3c5c6525b9611529217d605. * Revert "Move WithoutId to lib.rs" This reverts commit 0c23e5213be1366bb64029e2007e97194e126676. * Revert "Fix errors" This reverts commit a283d155e5622bba0b6df8b07649fc246df8bb77. * Revert "cargo fmt" This reverts commit 36a5210352809b3ca417ec3b869ae4baaca17e16. * Revert "Fix errors" This reverts commit c9102c14f466a5d6175732625e74183579ee2be5. * Revert "Update without_id.rs" This reverts commit 19adb2fcc805f92f6720a439f3b2c80a2b866938. * Revert "Update without_id.rs" This reverts commit e26107a2fe30cc2ec81797830e3a34a1676619e4. * Revert "Fix attribute filtering in WithoutId macro" This reverts commit acaa4902b0e7e33205c5d287cd22b83732a1a401. * Revert "Only derive WithoutId for Community with "full" feature" This reverts commit de0e9c6fdc3c9344998d9d72e5e361a7f009c829. * Revert "cargo fmt" This reverts commit 5e1bd1ce58e997e9431f212fd2ee0283faaf6da3. * Revert "Add missing "|" in private_message_report_view.rs" This reverts commit c7ae9f1cd50dfead0fbc363d93692f82274ff870. * Revert "Fix syntatx errors" This reverts commit d942f099de8128b5a02fe74f5af43a4453a06350. * Revert "Update Cargo.toml" This reverts commit 23cdb6f6d3df6d2db06173f066c117a0c96dd8e1. * Revert "Add WithoutId derives" This reverts commit 06006d6ad338e946410962f4276f67fe5096ad5a. * Revert "WithoutId" This reverts commit 5e86922b0fd5bf08d114a8eee5d1e10b2ea534ee. * Revert "CommentAggregatesNotInComment" This reverts commit 603aede7cecacd246664f7f3f0047202f80d9938. * Revert "PostAggregatesNotInPost" This reverts commit 1ee3fcaeab8705e4e0e849ae6b93b45716aa9cc0. * Restore original position of options.saved_only filter * rerun ci * Update post_view.rs * rerun ci
2023-08-08 09:41:10 +00:00
pg::Pg,
result::Error,
select,
Reduce amount of columns selected (#3755) * PostAggregatesNotInPost * CommentAggregatesNotInComment * CommunityPersonBanAdditionalInfo (partial) * Revert "CommunityPersonBanAdditionalInfo (partial)" This reverts commit 158f7f0cd9a07392fb1f457ac43c8d7c57e4190d. * Replace some nullable parts of selection with id::nullable().is_not_null() * CommunityFollower::select_subscribed_type * WithoutId * Add WithoutId derives * Update Cargo.toml * rerun ci * Fix syntatx errors * rerun ci * Add missing "|" in private_message_report_view.rs * rerun ci * cargo fmt * rerun ci * Only derive WithoutId for Community with "full" feature * rerun ci * Fix attribute filtering in WithoutId macro * rerun ci * Update without_id.rs * rerun ci * Update without_id.rs * rerun ci * Fix errors * rerun ci * cargo fmt * Fix errors * rerun ci * Move WithoutId to lib.rs * rerun ci * Remove macro_use for paste * rerun ci * Update comment_reply_view.rs * rerun ci * Update registration_application_view.rs * rerun ci * Revert "Update registration_application_view.rs" This reverts commit 2e98e4bb8385b4630ed2d1dfdd8da9a35c0126b2. * Revert "Update comment_reply_view.rs" This reverts commit 857bf9f5a2413ff0e6e6c95e1157e8ce6bf9c0c3. * Revert "Remove macro_use for paste" This reverts commit 13247279ed9090f2d3c5c6525b9611529217d605. * Revert "Move WithoutId to lib.rs" This reverts commit 0c23e5213be1366bb64029e2007e97194e126676. * Revert "Fix errors" This reverts commit a283d155e5622bba0b6df8b07649fc246df8bb77. * Revert "cargo fmt" This reverts commit 36a5210352809b3ca417ec3b869ae4baaca17e16. * Revert "Fix errors" This reverts commit c9102c14f466a5d6175732625e74183579ee2be5. * Revert "Update without_id.rs" This reverts commit 19adb2fcc805f92f6720a439f3b2c80a2b866938. * Revert "Update without_id.rs" This reverts commit e26107a2fe30cc2ec81797830e3a34a1676619e4. * Revert "Fix attribute filtering in WithoutId macro" This reverts commit acaa4902b0e7e33205c5d287cd22b83732a1a401. * Revert "Only derive WithoutId for Community with "full" feature" This reverts commit de0e9c6fdc3c9344998d9d72e5e361a7f009c829. * Revert "cargo fmt" This reverts commit 5e1bd1ce58e997e9431f212fd2ee0283faaf6da3. * Revert "Add missing "|" in private_message_report_view.rs" This reverts commit c7ae9f1cd50dfead0fbc363d93692f82274ff870. * Revert "Fix syntatx errors" This reverts commit d942f099de8128b5a02fe74f5af43a4453a06350. * Revert "Update Cargo.toml" This reverts commit 23cdb6f6d3df6d2db06173f066c117a0c96dd8e1. * Revert "Add WithoutId derives" This reverts commit 06006d6ad338e946410962f4276f67fe5096ad5a. * Revert "WithoutId" This reverts commit 5e86922b0fd5bf08d114a8eee5d1e10b2ea534ee. * Revert "CommentAggregatesNotInComment" This reverts commit 603aede7cecacd246664f7f3f0047202f80d9938. * Revert "PostAggregatesNotInPost" This reverts commit 1ee3fcaeab8705e4e0e849ae6b93b45716aa9cc0. * Restore original position of options.saved_only filter * rerun ci * Update post_view.rs * rerun ci
2023-08-08 09:41:10 +00:00
sql_types,
update,
Reduce amount of columns selected (#3755) * PostAggregatesNotInPost * CommentAggregatesNotInComment * CommunityPersonBanAdditionalInfo (partial) * Revert "CommunityPersonBanAdditionalInfo (partial)" This reverts commit 158f7f0cd9a07392fb1f457ac43c8d7c57e4190d. * Replace some nullable parts of selection with id::nullable().is_not_null() * CommunityFollower::select_subscribed_type * WithoutId * Add WithoutId derives * Update Cargo.toml * rerun ci * Fix syntatx errors * rerun ci * Add missing "|" in private_message_report_view.rs * rerun ci * cargo fmt * rerun ci * Only derive WithoutId for Community with "full" feature * rerun ci * Fix attribute filtering in WithoutId macro * rerun ci * Update without_id.rs * rerun ci * Update without_id.rs * rerun ci * Fix errors * rerun ci * cargo fmt * Fix errors * rerun ci * Move WithoutId to lib.rs * rerun ci * Remove macro_use for paste * rerun ci * Update comment_reply_view.rs * rerun ci * Update registration_application_view.rs * rerun ci * Revert "Update registration_application_view.rs" This reverts commit 2e98e4bb8385b4630ed2d1dfdd8da9a35c0126b2. * Revert "Update comment_reply_view.rs" This reverts commit 857bf9f5a2413ff0e6e6c95e1157e8ce6bf9c0c3. * Revert "Remove macro_use for paste" This reverts commit 13247279ed9090f2d3c5c6525b9611529217d605. * Revert "Move WithoutId to lib.rs" This reverts commit 0c23e5213be1366bb64029e2007e97194e126676. * Revert "Fix errors" This reverts commit a283d155e5622bba0b6df8b07649fc246df8bb77. * Revert "cargo fmt" This reverts commit 36a5210352809b3ca417ec3b869ae4baaca17e16. * Revert "Fix errors" This reverts commit c9102c14f466a5d6175732625e74183579ee2be5. * Revert "Update without_id.rs" This reverts commit 19adb2fcc805f92f6720a439f3b2c80a2b866938. * Revert "Update without_id.rs" This reverts commit e26107a2fe30cc2ec81797830e3a34a1676619e4. * Revert "Fix attribute filtering in WithoutId macro" This reverts commit acaa4902b0e7e33205c5d287cd22b83732a1a401. * Revert "Only derive WithoutId for Community with "full" feature" This reverts commit de0e9c6fdc3c9344998d9d72e5e361a7f009c829. * Revert "cargo fmt" This reverts commit 5e1bd1ce58e997e9431f212fd2ee0283faaf6da3. * Revert "Add missing "|" in private_message_report_view.rs" This reverts commit c7ae9f1cd50dfead0fbc363d93692f82274ff870. * Revert "Fix syntatx errors" This reverts commit d942f099de8128b5a02fe74f5af43a4453a06350. * Revert "Update Cargo.toml" This reverts commit 23cdb6f6d3df6d2db06173f066c117a0c96dd8e1. * Revert "Add WithoutId derives" This reverts commit 06006d6ad338e946410962f4276f67fe5096ad5a. * Revert "WithoutId" This reverts commit 5e86922b0fd5bf08d114a8eee5d1e10b2ea534ee. * Revert "CommentAggregatesNotInComment" This reverts commit 603aede7cecacd246664f7f3f0047202f80d9938. * Revert "PostAggregatesNotInPost" This reverts commit 1ee3fcaeab8705e4e0e849ae6b93b45716aa9cc0. * Restore original position of options.saved_only filter * rerun ci * Update post_view.rs * rerun ci
2023-08-08 09:41:10 +00:00
ExpressionMethods,
NullableExpressionMethods,
QueryDsl,
Queryable,
};
2022-11-09 10:05:00 +00:00
use diesel_async::RunQueryDsl;
2020-12-06 03:49:15 +00:00
2022-11-09 10:05:00 +00:00
#[async_trait]
impl Crud for Community {
type InsertForm = CommunityInsertForm;
type UpdateForm = CommunityUpdateForm;
type IdType = CommunityId;
2019-04-16 23:04:23 +00:00
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
let is_new_community = match &form.actor_id {
Some(id) => Community::read_from_apub_id(pool, id).await?.is_none(),
None => true,
};
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
let conn = &mut get_conn(pool).await?;
// Can't do separate insert/update commands because InsertForm/UpdateForm aren't convertible
let community_ = insert_into(community::table)
.values(form)
.on_conflict(community::actor_id)
.do_update()
.set(form)
2022-11-09 10:05:00 +00:00
.get_result::<Self>(conn)
.await?;
// Initialize languages for new community
if is_new_community {
2022-11-09 10:05:00 +00:00
CommunityLanguage::update(pool, vec![], community_.id).await?;
}
Ok(community_)
2019-04-16 23:04:23 +00:00
}
2022-11-09 10:05:00 +00:00
async fn update(
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
pool: &mut DbPool<'_>,
community_id: CommunityId,
form: &Self::UpdateForm,
) -> Result<Self, Error> {
2022-11-09 10:05:00 +00:00
let conn = &mut get_conn(pool).await?;
diesel::update(community::table.find(community_id))
.set(form)
.get_result::<Self>(conn)
2022-11-09 10:05:00 +00:00
.await
}
}
2022-11-09 10:05:00 +00:00
#[async_trait]
impl Joinable for CommunityModerator {
type Form = CommunityModeratorForm;
2022-11-09 10:05:00 +00:00
async fn join(
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
pool: &mut DbPool<'_>,
2021-02-26 13:49:58 +00:00
community_moderator_form: &CommunityModeratorForm,
) -> Result<Self, Error> {
use crate::schema::community_moderator::dsl::community_moderator;
2022-11-09 10:05:00 +00:00
let conn = &mut get_conn(pool).await?;
2019-04-16 23:04:23 +00:00
insert_into(community_moderator)
2021-02-26 13:49:58 +00:00
.values(community_moderator_form)
2019-04-16 23:04:23 +00:00
.get_result::<Self>(conn)
2022-11-09 10:05:00 +00:00
.await
2019-04-16 23:04:23 +00:00
}
2022-11-09 10:05:00 +00:00
async fn leave(
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
pool: &mut DbPool<'_>,
2021-02-26 13:49:58 +00:00
community_moderator_form: &CommunityModeratorForm,
) -> Result<usize, Error> {
Remove id column and use different primary key on some tables (#4093) * post_saved * fmt * remove unique and not null * put person_id first in primary key and remove index * use post_saved.find * change captcha_answer * remove removal of not null * comment_aggregates * comment_like * comment_saved * aggregates * remove "\" * deduplicate site_aggregates * person_post_aggregates * community_moderator * community_block * community_person_ban * custom_emoji_keyword * federation allow/block list * federation_queue_state * instance_block * local_site_rate_limit, local_user_language, login_token * person_ban, person_block, person_follower, post_like, post_read, received_activity * community_follower, community_language, site_language * fmt * image_upload * remove unused newtypes * remove more indexes * use .find * merge * fix site_aggregates_site function * fmt * Primary keys dess (#17) * Also order reports by oldest first (ref #4123) (#4129) * Support signed fetch for federation (fixes #868) (#4125) * Support signed fetch for federation (fixes #868) * taplo * add federation queue state to get_federated_instances api (#4104) * add federation queue state to get_federated_instances api * feature gate * move retry sleep function * move stuff around * Add UI setting for collapsing bot comments. Fixes #3838 (#4098) * Add UI setting for collapsing bot comments. Fixes #3838 * Fixing clippy check. * Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131) * Only check auth secure on release mode. (#4127) * Only check auth secure on release mode. * Fixing wrong js-client. * Adding is_debug_mode var. * Fixing the desktop image on the README. (#4135) * Delete dupes and add possibly missing unique constraint on person_aggregates. * Fixing clippy lints. --------- Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com> * fmt * Update community_block.rs * Update instance_block.rs * Update person_block.rs * Update person_block.rs --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
use crate::schema::community_moderator::dsl::community_moderator;
2022-11-09 10:05:00 +00:00
let conn = &mut get_conn(pool).await?;
Remove id column and use different primary key on some tables (#4093) * post_saved * fmt * remove unique and not null * put person_id first in primary key and remove index * use post_saved.find * change captcha_answer * remove removal of not null * comment_aggregates * comment_like * comment_saved * aggregates * remove "\" * deduplicate site_aggregates * person_post_aggregates * community_moderator * community_block * community_person_ban * custom_emoji_keyword * federation allow/block list * federation_queue_state * instance_block * local_site_rate_limit, local_user_language, login_token * person_ban, person_block, person_follower, post_like, post_read, received_activity * community_follower, community_language, site_language * fmt * image_upload * remove unused newtypes * remove more indexes * use .find * merge * fix site_aggregates_site function * fmt * Primary keys dess (#17) * Also order reports by oldest first (ref #4123) (#4129) * Support signed fetch for federation (fixes #868) (#4125) * Support signed fetch for federation (fixes #868) * taplo * add federation queue state to get_federated_instances api (#4104) * add federation queue state to get_federated_instances api * feature gate * move retry sleep function * move stuff around * Add UI setting for collapsing bot comments. Fixes #3838 (#4098) * Add UI setting for collapsing bot comments. Fixes #3838 * Fixing clippy check. * Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131) * Only check auth secure on release mode. (#4127) * Only check auth secure on release mode. * Fixing wrong js-client. * Adding is_debug_mode var. * Fixing the desktop image on the README. (#4135) * Delete dupes and add possibly missing unique constraint on person_aggregates. * Fixing clippy lints. --------- Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com> * fmt * Update community_block.rs * Update instance_block.rs * Update person_block.rs * Update person_block.rs --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
diesel::delete(community_moderator.find((
community_moderator_form.person_id,
community_moderator_form.community_id,
)))
.execute(conn)
2022-11-09 10:05:00 +00:00
.await
2019-04-16 23:04:23 +00:00
}
}
pub enum CollectionType {
Moderators,
Featured,
}
impl Community {
/// Get the community which has a given moderators or featured url, also return the collection type
pub async fn get_by_collection_url(
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
pool: &mut DbPool<'_>,
url: &DbUrl,
) -> Result<(Community, CollectionType), Error> {
use crate::schema::community::dsl::{featured_url, moderators_url};
use CollectionType::*;
let conn = &mut get_conn(pool).await?;
let res = community::table
.filter(moderators_url.eq(url))
.first::<Self>(conn)
.await;
if let Ok(c) = res {
return Ok((c, Moderators));
}
let res = community::table
.filter(featured_url.eq(url))
.first::<Self>(conn)
.await;
if let Ok(c) = res {
return Ok((c, Featured));
}
Err(diesel::NotFound)
}
pub async fn set_featured_posts(
community_id: CommunityId,
posts: Vec<Post>,
pool: &mut DbPool<'_>,
) -> Result<(), Error> {
use crate::schema::post;
let conn = &mut get_conn(pool).await?;
for p in &posts {
debug_assert!(p.community_id == community_id);
}
conn
.build_transaction()
.run(|conn| {
Box::pin(async move {
update(
// first remove all existing featured posts
post::table,
)
.filter(post::dsl::community_id.eq(community_id))
.set(post::dsl::featured_community.eq(false))
.execute(conn)
.await?;
// then mark the given posts as featured
let post_ids: Vec<_> = posts.iter().map(|p| p.id).collect();
update(post::table)
.filter(post::dsl::id.eq_any(post_ids))
.set(post::dsl::featured_community.eq(true))
.execute(conn)
.await?;
Ok(())
}) as _
})
.await
}
}
2021-10-16 13:33:38 +00:00
impl CommunityModerator {
2022-11-09 10:05:00 +00:00
pub async fn delete_for_community(
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
pool: &mut DbPool<'_>,
for_community_id: CommunityId,
) -> Result<usize, Error> {
use crate::schema::community_moderator::dsl::{community_id, community_moderator};
2022-11-09 10:05:00 +00:00
let conn = &mut get_conn(pool).await?;
diesel::delete(community_moderator.filter(community_id.eq(for_community_id)))
.execute(conn)
.await
}
pub async fn leave_all_communities(
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
pool: &mut DbPool<'_>,
for_person_id: PersonId,
) -> Result<usize, Error> {
use crate::schema::community_moderator::dsl::{community_moderator, person_id};
let conn = &mut get_conn(pool).await?;
diesel::delete(community_moderator.filter(person_id.eq(for_person_id)))
.execute(conn)
.await
}
2022-11-09 10:05:00 +00:00
pub async fn get_person_moderated_communities(
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
pool: &mut DbPool<'_>,
for_person_id: PersonId,
) -> Result<Vec<CommunityId>, Error> {
use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id};
2022-11-09 10:05:00 +00:00
let conn = &mut get_conn(pool).await?;
community_moderator
2021-02-26 13:49:58 +00:00
.filter(person_id.eq(for_person_id))
.select(community_id)
.load::<CommunityId>(conn)
2022-11-09 10:05:00 +00:00
.await
}
}
2022-11-09 10:05:00 +00:00
#[async_trait]
impl Bannable for CommunityPersonBan {
type Form = CommunityPersonBanForm;
2022-11-09 10:05:00 +00:00
async fn ban(
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
pool: &mut DbPool<'_>,
2021-02-26 13:49:58 +00:00
community_person_ban_form: &CommunityPersonBanForm,
) -> Result<Self, Error> {
use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id};
2022-11-09 10:05:00 +00:00
let conn = &mut get_conn(pool).await?;
2021-02-26 13:49:58 +00:00
insert_into(community_person_ban)
.values(community_person_ban_form)
.on_conflict((community_id, person_id))
.do_update()
.set(community_person_ban_form)
2019-04-16 23:04:23 +00:00
.get_result::<Self>(conn)
2022-11-09 10:05:00 +00:00
.await
2019-04-16 23:04:23 +00:00
}
2022-11-09 10:05:00 +00:00
async fn unban(
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
pool: &mut DbPool<'_>,
2021-02-26 13:49:58 +00:00
community_person_ban_form: &CommunityPersonBanForm,
) -> Result<usize, Error> {
Remove id column and use different primary key on some tables (#4093) * post_saved * fmt * remove unique and not null * put person_id first in primary key and remove index * use post_saved.find * change captcha_answer * remove removal of not null * comment_aggregates * comment_like * comment_saved * aggregates * remove "\" * deduplicate site_aggregates * person_post_aggregates * community_moderator * community_block * community_person_ban * custom_emoji_keyword * federation allow/block list * federation_queue_state * instance_block * local_site_rate_limit, local_user_language, login_token * person_ban, person_block, person_follower, post_like, post_read, received_activity * community_follower, community_language, site_language * fmt * image_upload * remove unused newtypes * remove more indexes * use .find * merge * fix site_aggregates_site function * fmt * Primary keys dess (#17) * Also order reports by oldest first (ref #4123) (#4129) * Support signed fetch for federation (fixes #868) (#4125) * Support signed fetch for federation (fixes #868) * taplo * add federation queue state to get_federated_instances api (#4104) * add federation queue state to get_federated_instances api * feature gate * move retry sleep function * move stuff around * Add UI setting for collapsing bot comments. Fixes #3838 (#4098) * Add UI setting for collapsing bot comments. Fixes #3838 * Fixing clippy check. * Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131) * Only check auth secure on release mode. (#4127) * Only check auth secure on release mode. * Fixing wrong js-client. * Adding is_debug_mode var. * Fixing the desktop image on the README. (#4135) * Delete dupes and add possibly missing unique constraint on person_aggregates. * Fixing clippy lints. --------- Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com> * fmt * Update community_block.rs * Update instance_block.rs * Update person_block.rs * Update person_block.rs --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
use crate::schema::community_person_ban::dsl::community_person_ban;
2022-11-09 10:05:00 +00:00
let conn = &mut get_conn(pool).await?;
Remove id column and use different primary key on some tables (#4093) * post_saved * fmt * remove unique and not null * put person_id first in primary key and remove index * use post_saved.find * change captcha_answer * remove removal of not null * comment_aggregates * comment_like * comment_saved * aggregates * remove "\" * deduplicate site_aggregates * person_post_aggregates * community_moderator * community_block * community_person_ban * custom_emoji_keyword * federation allow/block list * federation_queue_state * instance_block * local_site_rate_limit, local_user_language, login_token * person_ban, person_block, person_follower, post_like, post_read, received_activity * community_follower, community_language, site_language * fmt * image_upload * remove unused newtypes * remove more indexes * use .find * merge * fix site_aggregates_site function * fmt * Primary keys dess (#17) * Also order reports by oldest first (ref #4123) (#4129) * Support signed fetch for federation (fixes #868) (#4125) * Support signed fetch for federation (fixes #868) * taplo * add federation queue state to get_federated_instances api (#4104) * add federation queue state to get_federated_instances api * feature gate * move retry sleep function * move stuff around * Add UI setting for collapsing bot comments. Fixes #3838 (#4098) * Add UI setting for collapsing bot comments. Fixes #3838 * Fixing clippy check. * Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131) * Only check auth secure on release mode. (#4127) * Only check auth secure on release mode. * Fixing wrong js-client. * Adding is_debug_mode var. * Fixing the desktop image on the README. (#4135) * Delete dupes and add possibly missing unique constraint on person_aggregates. * Fixing clippy lints. --------- Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com> * fmt * Update community_block.rs * Update instance_block.rs * Update person_block.rs * Update person_block.rs --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
diesel::delete(community_person_ban.find((
community_person_ban_form.person_id,
community_person_ban_form.community_id,
)))
.execute(conn)
2022-11-09 10:05:00 +00:00
.await
2019-04-16 23:04:23 +00:00
}
}
impl CommunityFollower {
pub fn to_subscribed_type(follower: &Option<Self>) -> SubscribedType {
match follower {
Some(f) => {
if f.pending {
SubscribedType::Pending
} else {
SubscribedType::Subscribed
}
}
// If the row doesn't exist, the person isn't a follower.
None => SubscribedType::NotSubscribed,
}
}
Reduce amount of columns selected (#3755) * PostAggregatesNotInPost * CommentAggregatesNotInComment * CommunityPersonBanAdditionalInfo (partial) * Revert "CommunityPersonBanAdditionalInfo (partial)" This reverts commit 158f7f0cd9a07392fb1f457ac43c8d7c57e4190d. * Replace some nullable parts of selection with id::nullable().is_not_null() * CommunityFollower::select_subscribed_type * WithoutId * Add WithoutId derives * Update Cargo.toml * rerun ci * Fix syntatx errors * rerun ci * Add missing "|" in private_message_report_view.rs * rerun ci * cargo fmt * rerun ci * Only derive WithoutId for Community with "full" feature * rerun ci * Fix attribute filtering in WithoutId macro * rerun ci * Update without_id.rs * rerun ci * Update without_id.rs * rerun ci * Fix errors * rerun ci * cargo fmt * Fix errors * rerun ci * Move WithoutId to lib.rs * rerun ci * Remove macro_use for paste * rerun ci * Update comment_reply_view.rs * rerun ci * Update registration_application_view.rs * rerun ci * Revert "Update registration_application_view.rs" This reverts commit 2e98e4bb8385b4630ed2d1dfdd8da9a35c0126b2. * Revert "Update comment_reply_view.rs" This reverts commit 857bf9f5a2413ff0e6e6c95e1157e8ce6bf9c0c3. * Revert "Remove macro_use for paste" This reverts commit 13247279ed9090f2d3c5c6525b9611529217d605. * Revert "Move WithoutId to lib.rs" This reverts commit 0c23e5213be1366bb64029e2007e97194e126676. * Revert "Fix errors" This reverts commit a283d155e5622bba0b6df8b07649fc246df8bb77. * Revert "cargo fmt" This reverts commit 36a5210352809b3ca417ec3b869ae4baaca17e16. * Revert "Fix errors" This reverts commit c9102c14f466a5d6175732625e74183579ee2be5. * Revert "Update without_id.rs" This reverts commit 19adb2fcc805f92f6720a439f3b2c80a2b866938. * Revert "Update without_id.rs" This reverts commit e26107a2fe30cc2ec81797830e3a34a1676619e4. * Revert "Fix attribute filtering in WithoutId macro" This reverts commit acaa4902b0e7e33205c5d287cd22b83732a1a401. * Revert "Only derive WithoutId for Community with "full" feature" This reverts commit de0e9c6fdc3c9344998d9d72e5e361a7f009c829. * Revert "cargo fmt" This reverts commit 5e1bd1ce58e997e9431f212fd2ee0283faaf6da3. * Revert "Add missing "|" in private_message_report_view.rs" This reverts commit c7ae9f1cd50dfead0fbc363d93692f82274ff870. * Revert "Fix syntatx errors" This reverts commit d942f099de8128b5a02fe74f5af43a4453a06350. * Revert "Update Cargo.toml" This reverts commit 23cdb6f6d3df6d2db06173f066c117a0c96dd8e1. * Revert "Add WithoutId derives" This reverts commit 06006d6ad338e946410962f4276f67fe5096ad5a. * Revert "WithoutId" This reverts commit 5e86922b0fd5bf08d114a8eee5d1e10b2ea534ee. * Revert "CommentAggregatesNotInComment" This reverts commit 603aede7cecacd246664f7f3f0047202f80d9938. * Revert "PostAggregatesNotInPost" This reverts commit 1ee3fcaeab8705e4e0e849ae6b93b45716aa9cc0. * Restore original position of options.saved_only filter * rerun ci * Update post_view.rs * rerun ci
2023-08-08 09:41:10 +00:00
pub fn select_subscribed_type() -> dsl::Nullable<community_follower::pending> {
community_follower::pending.nullable()
}
/// Check if a remote instance has any followers on local instance. For this it is enough to check
/// if any follow relation is stored. Dont use this for local community.
pub async fn has_local_followers(
pool: &mut DbPool<'_>,
remote_community_id: CommunityId,
) -> Result<bool, Error> {
use crate::schema::community_follower::dsl::{community_follower, community_id};
let conn = &mut get_conn(pool).await?;
select(exists(
community_follower.filter(community_id.eq(remote_community_id)),
))
.get_result(conn)
.await
}
Reduce amount of columns selected (#3755) * PostAggregatesNotInPost * CommentAggregatesNotInComment * CommunityPersonBanAdditionalInfo (partial) * Revert "CommunityPersonBanAdditionalInfo (partial)" This reverts commit 158f7f0cd9a07392fb1f457ac43c8d7c57e4190d. * Replace some nullable parts of selection with id::nullable().is_not_null() * CommunityFollower::select_subscribed_type * WithoutId * Add WithoutId derives * Update Cargo.toml * rerun ci * Fix syntatx errors * rerun ci * Add missing "|" in private_message_report_view.rs * rerun ci * cargo fmt * rerun ci * Only derive WithoutId for Community with "full" feature * rerun ci * Fix attribute filtering in WithoutId macro * rerun ci * Update without_id.rs * rerun ci * Update without_id.rs * rerun ci * Fix errors * rerun ci * cargo fmt * Fix errors * rerun ci * Move WithoutId to lib.rs * rerun ci * Remove macro_use for paste * rerun ci * Update comment_reply_view.rs * rerun ci * Update registration_application_view.rs * rerun ci * Revert "Update registration_application_view.rs" This reverts commit 2e98e4bb8385b4630ed2d1dfdd8da9a35c0126b2. * Revert "Update comment_reply_view.rs" This reverts commit 857bf9f5a2413ff0e6e6c95e1157e8ce6bf9c0c3. * Revert "Remove macro_use for paste" This reverts commit 13247279ed9090f2d3c5c6525b9611529217d605. * Revert "Move WithoutId to lib.rs" This reverts commit 0c23e5213be1366bb64029e2007e97194e126676. * Revert "Fix errors" This reverts commit a283d155e5622bba0b6df8b07649fc246df8bb77. * Revert "cargo fmt" This reverts commit 36a5210352809b3ca417ec3b869ae4baaca17e16. * Revert "Fix errors" This reverts commit c9102c14f466a5d6175732625e74183579ee2be5. * Revert "Update without_id.rs" This reverts commit 19adb2fcc805f92f6720a439f3b2c80a2b866938. * Revert "Update without_id.rs" This reverts commit e26107a2fe30cc2ec81797830e3a34a1676619e4. * Revert "Fix attribute filtering in WithoutId macro" This reverts commit acaa4902b0e7e33205c5d287cd22b83732a1a401. * Revert "Only derive WithoutId for Community with "full" feature" This reverts commit de0e9c6fdc3c9344998d9d72e5e361a7f009c829. * Revert "cargo fmt" This reverts commit 5e1bd1ce58e997e9431f212fd2ee0283faaf6da3. * Revert "Add missing "|" in private_message_report_view.rs" This reverts commit c7ae9f1cd50dfead0fbc363d93692f82274ff870. * Revert "Fix syntatx errors" This reverts commit d942f099de8128b5a02fe74f5af43a4453a06350. * Revert "Update Cargo.toml" This reverts commit 23cdb6f6d3df6d2db06173f066c117a0c96dd8e1. * Revert "Add WithoutId derives" This reverts commit 06006d6ad338e946410962f4276f67fe5096ad5a. * Revert "WithoutId" This reverts commit 5e86922b0fd5bf08d114a8eee5d1e10b2ea534ee. * Revert "CommentAggregatesNotInComment" This reverts commit 603aede7cecacd246664f7f3f0047202f80d9938. * Revert "PostAggregatesNotInPost" This reverts commit 1ee3fcaeab8705e4e0e849ae6b93b45716aa9cc0. * Restore original position of options.saved_only filter * rerun ci * Update post_view.rs * rerun ci
2023-08-08 09:41:10 +00:00
}
impl Queryable<sql_types::Nullable<sql_types::Bool>, Pg> for SubscribedType {
type Row = Option<bool>;
fn build(row: Self::Row) -> deserialize::Result<Self> {
Ok(match row {
Some(true) => SubscribedType::Pending,
Some(false) => SubscribedType::Subscribed,
None => SubscribedType::NotSubscribed,
})
}
}
2022-11-09 10:05:00 +00:00
#[async_trait]
impl Followable for CommunityFollower {
type Form = CommunityFollowerForm;
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
async fn follow(pool: &mut DbPool<'_>, form: &CommunityFollowerForm) -> Result<Self, Error> {
use crate::schema::community_follower::dsl::{community_follower, community_id, person_id};
2022-11-09 10:05:00 +00:00
let conn = &mut get_conn(pool).await?;
2019-03-04 16:39:07 +00:00
insert_into(community_follower)
.values(form)
2021-03-10 22:33:55 +00:00
.on_conflict((community_id, person_id))
.do_update()
.set(form)
.get_result::<Self>(conn)
2022-11-09 10:05:00 +00:00
.await
2019-03-04 16:39:07 +00:00
}
2022-11-09 10:05:00 +00:00
async fn follow_accepted(
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
pool: &mut DbPool<'_>,
Remove id column and use different primary key on some tables (#4093) * post_saved * fmt * remove unique and not null * put person_id first in primary key and remove index * use post_saved.find * change captcha_answer * remove removal of not null * comment_aggregates * comment_like * comment_saved * aggregates * remove "\" * deduplicate site_aggregates * person_post_aggregates * community_moderator * community_block * community_person_ban * custom_emoji_keyword * federation allow/block list * federation_queue_state * instance_block * local_site_rate_limit, local_user_language, login_token * person_ban, person_block, person_follower, post_like, post_read, received_activity * community_follower, community_language, site_language * fmt * image_upload * remove unused newtypes * remove more indexes * use .find * merge * fix site_aggregates_site function * fmt * Primary keys dess (#17) * Also order reports by oldest first (ref #4123) (#4129) * Support signed fetch for federation (fixes #868) (#4125) * Support signed fetch for federation (fixes #868) * taplo * add federation queue state to get_federated_instances api (#4104) * add federation queue state to get_federated_instances api * feature gate * move retry sleep function * move stuff around * Add UI setting for collapsing bot comments. Fixes #3838 (#4098) * Add UI setting for collapsing bot comments. Fixes #3838 * Fixing clippy check. * Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131) * Only check auth secure on release mode. (#4127) * Only check auth secure on release mode. * Fixing wrong js-client. * Adding is_debug_mode var. * Fixing the desktop image on the README. (#4135) * Delete dupes and add possibly missing unique constraint on person_aggregates. * Fixing clippy lints. --------- Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com> * fmt * Update community_block.rs * Update instance_block.rs * Update person_block.rs * Update person_block.rs --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
community_id: CommunityId,
person_id: PersonId,
2022-11-09 10:05:00 +00:00
) -> Result<Self, Error> {
Remove id column and use different primary key on some tables (#4093) * post_saved * fmt * remove unique and not null * put person_id first in primary key and remove index * use post_saved.find * change captcha_answer * remove removal of not null * comment_aggregates * comment_like * comment_saved * aggregates * remove "\" * deduplicate site_aggregates * person_post_aggregates * community_moderator * community_block * community_person_ban * custom_emoji_keyword * federation allow/block list * federation_queue_state * instance_block * local_site_rate_limit, local_user_language, login_token * person_ban, person_block, person_follower, post_like, post_read, received_activity * community_follower, community_language, site_language * fmt * image_upload * remove unused newtypes * remove more indexes * use .find * merge * fix site_aggregates_site function * fmt * Primary keys dess (#17) * Also order reports by oldest first (ref #4123) (#4129) * Support signed fetch for federation (fixes #868) (#4125) * Support signed fetch for federation (fixes #868) * taplo * add federation queue state to get_federated_instances api (#4104) * add federation queue state to get_federated_instances api * feature gate * move retry sleep function * move stuff around * Add UI setting for collapsing bot comments. Fixes #3838 (#4098) * Add UI setting for collapsing bot comments. Fixes #3838 * Fixing clippy check. * Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131) * Only check auth secure on release mode. (#4127) * Only check auth secure on release mode. * Fixing wrong js-client. * Adding is_debug_mode var. * Fixing the desktop image on the README. (#4135) * Delete dupes and add possibly missing unique constraint on person_aggregates. * Fixing clippy lints. --------- Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com> * fmt * Update community_block.rs * Update instance_block.rs * Update person_block.rs * Update person_block.rs --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
use crate::schema::community_follower::dsl::{community_follower, pending};
2022-11-09 10:05:00 +00:00
let conn = &mut get_conn(pool).await?;
Remove id column and use different primary key on some tables (#4093) * post_saved * fmt * remove unique and not null * put person_id first in primary key and remove index * use post_saved.find * change captcha_answer * remove removal of not null * comment_aggregates * comment_like * comment_saved * aggregates * remove "\" * deduplicate site_aggregates * person_post_aggregates * community_moderator * community_block * community_person_ban * custom_emoji_keyword * federation allow/block list * federation_queue_state * instance_block * local_site_rate_limit, local_user_language, login_token * person_ban, person_block, person_follower, post_like, post_read, received_activity * community_follower, community_language, site_language * fmt * image_upload * remove unused newtypes * remove more indexes * use .find * merge * fix site_aggregates_site function * fmt * Primary keys dess (#17) * Also order reports by oldest first (ref #4123) (#4129) * Support signed fetch for federation (fixes #868) (#4125) * Support signed fetch for federation (fixes #868) * taplo * add federation queue state to get_federated_instances api (#4104) * add federation queue state to get_federated_instances api * feature gate * move retry sleep function * move stuff around * Add UI setting for collapsing bot comments. Fixes #3838 (#4098) * Add UI setting for collapsing bot comments. Fixes #3838 * Fixing clippy check. * Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131) * Only check auth secure on release mode. (#4127) * Only check auth secure on release mode. * Fixing wrong js-client. * Adding is_debug_mode var. * Fixing the desktop image on the README. (#4135) * Delete dupes and add possibly missing unique constraint on person_aggregates. * Fixing clippy lints. --------- Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com> * fmt * Update community_block.rs * Update instance_block.rs * Update person_block.rs * Update person_block.rs --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
diesel::update(community_follower.find((person_id, community_id)))
.set(pending.eq(false))
.get_result::<Self>(conn)
.await
}
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
async fn unfollow(pool: &mut DbPool<'_>, form: &CommunityFollowerForm) -> Result<usize, Error> {
Remove id column and use different primary key on some tables (#4093) * post_saved * fmt * remove unique and not null * put person_id first in primary key and remove index * use post_saved.find * change captcha_answer * remove removal of not null * comment_aggregates * comment_like * comment_saved * aggregates * remove "\" * deduplicate site_aggregates * person_post_aggregates * community_moderator * community_block * community_person_ban * custom_emoji_keyword * federation allow/block list * federation_queue_state * instance_block * local_site_rate_limit, local_user_language, login_token * person_ban, person_block, person_follower, post_like, post_read, received_activity * community_follower, community_language, site_language * fmt * image_upload * remove unused newtypes * remove more indexes * use .find * merge * fix site_aggregates_site function * fmt * Primary keys dess (#17) * Also order reports by oldest first (ref #4123) (#4129) * Support signed fetch for federation (fixes #868) (#4125) * Support signed fetch for federation (fixes #868) * taplo * add federation queue state to get_federated_instances api (#4104) * add federation queue state to get_federated_instances api * feature gate * move retry sleep function * move stuff around * Add UI setting for collapsing bot comments. Fixes #3838 (#4098) * Add UI setting for collapsing bot comments. Fixes #3838 * Fixing clippy check. * Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131) * Only check auth secure on release mode. (#4127) * Only check auth secure on release mode. * Fixing wrong js-client. * Adding is_debug_mode var. * Fixing the desktop image on the README. (#4135) * Delete dupes and add possibly missing unique constraint on person_aggregates. * Fixing clippy lints. --------- Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com> * fmt * Update community_block.rs * Update instance_block.rs * Update person_block.rs * Update person_block.rs --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
use crate::schema::community_follower::dsl::community_follower;
2022-11-09 10:05:00 +00:00
let conn = &mut get_conn(pool).await?;
Remove id column and use different primary key on some tables (#4093) * post_saved * fmt * remove unique and not null * put person_id first in primary key and remove index * use post_saved.find * change captcha_answer * remove removal of not null * comment_aggregates * comment_like * comment_saved * aggregates * remove "\" * deduplicate site_aggregates * person_post_aggregates * community_moderator * community_block * community_person_ban * custom_emoji_keyword * federation allow/block list * federation_queue_state * instance_block * local_site_rate_limit, local_user_language, login_token * person_ban, person_block, person_follower, post_like, post_read, received_activity * community_follower, community_language, site_language * fmt * image_upload * remove unused newtypes * remove more indexes * use .find * merge * fix site_aggregates_site function * fmt * Primary keys dess (#17) * Also order reports by oldest first (ref #4123) (#4129) * Support signed fetch for federation (fixes #868) (#4125) * Support signed fetch for federation (fixes #868) * taplo * add federation queue state to get_federated_instances api (#4104) * add federation queue state to get_federated_instances api * feature gate * move retry sleep function * move stuff around * Add UI setting for collapsing bot comments. Fixes #3838 (#4098) * Add UI setting for collapsing bot comments. Fixes #3838 * Fixing clippy check. * Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131) * Only check auth secure on release mode. (#4127) * Only check auth secure on release mode. * Fixing wrong js-client. * Adding is_debug_mode var. * Fixing the desktop image on the README. (#4135) * Delete dupes and add possibly missing unique constraint on person_aggregates. * Fixing clippy lints. --------- Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com> * fmt * Update community_block.rs * Update instance_block.rs * Update person_block.rs * Update person_block.rs --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
diesel::delete(community_follower.find((form.person_id, form.community_id)))
.execute(conn)
.await
2019-03-04 16:39:07 +00:00
}
}
2022-11-09 10:05:00 +00:00
#[async_trait]
impl ApubActor for Community {
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
async fn read_from_apub_id(
pool: &mut DbPool<'_>,
object_id: &DbUrl,
) -> Result<Option<Self>, Error> {
2022-11-09 10:05:00 +00:00
let conn = &mut get_conn(pool).await?;
Ok(
community::table
.filter(community::actor_id.eq(object_id))
.first::<Community>(conn)
2022-11-09 10:05:00 +00:00
.await
.ok()
.map(Into::into),
)
}
2022-11-09 10:05:00 +00:00
async fn read_from_name(
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
pool: &mut DbPool<'_>,
community_name: &str,
include_deleted: bool,
) -> Result<Community, Error> {
2022-11-09 10:05:00 +00:00
let conn = &mut get_conn(pool).await?;
let mut q = community::table
.into_boxed()
.filter(community::local.eq(true))
.filter(lower(community::name).eq(community_name.to_lowercase()));
if !include_deleted {
q = q
.filter(community::deleted.eq(false))
.filter(community::removed.eq(false));
}
2022-11-09 10:05:00 +00:00
q.first::<Self>(conn).await
}
2022-11-09 10:05:00 +00:00
async fn read_from_name_and_domain(
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
pool: &mut DbPool<'_>,
community_name: &str,
for_domain: &str,
) -> Result<Community, Error> {
2022-11-09 10:05:00 +00:00
let conn = &mut get_conn(pool).await?;
community::table
.inner_join(instance::table)
.filter(lower(community::name).eq(community_name.to_lowercase()))
.filter(lower(instance::domain).eq(for_domain.to_lowercase()))
.select(community::all_columns)
.first::<Self>(conn)
2022-11-09 10:05:00 +00:00
.await
}
}
2019-03-04 16:39:07 +00:00
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]
#![allow(clippy::indexing_slicing)]
2021-10-16 13:33:38 +00:00
use crate::{
source::{
community::{
Community,
CommunityFollower,
CommunityFollowerForm,
CommunityInsertForm,
CommunityModerator,
CommunityModeratorForm,
CommunityPersonBan,
CommunityPersonBanForm,
CommunityUpdateForm,
},
instance::Instance,
person::{Person, PersonInsertForm},
},
2021-10-16 13:33:38 +00:00
traits::{Bannable, Crud, Followable, Joinable},
2022-11-09 10:05:00 +00:00
utils::build_db_pool_for_tests,
CommunityVisibility,
2021-10-16 13:33:38 +00:00
};
use pretty_assertions::assert_eq;
use serial_test::serial;
2020-05-16 14:04:08 +00:00
2022-11-09 10:05:00 +00:00
#[tokio::test]
#[serial]
2022-11-09 10:05:00 +00:00
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
Make functions work with both connection and pool (#3420) * a lot * merge * Fix stuff broken by merge * Get rid of repetitive `&mut *context.conn().await?` * Add blank lines under each line with `conn =` * Fix style mistakes (partial) * Revert "Fix style mistakes (partial)" This reverts commit 48a033b87f4fdc1ce14ff86cc019e1c703cd2741. * Revert "Add blank lines under each line with `conn =`" This reverts commit 773a6d3beba2cf89eac75913078b40c4f5190dd4. * Revert "Get rid of repetitive `&mut *context.conn().await?`" This reverts commit d2c6263ea13710177d49b2791278db5ad115fca5. * Use DbConn for CaptchaAnswer methods * DbConn trait * Remove more `&mut *` * Fix stuff * Re-run CI * try to make ci start * fix * fix * Fix api_common::utils * Fix apub::activities::block * Fix apub::api::resolve_object * Fix some things * Revert "Fix some things" This reverts commit 2bf8574bc8333d8d34ca542d61a0a5b50039c24d. * Revert "Fix apub::api::resolve_object" This reverts commit 3e4059aabbe485b2ff060bdeced8ef958ff62832. * Revert "Fix apub::activities::block" This reverts commit 3b02389abd780a7b1b8a2c89e26febdaa6a12159. * Revert "Fix api_common::utils" This reverts commit 7dc73de613a5618fa57eb06450f3699bbcb41254. * Revert "Revert "Fix api_common::utils"" This reverts commit f740f115e5457e83e53cc223e48196a2c47a9975. * Revert "Revert "Fix apub::activities::block"" This reverts commit 2ee206af7c885c10092cf209bf4a5b1d60327866. * Revert "Revert "Fix apub::api::resolve_object"" This reverts commit 96ed8bf2e9dcadae760743929498312334e23d2e. * Fix fetch_local_site_data * Fix get_comment_parent_creator * Remove unused perma deleted text * Fix routes::feeds * Fix lib.rs * Update lib.rs * rerun ci * Attempt to create custom GetConn and RunQueryDsl traits * Start over * Add GetConn trait * aaaa * Revert "aaaa" This reverts commit acc9ca1aed10c39efdd91cefece066e035a1fe80. * Revert "Revert "aaaa"" This reverts commit 443a2a00a56d152bb7eb429efd0d29a78e21b163. * still aaaaaaaaaaaaa * Return to earlier thing Revert "Add GetConn trait" This reverts commit ab4e94aea5bd9d34cbcddf017339131047e75344. * Try to use DbPool enum * Revert "Try to use DbPool enum" This reverts commit e4d1712646a52006b865a1fbe0dcf79976fdb027. * DbConn and DbPool enums (db_schema only fails to compile for tests) * fmt * Make functions take `&mut DbPool<'_>` and make db_schema tests compile * Add try_join_with_pool macro and run fix-clippy on more crates * Fix some errors * I did it * Remove function variants that take connection * rerun ci * rerun ci * rerun ci
2023-07-11 13:09:59 +00:00
let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
.unwrap();
let new_person = PersonInsertForm::builder()
.name("bobbee".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
2022-11-09 10:05:00 +00:00
let inserted_person = Person::create(pool, &new_person).await.unwrap();
let new_community = CommunityInsertForm::builder()
.name("TIL".into())
.title("nada".to_owned())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
2019-03-04 16:39:07 +00:00
2022-11-09 10:05:00 +00:00
let inserted_community = Community::create(pool, &new_community).await.unwrap();
2019-03-04 16:39:07 +00:00
let expected_community = Community {
id: inserted_community.id,
name: "TIL".into(),
title: "nada".to_owned(),
description: None,
nsfw: false,
removed: false,
deleted: false,
published: inserted_community.published,
updated: None,
actor_id: inserted_community.actor_id.clone(),
local: true,
private_key: None,
public_key: "pubkey".to_owned(),
last_refreshed_at: inserted_community.published,
icon: None,
banner: None,
followers_url: inserted_community.followers_url.clone(),
inbox_url: inserted_community.inbox_url.clone(),
shared_inbox_url: None,
moderators_url: None,
featured_url: None,
hidden: false,
posting_restricted_to_mods: false,
instance_id: inserted_instance.id,
visibility: CommunityVisibility::Public,
2019-03-04 16:39:07 +00:00
};
let community_follower_form = CommunityFollowerForm {
community_id: inserted_community.id,
2021-02-26 13:49:58 +00:00
person_id: inserted_person.id,
2022-05-17 18:02:48 +00:00
pending: false,
2019-03-04 16:39:07 +00:00
};
2022-11-09 10:05:00 +00:00
let inserted_community_follower = CommunityFollower::follow(pool, &community_follower_form)
.await
.unwrap();
2019-03-04 16:39:07 +00:00
let expected_community_follower = CommunityFollower {
community_id: inserted_community.id,
2021-02-26 13:49:58 +00:00
person_id: inserted_person.id,
pending: false,
published: inserted_community_follower.published,
2019-03-04 16:39:07 +00:00
};
2021-02-26 13:49:58 +00:00
let community_moderator_form = CommunityModeratorForm {
community_id: inserted_community.id,
2021-02-26 13:49:58 +00:00
person_id: inserted_person.id,
2019-03-04 16:39:07 +00:00
};
2022-11-09 10:05:00 +00:00
let inserted_community_moderator = CommunityModerator::join(pool, &community_moderator_form)
.await
.unwrap();
2019-03-04 16:39:07 +00:00
2021-02-26 13:49:58 +00:00
let expected_community_moderator = CommunityModerator {
2019-03-04 16:39:07 +00:00
community_id: inserted_community.id,
2021-02-26 13:49:58 +00:00
person_id: inserted_person.id,
published: inserted_community_moderator.published,
2019-03-04 16:39:07 +00:00
};
2021-02-26 13:49:58 +00:00
let community_person_ban_form = CommunityPersonBanForm {
community_id: inserted_community.id,
2021-02-26 13:49:58 +00:00
person_id: inserted_person.id,
expires: None,
};
2022-11-09 10:05:00 +00:00
let inserted_community_person_ban = CommunityPersonBan::ban(pool, &community_person_ban_form)
.await
.unwrap();
2021-02-26 13:49:58 +00:00
let expected_community_person_ban = CommunityPersonBan {
community_id: inserted_community.id,
2021-02-26 13:49:58 +00:00
person_id: inserted_person.id,
published: inserted_community_person_ban.published,
expires: None,
};
2022-11-09 10:05:00 +00:00
let read_community = Community::read(pool, inserted_community.id).await.unwrap();
Replace TypedBuilder with Default in update forms (#3814) * Update comment.rs * Update community.rs * Update local_site.rs * Update local_site_rate_limit.rs * Update local_user.rs * Update person.rs * Update comment.rs * Update community.rs * Update local_site.rs * Update local_site_rate_limit.rs * Update local_user.rs * Update post.rs * Update private_message.rs * Update site.rs * Update post.rs * Update person.rs * Update private_message.rs * Update comment.rs * Update create.rs * Update leave_admin.rs * Update update.rs * Update remove.rs * Update add_admin.rs * Update verify_email.rs * Update mod.rs * Update mod.rs * Update undo_delete.rs * Update undo_delete.rs * Update utils.rs * Update feature.rs * Update delete.rs * Update lock.rs * Update create.rs * Update approve.rs * Update update.rs * Update lock_page.rs * Update block_user.rs * Update delete.rs * Update undo_block_user.rs * Update collection_remove.rs * Update post.rs * Update hide.rs * Update person.rs * Update remove.rs * Update post_view.rs * Update create.rs * Update remove.rs * Update collection_add.rs * Update community.rs * Update update.rs * Update post_aggregates.rs * Update update.rs * Update comment.rs * Update code_migrations.rs * Update registration_application_view.rs * Update update.rs * Update ban_person.rs * Update community.rs * Update delete.rs * Update delete.rs * Update delete.rs * Update person_aggregates.rs * Update save_settings.rs * Update distinguish.rs * Update mark_read.rs * Update site_aggregates.rs * Update create.rs * Fix * rerun ci * Update comment.rs * rerun ci * Update create.rs * Update create.rs * Update post_view.rs * rerun ci * Update undo_delete.rs * rerun ci
2023-08-08 09:41:41 +00:00
let update_community_form = CommunityUpdateForm {
title: Some("nada".to_owned()),
..Default::default()
};
2022-11-09 10:05:00 +00:00
let updated_community = Community::update(pool, inserted_community.id, &update_community_form)
.await
.unwrap();
let ignored_community = CommunityFollower::unfollow(pool, &community_follower_form)
.await
.unwrap();
let left_community = CommunityModerator::leave(pool, &community_moderator_form)
.await
.unwrap();
let unban = CommunityPersonBan::unban(pool, &community_person_ban_form)
.await
.unwrap();
let num_deleted = Community::delete(pool, inserted_community.id)
.await
.unwrap();
Person::delete(pool, inserted_person.id).await.unwrap();
Instance::delete(pool, inserted_instance.id).await.unwrap();
2019-03-04 16:39:07 +00:00
assert_eq!(expected_community, read_community);
assert_eq!(expected_community, inserted_community);
assert_eq!(expected_community, updated_community);
assert_eq!(expected_community_follower, inserted_community_follower);
2021-02-26 13:49:58 +00:00
assert_eq!(expected_community_moderator, inserted_community_moderator);
assert_eq!(expected_community_person_ban, inserted_community_person_ban);
2019-03-04 16:39:07 +00:00
assert_eq!(1, ignored_community);
assert_eq!(1, left_community);
assert_eq!(1, unban);
// assert_eq!(2, loaded_count);
2019-03-04 16:39:07 +00:00
assert_eq!(1, num_deleted);
}
}