Skip to content

Commit cfc3d0f

Browse files
authored
Merge pull request #64 from dynata/dev
User Management SDKs
2 parents f0c3b40 + 0a831f4 commit cfc3d0f

18 files changed

+376
-1
lines changed

dynatademand/api.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,44 @@ def get_project_detailed_report(self, project_id):
291291
)
292292
return self._api_get('/projects/{}/detailedReport'.format(project_id))
293293

294+
def get_user_info(self):
295+
return self._api_get('/user')
296+
297+
def get_company_users(self):
298+
return self._api_get('/users')
299+
300+
def get_company_teams(self):
301+
return self._api_get('/teams')
302+
303+
def get_roles(self, **kwargs):
304+
self.validator.validate_request(
305+
'get_roles',
306+
query_params=kwargs
307+
)
308+
return self._api_get('/roles', kwargs)
309+
310+
def get_project_permissions(self, project_id):
311+
self.validator.validate_request(
312+
'get_project_permissions',
313+
path_data={'extProjectId': '{}'.format(project_id)},
314+
)
315+
return self._api_get('/projects/{}/permissions'.format(project_id))
316+
317+
def upsert_project_permissions(self, project_id, upsert_permissions_data):
318+
self.validator.validate_request(
319+
'upsert_project_permissions',
320+
path_data={'extProjectId': '{}'.format(project_id)},
321+
request_body=upsert_permissions_data,
322+
)
323+
response_data = self._api_post('/projects/{}/permissions'.format(project_id), upsert_permissions_data)
324+
if response_data.get('status').get('message') != 'success':
325+
raise DemandAPIError(
326+
"Could not upsert project permissions. Demand API responded with: {}".format(
327+
response_data
328+
)
329+
)
330+
return response_data
331+
294332
def add_line_item(self, project_id, lineitem_data):
295333
'''
296334
A line item is a project entity that exist for a specific market and
@@ -524,7 +562,7 @@ def delete_template(self, id):
524562
self.validator.validate_request(
525563
'delete_template',
526564
path_data={'id': '{}'.format(id)},
527-
)
565+
)
528566
return self._api_delete('/templates/quotaplan/{}'.format(id))
529567

530568
def get_templates(self, country, lang, **kwargs):
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"users": {
5+
"type": "array",
6+
"items": {
7+
"type": "object",
8+
"properties": {
9+
"id": {
10+
"type": "integer"
11+
},
12+
"role": {
13+
"type": "string"
14+
}
15+
}
16+
}
17+
},
18+
"teams": {
19+
"type": "array",
20+
"items": {
21+
"type": "object",
22+
"properties": {
23+
"id": {
24+
"type": "integer"
25+
}
26+
}
27+
}
28+
}
29+
}
30+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"extProjectId": {
5+
"type": "string",
6+
"required": true
7+
}
8+
},
9+
"required": [
10+
"extProjectId"
11+
]
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"extProjectId": {
5+
"type": "string",
6+
"required": true
7+
}
8+
},
9+
"required": [
10+
"extProjectId"
11+
]
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"name": {
5+
"type": "string",
6+
"description": "This is the name of the role. eg: manager"
7+
},
8+
"id": {
9+
"type": "array",
10+
"items": {
11+
"type": "string"
12+
}
13+
}
14+
},
15+
"required": []
16+
}

dynatademand/validator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
'buy_project': ['path', 'body', ],
1818
'get_project_detailed_report': ['path', ],
1919
'reconcile_project': ['path', ],
20+
'get_project_permissions': ['path', ],
21+
'upsert_project_permissions': ['path', 'body', ],
22+
23+
# Roles
24+
'get_roles': ['query', ],
2025

2126
# Invoices
2227
'get_invoice': ['path', ],

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pytest = "4.6.6"
1818
jsonschema = "3.2.0"
1919
pytest-runner = "5.2"
2020
flake8 = "^3.7.9"
21+
pyrsistent = "0.14.11"
2122

2223
[build-system]
2324
requires = ["poetry>=0.12"]

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
responses>=0.10.0
2+
jsonschema>=2.5.0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"email": "samplifyweb@dynata.com",
4+
"id": 71,
5+
"name": "Bears Beets",
6+
"userName": "battlestargalactica"
7+
},
8+
{
9+
"email": "samplify@dynata.com",
10+
"id": 102,
11+
"name": "Michael Scott",
12+
"userName": "papercompany"
13+
}
14+
]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"currentUser": {
3+
"roles": [
4+
"PROJECT_MANAGER"
5+
]
6+
},
7+
"extProjectId": "1910a9fe-59de-4796-aac6-8b7356a7d340",
8+
"teams": [
9+
{
10+
"id": 139,
11+
"name": "All Users"
12+
}
13+
],
14+
"users": [
15+
{
16+
"id": 71,
17+
"role": "PROJECT_MANAGER",
18+
"username": "samplifyweb"
19+
}
20+
]
21+
}

0 commit comments

Comments
 (0)