Skip to content

Commit

Permalink
Merge pull request #189 from Remmeauth/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiia-bilova committed Oct 30, 2019
2 parents ae39199 + ec5bcca commit 48c0640
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
15 changes: 15 additions & 0 deletions directory/block_producer/views/block_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ def post(self, request, block_producer_id):
) as error:
return JsonResponse({'error': error.message}, status=HTTPStatus.NOT_FOUND)

block_producer = self.get(request=None, block_producer_id=block_producer_id)

block_producer_name = json.loads(block_producer.content).get('result').get('name')
username = json.loads(block_producer.content).get('result').get('user').get('username')

if request.META.get('HTTP_HOST'): # fixme: if tests, no https host, better to mock
admin_host = f"{request.scheme}://{request.META.get('HTTP_HOST')}"

TelegramBot().notify_block_producer_update(
admin_host=admin_host,
block_producer_id=block_producer_id,
block_producer_name=block_producer_name,
username=username,
)

return JsonResponse({'result': 'Block producer has been updated.'}, status=HTTPStatus.OK)

@authentication_classes((JSONWebTokenAuthentication,))
Expand Down
25 changes: 25 additions & 0 deletions directory/services/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,28 @@ def notify_block_producer_creation(self, admin_host, block_producer_identifier):
message += f'\nTo moderate use following [link]({link_to_moderate}).'

self._send_message_telegram_api(chat_id=subscriber_chat_id, message=message)

def notify_block_producer_update(self, admin_host, block_producer_id, block_producer_name, username):
"""
Notify block producer update.
"""
subscribers = requests.get(f'{self.host}/subscribers/block-producer/creation', headers={
'Content-type': 'application/json',
}).json().get('result')

administrators = requests.get(f'{self.host}/administrators', headers={
'Content-type': 'application/json',
}).json().get('result')

link_to_moderate = f'{admin_host}/admin/block_producer/blockproducer/{block_producer_id}/change/'

for subscriber in subscribers:
message = f'User {username} HAS BEEN UPDATED his block producer with ' \
f'the name {block_producer_name} and identifier {block_producer_id}.'

subscriber_chat_id = subscriber.get('chat_id')

if subscriber in administrators:
message += f'\nTo moderate use following [link]({link_to_moderate}).'

self._send_message_telegram_api(chat_id=subscriber_chat_id, message=message)
6 changes: 3 additions & 3 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
add-trailing-comma==1.4.1
add-trailing-comma==1.5.0
flake8-commas==2.0.0
flake8-comprehensions==2.2.0
flake8-comprehensions==3.0.1
flake8-docstrings==1.5.0
flake8-per-file-ignores==0.8.1
flake8-print==3.1.1
flake8==3.7.8
flake8==3.7.9
isort==4.3.21
pep8-naming==0.8.2
pydocstyle==4.0.1
Expand Down
6 changes: 3 additions & 3 deletions requirements/project.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
boto3==1.9.250
dataclasses-json==0.3.4
boto3==1.10.5
dataclasses-json==0.3.5
dj-database-url==0.5.0
django-admin-multiple-choice-list-filter==0.1.1
django-cors-headers==3.1.1
django==2.2.6
djangorestframework-jwt==1.11.0
djangorestframework==3.10.3
psycopg2==2.8.3
psycopg2==2.8.4
requests==2.22.0
sendgrid==6.1.0
whitenoise==4.1.4
4 changes: 2 additions & 2 deletions requirements/tests.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
coverage==4.5.4
pytest-flask==0.15.0
pytest-mock==1.11.1
pytest==5.2.1
pytest-mock==1.11.2
pytest==5.2.2

0 comments on commit 48c0640

Please sign in to comment.