-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow sharing of investigations (#3865)
* Revert "Disables the user lookup endpoint" This reverts commit d827e03. * Revert "Remove user lookup from investigation sharing screen" This reverts commit f9c0819. * Require full email address to share investigation with individual users * Increase minimum parameter length for suggest endpoint As suggested by @stchris
- Loading branch information
1 parent
88c3216
commit 2c03781
Showing
7 changed files
with
212 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
from aleph.tests.util import TestCase | ||
from aleph.logic.roles import create_group | ||
|
||
|
||
class PermissionsApiTestCase(TestCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.role, self.headers = self.login( | ||
foreign_id="john", | ||
name="John Doe", | ||
email="[email protected]", | ||
) | ||
self.col = self.create_collection(creator=self.role) | ||
|
||
def test_update(self): | ||
jane = self.create_user( | ||
foreign_id="jane", | ||
name="Jane Doe", | ||
email="[email protected]", | ||
) | ||
|
||
url = f"/api/2/collections/{self.col.id}/permissions" | ||
res = self.client.get(url, headers=self.headers) | ||
assert len(res.json["results"]) == 1 | ||
assert res.json["results"][0]["role"]["id"] == str(self.role.id) | ||
|
||
# Granting a new user access without providing their full email address is ignored | ||
data = [ | ||
{"role_id": str(self.role.id), "read": True, "write": True}, | ||
{"role_id": str(jane.id), "read": True, "write": False}, | ||
] | ||
res = self.client.put(url, headers=self.headers, json=data) | ||
assert res.status_code == 200 | ||
assert len(res.json["results"]) == 1 | ||
assert res.json["results"][0]["role"]["id"] == str(self.role.id) | ||
|
||
# Granting a new user accces with an incorrect email address is ignored | ||
data = [ | ||
{ | ||
"role_id": str(self.role.id), | ||
"read": True, | ||
"write": True, | ||
}, | ||
{ | ||
"role_id": str(jane.id), | ||
"email": "[email protected]", | ||
"read": True, | ||
"write": False, | ||
}, | ||
] | ||
res = self.client.put(url, headers=self.headers, json=data) | ||
assert res.status_code == 200 | ||
assert len(res.json["results"]) == 1 | ||
assert res.json["results"][0]["role"]["id"] == str(self.role.id) | ||
|
||
# Granting a new user access updates permissions if full email address is provided | ||
data = [ | ||
{ | ||
"role_id": str(self.role.id), | ||
"read": True, | ||
"write": False, | ||
}, | ||
{ | ||
"role_id": str(jane.id), | ||
"email": "[email protected]", | ||
"read": True, | ||
"write": False, | ||
}, | ||
] | ||
res = self.client.put(url, headers=self.headers, json=data) | ||
assert res.status_code == 200 | ||
assert len(res.json["results"]) == 2 | ||
assert res.json["results"][0]["role"]["id"] == str(self.role.id) | ||
assert res.json["results"][1]["role"]["id"] == str(jane.id) | ||
assert res.json["results"][1]["read"] is True | ||
assert res.json["results"][1]["write"] is False | ||
|
||
def test_update_groups(self): | ||
group = create_group("group") | ||
|
||
url = f"/api/2/collections/{self.col.id}/permissions" | ||
res = self.client.get(url, headers=self.headers) | ||
assert len(res.json["results"]) == 1 | ||
assert res.json["results"][0]["role"]["id"] == str(self.role.id) | ||
|
||
# Updated permissions for a group the user is not a member of are ignored | ||
data = [ | ||
{"role_id": str(self.role.id), "read": True, "write": True}, | ||
{"role_id": str(group.id), "read": True, "write": False}, | ||
] | ||
res = self.client.put(url, headers=self.headers, json=data) | ||
assert res.status_code == 200 | ||
assert len(res.json["results"]) == 1 | ||
assert res.json["results"][0]["role"]["id"] == str(self.role.id) | ||
|
||
self.role.add_role(group) | ||
res = self.client.put(url, headers=self.headers, json=data) | ||
assert res.status_code == 200 | ||
assert len(res.json["results"]) == 2 | ||
assert res.json["results"][0]["role"]["id"] == str(self.role.id) | ||
assert res.json["results"][1]["role"]["id"] == str(group.id) | ||
assert res.json["results"][1]["read"] is True | ||
assert res.json["results"][1]["write"] is False |
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 |
---|---|---|
|
@@ -17,10 +17,55 @@ def setUp(self): | |
def test_suggest(self): | ||
res = self.client.get("/api/2/roles/_suggest") | ||
assert res.status_code == 403, res | ||
_, headers = self.login(is_admin=True) | ||
res = self.client.get("/api/2/roles/_suggest?prefix=user", headers=headers) | ||
assert res.status_code == 200, res | ||
assert res.json["total"] == 0, res.json | ||
|
||
_, headers = self.login(foreign_id="jane", email="[email protected]") | ||
john, _ = self.login(foreign_id="john", email="[email protected]") | ||
|
||
res = self.client.get( | ||
"/api/2/roles/_suggest", | ||
headers=headers, | ||
) | ||
assert res.status_code == 200 | ||
assert res.json["total"] == 0 | ||
assert res.json["results"] == [] | ||
|
||
res = self.client.get( | ||
"/api/2/roles/_suggest", | ||
query_string={"prefix": "john"}, | ||
headers=headers, | ||
) | ||
assert res.status_code == 200 | ||
assert res.json["total"] == 0 | ||
assert res.json["results"] == [] | ||
|
||
res = self.client.get( | ||
"/api/2/roles/_suggest", | ||
query_string={"prefix": "[email protected]"}, | ||
headers=headers, | ||
) | ||
assert res.status_code == 200 | ||
assert res.json["total"] == 1 | ||
assert len(res.json["results"]) == 1 | ||
assert res.json["results"][0]["id"] == str(john.id) | ||
|
||
res = self.client.get( | ||
"/api/2/roles/_suggest", | ||
query_string={"prefix": "[email protected]"}, | ||
headers=headers, | ||
) | ||
assert res.status_code == 200 | ||
assert res.json["total"] == 1 | ||
assert len(res.json["results"]) == 1 | ||
assert res.json["results"][0]["id"] == str(john.id) | ||
|
||
res = self.client.get( | ||
"/api/2/roles/_suggest", | ||
query_string={"prefix": "[email protected]", "exclude:id": john.id}, | ||
headers=headers, | ||
) | ||
assert res.status_code == 200 | ||
assert res.json["total"] == 0 | ||
assert len(res.json["results"]) == 0 | ||
|
||
def test_view(self): | ||
res = self.client.get("/api/2/roles/%s" % self.rolex) | ||
|
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