A project owner or admin (with the 'modify_project') acl can ask the creation of a project user token. The token description and acl can be passed to the endpoint.
The endpoint return the token id and the description.
1 new commit added
Attempt to fix wrong code stype
Wouldn't it be better to do /<repo>/token/create or something? createapitoken is a pretty poorly named endpoint...
/<repo>/token/create
createapitoken
Propose a better API endpoint name repo/token/create
Thanks, yes you are right so here is an update.
You could use a wtforms form here to do the validation for you (disable the csrf protection and dynamically load the list of ACLs), there are some examples of this in the code already (let me know if you don't find one)
Let's specify that it's acls=None here :)
acls=None
We should use a list here, saves us the troubles of splitting the content on comas
You may want to use form.getlist('acl') here ;-)
form.getlist('acl')
@fbo if you would have time to update this one it would be nice, this way we could get it into the 5.3-beta I hope to cut tomorrow
Sure, I'll travel tomorrow morning but I'll be able to finish it (and the other PR (hope)) in the train.
Use wtforms to validate a new token in the projects api
I don't think we want the full list here, more likely the USER_ACLS list only
descriptions are not unique, so depending on the ordering you may get an expired token here. Should we make add_token_to_user return the token id instead?
Improve add_token_to_user to return the token
rebased onto 7c5cfacce801976a43080fa0c86fa999ead34e97
Any idea why the CI fails this way ? is it related to the patch ?
pretty please pagure-ci rebuild
rebased onto 969d10ecf6cbe31a380de5b6e65c039ddcaf4cf8
Looks like at least one test is failing (genuinely)
rebased onto fa793fd116352d4495f19364e48a427edbb3b33a
It returns three failing test files:
15:50:35 FAILED test: py-test_pagure_repospanner 15:50:35 FAILED test: py-test_pagure_flask_ui_repo 15:50:35 FAILED test: py-test_pagure_flask_ui_app
The first one currently fails on all tests/PRs (I hope the new way to run the tests will help with this), the other two are more concerning me :(
A local run with the container reports: Failed tests: FAILED test: py3-test_style FAILED test: py3-test_pagure_flask_ui_repo FAILED test: py3-test_pagure_flask_ui_app
Ok so then let me know if the patch needs more edit or if it ready to be merged :)
91 failed :( should I rebase the branch on master ?
rebased onto 0bf7de9bfcaa7885bca3aa5fa34a1f752d920c01
The UI endpoint seems to be //token/new, should we align the API with the UI?
Ok, I've had to apply the following two patches to get this PR to pass tests:
3 new commits added
Align new token API endpoint with UI endpoint
Black8 fixes
Fix the tests
Black seems still unhappy: https://ci.centos.org/job/pagure-pr/2212/artifact/pagure/results_f29-rpms-py3/py3-test_style/view/
This is the change black does locally:
diff --git a/ pagure/api/project.py b/ pagure/api/project.py index 20c6e8af..e947a306 100644 --- a/ pagure/api/project.py +++ b/ pagure/api/project.py @@ -2138,9 +2138,7 @@ def api_modify_project_options(repo, username=None, namespace=None): @API.route("/<repo>/token/new", methods=["POST"]) @API.route("/<namespace>/<repo>/token/new", methods=["POST"]) @API.route("/fork/<username>/<repo>/token/new", methods=["POST"]) -@API.route( - "/fork/<username>/<namespace>/<repo>/token/new", methods=["POST"] -) +@API.route("/fork/<username>/<namespace>/<repo>/token/new", methods=["POST"]) @api_login_required(acls=["modify_project"]) @api_method def api_project_create_api_token(repo, namespace=None, username=None):
Thanks I'll fix that.
Curious, I've run the full test suite locally and black has not complain.
Fix black compliance
The failed test is repospanner which fails for everyone, everything pass, so let's get this in :)
Pull-Request has been merged by pingou
\o/
A project owner or admin (with the 'modify_project') acl can
ask the creation of a project user token. The token
description and acl can be passed to the endpoint.
The endpoint return the token id and the description.