Skip to content

Commit cbce28b

Browse files
committed
fixed #5 (token removed), #7(whoami) and updated services
1 parent 0b250f8 commit cbce28b

5 files changed

Lines changed: 41 additions & 6 deletions

File tree

.github/workflows/release.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ jobs:
3333

3434
- name: Create Release
3535
uses: ncipollo/release-action@v1.12.0
36-
env:
37-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3836
with:
3937
tag: ${{ env.VERSION}}
4038
name: Version ${{env.VERSION}}

CommuniApi/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __init__(self, communi_server, communi_token, communi_appid):
2727
level=logging.DEBUG)
2828
self.session = requests.Session()
2929
self.session.headers['X-Authorization'] = 'Bearer ' + self.communi_token
30+
self.login()
3031

3132
logging.debug('Instance initialized')
3233

@@ -48,12 +49,26 @@ def login(self):
4849
response = self.session.get(url=url)
4950
if response.status_code == 200:
5051
response_content = json.loads(response.content)
51-
logging.debug("Login with user ID:{} - success".format(response_content['id']))
52+
self.user_id = response_content['id']
53+
logging.debug("Login with user ID:{} - success".format(self.user_id))
5254
return response_content
5355
else:
5456
logging.debug("Login failed with {}".format(response.content))
5557
return False
5658

59+
def who_am_i(self):
60+
""" Method to request user information associated with the logged in user (id stored upon successful login)
61+
This can be used to test if the user is authorized
62+
63+
:return: dict of user OR bool False if not successful
64+
"""
65+
66+
userList = self.getUserList(userId=self.user_id)
67+
if userList == {'_loadStatus': '1', 'vorname': '', 'nachname': ''}:
68+
return False
69+
else:
70+
return self.getUserList(userId=self.user_id)
71+
5772
def getUserList(self, **kwargs):
5873
"""
5974
Method that requests the list of all users from Communi and optionally aplies filter by ID

CommuniApi/communiActions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ def update_group_users_by_services(communi_api, event_services, groupId):
6565
mail = user[0]
6666
name = user[1]
6767
logging.debug('Trying to match {} of user {} for service {}'.format(mail, name, service_name))
68-
69-
if mail in communi_users_ids.keys():
68+
if service_name in ['Begrüßung & Opferzählen', 'Opfer zählen']:
69+
logging.debug('not adding User {} with mail {} because of service name'.format(name, mail))
70+
user_name_text += '\n• {} - nicht im Chat'.format(name)
71+
elif mail in communi_users_ids.keys():
7072
communi_user_id = communi_users_ids[mail]
7173
logging.debug('User {} found in communi'.format(mail))
7274
if new_group or (communi_user_id not in user_group_list):

tests/test_CommuniApi.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ def test_login(self):
5454
result = self.api.login()
5555
self.assertTrue(result)
5656

57+
def test_who_am_i(self):
58+
"""This test overwrites the stored user_id in order to fail who_am_i()
59+
It will restore the original ID and expect a successful response
60+
"""
61+
user_id = self.api.user_id
62+
self.api.user_id = 0
63+
result = self.api.who_am_i()
64+
self.assertFalse(result)
65+
66+
self.api.user_id = user_id
67+
result = self.api.who_am_i()
68+
self.assertIsInstance(result, dict)
69+
self.assertIn('id', result.keys())
70+
self.assertGreaterEqual(result['id'],0)
71+
self.assertGreaterEqual(len(result['vorname']),1)
72+
self.assertGreaterEqual(len(result['nachname']),1)
73+
self.assertIn('mailadresse', result.keys())
74+
self.assertGreaterEqual(len(result['mailadresse']),1)
75+
76+
5777
def test_getUserList(self):
5878
"""
5979
IMPORTANT - This test method and the parameters used depend on the target system!

versions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
VERSION = '1.0.0'
3+
VERSION = '1.0.1'
44

55
if __name__ == '__main__':
66
os.environ['VERSION'] = VERSION

0 commit comments

Comments
 (0)