Prevent access to bot routes as bot.
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -2528,7 +2528,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "rauth"
|
name = "rauth"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
source = "git+https://gitlab.insrt.uk/insert/rauth?rev=19bef300ecc269c028e3d746f0a2f09842d3b37b#19bef300ecc269c028e3d746f0a2f09842d3b37b"
|
source = "git+https://github.com/insertish/rauth?rev=19bef300ecc269c028e3d746f0a2f09842d3b37b#19bef300ecc269c028e3d746f0a2f09842d3b37b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"handlebars",
|
"handlebars",
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ async-std = { version = "1.8.0", features = ["tokio1", "tokio02", "attributes"]
|
|||||||
web-push = "0.7.2"
|
web-push = "0.7.2"
|
||||||
many-to-many = "0.1.2"
|
many-to-many = "0.1.2"
|
||||||
lettre = "0.10.0-alpha.4"
|
lettre = "0.10.0-alpha.4"
|
||||||
rauth = { git = "https://gitlab.insrt.uk/insert/rauth", rev = "19bef300ecc269c028e3d746f0a2f09842d3b37b" }
|
rauth = { git = "https://github.com/insertish/rauth", rev = "19bef300ecc269c028e3d746f0a2f09842d3b37b" }
|
||||||
hive_pubsub = { git = "https://gitlab.insrt.uk/insert/hive", rev = "a89826df2b30166220e68a6ed01a58b751456604", features = ["mongo"] }
|
hive_pubsub = { git = "https://gitlab.insrt.uk/insert/hive", rev = "a89826df2b30166220e68a6ed01a58b751456604", features = ["mongo"] }
|
||||||
|
|
||||||
# web
|
# web
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ pub struct Data {
|
|||||||
|
|
||||||
#[post("/create", data = "<info>")]
|
#[post("/create", data = "<info>")]
|
||||||
pub async fn create_bot(user: User, info: Json<Data>) -> Result<Value> {
|
pub async fn create_bot(user: User, info: Json<Data>) -> Result<Value> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let info = info.into_inner();
|
let info = info.into_inner();
|
||||||
info.validate()
|
info.validate()
|
||||||
.map_err(|error| Error::FailedValidation { error })?;
|
.map_err(|error| Error::FailedValidation { error })?;
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ use mongodb::bson::doc;
|
|||||||
|
|
||||||
#[delete("/<target>")]
|
#[delete("/<target>")]
|
||||||
pub async fn delete_bot(user: User, target: Ref) -> Result<EmptyResponse> {
|
pub async fn delete_bot(user: User, target: Ref) -> Result<EmptyResponse> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let bot = target.fetch_bot().await?;
|
let bot = target.fetch_bot().await?;
|
||||||
if bot.owner != user.id {
|
if bot.owner != user.id {
|
||||||
return Err(Error::MissingPermission);
|
return Err(Error::MissingPermission);
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ pub struct Data {
|
|||||||
|
|
||||||
#[patch("/<target>", data = "<data>")]
|
#[patch("/<target>", data = "<data>")]
|
||||||
pub async fn edit_bot(user: User, target: Ref, data: Json<Data>) -> Result<EmptyResponse> {
|
pub async fn edit_bot(user: User, target: Ref, data: Json<Data>) -> Result<EmptyResponse> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let data = data.into_inner();
|
let data = data.into_inner();
|
||||||
data.validate()
|
data.validate()
|
||||||
.map_err(|error| Error::FailedValidation { error })?;
|
.map_err(|error| Error::FailedValidation { error })?;
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ use serde_json::Value;
|
|||||||
|
|
||||||
#[get("/<target>")]
|
#[get("/<target>")]
|
||||||
pub async fn fetch_bot(user: User, target: Ref) -> Result<Value> {
|
pub async fn fetch_bot(user: User, target: Ref) -> Result<Value> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let bot = target.fetch_bot().await?;
|
let bot = target.fetch_bot().await?;
|
||||||
|
|
||||||
if !bot.public {
|
if !bot.public {
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ use serde_json::Value;
|
|||||||
|
|
||||||
#[get("/@me")]
|
#[get("/@me")]
|
||||||
pub async fn fetch_owned_bots(user: User) -> Result<Value> {
|
pub async fn fetch_owned_bots(user: User) -> Result<Value> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let bots = get_collection("bots")
|
let bots = get_collection("bots")
|
||||||
.find(
|
.find(
|
||||||
doc! {
|
doc! {
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ use serde_json::Value;
|
|||||||
|
|
||||||
#[get("/<target>/invite")]
|
#[get("/<target>/invite")]
|
||||||
pub async fn fetch_public_bot(user: User, target: Ref) -> Result<Value> {
|
pub async fn fetch_public_bot(user: User, target: Ref) -> Result<Value> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let bot = target.fetch_bot().await?;
|
let bot = target.fetch_bot().await?;
|
||||||
|
|
||||||
if !bot.public {
|
if !bot.public {
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ pub enum Destination {
|
|||||||
|
|
||||||
#[post("/<target>/invite", data = "<dest>")]
|
#[post("/<target>/invite", data = "<dest>")]
|
||||||
pub async fn invite_bot(user: User, target: Ref, dest: Json<Destination>) -> Result<EmptyResponse> {
|
pub async fn invite_bot(user: User, target: Ref, dest: Json<Destination>) -> Result<EmptyResponse> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let bot = target.fetch_bot().await?;
|
let bot = target.fetch_bot().await?;
|
||||||
|
|
||||||
if !bot.public {
|
if !bot.public {
|
||||||
|
|||||||
Reference in New Issue
Block a user