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