Monetization status, additional files fix, deps fix (#574)

This commit is contained in:
Geometrically
2023-04-16 20:03:53 -07:00
committed by GitHub
parent 95ae981698
commit a560f6e9f6
26 changed files with 1208 additions and 1422 deletions

View File

@@ -102,16 +102,14 @@ pub struct Project {
/// A string of URLs to visual content featuring the project
pub gallery: Vec<GalleryItem>,
/// The project linked from FlameAnvil to sync with
pub flame_anvil_project: Option<i32>,
/// The user_id of the team member whose token
pub flame_anvil_user: Option<UserId>,
/// The color of the project (picked from icon)
pub color: Option<u32>,
/// The thread of the moderation messages of the project
pub thread_id: Option<ThreadId>,
/// The monetization status of this project
pub monetization_status: MonetizationStatus,
}
impl From<QueryProject> for Project {
@@ -197,10 +195,9 @@ impl From<QueryProject> for Project {
ordering: x.ordering,
})
.collect(),
flame_anvil_project: m.flame_anvil_project,
flame_anvil_user: m.flame_anvil_user.map(|x| x.into()),
color: m.color,
thread_id: m.thread_id.map(|x| x.into()),
monetization_status: m.monetization_status,
}
}
}
@@ -418,6 +415,39 @@ impl ProjectStatus {
}
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub enum MonetizationStatus {
ForceDemonetized,
Demonetized,
Monetized,
}
impl std::fmt::Display for MonetizationStatus {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
fmt.write_str(self.as_str())
}
}
impl MonetizationStatus {
pub fn from_str(string: &str) -> MonetizationStatus {
match string {
"force-demonetized" => MonetizationStatus::ForceDemonetized,
"demonetized" => MonetizationStatus::Demonetized,
"monetized" => MonetizationStatus::Monetized,
_ => MonetizationStatus::Monetized,
}
}
// These are constant, so this can remove unnecessary allocations (`to_string`)
pub fn as_str(&self) -> &'static str {
match self {
MonetizationStatus::ForceDemonetized => "force-demonetized",
MonetizationStatus::Demonetized => "demonetized",
MonetizationStatus::Monetized => "monetized",
}
}
}
/// A specific version of a project
#[derive(Serialize, Deserialize)]
pub struct Version {

View File

@@ -71,12 +71,7 @@ pub struct TeamMember {
impl TeamMember {
pub fn from(data: QueryTeamMember, override_permissions: bool) -> Self {
let has_flame_anvil_key = data.user.flame_anvil_key.is_some();
let mut user: User = data.user.into();
if !override_permissions {
user.has_flame_anvil_key = Some(has_flame_anvil_key);
}
let user: User = data.user.into();
Self {
team_id: data.team_id.into(),

View File

@@ -47,7 +47,6 @@ pub struct User {
pub role: Role,
pub badges: Badges,
pub payout_data: Option<UserPayoutData>,
pub has_flame_anvil_key: Option<bool>,
}
#[derive(Serialize, Deserialize, Clone)]
@@ -141,7 +140,6 @@ impl From<DBUser> for User {
role: Role::from_string(&data.role),
badges: data.badges,
payout_data: None,
has_flame_anvil_key: None,
}
}
}