From 33e214901855fdd9a39ff17bca007e6e297bf0b3 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Tue, 6 Dec 2022 09:11:47 +0100 Subject: [PATCH] feature/ add more feature with api-collections --- README.md | 7 ++++++ .../apicollectionlist/apicollectionlist.html | 10 ++++---- apimanager/apicollectionlist/views.py | 24 +++++++++++++++---- .../templates/apicollections/index.html | 22 ++++++++++++++--- apimanager/apicollections/views.py | 6 ++++- apimanager/apimanager/settings.py | 6 +++-- apimanager/obp/views.py | 8 +++++-- 7 files changed, 66 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 0a34de6..36f81b1 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,13 @@ DATABASE = { "PORT": "5432", } } + +# This is an optional setting. +# CALLBACK_BASE_URL can be used to explicitly set the redirect base url that API Manager uses during OAuth authentication. +# If CALLBACK_BASE_URL is not set, API Manager (this applicaiton) in the function "get_redirect_url" will use the Django HTTP_HOST environ field (see here: https://docs.djangoproject.com/en/4.1/ref/request-response/). Note, this might be modified by NGINX via the directive: proxy_set_header Host $http_host; +# In order to be explicit you can set it here e.g. +# CALLBACK_BASE_URL="https://apimanager.example.com" + ``` diff --git a/apimanager/apicollectionlist/templates/apicollectionlist/apicollectionlist.html b/apimanager/apicollectionlist/templates/apicollectionlist/apicollectionlist.html index d029878..3b7e2ab 100644 --- a/apimanager/apicollectionlist/templates/apicollectionlist/apicollectionlist.html +++ b/apimanager/apicollectionlist/templates/apicollectionlist/apicollectionlist.html @@ -1,7 +1,7 @@ {% extends 'base.html' %} {% load static %} {% load i18n %} {% block page_title %} {{ block.super }} / {% trans "Customer List" %}{% endblock page_title %} {% block content %}
-

{% trans "My API Collection List" %}

+

{% trans "API Collection List" %}

