You've already forked AstralRinth
forked from didirus/AstralRinth
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:
@@ -189,6 +189,7 @@ pub async fn join_team(
|
||||
None,
|
||||
None,
|
||||
Some(true),
|
||||
None,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
@@ -214,6 +215,8 @@ pub struct NewTeamMember {
|
||||
pub role: String,
|
||||
#[serde(default = "Permissions::default")]
|
||||
pub permissions: Permissions,
|
||||
#[serde(default)]
|
||||
pub payouts_split: f32,
|
||||
}
|
||||
|
||||
#[post("{id}/members")]
|
||||
@@ -255,6 +258,13 @@ pub async fn add_team_member(
|
||||
"The `Owner` role is restricted to one person".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
if !(0.0..=5000.0).contains(&new_member.payouts_split) {
|
||||
return Err(ApiError::InvalidInput(
|
||||
"Payouts split must be between 0 and 5000!".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let request = crate::database::models::team_item::TeamMember::get_from_user_id_pending(
|
||||
team_id,
|
||||
new_member.user_id.into(),
|
||||
@@ -291,6 +301,7 @@ pub async fn add_team_member(
|
||||
role: new_member.role.clone(),
|
||||
permissions: new_member.permissions,
|
||||
accepted: false,
|
||||
payouts_split: new_member.payouts_split,
|
||||
}
|
||||
.insert(&mut transaction)
|
||||
.await?;
|
||||
@@ -349,6 +360,7 @@ pub async fn add_team_member(
|
||||
pub struct EditTeamMember {
|
||||
pub permissions: Option<Permissions>,
|
||||
pub role: Option<String>,
|
||||
pub payouts_split: Option<f32>,
|
||||
}
|
||||
|
||||
#[patch("{id}/members/{user_id}")]
|
||||
@@ -406,6 +418,14 @@ pub async fn edit_team_member(
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(payouts_split) = edit_member.payouts_split {
|
||||
if !(0.0..=5000.0).contains(&payouts_split) {
|
||||
return Err(ApiError::InvalidInput(
|
||||
"Payouts split must be between 0 and 5000!".to_string(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if edit_member.role.as_deref() == Some(crate::models::teams::OWNER_ROLE) {
|
||||
return Err(ApiError::InvalidInput(
|
||||
"The `Owner` role is restricted to one person".to_string(),
|
||||
@@ -418,6 +438,7 @@ pub async fn edit_team_member(
|
||||
edit_member.permissions,
|
||||
edit_member.role.clone(),
|
||||
None,
|
||||
edit_member.payouts_split,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
@@ -491,6 +512,7 @@ pub async fn transfer_ownership(
|
||||
None,
|
||||
Some(crate::models::teams::DEFAULT_ROLE.to_string()),
|
||||
None,
|
||||
None,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
@@ -501,6 +523,7 @@ pub async fn transfer_ownership(
|
||||
Some(Permissions::ALL),
|
||||
Some(crate::models::teams::OWNER_ROLE.to_string()),
|
||||
None,
|
||||
None,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Reference in New Issue
Block a user