From 56c8b8b2a783735be859c691ca6c25ed575d73d8 Mon Sep 17 00:00:00 2001 From: Michal Konecny Date: Apr 29 2025 13:37:32 +0000 Subject: Fix for API call with token Recently on staging deployment of src.stg.fedoraproject.org I encountered issue with `AttributeError: 'User' object has no attribute 'can_create'`. After some digging with help from pagure matrix channel and from @abompard I was able to found out that there is a fix for that on src.fedoraproject.org, but it's not documented anywhere. So I'm submitting this PR with the fix. Here is the reasoning behind it. The API doesn't use OIDC authentication, but instead using token, so the `flask.g.fas_user` doesn't contain `can_create` attribute as this one is added during OIDC authentication. This patch is checking if the attribute is present first. --- diff --git a/pagure/api/project.py b/pagure/api/project.py index 80e0f22..02991fd 100644 --- a/pagure/api/project.py +++ b/pagure/api/project.py @@ -1449,6 +1449,7 @@ def api_new_project(): if ( pagure_config["PAGURE_AUTH"] == "oidc" + and hasattr(flask.g.fas_user, "can_create") and flask.g.fas_user.can_create is False ): raise pagure.exceptions.APIError(