@@ -9,17 +9,17 @@ - + {% for apicollection in apicollections_list %} - {% url 'apicollection_update' apicollection.api_collection_id apicollection.user_id as url_apicollection_update %} + {% url 'my-api-collection-detail' apicollection.api_collection_id as url_collection_detail %} - + - + {% endfor %} diff --git a/apimanager/apicollectionlist/views.py b/apimanager/apicollectionlist/views.py index 2f0182a..fe69d99 100644 --- a/apimanager/apicollectionlist/views.py +++ b/apimanager/apicollectionlist/views.py @@ -23,13 +23,21 @@ class ApiCollectionListView(IndexView, LoginRequiredMixin, FormView ): success_url = '/apicollections/list' def get_apicollections(self, context): + """Get All user """ api = API(self.request.session.get('obp')) try: apicollections_list = [] - urlpath = '/my/api-collections' - result = api.get(urlpath) - if 'api_collections' in result: - apicollections_list.extend(result['api_collections']) + #TODO: NOTE- THIS RETURNS ALL USER. THIS IS A POTENTIAL PERFORMANCE ISSUE. WE NEED ENDPOINT FOR COLLECTION. + #Endpoint will return users. + get_all_users_url_path = '/users' + + user = api.get(get_all_users_url_path) + for i in user["users"]: + # Returns the APIs collections for a user. + api_collections_for_user_url_path = '/users/{}/api-collections'.format(i["user_id"]) + api_collections_for_user = api.get(api_collections_for_user_url_path) + if 'api_collections' in api_collections_for_user: + apicollections_list.extend(api_collections_for_user['api_collections']) except APIError as err: messages.error(self.request, err) return [] @@ -40,8 +48,16 @@ class ApiCollectionListView(IndexView, LoginRequiredMixin, FormView ): return apicollections_list def get_context_data(self, **kwargs): + api = API(self.request.session.get('obp')) context = super(IndexView, self).get_context_data(**kwargs) apicollections_list = self.get_apicollections(context) + try: + for final_collection_list in apicollections_list: + url_path = "/users/user_id/{}".format(final_collection_list["user_id"]) + result = api.get(url_path) + final_collection_list["username"] = result["username"] + except Exception as e: + messages.error(self.request, "Unknown Error {}".format(str(e))) context.update({ 'apicollections_list': apicollections_list, }) diff --git a/apimanager/apicollections/templates/apicollections/index.html b/apimanager/apicollections/templates/apicollections/index.html index 3555a48..0adffdd 100644 --- a/apimanager/apicollections/templates/apicollections/index.html +++ b/apimanager/apicollections/templates/apicollections/index.html @@ -26,7 +26,7 @@ {% if api_collection.api_collection_id %}
@@ -60,14 +60,19 @@
{% endif %} {% if forloop.counter0 == 0 %} -
+
{% endif %} {% if forloop.counter0 > 0 %} -
+ +
@@ -81,5 +86,16 @@ {% block extrajs %} + {% endblock extrajs %} diff --git a/apimanager/apicollections/views.py b/apimanager/apicollections/views.py index 7349283..725bedb 100644 --- a/apimanager/apicollections/views.py +++ b/apimanager/apicollections/views.py @@ -13,7 +13,7 @@ from django.urls import reverse, reverse_lazy from base.utils import exception_handle, error_once_only from .forms import ApiCollectionsForm, ApiCollectionEndpointsForm from django.views.decorators.csrf import csrf_exempt - +from django.conf import settings class IndexView(LoginRequiredMixin, FormView): """Index view for API Collection""" @@ -32,6 +32,8 @@ class IndexView(LoginRequiredMixin, FormView): error_once_only(self.request, response['message']) else: api_collections=response['api_collections'] + for locale in api_collections: + locale["collection_on_api_explorer_url"] = f"{settings.API_EXPLORER}/?api-collection-id={locale['api_collection_id']}" except APIError as err: messages.error(self.request, err) except BaseException as err: @@ -113,6 +115,8 @@ class DeleteCollectionEndpointView(LoginRequiredMixin, FormView): """Deletes api collection endpoint from API""" api = API(self.request.session.get('obp')) try: + get_api_collection_by_Id_url = "/my/api-collections/{}".format(kwargs["api_collection_id"]) + result = api.get(get_api_collection_by_Id_url) urlpath = '/my/api-collections/{}/api-collection-endpoints/{}'.format(kwargs['api_collection_name'],kwargs['operation_id']) result = api.delete(urlpath) if result is not None and 'code' in result and result['code']>=400: diff --git a/apimanager/apimanager/settings.py b/apimanager/apimanager/settings.py index 45e4a3b..3d4bce9 100644 --- a/apimanager/apimanager/settings.py +++ b/apimanager/apimanager/settings.py @@ -253,6 +253,7 @@ API_MANAGER_DATE_FORMAT= '%Y-%m-%d' API_HOST = 'http://127.0.0.1:8080' +API_EXPLORER = 'http://127.0.0.1:8082' # Only override this if you have a separate portal instance API_PORTAL = API_HOST API_BASE_PATH = '/obp/v' @@ -301,13 +302,14 @@ LOGO_URL = 'https://static.openbankproject.com/images/OBP/favicon.png' OVERRIDE_CSS_URL = None VERIFY = True +CALLBACK_BASE_URL = "" -# Local settings can override anything in here +# Local settings can replace any value ABOVE try: from apimanager.local_settings import * # noqa except ImportError: pass -# EVERYTHING BELOW HERE WILL NOT BE OVERWRITTEN BY LOCALSETTINGS! +# EVERYTHING BELOW HERE WILL *NOT* BE OVERWRITTEN BY LOCALSETTINGS! # DO NOT TRY TO DO SO YOU WILL BE IGNORED! # Settings here might use parts overwritten in local settings diff --git a/apimanager/obp/views.py b/apimanager/obp/views.py index 4e7fa73..85f7df0 100644 --- a/apimanager/obp/views.py +++ b/apimanager/obp/views.py @@ -16,6 +16,7 @@ from .api import API, APIError from .authenticator import AuthenticatorError from .forms import DirectLoginForm, GatewayLoginForm from .oauth import OAuthAuthenticator +from django.conf import settings class LoginToDjangoMixin(object): @@ -53,8 +54,11 @@ class OAuthInitiateView(RedirectView): Gets the callback URI to where the user shall be returned after initiation at OAuth server """ - base_url = '{}://{}'.format( - request.scheme, request.environ['HTTP_HOST']) + if settings.CALLBACK_BASE_URL: + base_url = settings.CALLBACK_BASE_URL + else: + base_url = '{}://{}'.format( + request.scheme, request.environ['HTTP_HOST']) uri = base_url + reverse('oauth-authorize') if 'next' in request.GET: uri = '{}?next={}'.format(uri, request.GET['next'])
{% trans "API Collection Id" %}{% trans "User Id" %}{% trans "User Name" %} {% trans "API Collection Name" %} {% trans "More info" %}
{{ apicollection.api_collection_id }}{{ apicollection.user_id }}{{ apicollection.username }} {{ apicollection.api_collection_name }}
@@ -32,7 +32,7 @@
{% trans "View" %}{% trans "View" %}