Skip to content

Commit

Permalink
Merge pull request #62 from GeoNodeUserGroup-DE/issue_#51_Bug_creatin…
Browse files Browse the repository at this point in the history
…g_user_via_json_content_expects_username

[Fixes #51] Bug: creating user via json_content expects username, also fixes bug when using delete user
  • Loading branch information
mwallschlaeger authored Jun 17, 2024
2 parents d87ea94 + 4814677 commit 165c699
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions geonoderest/users.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
import sys
import logging
from typing import Dict, Optional

from geonoderest.resources import GeonodeResourceHandler
Expand Down Expand Up @@ -157,7 +159,7 @@ def patch(

def cmd_create(
self,
username: str,
username: Optional[str] = None,
email: str = "",
first_name: str = "",
last_name: str = "",
Expand Down Expand Up @@ -208,7 +210,7 @@ def cmd_create(

def create(
self,
username: str,
username: Optional[str] = None,
email: str = "",
first_name: str = "",
last_name: str = "",
Expand All @@ -231,6 +233,10 @@ def create(
json_content (dict) dict object with addition metadata / fields
"""
if json_content is None:
if username is None:
logging.error("missing username for user creation ...")
sys.exit(1)

json_content = {
"username": username,
"email": email,
Expand All @@ -243,3 +249,12 @@ def create(
endpoint=self.ENDPOINT_NAME,
params=json_content,
)

def cmd_delete(self, pk: int, **kwargs):
self.delete(pk=pk, **kwargs)
print(f"{self.JSON_OBJECT_NAME}: {pk} deleted ...")

def delete(self, pk: int, **kwargs):
"""delete geonode resource object"""
self.http_get(endpoint=f"{self.ENDPOINT_NAME}/{pk}")
self.http_delete(endpoint=f"users/{pk}")

0 comments on commit 165c699

Please sign in to comment.