Browse Source

Fix API to allow returning user list with the master user

master
Inex Code 2 months ago
parent
commit
1ac5f72433
  1. 2
      selfprivacy_api/app.py
  2. 2
      selfprivacy_api/resources/api_auth/app_tokens.py
  3. 2
      selfprivacy_api/resources/common.py
  4. 12
      selfprivacy_api/resources/users.py
  5. 2
      setup.py
  6. 19
      tests/test_users.py

2
selfprivacy_api/app.py

@ -68,7 +68,7 @@ def create_app(test_config=None):
def spec():
if app.config["ENABLE_SWAGGER"] == "1":
swag = swagger(app)
swag["info"]["version"] = "1.2.4"
swag["info"]["version"] = "1.2.5"
swag["info"]["title"] = "SelfPrivacy API"
swag["info"]["description"] = "SelfPrivacy API"
swag["securityDefinitions"] = {

2
selfprivacy_api/resources/api_auth/app_tokens.py

@ -64,7 +64,7 @@ class Tokens(Resource):
schema:
type: object
properties:
token:
token_name:
type: string
description: Token name to delete
required: true

2
selfprivacy_api/resources/common.py

@ -23,4 +23,4 @@ class ApiVersion(Resource):
401:
description: Unauthorized
"""
return {"version": "1.2.4"}
return {"version": "1.2.5"}

12
selfprivacy_api/resources/users.py

@ -24,8 +24,15 @@ class Users(Resource):
401:
description: Unauthorized
"""
parser = reqparse.RequestParser(bundle_errors=True)
parser.add_argument("withMainUser", type=bool, required=False)
args = parser.parse_args()
with_main_user = False if args["withMainUser"] is None else args["withMainUser"]
with ReadUserData() as data:
users = []
if with_main_user:
users.append(data["username"])
if "users" in data:
for user in data["users"]:
users.append(user["username"])
@ -96,7 +103,10 @@ class Users(Resource):
if "users" not in data:
data["users"] = []
# Return 400 if user already exists
# Return 409 if user already exists
if data["username"] == args["username"]:
return {"error": "User already exists"}, 409
for user in data["users"]:
if user["username"] == args["username"]:
return {"error": "User already exists"}, 409

2
setup.py

@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(
name="selfprivacy_api",
version="1.2.3",
version="1.2.5",
packages=find_packages(),
scripts=[
"selfprivacy_api/app.py",

19
tests/test_users.py

@ -130,12 +130,24 @@ def test_get_one_user(authorized_client, one_user, mock_subprocess_popen):
assert response.json == ["user1"]
def test_get_one_user_with_main(authorized_client, one_user, mock_subprocess_popen):
response = authorized_client.get("/users?withMainUser=true")
assert response.status_code == 200
assert response.json == ["tester", "user1"]
def test_get_no_users(authorized_client, no_users, mock_subprocess_popen):
response = authorized_client.get("/users")
assert response.status_code == 200
assert response.json == []
def test_get_no_users_with_main(authorized_client, no_users, mock_subprocess_popen):
response = authorized_client.get("/users?withMainUser=true")
assert response.status_code == 200
assert response.json == ["tester"]
def test_get_undefined_users(
authorized_client, undefined_settings, mock_subprocess_popen
):
@ -199,6 +211,13 @@ def test_post_existing_user(authorized_client, one_user, mock_subprocess_popen):
assert response.status_code == 409
def test_post_existing_main_user(authorized_client, one_user, mock_subprocess_popen):
response = authorized_client.post(
"/users", json={"username": "tester", "password": "password"}
)
assert response.status_code == 409
def test_post_user_to_undefined_users(
authorized_client, undefined_settings, mock_subprocess_popen
):

Loading…
Cancel
Save