Passed
Pull Request — master (#14)
by
unknown
01:52
created

NextCloud.GroupFolders.create_group_folder()   A

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
import enum
2
import requests
3
4
PUBLIC_API_NAME_CLASS_MAP = dict()
5
6
7
class Requester(object):
8
    def __init__(self, endpoint, user, passwd, js=False):
9
        self.query_components = []
10
11
        self.to_json = js
12
13
        self.base_url = endpoint
14
        # GroupFolders.url = endpoint + "/ocs/v2.php/apps/groupfolders/folders"
15
16
        self.h_get = {"OCS-APIRequest": "true"}
17
        self.h_post = {"OCS-APIRequest": "true",
18
                       "Content-Type": "application/x-www-form-urlencoded"}
19
        self.auth_pk = (user, passwd)
20
        self.API_URL = None
21
22
    def rtn(self, resp):
23
        if self.to_json:
24
            return resp.json()
25
        else:
26
            return resp.content.decode("UTF-8")
27
28
    def get(self, url="", params=None):
29
        url = self.get_full_url(url)
30
        res = requests.get(url, auth=self.auth_pk, headers=self.h_get, params=params)
31
        return self.rtn(res)
32
33
    def post(self, url="", data=None):
34
        url = self.get_full_url(url)
35
        res = requests.post(url, auth=self.auth_pk, data=data, headers=self.h_post)
36
        return self.rtn(res)
37
38
    def put(self, url="", data=None):
39
        url = self.get_full_url(url)
40
        res = requests.put(url, auth=self.auth_pk, data=data, headers=self.h_post)
41
        return self.rtn(res)
42
43
    def delete(self, url="", data=None):
44
        url = self.get_full_url(url)
45
        res = requests.delete(url, auth=self.auth_pk, data=data, headers=self.h_post)
46
        return self.rtn(res)
47
48
    def get_full_url(self, additional_url=""):
49
        """
50
        Build full url for request to NextCloud api
51
52
        Construct url from self.base_url, self.API_URL, additional_url (if given), add format=json param if self.json
53
54
        :param additional_url: str
55
            add to url after api_url
56
        :return: str
57
        """
58
        if additional_url and not str(additional_url).startswith("/"):
59
            additional_url = "/{}".format(additional_url)
60
61
        if self.to_json:
62
            self.query_components.append("format=json")
63
64
        ret = "{base_url}{api_url}{additional_url}".format(
65
            base_url=self.base_url, api_url=self.API_URL, additional_url=additional_url)
66
67
        if self.to_json:
68
            ret += "?format=json"
69
        return ret
70
71
72
def nextcloud_method(method_to_wrap):
73
    class_name = method_to_wrap.__qualname__.split(".", 1)[0]
74
    PUBLIC_API_NAME_CLASS_MAP[method_to_wrap.__name__] = class_name
75
    return method_to_wrap
76
77
78
class NextCloud(object):
79
80
    def __init__(self, endpoint, user, password, js=False):
81
        self.query_components = []
82
83
        requester = Requester(endpoint, user, password, js)
84
85
        self.functionality = {
86
            "Apps": Apps(requester),
87
            "Group": Group(requester),
88
            "GroupFolders": GroupFolders(requester),
89
            "Share": Share(requester),
90
            "User": User(requester),
91
            "FederatedCloudShare": FederatedCloudShare(requester),
92
            "Activity": Activity(requester),
93
            "Notifications": Notifications(requester),
94
            "UserLDAP": UserLDAP(requester),
95
            "Capabilities": Capabilities(requester),
96
        }
97
        for name, location in PUBLIC_API_NAME_CLASS_MAP.items():
98
            setattr(self, name, getattr(self.functionality[location], name))
99
100
101
class WithRequester(object):
102
103
    API_URL = NotImplementedError
104
105
    def __init__(self, requester):
106
        self._requester = requester
107
108
    @property
109
    def requester(self):
110
        """ Get requester instance """
111
        # dynamically set API_URL for requester
112
        self._requester.API_URL = self.API_URL
113
        return self._requester
114
115
116
class Capabilities(WithRequester):
117
    API_URL = "/ocs/v1.php/cloud/capabilities"
118
119
    @nextcloud_method
120
    def get_capabilities(self):
121
        """ Obtain capabilities provided by the Nextcloud server and its apps """
122
        return self.requester.get()
123
124
125
class GroupFolders(WithRequester):
126
    API_URL = "/apps/groupfolders/folders"
127
128
    @nextcloud_method
129
    def get_group_folders(self):
130
        """
131
        Return a list of call configured folders and their settings
132
133
        Returns:
134
135
        """
136
        return self.requester.get()
137
138
    @nextcloud_method
139
    def get_group_folder(self, fid):
140
        """
141
        Return a specific configured folder and it's settings
142
143
        Args:
144
            fid (int/str): group folder id
145
146
        Returns:
147
148
        """
149
        return self.requester.get(fid)
150
151
    @nextcloud_method
152
    def create_group_folder(self, mountpoint):
153
        """
154
        Create a new group folder
155
156
        Args:
157
            mountpoint (str): name for the new folder
158
159
        Returns:
160
161
        """
162
        return self.requester.post(data={"mountpoint": mountpoint})
163
164
    @nextcloud_method
165
    def delete_group_folder(self, fid):
166
        """
167
        Delete a group folder
168
169
        Args:
170
            fid (int/str): group folder id
171
172
        Returns:
173
174
        """
175
        return self.requester.delete(fid)
176
177
    @nextcloud_method
178
    def grant_access_to_group_folder(self, fid, gid):
179
        """
180
        Give a group access to a folder
181
182
        Args:
183
            fid (int/str): group folder id
184
            gid (str): group to share with id
185
186
        Returns:
187
188
        """
189
        url = "/".join([str(fid), "groups"])
190
        return self.requester.post(url, data={"group": gid})
191
192
    @nextcloud_method
193
    def revoke_access_to_group_folder(self, fid, gid):
194
        """
195
        Remove access from a group to a folder
196
197
        Args:
198
            fid (int/str): group folder id
199
            gid (str): group id
200
201
        Returns:
202
203
        """
204
        url = "/".join([str(fid), "groups", gid])
205
        return self.requester.delete(url)
206
207
    @nextcloud_method
208
    def set_permissions_to_group_folder(self, fid, gid, permissions):
209
        """
210
        Set the permissions a group has in a folder
211
212
        Args:
213
            fid (int/str): group folder id
214
            gid (str): group id
215
            permissions (int): The new permissions for the group as attribute of Permission class
216
217
        Returns:
218
219
        """
220
        url = "/".join([str(fid), "groups", gid])
221
        return self.requester.post(url=url, data={"permissions": permissions})
222
223
    @nextcloud_method
224
    def set_quota_of_group_folder(self, fid, quota):
225
        """
226
        Set the quota for a folder in bytes
227
228
        Args:
229
            fid (int/str): group folder id
230
            quota (int/str): The new quota for the folder in bytes, user -3 for unlimited
231
232
        Returns:
233
234
        """
235
        url = "/".join([str(fid), "quota"])
236
        return self.requester.post(url, {"quota": quota})
237
238
    @nextcloud_method
239
    def rename_group_folder(self, fid, mountpoint):
240
        """
241
        Change the name of a folder
242
243
        Args:
244
            fid (int/str): group folder id
245
            mountpoint (str): The new name for the folder
246
247
        Returns:
248
249
        """
250
        url = "/".join([str(fid), "mountpoint"])
251
        return self.requester.post(url=url, data={"mountpoint": mountpoint})
252
253
254
class Share(WithRequester):
255
    API_URL = "/ocs/v2.php/apps/files_sharing/api/v1"
256
    LOCAL = "shares"
257
258
    def get_local_url(self, additional_url=""):
259
        if additional_url:
260
            return "/".join([self.LOCAL, additional_url])
261
        return self.LOCAL
262
263
    @staticmethod
264
    def validate_share_parameters(path, share_type, share_with):
265
        """
266
        Check if share parameters make sense
267
268
        Args:
269
            path (str): path to the file/folder which should be shared
270
            share_type (int): ShareType attribute
271
            share_with (str): user/group id with which the file should be shared
272
273
        Returns:
274
            bool: True if parameters make sense together, False otherwise
275
        """
276
        if (path is None or not isinstance(share_type, int)) \
277
                or (share_type in [ShareType.GROUP, ShareType.USER, ShareType.FEDERATED_CLOUD_SHARE]
278
                    and share_with is None):
279
            return False
280
        return True
281
282
    @nextcloud_method
283
    def get_shares(self):
284
        """ Get all shares from the user """
285
        return self.requester.get(self.get_local_url())
286
287
    @nextcloud_method
288
    def get_shares_from_path(self, path, reshares=None, subfiles=None):
289
        """
290
        Get all shares from a given file/folder
291
292
        Args:
293
            path (str): path to file/folder
294
            reshares (bool): (optional) return not only the shares from the current user but all shares from the given file
295
            subfiles (bool): (optional) return all shares within a folder, given that path defines a folder
296
297
        Returns:
298
299
        """
300
        url = self.get_local_url()
301
        params = {
302
            "path": path,
303
            "reshares": None if reshares is None else str(bool(reshares)).lower(),  # TODO: test reshares, subfiles
304
            "subfiles": None if subfiles is None else str(bool(subfiles)).lower(),
305
        }
306
        return self.requester.get(url, params=params)
307
308
    @nextcloud_method
309
    def get_share_info(self, sid):
310
        """
311
        Get information about a given share
312
313
        Args:
314
            sid (int): share id
315
316
        Returns:
317
        """
318
        return self.requester.get(self.get_local_url(sid))
319
320
    @nextcloud_method
321
    def create_share(
322
            self, path, share_type, share_with=None, public_upload=None,
323
            password=None, permissions=None):
324
        """
325
        Share a file/folder with a user/group or as public link
326
327
        Mandatory fields: share_type, path and share_with for share_type USER (0) or GROUP (1).
328
329
        Args:
330
            path (str): path to the file/folder which should be shared
331
            share_type (int): ShareType attribute
332
            share_with (str): user/group id with which the file should be shared
333
            public_upload (bool): bool, allow public upload to a public shared folder (true/false)
334
            password (str): password to protect public link Share with
335
            permissions (int): sum of selected Permission attributes
336
337
        Returns:
338
339
        """
340
        if not self.validate_share_parameters(path, share_type, share_with):
341
            return False
342
343
        url = self.get_local_url()
344
        if public_upload:
345
            public_upload = "true"
346
347
        data = {"path": path, "shareType": share_type}
348
        if share_type in [ShareType.GROUP, ShareType.USER, ShareType.FEDERATED_CLOUD_SHARE]:
349
            data["shareWith"] = share_with
350
        if public_upload:
351
            data["publicUpload"] = public_upload
352
        if share_type == ShareType.PUBLIC_LINK and password is not None:
353
            data["password"] = str(password)
354
        if permissions is not None:
355
            data["permissions"] = permissions
356
        return self.requester.post(url, data)
357
358
    @nextcloud_method
359
    def delete_share(self, sid):
360
        """
361
        Remove the given share
362
363
        Args:
364
            sid (str): share id
365
366
        Returns:
367
368
        """
369
        return self.requester.delete(self.get_local_url(sid))
370
371
    @nextcloud_method
372
    def update_share(self, sid, permissions=None, password=None, public_upload=None, expire_date=""):
373
        """
374
        Update a given share, only one value can be updated per request
375
376
        Args:
377
            sid (str): share id
378
            permissions (int): sum of selected Permission attributes
379
            password (str): password to protect public link Share with
380
            public_upload (bool): bool, allow public upload to a public shared folder (true/false)
381
            expire_date (str): set an expire date for public link shares. Format: ‘YYYY-MM-DD’
382
383
        Returns:
384
385
        """
386
        params = dict(
387
            permissions=permissions,
388
            password=password,
389
            expireDate=expire_date
390
        )
391
        if public_upload:
392
            params["publicUpload"] = "true"
393
        if public_upload is False:
394
            params["publicUpload"] = "false"
395
396
        # check if only one param specified
397
        specified_params_count = sum([int(bool(each)) for each in params.values()])
398
        if specified_params_count > 1:
399
            raise ValueError("Only one parameter for update can be specified per request")
400
401
        url = self.get_local_url(sid)
402
        return self.requester.put(url, data=params)
403
404
405
class FederatedCloudShare(WithRequester):
406
    API_URL = "/ocs/v2.php/apps/files_sharing/api/v1"
407
    FEDERATED = "remote_shares"
408
409
    def get_federated_url(self, additional_url=""):
410
        if additional_url:
411
            return "/".join([self.FEDERATED, additional_url])
412
        return self.FEDERATED
413
414
    @nextcloud_method
415
    def list_accepted_federated_cloudshares(self):
416
        url = self.get_federated_url()
417
        return self.requester.get(url)
418
419
    @nextcloud_method
420
    def get_known_federated_cloudshare(self, sid):
421
        url = self.get_federated_url(sid)
422
        return self.requester.get(url)
423
424
    @nextcloud_method
425
    def delete_accepted_federated_cloudshare(self, sid):
426
        url = self.get_federated_url(sid)
427
        return self.requester.delete(url)
428
429
    @nextcloud_method
430
    def list_pending_federated_cloudshares(self, sid):
431
        url = self.get_federated_url("pending")
432
        return self.requester.get(url)
433
434
    @nextcloud_method
435
    def accept_pending_federated_cloudshare(self, sid):
436
        url = self.get_federated_url("pending/{sid}".format(sid=sid))
437
        return self.requester.post(url)
438
439
    @nextcloud_method
440
    def decline_pending_federated_cloudshare(self, sid):
441
        url = self.get_federated_url("pending/{sid}".format(sid=sid))
442
        return self.requester.delete(url)
443
444
445
class Apps(WithRequester):
446
    API_URL = "/ocs/v1.php/cloud/apps"
447
448
    @nextcloud_method
449
    def get_apps(self, filter=None):
450
        """
451
        Get a list of apps installed on the Nextcloud server
452
453
        :param filter: str, optional "enabled" or "disabled"
454
        :return:
455
        """
456
        params = {
457
            "filter": filter
458
        }
459
        return self.requester.get(params=params)
460
461
    @nextcloud_method
462
    def get_app(self, app_id):
463
        """
464
        Provide information on a specific application
465
466
        :param app_id: str, app id
467
        :return:
468
        """
469
        return self.requester.get(app_id)
470
471
    @nextcloud_method
472
    def enable_app(self, app_id):
473
        """
474
        Enable an app
475
476
        :param app_id: str, app id
477
        :return:
478
        """
479
        return self.requester.post(app_id)
480
481
    @nextcloud_method
482
    def disable_app(self, app_id):
483
        """
484
        Disable the specified app
485
486
        :param app_id: str, app id
487
        :return:
488
        """
489
        return self.requester.delete(app_id)
490
491
492
class Group(WithRequester):
493
    API_URL = "/ocs/v1.php/cloud/groups"
494
495
    @nextcloud_method
496
    def get_groups(self, search=None, limit=None, offset=None):
497
        """
498
        Retrieve a list of groups from the Nextcloud server
499
500
        :param search: string, optional search string
501
        :param limit: int, optional limit value
502
        :param offset: int, optional offset value
503
        :return:
504
        """
505
        params = {
506
            'search': search,
507
            'limit': limit,
508
            'offset': offset
509
        }
510
        return self.requester.get(params=params)
511
512
    @nextcloud_method
513
    def add_group(self, gid):
514
        """
515
        Add a new group
516
517
        :param gid: str, group name
518
        :return:
519
        """
520
        msg = {"groupid": gid}
521
        return self.requester.post("", msg)
522
523
    @nextcloud_method
524
    def get_group(self, gid):
525
        """
526
        Retrieve a list of group members
527
528
        :param gid: str, group name
529
        :return:
530
        """
531
        return self.requester.get("{gid}".format(gid=gid))
532
533
    @nextcloud_method
534
    def get_subadmins(self, gid):
535
        """
536
        List subadmins of the group
537
538
        :param gid: str, group name
539
        :return:
540
        """
541
        return self.requester.get("{gid}/subadmins".format(gid=gid))
542
543
    @nextcloud_method
544
    def delete_group(self, gid):
545
        """
546
        Remove a group
547
548
        :param gid: str, group name
549
        :return:
550
        """
551
        return self.requester.delete("{gid}".format(gid=gid))
552
553
554
class User(WithRequester):
555
    API_URL = "/ocs/v1.php/cloud/users"
556
557
    @nextcloud_method
558
    def add_user(self, uid, passwd):
559
        """
560
        Create a new user on the Nextcloud server
561
562
        :param uid: str, uid of new user
563
        :param passwd: str, password of new user
564
        :return:
565
        """
566
        msg = {'userid': uid, 'password': passwd}
567
        return self.requester.post("", msg)
568
569
    @nextcloud_method
570
    def get_users(self, search=None, limit=None, offset=None):
571
        """
572
        Retrieve a list of users from the Nextcloud server
573
574
        :param search: string, optional search string
575
        :param limit: int, optional limit value
576
        :param offset: int, optional offset value
577
        :return:
578
        """
579
        params = {
580
            'search': search,
581
            'limit': limit,
582
            'offset': offset
583
        }
584
        return self.requester.get(params=params)
585
586
    @nextcloud_method
587
    def get_user(self, uid):
588
        """
589
        Retrieve information about a single user
590
591
        :param uid: str, uid of user
592
        :return:
593
        """
594
        return self.requester.get("{uid}".format(uid=uid))
595
596
    @nextcloud_method
597
    def edit_user(self, uid, what, value):
598
        """
599
        Edit attributes related to a user
600
601
        Users are able to edit email, displayname and password; admins can also edit the quota value
602
603
        :param uid: str, uid of user
604
        :param what: str, the field to edit
605
        :param value: str, the new value for the field
606
        :return:
607
        """
608
        what_to_key_map = dict(
609
            email="email", quota="quote", phone="phone", address="address", website="website",
610
            twitter="twitter", displayname="displayname", password="password",
611
        )
612
        assert what in what_to_key_map, (
613
            "You have chosen to edit user's '{what}', but you can choose only from: {choices}"
614
            .format(what=what, choices=", ".join(what_to_key_map.keys()))
615
        )
616
617
        url = "{uid}".format(uid=uid)
618
        msg = dict(
619
            key=what_to_key_map[what],
620
            value=value,
621
        )
622
        return self.requester.put(url, msg)
623
624
    @nextcloud_method
625
    def disable_user(self, uid):
626
        """
627
        Disable a user on the Nextcloud server so that the user cannot login anymore
628
629
        :param uid: str, uid of user
630
        :return:
631
        """
632
        return self.requester.put("{uid}/disable".format(uid=uid))
633
634
    @nextcloud_method
635
    def enable_user(self, uid):
636
        """
637
        Enable a user on the Nextcloud server so that the user can login again
638
639
        :param uid: str, uid of user
640
        :return:
641
        """
642
        return self.requester.put("{uid}/enable".format(uid=uid))
643
644
    @nextcloud_method
645
    def delete_user(self, uid):
646
        """
647
        Delete a user from the Nextcloud server
648
649
        :param uid: str, uid of user
650
        :return:
651
        """
652
        return self.requester.delete("{uid}".format(uid=uid))
653
654
    @nextcloud_method
655
    def add_to_group(self, uid, gid):
656
        """
657
        Add the specified user to the specified group
658
659
        :param uid: str, uid of user
660
        :param gid: str, name of group
661
        :return:
662
        """
663
        url = "{uid}/groups".format(uid=uid)
664
        msg = {'groupid': gid}
665
        return self.requester.post(url, msg)
666
667
    @nextcloud_method
668
    def remove_from_group(self, uid, gid):
669
        """
670
        Remove the specified user from the specified group
671
672
        :param uid: str, uid of user
673
        :param gid: str, name of group
674
        :return:
675
        """
676
        url = "{uid}/groups".format(uid=uid)
677
        msg = {'groupid': gid}
678
        return self.requester.delete(url, msg)
679
680
    @nextcloud_method
681
    def create_subadmin(self, uid, gid):
682
        """
683
        Make a user the subadmin of a group
684
685
        :param uid: str, uid of user
686
        :param gid: str, name of group
687
        :return:
688
        """
689
        url = "{uid}/subadmins".format(uid=uid)
690
        msg = {'groupid': gid}
691
        return self.requester.post(url, msg)
692
693
    @nextcloud_method
694
    def remove_subadmin(self, uid, gid):
695
        """
696
        Remove the subadmin rights for the user specified from the group specified
697
698
        :param uid: str, uid of user
699
        :param gid: str, name of group
700
        :return:
701
        """
702
        url = "{uid}/subadmins".format(uid=uid)
703
        msg = {'groupid': gid}
704
        return self.requester.delete(url, msg)
705
706
    @nextcloud_method
707
    def get_subadmin_groups(self, uid):
708
        """
709
        Get the groups in which the user is a subadmin
710
711
        :param uid: str, uid of user
712
        :return:
713
        """
714
        url = "{uid}/subadmins".format(uid=uid)
715
        return self.requester.get(url)
716
717
    @nextcloud_method
718
    def resend_welcome_mail(self, uid):
719
        """
720
        Trigger the welcome email for this user again
721
722
        :param uid: str, uid of user
723
        :return:
724
        """
725
        url = "{uid}/welcome".format(uid=uid)
726
        return self.requester.post(url)
727
728
729
class Activity(WithRequester):
730
    API_URL = "/ocs/v2.php/apps/activity/api/v2/activity"
731
732
    @nextcloud_method
733
    def get_activities(self, since=None, limit=None, object_type=None, object_id=None, sort=None):
734
        """
735
        Get an activity feed showing your file changes and other interesting things going on in your Nextcloud
736
737
        All args are optional
738
739
        Args:
740
            since (int): ID of the last activity that you’ve seen
741
            limit (int): How many activities should be returned (default: 50)
742
            object_type (string): Filter the activities to a given object. May only appear together with object_id
743
            object_id (string): Filter the activities to a given object. May only appear together with object_type
744
            sort (str, "asc" or "desc"): Sort activities ascending or descending (from the since) (Default: desc)
745
746
        Returns:
747
748
        """
749
        params = dict(
750
            since=since,
751
            limit=limit,
752
            object_type=object_type,
753
            object_id=object_id,
754
            sort=sort
755
        )
756
        if params['object_type'] and params['object_id']:
757
            return self.requester.get(url="filter", params=params)
758
        return self.requester.get(params=params)
759
760
761
class Notifications(WithRequester):
762
    API_URL = "/ocs/v2.php/apps/notifications/api/v2/notifications"
763
764
    @nextcloud_method
765
    def get_notifications(self):
766
        """ Get list of notifications for a logged in user """
767
        return self.requester.get()
768
769
    @nextcloud_method
770
    def get_notification(self, notification_id):
771
        """
772
        Get single notification by id for a user
773
774
        Args:
775
            notification_id (int): Notification id
776
777
        Returns:
778
779
        """
780
        return self.requester.get(url=notification_id)
781
782
    @nextcloud_method
783
    def delete_notification(self, notification_id):
784
        """
785
        Delete single notification by id for a user
786
787
        Args:
788
            notification_id (int): Notification id
789
790
        Returns:
791
792
        """
793
        return self.requester.delete(url=notification_id)
794
795
    @nextcloud_method
796
    def delete_all_notifications(self):
797
        """ Delete all notification for a logged in user
798
799
        Notes:
800
            This endpoint was added for Nextcloud 14
801
        """
802
        return self.requester.delete()
803
804
805
class UserLDAP(WithRequester):
806
    API_URL = "/ocs/v2.php/apps/user_ldap/api/v1/config"
807
808
    @nextcloud_method
809
    def create_ldap_config(self):
810
        """ Create a new and empty LDAP configuration """
811
        return self.requester.post()
812
813
    @nextcloud_method
814
    def get_ldap_config(self, config_id, show_password=None):
815
        """
816
        Get all keys and values of the specified LDAP configuration
817
818
        Args:
819
            config_id (str): User LDAP config id
820
            show_password (int): 0 or 1 whether to return the password in clear text (default 0)
821
822
        Returns:
823
824
        """
825
        params = dict(showPassword=show_password)
826
        return self.requester.get(config_id, params=params)
827
828
    @nextcloud_method
829
    def edit_ldap_config(self, config_id, data):
830
        """
831
        Update a configuration with the provided values
832
833
        You can find list of all config keys in get_ldap_config method response or in Nextcloud docs
834
835
        Args:
836
            config_id (str): User LDAP config id
837
            data (dict): config values to update
838
839
        Returns:
840
841
        """
842
        # TODO: refactor to provide methods for configuration s.a. edit_ldap_password and get_ldap_password
843
        prepared_data = {'configData[{}]'.format(key): value for key, value in data.items()}
844
        return self.requester.put(config_id, data=prepared_data)
845
846
    @nextcloud_method
847
    def delete_ldap_config(self, config_id):
848
        """
849
        Delete a given LDAP configuration
850
851
        Args:
852
            config_id (str): User LDAP config id
853
854
        Returns:
855
856
        """
857
        return self.requester.delete(config_id)
858
859
860
class OCSCode(enum.IntEnum):
861
    OK = 100
862
    SERVER_ERROR = 996
863
    NOT_AUTHORIZED = 997
864
    NOT_FOUND = 998
865
    UNKNOWN_ERROR = 999
866
867
868
class ShareType(enum.IntEnum):
869
    USER = 0
870
    GROUP = 1
871
    PUBLIC_LINK = 3
872
    FEDERATED_CLOUD_SHARE = 6
873
874
875
class Permission(enum.IntEnum):
876
    """ Permission for Share have to be sum of selected permissions """
877
    READ = 1
878
    UPDATE = 2
879
    CREATE = 4
880
    DELETE = 8
881
    SHARE = 16
882
    ALL = 31
883
884
885
QUOTA_UNLIMITED = -3
886
887
888
def datetime_to_expire_date(date):
889
    return date.strftime("%Y-%m-%d")
890