feat: Working server/comment routes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use iso8601_timestamp::Timestamp;
|
||||
|
||||
use crate::v0::{Report, User};
|
||||
use crate::v0::{self, Report, User};
|
||||
|
||||
auto_derived! {
|
||||
#[derive(Default)]
|
||||
@@ -28,7 +28,7 @@ auto_derived! {
|
||||
#[cfg_attr(feature="serde", serde(rename="mod"))]
|
||||
pub mod_id: String,
|
||||
/// The action performed (previously 'permission')
|
||||
pub action: String,
|
||||
pub action: AdminAuditItemActions,
|
||||
/// The relevant case ID, if applicable
|
||||
#[cfg_attr(feature="serde", serde(rename="case"))]
|
||||
pub case_id: String,
|
||||
@@ -37,14 +37,19 @@ auto_derived! {
|
||||
pub target_id: Option<String>,
|
||||
/// The context attached to the action, if applicable (eg. search phrases)
|
||||
pub context: Option<String>,
|
||||
/// The time the action occurred at.
|
||||
pub timestamp: Timestamp,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[cfg_attr(feature = "validator", derive(validator::Validate))]
|
||||
pub struct AdminCaseCommentCreate {
|
||||
/// The ID of the case this comment is attached to
|
||||
pub struct AdminCommentCreate {
|
||||
/// The ID of the case this comment is attached to, if applicable. This should be the 7 character short code.
|
||||
#[cfg_attr(feature="serde", serde(rename="case"))]
|
||||
pub case_id: String,
|
||||
pub case_id: Option<String>,
|
||||
/// The ID of the object this comment is attached to. Use full case ULID when creating a case comment.
|
||||
#[cfg_attr(feature="serde", serde(rename="object"))]
|
||||
pub object_id: String,
|
||||
/// The content
|
||||
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 2000)))]
|
||||
pub content: String
|
||||
@@ -52,25 +57,39 @@ auto_derived! {
|
||||
|
||||
#[derive(Default)]
|
||||
#[cfg_attr(feature = "validator", derive(validator::Validate))]
|
||||
pub struct AdminCaseCommentEdit {
|
||||
pub struct AdminCommentEdit {
|
||||
/// The new content
|
||||
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 2000)))]
|
||||
pub content: String
|
||||
}
|
||||
|
||||
pub struct AdminCaseComment {
|
||||
pub struct AdminComment {
|
||||
/// The comment ID
|
||||
pub id: String,
|
||||
/// The ID of the case this comment is attached to
|
||||
/// The ID of the case this comment is attached to, if applicable. This should be the 7 character short code
|
||||
#[cfg_attr(feature="serde", serde(rename="case"))]
|
||||
pub case_id: String,
|
||||
/// The user who posted the comment
|
||||
#[cfg_attr(feature="serde", serde(skip_serializing_if="Option::is_none"))]
|
||||
pub case_id: Option<String>,
|
||||
/// The object this comment is attached to. If this is referencing a case this is the full case ID
|
||||
#[cfg_attr(feature="serde", serde(rename="object"))]
|
||||
pub object_id: String,
|
||||
/// The user who posted the comment/action
|
||||
#[cfg_attr(feature="serde", serde(rename="user"))]
|
||||
pub user_id: String,
|
||||
/// When the comment was edited, if applicable, in iso8601
|
||||
pub edited_at: Option<Timestamp>,
|
||||
/// The content
|
||||
pub content: String
|
||||
/// The content, if this is not a system event
|
||||
#[cfg_attr(feature="serde", serde(skip_serializing_if="Option::is_none"))]
|
||||
pub content: Option<String>,
|
||||
/// The system event that happened, if this is not a comment (only applicable for cases)
|
||||
#[cfg_attr(feature="serde", serde(skip_serializing_if="Option::is_none"))]
|
||||
pub system_message: Option<AdminAuditItemActions>,
|
||||
/// The system message target
|
||||
#[cfg_attr(feature="serde", serde(skip_serializing_if="Option::is_none"))]
|
||||
pub system_message_target: Option<String>,
|
||||
/// The system message raw context
|
||||
#[cfg_attr(feature="serde", serde(skip_serializing_if="Option::is_none"))]
|
||||
pub system_message_context: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -119,23 +138,6 @@ auto_derived! {
|
||||
pub reports: Vec<Report>
|
||||
}
|
||||
|
||||
|
||||
pub struct AdminObjectNote {
|
||||
/// When the note was edited, in iso8601
|
||||
pub edited_at: Timestamp,
|
||||
/// The last user to edit the note
|
||||
#[cfg_attr(feature="serde", serde(rename="last_edited_by"))]
|
||||
pub last_edited_by_id: String,
|
||||
/// The content of the note
|
||||
pub content: String,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "validator", derive(validator::Validate))]
|
||||
pub struct AdminObjectNoteEdit {
|
||||
#[cfg_attr(feature = "validator", validate(length(max = 2000)))]
|
||||
pub content: String
|
||||
}
|
||||
|
||||
pub struct AdminStrike {
|
||||
/// The strike ID
|
||||
pub id: String,
|
||||
@@ -259,9 +261,11 @@ auto_derived! {
|
||||
pub permissions: Option<u64>,
|
||||
}
|
||||
|
||||
#[repr(u64)]
|
||||
// Flags
|
||||
|
||||
#[repr(u32)]
|
||||
pub enum AdminUserPermissionFlags {
|
||||
ObjectNotes = 0,
|
||||
Comments = 0,
|
||||
|
||||
ManageAdminUsers = 1,
|
||||
CreateTokens = 2,
|
||||
@@ -285,4 +289,88 @@ auto_derived! {
|
||||
ManageNotes = 15,
|
||||
Discover = 16,
|
||||
}
|
||||
|
||||
pub enum AdminAuditItemActions {
|
||||
// Meta
|
||||
CreateAdminUser,
|
||||
EditAdminUser,
|
||||
CreateToken,
|
||||
RevokeToken,
|
||||
|
||||
// Comments
|
||||
CommentCreate,
|
||||
CommentEdit,
|
||||
CommentFetchForObject,
|
||||
|
||||
// Servers
|
||||
ServerFetch,
|
||||
ServerFetchParticipants,
|
||||
ServerFetchMembers,
|
||||
ServerAddMember,
|
||||
ServerChangeOwner,
|
||||
ServerCreateInvite,
|
||||
ServerDeleteInvite,
|
||||
ServerDeleteAllInvites,
|
||||
ServerDelete,
|
||||
ServerEdit,
|
||||
ServerRemoveMember,
|
||||
ServerSetFlags,
|
||||
ServerInstanceBanAllMembers,
|
||||
ServerBanMember,
|
||||
ServerUnbanMember
|
||||
}
|
||||
|
||||
// Joiner payloads
|
||||
pub struct AdminServerResponse {
|
||||
pub server: v0::Server,
|
||||
pub owner: v0::User,
|
||||
pub comments: Vec<v0::AdminComment>,
|
||||
}
|
||||
|
||||
pub struct AdminServerParticipantsResponse {
|
||||
pub users: Vec<v0::User>,
|
||||
pub members: Vec<v0::Member>,
|
||||
pub sort_strategy: String
|
||||
}
|
||||
|
||||
pub struct AdminMemberWithUserAndOffsetResponse {
|
||||
pub after: Option<usize>,
|
||||
pub users: Vec<v0::MemberWithUserResponse>
|
||||
}
|
||||
}
|
||||
|
||||
impl AdminAuditItemActions {
|
||||
/// Does this action create a case comment?
|
||||
pub fn makes_comment(&self) -> bool {
|
||||
match self {
|
||||
AdminAuditItemActions::CreateAdminUser => false,
|
||||
AdminAuditItemActions::EditAdminUser => false,
|
||||
AdminAuditItemActions::CreateToken => false,
|
||||
AdminAuditItemActions::RevokeToken => false,
|
||||
AdminAuditItemActions::CommentCreate => false,
|
||||
AdminAuditItemActions::CommentEdit => false,
|
||||
AdminAuditItemActions::CommentFetchForObject => false,
|
||||
AdminAuditItemActions::ServerFetch => false,
|
||||
AdminAuditItemActions::ServerFetchParticipants => false,
|
||||
AdminAuditItemActions::ServerAddMember => true,
|
||||
AdminAuditItemActions::ServerChangeOwner => true,
|
||||
AdminAuditItemActions::ServerCreateInvite => true,
|
||||
AdminAuditItemActions::ServerDeleteInvite => true,
|
||||
AdminAuditItemActions::ServerDeleteAllInvites => true,
|
||||
AdminAuditItemActions::ServerDelete => true,
|
||||
AdminAuditItemActions::ServerEdit => true,
|
||||
AdminAuditItemActions::ServerRemoveMember => true,
|
||||
AdminAuditItemActions::ServerSetFlags => true,
|
||||
AdminAuditItemActions::ServerInstanceBanAllMembers => true,
|
||||
AdminAuditItemActions::ServerBanMember => true,
|
||||
AdminAuditItemActions::ServerUnbanMember => true,
|
||||
AdminAuditItemActions::ServerFetchMembers => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for AdminAuditItemActions {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user