Skip to content

Commit

Permalink
add icon to arcadia
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesycod committed Jan 6, 2024
1 parent 110b976 commit 5554dad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/panelapi/auth.rs
Expand Up @@ -199,7 +199,7 @@ pub async fn get_staff_member(pool: &PgPool, cache_http: &crate::impls::cache::C
.await
.map_err(|e: sqlx::Error| format!("Error while getting staff perms of user {}: {}", user_id, e))?;

let pos = sqlx::query!("SELECT id, name, role_id, perms, corresponding_roles, index, created_at FROM staff_positions WHERE id = ANY($1)", &data.positions)
let pos = sqlx::query!("SELECT id, name, role_id, perms, corresponding_roles, icon, index, created_at FROM staff_positions WHERE id = ANY($1)", &data.positions)
.fetch_all(pool)
.await
.map_err(|e: sqlx::Error| format!("Error while getting positions of user {}: {}", user_id, e))?;
Expand All @@ -221,6 +221,7 @@ pub async fn get_staff_member(pool: &PgPool, cache_http: &crate::impls::cache::C
role_id: position_data.role_id,
perms: position_data.perms,
corresponding_roles: serde_json::from_value(position_data.corresponding_roles.clone()).unwrap_or_default(),
icon: position_data.icon,
index: position_data.index,
created_at: position_data.created_at,
});
Expand Down
13 changes: 8 additions & 5 deletions src/panelapi/server.rs
Expand Up @@ -2454,7 +2454,7 @@ async fn query(

match action {
StaffPositionAction::ListPositions => {
let pos = sqlx::query!("SELECT id, name, role_id, perms, corresponding_roles, index, created_at FROM staff_positions ORDER BY index ASC")
let pos = sqlx::query!("SELECT id, name, role_id, perms, corresponding_roles, icon, index, created_at FROM staff_positions ORDER BY index ASC")
.fetch_all(&state.pool)
.await
.map_err(|e| format!("Error while getting staff positions {}", e))
Expand All @@ -2469,6 +2469,7 @@ async fn query(
role_id: position_data.role_id,
perms: position_data.perms,
corresponding_roles: serde_json::from_value(position_data.corresponding_roles).map_err(Error::new)?,
icon: position_data.icon,
index: position_data.index,
created_at: position_data.created_at,
});
Expand Down Expand Up @@ -2623,7 +2624,7 @@ async fn query(

Ok((StatusCode::NO_CONTENT, "").into_response())
},
StaffPositionAction::CreatePosition { name, role_id, perms, index, corresponding_roles } => {
StaffPositionAction::CreatePosition { name, role_id, perms, index, corresponding_roles, icon } => {
// Get permissions
let sm = super::auth::get_staff_member(&state.pool, &state.cache_http, &auth_data.user_id)
.await
Expand Down Expand Up @@ -2722,10 +2723,11 @@ async fn query(

// Create the position
sqlx::query!(
"INSERT INTO staff_positions (name, perms, corresponding_roles, role_id, index) VALUES ($1, $2, $3, $4, $5)",
"INSERT INTO staff_positions (name, perms, corresponding_roles, icon, role_id, index) VALUES ($1, $2, $3, $4, $5, $6)",
name,
&perms,
serde_json::to_value(corresponding_roles).map_err(Error::new)?,
icon,
role_id,
index,
)
Expand All @@ -2738,7 +2740,7 @@ async fn query(

Ok((StatusCode::NO_CONTENT, "").into_response())
},
StaffPositionAction::EditPosition { id, name, role_id, perms, corresponding_roles } => {
StaffPositionAction::EditPosition { id, name, role_id, perms, corresponding_roles, icon } => {
let uuid = sqlx::types::uuid::Uuid::parse_str(&id).map_err(Error::new)?;

// Get permissions
Expand Down Expand Up @@ -2842,11 +2844,12 @@ async fn query(

// Update the position
sqlx::query!(
"UPDATE staff_positions SET name = $1, perms = $2, corresponding_roles = $3, role_id = $4 WHERE id = $5",
"UPDATE staff_positions SET name = $1, perms = $2, corresponding_roles = $3, role_id = $4, icon = $5 WHERE id = $6",
name,
&perms,
serde_json::to_value(corresponding_roles).map_err(Error::new)?,
role_id,
icon,
uuid
)
.execute(&mut *tx)
Expand Down
6 changes: 6 additions & 0 deletions src/panelapi/types/staff_positions.rs
Expand Up @@ -47,6 +47,8 @@ pub enum StaffPositionAction {
corresponding_roles: Vec<Link>,
/// The preset permissions of this position
perms: Vec<String>,
/// The icon of the position
icon: String,
/// The index of the position, higher means further down on hierarchy
index: i32,
},
Expand All @@ -64,6 +66,8 @@ pub enum StaffPositionAction {
corresponding_roles: Vec<Link>,
/// The preset permissions of this position
perms: Vec<String>,
/// The icon of the position
icon: String,
},
/// Delete a staff position
DeletePosition {
Expand All @@ -85,6 +89,8 @@ pub struct StaffPosition {
pub perms: Vec<String>,
/// Corresponding roles of the position
pub corresponding_roles: Vec<Link>,
/// The icon of the position
pub icon: String,
/// The index of the position, higher means further down on hierarchy
pub index: i32,
/// When the staff position was created/added
Expand Down

0 comments on commit 5554dad

Please sign in to comment.