General cleanup: fix some bugs, some refactoring (#65)

* Merged mod file upload in version creation, mod creation and
  version file add to one function;  This makes sure that they are
  consistent
* Made some fields on `User` optional: `github_id`, `avatar_url`, `bio`.
    * We may not want to publicly show the `github_id` to everyone
      with access to the API
    * If we allow non-github users, some of those fields would be
      invalid; some oauth providers may not have avatars or bios
* Made CORS origins should configurable
* Made `--reconfigure-indices` and `--reset-indices` exit after
  completion instead of starting the server
This commit is contained in:
Aeledfyr
2020-10-01 00:07:52 -05:00
committed by GitHub
parent 43a791db65
commit c4fb7b7928
16 changed files with 318 additions and 561 deletions

View File

@@ -9,29 +9,30 @@ pub struct UserId(pub u64);
#[derive(Serialize, Deserialize)]
pub struct User {
pub id: UserId,
pub github_id: u64,
pub github_id: Option<u64>,
pub username: String,
pub name: String,
pub email: Option<String>,
pub avatar_url: String,
pub bio: String,
pub avatar_url: Option<String>,
pub bio: Option<String>,
pub created: chrono::DateTime<chrono::Utc>,
pub role: Role,
}
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Role {
Developer,
Moderator,
Admin,
}
impl ToString for Role {
fn to_string(&self) -> String {
impl std::fmt::Display for Role {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Role::Developer => String::from("developer"),
Role::Moderator => String::from("moderator"),
Role::Admin => String::from("admin"),
Role::Developer => write!(fmt, "developer"),
Role::Moderator => write!(fmt, "moderator"),
Role::Admin => write!(fmt, "admin"),
}
}
}