diff --git a/pagure/api/project.py b/pagure/api/project.py index ae37788..9c8fef0 100644 --- a/pagure/api/project.py +++ b/pagure/api/project.py @@ -361,6 +361,14 @@ def api_new_project(): | | | | added to the project on | | | | | creation. | +------------------+---------+--------------+---------------------------+ + | ``private`` | boolean | Optional | | A boolean to specify if | + | | | | the project to create | + | | | | is private. | + | | | | Note: not all pagure | + | | | | instance support private| + | | | | projects, confirm this | + | | | | with your administrators| + +------------------+---------+--------------+---------------------------+ Sample response ^^^^^^^^^^^^^^^ @@ -396,12 +404,17 @@ def api_new_project(): if namespace: namespace = namespace.strip() + private = False + if pagure.APP.config.get('PRIVATE_PROJECTS', False): + private = form.private.data + try: message = pagure.lib.new_project( SESSION, name=name, namespace=namespace, description=description, + private=private, url=url, avatar_email=avatar_email, user=flask.g.fas_user.username, diff --git a/tests/test_pagure_flask_api_project.py b/tests/test_pagure_flask_api_project.py index 70016f6..46e5b40 100644 --- a/tests/test_pagure_flask_api_project.py +++ b/tests/test_pagure_flask_api_project.py @@ -622,6 +622,36 @@ class PagureFlaskApiProjecttests(tests.Modeltests): {'message': 'Project "test_42" created'} ) + @patch.dict('pagure.APP.config', {'PRIVATE_PROJECTS': True}) + @patch('pagure.lib.git.generate_gitolite_acls') + def test_api_new_project_private(self, p_gga): + """ Test the api_new_project method of the flask api to create + a private project. """ + p_gga.return_value = True + + tests.create_projects(self.session) + tests.create_projects_git(os.path.join(self.path, 'tickets')) + tests.create_tokens(self.session) + tests.create_tokens_acl(self.session) + + headers = {'Authorization': 'token aaabbbcccddd'} + + data = { + 'name': 'test', + 'description': 'Just a small test project', + 'private': True, + } + + # Valid request + output = self.app.post( + '/api/0/new/', data=data, headers=headers) + self.assertEqual(output.status_code, 200) + data = json.loads(output.data) + self.assertDictEqual( + data, + {'message': 'Project "pingou/test" created'} + ) + @patch('pagure.lib.git.generate_gitolite_acls') def test_api_new_project_user_token(self, p_gga): """ Test the api_new_project method of the flask api. """