From 3f2aeba17e5c3bca752d5e09a9337f74ecdbe29b Mon Sep 17 00:00:00 2001 From: realaravinth Date: Sun, 9 May 2021 19:32:17 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20=20@=20aa0c3?= =?UTF-8?q?0f1bd2f34e90bd7565e34bd2d3e9aed872a=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- guard/all.html | 2 +- guard/api/v1/fn.services.html | 2 +- guard/api/v1/index.html | 4 +- .../add/fn.add_notification.html | 6 + guard/api/v1/notifications/add/index.html | 8 + .../api/v1/notifications/add/sidebar-items.js | 1 + .../add/struct.AddNotification.html | 119 ++++++++++ guard/api/v1/notifications/fn.services.html | 5 + guard/api/v1/notifications/index.html | 7 + guard/api/v1/notifications/routes/index.html | 6 + .../v1/notifications/routes/sidebar-items.js | 1 + .../routes/struct.Notifications.html | 117 ++++++++++ guard/api/v1/notifications/sidebar-items.js | 1 + guard/api/v1/routes/constant.ROUTES.html | 2 +- guard/api/v1/routes/index.html | 2 +- guard/api/v1/routes/struct.Routes.html | 7 +- guard/api/v1/sidebar-items.js | 2 +- guard/constant.V1_API_ROUTES.html | 2 +- implementors/core/marker/trait.Freeze.js | 2 +- implementors/core/marker/trait.Send.js | 2 +- implementors/core/marker/trait.Sync.js | 2 +- implementors/core/marker/trait.Unpin.js | 2 +- implementors/serde/de/trait.Deserialize.js | 2 +- implementors/serde/ser/trait.Serialize.js | 2 +- implementors/std/panic/trait.RefUnwindSafe.js | 2 +- implementors/std/panic/trait.UnwindSafe.js | 2 +- search-index.js | 2 +- source-files.js | 2 +- src/guard/api/v1/mod.rs.html | 4 + src/guard/api/v1/notifications/add.rs.html | 211 ++++++++++++++++++ src/guard/api/v1/notifications/mod.rs.html | 105 +++++++++ src/guard/api/v1/routes.rs.html | 6 + src/guard/pages/routes.rs.html | 4 +- 33 files changed, 621 insertions(+), 23 deletions(-) create mode 100644 guard/api/v1/notifications/add/fn.add_notification.html create mode 100644 guard/api/v1/notifications/add/index.html create mode 100644 guard/api/v1/notifications/add/sidebar-items.js create mode 100644 guard/api/v1/notifications/add/struct.AddNotification.html create mode 100644 guard/api/v1/notifications/fn.services.html create mode 100644 guard/api/v1/notifications/index.html create mode 100644 guard/api/v1/notifications/routes/index.html create mode 100644 guard/api/v1/notifications/routes/sidebar-items.js create mode 100644 guard/api/v1/notifications/routes/struct.Notifications.html create mode 100644 guard/api/v1/notifications/sidebar-items.js create mode 100644 src/guard/api/v1/notifications/add.rs.html create mode 100644 src/guard/api/v1/notifications/mod.rs.html diff --git a/guard/all.html b/guard/all.html index 0a0d7230..8315d743 100644 --- a/guard/all.html +++ b/guard/all.html @@ -3,5 +3,5 @@

List of all items[] -

Structs

Enums

Macros

Functions

Typedefs

Statics

Constants

+

Structs

Enums

Macros

Functions

Typedefs

Statics

Constants

\ No newline at end of file diff --git a/guard/api/v1/fn.services.html b/guard/api/v1/fn.services.html index 7a7d3890..ec652916 100644 --- a/guard/api/v1/fn.services.html +++ b/guard/api/v1/fn.services.html @@ -1,5 +1,5 @@ guard::api::v1::services - Rust

Function guard::api::v1::services[][src]

pub fn services(cfg: &mut ServiceConfig)
+ Change settings

Function guard::api::v1::services[][src]

pub fn services(cfg: &mut ServiceConfig)
\ No newline at end of file diff --git a/guard/api/v1/index.html b/guard/api/v1/index.html index e4f56bb0..665535ce 100644 --- a/guard/api/v1/index.html +++ b/guard/api/v1/index.html @@ -1,8 +1,8 @@ guard::api::v1 - Rust

Module guard::api::v1[][src]

Re-exports

+ Change settings

Module guard::api::v1[][src]

Re-exports

pub use routes::ROUTES;

Modules

-
account
auth
mcaptcha
meta
pow
routes

Functions

+
account
auth
mcaptcha
meta
notifications
pow
routes

Functions

services
\ No newline at end of file diff --git a/guard/api/v1/notifications/add/fn.add_notification.html b/guard/api/v1/notifications/add/fn.add_notification.html new file mode 100644 index 00000000..7cec9cb2 --- /dev/null +++ b/guard/api/v1/notifications/add/fn.add_notification.html @@ -0,0 +1,6 @@ +guard::api::v1::notifications::add::add_notification - Rust + +

Function guard::api::v1::notifications::add::add_notification[][src]

pub async fn add_notification(
    payload: Json<AddNotification>,
    data: Data<Data>,
    id: Identity
) -> Result<impl Responder, ServiceError>

route handler that adds a notification message

+
+ \ No newline at end of file diff --git a/guard/api/v1/notifications/add/index.html b/guard/api/v1/notifications/add/index.html new file mode 100644 index 00000000..1462eacc --- /dev/null +++ b/guard/api/v1/notifications/add/index.html @@ -0,0 +1,8 @@ +guard::api::v1::notifications::add - Rust + +

Module guard::api::v1::notifications::add[][src]

Structs

+
AddNotification

Functions

+
add_notification

route handler that adds a notification message

+
+ \ No newline at end of file diff --git a/guard/api/v1/notifications/add/sidebar-items.js b/guard/api/v1/notifications/add/sidebar-items.js new file mode 100644 index 00000000..3fcd893e --- /dev/null +++ b/guard/api/v1/notifications/add/sidebar-items.js @@ -0,0 +1 @@ +initSidebarItems({"fn":[["add_notification","route handler that adds a notification message"]],"struct":[["AddNotification",""]]}); \ No newline at end of file diff --git a/guard/api/v1/notifications/add/struct.AddNotification.html b/guard/api/v1/notifications/add/struct.AddNotification.html new file mode 100644 index 00000000..bfcee935 --- /dev/null +++ b/guard/api/v1/notifications/add/struct.AddNotification.html @@ -0,0 +1,119 @@ +guard::api::v1::notifications::add::AddNotification - Rust + +

Struct guard::api::v1::notifications::add::AddNotification[][src]

pub struct AddNotification {
+    pub to: String,
+    pub heading: String,
+    pub message: String,
+}

+ Fields

to: Stringheading: Stringmessage: String

Trait Implementations

impl<'de> Deserialize<'de> for AddNotification[src]

