Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create user options #51

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/nextcloud/api_wrappers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,30 @@ class User(WithRequester):
API_URL = "/ocs/v1.php/cloud/users"
SUCCESS_CODE = 100

def add_user(self, uid, passwd):
def add_user(self, uid, passwd=None, displayName=None, email=None, groups=None, subadmin=None, quota=None, language=None):
"""
Create a new user on the Nextcloud server

:param uid: str, uid of new user
:param passwd: str, password of new user
:param uid: string, the required username for the new user
:param passwd: string, the password for the new user, leave empty to send welcome mail
:param displayName: string, the display name for the new user
:param email: string, the email for the new user, required if password empty
:param groups: array, the groups for the new user
:param subadmin: array, the groups in which the new user is subadmin
:param quota: string, quota for the new user
:param language: string, language for the new user
:return:
"""
msg = {'userid': uid, 'password': passwd}
msg = {
'userid': uid,
'password': passwd,
'displayName': displayName,
'email': email,
'groups': groups,
'subadmin': subadmin,
'quota': quota,
'language': language
}
return self.requester.post("", msg)

def get_users(self, search=None, limit=None, offset=None):
Expand Down
13 changes: 7 additions & 6 deletions src/nextcloud/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ def __init__(self, endpoint, user, passwd, json_output=False):

self.base_url = endpoint

self.h_get = {"OCS-APIRequest": "true"}
self.h_get = {"OCS-APIRequest": "true",
"Accept": "application/json"}
self.h_post = {"OCS-APIRequest": "true",
"Content-Type": "application/x-www-form-urlencoded"}
"Content-Type": "application/json"}
self.auth_pk = (user, passwd)
self.API_URL = None
self.SUCCESS_CODE = None
Expand All @@ -50,7 +51,7 @@ def get(self, url="", params=None):
@catch_connection_error
def post(self, url="", data=None):
url = self.get_full_url(url)
res = requests.post(url, auth=self.auth_pk, data=data, headers=self.h_post)
res = requests.post(url, auth=self.auth_pk, json=data, headers=self.h_post)
return self.rtn(res)

@catch_connection_error
Expand All @@ -59,19 +60,19 @@ def put_with_timestamp(self, url="", data=None, timestamp=None):
if isinstance(timestamp, (float, int)):
h_post["X-OC-MTIME"] = f"{timestamp:.0f}"
url = self.get_full_url(url)
res = requests.put(url, auth=self.auth_pk, data=data, headers=h_post)
res = requests.put(url, auth=self.auth_pk, json=data, headers=h_post)
return self.rtn(res)

@catch_connection_error
def put(self, url="", data=None):
url = self.get_full_url(url)
res = requests.put(url, auth=self.auth_pk, data=data, headers=self.h_post)
res = requests.put(url, auth=self.auth_pk, json=data, headers=self.h_post)
return self.rtn(res)

@catch_connection_error
def delete(self, url="", data=None):
url = self.get_full_url(url)
res = requests.delete(url, auth=self.auth_pk, data=data, headers=self.h_post)
res = requests.delete(url, auth=self.auth_pk, json=data, headers=self.h_post)
return self.rtn(res)

def get_full_url(self, additional_url=""):
Expand Down