66from PyQt6 import uic , QtCore , QtWidgets
77from PyQt6 .QtWidgets import QMessageBox , QWizard
88
9- from ...api import NoAPIKeyError , APINotFoundError , CKANAPI
9+ from ...api import (
10+ APIAuthorizationError , APINotFoundError , NoAPIKeyError , CKANAPI )
1011
1112
1213def 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-
6643class SetupWizard (QtWidgets .QWizard ):
6744 """DCOR-Aid setup wizard"""
6845
0 commit comments