From 99d65529c2d11bb8d6fa589ec44f8f0d03c6edcc Mon Sep 17 00:00:00 2001
From: Michal Konecny <mkonecny@redhat.com>
Date: Oct 30 2023 11:21:20 +0000
Subject: [PATCH 1/2] Fix format and styling issues


Signed-off-by: Michal Konecny <mkonecny@redhat.com>

---

diff --git a/pagure/api/project.py b/pagure/api/project.py
index 6201daf..33d0b6f 100644
--- a/pagure/api/project.py
+++ b/pagure/api/project.py
@@ -1451,7 +1451,10 @@ def api_new_project():
             404, error_code=APIERROR.ENEWPROJECTDISABLED
         )
 
-    if pagure_config["PAGURE_AUTH"] == 'oidc' and flask.g.fas_user.can_create is False:
+    if (
+        pagure_config["PAGURE_AUTH"] == "oidc"
+        and flask.g.fas_user.can_create is False
+    ):
         raise pagure.exceptions.APIError(
             403, error_code=APIERROR.ENEWPROJECTFORBIDDEN
         )
diff --git a/pagure/default_config.py b/pagure/default_config.py
index d6cb960..615293b 100644
--- a/pagure/default_config.py
+++ b/pagure/default_config.py
@@ -65,7 +65,8 @@ ENABLE_NEW_PROJECTS = True
 # When using OIDC auth, users must be in this OIDC group to create new projects
 RESTRICT_CREATE_BY_OIDC_GROUP = None
 
-# When using OIDC auth, users must be a member of RESTRICT_NEW_PROJECTS_BY_OIDC_GROUP and in total
+# When using OIDC auth, users must be a member of
+# RESTRICT_NEW_PROJECTS_BY_OIDC_GROUP and in total
 # this many groups to create new projects
 RESTRICT_CREATE_BY_OIDC_GROUP_COUNT = 0
 
diff --git a/pagure/ui/app.py b/pagure/ui/app.py
index e6eba74..bf4694c 100644
--- a/pagure/ui/app.py
+++ b/pagure/ui/app.py
@@ -1053,10 +1053,16 @@ def new_project():
             description="Creation of new project is not allowed on this \
                 pagure instance",
         )
-    
-    if pagure_config["PAGURE_AUTH"] == 'oidc' and flask.g.fas_user.can_create is False:
-        flask.abort(403,description="You are not allowed to create new projects on this instance")
 
+    if (
+        pagure_config["PAGURE_AUTH"] == "oidc"
+        and flask.g.fas_user.can_create is False
+    ):
+        flask.abort(
+            403,
+            description="You are not allowed to create new projects on this \
+                instance",
+        )
 
     namespaces = pagure_config["ALLOWED_PREFIX"][:]
     if user:
diff --git a/pagure/ui/groups.py b/pagure/ui/groups.py
index c089ec7..e967959 100644
--- a/pagure/ui/groups.py
+++ b/pagure/ui/groups.py
@@ -354,8 +354,15 @@ def add_group():
     if not pagure_config.get("ENABLE_GROUP_MNGT", False):
         flask.abort(404)
 
-    if pagure_config["PAGURE_AUTH"] == 'oidc' and flask.g.fas_user.can_create is False:
-        flask.abort(403,description="You are not allowed to create new groups on this instance")
+    if (
+        pagure_config["PAGURE_AUTH"] == "oidc"
+        and flask.g.fas_user.can_create is False
+    ):
+        flask.abort(
+            403,
+            description="You are not allowed to create new groups on this \
+                instance",
+        )
 
     user = pagure.lib.query.search_user(
         flask.g.session, username=flask.g.fas_user.username
diff --git a/pagure/ui/oidc_login.py b/pagure/ui/oidc_login.py
index f3f37d2..97d8f1c 100644
--- a/pagure/ui/oidc_login.py
+++ b/pagure/ui/oidc_login.py
@@ -60,12 +60,16 @@ def fas_user_from_oidc():
                 pass
 
         oidc_group = pagure_config.get("RESTRICT_CREATE_BY_OIDC_GROUP", None)
-        oidc_group_count = pagure_config.get("RESTRICT_CREATE_BY_OIDC_GROUP_COUNT", 0)
+        oidc_group_count = pagure_config.get(
+            "RESTRICT_CREATE_BY_OIDC_GROUP_COUNT", 0
+        )
         can_create = True
         if oidc_group:
             if oidc_group not in info.get(groups_key, []):
                 can_create = False
-            elif (oidc_group_count != 0) and (len(info.get(groups_key, [])) < oidc_group_count):
+            elif (oidc_group_count != 0) and (
+                len(info.get(groups_key, [])) < oidc_group_count
+            ):
                 can_create = False
 
         # Create the user object

From f9185cd04cd5c6c986c81d118812d22ffdff8e98 Mon Sep 17 00:00:00 2001
From: Michal Konecny <mkonecny@redhat.com>
Date: Oct 30 2023 12:10:07 +0000
Subject: [PATCH 2/2] Fix test_pagure_api_flask tests


Signed-off-by: Michal Konecny <mkonecny@redhat.com>

---

diff --git a/tests/test_pagure_flask_api.py b/tests/test_pagure_flask_api.py
index 50f5223..fd3005e 100644
--- a/tests/test_pagure_flask_api.py
+++ b/tests/test_pagure_flask_api.py
@@ -176,7 +176,7 @@ class PagureFlaskApitests(tests.SimplePagureTest):
         output = self.app.get("/api/0/-/error_codes")
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(len(data), 46)
+        self.assertEqual(len(data), 47)
         self.assertEqual(
             sorted(data.keys()),
             sorted(
@@ -196,6 +196,7 @@ class PagureFlaskApitests(tests.SimplePagureTest):
                     "EISSUENOTALLOWED",
                     "EMODIFYPROJECTNOTALLOWED",
                     "ENEWPROJECTDISABLED",
+                    "ENEWPROJECTFORBIDDEN",
                     "ENOCODE",
                     "ENOCOMMENT",
                     "ENOCOMMIT",

