1
0

Initial work on payouts (badges, perms, splits) (#440)

* Initial work on payouts (badges, perms, splits)

* Fix clippy error, bitflag consistency
This commit is contained in:
Geometrically
2022-09-02 12:38:58 -07:00
committed by GitHub
parent 4c1dca73c4
commit e7c3f8bf47
13 changed files with 1030 additions and 801 deletions

View File

@@ -2,7 +2,7 @@ use crate::database::models::User;
use crate::file_hosting::FileHost;
use crate::models::notifications::Notification;
use crate::models::projects::{Project, ProjectStatus};
use crate::models::users::{Role, UserId};
use crate::models::users::{Badges, Role, UserId};
use crate::routes::ApiError;
use crate::util::auth::get_user_from_headers;
use crate::util::routes::read_from_payload;
@@ -154,6 +154,7 @@ pub struct EditUser {
#[validate(length(max = 160))]
pub bio: Option<Option<String>>,
pub role: Option<Role>,
pub badges: Option<Badges>,
}
#[patch("{id}")]
@@ -277,6 +278,27 @@ pub async fn user_edit(
.await?;
}
if let Some(badges) = &new_user.badges {
if !user.role.is_admin() {
return Err(ApiError::CustomAuthentication(
"You do not have the permissions to edit the badges of this user!"
.to_string(),
));
}
sqlx::query!(
"
UPDATE users
SET badges = $1
WHERE (id = $2)
",
badges.bits() as i64,
id as crate::database::models::ids::UserId,
)
.execute(&mut *transaction)
.await?;
}
transaction.commit().await?;
Ok(HttpResponse::NoContent().body(""))
} else {