Skip to content

Commit

Permalink
Fix authentication and improve interactions with the API - Merge #260
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Oct 4, 2019
2 parents 776c523 + e5a3cc4 commit 9bfe2b1
Show file tree
Hide file tree
Showing 23 changed files with 499 additions and 1,820 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -127,3 +127,5 @@ help/
.idea
.coverage
.noseids

modules/isogeo_pysdk/samples/*
60 changes: 30 additions & 30 deletions isogeo.py
Expand Up @@ -66,6 +66,7 @@
IsogeoPlgTools,
SharesParser,
SearchFormManager,
UserInformer
)

# ############################################################################
Expand Down Expand Up @@ -205,11 +206,14 @@ def __init__(self, iface):

# SUBMODULES
# instanciating
self.informer = UserInformer(message_bar = msgBar, trad = self.tr)

self.md_display = MetadataDisplayer()

self.approps_mng = SharesParser()
self.approps_mng.tr = self.tr


self.authenticator = Authenticator()

self.api_requester = ApiRequester()
Expand All @@ -220,7 +224,8 @@ def __init__(self, iface):
self.form_mng.qs_mng.lang = self.lang

# connecting
self.api_requester.token_sig.connect(self.token_slot)
self.api_requester.api_sig.connect(self.token_slot)
self.api_requester.api_sig.connect(self.informer.request_slot)
self.api_requester.search_sig.connect(self.search_slot)
self.api_requester.details_sig.connect(self.md_display.show_complete_md)
self.api_requester.shares_sig.connect(self.approps_mng.send_share_info)
Expand Down Expand Up @@ -356,56 +361,50 @@ def user_authentication(self):
their default value, it asks for them.
If not, it tries to send a request.
"""
self.savedSearch = "first"
self.form_mng.switch_widgets_on_and_off(0)
api_init = self.authenticator.manage_api_initialization()
if api_init[0]:
self.api_requester.setup_api_params(api_init[1])

def write_ids_and_test(self):
"""Store the id & secret and launch the test function.
Called when the authentification window is closed,
it stores the values in the file, then call the
user_authentification function to test them.
"""
self.authenticator.credentials_storer()
# launch authentication
self.user_authentication()
else :
pass

def auth_slot(self, auth_signal: str):
if auth_signal == "ok":
self.user_authentication()
else :
pass

def token_slot(self, token_signal: str):
""" Slot connected to ApiRequester.token_sig signal emitted when a response to
""" Slot connected to ApiRequester.api_sig signal emitted when a response to
a token request has been received from Isogeo's API or when the content of
a response to any type of request can't be parsed. The 'token_sig' parameter
a response to any type of request can't be parsed. The 'api_sig' parameter
correspond to the string passed by ApiRequester.handle_reply method (see
modules/api/request.py). The value of this parameter depend on the response's
content received from Isogeo's API.
:param str token_signal: a string passed by the signal whose value determines
what will be done. Options :
- "tokenOK" : Authentication has succeeded, the token is stored so it sends
- "ok" : Authentication has succeeded, the token is stored so it sends
a search request to the API.
- "credIssue" : User's credentials are wrong so it displays the authentication
- "creds_issue" : User's credentials are wrong so it displays the authentication
form to provide good ones.
- "NoInternet" : Asks to user to check his Internet connection.
"""
logger.debug(token_signal)
if token_signal == "tokenOK":
if token_signal == "ok":
if self.savedSearch == "first":
self.authenticator.ui_auth_form.btn_ok_cancel.buttons()[0].setEnabled(True)
self.authenticator.first_auth = False
logger.debug("First search since plugin started.")
self.set_widget_status()
logger.debug("Asking application properties to the Isogeo API.")
self.api_requester.send_request(request_type="shares")
else:
self.api_requester.send_request()
elif token_signal == "credIssue":
self.authenticator.display_auth_form()

elif token_signal == "creds_issue":
self.authenticator.ui_auth_form.btn_ok_cancel.buttons()[0].setEnabled(False)
else:
msgBar.pushMessage(
self.tr(
"Request to Isogeo failed: please check your Internet connection."
),
duration=10,
level=1,
)
self.pluginIsActive = False

# --- SEARCH --------------------------------------------------------------
Expand Down Expand Up @@ -829,7 +828,8 @@ def run(self):
self.form_mng.btn_report.pressed.connect(
partial(
plg_tools.open_webpage,
link="https://github.com/isogeo/isogeo-plugin-qgis/issues/new?title={}"
link="https://github.com/isogeo/isogeo-plugin-qgis/issues/new?"
"assignees=&template=bug_report.md&title={}"
" - plugin v{} QGIS {} ({})&labels=bug&milestone=4".format(
self.tr("TITLE ISSUE REPORTED"),
plg_tools.plugin_metadata(base_path=plg_basepath),
Expand All @@ -846,10 +846,11 @@ def run(self):
self.form_mng.btn_credits.pressed.connect(self.credits_dialog.show)

# -- Authentication form ----------------------------------------------
self.authenticator.ui_auth_form.btn_check_auth.pressed.connect(
self.write_ids_and_test
self.authenticator.auth_sig.connect(
self.auth_slot
)


""" ------ CUSTOM CONNECTIONS ------------------------------------- """
# get shares only if user switch on tabs
# catch QGIS log messages - see: https://gis.stackexchange.com/a/223965/19817
Expand All @@ -866,7 +867,6 @@ def run(self):
self.form_mng.cbb_chck_kw.setEnabled(plg_tools.test_qgis_style()) # see #137
# self.form_mng.cbb_chck_kw.setMaximumSize(QSize(250, 25))
self.form_mng.txt_input.setFocus()
self.savedSearch = "first"
# load cache file
self.form_mng.results_mng.cache_mng.loader()
# launch authentication
Expand Down
1 change: 1 addition & 0 deletions modules/__init__.py
Expand Up @@ -4,3 +4,4 @@
from .tools import IsogeoPlgTools
from .quick_search import QuickSearchManager
from .search_form import SearchFormManager
from .user_inform import UserInformer

0 comments on commit 9bfe2b1

Please sign in to comment.