Skip to content

Commit

Permalink
Add admin functionality to API (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
onuratakan authored Jan 29, 2024
1 parent 3061696 commit 2e61947
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
27 changes: 27 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,33 @@ def my_function():




def test_add_admin(self):
id = "test_add_admin"
id_admin = "test_add_admin_admin"
the_admin_access_key = AccessKey(id_admin)
the_admin_access_key.enable()
the_admin_access_key.set_is_admin(True)


# Testing to access get_admins_url and expected to get 403
response = requests.get("http://localhost:7777"+get_admins_url, auth=HTTPBasicAuth("", id), )
self.assertEqual(response.status_code, 403)


# Adding the id as user with add_admin_url endpoint
data = {"key": id}
response = requests.post("http://localhost:7777"+add_admin_url, auth=HTTPBasicAuth("", id_admin), data=data)



# Testing to access get_admins_url and expected to get 200
response = requests.get("http://localhost:7777"+get_admins_url, auth=HTTPBasicAuth("", id), )
self.assertEqual(response.status_code, 200)




backup = sys.argv
sys.argv = [sys.argv[0]]
unittest.main(exit=False)
Expand Down
18 changes: 18 additions & 0 deletions upsonic_on_prem/api/operations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,21 @@
@app.route(get_admins_url, methods=["get"])
def get_admins():
return jsonify(AccessKey.get_admins())






@app.route(add_admin_url, methods=["POST"])
def add_admin():
key = request.form.get("key")

user = AccessKey(key)
user.enable()

user.set_is_admin(True)

return jsonify(True)


4 changes: 3 additions & 1 deletion upsonic_on_prem/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
dump_url = "/dump"
load_url = "/load"

get_admins_url = "/get_admins"
get_admins_url = "/get_admins"

add_admin_url = "/add_admin"

0 comments on commit 2e61947

Please sign in to comment.