style: cargo clippy --fix && cargo fmt
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
This commit is contained in:
parent
e1d3a73687
commit
2b9a44c4f0
4 changed files with 38 additions and 35 deletions
|
@ -9,7 +9,11 @@ use axum::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::v1::auth::CurrentUser, error::Error, objects::{AuditLog, Member, PaginationRequest, Permissions}, utils::global_checks, AppState
|
AppState,
|
||||||
|
api::v1::auth::CurrentUser,
|
||||||
|
error::Error,
|
||||||
|
objects::{AuditLog, Member, PaginationRequest, Permissions},
|
||||||
|
utils::global_checks,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
|
@ -23,15 +27,11 @@ pub async fn get(
|
||||||
global_checks(&mut conn, &app_state.config, uuid).await?;
|
global_checks(&mut conn, &app_state.config, uuid).await?;
|
||||||
|
|
||||||
let caller = Member::check_membership(&mut conn, uuid, guild_uuid).await?;
|
let caller = Member::check_membership(&mut conn, uuid, guild_uuid).await?;
|
||||||
caller.check_permission(&mut conn, &app_state.cache_pool, Permissions::ManageGuild).await?;
|
caller
|
||||||
|
.check_permission(&mut conn, &app_state.cache_pool, Permissions::ManageGuild)
|
||||||
|
|
||||||
let logs = AuditLog::fetch_page(
|
|
||||||
&mut conn,
|
|
||||||
guild_uuid,
|
|
||||||
pagination,
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
let logs = AuditLog::fetch_page(&mut conn, guild_uuid, pagination).await?;
|
||||||
|
|
||||||
Ok((StatusCode::OK, Json(logs)))
|
Ok((StatusCode::OK, Json(logs)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,12 @@ use axum::{
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
mod auditlogs;
|
||||||
mod bans;
|
mod bans;
|
||||||
mod channels;
|
mod channels;
|
||||||
mod invites;
|
mod invites;
|
||||||
mod members;
|
mod members;
|
||||||
mod roles;
|
mod roles;
|
||||||
mod auditlogs;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AppState,
|
AppState,
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
use uuid::Uuid;
|
use crate::{
|
||||||
use diesel::{insert_into, Insertable, QueryDsl, Queryable, Selectable, SelectableHelper, ExpressionMethods};
|
Conn,
|
||||||
use serde::{Deserialize, Serialize};
|
error::Error,
|
||||||
use crate::{error::Error, objects::{load_or_empty, Pagination, PaginationRequest}, schema::audit_logs, Conn};
|
objects::{Pagination, PaginationRequest, load_or_empty},
|
||||||
|
schema::audit_logs,
|
||||||
|
};
|
||||||
|
use diesel::{
|
||||||
|
ExpressionMethods, Insertable, QueryDsl, Queryable, Selectable, SelectableHelper, insert_into,
|
||||||
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Insertable, Selectable, Queryable, Serialize, Deserialize, Clone)]
|
#[derive(Insertable, Selectable, Queryable, Serialize, Deserialize, Clone)]
|
||||||
#[diesel(table_name = audit_logs)]
|
#[diesel(table_name = audit_logs)]
|
||||||
#[diesel(check_for_backend(diesel::pg::Pg))]
|
#[diesel(check_for_backend(diesel::pg::Pg))]
|
||||||
pub struct AuditLog {
|
pub struct AuditLog {
|
||||||
|
|
||||||
pub uuid: Uuid,
|
pub uuid: Uuid,
|
||||||
pub guild_uuid: Uuid,
|
pub guild_uuid: Uuid,
|
||||||
pub action_id: i16,
|
pub action_id: i16,
|
||||||
|
@ -23,7 +28,6 @@ pub struct AuditLog {
|
||||||
pub changed_to: Option<String>,
|
pub changed_to: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl AuditLog {
|
impl AuditLog {
|
||||||
pub async fn count(conn: &mut Conn, guild_uuid: Uuid) -> Result<i64, Error> {
|
pub async fn count(conn: &mut Conn, guild_uuid: Uuid) -> Result<i64, Error> {
|
||||||
use audit_logs::dsl;
|
use audit_logs::dsl;
|
||||||
|
@ -40,7 +44,6 @@ impl AuditLog {
|
||||||
guild_uuid: Uuid,
|
guild_uuid: Uuid,
|
||||||
pagination: PaginationRequest,
|
pagination: PaginationRequest,
|
||||||
) -> Result<Pagination<AuditLog>, Error> {
|
) -> Result<Pagination<AuditLog>, Error> {
|
||||||
|
|
||||||
// TODO: Maybe add cache, but I do not know how
|
// TODO: Maybe add cache, but I do not know how
|
||||||
let per_page = pagination.per_page.unwrap_or(20);
|
let per_page = pagination.per_page.unwrap_or(20);
|
||||||
let offset = (pagination.page - 1) * per_page;
|
let offset = (pagination.page - 1) * per_page;
|
||||||
|
@ -59,7 +62,7 @@ impl AuditLog {
|
||||||
.offset(offset as i64)
|
.offset(offset as i64)
|
||||||
.select(AuditLog::as_select())
|
.select(AuditLog::as_select())
|
||||||
.load(conn)
|
.load(conn)
|
||||||
.await
|
.await,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let pages = (AuditLog::count(conn, guild_uuid).await? as f32 / per_page as f32).ceil();
|
let pages = (AuditLog::count(conn, guild_uuid).await? as f32 / per_page as f32).ceil();
|
||||||
|
@ -99,7 +102,7 @@ impl AuditLog {
|
||||||
role_uuid,
|
role_uuid,
|
||||||
audit_message,
|
audit_message,
|
||||||
changed_from,
|
changed_from,
|
||||||
changed_to
|
changed_to,
|
||||||
};
|
};
|
||||||
|
|
||||||
insert_into(audit_logs::table)
|
insert_into(audit_logs::table)
|
||||||
|
|
|
@ -7,6 +7,7 @@ use log::debug;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
mod auditlog;
|
||||||
mod bans;
|
mod bans;
|
||||||
mod channel;
|
mod channel;
|
||||||
mod email_token;
|
mod email_token;
|
||||||
|
@ -19,8 +20,8 @@ mod message;
|
||||||
mod password_reset_token;
|
mod password_reset_token;
|
||||||
mod role;
|
mod role;
|
||||||
mod user;
|
mod user;
|
||||||
mod auditlog;
|
|
||||||
|
|
||||||
|
pub use auditlog::AuditLog;
|
||||||
pub use bans::GuildBan;
|
pub use bans::GuildBan;
|
||||||
pub use channel::Channel;
|
pub use channel::Channel;
|
||||||
pub use email_token::EmailToken;
|
pub use email_token::EmailToken;
|
||||||
|
@ -35,7 +36,6 @@ pub use password_reset_token::PasswordResetToken;
|
||||||
pub use role::Permissions;
|
pub use role::Permissions;
|
||||||
pub use role::Role;
|
pub use role::Role;
|
||||||
pub use user::User;
|
pub use user::User;
|
||||||
pub use auditlog::AuditLog;
|
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue