ocm_types/
notification.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
5#[serde(rename_all = "camelCase")]
6pub struct NewNotification {
7    /// A notification type that is understandable for both humans and
8    /// machines (e.g. no use of special characters) providing more
9    /// information on the cause of the error.
10    /// Values that MAY be used by implementations are:
11    /// `SHARE_ACCEPTED`, `SHARE_DECLINED`, `REQUEST_RESHARE`,
12    /// `SHARE_UNSHARED`, `RESHARE_UNDO`, `RESHARE_CHANGE_PERMISSION`,
13    /// `USER_REMOVED`.
14    pub notification_type: String,
15    /// Resource type (file, folder, user, calendar, contact, ...)
16    pub resource_type: String,
17    /// Identifier of the shared resource. If the resourceType is `file`,
18    /// then see `NewShare/providerId` for the required information.
19    /// If the resourceType is `user`, then this is the user identifier
20    /// previously sent via `/invite-accepted`.
21    pub provider_id: String,
22    /// Optional additional parameters, depending on the notification
23    /// and the resource type.
24    #[serde(skip_serializing_if = "Option::is_none", default)]
25    pub notification: Option<Value>,
26}
27
28#[cfg(test)]
29mod tests {
30    use serde_json::json;
31
32    use super::NewNotification;
33
34    #[test]
35    fn serde_1() {
36        let notification =  NewNotification {
37            notification_type: "SHARE_ACCEPTED".to_string(),
38            resource_type: "file".to_string(),
39            provider_id: "7c084226-d9a1-11e6-bf26-cec0c932ce01".to_string(),
40            notification: Some(json!({
41                "message": "Recipient accepted the share",
42                "sharedSecret": "hfiuhworzwnur98d3wjiwhr"
43            }))
44        };
45
46        let json = json!({
47            "notificationType": "SHARE_ACCEPTED",
48            "resourceType": "file",
49            "providerId": "7c084226-d9a1-11e6-bf26-cec0c932ce01",
50            "notification": {
51                "message": "Recipient accepted the share",
52                "sharedSecret": "hfiuhworzwnur98d3wjiwhr"
53            }
54        });
55        assert_eq!(serde_json::to_value(notification).unwrap() ,json);
56    }
57    
58    #[test]
59    fn serde_2() {
60        let notification =  NewNotification {
61            notification_type: "USER_REMOVED".to_string(),
62            resource_type: "user".to_string(),
63            provider_id: "51dc30ddc473d43a6011e9ebba6ca770".to_string(),
64            notification: None
65        };
66
67        let json = json!({
68            "notificationType": "USER_REMOVED",
69            "resourceType": "user",
70            "providerId": "51dc30ddc473d43a6011e9ebba6ca770",
71        });
72        assert_eq!(serde_json::to_value(notification).unwrap() ,json);
73    }
74}
75//   example:
76//     shareWasAccepted:
77//       notificationType: SHARE_ACCEPTED
78//       resourceType: file
79//       providerId: 
80//       notification:
81//         message: Recipient accepted the share
82//         sharedSecret: 
83//     userWasRemoved:
84//       notificationType: USER_REMOVED
85//       resourceType: user
86//       providerId: