Skip to content

Commit

Permalink
[Fixes #20] add user create function
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Wallschlaeger committed Apr 30, 2024
1 parent b2b0d70 commit 63511a2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
48 changes: 48 additions & 0 deletions geonodectl
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,55 @@ To use this tool you have to set the following environment variables before star
help="username of the new user ...",
)

users_create.add_argument(
"--email",
type=str,
required=True,
dest="email",
help="email of the new user ...",
)

users_create.add_argument(
"--first_name",
type=str,
required=False,
dest="first_name",
help="first_name of the new user ...",
)

users_create.add_argument(
"--last_name",
type=str,
required=False,
dest="last_name",
help="last_name of the new user ...",
)

users_create.add_argument(
"--is_superuser",
action='store_true',
required=False,
dest="is_superuser",
default=False,
help="set to make the new user a superuser ...",
)

users_create.add_argument(
"--is_staff",
action='store_true',
required=False,
dest="is_staff",
default=False,
help="set to make the new user a staff user ...",
)

users_create.add_argument(
"--password",
type=str,
required=False,
dest="password",
help="password of the new user ...",
)

###########################
# UPLOAD ARGUMENT PARSING #
Expand Down
15 changes: 12 additions & 3 deletions geonoderest/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ def get(
def cmd_create(
self,
username: str,
password: Optional[str],
email: str,
first_name: str = "",
last_name: str = "",
is_superuser: bool = False,
is_staff: bool = False,
password: Optional[str] = None,
**kwargs,
):
"""
Expand All @@ -104,13 +106,17 @@ def cmd_create(
email (str): email of the new user
first_name (str): first name of the new user
last_name (str): last name of the new user
is_superuser (bool): if true user will be a superuser
is_staff (bool): if true user will be staff user
"""

obj = self.create(username=username,
password=password,
email=email,
first_name=first_name,
last_name=last_name,
is_superuser=is_superuser,
is_staff=is_staff,
**kwargs)
print_json(obj)

Expand All @@ -121,6 +127,8 @@ def create(
email: str,
first_name: str = "",
last_name: str = "",
is_superuser: bool = False,
is_staff: bool = False,
**kwargs,
) -> Dict:
"""
Expand All @@ -138,10 +146,11 @@ def create(
"email": email,
"first_name": first_name,
"last_name": last_name,
"is_staff": is_staff,
"is_superuser": is_superuser,
}
if password:
if password is not None:
json_content["password"] = password

return self.http_post(
endpoint=self.ENDPOINT_NAME,
params=json_content,
Expand Down

0 comments on commit 63511a2

Please sign in to comment.