refactor: Use get_user_status
util in more places
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
parent
4e50cb34c0
commit
21880c5f82
1 changed files with 32 additions and 40 deletions
|
@ -103,17 +103,15 @@ impl UsersStatusExt for DatabaseConnection {
|
|||
whitelister: &UserModel,
|
||||
target_public_key: &PublicKey,
|
||||
) -> ServerResult<bool> {
|
||||
whitelister
|
||||
.find_related(UsersStatusEntity)
|
||||
.filter(
|
||||
UsersStatusColumn::Target
|
||||
.eq(target_public_key.to_string())
|
||||
.and(UsersStatusColumn::Status.eq(AccessStatus::Whitelisted)),
|
||||
)
|
||||
.one(self)
|
||||
.await
|
||||
.map(|u| u.is_some())
|
||||
.map_err(Into::into)
|
||||
get_user_status(
|
||||
self,
|
||||
whitelister,
|
||||
target_public_key,
|
||||
AccessStatus::Whitelisted,
|
||||
)
|
||||
.await
|
||||
.map(|u| u.is_some())
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
async fn is_blacklisted(
|
||||
|
@ -121,17 +119,15 @@ impl UsersStatusExt for DatabaseConnection {
|
|||
blacklister: &UserModel,
|
||||
target_public_key: &PublicKey,
|
||||
) -> ServerResult<bool> {
|
||||
blacklister
|
||||
.find_related(UsersStatusEntity)
|
||||
.filter(
|
||||
UsersStatusColumn::Target
|
||||
.eq(target_public_key.to_string())
|
||||
.and(UsersStatusColumn::Status.eq(AccessStatus::Blacklisted)),
|
||||
)
|
||||
.one(self)
|
||||
.await
|
||||
.map(|u| u.is_some())
|
||||
.map_err(Into::into)
|
||||
get_user_status(
|
||||
self,
|
||||
blacklister,
|
||||
target_public_key,
|
||||
AccessStatus::Blacklisted,
|
||||
)
|
||||
.await
|
||||
.map(|u| u.is_some())
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
async fn add_to_whitelist(
|
||||
|
@ -223,15 +219,13 @@ impl UsersStatusExt for DatabaseConnection {
|
|||
whitelister: &UserModel,
|
||||
target_public_key: &PublicKey,
|
||||
) -> ServerResult<()> {
|
||||
if let Some(target_user) = whitelister
|
||||
.find_related(UsersStatusEntity)
|
||||
.filter(
|
||||
UsersStatusColumn::Target
|
||||
.eq(target_public_key.to_string())
|
||||
.and(UsersStatusColumn::Status.eq(AccessStatus::Whitelisted)),
|
||||
)
|
||||
.one(self)
|
||||
.await?
|
||||
if let Some(target_user) = get_user_status(
|
||||
self,
|
||||
whitelister,
|
||||
target_public_key,
|
||||
AccessStatus::Whitelisted,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
target_user.delete(self).await?;
|
||||
}
|
||||
|
@ -243,15 +237,13 @@ impl UsersStatusExt for DatabaseConnection {
|
|||
blacklister: &UserModel,
|
||||
target_public_key: &PublicKey,
|
||||
) -> ServerResult<()> {
|
||||
if let Some(target_user) = blacklister
|
||||
.find_related(UsersStatusEntity)
|
||||
.filter(
|
||||
UsersStatusColumn::Target
|
||||
.eq(target_public_key.to_string())
|
||||
.and(UsersStatusColumn::Status.eq(AccessStatus::Blacklisted)),
|
||||
)
|
||||
.one(self)
|
||||
.await?
|
||||
if let Some(target_user) = get_user_status(
|
||||
self,
|
||||
blacklister,
|
||||
target_public_key,
|
||||
AccessStatus::Blacklisted,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
target_user.delete(self).await?;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue