2023-01-20 01:28:28 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2023-01-22 23:50:29 +00:00
|
|
|
use specs::{Component, DerefFlaggedStorage, VecStorage};
|
2023-05-04 22:11:43 +00:00
|
|
|
use strum::EnumVariantNames;
|
2019-08-09 14:22:59 +00:00
|
|
|
|
2023-05-04 22:11:43 +00:00
|
|
|
// EnumVariantNames is used by bins for clap only, but using strum here gets rid
|
|
|
|
// of the clap dependency
|
|
|
|
#[derive(
|
|
|
|
Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize, EnumVariantNames,
|
|
|
|
)]
|
|
|
|
pub enum AdminRole {
|
|
|
|
Moderator = 0,
|
|
|
|
Admin = 1,
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
}
|
|
|
|
|
2023-05-05 13:05:57 +00:00
|
|
|
impl core::str::FromStr for AdminRole {
|
|
|
|
type Err = &'static str;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
match s {
|
|
|
|
"mod" | "moderator" => Ok(AdminRole::Moderator),
|
|
|
|
"admin" => Ok(AdminRole::Admin),
|
|
|
|
_ => Err("Could not parse AdminRole"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToString for AdminRole {
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
match self {
|
|
|
|
AdminRole::Moderator => "moderator",
|
|
|
|
AdminRole::Admin => "admin",
|
|
|
|
}
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-20 01:28:28 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
pub struct Admin(pub AdminRole);
|
2019-08-09 14:22:59 +00:00
|
|
|
|
2019-08-14 15:51:59 +00:00
|
|
|
impl Component for Admin {
|
2023-01-22 23:50:29 +00:00
|
|
|
type Storage = DerefFlaggedStorage<Self, VecStorage<Self>>;
|
2019-08-09 14:22:59 +00:00
|
|
|
}
|