Skip to content

Commit ec0ed92

Browse files
committed
Merge pull request #67 from FodT/permissions-fix
Permissions fix
2 parents 0684186 + bafe852 commit ec0ed92

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

terminalone/models/permission.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def _change_access(self, entity_access, id_to_change, add):
4949
raise ClientError('Must be one of {}!'.format(entity_hierarchy))
5050
if add:
5151
if self.properties[entity_access] is None:
52-
self.properties[entity_access] = "placeholder"
53-
self.properties[entity_access][id_to_change] = {}
52+
self.properties[entity_access] = {}
53+
self.properties[entity_access][id_to_change] = "placeholder"
5454
else:
5555
self.properties[entity_access].pop(id_to_change)
5656
depth = entity_hierarchy.index(entity_access)
@@ -86,7 +86,10 @@ def _generate_save_data(self, data=None):
8686
data.pop('organization', None)
8787
data.pop('agency', None)
8888
data.pop('advertiser', None)
89-
data['advertiser_id'] = self.properties['advertiser'].keys()
90-
data['agency_id'] = self.properties['agency'].keys()
91-
data['organization_id'] = self.properties['organization'].keys()
89+
if self.properties['advertiser'] is not None:
90+
data['advertiser_id'] = self.properties['advertiser'].keys()
91+
if self.properties['agency'] is not None:
92+
data['agency_id'] = self.properties['agency'].keys()
93+
if self.properties['organization'] is not None:
94+
data['organization_id'] = self.properties['organization'].keys()
9295
return data

terminalone/models/user.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class User(Entity):
6060
'view_organizations': int,
6161
})
6262
_readonly = Entity._readonly.copy()
63+
_readonly.update({
64+
'last_login_on',
65+
})
6366

6467
def __init__(self, session, properties=None, **kwargs):
6568
super(User, self).__init__(session, properties, **kwargs)

tests/fixtures/permissions_none.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version='1.0' ?>
2+
<result>
3+
<permissions>
4+
<flags>
5+
<access type="edit_data_definition" value="0" />
6+
<access type="view_data_definition" value="1" />
7+
<access type="edit_segments" value="0" />
8+
<access type="edit_campaigns" value="0" />
9+
<access type="access_internal_fees" value="0" />
10+
<access type="edit_margins_and_performance" value="0" />
11+
<access type="view_organizations" value="1" />
12+
<access type="view_segments" value="1" />
13+
<access type="view_dmp_reports" value="1" />
14+
<access type="type" value="INTERNAL" />
15+
<access type="role" value="USER" />
16+
<access type="scope" value="GLOBAL" />
17+
</flags>
18+
</permissions>
19+
<status code="ok" />
20+
<user name="dummyuser" id="10000" type="user" />
21+
</result>

tests/test_permissions.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,19 @@ def test_it_should_add_entity_ids_on_save(self):
135135
p.add('organization', 10)
136136
data = p._generate_save_data()
137137
assert sorted(data['organization_id']) == [1, 2, 10], data['organization_id']
138+
139+
@responses.activate
140+
def test_it_should_add_access_to_empty_permissions(self):
141+
self.setup()
142+
with open('tests/fixtures/permissions_none.xml') as f:
143+
fixture = f.read()
144+
responses.add(responses.GET,
145+
'https://api.mediamath.com/api/v2.0/users/10000/permissions',
146+
body=fixture,
147+
content_type='application/xml',
148+
match_querystring=True)
149+
150+
p = self.t1.get('users', 10000, child='permissions')
151+
p.add('organization', 10)
152+
data = p._generate_save_data()
153+
assert sorted(data['organization_id']) == [10], data['organization_id']

0 commit comments

Comments
 (0)