Skip to content

Commit a4f1a7f

Browse files
committed
fix: automated user sign-up did not work for DCOR Playground
1 parent cad6b60 commit a4f1a7f

2 files changed

Lines changed: 8 additions & 30 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
0.17.0
22
- BREAKING CHANGE: migrate codebase from PyQt5 to PyQt6
3+
- fix: automated user sign-up did not work for DCOR Playground
34
- enh: detect DCOR maintenance mode
45
- tests: allow to use different DCOR instance for testing
56
- tests: make tests independent of testing user

dcoraid/gui/wizard/__init__.py

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from PyQt6 import uic, QtCore, QtWidgets
77
from PyQt6.QtWidgets import QMessageBox, QWizard
88

9-
from ...api import NoAPIKeyError, APINotFoundError, CKANAPI
9+
from ...api import (
10+
APIAuthorizationError, APINotFoundError, NoAPIKeyError, CKANAPI)
1011

1112

1213
def get_dcor_dev_api_key():
@@ -22,47 +23,23 @@ def get_dcor_dev_api_key():
2223
ssl_verify=True)
2324
try:
2425
api.get_user_dict()
25-
except (NoAPIKeyError, APINotFoundError):
26+
except (APIAuthorizationError, APINotFoundError, NoAPIKeyError):
2627
# create a new user
2728
rstr = str(uuid.uuid4())
2829
pwd = str(uuid.uuid4())[:8]
2930
usr = "dcoraid-{}".format(rstr[:5])
30-
api.post(
31+
user_dict = api.post(
3132
"user_create",
3233
data={"name": usr,
3334
"fullname": "Player {}".format(rstr[:5]),
34-
"email": "{}@dcor-dev.mpl.mpg.de".format(usr),
35+
"email": f"{usr}@dcor-dev.mpl.mpg.de",
3536
"password": pwd,
37+
"with_apitoken": True,
3638
})
37-
# Ask the user to create an access token via the web interface, since
38-
# CKAN does not support API token generation via API:
39-
# https://github.com/ckan/ckan/issues/7836
40-
api_dlg = APITokenRequestDCORDev(parent=None,
41-
user=usr,
42-
password=pwd)
43-
if api_dlg.exec():
44-
api_key = api_dlg.get_api_key()
45-
else:
46-
api_key = ""
39+
api_key = user_dict["token"]
4740
return api_key
4841

4942

50-
class APITokenRequestDCORDev(QtWidgets.QDialog):
51-
def __init__(self, parent, user, password):
52-
super(APITokenRequestDCORDev, self).__init__(parent)
53-
ref_ui = resources.files("dcoraid.gui.wizard") / "dcordevapi.ui"
54-
with resources.as_file(ref_ui) as path_ui:
55-
uic.loadUi(path_ui, self)
56-
57-
self.label_user.setText(user)
58-
url = f"https://dcor-dev.mpl.mpg.de/user/{user}/api-tokens"
59-
self.label_url.setText(f"<a href='{url}'>{url}</a>")
60-
self.label_password.setText(password)
61-
62-
def get_api_key(self):
63-
return self.lineEdit_token.text().strip()
64-
65-
6643
class SetupWizard(QtWidgets.QWizard):
6744
"""DCOR-Aid setup wizard"""
6845

0 commit comments

Comments
 (0)