impl Serialize for AddNotification[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

+

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

+

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

+

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

+ \ No newline at end of file diff --git a/guard/api/v1/notifications/fn.services.html b/guard/api/v1/notifications/fn.services.html new file mode 100644 index 00000000..ed6c431d --- /dev/null +++ b/guard/api/v1/notifications/fn.services.html @@ -0,0 +1,5 @@ +guard::api::v1::notifications::services - Rust + +

Function guard::api::v1::notifications::services[][src]

pub fn services(cfg: &mut ServiceConfig)
+ \ No newline at end of file diff --git a/guard/api/v1/notifications/index.html b/guard/api/v1/notifications/index.html new file mode 100644 index 00000000..9062cc76 --- /dev/null +++ b/guard/api/v1/notifications/index.html @@ -0,0 +1,7 @@ +guard::api::v1::notifications - Rust + +

Module guard::api::v1::notifications[][src]

Modules

+
add
routes

Functions

+
services
+ \ No newline at end of file diff --git a/guard/api/v1/notifications/routes/index.html b/guard/api/v1/notifications/routes/index.html new file mode 100644 index 00000000..1515dff0 --- /dev/null +++ b/guard/api/v1/notifications/routes/index.html @@ -0,0 +1,6 @@ +guard::api::v1::notifications::routes - Rust + +

Module guard::api::v1::notifications::routes[][src]

Structs

+
Notifications
+ \ No newline at end of file diff --git a/guard/api/v1/notifications/routes/sidebar-items.js b/guard/api/v1/notifications/routes/sidebar-items.js new file mode 100644 index 00000000..c0a8ffc6 --- /dev/null +++ b/guard/api/v1/notifications/routes/sidebar-items.js @@ -0,0 +1 @@ +initSidebarItems({"struct":[["Notifications",""]]}); \ No newline at end of file diff --git a/guard/api/v1/notifications/routes/struct.Notifications.html b/guard/api/v1/notifications/routes/struct.Notifications.html new file mode 100644 index 00000000..f30cf198 --- /dev/null +++ b/guard/api/v1/notifications/routes/struct.Notifications.html @@ -0,0 +1,117 @@ +guard::api::v1::notifications::routes::Notifications - Rust + +

Struct guard::api::v1::notifications::routes::Notifications[][src]

pub struct Notifications {
+    pub add: &'static str,
+    pub mark_read: &'static str,
+    pub get: &'static str,
+}

+ Fields

add: &'static strmark_read: &'static strget: &'static str

Implementations

impl Notifications[src]

pub const fn new() -> Notifications[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

+

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

+

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

+

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

+ \ No newline at end of file diff --git a/guard/api/v1/notifications/sidebar-items.js b/guard/api/v1/notifications/sidebar-items.js new file mode 100644 index 00000000..d69c2c9e --- /dev/null +++ b/guard/api/v1/notifications/sidebar-items.js @@ -0,0 +1 @@ +initSidebarItems({"fn":[["services",""]],"mod":[["add",""],["routes",""]]}); \ No newline at end of file diff --git a/guard/api/v1/routes/constant.ROUTES.html b/guard/api/v1/routes/constant.ROUTES.html index 52084f68..e839bcb6 100644 --- a/guard/api/v1/routes/constant.ROUTES.html +++ b/guard/api/v1/routes/constant.ROUTES.html @@ -1,5 +1,5 @@ guard::api::v1::routes::ROUTES - Rust

Constant guard::api::v1::routes::ROUTES[][src]

pub const ROUTES: Routes;
+ Change settings

Constant guard::api::v1::routes::ROUTES[][src]

pub const ROUTES: Routes;
\ No newline at end of file diff --git a/guard/api/v1/routes/index.html b/guard/api/v1/routes/index.html index 4ad25e42..f1975556 100644 --- a/guard/api/v1/routes/index.html +++ b/guard/api/v1/routes/index.html @@ -1,7 +1,7 @@ guard::api::v1::routes - Rust

Module guard::api::v1::routes[][src]

Structs

+ Change settings

Module guard::api::v1::routes[][src]

Structs

Routes

Constants

ROUTES
\ No newline at end of file diff --git a/guard/api/v1/routes/struct.Routes.html b/guard/api/v1/routes/struct.Routes.html index 327d74de..2d2350bc 100644 --- a/guard/api/v1/routes/struct.Routes.html +++ b/guard/api/v1/routes/struct.Routes.html @@ -1,7 +1,7 @@ guard::api::v1::routes::Routes - Rust -

Struct guard::api::v1::routes::Routes[][src]

pub struct Routes {
+

Struct guard::api::v1::routes::Routes[][src]

pub struct Routes {
     pub auth: Auth,
     pub account: Account,
     pub levels: Levels,
@@ -9,8 +9,9 @@
     pub duration: Duration,
     pub meta: Meta,
     pub pow: PoW,
+    pub notifications: Notifications,
 }

- Fields

auth: Authaccount: Accountlevels: Levelsmcaptcha: MCaptchaduration: Durationmeta: Metapow: PoW

Implementations

impl Routes[src]

const fn new() -> Routes[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

 /*
 * Copyright (C) 2021  Aravinth Manivannan <realaravinth@batsense.net>
@@ -63,6 +65,7 @@
 pub mod auth;
 pub mod mcaptcha;
 pub mod meta;
+mod notifications;
 pub mod pow;
 mod routes;
 
@@ -73,6 +76,7 @@
     auth::services(cfg);
     account::services(cfg);
     mcaptcha::services(cfg);
+    notifications::services(cfg);
     pow::services(cfg);
 }
 
diff --git a/src/guard/api/v1/notifications/add.rs.html b/src/guard/api/v1/notifications/add.rs.html
new file mode 100644
index 00000000..3ca19ac4
--- /dev/null
+++ b/src/guard/api/v1/notifications/add.rs.html
@@ -0,0 +1,211 @@
+add.rs - source
+
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+
+/*
+* Copyright (C) 2021  Aravinth Manivannan <realaravinth@batsense.net>
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+use actix_identity::Identity;
+use actix_web::{web, HttpResponse, Responder};
+use serde::{Deserialize, Serialize};
+
+use crate::errors::*;
+use crate::Data;
+
+#[derive(Serialize, Deserialize)]
+pub struct AddNotification {
+    pub to: String,
+    pub heading: String,
+    pub message: String,
+}
+
+/// route handler that adds a notification message
+pub async fn add_notification(
+    payload: web::Json<AddNotification>,
+    data: web::Data<Data>,
+    id: Identity,
+) -> ServiceResult<impl Responder> {
+    let sender = id.identity().unwrap();
+    // TODO handle error where payload.to doesnt exist
+    sqlx::query!(
+        "INSERT INTO mcaptcha_notifications (
+              heading, message, tx, rx)
+              VALUES  (
+              $1, $2,
+                  (SELECT ID FROM mcaptcha_users WHERE name = $3),
+                  (SELECT ID FROM mcaptcha_users WHERE name = $4)
+                      );",
+        &payload.heading,
+        &payload.message,
+        &sender,
+        &payload.to,
+    )
+    .execute(&data.db)
+    .await?;
+    Ok(HttpResponse::Ok())
+}
+
+#[cfg(test)]
+mod tests {
+    use actix_web::http::{header, StatusCode};
+    use actix_web::test;
+
+    use super::*;
+    use crate::tests::*;
+    use crate::*;
+
+    #[actix_rt::test]
+    async fn notification_works() {
+        const NAME1: &str = "notifuser1";
+        const NAME2: &str = "notiuser2";
+        const PASSWORD: &str = "longpassworddomain";
+        const EMAIL1: &str = "testnotification1@a.com";
+        const EMAIL2: &str = "testnotification2@a.com";
+
+        {
+            let data = Data::new().await;
+            delete_user(NAME1, &data).await;
+            delete_user(NAME2, &data).await;
+        }
+
+        register_and_signin(NAME1, EMAIL1, PASSWORD).await;
+        register_and_signin(NAME2, EMAIL2, PASSWORD).await;
+        let (data, _creds, signin_resp) = signin(NAME1, PASSWORD).await;
+        let cookies = get_cookie!(signin_resp);
+        let mut app = get_app!(data).await;
+
+        let msg = AddNotification {
+            to: NAME2.into(),
+            heading: "Test notification".into(),
+            message: "Testeing notifications with a dummy message".into(),
+        };
+
+        let send_notification_resp = test::call_service(
+            &mut app,
+            post_request!(&msg, V1_API_ROUTES.notifications.add)
+                .cookie(cookies.clone())
+                .to_request(),
+        )
+        .await;
+        assert_eq!(send_notification_resp.status(), StatusCode::OK);
+    }
+}
+
+
+ \ No newline at end of file diff --git a/src/guard/api/v1/notifications/mod.rs.html b/src/guard/api/v1/notifications/mod.rs.html new file mode 100644 index 00000000..10a671ed --- /dev/null +++ b/src/guard/api/v1/notifications/mod.rs.html @@ -0,0 +1,105 @@ +mod.rs - source + +
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+
+/*
+* Copyright (C) 2021  Aravinth Manivannan <realaravinth@batsense.net>
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+mod add;
+
+pub mod routes {
+
+    pub struct Notifications {
+        pub add: &'static str,
+        pub mark_read: &'static str,
+        pub get: &'static str,
+    }
+
+    impl Notifications {
+        pub const fn new() -> Notifications {
+            Notifications {
+                add: "/api/v1/notifications/add",
+                mark_read: "/api/v1/notifications/read/",
+                get: "/api/v1/notifications/get/",
+            }
+        }
+    }
+}
+
+pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
+    use crate::define_resource;
+    use crate::V1_API_ROUTES;
+
+    define_resource!(
+        cfg,
+        V1_API_ROUTES.notifications.add,
+        Methods::ProtectPost,
+        add::add_notification
+    );
+}
+
+
+ \ No newline at end of file diff --git a/src/guard/api/v1/routes.rs.html b/src/guard/api/v1/routes.rs.html index 1a3724b5..8206f7c6 100644 --- a/src/guard/api/v1/routes.rs.html +++ b/src/guard/api/v1/routes.rs.html @@ -51,6 +51,9 @@ 48 49 50 +51 +52 +53
 /*
 * Copyright (C) 2021  Aravinth Manivannan <realaravinth@batsense.net>
@@ -75,6 +78,7 @@
 use super::mcaptcha::levels::routes::Levels;
 use super::mcaptcha::mcaptcha::routes::MCaptcha;
 use super::meta::routes::Meta;
+use super::notifications::routes::Notifications;
 use super::pow::routes::PoW;
 
 pub const ROUTES: Routes = Routes::new();
@@ -87,6 +91,7 @@
     pub duration: Duration,
     pub meta: Meta,
     pub pow: PoW,
+    pub notifications: Notifications,
 }
 
 impl Routes {
@@ -99,6 +104,7 @@
             duration: Duration::new(),
             meta: Meta::new(),
             pow: PoW::new(),
+            notifications: Notifications::new(),
         }
     }
 }
diff --git a/src/guard/pages/routes.rs.html b/src/guard/pages/routes.rs.html
index 9da93ee7..003a8f0c 100644
--- a/src/guard/pages/routes.rs.html
+++ b/src/guard/pages/routes.rs.html
@@ -90,9 +90,9 @@
             panel,
             home,
             errors: Errors::new(),
-            about: "/aboubt",
+            about: "/about",
             thanks: "/thanks",
-            donate: "/donat",
+            donate: "/donate",
         }
     }
 }