refactor: Use get_user_status util in more places
All checks were successful
DCO checker / DCO checker (pull_request) Successful in 9s
Rust CI / Rust CI (pull_request) Successful in 4m52s

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-07-18 11:14:49 +03:00
parent 4e50cb34c0
commit 21880c5f82
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F

View file

@ -103,14 +103,12 @@ impl UsersStatusExt for DatabaseConnection {
whitelister: &UserModel, whitelister: &UserModel,
target_public_key: &PublicKey, target_public_key: &PublicKey,
) -> ServerResult<bool> { ) -> ServerResult<bool> {
whitelister get_user_status(
.find_related(UsersStatusEntity) self,
.filter( whitelister,
UsersStatusColumn::Target target_public_key,
.eq(target_public_key.to_string()) AccessStatus::Whitelisted,
.and(UsersStatusColumn::Status.eq(AccessStatus::Whitelisted)),
) )
.one(self)
.await .await
.map(|u| u.is_some()) .map(|u| u.is_some())
.map_err(Into::into) .map_err(Into::into)
@ -121,14 +119,12 @@ impl UsersStatusExt for DatabaseConnection {
blacklister: &UserModel, blacklister: &UserModel,
target_public_key: &PublicKey, target_public_key: &PublicKey,
) -> ServerResult<bool> { ) -> ServerResult<bool> {
blacklister get_user_status(
.find_related(UsersStatusEntity) self,
.filter( blacklister,
UsersStatusColumn::Target target_public_key,
.eq(target_public_key.to_string()) AccessStatus::Blacklisted,
.and(UsersStatusColumn::Status.eq(AccessStatus::Blacklisted)),
) )
.one(self)
.await .await
.map(|u| u.is_some()) .map(|u| u.is_some())
.map_err(Into::into) .map_err(Into::into)
@ -223,14 +219,12 @@ impl UsersStatusExt for DatabaseConnection {
whitelister: &UserModel, whitelister: &UserModel,
target_public_key: &PublicKey, target_public_key: &PublicKey,
) -> ServerResult<()> { ) -> ServerResult<()> {
if let Some(target_user) = whitelister if let Some(target_user) = get_user_status(
.find_related(UsersStatusEntity) self,
.filter( whitelister,
UsersStatusColumn::Target target_public_key,
.eq(target_public_key.to_string()) AccessStatus::Whitelisted,
.and(UsersStatusColumn::Status.eq(AccessStatus::Whitelisted)),
) )
.one(self)
.await? .await?
{ {
target_user.delete(self).await?; target_user.delete(self).await?;
@ -243,14 +237,12 @@ impl UsersStatusExt for DatabaseConnection {
blacklister: &UserModel, blacklister: &UserModel,
target_public_key: &PublicKey, target_public_key: &PublicKey,
) -> ServerResult<()> { ) -> ServerResult<()> {
if let Some(target_user) = blacklister if let Some(target_user) = get_user_status(
.find_related(UsersStatusEntity) self,
.filter( blacklister,
UsersStatusColumn::Target target_public_key,
.eq(target_public_key.to_string()) AccessStatus::Blacklisted,
.and(UsersStatusColumn::Status.eq(AccessStatus::Blacklisted)),
) )
.one(self)
.await? .await?
{ {
target_user.delete(self).await?; target_user.delete(self).await?;