Skip to content

Commit 2fa193c

Browse files
fschrempfbensteUEM
authored andcommitted
Implement get_global_permissions() - Fixes #76
1 parent 186518f commit 2fa193c

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

ChurchToolsApi/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,25 @@ def update_group(self, group_id: int, data: dict):
365365
else:
366366
logging.warning("Something went wrong updating group: {}".format(response.status_code))
367367

368+
def get_global_permissions(self) -> dict:
369+
"""
370+
Get global permissions of the current user
371+
:return: dict with module names which contain dicts with individual permissions items
372+
"""
373+
url = self.domain + '/api/permissions/global'
374+
headers = {
375+
'accept': 'application/json'
376+
}
377+
response = self.session.get(url=url, headers=headers)
378+
if response.status_code == 200:
379+
response_content = json.loads(response.content)
380+
response_data = response_content['data'].copy()
381+
logging.debug("First response of Global Permissions successful {}".format(response_content))
382+
383+
return response_data
384+
else:
385+
logging.warning("Something went wrong fetching global permissions: {}".format(response.status_code))
386+
368387
def get_grouptypes(self, **kwargs):
369388
"""
370389
Get list of all grouptypes

ChurchToolsApi/test_ChurchToolsApi.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,21 @@ def test_update_group(self):
234234
group = self.api.get_groups(group_id=test_group_id)
235235
self.assertEqual(group['information']['note'], '')
236236

237+
def test_get_global_permissions(self):
238+
"""
239+
IMPORTANT - This test method and the parameters used depend on the target system!
240+
241+
Checks that the global permissions for the current user can be retrieved
242+
and one core permission and one db permission matches the expected value.
243+
:return:
244+
"""
245+
permissions = self.api.get_global_permissions()
246+
self.assertIn('churchcore',permissions.keys())
247+
self.assertIn('administer settings',permissions['churchcore'].keys())
248+
249+
self.assertFalse(permissions['churchcore']['administer settings'])
250+
self.assertFalse(permissions['churchdb']['view birthdaylist'])
251+
self.assertTrue(permissions['churchwiki']['view'])
237252

238253
def test_file_upload_replace_delete(self):
239254
"""

0 commit comments

Comments
 (0)