Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
Merge branch 'fix/stale-role-grants-and-ms-teams-text-formatting' int…
Browse files Browse the repository at this point in the history
…o fix/ms-teams-platform
  • Loading branch information
wallrony committed Sep 19, 2022
2 parents 491f4b3 + 84152a4 commit 8f52214
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 8 additions & 2 deletions plugins/sdm/lib/helper/approve_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ def evaluate(self, request_id, **kwargs):
yield from self.__register_auto_approve_use(grant_request)

def __approve_assign_role(self, grant_request):
yield from self.__grant_temporal_access_by_role(grant_request['sdm_object'].name, grant_request['sdm_account'].id)
self._bot.add_thumbsup_reaction(grant_request['message'])
self._bot.remove_grant_request(grant_request['id'])
try:
yield from self.__grant_temporal_access_by_role(grant_request['sdm_object'].name, grant_request['sdm_account'].id)
except Exception as e:
yield str(e)
return
self._bot.add_thumbsup_reaction(grant_request['message'])
yield from self.__notify_assign_role_request_granted(grant_request['message'], grant_request['sdm_object'].name)
self._bot.get_metrics_helper().increment_manual_approvals()

Expand All @@ -48,6 +52,8 @@ def __grant_temporal_access_by_role(self, role_name, account_id):
granted_resources_via_account = self.__sdm_service.get_granted_resources_via_account(resources, account_id)
granted_resources_via_role = self.__sdm_service.get_granted_resources_via_role(resources, account_id)
granted_resources = self.__remove_duplicated_resources(granted_resources_via_account + granted_resources_via_role)
if len(granted_resources) == len(resources):
raise Exception(f"The user already have access to all resources assigned to the role {role_name}")
if len(granted_resources) > 0:
granted_resources_text = ''
for resource in granted_resources:
Expand Down
9 changes: 8 additions & 1 deletion plugins/sdm/lib/platform/ms_teams_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ def get_user_nick(self, approver):

def clean_up_message(self, text):
unbolded_text = remove_bold_symbols(text)
return re.sub(r'<at>.+</at>', '', unbolded_text).strip()
return self.clean_message_at_symbols(unbolded_text)

def clean_message_at_symbols(self, text):
text_without_bot_mention = self.remove_bot_mention_symbols(text)
return re.sub(r'<at>|</at>', '', text_without_bot_mention).strip()

def remove_bot_mention_symbols(self, text):
return re.sub(r'^<at>[a-zA-Z0-9_ ]+</at>', '', text).strip()

def format_access_request_params(self, resource_name, sender_nick):
return f'**{resource_name}**', f'**{sender_nick}**'
Expand Down

0 comments on commit 8f52214

Please sign in to comment.