add seperate non token webhook routes
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use revolt_quark::{Db, Ref, Result, Error, models::{webhook::{FieldsWebhook, Webhook, PartialWebhook}, File}};
|
||||
use revolt_quark::{Db, Ref, Result, Error, models::{webhook::{FieldsWebhook, Webhook, PartialWebhook}, File, User}, Permission, perms};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use validator::Validate;
|
||||
use rocket::serde::json::Json;
|
||||
@@ -19,17 +19,20 @@ pub struct WebhookEditBody {
|
||||
///
|
||||
/// edits a webhook
|
||||
#[openapi(tag = "Webhooks")]
|
||||
#[patch("/<target>/<token>", data="<data>")]
|
||||
pub async fn req(db: &Db, target: Ref, token: String, data: Json<WebhookEditBody>) -> Result<Json<Webhook>> {
|
||||
#[patch("/<target>", data="<data>")]
|
||||
pub async fn req(db: &Db, target: Ref, user: User, data: Json<WebhookEditBody>) -> Result<Json<Webhook>> {
|
||||
let data = data.into_inner();
|
||||
data.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
let mut webhook = target.as_webhook(db).await?;
|
||||
|
||||
(webhook.token == token)
|
||||
.then_some(())
|
||||
.ok_or(Error::InvalidCredentials)?;
|
||||
let channel = Ref::from_unchecked(webhook.channel.clone()).as_channel(db).await?;
|
||||
|
||||
perms(&user)
|
||||
.channel(&channel)
|
||||
.throw_permission(db, Permission::ManageWebhooks)
|
||||
.await?;
|
||||
|
||||
if data.name.is_none()
|
||||
&& data.avatar.is_none()
|
||||
|
||||
Reference in New Issue
Block a user