Skip to main content

ocm_types/share/
mod.rs

1// SPDX-FileCopyrightText: 2026 Matthias Kraus <info@opengeomesh.org>
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5mod protocols;
6
7pub use protocols::*;
8
9use serde::{Deserialize, Serialize};
10
11use crate::common::{OcmAddress, ShareType};
12
13#[derive(Debug, PartialEq, Eq, Default, Clone, Serialize, Deserialize)]
14#[serde(rename_all = "camelCase")]
15pub struct NewShare {
16    /// Consumer specific identifier of the user, group or federation the provider
17    /// wants to share the resource with. This is known in advance.
18    /// Please note that the consumer service endpoint is known in advance
19    /// as well, so this is no part of the request body.
20    /// example: 51dc30ddc473d43a6011e9ebba6ca770@geant.org
21    pub share_with: OcmAddress,
22    /// Name of the resource (file or folder).
23    /// example: resource.txt
24    pub name: String,
25    /// Optional description of the resource (file or folder).
26    #[serde(skip_serializing_if = "Option::is_none", default)]
27    pub description: Option<String>,
28    /// Identifier to identify the shared resource at the provider side.
29    /// This is unique per provider such that if the same resource is shared twice,
30    /// this providerId will not be repeated.
31    ///
32    /// example: 7c084226-d9a1-11e6-bf26-cec0c932ce01
33    pub provider_id: String,
34    /// Provider specific identifier of the user who owns the resource.
35    ///
36    /// example: 6358b71804dfa8ab069cf05ed1b0ed2a@apiwise.nl
37    pub owner: OcmAddress,
38    /// Provider specific identifier of the user that wants to share the
39    /// resource. Please note that the requesting provider is being
40    /// identified on a higher level, so the former `remote` property
41    /// is not part of the request body.
42    ///
43    /// example: 527bd5b5d689e2c32ae974c6229ff785@apiwise.nl
44    pub sender: OcmAddress,
45    /// Display name of the owner of the resource
46    /// example: Dimitri
47    #[serde(skip_serializing_if = "Option::is_none", default)]
48    pub owner_display_name: Option<String>,
49    /// Display name of the user that wants to share the resource
50    /// example: John Doe
51    #[serde(skip_serializing_if = "Option::is_none", default)]
52    pub sender_display_name: Option<String>,
53    /// Recipient share type
54    pub share_type: ShareType,
55    /// Resource type (file, calendar, contact, ...)
56    /// example: file
57    pub resource_type: String,
58    /// The expiration time for the share, in seconds of UTC time since
59    /// Unix epoch. If omitted, it is assumed that the share does not expire.
60    #[serde(skip_serializing_if = "Option::is_none", default)]
61    pub expiration: Option<i64>,
62    pub protocol: Protocol,
63}
64
65/// The Sending Server
66/// * holds the Resource ("file server" or "Entreprise File Sync and Share (EFSS) server" role), provides access to it (by exposing at least one "API"),
67/// * takes the decision to create the Share based on user interface gestures from the Sending Party (the "Authorization Server" role in OAuth)
68/// * takes the decision about authorizing attempts to access the Resource (the "Resource Server" role in OAuth)
69/// * sends out Share Creation Notifications when appropriate
70#[derive(Debug, Clone, PartialEq, Eq, Hash)]
71pub struct SendingServer(String);
72
73impl NewShare {
74    /// Get the Sending Server from the sender of the share.
75    pub fn sending_server(&self) -> SendingServer {
76        SendingServer(self.owner.get_server_url().into())
77    }
78}
79
80impl<T: Into<String>> From<T> for SendingServer {
81    fn from(value: T) -> Self {
82        // FIXME make sure this is a fqdn
83        Self(value.into())
84    }
85}
86impl AsRef<str> for SendingServer {
87    fn as_ref(&self) -> &str {
88        &self.0
89    }
90}
91
92/// Consumer successfully received the share. The response might contain
93/// the display name of the recipient of the share for general user
94/// experience improvement.
95#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
96#[serde(rename_all = "camelCase")]
97pub struct ShareCreationResponse {
98    /// display name of the recipient
99    /// example: John Doe
100    pub recipient_display_name: Option<String>,
101    /// The public key(s) of the recipient. This value MUST be provided
102    /// in case the Share Creation Notification includes the `ssh` protocol.
103    #[serde(skip_serializing_if = "Vec::is_empty", default)]
104    pub recipient_public_keys: Vec<String>
105}