- /root/.cargo/bin/cargo fmt -- --check
# latest rust for clippy to get extra checks
+ # when adding new clippy lints, make sure to also add them in scripts/fix-clippy.sh
- name: cargo clippy
- image: rust:1.64-buster
+ image: rust:1.65-buster
commands:
- apt-get update
- apt-get -y install protobuf-compiler libprotobuf-dev
- rustup component add clippy
- - cargo clippy --workspace --tests --all-targets --all-features -- -D warnings -D deprecated -D clippy::perf -D clippy::complexity -D clippy::dbg_macro
+ - cargo clippy --workspace --tests --all-targets --all-features --
+ -D warnings -D deprecated -D clippy::perf -D clippy::complexity
+ -D clippy::dbg_macro -D clippy::inefficient_to_string
+ -D clippy::items-after-statements -D clippy::implicit_clone
+ -D clippy::wildcard_imports -D clippy::cast_lossless
+ -D clippy::manual_string_new -D clippy::redundant_closure_for_method_calls
- cargo clippy --workspace --all-features -- -D clippy::unwrap_used
- name: cargo test
mod_person_id: local_user_view.person.id,
other_person_id: data.person_id,
community_id: data.community_id,
- reason: data.reason.to_owned(),
+ reason: data.reason.clone(),
banned: Some(data.ban),
expires,
};
use actix_web::{web, web::Data};
use captcha::Captcha;
use lemmy_api_common::{
- comment::*,
- community::*,
- person::*,
- post::*,
- private_message::*,
- site::*,
+ comment::{
+ CreateCommentLike,
+ CreateCommentReport,
+ ListCommentReports,
+ ResolveCommentReport,
+ SaveComment,
+ },
+ community::{
+ AddModToCommunity,
+ BanFromCommunity,
+ BlockCommunity,
+ FollowCommunity,
+ TransferCommunity,
+ },
+ person::{
+ AddAdmin,
+ BanPerson,
+ BlockPerson,
+ ChangePassword,
+ GetBannedPersons,
+ GetCaptcha,
+ GetPersonMentions,
+ GetReplies,
+ GetReportCount,
+ GetUnreadCount,
+ Login,
+ MarkAllAsRead,
+ MarkCommentReplyAsRead,
+ MarkPersonMentionAsRead,
+ PasswordChangeAfterReset,
+ PasswordReset,
+ SaveUserSettings,
+ VerifyEmail,
+ },
+ post::{
+ CreatePostLike,
+ CreatePostReport,
+ GetSiteMetadata,
+ ListPostReports,
+ LockPost,
+ MarkPostAsRead,
+ ResolvePostReport,
+ SavePost,
+ StickyPost,
+ },
+ private_message::{
+ CreatePrivateMessageReport,
+ ListPrivateMessageReports,
+ MarkPrivateMessageAsRead,
+ ResolvePrivateMessageReport,
+ },
+ site::{
+ ApproveRegistrationApplication,
+ GetModlog,
+ GetUnreadRegistrationApplicationCount,
+ LeaveAdmin,
+ ListRegistrationApplications,
+ PurgeComment,
+ PurgeCommunity,
+ PurgePerson,
+ PurgePost,
+ ResolveObject,
+ Search,
+ },
utils::local_site_to_slur_regex,
- websocket::*,
+ websocket::{CommunityJoin, ModJoin, PostJoin, UserJoin},
};
use lemmy_db_schema::source::local_site::LocalSite;
use lemmy_utils::{error::LemmyError, utils::check_slurs, ConnectionId};
let form = ModBanForm {
mod_person_id: local_user_view.person.id,
other_person_id: data.person_id,
- reason: data.reason.to_owned(),
+ reason: data.reason.clone(),
banned: Some(data.ban),
expires,
};
}
let local_user_id = local_user_view.local_user.id;
- let new_password = data.new_password.to_owned();
+ let new_password = data.new_password.clone();
let updated_local_user =
LocalUser::update_password(context.pool(), local_user_id, &new_password).await?;
let captcha_item = CaptchaItem {
answer,
- uuid: uuid.to_owned(),
+ uuid: uuid.clone(),
expires: naive_now() + Duration::minutes(10), // expires in 10 minutes
};
let display_name = diesel_option_overwrite(&data.display_name);
let matrix_user_id = diesel_option_overwrite(&data.matrix_user_id);
let bot_account = data.bot_account;
- let email_deref = data.email.as_deref().map(|e| e.to_lowercase());
+ let email_deref = data.email.as_deref().map(str::to_lowercase);
let email = diesel_option_overwrite(&email_deref);
if let Some(Some(email)) = &email {
.show_scores(data.show_scores)
.default_sort_type(default_sort_type)
.default_listing_type(default_listing_type)
- .theme(data.theme.to_owned())
- .interface_language(data.interface_language.to_owned())
+ .theme(data.theme.clone())
+ .interface_language(data.interface_language.clone())
.build();
let local_user_res = LocalUser::update(context.pool(), local_user_id, &local_user_form).await;
Comment::delete(context.pool(), comment_id).await?;
// Mod tables
- let reason = data.reason.to_owned();
+ let reason = data.reason.clone();
let form = AdminPurgeCommentForm {
admin_person_id: local_user_view.person.id,
reason,
Community::delete(context.pool(), community_id).await?;
// Mod tables
- let reason = data.reason.to_owned();
+ let reason = data.reason.clone();
let form = AdminPurgeCommunityForm {
admin_person_id: local_user_view.person.id,
reason,
Person::delete(context.pool(), person_id).await?;
// Mod tables
- let reason = data.reason.to_owned();
+ let reason = data.reason.clone();
let form = AdminPurgePersonForm {
admin_person_id: local_user_view.person.id,
reason,
Post::delete(context.pool(), post_id).await?;
// Mod tables
- let reason = data.reason.to_owned();
+ let reason = data.reason.clone();
let form = AdminPurgePostForm {
admin_person_id: local_user_view.person.id,
reason,
user_id: Option<PersonId>,
pool: &DbPool,
) -> Result<ResolveObjectResponse, LemmyError> {
+ use SearchableObjects::*;
let removed_or_deleted;
let mut res = ResolveObjectResponse {
comment: None,
community: None,
person: None,
};
- use SearchableObjects::*;
match object {
Person(p) => {
removed_or_deleted = p.deleted;
// TODO no clean / non-nsfw searching rn
- let q = data.q.to_owned();
+ let q = data.q.clone();
let page = data.page;
let limit = data.limit;
let sort = data.sort;
// If the community or creator is included, dont search communities or users
let community_or_creator_included =
data.community_id.is_some() || data.community_name.is_some() || data.creator_id.is_some();
- let community_actor_id_2 = community_actor_id.to_owned();
+ let community_actor_id_2 = community_actor_id.clone();
let local_user_ = local_user.clone();
posts = PostQuery::builder()
.list()
.await?;
- let q = data.q.to_owned();
- let community_actor_id = community_actor_id.to_owned();
+ let q = data.q.clone();
+ let community_actor_id = community_actor_id.clone();
let local_user_ = local_user.clone();
comments = CommentQuery::builder()
.list()
.await?;
- let q = data.q.to_owned();
+ let q = data.q.clone();
communities = if community_or_creator_included {
vec![]
.await?
};
- let q = data.q.to_owned();
+ let q = data.q.clone();
users = if community_or_creator_included {
vec![]
.iter_mut()
.filter(|cv| cv.community.deleted || cv.community.removed)
{
- cv.community = cv.to_owned().community.blank_out_deleted_or_removed_info();
+ cv.community = cv.clone().community.blank_out_deleted_or_removed_info();
}
for pv in posts
.iter_mut()
.filter(|p| p.post.deleted || p.post.removed)
{
- pv.post = pv.to_owned().post.blank_out_deleted_or_removed_info();
+ pv.post = pv.clone().post.blank_out_deleted_or_removed_info();
}
for cv in comments
.iter_mut()
.filter(|cv| cv.comment.deleted || cv.comment.removed)
{
- cv.comment = cv.to_owned().comment.blank_out_deleted_or_removed_info();
+ cv.comment = cv.clone().comment.blank_out_deleted_or_removed_info();
}
}
use crate::Perform;
use actix_web::web::Data;
-use lemmy_api_common::{utils::get_local_user_view_from_jwt, websocket::*};
+use lemmy_api_common::{
+ utils::get_local_user_view_from_jwt,
+ websocket::{
+ CommunityJoin,
+ CommunityJoinResponse,
+ ModJoin,
+ ModJoinResponse,
+ PostJoin,
+ PostJoinResponse,
+ UserJoin,
+ UserJoinResponse,
+ },
+};
use lemmy_utils::{error::LemmyError, ConnectionId};
use lemmy_websocket::{
messages::{JoinCommunityRoom, JoinModRoom, JoinPostRoom, JoinUserRoom},
.opengraph
.properties
.get("description")
- .map(|t| t.to_string());
+ .map(std::string::ToString::to_string);
let og_title = page
.opengraph
.properties
.get("title")
- .map(|t| t.to_string());
+ .map(std::string::ToString::to_string);
let og_image = page
.opengraph
.images
// Try to generate a small thumbnail if there's a full sized one from post-links
Some(metadata_image) => fetch_pictrs(client, settings, metadata_image)
.await
- .map(|r| r.files[0].file.to_owned()),
+ .map(|r| r.files[0].file.clone()),
// Metadata, but no image
None => fetch_pictrs(client, settings, url)
.await
- .map(|r| r.files[0].file.to_owned()),
+ .map(|r| r.files[0].file.clone()),
},
// No metadata, try to fetch the URL as an image
None => fetch_pictrs(client, settings, url)
.await
- .map(|r| r.files[0].file.to_owned()),
+ .map(|r| r.files[0].file.clone()),
};
// The full urls are necessary for federation
// These helped with testing
#[actix_rt::test]
async fn test_site_metadata() {
- let settings = &SETTINGS.to_owned();
+ let settings = &SETTINGS.clone();
let client = reqwest::Client::builder()
.user_agent(build_user_agent(settings))
.build()
let local_user_id = user.local_user.id;
PasswordResetRequest::create_token(pool, local_user_id, &token2).await?;
- let email = &user.local_user.email.to_owned().expect("email");
+ let email = &user.local_user.email.clone().expect("email");
let lang = get_interface_language(user);
let subject = &lang.password_reset_subject(&user.person.name);
let protocol_and_hostname = settings.get_protocol_and_hostname();
user: &LocalUserView,
settings: &Settings,
) -> Result<(), LemmyError> {
- let email = &user.local_user.email.to_owned().expect("email");
+ let email = &user.local_user.email.clone().expect("email");
let lang = get_interface_language(user);
let subject = &lang.email_verified_subject(&user.person.actor_id);
let body = &lang.email_verified_body();
user: &LocalUserView,
settings: &Settings,
) -> Result<(), LemmyError> {
- let email = &user.local_user.email.to_owned().expect("email");
+ let email = &user.local_user.email.clone().expect("email");
let lang = get_interface_language(user);
let subject = lang.registration_approved_subject(&user.person.actor_id);
let body = lang.registration_approved_body(&settings.hostname);
);
for admin in &admins {
- let email = &admin.local_user.email.to_owned().expect("email");
+ let email = &admin.local_user.email.clone().expect("email");
let lang = get_interface_language_from_settings(admin);
let subject = lang.new_application_subject(applicant_username, &settings.hostname);
let body = lang.new_application_body(applications_link);
let local_site = LocalSite::read(context.pool()).await?;
let content_slurs_removed = remove_slurs(
- &data.content.to_owned(),
+ &data.content.clone(),
&local_site_to_slur_regex(&local_site),
);
.await?;
let comment_form = CommentInsertForm::builder()
- .content(content_slurs_removed.to_owned())
+ .content(content_slurs_removed.clone())
.post_id(data.post_id)
.creator_id(local_user_view.person.id)
.language_id(Some(language_id))
// Create the comment
let comment_form2 = comment_form.clone();
- let parent_path = parent_opt.to_owned().map(|t| t.path);
+ let parent_path = parent_opt.clone().map(|t| t.path);
let inserted_comment = Comment::create(context.pool(), &comment_form2, parent_path.as_ref())
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_comment"))?;
inserted_comment.id,
UserOperationCrud::CreateComment,
websocket_id,
- data.form_id.to_owned(),
+ data.form_id.clone(),
Some(local_user_view.person.id),
recipient_ids,
context,
None
};
- let parent_path_cloned = parent_path.to_owned();
+ let parent_path_cloned = parent_path.clone();
let post_id = data.post_id;
let local_user = local_user_view.map(|l| l.local_user);
let mut comments = CommentQuery::builder()
.iter_mut()
.filter(|cv| cv.comment.deleted || cv.comment.removed)
{
- cv.comment = cv.to_owned().comment.blank_out_deleted_or_removed_info();
+ cv.comment = cv.clone().comment.blank_out_deleted_or_removed_info();
}
Ok(GetCommentsResponse { comments })
mod_person_id: local_user_view.person.id,
comment_id: data.comment_id,
removed: Some(removed),
- reason: data.reason.to_owned(),
+ reason: data.reason.clone(),
};
ModRemoveComment::create(context.pool(), &form).await?;
local_user_view.person,
community,
deletable,
- data.reason.clone().or_else(|| Some("".to_string())),
+ data.reason.clone().or_else(|| Some(String::new())),
removed,
context,
)
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
// Do the mentions / recipients
- let updated_comment_content = updated_comment.content.to_owned();
+ let updated_comment_content = updated_comment.content.clone();
let mentions = scrape_text_for_mentions(&updated_comment_content);
let recipient_ids = send_local_notifs(
mentions,
data.comment_id,
UserOperationCrud::EditComment,
websocket_id,
- data.form_id.to_owned(),
+ data.form_id.clone(),
None,
recipient_ids,
context,
let keypair = generate_actor_keypair()?;
let community_form = CommunityInsertForm::builder()
- .name(data.name.to_owned())
- .title(data.title.to_owned())
- .description(data.description.to_owned())
+ .name(data.name.clone())
+ .title(data.title.clone())
+ .description(data.description.clone())
.icon(icon)
.banner(banner)
.nsfw(data.nsfw)
- .actor_id(Some(community_actor_id.to_owned()))
+ .actor_id(Some(community_actor_id.clone()))
.private_key(Some(keypair.private_key))
.public_key(keypair.public_key)
.followers_url(Some(generate_followers_url(&community_actor_id)?))
check_private_instance(&local_user_view, &local_site)?;
- let person_id = local_user_view.to_owned().map(|l| l.person.id);
+ let person_id = local_user_view.clone().map(|l| l.person.id);
let sort = data.sort;
let listing_type = data.type_;
.iter_mut()
.filter(|cv| cv.community.deleted || cv.community.removed)
{
- cv.community = cv.to_owned().community.blank_out_deleted_or_removed_info();
+ cv.community = cv.clone().community.blank_out_deleted_or_removed_info();
}
}
let community_id = match data.id {
Some(id) => id,
None => {
- let name = data.name.to_owned().unwrap_or_else(|| "main".to_string());
+ let name = data.name.clone().unwrap_or_else(|| "main".to_string());
resolve_actor_identifier::<ApubCommunity, Community>(&name, context, true)
.await
.map_err(|e| e.with_message("couldnt_find_community"))?
mod_person_id: local_user_view.person.id,
community_id: data.community_id,
removed: Some(removed),
- reason: data.reason.to_owned(),
+ reason: data.reason.clone(),
expires,
};
ModRemoveCommunity::create(context.pool(), &form).await?;
local_user_view.person,
updated_community,
deletable,
- data.reason.clone().or_else(|| Some("".to_string())),
+ data.reason.clone().or_else(|| Some(String::new())),
removed,
context,
)
}
let community_form = CommunityUpdateForm::builder()
- .title(data.title.to_owned())
+ .title(data.title.clone())
.description(description)
.icon(icon)
.banner(banner)
use actix_web::{web, web::Data};
-use lemmy_api_common::{comment::*, community::*, person::*, post::*, private_message::*, site::*};
+use lemmy_api_common::{
+ comment::{CreateComment, DeleteComment, EditComment, GetComment, GetComments, RemoveComment},
+ community::{
+ CreateCommunity,
+ DeleteCommunity,
+ EditCommunity,
+ GetCommunity,
+ ListCommunities,
+ RemoveCommunity,
+ },
+ person::{DeleteAccount, GetPersonDetails, Register},
+ post::{CreatePost, DeletePost, EditPost, GetPost, GetPosts, RemovePost},
+ private_message::{
+ CreatePrivateMessage,
+ DeletePrivateMessage,
+ EditPrivateMessage,
+ GetPrivateMessages,
+ },
+ site::{CreateSite, EditSite, GetSite},
+};
use lemmy_utils::{error::LemmyError, ConnectionId};
use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperationCrud};
use serde::Deserialize;
let post_form = PostInsertForm::builder()
.name(data.name.trim().to_owned())
.url(url)
- .body(data.body.to_owned())
+ .body(data.body.clone())
.community_id(data.community_id)
.creator_id(local_user_view.person.id)
.nsfw(data.nsfw)
.iter_mut()
.filter(|p| p.post.deleted || p.post.removed)
{
- pv.post = pv.to_owned().post.blank_out_deleted_or_removed_info();
+ pv.post = pv.clone().post.blank_out_deleted_or_removed_info();
}
for pv in posts
.iter_mut()
.filter(|p| p.community.deleted || p.community.removed)
{
- pv.community = pv.to_owned().community.blank_out_deleted_or_removed_info();
+ pv.community = pv.clone().community.blank_out_deleted_or_removed_info();
}
}
mod_person_id: local_user_view.person.id,
post_id: data.post_id,
removed: Some(removed),
- reason: data.reason.to_owned(),
+ reason: data.reason.clone(),
};
ModRemovePost::create(context.pool(), &form).await?;
local_user_view.person,
community,
deletable,
- data.reason.clone().or_else(|| Some("".to_string())),
+ data.reason.clone().or_else(|| Some(String::new())),
removed,
context,
)
.await?;
let post_form = PostUpdateForm::builder()
- .name(data.name.to_owned())
+ .name(data.name.clone())
.url(url)
.body(body)
.nsfw(data.nsfw)
let local_site = LocalSite::read(context.pool()).await?;
let content_slurs_removed = remove_slurs(
- &data.content.to_owned(),
+ &data.content.clone(),
&local_site_to_slur_regex(&local_site),
);
check_person_block(local_user_view.person.id, data.recipient_id, context.pool()).await?;
let private_message_form = PrivateMessageInsertForm::builder()
- .content(content_slurs_removed.to_owned())
+ .content(content_slurs_removed.clone())
.creator_id(local_user_view.person.id)
.recipient_id(data.recipient_id)
.build();
.filter(|pmv| pmv.private_message.deleted)
{
pmv.private_message = pmv
- .to_owned()
+ .clone()
.private_message
.blank_out_deleted_or_removed_info();
}
let inbox_url = Some(generate_site_inbox_url(&actor_id)?);
let keypair = generate_actor_keypair()?;
let site_form = SiteUpdateForm::builder()
- .name(Some(data.name.to_owned()))
+ .name(Some(data.name.clone()))
.sidebar(sidebar)
.description(description)
.icon(icon)
.federation_http_fetch_retry_limit(data.federation_http_fetch_retry_limit)
.federation_worker_count(data.federation_worker_count)
.captcha_enabled(data.captcha_enabled)
- .captcha_difficulty(data.captcha_difficulty.to_owned())
+ .captcha_difficulty(data.captcha_difficulty.clone())
.build();
LocalSite::update(context.pool(), &local_site_form).await?;
SiteLanguage::update(context.pool(), discussion_languages.clone(), &site).await?;
}
- let name = data.name.to_owned();
+ let name = data.name.clone();
let site_form = SiteUpdateForm::builder()
.name(name)
.sidebar(diesel_option_overwrite(&data.sidebar))
.federation_http_fetch_retry_limit(data.federation_http_fetch_retry_limit)
.federation_worker_count(data.federation_worker_count)
.captcha_enabled(data.captcha_enabled)
- .captcha_difficulty(data.captcha_difficulty.to_owned())
+ .captcha_difficulty(data.captcha_difficulty.clone())
.build();
let update_local_site = LocalSite::update(context.pool(), &local_site_form)
.ok();
// Replace the blocked and allowed instances
- let allowed = data.allowed_instances.to_owned();
+ let allowed = data.allowed_instances.clone();
FederationAllowList::replace(context.pool(), allowed).await?;
- let blocked = data.blocked_instances.to_owned();
+ let blocked = data.blocked_instances.clone();
FederationBlockList::replace(context.pool(), blocked).await?;
// TODO can't think of a better way to do this.
let check = context
.chat_server()
.send(CheckCaptcha {
- uuid: data.captcha_uuid.to_owned().unwrap_or_default(),
- answer: data.captcha_answer.to_owned().unwrap_or_default(),
+ uuid: data.captcha_uuid.clone().unwrap_or_default(),
+ answer: data.captcha_answer.clone().unwrap_or_default(),
})
.await?;
if !check {
// Register the new person
let person_form = PersonInsertForm::builder()
- .name(data.username.to_owned())
+ .name(data.username.clone())
.actor_id(Some(actor_id.clone()))
.private_key(Some(actor_keypair.private_key))
.public_key(actor_keypair.public_key)
// Create the local user
let local_user_form = LocalUserInsertForm::builder()
.person_id(inserted_person.id)
- .email(data.email.as_deref().map(|s| s.to_lowercase()))
+ .email(data.email.as_deref().map(str::to_lowercase))
.password_encrypted(data.password.to_string())
.show_nsfw(Some(data.show_nsfw))
.build();
let form = RegistrationApplicationInsertForm {
local_user_id: inserted_local_user.id,
// We already made sure answer was not null above
- answer: data.answer.to_owned().expect("must have an answer"),
+ answer: data.answer.clone().expect("must have an answer"),
};
RegistrationApplication::create(context.pool(), &form).await?;
let saved_only = data.saved_only;
let community_id = data.community_id;
let local_user = local_user_view.map(|l| l.local_user);
- let local_user_clone = local_user.to_owned();
+ let local_user_clone = local_user.clone();
let posts_query = PostQuery::builder()
.pool(context.pool())
file_to_json_object("assets/lemmy/collections/group_moderators.json").unwrap();
let url = Url::parse("https://enterprise.lemmy.ml/c/tenforward").unwrap();
let mut request_counter = 0;
- let community_context = CommunityContext(community, context.to_owned());
+ let community_context = CommunityContext(community, context.clone());
ApubCommunityModerators::verify(&json, &url, &community_context, &mut request_counter)
.await
.unwrap();
ActorT: ApubObject<DataType = LemmyContext, Error = LemmyError> + Actor + Send + 'static,
for<'de2> <ActorT as ApubObject>::ApubType: serde::Deserialize<'de2>,
{
+ static DATA: OnceCell<Data<LemmyContext>> = OnceCell::new();
let activity_value: Value = serde_json::from_str(&payload)?;
debug!("Parsing activity {}", payload);
let activity: Activity = serde_json::from_value(activity_value.clone())?;
}
info!("Received activity {}", payload);
- static DATA: OnceCell<Data<LemmyContext>> = OnceCell::new();
let data = DATA.get_or_init(|| Data::new(context.get_ref().clone()));
receive_activity::<Activity, ActorT, LemmyContext>(
request,
.build()
.expect("configure federation");
LocalInstance::new(
- context.settings().hostname.to_owned(),
+ context.settings().hostname.clone(),
context.client().clone(),
settings,
)
if is_strict || strict_allowlist {
// need to allow this explicitly because apub receive might contain objects from our local
// instance.
- let mut allowed_and_local = allowed.to_owned();
+ let mut allowed_and_local = allowed.clone();
allowed_and_local.push(local_instance);
if !allowed_and_local.contains(&domain) {
if let Some(port) = actor_id.port() {
format!(":{}", port)
} else {
- "".to_string()
+ String::new()
},
);
Ok(Url::parse(&url)?.into())
sensitive: bool,
pool: &DbPool,
) -> Result<bool, LemmyError> {
- let ap_id = ap_id.to_owned().into();
+ let ap_id = ap_id.clone().into();
Ok(Activity::insert(pool, ap_id, activity, local, Some(sensitive)).await?)
}
context: &LemmyContext,
request_counter: &mut i32,
) -> Result<ApubCommunity, LemmyError> {
- let apub_id = group.id.inner().to_owned();
+ let apub_id = group.id.inner().clone();
let instance = Instance::create_from_actor_id(context.pool(), &apub_id).await?;
let form = Group::into_insert_form(group.clone(), instance.id);
}
fn shared_inbox(&self) -> Option<Url> {
- self.shared_inbox_url.clone().map(|s| s.into())
+ self.shared_inbox_url.clone().map(Into::into)
}
}
impl ActorType for ApubCommunity {
fn actor_id(&self) -> Url {
- self.actor_id.to_owned().into()
+ self.actor_id.clone().into()
}
fn private_key(&self) -> Option<String> {
- self.private_key.to_owned()
+ self.private_key.clone()
}
}
data: &Self::DataType,
_request_counter: &mut i32,
) -> Result<Self, LemmyError> {
- let apub_id = apub.id.inner().to_owned();
+ let apub_id = apub.id.inner().clone();
let instance = DbInstance::create_from_actor_id(data.pool(), &apub_id).await?;
let site_form = SiteInsertForm {
impl ActorType for ApubSite {
fn actor_id(&self) -> Url {
- self.actor_id.to_owned().into()
+ self.actor_id.clone().into()
}
fn private_key(&self) -> Option<String> {
- self.private_key.to_owned()
+ self.private_key.clone()
}
}
// TODO: would be nice if we didnt have to use a full context for tests.
pub(crate) async fn init_context() -> LemmyContext {
+ async fn x() -> Result<String, LemmyError> {
+ Ok(String::new())
+ }
// call this to run migrations
let pool = build_db_pool_for_tests().await;
- let settings = SETTINGS.to_owned();
+ let settings = SETTINGS.clone();
let client = Client::builder()
.user_agent(build_user_agent(&settings))
.build()
let client = ClientBuilder::new(client).with(BlockedMiddleware).build();
let secret = Secret {
id: 0,
- jwt_secret: "".to_string(),
+ jwt_secret: String::new(),
};
- async fn x() -> Result<String, LemmyError> {
- Ok("".to_string())
- }
let rate_limit_config = RateLimitConfig::builder().build();
let rate_limit_cell = RateLimitCell::new(rate_limit_config).await;
context: &LemmyContext,
request_counter: &mut i32,
) -> Result<ApubPerson, LemmyError> {
- let apub_id = person.id.inner().to_owned();
+ let apub_id = person.id.inner().clone();
let instance = Instance::create_from_actor_id(context.pool(), &apub_id).await?;
let person_form = PersonInsertForm {
impl ActorType for ApubPerson {
fn actor_id(&self) -> Url {
- self.actor_id.to_owned().into()
+ self.actor_id.clone().into()
}
fn private_key(&self) -> Option<String> {
- self.private_key.to_owned()
+ self.private_key.clone()
}
}
}
fn shared_inbox(&self) -> Option<Url> {
- self.shared_inbox_url.clone().map(|s| s.into())
+ self.shared_inbox_url.clone().map(Into::into)
}
}
content: self.body.as_ref().map(|b| markdown_to_html(b)),
media_type: Some(MediaTypeMarkdownOrHtml::Html),
source: self.body.clone().map(Source::new),
- url: self.url.clone().map(|u| u.into()),
+ url: self.url.clone().map(Into::into),
attachment: self.url.clone().map(Attachment::new).into_iter().collect(),
image: self.thumbnail_url.clone().map(ImageObject::new),
comments_enabled: Some(!self.locked),
let community = page.extract_community(context, request_counter).await?;
let form = if !page.is_mod_action(context).await? {
- let first_attachment = page.attachment.into_iter().map(|a| a.url()).next();
+ let first_attachment = page.attachment.into_iter().map(Attachment::url).next();
let url = if first_attachment.is_some() {
first_attachment
} else if page.kind == PageType::Video {
);
match parent.deref() {
PostOrComment::Post(p) => {
- let post = p.deref().to_owned();
+ let post = p.deref().clone();
Ok((post, None))
}
PostOrComment::Comment(c) => {
let post_id = c.post_id;
let post = Post::read(context.pool(), post_id).await?;
- let comment = c.deref().to_owned();
+ let comment = c.deref().clone();
Ok((post.into(), Some(comment)))
}
}
aggregates::structs::{PersonPostAggregates, PersonPostAggregatesForm},
diesel::BoolExpressionMethods,
newtypes::{PersonId, PostId},
- schema::person_post_aggregates::dsl::*,
+ schema::person_post_aggregates::dsl::{person_id, person_post_aggregates, post_id},
utils::{get_conn, DbPool},
};
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
use crate::{
newtypes::DbUrl,
- schema::activity::dsl::*,
- source::activity::*,
+ schema::activity::dsl::{activity, ap_id},
+ source::activity::{Activity, ActivityInsertForm, ActivityUpdateForm},
traits::Crud,
utils::{get_conn, DbPool},
};
use diesel::{
- dsl::*,
+ dsl::insert_into,
result::{DatabaseErrorKind, Error},
ExpressionMethods,
QueryDsl,
.unwrap();
let activity_form = ActivityInsertForm {
ap_id: ap_id_.clone(),
- data: test_json.to_owned(),
+ data: test_json.clone(),
local: Some(true),
sensitive: Some(false),
updated: None,
diesel::JoinOnDsl,
newtypes::{CommunityId, InstanceId, LanguageId, LocalUserId, SiteId},
schema::{local_site, site, site_language},
- source::{actor_language::*, language::Language, site::Site},
+ source::{
+ actor_language::{
+ CommunityLanguage,
+ CommunityLanguageForm,
+ LocalUserLanguage,
+ LocalUserLanguageForm,
+ SiteLanguage,
+ SiteLanguageForm,
+ },
+ language::Language,
+ site::Site,
+ },
utils::{get_conn, DbPool},
};
-use diesel::{delete, dsl::*, insert_into, result::Error, select, ExpressionMethods, QueryDsl};
+use diesel::{
+ delete,
+ dsl::{count, exists},
+ insert_into,
+ result::Error,
+ select,
+ ExpressionMethods,
+ QueryDsl,
+};
use diesel_async::{AsyncPgConnection, RunQueryDsl};
use lemmy_utils::error::LemmyError;
use tokio::sync::OnceCell;
pool: &DbPool,
for_local_user_id: LocalUserId,
) -> Result<Vec<LanguageId>, Error> {
- use crate::schema::local_user_language::dsl::*;
+ use crate::schema::local_user_language::dsl::{
+ language_id,
+ local_user_id,
+ local_user_language,
+ };
let conn = &mut get_conn(pool).await?;
conn
.build_transaction()
.run(|conn| {
Box::pin(async move {
- use crate::schema::local_user_language::dsl::*;
+ use crate::schema::local_user_language::dsl::{local_user_id, local_user_language};
// Clear the current user languages
delete(local_user_language.filter(local_user_id.eq(for_local_user_id)))
.execute(conn)
.build_transaction()
.run(|conn| {
Box::pin(async move {
- use crate::schema::site_language::dsl::*;
+ use crate::schema::site_language::dsl::{site_id, site_language};
// Clear the current languages
delete(site_language.filter(site_id.eq(for_site_id)))
for_language_id: Option<LanguageId>,
for_community_id: CommunityId,
) -> Result<(), LemmyError> {
- use crate::schema::community_language::dsl::*;
+ use crate::schema::community_language::dsl::{community_id, community_language, language_id};
let conn = &mut get_conn(pool).await?;
if let Some(for_language_id) = for_language_id {
pool: &DbPool,
for_community_id: CommunityId,
) -> Result<Vec<LanguageId>, Error> {
- use crate::schema::community_language::dsl::*;
+ use crate::schema::community_language::dsl::{community_id, community_language, language_id};
let conn = &mut get_conn(pool).await?;
let langs = community_language
.build_transaction()
.run(|conn| {
Box::pin(async move {
- use crate::schema::community_language::dsl::*;
+ use crate::schema::community_language::dsl::{community_id, community_language};
// Clear the current languages
delete(community_language.filter(community_id.eq(for_community_id)))
.execute(conn)
community_id: CommunityId,
local_user_id: LocalUserId,
) -> Result<Option<LanguageId>, Error> {
- let conn = &mut get_conn(pool).await?;
use crate::schema::{community_language::dsl as cl, local_user_language::dsl as ul};
+ let conn = &mut get_conn(pool).await?;
let intersection = ul::local_user_language
.inner_join(cl::community_language.on(ul::language_id.eq(cl::language_id)))
.filter(ul::local_user_id.eq(local_user_id))
static ALL_LANGUAGES_COUNT: OnceCell<usize> = OnceCell::const_new();
let count = ALL_LANGUAGES_COUNT
.get_or_init(|| async {
- use crate::schema::language::dsl::*;
+ use crate::schema::language::dsl::{id, language};
let count: i64 = language
.select(count(id))
.first(conn)
#[cfg(test)]
mod tests {
use crate::{
- impls::actor_language::*,
+ impls::actor_language::{
+ convert_read_languages,
+ convert_update_languages,
+ default_post_language,
+ get_conn,
+ CommunityLanguage,
+ DbPool,
+ Language,
+ LanguageId,
+ LocalUserLanguage,
+ QueryDsl,
+ RunQueryDsl,
+ SiteLanguage,
+ },
source::{
community::{Community, CommunityInsertForm},
instance::Instance,
#[tokio::test]
#[serial]
async fn test_convert_read_languages() {
+ use crate::schema::language::dsl::{id, language};
let pool = &build_db_pool_for_tests().await;
// call with all languages, returns empty vec
- use crate::schema::language::dsl::*;
let conn = &mut get_conn(pool).await.unwrap();
let all_langs = language.select(id).get_results(conn).await.unwrap();
let converted1: Vec<LanguageId> = convert_read_languages(conn, all_langs).await.unwrap();
use crate::{
newtypes::{CommentId, DbUrl, PersonId},
- schema::comment::dsl::*,
+ schema::comment::dsl::{ap_id, comment, content, creator_id, deleted, path, removed, updated},
source::comment::{
Comment,
CommentInsertForm,
traits::{Crud, DeleteableOrRemoveable, Likeable, Saveable},
utils::{get_conn, naive_now, DbPool},
};
-use diesel::{dsl::*, result::Error, ExpressionMethods, QueryDsl};
+use diesel::{
+ dsl::{insert_into, sql_query},
+ result::Error,
+ ExpressionMethods,
+ QueryDsl,
+};
use diesel_async::RunQueryDsl;
use diesel_ltree::Ltree;
use url::Url;
type Form = CommentLikeForm;
type IdType = CommentId;
async fn like(pool: &DbPool, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
- use crate::schema::comment_like::dsl::*;
+ use crate::schema::comment_like::dsl::{comment_id, comment_like, person_id};
let conn = &mut get_conn(pool).await?;
insert_into(comment_like)
.values(comment_like_form)
person_id_: PersonId,
comment_id_: CommentId,
) -> Result<usize, Error> {
- use crate::schema::comment_like::dsl::*;
+ use crate::schema::comment_like::dsl::{comment_id, comment_like, person_id};
let conn = &mut get_conn(pool).await?;
diesel::delete(
comment_like
impl Saveable for CommentSaved {
type Form = CommentSavedForm;
async fn save(pool: &DbPool, comment_saved_form: &CommentSavedForm) -> Result<Self, Error> {
- use crate::schema::comment_saved::dsl::*;
+ use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id};
let conn = &mut get_conn(pool).await?;
insert_into(comment_saved)
.values(comment_saved_form)
.await
}
async fn unsave(pool: &DbPool, comment_saved_form: &CommentSavedForm) -> Result<usize, Error> {
- use crate::schema::comment_saved::dsl::*;
+ use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id};
let conn = &mut get_conn(pool).await?;
diesel::delete(
comment_saved
impl DeleteableOrRemoveable for Comment {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
- self.content = "".into();
+ self.content = String::new();
self
}
}
use crate::{
newtypes::LanguageId,
source::{
- comment::*,
+ comment::{
+ Comment,
+ CommentInsertForm,
+ CommentLike,
+ CommentLikeForm,
+ CommentSaved,
+ CommentSavedForm,
+ CommentUpdateForm,
+ },
community::{Community, CommunityInsertForm},
instance::Instance,
person::{Person, PersonInsertForm},
- post::*,
+ post::{Post, PostInsertForm},
},
traits::{Crud, Likeable, Saveable},
utils::build_db_pool_for_tests,
path: Ltree(format!("0.{}", inserted_comment.id)),
published: inserted_comment.published,
updated: None,
- ap_id: inserted_comment.ap_id.to_owned(),
+ ap_id: inserted_comment.ap_id.clone(),
distinguished: false,
local: true,
language_id: LanguageId::default(),
use crate::{
newtypes::{CommentId, CommentReplyId, PersonId},
- schema::comment_reply::dsl::*,
- source::comment_reply::*,
+ schema::comment_reply::dsl::{comment_id, comment_reply, read, recipient_id},
+ source::comment_reply::{CommentReply, CommentReplyInsertForm, CommentReplyUpdateForm},
traits::Crud,
utils::{get_conn, DbPool},
};
-use diesel::{dsl::*, result::Error, ExpressionMethods, QueryDsl};
+use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl;
#[async_trait]
mod tests {
use crate::{
source::{
- comment::*,
- comment_reply::*,
+ comment::{Comment, CommentInsertForm},
+ comment_reply::{CommentReply, CommentReplyInsertForm, CommentReplyUpdateForm},
community::{Community, CommunityInsertForm},
instance::Instance,
- person::*,
- post::*,
+ person::{Person, PersonInsertForm},
+ post::{Post, PostInsertForm},
},
traits::Crud,
utils::build_db_pool_for_tests,
use crate::{
newtypes::{CommentReportId, PersonId},
- schema::comment_report::dsl::*,
+ schema::comment_report::dsl::{comment_report, resolved, resolver_id, updated},
source::comment_report::{CommentReport, CommentReportForm},
traits::Reportable,
utils::{get_conn, naive_now, DbPool},
};
-use diesel::{dsl::*, result::Error, ExpressionMethods, QueryDsl};
+use diesel::{
+ dsl::{insert_into, update},
+ result::Error,
+ ExpressionMethods,
+ QueryDsl,
+};
use diesel_async::RunQueryDsl;
#[async_trait]
use crate::{
newtypes::{CommunityId, DbUrl, PersonId},
- schema::community::dsl::*,
+ schema::community::dsl::{actor_id, community, deleted, local, name, removed},
source::{
actor_language::{CommunityLanguage, SiteLanguage},
community::{
utils::{functions::lower, get_conn, DbPool},
SubscribedType,
};
-use diesel::{dsl::*, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
+use diesel::{
+ dsl::{exists, insert_into},
+ result::Error,
+ ExpressionMethods,
+ QueryDsl,
+ TextExpressionMethods,
+};
use diesel_async::RunQueryDsl;
mod safe_type {
- use crate::{schema::community::*, source::community::Community, traits::ToSafe};
+ use crate::{
+ schema::community::{
+ actor_id,
+ banner,
+ deleted,
+ description,
+ hidden,
+ icon,
+ id,
+ instance_id,
+ local,
+ name,
+ nsfw,
+ posting_restricted_to_mods,
+ published,
+ removed,
+ title,
+ updated,
+ },
+ source::community::Community,
+ traits::ToSafe,
+ };
type Columns = (
id,
pool: &DbPool,
community_moderator_form: &CommunityModeratorForm,
) -> Result<Self, Error> {
- use crate::schema::community_moderator::dsl::*;
+ use crate::schema::community_moderator::dsl::community_moderator;
let conn = &mut get_conn(pool).await?;
insert_into(community_moderator)
.values(community_moderator_form)
pool: &DbPool,
community_moderator_form: &CommunityModeratorForm,
) -> Result<usize, Error> {
- use crate::schema::community_moderator::dsl::*;
+ use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id};
let conn = &mut get_conn(pool).await?;
diesel::delete(
community_moderator
impl DeleteableOrRemoveable for CommunitySafe {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
- self.title = "".into();
+ self.title = String::new();
self.description = None;
self.icon = None;
self.banner = None;
impl DeleteableOrRemoveable for Community {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
- self.title = "".into();
+ self.title = String::new();
self.description = None;
self.icon = None;
self.banner = None;
pool: &DbPool,
for_community_id: CommunityId,
) -> Result<usize, Error> {
- use crate::schema::community_moderator::dsl::*;
+ use crate::schema::community_moderator::dsl::{community_id, community_moderator};
let conn = &mut get_conn(pool).await?;
diesel::delete(community_moderator.filter(community_id.eq(for_community_id)))
pool: &DbPool,
for_person_id: PersonId,
) -> Result<Vec<CommunityId>, Error> {
- use crate::schema::community_moderator::dsl::*;
+ use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id};
let conn = &mut get_conn(pool).await?;
community_moderator
.filter(person_id.eq(for_person_id))
pool: &DbPool,
community_person_ban_form: &CommunityPersonBanForm,
) -> Result<Self, Error> {
- use crate::schema::community_person_ban::dsl::*;
+ use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id};
let conn = &mut get_conn(pool).await?;
insert_into(community_person_ban)
.values(community_person_ban_form)
pool: &DbPool,
community_person_ban_form: &CommunityPersonBanForm,
) -> Result<usize, Error> {
- use crate::schema::community_person_ban::dsl::*;
+ use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id};
let conn = &mut get_conn(pool).await?;
diesel::delete(
community_person_ban
pool: &DbPool,
community_follower_form: &CommunityFollowerForm,
) -> Result<Self, Error> {
- use crate::schema::community_follower::dsl::*;
+ use crate::schema::community_follower::dsl::{community_follower, community_id, person_id};
let conn = &mut get_conn(pool).await?;
insert_into(community_follower)
.values(community_follower_form)
community_id_: CommunityId,
person_id_: PersonId,
) -> Result<Self, Error> {
- use crate::schema::community_follower::dsl::*;
+ use crate::schema::community_follower::dsl::{
+ community_follower,
+ community_id,
+ pending,
+ person_id,
+ };
let conn = &mut get_conn(pool).await?;
diesel::update(
community_follower
pool: &DbPool,
community_follower_form: &CommunityFollowerForm,
) -> Result<usize, Error> {
- use crate::schema::community_follower::dsl::*;
+ use crate::schema::community_follower::dsl::{community_follower, community_id, person_id};
let conn = &mut get_conn(pool).await?;
diesel::delete(
community_follower
// TODO: this function name only makes sense if you call it with a remote community. for a local
// community, it will also return true if only remote followers exist
async fn has_local_followers(pool: &DbPool, community_id_: CommunityId) -> Result<bool, Error> {
- use crate::schema::community_follower::dsl::*;
+ use crate::schema::community_follower::dsl::{community_follower, community_id};
let conn = &mut get_conn(pool).await?;
diesel::select(exists(
community_follower.filter(community_id.eq(community_id_)),
#[cfg(test)]
mod tests {
use crate::{
- source::{community::*, instance::Instance, person::*},
+ source::{
+ community::{
+ Community,
+ CommunityFollower,
+ CommunityFollowerForm,
+ CommunityInsertForm,
+ CommunityModerator,
+ CommunityModeratorForm,
+ CommunityPersonBan,
+ CommunityPersonBanForm,
+ CommunityUpdateForm,
+ },
+ instance::Instance,
+ person::{Person, PersonInsertForm},
+ },
traits::{Bannable, Crud, Followable, Joinable},
utils::build_db_pool_for_tests,
};
deleted: false,
published: inserted_community.published,
updated: None,
- actor_id: inserted_community.actor_id.to_owned(),
+ 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.to_owned(),
- inbox_url: inserted_community.inbox_url.to_owned(),
+ followers_url: inserted_community.followers_url.clone(),
+ inbox_url: inserted_community.inbox_url.clone(),
shared_inbox_url: None,
hidden: false,
posting_restricted_to_mods: false,
use crate::{
- schema::community_block::dsl::*,
+ schema::community_block::dsl::{community_block, community_id, person_id},
source::community_block::{CommunityBlock, CommunityBlockForm},
traits::Blockable,
utils::{get_conn, DbPool},
};
-use diesel::{dsl::*, result::Error, *};
+use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl;
#[async_trait]
use crate::{
newtypes::LocalUserId,
- schema::email_verification::dsl::*,
- source::email_verification::*,
+ schema::email_verification::dsl::{
+ email_verification,
+ local_user_id,
+ published,
+ verification_token,
+ },
+ source::email_verification::{EmailVerification, EmailVerificationForm},
utils::{get_conn, DbPool},
};
-use diesel::{dsl::*, insert_into, result::Error, ExpressionMethods, QueryDsl};
+use diesel::{
+ dsl::{now, IntervalDsl},
+ insert_into,
+ result::Error,
+ ExpressionMethods,
+ QueryDsl,
+};
use diesel_async::RunQueryDsl;
impl EmailVerification {
},
utils::{get_conn, DbPool},
};
-use diesel::{dsl::*, result::Error};
+use diesel::{dsl::insert_into, result::Error};
use diesel_async::{AsyncPgConnection, RunQueryDsl};
impl FederationAllowList {
},
utils::{get_conn, DbPool},
};
-use diesel::{dsl::*, result::Error};
+use diesel::{dsl::insert_into, result::Error};
use diesel_async::{AsyncPgConnection, RunQueryDsl};
impl FederationBlockList {
source::instance::{Instance, InstanceForm},
utils::{get_conn, naive_now, DbPool},
};
-use diesel::{dsl::*, result::Error, ExpressionMethods, QueryDsl};
+use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
use diesel_async::{AsyncPgConnection, RunQueryDsl};
use lemmy_utils::utils::generate_domain_url;
use url::Url;
use crate::{
diesel::ExpressionMethods,
newtypes::LanguageId,
- schema::language::dsl::*,
+ schema::language::dsl::{code, id, language},
source::language::Language,
utils::{get_conn, DbPool},
};
use crate::{
- schema::local_site::dsl::*,
- source::local_site::*,
+ schema::local_site::dsl::local_site,
+ source::local_site::{LocalSite, LocalSiteInsertForm, LocalSiteUpdateForm},
utils::{get_conn, DbPool},
};
-use diesel::{dsl::*, result::Error};
+use diesel::{dsl::insert_into, result::Error};
use diesel_async::RunQueryDsl;
impl LocalSite {
use crate::{
schema::local_site_rate_limit,
- source::local_site_rate_limit::*,
+ source::local_site_rate_limit::{
+ LocalSiteRateLimit,
+ LocalSiteRateLimitInsertForm,
+ LocalSiteRateLimitUpdateForm,
+ },
utils::{get_conn, DbPool},
};
-use diesel::{dsl::*, result::Error};
+use diesel::{dsl::insert_into, result::Error};
use diesel_async::RunQueryDsl;
impl LocalSiteRateLimit {
use crate::{
newtypes::LocalUserId,
- schema::local_user::dsl::*,
+ schema::local_user::dsl::{
+ accepted_application,
+ email_verified,
+ local_user,
+ password_encrypted,
+ validator_time,
+ },
source::{
actor_language::{LocalUserLanguage, SiteLanguage},
local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
utils::{get_conn, naive_now, DbPool},
};
use bcrypt::{hash, DEFAULT_COST};
-use diesel::{dsl::*, result::Error, ExpressionMethods, QueryDsl};
+use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl;
mod safe_settings_type {
use crate::{
- schema::local_user::columns::*,
+ schema::local_user::columns::{
+ accepted_application,
+ default_listing_type,
+ default_sort_type,
+ email,
+ email_verified,
+ id,
+ interface_language,
+ person_id,
+ send_notifications_to_email,
+ show_avatars,
+ show_bot_accounts,
+ show_new_post_notifs,
+ show_nsfw,
+ show_read_posts,
+ show_scores,
+ theme,
+ validator_time,
+ },
source::local_user::LocalUser,
traits::ToSafeSettings,
};
use crate::{
- source::moderator::*,
+ source::moderator::{
+ AdminPurgeComment,
+ AdminPurgeCommentForm,
+ AdminPurgeCommunity,
+ AdminPurgeCommunityForm,
+ AdminPurgePerson,
+ AdminPurgePersonForm,
+ AdminPurgePost,
+ AdminPurgePostForm,
+ ModAdd,
+ ModAddCommunity,
+ ModAddCommunityForm,
+ ModAddForm,
+ ModBan,
+ ModBanForm,
+ ModBanFromCommunity,
+ ModBanFromCommunityForm,
+ ModHideCommunity,
+ ModHideCommunityForm,
+ ModLockPost,
+ ModLockPostForm,
+ ModRemoveComment,
+ ModRemoveCommentForm,
+ ModRemoveCommunity,
+ ModRemoveCommunityForm,
+ ModRemovePost,
+ ModRemovePostForm,
+ ModStickyPost,
+ ModStickyPostForm,
+ ModTransferCommunity,
+ ModTransferCommunityForm,
+ },
traits::Crud,
utils::{get_conn, DbPool},
};
-use diesel::{dsl::*, result::Error, QueryDsl};
+use diesel::{dsl::insert_into, result::Error, QueryDsl};
use diesel_async::RunQueryDsl;
#[async_trait]
type UpdateForm = ModRemovePostForm;
type IdType = i32;
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
- use crate::schema::mod_remove_post::dsl::*;
+ use crate::schema::mod_remove_post::dsl::mod_remove_post;
let conn = &mut get_conn(pool).await?;
mod_remove_post.find(from_id).first::<Self>(conn).await
}
async fn create(pool: &DbPool, form: &ModRemovePostForm) -> Result<Self, Error> {
- use crate::schema::mod_remove_post::dsl::*;
+ use crate::schema::mod_remove_post::dsl::mod_remove_post;
let conn = &mut get_conn(pool).await?;
insert_into(mod_remove_post)
.values(form)
}
async fn update(pool: &DbPool, from_id: i32, form: &ModRemovePostForm) -> Result<Self, Error> {
- use crate::schema::mod_remove_post::dsl::*;
+ use crate::schema::mod_remove_post::dsl::mod_remove_post;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_remove_post.find(from_id))
.set(form)
type UpdateForm = ModLockPostForm;
type IdType = i32;
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
- use crate::schema::mod_lock_post::dsl::*;
+ use crate::schema::mod_lock_post::dsl::mod_lock_post;
let conn = &mut get_conn(pool).await?;
mod_lock_post.find(from_id).first::<Self>(conn).await
}
async fn create(pool: &DbPool, form: &ModLockPostForm) -> Result<Self, Error> {
- use crate::schema::mod_lock_post::dsl::*;
+ use crate::schema::mod_lock_post::dsl::mod_lock_post;
let conn = &mut get_conn(pool).await?;
insert_into(mod_lock_post)
.values(form)
}
async fn update(pool: &DbPool, from_id: i32, form: &ModLockPostForm) -> Result<Self, Error> {
- use crate::schema::mod_lock_post::dsl::*;
+ use crate::schema::mod_lock_post::dsl::mod_lock_post;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_lock_post.find(from_id))
.set(form)
type UpdateForm = ModStickyPostForm;
type IdType = i32;
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
- use crate::schema::mod_sticky_post::dsl::*;
+ use crate::schema::mod_sticky_post::dsl::mod_sticky_post;
let conn = &mut get_conn(pool).await?;
mod_sticky_post.find(from_id).first::<Self>(conn).await
}
async fn create(pool: &DbPool, form: &ModStickyPostForm) -> Result<Self, Error> {
- use crate::schema::mod_sticky_post::dsl::*;
+ use crate::schema::mod_sticky_post::dsl::mod_sticky_post;
let conn = &mut get_conn(pool).await?;
insert_into(mod_sticky_post)
.values(form)
}
async fn update(pool: &DbPool, from_id: i32, form: &ModStickyPostForm) -> Result<Self, Error> {
- use crate::schema::mod_sticky_post::dsl::*;
+ use crate::schema::mod_sticky_post::dsl::mod_sticky_post;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_sticky_post.find(from_id))
.set(form)
type UpdateForm = ModRemoveCommentForm;
type IdType = i32;
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
- use crate::schema::mod_remove_comment::dsl::*;
+ use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
let conn = &mut get_conn(pool).await?;
mod_remove_comment.find(from_id).first::<Self>(conn).await
}
async fn create(pool: &DbPool, form: &ModRemoveCommentForm) -> Result<Self, Error> {
- use crate::schema::mod_remove_comment::dsl::*;
+ use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
let conn = &mut get_conn(pool).await?;
insert_into(mod_remove_comment)
.values(form)
}
async fn update(pool: &DbPool, from_id: i32, form: &ModRemoveCommentForm) -> Result<Self, Error> {
- use crate::schema::mod_remove_comment::dsl::*;
+ use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_remove_comment.find(from_id))
.set(form)
type UpdateForm = ModRemoveCommunityForm;
type IdType = i32;
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
- use crate::schema::mod_remove_community::dsl::*;
+ use crate::schema::mod_remove_community::dsl::mod_remove_community;
let conn = &mut get_conn(pool).await?;
mod_remove_community.find(from_id).first::<Self>(conn).await
}
async fn create(pool: &DbPool, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
- use crate::schema::mod_remove_community::dsl::*;
+ use crate::schema::mod_remove_community::dsl::mod_remove_community;
let conn = &mut get_conn(pool).await?;
insert_into(mod_remove_community)
.values(form)
from_id: i32,
form: &ModRemoveCommunityForm,
) -> Result<Self, Error> {
- use crate::schema::mod_remove_community::dsl::*;
+ use crate::schema::mod_remove_community::dsl::mod_remove_community;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_remove_community.find(from_id))
.set(form)
type UpdateForm = ModBanFromCommunityForm;
type IdType = i32;
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
- use crate::schema::mod_ban_from_community::dsl::*;
+ use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
let conn = &mut get_conn(pool).await?;
mod_ban_from_community
.find(from_id)
}
async fn create(pool: &DbPool, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
- use crate::schema::mod_ban_from_community::dsl::*;
+ use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
let conn = &mut get_conn(pool).await?;
insert_into(mod_ban_from_community)
.values(form)
from_id: i32,
form: &ModBanFromCommunityForm,
) -> Result<Self, Error> {
- use crate::schema::mod_ban_from_community::dsl::*;
+ use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_ban_from_community.find(from_id))
.set(form)
type UpdateForm = ModBanForm;
type IdType = i32;
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
- use crate::schema::mod_ban::dsl::*;
+ use crate::schema::mod_ban::dsl::mod_ban;
let conn = &mut get_conn(pool).await?;
mod_ban.find(from_id).first::<Self>(conn).await
}
async fn create(pool: &DbPool, form: &ModBanForm) -> Result<Self, Error> {
- use crate::schema::mod_ban::dsl::*;
+ use crate::schema::mod_ban::dsl::mod_ban;
let conn = &mut get_conn(pool).await?;
insert_into(mod_ban)
.values(form)
}
async fn update(pool: &DbPool, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
- use crate::schema::mod_ban::dsl::*;
+ use crate::schema::mod_ban::dsl::mod_ban;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_ban.find(from_id))
.set(form)
type IdType = i32;
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
- use crate::schema::mod_hide_community::dsl::*;
+ use crate::schema::mod_hide_community::dsl::mod_hide_community;
let conn = &mut get_conn(pool).await?;
mod_hide_community.find(from_id).first::<Self>(conn).await
}
async fn create(pool: &DbPool, form: &ModHideCommunityForm) -> Result<Self, Error> {
- use crate::schema::mod_hide_community::dsl::*;
+ use crate::schema::mod_hide_community::dsl::mod_hide_community;
let conn = &mut get_conn(pool).await?;
insert_into(mod_hide_community)
.values(form)
}
async fn update(pool: &DbPool, from_id: i32, form: &ModHideCommunityForm) -> Result<Self, Error> {
- use crate::schema::mod_hide_community::dsl::*;
+ use crate::schema::mod_hide_community::dsl::mod_hide_community;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_hide_community.find(from_id))
.set(form)
type UpdateForm = ModAddCommunityForm;
type IdType = i32;
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
- use crate::schema::mod_add_community::dsl::*;
+ use crate::schema::mod_add_community::dsl::mod_add_community;
let conn = &mut get_conn(pool).await?;
mod_add_community.find(from_id).first::<Self>(conn).await
}
async fn create(pool: &DbPool, form: &ModAddCommunityForm) -> Result<Self, Error> {
- use crate::schema::mod_add_community::dsl::*;
+ use crate::schema::mod_add_community::dsl::mod_add_community;
let conn = &mut get_conn(pool).await?;
insert_into(mod_add_community)
.values(form)
}
async fn update(pool: &DbPool, from_id: i32, form: &ModAddCommunityForm) -> Result<Self, Error> {
- use crate::schema::mod_add_community::dsl::*;
+ use crate::schema::mod_add_community::dsl::mod_add_community;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_add_community.find(from_id))
.set(form)
type UpdateForm = ModTransferCommunityForm;
type IdType = i32;
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
- use crate::schema::mod_transfer_community::dsl::*;
+ use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
let conn = &mut get_conn(pool).await?;
mod_transfer_community
.find(from_id)
}
async fn create(pool: &DbPool, form: &ModTransferCommunityForm) -> Result<Self, Error> {
- use crate::schema::mod_transfer_community::dsl::*;
+ use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
let conn = &mut get_conn(pool).await?;
insert_into(mod_transfer_community)
.values(form)
from_id: i32,
form: &ModTransferCommunityForm,
) -> Result<Self, Error> {
- use crate::schema::mod_transfer_community::dsl::*;
+ use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_transfer_community.find(from_id))
.set(form)
type UpdateForm = ModAddForm;
type IdType = i32;
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
- use crate::schema::mod_add::dsl::*;
+ use crate::schema::mod_add::dsl::mod_add;
let conn = &mut get_conn(pool).await?;
mod_add.find(from_id).first::<Self>(conn).await
}
async fn create(pool: &DbPool, form: &ModAddForm) -> Result<Self, Error> {
- use crate::schema::mod_add::dsl::*;
+ use crate::schema::mod_add::dsl::mod_add;
let conn = &mut get_conn(pool).await?;
insert_into(mod_add)
.values(form)
}
async fn update(pool: &DbPool, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
- use crate::schema::mod_add::dsl::*;
+ use crate::schema::mod_add::dsl::mod_add;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_add.find(from_id))
.set(form)
type UpdateForm = AdminPurgePersonForm;
type IdType = i32;
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
- use crate::schema::admin_purge_person::dsl::*;
+ use crate::schema::admin_purge_person::dsl::admin_purge_person;
let conn = &mut get_conn(pool).await?;
admin_purge_person.find(from_id).first::<Self>(conn).await
}
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
- use crate::schema::admin_purge_person::dsl::*;
+ use crate::schema::admin_purge_person::dsl::admin_purge_person;
let conn = &mut get_conn(pool).await?;
insert_into(admin_purge_person)
.values(form)
}
async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result<Self, Error> {
- use crate::schema::admin_purge_person::dsl::*;
+ use crate::schema::admin_purge_person::dsl::admin_purge_person;
let conn = &mut get_conn(pool).await?;
diesel::update(admin_purge_person.find(from_id))
.set(form)
type UpdateForm = AdminPurgeCommunityForm;
type IdType = i32;
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
- use crate::schema::admin_purge_community::dsl::*;
+ use crate::schema::admin_purge_community::dsl::admin_purge_community;
let conn = &mut get_conn(pool).await?;
admin_purge_community
.find(from_id)
}
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
- use crate::schema::admin_purge_community::dsl::*;
+ use crate::schema::admin_purge_community::dsl::admin_purge_community;
let conn = &mut get_conn(pool).await?;
insert_into(admin_purge_community)
.values(form)
}
async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result<Self, Error> {
- use crate::schema::admin_purge_community::dsl::*;
+ use crate::schema::admin_purge_community::dsl::admin_purge_community;
let conn = &mut get_conn(pool).await?;
diesel::update(admin_purge_community.find(from_id))
.set(form)
type UpdateForm = AdminPurgePostForm;
type IdType = i32;
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
- use crate::schema::admin_purge_post::dsl::*;
+ use crate::schema::admin_purge_post::dsl::admin_purge_post;
let conn = &mut get_conn(pool).await?;
admin_purge_post.find(from_id).first::<Self>(conn).await
}
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
- use crate::schema::admin_purge_post::dsl::*;
+ use crate::schema::admin_purge_post::dsl::admin_purge_post;
let conn = &mut get_conn(pool).await?;
insert_into(admin_purge_post)
.values(form)
}
async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result<Self, Error> {
- use crate::schema::admin_purge_post::dsl::*;
+ use crate::schema::admin_purge_post::dsl::admin_purge_post;
let conn = &mut get_conn(pool).await?;
diesel::update(admin_purge_post.find(from_id))
.set(form)
type UpdateForm = AdminPurgeCommentForm;
type IdType = i32;
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
- use crate::schema::admin_purge_comment::dsl::*;
+ use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
let conn = &mut get_conn(pool).await?;
admin_purge_comment.find(from_id).first::<Self>(conn).await
}
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
- use crate::schema::admin_purge_comment::dsl::*;
+ use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
let conn = &mut get_conn(pool).await?;
insert_into(admin_purge_comment)
.values(form)
}
async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result<Self, Error> {
- use crate::schema::admin_purge_comment::dsl::*;
+ use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
let conn = &mut get_conn(pool).await?;
diesel::update(admin_purge_comment.find(from_id))
.set(form)
#[cfg(test)]
mod tests {
use crate::{
- source::{comment::*, community::*, instance::Instance, moderator::*, person::*, post::*},
+ source::{
+ comment::{Comment, CommentInsertForm},
+ community::{Community, CommunityInsertForm},
+ instance::Instance,
+ moderator::{
+ ModAdd,
+ ModAddCommunity,
+ ModAddCommunityForm,
+ ModAddForm,
+ ModBan,
+ ModBanForm,
+ ModBanFromCommunity,
+ ModBanFromCommunityForm,
+ ModLockPost,
+ ModLockPostForm,
+ ModRemoveComment,
+ ModRemoveCommentForm,
+ ModRemoveCommunity,
+ ModRemoveCommunityForm,
+ ModRemovePost,
+ ModRemovePostForm,
+ ModStickyPost,
+ ModStickyPostForm,
+ },
+ person::{Person, PersonInsertForm},
+ post::{Post, PostInsertForm},
+ },
traits::Crud,
utils::build_db_pool_for_tests,
};
use serial_test::serial;
+
#[tokio::test]
#[serial]
async fn test_crud() {
use crate::{
newtypes::LocalUserId,
- schema::password_reset_request::dsl::*,
- source::password_reset_request::*,
+ schema::password_reset_request::dsl::{password_reset_request, published, token_encrypted},
+ source::password_reset_request::{PasswordResetRequest, PasswordResetRequestForm},
traits::Crud,
utils::{get_conn, DbPool},
};
-use diesel::{dsl::*, result::Error, ExpressionMethods, QueryDsl};
+use diesel::{
+ dsl::{insert_into, now, IntervalDsl},
+ result::Error,
+ ExpressionMethods,
+ QueryDsl,
+};
use diesel_async::RunQueryDsl;
use sha2::{Digest, Sha256};
instance::Instance,
local_user::{LocalUser, LocalUserInsertForm},
password_reset_request::PasswordResetRequest,
- person::*,
+ person::{Person, PersonInsertForm},
},
traits::Crud,
utils::build_db_pool_for_tests,
use crate::{
newtypes::{DbUrl, PersonId},
- schema::person::dsl::*,
+ schema::person::dsl::{
+ actor_id,
+ avatar,
+ banner,
+ bio,
+ deleted,
+ display_name,
+ local,
+ matrix_user_id,
+ name,
+ person,
+ updated,
+ },
source::person::{Person, PersonInsertForm, PersonUpdateForm},
traits::{ApubActor, Crud},
utils::{functions::lower, get_conn, naive_now, DbPool},
};
-use diesel::{dsl::*, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
+use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
use diesel_async::RunQueryDsl;
mod safe_type {
- use crate::{schema::person::columns::*, source::person::Person, traits::ToSafe};
+ use crate::{
+ schema::person::columns::{
+ actor_id,
+ admin,
+ avatar,
+ ban_expires,
+ banned,
+ banner,
+ bio,
+ bot_account,
+ deleted,
+ display_name,
+ id,
+ inbox_url,
+ instance_id,
+ local,
+ matrix_user_id,
+ name,
+ published,
+ shared_inbox_url,
+ updated,
+ },
+ source::person::Person,
+ traits::ToSafe,
+ };
type Columns = (
id,
#[cfg(test)]
mod tests {
use crate::{
- source::{instance::Instance, person::*},
+ source::{
+ instance::Instance,
+ person::{Person, PersonInsertForm, PersonUpdateForm},
+ },
traits::Crud,
utils::build_db_pool_for_tests,
};
deleted: false,
published: inserted_person.published,
updated: None,
- actor_id: inserted_person.actor_id.to_owned(),
+ actor_id: inserted_person.actor_id.clone(),
bio: None,
local: true,
bot_account: false,
private_key: None,
public_key: "nada".to_owned(),
last_refreshed_at: inserted_person.published,
- inbox_url: inserted_person.inbox_url.to_owned(),
+ inbox_url: inserted_person.inbox_url.clone(),
shared_inbox_url: None,
matrix_user_id: None,
ban_expires: None,
let read_person = Person::read(pool, inserted_person.id).await.unwrap();
let update_person_form = PersonUpdateForm::builder()
- .actor_id(Some(inserted_person.actor_id.to_owned()))
+ .actor_id(Some(inserted_person.actor_id.clone()))
.build();
let updated_person = Person::update(pool, inserted_person.id, &update_person_form)
.await
use crate::{
newtypes::PersonId,
- schema::person_block::dsl::*,
+ schema::person_block::dsl::{person_block, person_id, target_id},
source::person_block::{PersonBlock, PersonBlockForm},
traits::Blockable,
utils::{get_conn, DbPool},
};
-use diesel::{dsl::*, result::Error, ExpressionMethods, QueryDsl};
+use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl;
impl PersonBlock {
use crate::{
newtypes::{CommentId, PersonId, PersonMentionId},
- schema::person_mention::dsl::*,
- source::person_mention::*,
+ schema::person_mention::dsl::{comment_id, person_mention, read, recipient_id},
+ source::person_mention::{PersonMention, PersonMentionInsertForm, PersonMentionUpdateForm},
traits::Crud,
utils::{get_conn, DbPool},
};
-use diesel::{dsl::*, result::Error, *};
+use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl;
#[async_trait]
mod tests {
use crate::{
source::{
- comment::*,
+ comment::{Comment, CommentInsertForm},
community::{Community, CommunityInsertForm},
instance::Instance,
- person::*,
- person_mention::*,
- post::*,
+ person::{Person, PersonInsertForm},
+ person_mention::{PersonMention, PersonMentionInsertForm, PersonMentionUpdateForm},
+ post::{Post, PostInsertForm},
},
traits::Crud,
utils::build_db_pool_for_tests,
use crate::{
newtypes::{CommunityId, DbUrl, PersonId, PostId},
- schema::post::dsl::*,
+ schema::post::dsl::{
+ ap_id,
+ body,
+ community_id,
+ creator_id,
+ deleted,
+ name,
+ post,
+ published,
+ removed,
+ stickied,
+ thumbnail_url,
+ updated,
+ url,
+ },
source::post::{
Post,
PostInsertForm,
utils::{get_conn, naive_now, DbPool, FETCH_LIMIT_MAX},
};
use ::url::Url;
-use diesel::{dsl::*, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
+use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
use diesel_async::RunQueryDsl;
#[async_trait]
pool: &DbPool,
for_creator_id: PersonId,
) -> Result<Vec<Self>, Error> {
- use crate::schema::post::dsl::*;
let conn = &mut get_conn(pool).await?;
let pictrs_search = "%pictrs/image%";
type Form = PostLikeForm;
type IdType = PostId;
async fn like(pool: &DbPool, post_like_form: &PostLikeForm) -> Result<Self, Error> {
- use crate::schema::post_like::dsl::*;
+ use crate::schema::post_like::dsl::{person_id, post_id, post_like};
let conn = &mut get_conn(pool).await?;
insert_into(post_like)
.values(post_like_form)
impl Saveable for PostSaved {
type Form = PostSavedForm;
async fn save(pool: &DbPool, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
- use crate::schema::post_saved::dsl::*;
+ use crate::schema::post_saved::dsl::{person_id, post_id, post_saved};
let conn = &mut get_conn(pool).await?;
insert_into(post_saved)
.values(post_saved_form)
.await
}
async fn unsave(pool: &DbPool, post_saved_form: &PostSavedForm) -> Result<usize, Error> {
- use crate::schema::post_saved::dsl::*;
+ use crate::schema::post_saved::dsl::{person_id, post_id, post_saved};
let conn = &mut get_conn(pool).await?;
diesel::delete(
post_saved
impl Readable for PostRead {
type Form = PostReadForm;
async fn mark_as_read(pool: &DbPool, post_read_form: &PostReadForm) -> Result<Self, Error> {
- use crate::schema::post_read::dsl::*;
+ use crate::schema::post_read::dsl::{person_id, post_id, post_read};
let conn = &mut get_conn(pool).await?;
insert_into(post_read)
.values(post_read_form)
}
async fn mark_as_unread(pool: &DbPool, post_read_form: &PostReadForm) -> Result<usize, Error> {
- use crate::schema::post_read::dsl::*;
+ use crate::schema::post_read::dsl::{person_id, post_id, post_read};
let conn = &mut get_conn(pool).await?;
diesel::delete(
post_read
impl DeleteableOrRemoveable for Post {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
- self.name = "".into();
+ self.name = String::new();
self.url = None;
self.body = None;
self.embed_title = None;
source::{
community::{Community, CommunityInsertForm},
instance::Instance,
- person::*,
- post::*,
+ person::{Person, PersonInsertForm},
+ post::{
+ Post,
+ PostInsertForm,
+ PostLike,
+ PostLikeForm,
+ PostRead,
+ PostReadForm,
+ PostSaved,
+ PostSavedForm,
+ PostUpdateForm,
+ },
},
traits::{Crud, Likeable, Readable, Saveable},
utils::build_db_pool_for_tests,
embed_description: None,
embed_video_url: None,
thumbnail_url: None,
- ap_id: inserted_post.ap_id.to_owned(),
+ ap_id: inserted_post.ap_id.clone(),
local: true,
language_id: Default::default(),
};
use crate::{
newtypes::{PersonId, PostReportId},
- schema::post_report::dsl::*,
- source::post_report::*,
+ schema::post_report::dsl::{post_report, resolved, resolver_id, updated},
+ source::post_report::{PostReport, PostReportForm},
traits::Reportable,
utils::{get_conn, naive_now, DbPool},
};
-use diesel::{dsl::*, result::Error, ExpressionMethods, QueryDsl};
+use diesel::{
+ dsl::{insert_into, update},
+ result::Error,
+ ExpressionMethods,
+ QueryDsl,
+};
use diesel_async::RunQueryDsl;
#[async_trait]
use crate::{
newtypes::{DbUrl, PersonId, PrivateMessageId},
- schema::private_message::dsl::*,
- source::private_message::*,
+ schema::private_message::dsl::{ap_id, private_message, read, recipient_id},
+ source::private_message::{PrivateMessage, PrivateMessageInsertForm, PrivateMessageUpdateForm},
traits::{Crud, DeleteableOrRemoveable},
utils::{get_conn, DbPool},
};
-use diesel::{dsl::*, result::Error, *};
+use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl;
use lemmy_utils::error::LemmyError;
use url::Url;
impl DeleteableOrRemoveable for PrivateMessage {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
- self.content = "".into();
+ self.content = String::new();
self
}
}
#[cfg(test)]
mod tests {
use crate::{
- source::{instance::Instance, person::*, private_message::*},
+ source::{
+ instance::Instance,
+ person::{Person, PersonInsertForm},
+ private_message::{PrivateMessage, PrivateMessageInsertForm, PrivateMessageUpdateForm},
+ },
traits::Crud,
utils::build_db_pool_for_tests,
};
read: false,
updated: None,
published: inserted_private_message.published,
- ap_id: inserted_private_message.ap_id.to_owned(),
+ ap_id: inserted_private_message.ap_id.clone(),
local: true,
};
use crate::{
newtypes::{PersonId, PrivateMessageReportId},
- schema::private_message_report::dsl::*,
+ schema::private_message_report::dsl::{private_message_report, resolved, resolver_id, updated},
source::private_message_report::{PrivateMessageReport, PrivateMessageReportForm},
traits::Reportable,
utils::{get_conn, naive_now, DbPool},
};
-use diesel::{dsl::*, result::Error, *};
+use diesel::{
+ dsl::{insert_into, update},
+ result::Error,
+ ExpressionMethods,
+ QueryDsl,
+};
use diesel_async::RunQueryDsl;
#[async_trait]
use crate::{
newtypes::LocalUserId,
- schema::registration_application::dsl::*,
- source::registration_application::*,
+ schema::registration_application::dsl::{local_user_id, registration_application},
+ source::registration_application::{
+ RegistrationApplication,
+ RegistrationApplicationInsertForm,
+ RegistrationApplicationUpdateForm,
+ },
traits::Crud,
utils::{get_conn, DbPool},
};
use crate::{
- schema::secret::dsl::*,
+ schema::secret::dsl::secret,
source::secret::Secret,
utils::{get_conn, DbPool},
};
use crate::{
newtypes::{DbUrl, SiteId},
- schema::site::dsl::*,
- source::{actor_language::SiteLanguage, site::*},
+ schema::site::dsl::{actor_id, id, site},
+ source::{
+ actor_language::SiteLanguage,
+ site::{Site, SiteInsertForm, SiteUpdateForm},
+ },
traits::Crud,
utils::{get_conn, DbPool},
};
-use diesel::{dsl::*, result::Error, ExpressionMethods, QueryDsl};
+use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl;
use url::Url;
impl Display for DbUrl {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
- self.to_owned().0.fmt(f)
+ self.clone().0.fmt(f)
}
}
pub async fn get_conn(
pool: &DbPool,
) -> Result<PooledConnection<AsyncDieselConnectionManager<AsyncPgConnection>>, DieselError> {
- // TODO Maybe find a better diesel error for this
- pool.get().await.map_err(|_| DieselError::NotInTransaction)
+ pool.get().await.map_err(|e| QueryBuilderError(e.into()))
}
pub fn get_database_url_from_env() -> Result<String, VarError> {
// An empty string is an erase
Some(unwrapped) => {
if !unwrapped.eq("") {
- Some(Some(unwrapped.to_owned()))
+ Some(Some(unwrapped.clone()))
} else {
Some(None)
}
pub fn diesel_option_overwrite_to_url(
opt: &Option<String>,
) -> Result<Option<Option<DbUrl>>, LemmyError> {
- match opt.as_ref().map(|s| s.as_str()) {
+ match opt.as_ref().map(std::string::String::as_str) {
// An empty string is an erase
Some("") => Ok(Some(None)),
Some(str_url) => match Url::parse(str_url) {
pub fn diesel_option_overwrite_to_url_create(
opt: &Option<String>,
) -> Result<Option<DbUrl>, LemmyError> {
- match opt.as_ref().map(|s| s.as_str()) {
+ match opt.as_ref().map(std::string::String::as_str) {
// An empty string is nothing
Some("") => Ok(None),
Some(str_url) => match Url::parse(str_url) {
});
pub mod functions {
- use diesel::sql_types::*;
+ use diesel::sql_types::{BigInt, Text, Timestamp};
sql_function! {
fn hot_rank(score: BigInt, time: Timestamp) -> Integer;
#[test]
fn test_diesel_option_overwrite() {
assert_eq!(diesel_option_overwrite(&None), None);
- assert_eq!(diesel_option_overwrite(&Some("".to_string())), Some(None));
+ assert_eq!(diesel_option_overwrite(&Some(String::new())), Some(None));
assert_eq!(
diesel_option_overwrite(&Some("test".to_string())),
Some(Some("test".to_string()))
fn test_diesel_option_overwrite_to_url() {
assert!(matches!(diesel_option_overwrite_to_url(&None), Ok(None)));
assert!(matches!(
- diesel_option_overwrite_to_url(&Some("".to_string())),
+ diesel_option_overwrite_to_url(&Some(String::new())),
Ok(Some(None))
));
assert!(matches!(
use crate::structs::CommentReportView;
use diesel::{
- dsl::*,
+ dsl::now,
result::Error,
BoolExpressionMethods,
ExpressionMethods,
admin: bool,
community_id: Option<CommunityId>,
) -> Result<i64, Error> {
- use diesel::dsl::*;
+ use diesel::dsl::count;
let conn = &mut get_conn(pool).await?;
use crate::comment_report_view::{CommentReportQuery, CommentReportView};
use lemmy_db_schema::{
aggregates::structs::CommentAggregates,
- source::{comment::*, comment_report::*, community::*, instance::Instance, person::*, post::*},
+ source::{
+ comment::{Comment, CommentInsertForm},
+ comment_report::{CommentReport, CommentReportForm},
+ community::{
+ Community,
+ CommunityInsertForm,
+ CommunityModerator,
+ CommunityModeratorForm,
+ CommunitySafe,
+ },
+ instance::Instance,
+ person::{Person, PersonInsertForm, PersonSafe},
+ post::{Post, PostInsertForm},
+ },
traits::{Crud, Joinable, Reportable},
utils::build_db_pool_for_tests,
};
.await
.unwrap();
let expected_jessica_report_view = CommentReportView {
- comment_report: inserted_jessica_report.to_owned(),
- comment: inserted_comment.to_owned(),
+ comment_report: inserted_jessica_report.clone(),
+ comment: inserted_comment.clone(),
post: inserted_post,
community: CommunitySafe {
id: inserted_community.id,
removed: false,
deleted: false,
nsfw: false,
- actor_id: inserted_community.actor_id.to_owned(),
+ actor_id: inserted_community.actor_id.clone(),
local: true,
title: inserted_community.title,
description: None,
display_name: None,
published: inserted_jessica.published,
avatar: None,
- actor_id: inserted_jessica.actor_id.to_owned(),
+ actor_id: inserted_jessica.actor_id.clone(),
local: true,
banned: false,
deleted: false,
bio: None,
banner: None,
updated: None,
- inbox_url: inserted_jessica.inbox_url.to_owned(),
+ inbox_url: inserted_jessica.inbox_url.clone(),
shared_inbox_url: None,
matrix_user_id: None,
ban_expires: None,
},
comment_creator: PersonSafe {
id: inserted_timmy.id,
- name: inserted_timmy.name.to_owned(),
+ name: inserted_timmy.name.clone(),
display_name: None,
published: inserted_timmy.published,
avatar: None,
- actor_id: inserted_timmy.actor_id.to_owned(),
+ actor_id: inserted_timmy.actor_id.clone(),
local: true,
banned: false,
deleted: false,
bio: None,
banner: None,
updated: None,
- inbox_url: inserted_timmy.inbox_url.to_owned(),
+ inbox_url: inserted_timmy.inbox_url.clone(),
shared_inbox_url: None,
matrix_user_id: None,
ban_expires: None,
display_name: None,
published: inserted_sara.published,
avatar: None,
- actor_id: inserted_sara.actor_id.to_owned(),
+ actor_id: inserted_sara.actor_id.clone(),
local: true,
banned: false,
deleted: false,
bio: None,
banner: None,
updated: None,
- inbox_url: inserted_sara.inbox_url.to_owned(),
+ inbox_url: inserted_sara.inbox_url.clone(),
shared_inbox_url: None,
matrix_user_id: None,
ban_expires: None,
assert_eq!(
reports,
[
- expected_jessica_report_view.to_owned(),
- expected_sara_report_view.to_owned()
+ expected_jessica_report_view.clone(),
+ expected_sara_report_view.clone()
]
);
.updated;
expected_jessica_report_view_after_resolve.resolver = Some(PersonSafe {
id: inserted_timmy.id,
- name: inserted_timmy.name.to_owned(),
+ name: inserted_timmy.name.clone(),
display_name: None,
published: inserted_timmy.published,
avatar: None,
- actor_id: inserted_timmy.actor_id.to_owned(),
+ actor_id: inserted_timmy.actor_id.clone(),
local: true,
banned: false,
deleted: false,
bio: None,
banner: None,
updated: None,
- inbox_url: inserted_timmy.inbox_url.to_owned(),
+ inbox_url: inserted_timmy.inbox_url.clone(),
shared_inbox_url: None,
matrix_user_id: None,
ban_expires: None,
use crate::structs::CommentView;
use diesel::{
- dsl::*,
+ dsl::now,
result::Error,
BoolExpressionMethods,
ExpressionMethods,
impl<'a> CommentQuery<'a> {
pub async fn list(self) -> Result<Vec<CommentView>, Error> {
- use diesel::dsl::*;
let conn = &mut get_conn(self.pool).await?;
// The left join below will return None in this case
#[cfg(test)]
mod tests {
- use crate::comment_view::*;
+ use crate::comment_view::{
+ Comment,
+ CommentQuery,
+ CommentSortType,
+ CommentView,
+ Community,
+ CommunitySafe,
+ DbPool,
+ LocalUser,
+ Person,
+ PersonBlock,
+ PersonSafe,
+ Post,
+ };
use lemmy_db_schema::{
aggregates::structs::CommentAggregates,
newtypes::LanguageId,
source::{
actor_language::LocalUserLanguage,
- comment::*,
- community::*,
+ comment::{CommentInsertForm, CommentLike, CommentLikeForm},
+ community::CommunityInsertForm,
instance::Instance,
language::Language,
local_user::LocalUserInsertForm,
- person::*,
+ person::PersonInsertForm,
person_block::PersonBlockForm,
- post::*,
+ post::PostInsertForm,
},
traits::{Blockable, Crud, Likeable},
utils::build_db_pool_for_tests,
let inserted_person = Person::create(pool, &new_person).await.unwrap();
let local_user_form = LocalUserInsertForm::builder()
.person_id(inserted_person.id)
- .password_encrypted("".to_string())
+ .password_encrypted(String::new())
.build();
let inserted_local_user = LocalUser::create(pool, &local_user_form).await.unwrap();
let expected_comment_view_no_person = expected_comment_view(&data, pool).await;
- let mut expected_comment_view_with_person = expected_comment_view_no_person.to_owned();
+ let mut expected_comment_view_with_person = expected_comment_view_no_person.clone();
expected_comment_view_with_person.my_vote = Some(1);
let read_comment_views_no_person = CommentQuery::builder()
updated: None,
local: true,
distinguished: false,
- path: data.inserted_comment_0.to_owned().path,
+ path: data.inserted_comment_0.clone().path,
language_id: LanguageId(0),
},
creator: PersonSafe {
display_name: None,
published: data.inserted_person.published,
avatar: None,
- actor_id: data.inserted_person.actor_id.to_owned(),
+ actor_id: data.inserted_person.actor_id.clone(),
local: true,
banned: false,
deleted: false,
bio: None,
banner: None,
updated: None,
- inbox_url: data.inserted_person.inbox_url.to_owned(),
+ inbox_url: data.inserted_person.inbox_url.clone(),
shared_inbox_url: None,
matrix_user_id: None,
ban_expires: None,
},
post: Post {
id: data.inserted_post.id,
- name: data.inserted_post.name.to_owned(),
+ name: data.inserted_post.name.clone(),
creator_id: data.inserted_person.id,
url: None,
body: None,
embed_description: None,
embed_video_url: None,
thumbnail_url: None,
- ap_id: data.inserted_post.ap_id.to_owned(),
+ ap_id: data.inserted_post.ap_id.clone(),
local: true,
language_id: Default::default(),
},
removed: false,
deleted: false,
nsfw: false,
- actor_id: data.inserted_community.actor_id.to_owned(),
+ actor_id: data.inserted_community.actor_id.clone(),
local: true,
title: "nada".to_owned(),
description: None,
use crate::structs::PostReportView;
use diesel::{
- dsl::*,
+ dsl::now,
result::Error,
BoolExpressionMethods,
ExpressionMethods,
admin: bool,
community_id: Option<CommunityId>,
) -> Result<i64, Error> {
- use diesel::dsl::*;
+ use diesel::dsl::count;
let conn = &mut get_conn(pool).await?;
let mut query = post_report::table
.inner_join(post::table)
use lemmy_db_schema::{
aggregates::structs::PostAggregates,
source::{
- community::*,
+ community::{
+ Community,
+ CommunityInsertForm,
+ CommunityModerator,
+ CommunityModeratorForm,
+ CommunitySafe,
+ },
instance::Instance,
- person::*,
- post::*,
+ person::{Person, PersonInsertForm, PersonSafe},
+ post::{Post, PostInsertForm},
post_report::{PostReport, PostReportForm},
},
traits::{Crud, Joinable, Reportable},
.await
.unwrap();
let expected_jessica_report_view = PostReportView {
- post_report: inserted_jessica_report.to_owned(),
- post: inserted_post.to_owned(),
+ post_report: inserted_jessica_report.clone(),
+ post: inserted_post.clone(),
community: CommunitySafe {
id: inserted_community.id,
name: inserted_community.name,
removed: false,
deleted: false,
nsfw: false,
- actor_id: inserted_community.actor_id.to_owned(),
+ actor_id: inserted_community.actor_id.clone(),
local: true,
title: inserted_community.title,
description: None,
display_name: None,
published: inserted_jessica.published,
avatar: None,
- actor_id: inserted_jessica.actor_id.to_owned(),
+ actor_id: inserted_jessica.actor_id.clone(),
local: true,
banned: false,
deleted: false,
bio: None,
banner: None,
updated: None,
- inbox_url: inserted_jessica.inbox_url.to_owned(),
+ inbox_url: inserted_jessica.inbox_url.clone(),
shared_inbox_url: None,
matrix_user_id: None,
ban_expires: None,
},
post_creator: PersonSafe {
id: inserted_timmy.id,
- name: inserted_timmy.name.to_owned(),
+ name: inserted_timmy.name.clone(),
display_name: None,
published: inserted_timmy.published,
avatar: None,
- actor_id: inserted_timmy.actor_id.to_owned(),
+ actor_id: inserted_timmy.actor_id.clone(),
local: true,
banned: false,
deleted: false,
bio: None,
banner: None,
updated: None,
- inbox_url: inserted_timmy.inbox_url.to_owned(),
+ inbox_url: inserted_timmy.inbox_url.clone(),
shared_inbox_url: None,
matrix_user_id: None,
ban_expires: None,
display_name: None,
published: inserted_sara.published,
avatar: None,
- actor_id: inserted_sara.actor_id.to_owned(),
+ actor_id: inserted_sara.actor_id.clone(),
local: true,
banned: false,
deleted: false,
bio: None,
banner: None,
updated: None,
- inbox_url: inserted_sara.inbox_url.to_owned(),
+ inbox_url: inserted_sara.inbox_url.clone(),
shared_inbox_url: None,
matrix_user_id: None,
ban_expires: None,
assert_eq!(
reports,
[
- expected_jessica_report_view.to_owned(),
- expected_sara_report_view.to_owned()
+ expected_jessica_report_view.clone(),
+ expected_sara_report_view.clone()
]
);
.updated = read_jessica_report_view_after_resolve.post_report.updated;
expected_jessica_report_view_after_resolve.resolver = Some(PersonSafe {
id: inserted_timmy.id,
- name: inserted_timmy.name.to_owned(),
+ name: inserted_timmy.name.clone(),
display_name: None,
published: inserted_timmy.published,
avatar: None,
- actor_id: inserted_timmy.actor_id.to_owned(),
+ actor_id: inserted_timmy.actor_id.clone(),
local: true,
banned: false,
deleted: false,
bio: None,
banner: None,
updated: None,
- inbox_url: inserted_timmy.inbox_url.to_owned(),
+ inbox_url: inserted_timmy.inbox_url.clone(),
shared_inbox_url: None,
matrix_user_id: None,
ban_expires: None,
use crate::structs::PostView;
use diesel::{
debug_query,
- dsl::*,
+ dsl::{now, IntervalDsl},
pg::Pg,
result::Error,
sql_function,
impl<'a> PostQuery<'a> {
pub async fn list(self) -> Result<Vec<PostView>, Error> {
- use diesel::dsl::*;
let conn = &mut get_conn(self.pool).await?;
// The left join below will return None in this case
let searcher = fuzzy_search(&search_term);
query = query.filter(
post::name
- .ilike(searcher.to_owned())
+ .ilike(searcher.clone())
.or(post::body.ilike(searcher)),
);
}
newtypes::LanguageId,
source::{
actor_language::LocalUserLanguage,
- community::*,
+ community::{Community, CommunityInsertForm, CommunitySafe},
community_block::{CommunityBlock, CommunityBlockForm},
instance::Instance,
language::Language,
local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
- person::*,
+ person::{Person, PersonInsertForm, PersonSafe},
person_block::{PersonBlock, PersonBlockForm},
- post::*,
+ post::{Post, PostInsertForm, PostLike, PostLikeForm},
},
traits::{Blockable, Crud, Likeable},
utils::{build_db_pool_for_tests, DbPool},
let person_name = "tegan".to_string();
let new_person = PersonInsertForm::builder()
- .name(person_name.to_owned())
+ .name(person_name.clone())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let local_user_form = LocalUserInsertForm::builder()
.person_id(inserted_person.id)
- .password_encrypted("".to_string())
+ .password_encrypted(String::new())
.build();
let inserted_local_user = LocalUser::create(pool, &local_user_form).await.unwrap();
embed_description: None,
embed_video_url: None,
thumbnail_url: None,
- ap_id: inserted_post.ap_id.to_owned(),
+ ap_id: inserted_post.ap_id.clone(),
local: true,
language_id: LanguageId(47),
},
display_name: None,
published: inserted_person.published,
avatar: None,
- actor_id: inserted_person.actor_id.to_owned(),
+ actor_id: inserted_person.actor_id.clone(),
local: true,
admin: false,
bot_account: false,
bio: None,
banner: None,
updated: None,
- inbox_url: inserted_person.inbox_url.to_owned(),
+ inbox_url: inserted_person.inbox_url.clone(),
shared_inbox_url: None,
matrix_user_id: None,
ban_expires: None,
removed: false,
deleted: false,
nsfw: false,
- actor_id: inserted_community.actor_id.to_owned(),
+ actor_id: inserted_community.actor_id.clone(),
local: true,
title: "nada".to_owned(),
description: None,
/// Returns the current unresolved post report count for the communities you mod
pub async fn get_report_count(pool: &DbPool) -> Result<i64, Error> {
- use diesel::dsl::*;
+ use diesel::dsl::count;
let conn = &mut get_conn(pool).await?;
private_message_report::table
/// Gets the number of unread messages
pub async fn get_unread_messages(pool: &DbPool, my_person_id: PersonId) -> Result<i64, Error> {
- use diesel::dsl::*;
+ use diesel::dsl::count;
let conn = &mut get_conn(pool).await?;
private_message::table
.filter(private_message::read.eq(false))
source::{
instance::Instance,
local_user::{LocalUser, LocalUserInsertForm, LocalUserSettings, LocalUserUpdateForm},
- person::*,
+ person::{Person, PersonInsertForm, PersonSafe},
registration_application::{
RegistrationApplication,
RegistrationApplicationInsertForm,
.unwrap();
let mut expected_sara_app_view = RegistrationApplicationView {
- registration_application: sara_app.to_owned(),
+ registration_application: sara_app.clone(),
creator_local_user: LocalUserSettings {
id: inserted_sara_local_user.id,
person_id: inserted_sara_local_user.person_id,
},
creator: PersonSafe {
id: inserted_sara_person.id,
- name: inserted_sara_person.name.to_owned(),
+ name: inserted_sara_person.name.clone(),
display_name: None,
published: inserted_sara_person.published,
avatar: None,
- actor_id: inserted_sara_person.actor_id.to_owned(),
+ actor_id: inserted_sara_person.actor_id.clone(),
local: true,
banned: false,
ban_expires: None,
bio: None,
banner: None,
updated: None,
- inbox_url: inserted_sara_person.inbox_url.to_owned(),
+ inbox_url: inserted_sara_person.inbox_url.clone(),
shared_inbox_url: None,
matrix_user_id: None,
instance_id: inserted_instance.id,
assert_eq!(
apps,
- [
- read_jess_app_view.to_owned(),
- expected_sara_app_view.to_owned()
- ]
+ [read_jess_app_view.clone(), expected_sara_app_view.clone()]
);
// Make sure the counts are correct
expected_sara_app_view.admin = Some(PersonSafe {
id: inserted_timmy_person.id,
- name: inserted_timmy_person.name.to_owned(),
+ name: inserted_timmy_person.name.clone(),
display_name: None,
published: inserted_timmy_person.published,
avatar: None,
- actor_id: inserted_timmy_person.actor_id.to_owned(),
+ actor_id: inserted_timmy_person.actor_id.clone(),
local: true,
banned: false,
ban_expires: None,
bio: None,
banner: None,
updated: None,
- inbox_url: inserted_timmy_person.inbox_url.to_owned(),
+ inbox_url: inserted_timmy_person.inbox_url.clone(),
shared_inbox_url: None,
matrix_user_id: None,
instance_id: inserted_instance.id,
use crate::structs::CommentReplyView;
use diesel::{
- dsl::*,
+ dsl::now,
result::Error,
BoolExpressionMethods,
ExpressionMethods,
/// Gets the number of unread replies
pub async fn get_unread_replies(pool: &DbPool, my_person_id: PersonId) -> Result<i64, Error> {
- use diesel::dsl::*;
+ use diesel::dsl::count;
let conn = &mut get_conn(pool).await?;
impl<'a> CommentReplyQuery<'a> {
pub async fn list(self) -> Result<Vec<CommentReplyView>, Error> {
- use diesel::dsl::*;
let conn = &mut get_conn(self.pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
use crate::structs::CommunityPersonBanView;
-use diesel::{dsl::*, result::Error, BoolExpressionMethods, ExpressionMethods, QueryDsl};
+use diesel::{dsl::now, result::Error, BoolExpressionMethods, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl;
use lemmy_db_schema::{
newtypes::{CommunityId, PersonId},
if let Some(search_term) = self.search_term {
let searcher = fuzzy_search(&search_term);
query = query
- .filter(community::name.ilike(searcher.to_owned()))
+ .filter(community::name.ilike(searcher.clone()))
.or_filter(community::title.ilike(searcher));
};
use crate::structs::PersonMentionView;
use diesel::{
- dsl::*,
+ dsl::now,
result::Error,
BoolExpressionMethods,
ExpressionMethods,
/// Gets the number of unread mentions
pub async fn get_unread_mentions(pool: &DbPool, my_person_id: PersonId) -> Result<i64, Error> {
- use diesel::dsl::*;
+ use diesel::dsl::count;
let conn = &mut get_conn(pool).await?;
person_mention::table
impl<'a> PersonMentionQuery<'a> {
pub async fn list(self) -> Result<Vec<PersonMentionView>, Error> {
- use diesel::dsl::*;
let conn = &mut get_conn(self.pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
use crate::structs::PersonViewSafe;
use diesel::{
- dsl::*,
+ dsl::{now, IntervalDsl},
result::Error,
BoolExpressionMethods,
ExpressionMethods,
if let Some(search_term) = self.search_term {
let searcher = fuzzy_search(&search_term);
query = query
- .filter(person::name.ilike(searcher.to_owned()))
+ .filter(person::name.ilike(searcher.clone()))
.or_filter(person::display_name.ilike(searcher));
}
-use actix_web::{error::ErrorBadRequest, *};
+use actix_web::{error::ErrorBadRequest, web, Error, HttpRequest, HttpResponse, Result};
use anyhow::anyhow;
use chrono::{DateTime, NaiveDateTime, Utc};
use lemmy_db_schema::{
let mut channel_builder = ChannelBuilder::default();
channel_builder
- .namespaces(RSS_NAMESPACE.to_owned())
+ .namespaces(RSS_NAMESPACE.clone())
.title(&format!("{} - {}", site_view.site.name, listing_type))
.link(context.settings().get_protocol_and_hostname())
.items(items);
_ => return Err(ErrorBadRequest(LemmyError::from(anyhow!("wrong_type")))),
};
- let jwt_secret = context.secret().jwt_secret.to_owned();
+ let jwt_secret = context.secret().jwt_secret.clone();
let protocol_and_hostname = context.settings().get_protocol_and_hostname();
let builder = match request_type {
fn get_sort_type(info: web::Query<Params>) -> Result<SortType, ParseError> {
let sort_query = info
.sort
- .to_owned()
+ .clone()
.unwrap_or_else(|| SortType::Hot.to_string());
SortType::from_str(&sort_query)
}
let mut channel_builder = ChannelBuilder::default();
channel_builder
- .namespaces(RSS_NAMESPACE.to_owned())
+ .namespaces(RSS_NAMESPACE.clone())
.title(&format!("{} - {}", site_view.site.name, person.name))
.link(person.actor_id.to_string())
.items(items);
let mut channel_builder = ChannelBuilder::default();
channel_builder
- .namespaces(RSS_NAMESPACE.to_owned())
+ .namespaces(RSS_NAMESPACE.clone())
.title(&format!("{} - {}", site_view.site.name, community.name))
.link(community.actor_id.to_string())
.items(items);
let mut channel_builder = ChannelBuilder::default();
channel_builder
- .namespaces(RSS_NAMESPACE.to_owned())
+ .namespaces(RSS_NAMESPACE.clone())
.title(&format!("{} - Subscribed", site_view.site.name))
.link(protocol_and_hostname)
.items(items);
let mut channel_builder = ChannelBuilder::default();
channel_builder
- .namespaces(RSS_NAMESPACE.to_owned())
+ .namespaces(RSS_NAMESPACE.clone())
.title(&format!("{} - Inbox", site_view.site.name))
.link(format!("{}/inbox", protocol_and_hostname,))
.items(items);
i.pub_date(dt.to_rfc2822());
let post_url = format!("{}/post/{}", protocol_and_hostname, p.post.id);
- i.link(post_url.to_owned());
- i.comments(post_url.to_owned());
+ i.link(post_url.clone());
+ i.comments(post_url.clone());
let guid = GuidBuilder::default()
.permalink(true)
.value(&post_url)
-use actix_web::{error::ErrorBadRequest, *};
+use actix_web::{error::ErrorBadRequest, web, Error, HttpResponse, Result};
use anyhow::anyhow;
use lemmy_db_views::structs::SiteView;
use lemmy_utils::{error::LemmyError, version};
.collect();
let json = WebfingerResponse {
- subject: info.resource.to_owned(),
+ subject: info.resource.clone(),
links,
};
WebfingerLink {
rel: Some("http://webfinger.net/rel/profile-page".to_string()),
kind: Some("text/html".to_string()),
- href: Some(url.to_owned()),
+ href: Some(url.clone()),
},
WebfingerLink {
rel: Some("self".to_string()),
) -> Result<(), LemmyError> {
let email_config = settings
.email
- .to_owned()
+ .clone()
.ok_or_else(|| LemmyError::from_message("no_email_setup"))?;
- let domain = settings.hostname.to_owned();
+ let domain = settings.hostname.clone();
let (smtp_server, smtp_port) = {
let email_and_port = email_config.smtp_server.split(':').collect::<Vec<&str>>();
// The initial value
if rate_limit.allowance == -2f64 {
- rate_limit.allowance = rate as f64;
+ rate_limit.allowance = f64::from(rate);
};
rate_limit.last_checked = current;
- rate_limit.allowance += time_passed * (rate as f64 / per as f64);
- if rate_limit.allowance > rate as f64 {
- rate_limit.allowance = rate as f64;
+ rate_limit.allowance += time_passed * (f64::from(rate) / f64::from(per));
+ if rate_limit.allowance > f64::from(rate) {
+ rate_limit.allowance = f64::from(rate);
}
if rate_limit.allowance < 1.0 {
/// `lemmy-alpha` instead. It has no effect in production.
pub fn get_hostname_without_port(&self) -> Result<String, anyhow::Error> {
Ok(
- self
+ (*self
.hostname
.split(':')
.collect::<Vec<&str>>()
.first()
- .context(location_info!())?
- .to_string(),
+ .context(location_info!())?)
+ .to_string(),
)
}
pub fn webfinger_regex(&self) -> Regex {
- WEBFINGER_REGEX.to_owned()
+ WEBFINGER_REGEX.clone()
}
pub fn pictrs_config(&self) -> Result<PictrsConfig, LemmyError> {
self
.pictrs
- .to_owned()
+ .clone()
.ok_or_else(|| anyhow!("images_disabled").into())
}
}
assert_eq!(slur_check(test, &slur_regex), Err(has_slurs_vec));
assert_eq!(slur_check(slur_free, &slur_regex), Ok(()));
if let Err(slur_vec) = slur_check(test, &slur_regex) {
- assert_eq!(&slurs_vec_to_str(slur_vec), has_slurs_err_str);
+ assert_eq!(&slurs_vec_to_str(&slur_vec), has_slurs_err_str);
}
}
pub fn check_slurs(text: &str, slur_regex: &Option<Regex>) -> Result<(), LemmyError> {
if let Err(slurs) = slur_check(text, slur_regex) {
Err(LemmyError::from_error_message(
- anyhow::anyhow!("{}", slurs_vec_to_str(slurs)),
+ anyhow::anyhow!("{}", slurs_vec_to_str(&slurs)),
"slurs",
))
} else {
}
}
-pub(crate) fn slurs_vec_to_str(slurs: Vec<&str>) -> String {
+pub(crate) fn slurs_vec_to_str(slurs: &[&str]) -> String {
let start = "No slurs - ";
let combined = &slurs.join(", ");
[start, combined].concat()
}
pub fn clean_url_params(url: &Url) -> Url {
- let mut url_out = url.to_owned();
+ let mut url_out = url.clone();
if url.query().is_some() {
let new_query = url
.query_pairs()
use crate::{
- messages::*,
+ messages::{CaptchaItem, StandardMessage, WsMessage},
serialize_websocket_message,
LemmyContext,
OperationType,
};
use actix::prelude::*;
use anyhow::Context as acontext;
-use lemmy_api_common::{comment::*, post::*};
+use lemmy_api_common::{comment::CommentResponse, post::PostResponse};
use lemmy_db_schema::{
newtypes::{CommunityId, LocalUserId, PostId},
source::secret::Secret,
ctx: &mut Context<Self>,
) -> impl Future<Output = Result<String, LemmyError>> {
let ip: IpAddr = match self.sessions.get(&msg.id) {
- Some(info) => info.ip.to_owned(),
+ Some(info) => info.ip.clone(),
None => IpAddr("blank_ip".to_string()),
};
let context = LemmyContext {
pool: self.pool.clone(),
chat_server: ctx.address(),
- client: self.client.to_owned(),
- settings: self.settings.to_owned(),
- secret: self.secret.to_owned(),
- rate_limit_cell: self.rate_limit_cell.to_owned(),
+ client: self.client.clone(),
+ settings: self.settings.clone(),
+ secret: self.secret.clone(),
+ rate_limit_cell: self.rate_limit_cell.clone(),
};
let message_handler_crud = self.message_handler_crud;
let message_handler = self.message_handler;
use crate::{
chat_server::{ChatServer, SessionInfo},
- messages::*,
+ messages::{
+ CaptchaItem,
+ CheckCaptcha,
+ Connect,
+ Disconnect,
+ GetCommunityUsersOnline,
+ GetPostUsersOnline,
+ GetUsersOnline,
+ JoinCommunityRoom,
+ JoinModRoom,
+ JoinPostRoom,
+ JoinUserRoom,
+ SendAllMessage,
+ SendComment,
+ SendCommunityRoomMessage,
+ SendModRoomMessage,
+ SendPost,
+ SendUserRoomMessage,
+ StandardMessage,
+ },
OperationType,
};
use actix::{Actor, Context, Handler, ResponseFuture};
type Result = ResponseFuture<Result<String, std::convert::Infallible>>;
fn handle(&mut self, msg: StandardMessage, ctx: &mut Context<Self>) -> Self::Result {
+ use tracing::Instrument;
let fut = self.parse_json_message(msg, ctx);
let span = root_span();
- use tracing::Instrument;
-
Box::pin(
async move {
match fut.await {
) -> Result<HttpResponse, Error> {
ws::start(
WsSession {
- cs_addr: context.chat_server().to_owned(),
+ cs_addr: context.chat_server().clone(),
id: 0,
hb: Instant::now(),
ip: get_ip(&req.connection_info()),
- rate_limiter: rate_limiter.as_ref().to_owned(),
+ rate_limiter: rate_limiter.as_ref().clone(),
},
&req,
stream,
.cs_addr
.send(Connect {
addr: addr.recipient(),
- ip: self.ip.to_owned(),
+ ip: self.ip.clone(),
})
.into_actor(self)
.then(|res, act, ctx| {
// notify chat server
self.cs_addr.do_send(Disconnect {
id: self.id,
- ip: self.ip.to_owned(),
+ ip: self.ip.clone(),
});
Running::Stop
}
// notify chat server
act.cs_addr.do_send(Disconnect {
id: act.id,
- ip: act.ip.to_owned(),
+ ip: act.ip.clone(),
});
// stop actor
/// Check the rate limit, and stop the ctx if it fails
fn rate_limit_check(&mut self, ctx: &mut ws::WebsocketContext<Self>) -> bool {
- let check = self.rate_limiter.message().check(self.ip.to_owned());
+ let check = self.rate_limiter.message().check(self.ip.clone());
if !check {
debug!("Websocket join with IP: {} has been rate limited.", self.ip);
ctx.stop()
--- /dev/null
+#!/bin/bash
+set -e
+
+cargo workspaces exec cargo clippy --fix --allow-dirty --tests --all-targets --all-features -- \
+ -D warnings -D deprecated -D clippy::perf -D clippy::complexity \
+ -D clippy::dbg_macro -D clippy::inefficient_to_string \
+ -D clippy::items-after-statements -D clippy::implicit_clone \
+ -D clippy::wildcard_imports -D clippy::cast_lossless \
+ -D clippy::manual_string_new -D clippy::redundant_closure_for_method_calls
-use actix_web::*;
+use actix_web::{guard, web, Error, HttpResponse, Result};
use lemmy_api::Perform;
use lemmy_api_common::{
- comment::*,
- community::*,
- person::*,
- post::*,
- private_message::*,
- site::*,
- websocket::*,
+ comment::{
+ CreateComment,
+ CreateCommentLike,
+ CreateCommentReport,
+ DeleteComment,
+ EditComment,
+ GetComment,
+ GetComments,
+ ListCommentReports,
+ RemoveComment,
+ ResolveCommentReport,
+ SaveComment,
+ },
+ community::{
+ AddModToCommunity,
+ BanFromCommunity,
+ BlockCommunity,
+ CreateCommunity,
+ DeleteCommunity,
+ EditCommunity,
+ FollowCommunity,
+ GetCommunity,
+ HideCommunity,
+ ListCommunities,
+ RemoveCommunity,
+ TransferCommunity,
+ },
+ person::{
+ AddAdmin,
+ BanPerson,
+ BlockPerson,
+ ChangePassword,
+ DeleteAccount,
+ GetBannedPersons,
+ GetCaptcha,
+ GetPersonDetails,
+ GetPersonMentions,
+ GetReplies,
+ GetReportCount,
+ GetUnreadCount,
+ Login,
+ MarkAllAsRead,
+ MarkCommentReplyAsRead,
+ MarkPersonMentionAsRead,
+ PasswordChangeAfterReset,
+ PasswordReset,
+ Register,
+ SaveUserSettings,
+ VerifyEmail,
+ },
+ post::{
+ CreatePost,
+ CreatePostLike,
+ CreatePostReport,
+ DeletePost,
+ EditPost,
+ GetPost,
+ GetPosts,
+ GetSiteMetadata,
+ ListPostReports,
+ LockPost,
+ MarkPostAsRead,
+ RemovePost,
+ ResolvePostReport,
+ SavePost,
+ StickyPost,
+ },
+ private_message::{
+ CreatePrivateMessage,
+ CreatePrivateMessageReport,
+ DeletePrivateMessage,
+ EditPrivateMessage,
+ GetPrivateMessages,
+ ListPrivateMessageReports,
+ MarkPrivateMessageAsRead,
+ ResolvePrivateMessageReport,
+ },
+ site::{
+ ApproveRegistrationApplication,
+ CreateSite,
+ EditSite,
+ GetModlog,
+ GetSite,
+ GetUnreadRegistrationApplicationCount,
+ LeaveAdmin,
+ ListRegistrationApplications,
+ PurgeComment,
+ PurgeCommunity,
+ PurgePerson,
+ PurgePost,
+ ResolveObject,
+ Search,
+ },
+ websocket::{CommunityJoin, ModJoin, PostJoin, UserJoin},
};
use lemmy_api_crud::PerformCrud;
use lemmy_utils::rate_limit::RateLimitCell;
pool: &DbPool,
protocol_and_hostname: &str,
) -> Result<(), LemmyError> {
- use lemmy_db_schema::schema::person::dsl::*;
+ use lemmy_db_schema::schema::person::dsl::{actor_id, local, person};
let conn = &mut get_conn(pool).await?;
info!("Running user_updates_2020_04_02");
pool: &DbPool,
protocol_and_hostname: &str,
) -> Result<(), LemmyError> {
- use lemmy_db_schema::schema::community::dsl::*;
+ use lemmy_db_schema::schema::community::dsl::{actor_id, community, local};
let conn = &mut get_conn(pool).await?;
info!("Running community_updates_2020_04_02");
)?;
let form = CommunityUpdateForm::builder()
- .actor_id(Some(community_actor_id.to_owned()))
+ .actor_id(Some(community_actor_id.clone()))
.private_key(Some(Some(keypair.private_key)))
.public_key(Some(keypair.public_key))
.last_refreshed_at(Some(naive_now()))
pool: &DbPool,
protocol_and_hostname: &str,
) -> Result<(), LemmyError> {
- use lemmy_db_schema::schema::post::dsl::*;
+ use lemmy_db_schema::schema::post::dsl::{ap_id, local, post};
let conn = &mut get_conn(pool).await?;
info!("Running post_updates_2020_04_03");
pool: &DbPool,
protocol_and_hostname: &str,
) -> Result<(), LemmyError> {
- use lemmy_db_schema::schema::comment::dsl::*;
+ use lemmy_db_schema::schema::comment::dsl::{ap_id, comment, local};
let conn = &mut get_conn(pool).await?;
info!("Running comment_updates_2020_04_03");
pool: &DbPool,
protocol_and_hostname: &str,
) -> Result<(), LemmyError> {
- use lemmy_db_schema::schema::private_message::dsl::*;
+ use lemmy_db_schema::schema::private_message::dsl::{ap_id, local, private_message};
let conn = &mut get_conn(pool).await?;
info!("Running private_message_updates_2020_05_05");
pool: &DbPool,
protocol_and_hostname: &str,
) -> Result<(), LemmyError> {
- use lemmy_db_schema::schema::post::dsl::*;
+ use lemmy_db_schema::schema::post::dsl::{post, thumbnail_url};
let conn = &mut get_conn(pool).await?;
info!("Running post_thumbnail_url_updates_2020_07_27");
let conn = &mut get_conn(pool).await?;
info!("Running apub_columns_2021_02_02");
{
- use lemmy_db_schema::schema::person::dsl::*;
+ use lemmy_db_schema::schema::person::dsl::{inbox_url, person, shared_inbox_url};
let persons = person
.filter(inbox_url.like("http://changeme%"))
.load::<Person>(conn)
}
{
- use lemmy_db_schema::schema::community::dsl::*;
+ use lemmy_db_schema::schema::community::dsl::{
+ community,
+ followers_url,
+ inbox_url,
+ shared_inbox_url,
+ };
let communities = community
.filter(inbox_url.like("http://changeme%"))
.load::<Community>(conn)
{
// update communities with empty pubkey
- use lemmy_db_schema::schema::community::dsl::*;
+ use lemmy_db_schema::schema::community::dsl::{community, local, public_key};
let communities: Vec<Community> = community
.filter(local.eq(true))
.filter(public_key.eq(""))
{
// update persons with empty pubkey
- use lemmy_db_schema::schema::person::dsl::*;
+ use lemmy_db_schema::schema::person::dsl::{local, person, public_key};
let persons = person
.filter(local.eq(true))
.filter(public_key.eq(""))
// Register the user if there's a site setup
let person_form = PersonInsertForm::builder()
- .name(setup.admin_username.to_owned())
+ .name(setup.admin_username.clone())
.admin(Some(true))
.instance_id(instance.id)
.actor_id(Some(person_actor_id.clone()))
let local_user_form = LocalUserInsertForm::builder()
.person_id(person_inserted.id)
- .password_encrypted(setup.admin_password.to_owned())
- .email(setup.admin_email.to_owned())
+ .password_encrypted(setup.admin_password.clone())
+ .email(setup.admin_email.clone())
.build();
LocalUser::create(pool, &local_user_form).await?;
};
.name(
settings
.setup
- .to_owned()
+ .clone()
.map(|s| s.site_name)
.unwrap_or_else(|| "New Site".to_string()),
)
extern crate diesel_migrations;
use actix::prelude::*;
-use actix_web::{web::Data, *};
+use actix_web::{middleware, web::Data, App, HttpServer, Result};
use diesel_migrations::EmbeddedMigrations;
use doku::json::{AutoComments, CommentsStyle, Formatting, ObjectsStyle};
use lemmy_api::match_websocket_operation;
HttpServer::new(move || {
let context = LemmyContext::create(
pool.clone(),
- chat_server.to_owned(),
+ chat_server.clone(),
client.clone(),
- settings.to_owned(),
- secret.to_owned(),
+ settings.clone(),
+ secret.clone(),
rate_limit_cell.clone(),
);
App::new()
/// Clear old activities (this table gets very large)
fn clear_old_activities(conn: &mut PgConnection) {
- use diesel::dsl::*;
- use lemmy_db_schema::schema::activity::dsl::*;
+ use diesel::dsl::{now, IntervalDsl};
+ use lemmy_db_schema::schema::activity::dsl::{activity, published};
info!("Clearing old activities...");
diesel::delete(activity.filter(published.lt(now - 6.months())))
.execute(conn)