add: ProfileStyle products
This commit is contained in:
parent
077e9252e3
commit
95cb889080
19 changed files with 525 additions and 54 deletions
|
@ -3,10 +3,11 @@ use crate::{
|
|||
get_user_from_token,
|
||||
model::{ApiReturn, Error},
|
||||
routes::api::v1::{
|
||||
AppendAssociations, AwardAchievement, DeleteUser, DisableTotp, RefreshGrantToken,
|
||||
UpdateSecondaryUserRole, UpdateUserAwaitingPurchase, UpdateUserBanExpire,
|
||||
UpdateUserBanReason, UpdateUserInviteCode, UpdateUserIsDeactivated, UpdateUserIsVerified,
|
||||
UpdateUserPassword, UpdateUserRole, UpdateUserUsername,
|
||||
AddAppliedConfiguration, AppendAssociations, AwardAchievement, DeleteUser, DisableTotp,
|
||||
RefreshGrantToken, RemoveAppliedConfiguration, UpdateSecondaryUserRole,
|
||||
UpdateUserAwaitingPurchase, UpdateUserBanExpire, UpdateUserBanReason, UpdateUserInviteCode,
|
||||
UpdateUserIsDeactivated, UpdateUserIsVerified, UpdateUserPassword, UpdateUserRole,
|
||||
UpdateUserUsername,
|
||||
},
|
||||
State,
|
||||
};
|
||||
|
@ -24,6 +25,7 @@ use tetratto_core::{
|
|||
cache::Cache,
|
||||
model::{
|
||||
auth::{AchievementName, InviteCode, Token, UserSettings, SELF_SERVE_ACHIEVEMENTS},
|
||||
economy::CoinTransferMethod,
|
||||
moderation::AuditLogEntry,
|
||||
oauth,
|
||||
permissions::FinePermission,
|
||||
|
@ -180,6 +182,106 @@ pub async fn update_user_settings_request(
|
|||
}
|
||||
}
|
||||
|
||||
/// Add the given applied configuration.
|
||||
pub async fn add_applied_configuration_request(
|
||||
jar: CookieJar,
|
||||
Path(id): Path<usize>,
|
||||
Extension(data): Extension<State>,
|
||||
Json(req): Json<AddAppliedConfiguration>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let mut user = match get_user_from_token!(jar, data, oauth::AppScope::UserManageProfile) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
if user.id != id && !user.permissions.check(FinePermission::MANAGE_USERS) {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
let product_id: usize = match req.id.parse() {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Json(Error::MiscError(e.to_string()).into()),
|
||||
};
|
||||
|
||||
let product = match data.get_product_by_id(product_id).await {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Json(e.into()),
|
||||
};
|
||||
|
||||
if data
|
||||
.get_transfer_by_sender_method(user.id, CoinTransferMethod::Purchase(product.id))
|
||||
.await
|
||||
.is_err()
|
||||
{
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
// update
|
||||
user.applied_configurations.push((req.r#type, product.id));
|
||||
|
||||
// ...
|
||||
match data
|
||||
.update_user_applied_configurations(id, user.applied_configurations)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Applied configurations updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove the given applied configuration.
|
||||
pub async fn remove_applied_configuration_request(
|
||||
jar: CookieJar,
|
||||
Path(id): Path<usize>,
|
||||
Extension(data): Extension<State>,
|
||||
Json(req): Json<RemoveAppliedConfiguration>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let mut user = match get_user_from_token!(jar, data, oauth::AppScope::UserManageProfile) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
if user.id != id && !user.permissions.check(FinePermission::MANAGE_USERS) {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
let product_id: usize = match req.id.parse() {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Json(Error::MiscError(e.to_string()).into()),
|
||||
};
|
||||
|
||||
// update
|
||||
user.applied_configurations.remove(
|
||||
match user
|
||||
.applied_configurations
|
||||
.iter()
|
||||
.position(|x| x.1 == product_id)
|
||||
{
|
||||
Some(x) => x,
|
||||
None => return Json(Error::GeneralNotFound("configuration".to_string()).into()),
|
||||
},
|
||||
);
|
||||
|
||||
// ...
|
||||
match data
|
||||
.update_user_applied_configurations(id, user.applied_configurations)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Applied configurations updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Append associations to the current user.
|
||||
pub async fn append_associations_request(
|
||||
jar: CookieJar,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue