Skip to content

Commit

Permalink
https://github.com/OpenBankProject/API-Manager/pull/67
Browse files Browse the repository at this point in the history
user None exception in users\views
  • Loading branch information
PengfeiLi0218 committed Jan 29, 2019
1 parent e349d64 commit 179bb51
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
4 changes: 2 additions & 2 deletions apimanager/obp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def call(self, method='GET', url='', payload=None):
time_start = time.time()
try:
if payload:
response = session.request(method, url, json=payload)
response = session.request(method, url, json=payload, verify=False)
else:
response = session.request(method, url)
response = session.request(method, url, verify=False)
except ConnectionError as err:
raise APIError(err)
time_end = time.time()
Expand Down
2 changes: 1 addition & 1 deletion apimanager/obp/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_authorization_url(self, callback_uri):
)
try:
url = settings.API_HOST + settings.OAUTH_TOKEN_PATH
response = session.fetch_request_token(url)
response = session.fetch_request_token(url, verify=False)
except (ValueError, TokenRequestDenied, ConnectionError) as err:
raise AuthenticatorError(err)
else:
Expand Down
31 changes: 29 additions & 2 deletions apimanager/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def get_users_rolenames(self, context):
except APIError as err:
messages.error(self.request, err)
return [], []
except:
messages.error(self.request, "Unknown Error")
return [], []

role_names = []
try:
Expand All @@ -66,6 +69,9 @@ def get_users_rolenames(self, context):
except KeyError as err:
messages.error(self.request, 'KeyError: {}'.format(err))
return [], []
except:
messages.error(self.request, "Unknown Error")
return [], []

role_names = list(set(role_names))
role_names.sort()
Expand Down Expand Up @@ -93,10 +99,15 @@ def get_context_data(self, **kwargs):
users = api.get(urlpath)
except APIError as err:
messages.error(self.request, err)
except:
messages.error(self.request, 'Unknown Error')

role_names = self.get_users_rolenames(context)
users = FilterRoleName(context, self.request.GET) \
.apply([users] if username else users['users'])
try:
users = FilterRoleName(context, self.request.GET) \
.apply([users] if username else users['users'])
except:
users = []
context.update({
'role_names': role_names,
'statistics': {
Expand Down Expand Up @@ -124,6 +135,8 @@ def get_form(self, *args, **kwargs):
form.fields['bank_id'].choices = self.api.get_bank_id_choices()
except APIError as err:
messages.error(self.request, err)
except:
messages.error(self.request, 'Unknown Error')
return form

def form_valid(self, form):
Expand All @@ -139,6 +152,9 @@ def form_valid(self, form):
except APIError as err:
messages.error(self.request, err)
return super(DetailView, self).form_invalid(form)
except:
messages.error(self.request, 'Unknown Error')
return super(DetailView, self).form_invalid(form)

msg = 'Entitlement with role {} has been added.'.format(
entitlement['role_name'])
Expand All @@ -157,6 +173,8 @@ def get_context_data(self, **kwargs):
context['form'].fields['user_id'].initial = user['user_id']
except APIError as err:
messages.error(self.request, err)
except:
messages.error(self.request, 'Unknown Error')

context.update({
'apiuser': user, # 'user' is logged-in user in template context
Expand All @@ -179,6 +197,8 @@ def get_form(self, *args, **kwargs):
form.fields['bank_id'].choices = self.api.get_bank_id_choices()
except APIError as err:
messages.error(self.request, err)
except:
messages.error(self.request, 'Unknown Error')
return form

def form_valid(self, form):
Expand All @@ -194,6 +214,9 @@ def form_valid(self, form):
except APIError as err:
messages.error(self.request, err)
return super(MyDetailView, self).form_invalid(form)
except:
messages.error(self.request, 'Unknown Error')
return super(MyDetailView, self).form_invalid(form)

msg = 'Entitlement with role {} has been added.'.format(
entitlement['role_name'])
Expand All @@ -212,6 +235,8 @@ def get_context_data(self, **kwargs):
context['form'].fields['user_id'].initial = user['user_id']
except APIError as err:
messages.error(self.request, err)
except:
messages.error(self.request, 'Unknown Error')

context.update({
'apiuser': user, # 'user' is logged-in user in template context
Expand All @@ -234,6 +259,8 @@ def post(self, request, *args, **kwargs):
messages.success(request, msg)
except APIError as err:
messages.error(request, err)
except:
messages.error(self.request, 'Unknown Error')

redirect_url = request.POST.get('next', reverse('users-index'))
return HttpResponseRedirect(redirect_url)

0 comments on commit 179bb51

Please sign in to comment.