-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
2,314 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,10 @@ Content-Type: application/vnd.api+json | |
{ | ||
"id": "2a31ce0128b5f89e40fd90da3f014087", | ||
"type": "io.cozy.contacts" | ||
}, | ||
{ | ||
"id": "51bbc980acb0013cb5f618c04daba326", | ||
"type": "io.cozy.contacts.groups" | ||
} | ||
] | ||
} | ||
|
@@ -136,6 +140,20 @@ Content-Type: application/vnd.api+json | |
"status": "mail-not-sent", | ||
"name": "Bob", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"status": "mail-not-sent", | ||
"name": "Gaby", | ||
"email": "[email protected]", | ||
"only_in_groups": true, | ||
"groups": [0] | ||
} | ||
], | ||
"groups": [ | ||
{ | ||
"id": "51bbc980acb0013cb5f618c04daba326", | ||
"name": "G. people", | ||
"addedBy": 0 | ||
} | ||
], | ||
"rules": [ | ||
|
@@ -747,9 +765,9 @@ HTTP/1.1 204 No Content | |
|
||
### POST /sharings/:sharing-id/recipients | ||
|
||
This route allows the sharer to add new recipients to a sharing. It can also be | ||
used by a recipient when the sharing has `open_sharing` set to true if the | ||
recipient doesn't have the `read_only` flag | ||
This route allows the sharer to add new recipients (and groups of recipients) | ||
to a sharing. It can also be used by a recipient when the sharing has | ||
`open_sharing` set to true if the recipient doesn't have the `read_only` flag. | ||
|
||
#### Request | ||
|
||
|
@@ -868,9 +886,9 @@ Content-Type: application/vnd.api+json | |
### POST /sharings/:sharing-id/recipients/delegated | ||
|
||
This is an internal route for the stack. It is called by the recipient cozy on | ||
the owner cozy to add recipients to the sharing (`open_sharing: true` only). It | ||
should send an `email` address, but if the email address is not known, an | ||
`instance` URL can also be used. | ||
the owner cozy to add recipients and groups to the sharing (`open_sharing: | ||
true` only). Data for direct recipients should contain an email address but if | ||
it is not known, an instance URL can also be provided. | ||
|
||
#### Request | ||
|
||
|
@@ -892,6 +910,15 @@ Content-Type: application/vnd.api+json | |
"email": "[email protected]" | ||
} | ||
] | ||
}, | ||
"groups": { | ||
"data": [ | ||
{ | ||
"id": "b57cd790b2f4013c3ced18c04daba326", | ||
"name": "Dance", | ||
"addedBy": 1 | ||
} | ||
] | ||
} | ||
} | ||
} | ||
|
@@ -911,12 +938,68 @@ Content-Type: application/json | |
} | ||
``` | ||
|
||
### POST /sharings/:sharing-id/members/:index/invitation | ||
|
||
This is an internal route for the stack. It is called by the recipient cozy on | ||
the owner cozy to send an invitation. | ||
|
||
#### Request | ||
|
||
```http | ||
POST /sharings/ce8835a061d0ef68947afe69a0046722/members/4/invitation HTTP/1.1 | ||
Host: alice.example.net | ||
Content-Type: application/vnd.api+json | ||
``` | ||
|
||
```json | ||
{ | ||
"data": { | ||
"type": "io.cozy.sharings.members", | ||
"attributes": { | ||
"email": "[email protected]" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
#### Response | ||
|
||
```http | ||
HTTP/1.1 200 OK | ||
Content-Type: application/json | ||
``` | ||
|
||
```json | ||
{ | ||
"[email protected]": "uS6wN7fTYaLZ-GdC_P6UWA" | ||
} | ||
``` | ||
|
||
### DELETE /sharings/:sharing-id/groups/:group-index/:member-index | ||
|
||
This is an internal route for the stack. It is called by the recipient cozy on | ||
the owner cozy to remove a member of a sharing from a group. | ||
|
||
#### Request | ||
|
||
```http | ||
DELETE /sharings/ce8835a061d0ef68947afe69a0046722/groups/0/1 HTTP/1.1 | ||
Host: alice.example.net | ||
``` | ||
|
||
#### Response | ||
|
||
```http | ||
HTTP/1.1 204 No Content | ||
``` | ||
|
||
### PUT /sharings/:sharing-id/recipients | ||
|
||
This internal route is used to update the list of members, their states, emails | ||
and names, on the recipients cozy. The token used for this route can be the | ||
access token for a sharing where synchronization is active, or the sharecode | ||
for a member who has only a shortcut to the sharing on their Cozy instance. | ||
This internal route is used to update the list of members (their states, emails | ||
and names) and the list of groups on the recipients cozy. The token used for | ||
this route can be the access token for a sharing where synchronization is | ||
active, or the sharecode for a member who has only a shortcut to the sharing on | ||
their Cozy instance. | ||
|
||
#### Request | ||
|
||
|
@@ -953,6 +1036,13 @@ Content-Type: application/vnd.api+json | |
"email": "[email protected]", | ||
"read_only": true | ||
} | ||
], | ||
"included": [ | ||
{ | ||
"id": "51bbc980acb0013cb5f618c04daba326", | ||
"name": "G. people", | ||
"addedBy": 0 | ||
} | ||
] | ||
} | ||
``` | ||
|
@@ -1137,6 +1227,27 @@ Host: alice.example.net | |
HTTP/1.1 204 No Content | ||
``` | ||
|
||
### DELETE /sharings/:sharing-id/groups/:index | ||
|
||
This route can be only be called on the cozy instance of the sharer to revoke a | ||
group of the sharing. The parameter is the index of this recipient in the | ||
`groups` array of the sharing. The `removed` property for this group will be | ||
set to `true`, and it will revoke the members of this group unless they are | ||
still part of the sharing via another group or as direct recipients. | ||
|
||
#### Request | ||
|
||
```http | ||
DELETE /sharings/ce8835a061d0ef68947afe69a0046722/groups/0 HTTP/1.1 | ||
Host: alice.example.net | ||
``` | ||
|
||
#### Response | ||
|
||
```http | ||
HTTP/1.1 204 No Content | ||
``` | ||
|
||
### DELETE /sharings/:sharing-id/recipients/self | ||
|
||
This route can be used by an application in the cozy of a recipient to remove it | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package contact | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/cozy/cozy-stack/pkg/config/config" | ||
"github.com/cozy/cozy-stack/pkg/consts" | ||
"github.com/cozy/cozy-stack/pkg/couchdb" | ||
"github.com/cozy/cozy-stack/pkg/prefixer" | ||
"github.com/gofrs/uuid/v5" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetAllContacts(t *testing.T) { | ||
config.UseTestFile(t) | ||
instPrefix := prefixer.NewPrefixer(0, "cozy-test", "cozy-test") | ||
t.Cleanup(func() { _ = couchdb.DeleteDB(instPrefix, consts.Contacts) }) | ||
|
||
g := NewGroup() | ||
g.SetID(uuid.Must(uuid.NewV7()).String()) | ||
|
||
gaby := fmt.Sprintf(`{ | ||
"address": [], | ||
"birthday": "", | ||
"birthplace": "", | ||
"company": "", | ||
"cozy": [], | ||
"cozyMetadata": { | ||
"createdAt": "2024-02-13T15:05:58.917Z", | ||
"createdByApp": "Contacts", | ||
"createdByAppVersion": "1.7.0", | ||
"doctypeVersion": 3, | ||
"metadataVersion": 1, | ||
"updatedAt": "2024-02-13T15:06:21.046Z", | ||
"updatedByApps": [ | ||
{ | ||
"date": "2024-02-13T15:06:21.046Z", | ||
"slug": "Contacts", | ||
"version": "1.7.0" | ||
} | ||
] | ||
}, | ||
"displayName": "Gaby", | ||
"email": [], | ||
"fullname": "Gaby", | ||
"gender": "female", | ||
"indexes": { | ||
"byFamilyNameGivenNameEmailCozyUrl": "gaby" | ||
}, | ||
"jobTitle": "", | ||
"metadata": { | ||
"cozy": true, | ||
"version": 1 | ||
}, | ||
"name": { | ||
"givenName": "Gaby" | ||
}, | ||
"note": "", | ||
"phone": [], | ||
"relationships": { | ||
"groups": { | ||
"data": [ | ||
{ | ||
"_id": "%s", | ||
"_type": "io.cozy.contacts.groups" | ||
} | ||
] | ||
} | ||
} | ||
}`, g.ID()) | ||
|
||
doc := couchdb.JSONDoc{Type: consts.Contacts, M: make(map[string]interface{})} | ||
require.NoError(t, json.Unmarshal([]byte(gaby), &doc.M)) | ||
require.NoError(t, couchdb.CreateDoc(instPrefix, &doc)) | ||
|
||
contacts, err := g.GetAllContacts(instPrefix) | ||
require.NoError(t, err) | ||
require.Len(t, contacts, 1) | ||
assert.Equal(t, contacts[0].PrimaryName(), "Gaby") | ||
} |
Oops, something went wrong.