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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
use activitystreams_vocabulary::{Collection, Iri, create_actor, create_item, field_access};
mod role_filter;
pub use role_filter::{FilterKey, RoleFilter};
create_actor! {
/// Represents a group of people working together, collaborating on shared resources.
///
/// Each member [Person](activitystreams_vocabulary::Person) in the team has a defined role,
/// affecting the level of access they have to the team’s shared resources and to managing the team itself.
///
/// # Example
///
/// ```rust
/// use activityforge::{Team, context};
/// use activitystreams_vocabulary::{
/// Collection, Iri, MultibaseHeader, MultibasePublicKey, Multikey, MultikeyPublicKey, Name, Relationship,
/// };
/// # fn main() {
/// let id = Iri::try_from("https://dev.example/teams/mobilizon-dev-team").unwrap();
/// let name = Name::try_from("Mobilizon Development Team").unwrap();
/// let context = Iri::try_from("https://dev.example/teams/framasoft-developers").unwrap();
/// let summary = "We're creating a federated tool for organizing events!";
/// let inbox = Iri::try_from("https://dev.example/teams/mobilizon-dev-team/inbox").unwrap();
/// let outbox = Iri::try_from("https://dev.example/teams/mobilizon-dev-team/outbox").unwrap();
/// let followers =
/// Iri::try_from("https://dev.example/teams/mobilizon-dev-team/followers").unwrap();
///
/// let key_id = Iri::try_from("https://dev.example/aviva/treesim#main-key").unwrap();
/// let controller = Iri::try_from("https://dev.example/aviva/treesim").unwrap();
/// let encoded_multibase = "u7QGwDY2Tjn93PVFWWq02piP1NE9_XRlg-c8-jhJiHqKBHw";
///
/// let member0_subject =
/// Iri::try_from("https://dev.example/teams/mobilizon-dev-team").unwrap();
/// let member0_relationship = Iri::try_from("hasMember").unwrap();
/// let member0_object = Iri::try_from("https://dev.example/people/alice").unwrap();
/// let member0_tag = Iri::try_from("https://roles.example/admin").unwrap();
///
/// let member1_subject =
/// Iri::try_from("https://dev.example/teams/mobilizon-dev-team").unwrap();
/// let member1_relationship = Iri::try_from("hasMember").unwrap();
/// let member1_object = Iri::try_from("https://dev.example/people/bob").unwrap();
/// let member1_tag = Iri::try_from("maintain").unwrap();
///
/// let member2_subject =
/// Iri::try_from("https://dev.example/teams/mobilizon-dev-team").unwrap();
/// let member2_relationship = Iri::try_from("hasMember").unwrap();
/// let member2_object = Iri::try_from("https://dev.example/people/celine").unwrap();
/// let member2_tag = Iri::try_from("develop").unwrap();
///
/// let subteam0 = Iri::try_from("https://dev.example/teams/mobilizon-backend-team").unwrap();
/// let subteam1 = Iri::try_from("https://dev.example/teams/mobilizon-frontend-team").unwrap();
///
/// let json_str = format!(
/// r#"{{
/// "@context": [
/// "https://www.w3.org/ns/activitystreams",
/// "https://forgefed.org/ns"
/// ],
/// "type": "Team",
/// "id": "{id}",
/// "name": "{name}",
/// "summary": "{summary}",
/// "context": "{context}",
/// "inbox": "{inbox}",
/// "outbox": "{outbox}",
/// "followers": "{followers}",
/// "assertionMethod": [
/// {{
/// "type": "Multikey",
/// "id": "{key_id}",
/// "controller": "{controller}",
/// "publicKeyMultibase": "{encoded_multibase}"
/// }}
/// ],
/// "members": {{
/// "type": "Collection",
/// "totalItems": 3,
/// "items": [
/// {{
/// "type": "Relationship",
/// "tag": "{member0_tag}",
/// "object": "{member0_object}",
/// "relationship": "{member0_relationship}",
/// "subject": "{member0_subject}"
/// }},
/// {{
/// "type": "Relationship",
/// "tag": "{member1_tag}",
/// "object": "{member1_object}",
/// "relationship": "{member1_relationship}",
/// "subject": "{member1_subject}"
/// }},
/// {{
/// "type": "Relationship",
/// "tag": "{member2_tag}",
/// "object": "{member2_object}",
/// "relationship": "{member2_relationship}",
/// "subject": "{member2_subject}"
/// }}
/// ]
/// }},
/// "subteams": {{
/// "type": "Collection",
/// "totalItems": 2,
/// "items": [
/// "{subteam0}",
/// "{subteam1}"
/// ]
/// }}
/// }}"#
/// );
///
/// let context_property = context::forgefed_context();
///
/// let multibase = MultibasePublicKey::new()
/// .with_header(MultibaseHeader::Base64UrlNoPad)
/// .with_key(MultikeyPublicKey::Ed25519([
/// 0xb0, 0x0d, 0x8d, 0x93, 0x8e, 0x7f, 0x77, 0x3d, 0x51, 0x56, 0x5a, 0xad, 0x36, 0xa6,
/// 0x23, 0xf5, 0x34, 0x4f, 0x7f, 0x5d, 0x19, 0x60, 0xf9, 0xcf, 0x3e, 0x8e, 0x12, 0x62,
/// 0x1e, 0xa2, 0x81, 0x1f,
/// ]));
///
/// let multikey = Multikey::new_inner()
/// .with_id(key_id)
/// .with_controller(controller.clone())
/// .with_public_key_multibase(multibase);
///
/// let member0 = Relationship::new_inner()
/// .with_subject(member0_subject)
/// .with_relationship(member0_relationship)
/// .with_object(member0_object)
/// .with_tag(member0_tag);
///
/// let member1 = Relationship::new_inner()
/// .with_subject(member1_subject)
/// .with_relationship(member1_relationship)
/// .with_object(member1_object)
/// .with_tag(member1_tag);
///
/// let member2 = Relationship::new_inner()
/// .with_subject(member2_subject)
/// .with_relationship(member2_relationship)
/// .with_object(member2_object)
/// .with_tag(member2_tag);
///
/// let member_items = [member0, member1, member2];
/// let members = Collection::new_inner()
/// .with_total_items(member_items.len() as u64)
/// .with_items(member_items);
///
/// let subteam_items = [subteam0, subteam1];
/// let subteams = Collection::new_inner()
/// .with_total_items(subteam_items.len() as u64)
/// .with_items(subteam_items);
///
/// let team = Team::new()
/// .with_context_property(context_property)
/// .with_id(id)
/// .with_name(name)
/// .with_summary(summary)
/// .with_context(context)
/// .with_inbox(inbox)
/// .with_outbox(outbox)
/// .with_followers(followers)
/// .with_assertion_method([multikey])
/// .with_members(members)
/// .with_subteams(subteams);
///
/// assert_eq!(serde_json::to_string_pretty(&team).unwrap(), json_str);
/// assert_eq!(
/// serde_json::from_str::<Team>(json_str.as_str()).unwrap(),
/// team
/// );
/// # }
/// ```
Team: crate::ActorType::Team {
#[serde(skip_serializing_if = "Option::is_none")]
members: Option<Collection>,
#[serde(skip_serializing_if = "Option::is_none")]
subteams: Option<Collection>,
#[serde(skip_serializing_if = "Option::is_none")]
oversees: Option<Collection>,
#[serde(skip_serializing_if = "Option::is_none")]
overseen_by: Option<Collection>,
#[serde(skip_serializing_if = "Option::is_none")]
role_filter: Option<RoleFilter>,
}
}
field_access! {
Team {
/// [Collection](activitystreams_vocabulary::Collection) of [Relationship](activitystreams_vocabulary::Relationship)s whose relationship is `hasMember`, and whose subject is this `Organization`.
members: option_ref { Collection },
/// Identifies a collection of the subteams of this [Team].
///
/// Teams whose members inherit the access that this team’s members have to projects, and to project components (such as [Repository](crate::Repository)s).
///
/// The collection items are Relationship objects whose relationship is hasChild and whose instrument is the maximal role allowed for delegation, specified when the child was added.
subteams: option_ref { Collection },
/// Represents the list of [Team]s this [Team] oversees.
oversees: option_ref { Collection },
/// Represents the list of [Team]s overseen by this [Team].
overseen_by: option_ref { Collection },
/// Represents the list of [RoleFilter] entries for [Team] members.
///
/// Allows for fine-grained access control for individual [Team] members to shared resources.
role_filter: option_ref { RoleFilter },
}
}
create_item! {
TeamItem
boxed
default: Self::Team(Box::default()),
{
Team(Team),
Iri(Iri),
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::context;
use activitystreams_vocabulary::{
MultibaseHeader, MultibasePublicKey, Multikey, MultikeyPublicKey, Name, Relationship,
};
#[test]
fn test_valid() {
let id = Iri::try_from("https://dev.example/teams/mobilizon-dev-team").unwrap();
let name = Name::try_from("Mobilizon Development Team").unwrap();
let context = Iri::try_from("https://dev.example/teams/framasoft-developers").unwrap();
let summary = "We're creating a federated tool for organizing events!";
let inbox = Iri::try_from("https://dev.example/teams/mobilizon-dev-team/inbox").unwrap();
let outbox = Iri::try_from("https://dev.example/teams/mobilizon-dev-team/outbox").unwrap();
let followers =
Iri::try_from("https://dev.example/teams/mobilizon-dev-team/followers").unwrap();
let key_id = Iri::try_from("https://dev.example/aviva/treesim#main-key").unwrap();
let controller = Iri::try_from("https://dev.example/aviva/treesim").unwrap();
let encoded_multibase = "u7QGwDY2Tjn93PVFWWq02piP1NE9_XRlg-c8-jhJiHqKBHw";
let member0_subject =
Iri::try_from("https://dev.example/teams/mobilizon-dev-team").unwrap();
let member0_relationship = Iri::try_from("hasMember").unwrap();
let member0_object = Iri::try_from("https://dev.example/people/alice").unwrap();
let member0_tag = Iri::try_from("https://roles.example/admin").unwrap();
let member1_subject =
Iri::try_from("https://dev.example/teams/mobilizon-dev-team").unwrap();
let member1_relationship = Iri::try_from("hasMember").unwrap();
let member1_object = Iri::try_from("https://dev.example/people/bob").unwrap();
let member1_tag = Iri::try_from("maintain").unwrap();
let member2_subject =
Iri::try_from("https://dev.example/teams/mobilizon-dev-team").unwrap();
let member2_relationship = Iri::try_from("hasMember").unwrap();
let member2_object = Iri::try_from("https://dev.example/people/celine").unwrap();
let member2_tag = Iri::try_from("develop").unwrap();
let subteam0 = Iri::try_from("https://dev.example/teams/mobilizon-backend-team").unwrap();
let subteam1 = Iri::try_from("https://dev.example/teams/mobilizon-frontend-team").unwrap();
let json_str = format!(
r#"{{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://forgefed.org/ns"
],
"type": "Team",
"id": "{id}",
"name": "{name}",
"summary": "{summary}",
"context": "{context}",
"inbox": "{inbox}",
"outbox": "{outbox}",
"followers": "{followers}",
"assertionMethod": [
{{
"type": "Multikey",
"id": "{key_id}",
"controller": "{controller}",
"publicKeyMultibase": "{encoded_multibase}"
}}
],
"members": {{
"type": "Collection",
"totalItems": 3,
"items": [
{{
"type": "Relationship",
"tag": "{member0_tag}",
"object": "{member0_object}",
"relationship": "{member0_relationship}",
"subject": "{member0_subject}"
}},
{{
"type": "Relationship",
"tag": "{member1_tag}",
"object": "{member1_object}",
"relationship": "{member1_relationship}",
"subject": "{member1_subject}"
}},
{{
"type": "Relationship",
"tag": "{member2_tag}",
"object": "{member2_object}",
"relationship": "{member2_relationship}",
"subject": "{member2_subject}"
}}
]
}},
"subteams": {{
"type": "Collection",
"totalItems": 2,
"items": [
"{subteam0}",
"{subteam1}"
]
}}
}}"#
);
let context_property = context::forgefed_context();
let multibase = MultibasePublicKey::new()
.with_header(MultibaseHeader::Base64UrlNoPad)
.with_key(MultikeyPublicKey::Ed25519([
0xb0, 0x0d, 0x8d, 0x93, 0x8e, 0x7f, 0x77, 0x3d, 0x51, 0x56, 0x5a, 0xad, 0x36, 0xa6,
0x23, 0xf5, 0x34, 0x4f, 0x7f, 0x5d, 0x19, 0x60, 0xf9, 0xcf, 0x3e, 0x8e, 0x12, 0x62,
0x1e, 0xa2, 0x81, 0x1f,
]));
let multikey = Multikey::new_inner()
.with_id(key_id)
.with_controller(controller.clone())
.with_public_key_multibase(multibase);
let member0 = Relationship::new_inner()
.with_subject(member0_subject)
.with_relationship(member0_relationship)
.with_object(member0_object)
.with_tag(member0_tag);
let member1 = Relationship::new_inner()
.with_subject(member1_subject)
.with_relationship(member1_relationship)
.with_object(member1_object)
.with_tag(member1_tag);
let member2 = Relationship::new_inner()
.with_subject(member2_subject)
.with_relationship(member2_relationship)
.with_object(member2_object)
.with_tag(member2_tag);
let member_items = [member0, member1, member2];
let members = Collection::new_inner()
.with_total_items(member_items.len() as u64)
.with_items(member_items);
let subteam_items = [subteam0, subteam1];
let subteams = Collection::new_inner()
.with_total_items(subteam_items.len() as u64)
.with_items(subteam_items);
let repository = Team::new()
.with_context_property(context_property)
.with_id(id)
.with_name(name)
.with_summary(summary)
.with_context(context)
.with_inbox(inbox)
.with_outbox(outbox)
.with_followers(followers)
.with_assertion_method([multikey])
.with_members(members)
.with_subteams(subteams);
assert_eq!(serde_json::to_string_pretty(&repository).unwrap(), json_str);
assert_eq!(
serde_json::from_str::<Team>(json_str.as_str()).unwrap(),
repository
);
}
}