2022-05-03 17:44:13 +00:00
|
|
|
use crate::structs::RegistrationApplicationView;
|
2022-11-09 10:05:00 +00:00
|
|
|
use diesel::{
|
|
|
|
dsl::count,
|
|
|
|
result::Error,
|
|
|
|
ExpressionMethods,
|
|
|
|
JoinOnDsl,
|
|
|
|
NullableExpressionMethods,
|
|
|
|
QueryDsl,
|
|
|
|
};
|
|
|
|
use diesel_async::RunQueryDsl;
|
2021-12-15 19:49:59 +00:00
|
|
|
use lemmy_db_schema::{
|
2022-09-26 14:09:32 +00:00
|
|
|
schema::{local_user, person, registration_application},
|
2021-12-15 19:49:59 +00:00
|
|
|
source::{
|
2023-03-01 17:19:46 +00:00
|
|
|
local_user::LocalUser,
|
|
|
|
person::Person,
|
2021-12-15 19:49:59 +00:00
|
|
|
registration_application::RegistrationApplication,
|
|
|
|
},
|
2023-03-01 17:19:46 +00:00
|
|
|
traits::JoinView,
|
2022-11-09 10:05:00 +00:00
|
|
|
utils::{get_conn, limit_and_offset, DbPool},
|
2021-12-15 19:49:59 +00:00
|
|
|
};
|
2022-08-04 19:30:17 +00:00
|
|
|
use typed_builder::TypedBuilder;
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2023-03-01 17:19:46 +00:00
|
|
|
type RegistrationApplicationViewTuple =
|
|
|
|
(RegistrationApplication, LocalUser, Person, Option<Person>);
|
2021-12-15 19:49:59 +00:00
|
|
|
|
|
|
|
impl RegistrationApplicationView {
|
2022-11-09 10:05:00 +00:00
|
|
|
pub async fn read(pool: &DbPool, registration_application_id: i32) -> Result<Self, Error> {
|
|
|
|
let conn = &mut get_conn(pool).await?;
|
2022-09-26 14:09:32 +00:00
|
|
|
let person_alias_1 = diesel::alias!(person as person1);
|
|
|
|
|
2021-12-15 19:49:59 +00:00
|
|
|
let (registration_application, creator_local_user, creator, admin) =
|
|
|
|
registration_application::table
|
|
|
|
.find(registration_application_id)
|
|
|
|
.inner_join(
|
|
|
|
local_user::table.on(registration_application::local_user_id.eq(local_user::id)),
|
|
|
|
)
|
|
|
|
.inner_join(person::table.on(local_user::person_id.eq(person::id)))
|
|
|
|
.left_join(
|
2022-09-26 14:09:32 +00:00
|
|
|
person_alias_1
|
|
|
|
.on(registration_application::admin_id.eq(person_alias_1.field(person::id).nullable())),
|
2021-12-15 19:49:59 +00:00
|
|
|
)
|
|
|
|
.order_by(registration_application::published.desc())
|
|
|
|
.select((
|
|
|
|
registration_application::all_columns,
|
2023-03-01 17:19:46 +00:00
|
|
|
local_user::all_columns,
|
|
|
|
person::all_columns,
|
|
|
|
person_alias_1.fields(person::all_columns).nullable(),
|
2021-12-15 19:49:59 +00:00
|
|
|
))
|
2022-11-09 10:05:00 +00:00
|
|
|
.first::<RegistrationApplicationViewTuple>(conn)
|
|
|
|
.await?;
|
2021-12-15 19:49:59 +00:00
|
|
|
|
|
|
|
Ok(RegistrationApplicationView {
|
|
|
|
registration_application,
|
|
|
|
creator_local_user,
|
|
|
|
creator,
|
|
|
|
admin,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the current unread registration_application count
|
2022-11-09 10:05:00 +00:00
|
|
|
pub async fn get_unread_count(pool: &DbPool, verified_email_only: bool) -> Result<i64, Error> {
|
|
|
|
let conn = &mut get_conn(pool).await?;
|
2022-09-26 14:09:32 +00:00
|
|
|
let person_alias_1 = diesel::alias!(person as person1);
|
|
|
|
|
2021-12-15 19:49:59 +00:00
|
|
|
let mut query = registration_application::table
|
|
|
|
.inner_join(local_user::table.on(registration_application::local_user_id.eq(local_user::id)))
|
|
|
|
.inner_join(person::table.on(local_user::person_id.eq(person::id)))
|
|
|
|
.left_join(
|
2022-09-26 14:09:32 +00:00
|
|
|
person_alias_1
|
|
|
|
.on(registration_application::admin_id.eq(person_alias_1.field(person::id).nullable())),
|
2021-12-15 19:49:59 +00:00
|
|
|
)
|
|
|
|
.filter(registration_application::admin_id.is_null())
|
|
|
|
.into_boxed();
|
|
|
|
|
|
|
|
if verified_email_only {
|
|
|
|
query = query.filter(local_user::email_verified.eq(true))
|
|
|
|
}
|
|
|
|
|
|
|
|
query
|
|
|
|
.select(count(registration_application::id))
|
|
|
|
.first::<i64>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2021-12-15 19:49:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-04 19:30:17 +00:00
|
|
|
#[derive(TypedBuilder)]
|
|
|
|
#[builder(field_defaults(default))]
|
|
|
|
pub struct RegistrationApplicationQuery<'a> {
|
|
|
|
#[builder(!default)]
|
2022-11-09 10:05:00 +00:00
|
|
|
pool: &'a DbPool,
|
2021-12-15 19:49:59 +00:00
|
|
|
unread_only: Option<bool>,
|
|
|
|
verified_email_only: Option<bool>,
|
|
|
|
page: Option<i64>,
|
|
|
|
limit: Option<i64>,
|
|
|
|
}
|
|
|
|
|
2022-08-04 19:30:17 +00:00
|
|
|
impl<'a> RegistrationApplicationQuery<'a> {
|
2022-11-09 10:05:00 +00:00
|
|
|
pub async fn list(self) -> Result<Vec<RegistrationApplicationView>, Error> {
|
|
|
|
let conn = &mut get_conn(self.pool).await?;
|
2022-09-26 14:09:32 +00:00
|
|
|
let person_alias_1 = diesel::alias!(person as person1);
|
|
|
|
|
2021-12-15 19:49:59 +00:00
|
|
|
let mut query = registration_application::table
|
|
|
|
.inner_join(local_user::table.on(registration_application::local_user_id.eq(local_user::id)))
|
|
|
|
.inner_join(person::table.on(local_user::person_id.eq(person::id)))
|
|
|
|
.left_join(
|
2022-09-26 14:09:32 +00:00
|
|
|
person_alias_1
|
|
|
|
.on(registration_application::admin_id.eq(person_alias_1.field(person::id).nullable())),
|
2021-12-15 19:49:59 +00:00
|
|
|
)
|
|
|
|
.order_by(registration_application::published.desc())
|
|
|
|
.select((
|
|
|
|
registration_application::all_columns,
|
2023-03-01 17:19:46 +00:00
|
|
|
local_user::all_columns,
|
|
|
|
person::all_columns,
|
|
|
|
person_alias_1.fields(person::all_columns).nullable(),
|
2021-12-15 19:49:59 +00:00
|
|
|
))
|
|
|
|
.into_boxed();
|
|
|
|
|
|
|
|
if self.unread_only.unwrap_or(false) {
|
|
|
|
query = query.filter(registration_application::admin_id.is_null())
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.verified_email_only.unwrap_or(false) {
|
|
|
|
query = query.filter(local_user::email_verified.eq(true))
|
|
|
|
}
|
|
|
|
|
2022-07-08 10:21:33 +00:00
|
|
|
let (limit, offset) = limit_and_offset(self.page, self.limit)?;
|
2021-12-15 19:49:59 +00:00
|
|
|
|
|
|
|
query = query
|
|
|
|
.limit(limit)
|
|
|
|
.offset(offset)
|
|
|
|
.order_by(registration_application::published.desc());
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let res = query.load::<RegistrationApplicationViewTuple>(conn).await?;
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2023-03-01 17:19:46 +00:00
|
|
|
Ok(
|
|
|
|
res
|
|
|
|
.into_iter()
|
|
|
|
.map(RegistrationApplicationView::from_tuple)
|
|
|
|
.collect(),
|
|
|
|
)
|
2021-12-15 19:49:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-01 17:19:46 +00:00
|
|
|
impl JoinView for RegistrationApplicationView {
|
|
|
|
type JoinTuple = RegistrationApplicationViewTuple;
|
|
|
|
fn from_tuple(a: Self::JoinTuple) -> Self {
|
|
|
|
Self {
|
|
|
|
registration_application: a.0,
|
|
|
|
creator_local_user: a.1,
|
|
|
|
creator: a.2,
|
|
|
|
admin: a.3,
|
|
|
|
}
|
2021-12-15 19:49:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use crate::registration_application_view::{
|
2022-08-04 19:30:17 +00:00
|
|
|
RegistrationApplicationQuery,
|
2021-12-15 19:49:59 +00:00
|
|
|
RegistrationApplicationView,
|
|
|
|
};
|
|
|
|
use lemmy_db_schema::{
|
|
|
|
source::{
|
2022-10-27 09:24:07 +00:00
|
|
|
instance::Instance,
|
2023-03-01 17:19:46 +00:00
|
|
|
local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
|
|
|
|
person::{Person, PersonInsertForm},
|
2022-10-27 09:24:07 +00:00
|
|
|
registration_application::{
|
|
|
|
RegistrationApplication,
|
|
|
|
RegistrationApplicationInsertForm,
|
|
|
|
RegistrationApplicationUpdateForm,
|
|
|
|
},
|
2021-12-15 19:49:59 +00:00
|
|
|
},
|
|
|
|
traits::Crud,
|
2022-11-09 10:05:00 +00:00
|
|
|
utils::build_db_pool_for_tests,
|
2021-12-15 19:49:59 +00:00
|
|
|
};
|
|
|
|
use serial_test::serial;
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
#[tokio::test]
|
2021-12-15 19:49:59 +00:00
|
|
|
#[serial]
|
2022-11-09 10:05:00 +00:00
|
|
|
async fn test_crud() {
|
|
|
|
let pool = &build_db_pool_for_tests().await;
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2023-03-01 02:36:57 +00:00
|
|
|
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2022-10-27 09:24:07 +00:00
|
|
|
|
|
|
|
let timmy_person_form = PersonInsertForm::builder()
|
|
|
|
.name("timmy_rav".into())
|
|
|
|
.admin(Some(true))
|
|
|
|
.public_key("pubkey".to_string())
|
|
|
|
.instance_id(inserted_instance.id)
|
|
|
|
.build();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let inserted_timmy_person = Person::create(pool, &timmy_person_form).await.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
let timmy_local_user_form = LocalUserInsertForm::builder()
|
|
|
|
.person_id(inserted_timmy_person.id)
|
|
|
|
.password_encrypted("nada".to_string())
|
|
|
|
.build();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let _inserted_timmy_local_user = LocalUser::create(pool, &timmy_local_user_form)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
let sara_person_form = PersonInsertForm::builder()
|
|
|
|
.name("sara_rav".into())
|
|
|
|
.public_key("pubkey".to_string())
|
|
|
|
.instance_id(inserted_instance.id)
|
|
|
|
.build();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let inserted_sara_person = Person::create(pool, &sara_person_form).await.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
let sara_local_user_form = LocalUserInsertForm::builder()
|
|
|
|
.person_id(inserted_sara_person.id)
|
|
|
|
.password_encrypted("nada".to_string())
|
|
|
|
.build();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let inserted_sara_local_user = LocalUser::create(pool, &sara_local_user_form)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
|
|
|
// Sara creates an application
|
2022-10-27 09:24:07 +00:00
|
|
|
let sara_app_form = RegistrationApplicationInsertForm {
|
|
|
|
local_user_id: inserted_sara_local_user.id,
|
|
|
|
answer: "LET ME IIIIINN".to_string(),
|
2021-12-15 19:49:59 +00:00
|
|
|
};
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let sara_app = RegistrationApplication::create(pool, &sara_app_form)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let read_sara_app_view = RegistrationApplicationView::read(pool, sara_app.id)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
let jess_person_form = PersonInsertForm::builder()
|
|
|
|
.name("jess_rav".into())
|
|
|
|
.public_key("pubkey".to_string())
|
|
|
|
.instance_id(inserted_instance.id)
|
|
|
|
.build();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let inserted_jess_person = Person::create(pool, &jess_person_form).await.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
let jess_local_user_form = LocalUserInsertForm::builder()
|
|
|
|
.person_id(inserted_jess_person.id)
|
|
|
|
.password_encrypted("nada".to_string())
|
|
|
|
.build();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let inserted_jess_local_user = LocalUser::create(pool, &jess_local_user_form)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
|
|
|
// Sara creates an application
|
2022-10-27 09:24:07 +00:00
|
|
|
let jess_app_form = RegistrationApplicationInsertForm {
|
|
|
|
local_user_id: inserted_jess_local_user.id,
|
|
|
|
answer: "LET ME IIIIINN".to_string(),
|
2021-12-15 19:49:59 +00:00
|
|
|
};
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let jess_app = RegistrationApplication::create(pool, &jess_app_form)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let read_jess_app_view = RegistrationApplicationView::read(pool, jess_app.id)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
|
|
|
let mut expected_sara_app_view = RegistrationApplicationView {
|
2022-11-19 04:33:54 +00:00
|
|
|
registration_application: sara_app.clone(),
|
2023-03-01 17:19:46 +00:00
|
|
|
creator_local_user: LocalUser {
|
2021-12-15 19:49:59 +00:00
|
|
|
id: inserted_sara_local_user.id,
|
|
|
|
person_id: inserted_sara_local_user.person_id,
|
|
|
|
email: inserted_sara_local_user.email,
|
|
|
|
show_nsfw: inserted_sara_local_user.show_nsfw,
|
|
|
|
theme: inserted_sara_local_user.theme,
|
|
|
|
default_sort_type: inserted_sara_local_user.default_sort_type,
|
|
|
|
default_listing_type: inserted_sara_local_user.default_listing_type,
|
2022-08-18 19:11:19 +00:00
|
|
|
interface_language: inserted_sara_local_user.interface_language,
|
2021-12-15 19:49:59 +00:00
|
|
|
show_avatars: inserted_sara_local_user.show_avatars,
|
|
|
|
send_notifications_to_email: inserted_sara_local_user.send_notifications_to_email,
|
|
|
|
validator_time: inserted_sara_local_user.validator_time,
|
|
|
|
show_bot_accounts: inserted_sara_local_user.show_bot_accounts,
|
|
|
|
show_scores: inserted_sara_local_user.show_scores,
|
|
|
|
show_read_posts: inserted_sara_local_user.show_read_posts,
|
|
|
|
show_new_post_notifs: inserted_sara_local_user.show_new_post_notifs,
|
|
|
|
email_verified: inserted_sara_local_user.email_verified,
|
|
|
|
accepted_application: inserted_sara_local_user.accepted_application,
|
2023-03-02 20:37:41 +00:00
|
|
|
totp_2fa_secret: inserted_sara_local_user.totp_2fa_secret,
|
|
|
|
totp_2fa_url: inserted_sara_local_user.totp_2fa_url,
|
2023-03-01 17:19:46 +00:00
|
|
|
password_encrypted: inserted_sara_local_user.password_encrypted,
|
2023-07-03 15:10:25 +00:00
|
|
|
open_links_in_new_tab: inserted_sara_local_user.open_links_in_new_tab,
|
2021-12-15 19:49:59 +00:00
|
|
|
},
|
2023-03-01 17:19:46 +00:00
|
|
|
creator: Person {
|
2021-12-15 19:49:59 +00:00
|
|
|
id: inserted_sara_person.id,
|
2022-11-19 04:33:54 +00:00
|
|
|
name: inserted_sara_person.name.clone(),
|
2021-12-15 19:49:59 +00:00
|
|
|
display_name: None,
|
|
|
|
published: inserted_sara_person.published,
|
|
|
|
avatar: None,
|
2022-11-19 04:33:54 +00:00
|
|
|
actor_id: inserted_sara_person.actor_id.clone(),
|
2021-12-15 19:49:59 +00:00
|
|
|
local: true,
|
|
|
|
banned: false,
|
2022-01-08 12:37:07 +00:00
|
|
|
ban_expires: None,
|
2021-12-15 19:49:59 +00:00
|
|
|
deleted: false,
|
|
|
|
admin: false,
|
|
|
|
bot_account: false,
|
|
|
|
bio: None,
|
|
|
|
banner: None,
|
|
|
|
updated: None,
|
2022-11-19 04:33:54 +00:00
|
|
|
inbox_url: inserted_sara_person.inbox_url.clone(),
|
2021-12-15 19:49:59 +00:00
|
|
|
shared_inbox_url: None,
|
|
|
|
matrix_user_id: None,
|
2022-10-27 09:24:07 +00:00
|
|
|
instance_id: inserted_instance.id,
|
2023-03-01 17:19:46 +00:00
|
|
|
private_key: inserted_sara_person.private_key,
|
|
|
|
public_key: inserted_sara_person.public_key,
|
|
|
|
last_refreshed_at: inserted_sara_person.last_refreshed_at,
|
2021-12-15 19:49:59 +00:00
|
|
|
},
|
|
|
|
admin: None,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(read_sara_app_view, expected_sara_app_view);
|
|
|
|
|
|
|
|
// Do a batch read of the applications
|
2022-08-04 19:30:17 +00:00
|
|
|
let apps = RegistrationApplicationQuery::builder()
|
2022-11-09 10:05:00 +00:00
|
|
|
.pool(pool)
|
2022-08-04 19:30:17 +00:00
|
|
|
.unread_only(Some(true))
|
|
|
|
.build()
|
2021-12-15 19:49:59 +00:00
|
|
|
.list()
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2021-12-15 19:49:59 +00:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
apps,
|
2022-11-19 04:33:54 +00:00
|
|
|
[read_jess_app_view.clone(), expected_sara_app_view.clone()]
|
2021-12-15 19:49:59 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Make sure the counts are correct
|
2022-11-09 10:05:00 +00:00
|
|
|
let unread_count = RegistrationApplicationView::get_unread_count(pool, false)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
assert_eq!(unread_count, 2);
|
|
|
|
|
|
|
|
// Approve the application
|
2022-10-27 09:24:07 +00:00
|
|
|
let approve_form = RegistrationApplicationUpdateForm {
|
|
|
|
admin_id: Some(Some(inserted_timmy_person.id)),
|
2021-12-15 19:49:59 +00:00
|
|
|
deny_reason: None,
|
|
|
|
};
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
RegistrationApplication::update(pool, sara_app.id, &approve_form)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
|
|
|
// Update the local_user row
|
2022-10-27 09:24:07 +00:00
|
|
|
let approve_local_user_form = LocalUserUpdateForm::builder()
|
|
|
|
.accepted_application(Some(true))
|
|
|
|
.build();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
LocalUser::update(pool, inserted_sara_local_user.id, &approve_local_user_form)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
let read_sara_app_view_after_approve = RegistrationApplicationView::read(pool, sara_app.id)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
|
|
|
|
// Make sure the columns changed
|
|
|
|
expected_sara_app_view
|
|
|
|
.creator_local_user
|
|
|
|
.accepted_application = true;
|
|
|
|
expected_sara_app_view.registration_application.admin_id = Some(inserted_timmy_person.id);
|
|
|
|
|
2023-03-01 17:19:46 +00:00
|
|
|
expected_sara_app_view.admin = Some(Person {
|
2021-12-15 19:49:59 +00:00
|
|
|
id: inserted_timmy_person.id,
|
2022-11-19 04:33:54 +00:00
|
|
|
name: inserted_timmy_person.name.clone(),
|
2021-12-15 19:49:59 +00:00
|
|
|
display_name: None,
|
|
|
|
published: inserted_timmy_person.published,
|
|
|
|
avatar: None,
|
2022-11-19 04:33:54 +00:00
|
|
|
actor_id: inserted_timmy_person.actor_id.clone(),
|
2021-12-15 19:49:59 +00:00
|
|
|
local: true,
|
|
|
|
banned: false,
|
2022-01-08 12:37:07 +00:00
|
|
|
ban_expires: None,
|
2021-12-15 19:49:59 +00:00
|
|
|
deleted: false,
|
|
|
|
admin: true,
|
|
|
|
bot_account: false,
|
|
|
|
bio: None,
|
|
|
|
banner: None,
|
|
|
|
updated: None,
|
2022-11-19 04:33:54 +00:00
|
|
|
inbox_url: inserted_timmy_person.inbox_url.clone(),
|
2021-12-15 19:49:59 +00:00
|
|
|
shared_inbox_url: None,
|
|
|
|
matrix_user_id: None,
|
2022-10-27 09:24:07 +00:00
|
|
|
instance_id: inserted_instance.id,
|
2023-03-01 17:19:46 +00:00
|
|
|
private_key: inserted_timmy_person.private_key,
|
|
|
|
public_key: inserted_timmy_person.public_key,
|
|
|
|
last_refreshed_at: inserted_timmy_person.last_refreshed_at,
|
2021-12-15 19:49:59 +00:00
|
|
|
});
|
|
|
|
assert_eq!(read_sara_app_view_after_approve, expected_sara_app_view);
|
|
|
|
|
|
|
|
// Do a batch read of apps again
|
|
|
|
// It should show only jessicas which is unresolved
|
2022-08-04 19:30:17 +00:00
|
|
|
let apps_after_resolve = RegistrationApplicationQuery::builder()
|
2022-11-09 10:05:00 +00:00
|
|
|
.pool(pool)
|
2022-08-04 19:30:17 +00:00
|
|
|
.unread_only(Some(true))
|
|
|
|
.build()
|
2021-12-15 19:49:59 +00:00
|
|
|
.list()
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2021-12-15 19:49:59 +00:00
|
|
|
.unwrap();
|
|
|
|
assert_eq!(apps_after_resolve, vec![read_jess_app_view]);
|
|
|
|
|
|
|
|
// Make sure the counts are correct
|
2022-11-09 10:05:00 +00:00
|
|
|
let unread_count_after_approve = RegistrationApplicationView::get_unread_count(pool, false)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
assert_eq!(unread_count_after_approve, 1);
|
|
|
|
|
|
|
|
// Make sure the not undenied_only has all the apps
|
2022-08-04 19:30:17 +00:00
|
|
|
let all_apps = RegistrationApplicationQuery::builder()
|
2022-11-09 10:05:00 +00:00
|
|
|
.pool(pool)
|
2022-08-04 19:30:17 +00:00
|
|
|
.build()
|
2021-12-15 19:49:59 +00:00
|
|
|
.list()
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2021-12-15 19:49:59 +00:00
|
|
|
.unwrap();
|
|
|
|
assert_eq!(all_apps.len(), 2);
|
|
|
|
|
2022-11-09 10:05:00 +00:00
|
|
|
Person::delete(pool, inserted_timmy_person.id)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
Person::delete(pool, inserted_sara_person.id).await.unwrap();
|
|
|
|
Person::delete(pool, inserted_jess_person.id).await.unwrap();
|
|
|
|
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
2021-12-15 19:49:59 +00:00
|
|
|
}
|
|
|
|
}
|