@@ -214,9 +214,9 @@ def validate_auth(self):
214
214
raise ClientError ("Missing login or password" )
215
215
216
216
@staticmethod
217
- def _check_token (f ):
217
+ def check_token (f ):
218
218
"""Wrapper for creating/renewing authorization token.
219
- Every function that requires authentication should be decorated with this as @_check_token ."""
219
+ Every function that requires authentication should be decorated with this as @check_token ."""
220
220
221
221
def wrapper (self , * args , ** kwargs ):
222
222
# functions that run prior to required function using this decorator
@@ -329,7 +329,7 @@ def username(self):
329
329
return None # not authenticated
330
330
return self ._user_info ["username" ]
331
331
332
- @_check_token
332
+ @check_token
333
333
def workspace_service (self , workspace_id ):
334
334
"""
335
335
This Requests information about a workspace service from /workspace/{id}/service endpoint,
@@ -340,7 +340,7 @@ def workspace_service(self, workspace_id):
340
340
resp = self .get (f"/v1/workspace/{ workspace_id } /service" )
341
341
return json .load (resp )
342
342
343
- @_check_token
343
+ @check_token
344
344
def workspace_usage (self , workspace_id ):
345
345
"""
346
346
This Requests information about a workspace usage from /workspace/{id}/usage endpoint,
@@ -393,7 +393,7 @@ def server_version(self):
393
393
394
394
return self ._server_version
395
395
396
- @_check_token
396
+ @check_token
397
397
def workspaces_list (self ):
398
398
"""
399
399
Find all available workspaces
@@ -404,7 +404,7 @@ def workspaces_list(self):
404
404
workspaces = json .load (resp )
405
405
return workspaces
406
406
407
- @_check_token
407
+ @check_token
408
408
def create_workspace (self , workspace_name ):
409
409
"""
410
410
Create new workspace for currently active user.
@@ -423,7 +423,7 @@ def create_workspace(self, workspace_name):
423
423
e .extra = f"Workspace name: { workspace_name } "
424
424
raise e
425
425
426
- @_check_token
426
+ @check_token
427
427
def create_project (self , project_name , is_public = False , namespace = None ):
428
428
"""
429
429
Create new project repository in user namespace on Mergin Maps server.
@@ -473,7 +473,7 @@ def create_project(self, project_name, is_public=False, namespace=None):
473
473
e .extra = f"Namespace: { namespace } , project name: { project_name } "
474
474
raise e
475
475
476
- @_check_token
476
+ @check_token
477
477
def create_project_and_push (self , project_name , directory , is_public = False , namespace = None ):
478
478
"""
479
479
Convenience method to create project and push the initial version right after that.
@@ -519,7 +519,7 @@ def create_project_and_push(self, project_name, directory, is_public=False, name
519
519
if mp .inspect_files ():
520
520
self .push_project (directory )
521
521
522
- @_check_token
522
+ @check_token
523
523
def paginated_projects_list (
524
524
self ,
525
525
page = 1 ,
@@ -593,7 +593,7 @@ def paginated_projects_list(
593
593
projects = json .load (resp )
594
594
return projects
595
595
596
- @_check_token
596
+ @check_token
597
597
def projects_list (
598
598
self ,
599
599
tags = None ,
@@ -663,7 +663,7 @@ def projects_list(
663
663
break
664
664
return projects
665
665
666
- @_check_token
666
+ @check_token
667
667
def project_info (self , project_path_or_id , since = None , version = None ):
668
668
"""
669
669
Fetch info about project.
@@ -687,7 +687,7 @@ def project_info(self, project_path_or_id, since=None, version=None):
687
687
resp = self .get ("/v1/project/{}" .format (project_path_or_id ), params )
688
688
return json .load (resp )
689
689
690
- @_check_token
690
+ @check_token
691
691
def paginated_project_versions (self , project_path , page , per_page = 100 , descending = False ):
692
692
"""
693
693
Get records of project's versions (history) using calculated pagination.
@@ -709,7 +709,7 @@ def paginated_project_versions(self, project_path, page, per_page=100, descendin
709
709
resp_json = json .load (resp )
710
710
return resp_json ["versions" ], resp_json ["count" ]
711
711
712
- @_check_token
712
+ @check_token
713
713
def project_versions_count (self , project_path ):
714
714
"""
715
715
return the total count of versions
@@ -725,7 +725,7 @@ def project_versions_count(self, project_path):
725
725
resp_json = json .load (resp )
726
726
return resp_json ["count" ]
727
727
728
- @_check_token
728
+ @check_token
729
729
def project_versions (self , project_path , since = 1 , to = None ):
730
730
"""
731
731
Get records of project's versions (history) in ascending order.
@@ -773,7 +773,7 @@ def project_versions(self, project_path, since=1, to=None):
773
773
filtered_versions = list (filter (lambda v : (num_since <= int_version (v ["name" ]) <= num_to ), versions ))
774
774
return filtered_versions
775
775
776
- @_check_token
776
+ @check_token
777
777
def download_project (self , project_path , directory , version = None ):
778
778
"""
779
779
Download project into given directory. If version is not specified, latest version is downloaded
@@ -791,7 +791,7 @@ def download_project(self, project_path, directory, version=None):
791
791
download_project_wait (job )
792
792
download_project_finalize (job )
793
793
794
- @_check_token
794
+ @check_token
795
795
def user_info (self ):
796
796
server_type = self .server_type ()
797
797
if server_type == ServerType .OLD :
@@ -800,7 +800,7 @@ def user_info(self):
800
800
resp = self .get ("/v1/user/profile" )
801
801
return json .load (resp )
802
802
803
- @_check_token
803
+ @check_token
804
804
def set_project_access (self , project_path , access ):
805
805
"""
806
806
Updates access for given project.
@@ -824,7 +824,7 @@ def set_project_access(self, project_path, access):
824
824
e .extra = f"Project path: { project_path } "
825
825
raise e
826
826
827
- @_check_token
827
+ @check_token
828
828
def add_user_permissions_to_project (self , project_path , usernames , permission_level ):
829
829
"""
830
830
Add specified permissions to specified users to project
@@ -858,7 +858,7 @@ def add_user_permissions_to_project(self, project_path, usernames, permission_le
858
858
category = DeprecationWarning ,
859
859
)
860
860
861
- @_check_token
861
+ @check_token
862
862
def remove_user_permissions_from_project (self , project_path , usernames ):
863
863
"""
864
864
Removes specified users from project
@@ -883,7 +883,7 @@ def remove_user_permissions_from_project(self, project_path, usernames):
883
883
category = DeprecationWarning ,
884
884
)
885
885
886
- @_check_token
886
+ @check_token
887
887
def project_user_permissions (self , project_path ):
888
888
"""
889
889
Returns permissions for project
@@ -904,7 +904,7 @@ def project_user_permissions(self, project_path):
904
904
result ["readers" ] = access .get ("readersnames" , [])
905
905
return result
906
906
907
- @_check_token
907
+ @check_token
908
908
def push_project (self , directory ):
909
909
"""
910
910
Upload local changes to the repository.
@@ -918,7 +918,7 @@ def push_project(self, directory):
918
918
push_project_wait (job )
919
919
push_project_finalize (job )
920
920
921
- @_check_token
921
+ @check_token
922
922
def pull_project (self , directory ):
923
923
"""
924
924
Fetch and apply changes from repository.
@@ -932,7 +932,7 @@ def pull_project(self, directory):
932
932
pull_project_wait (job )
933
933
return pull_project_finalize (job )
934
934
935
- @_check_token
935
+ @check_token
936
936
def clone_project (self , source_project_path , cloned_project_name , cloned_project_namespace = None ):
937
937
"""
938
938
Clone project on server.
@@ -978,7 +978,7 @@ def clone_project(self, source_project_path, cloned_project_name, cloned_project
978
978
request = urllib .request .Request (url , data = json .dumps (data ).encode (), headers = json_headers , method = "POST" )
979
979
self ._do_request (request )
980
980
981
- @_check_token
981
+ @check_token
982
982
def delete_project_now (self , project_path ):
983
983
"""
984
984
Delete project repository on server immediately.
@@ -1002,7 +1002,7 @@ def delete_project_now(self, project_path):
1002
1002
request = urllib .request .Request (url , method = "DELETE" )
1003
1003
self ._do_request (request )
1004
1004
1005
- @_check_token
1005
+ @check_token
1006
1006
def delete_project (self , project_path ):
1007
1007
"""
1008
1008
Delete project repository on server. Newer servers since 2023
@@ -1027,7 +1027,7 @@ def delete_project(self, project_path):
1027
1027
request = urllib .request .Request (url , method = "DELETE" )
1028
1028
self ._do_request (request )
1029
1029
1030
- @_check_token
1030
+ @check_token
1031
1031
def project_status (self , directory ):
1032
1032
"""
1033
1033
Get project status, e.g. server and local changes.
@@ -1047,27 +1047,27 @@ def project_status(self, directory):
1047
1047
1048
1048
return pull_changes , push_changes , push_changes_summary
1049
1049
1050
- @_check_token
1050
+ @check_token
1051
1051
def project_version_info (self , project_id , version ):
1052
1052
"""Returns JSON with detailed information about a single project version"""
1053
1053
resp = self .get (f"/v1/project/version/{ project_id } /{ version } " )
1054
1054
return json .load (resp )
1055
1055
1056
- @_check_token
1056
+ @check_token
1057
1057
def project_file_history_info (self , project_path , file_path ):
1058
1058
"""Returns JSON with full history of a single file within a project"""
1059
1059
params = {"path" : file_path }
1060
1060
resp = self .get ("/v1/resource/history/{}" .format (project_path ), params )
1061
1061
return json .load (resp )
1062
1062
1063
- @_check_token
1063
+ @check_token
1064
1064
def project_file_changeset_info (self , project_path , file_path , version ):
1065
1065
"""Returns JSON with changeset details of a particular version of a file within a project"""
1066
1066
params = {"path" : file_path }
1067
1067
resp = self .get ("/v1/resource/changesets/{}/{}" .format (project_path , version ), params )
1068
1068
return json .load (resp )
1069
1069
1070
- @_check_token
1070
+ @check_token
1071
1071
def get_projects_by_names (self , projects ):
1072
1072
"""Returns JSON with projects' info for list of required projects.
1073
1073
The schema of the returned information is the same as the response from projects_list().
@@ -1082,7 +1082,7 @@ def get_projects_by_names(self, projects):
1082
1082
resp = self .post ("/v1/project/by_names" , {"projects" : projects }, {"Content-Type" : "application/json" })
1083
1083
return json .load (resp )
1084
1084
1085
- @_check_token
1085
+ @check_token
1086
1086
def download_file (self , project_dir , file_path , output_filename , version = None ):
1087
1087
"""
1088
1088
Download project file at specified version. Get the latest if no version specified.
@@ -1136,7 +1136,7 @@ def get_file_diff(self, project_dir, file_path, output_diff, version_from, versi
1136
1136
elif len (diffs ) == 1 :
1137
1137
shutil .copy (diffs [0 ], output_diff )
1138
1138
1139
- @_check_token
1139
+ @check_token
1140
1140
def download_file_diffs (self , project_dir , file_path , versions ):
1141
1141
"""Download file diffs for specified versions if they are not present
1142
1142
in the cache.
@@ -1213,7 +1213,7 @@ def has_writing_permissions(self, project_path):
1213
1213
info = self .project_info (project_path )
1214
1214
return info ["permissions" ]["upload" ]
1215
1215
1216
- @_check_token
1216
+ @check_token
1217
1217
def rename_project (self , project_path : str , new_project_name : str ) -> None :
1218
1218
"""
1219
1219
Rename project on server.
@@ -1285,7 +1285,7 @@ def reset_local_changes(self, directory: str, files_to_reset: typing.List[str] =
1285
1285
if files_download :
1286
1286
self .download_files (directory , files_download , version = current_version )
1287
1287
1288
- @_check_token
1288
+ @check_token
1289
1289
def download_files (
1290
1290
self , project_dir : str , file_paths : typing .List [str ], output_paths : typing .List [str ] = None , version : str = None
1291
1291
):
@@ -1311,7 +1311,7 @@ def has_editor_support(self):
1311
1311
"""
1312
1312
return is_version_acceptable (self .server_version (), "2024.4.0" )
1313
1313
1314
- @_check_token
1314
+ @check_token
1315
1315
def create_user (
1316
1316
self ,
1317
1317
email : str ,
@@ -1343,23 +1343,23 @@ def create_user(
1343
1343
user_info = self .post ("v2/users" , params , json_headers )
1344
1344
return json .load (user_info )
1345
1345
1346
- @_check_token
1346
+ @check_token
1347
1347
def get_workspace_member (self , workspace_id : int , user_id : int ) -> dict :
1348
1348
"""
1349
1349
Get a workspace member detail
1350
1350
"""
1351
1351
resp = self .get (f"v2/workspaces/{ workspace_id } /members/{ user_id } " )
1352
1352
return json .load (resp )
1353
1353
1354
- @_check_token
1354
+ @check_token
1355
1355
def list_workspace_members (self , workspace_id : int ) -> List [dict ]:
1356
1356
"""
1357
1357
Get a list of workspace members
1358
1358
"""
1359
1359
resp = self .get (f"v2/workspaces/{ workspace_id } /members" )
1360
1360
return json .load (resp )
1361
1361
1362
- @_check_token
1362
+ @check_token
1363
1363
def update_workspace_member (
1364
1364
self , workspace_id : int , user_id : int , workspace_role : WorkspaceRole , reset_projects_roles : bool = False
1365
1365
) -> dict :
@@ -1375,22 +1375,22 @@ def update_workspace_member(
1375
1375
workspace_member = self .patch (f"v2/workspaces/{ workspace_id } /members/{ user_id } " , params , json_headers )
1376
1376
return json .load (workspace_member )
1377
1377
1378
- @_check_token
1378
+ @check_token
1379
1379
def remove_workspace_member (self , workspace_id : int , user_id : int ):
1380
1380
"""
1381
1381
Remove a user from workspace members
1382
1382
"""
1383
1383
self .delete (f"v2/workspaces/{ workspace_id } /members/{ user_id } " )
1384
1384
1385
- @_check_token
1385
+ @check_token
1386
1386
def list_project_collaborators (self , project_id : str ) -> List [dict ]:
1387
1387
"""
1388
1388
Get a list of project collaborators
1389
1389
"""
1390
1390
project_collaborators = self .get (f"v2/projects/{ project_id } /collaborators" )
1391
1391
return json .load (project_collaborators )
1392
1392
1393
- @_check_token
1393
+ @check_token
1394
1394
def add_project_collaborator (self , project_id : str , user : str , project_role : ProjectRole ) -> dict :
1395
1395
"""
1396
1396
Add a user to project collaborators and grant them a project role.
@@ -1402,7 +1402,7 @@ def add_project_collaborator(self, project_id: str, user: str, project_role: Pro
1402
1402
project_collaborator = self .post (f"v2/projects/{ project_id } /collaborators" , params , json_headers )
1403
1403
return json .load (project_collaborator )
1404
1404
1405
- @_check_token
1405
+ @check_token
1406
1406
def update_project_collaborator (self , project_id : str , user_id : int , project_role : ProjectRole ) -> dict :
1407
1407
"""
1408
1408
Update project role of the existing project collaborator.
@@ -1412,7 +1412,7 @@ def update_project_collaborator(self, project_id: str, user_id: int, project_rol
1412
1412
project_collaborator = self .patch (f"v2/projects/{ project_id } /collaborators/{ user_id } " , params , json_headers )
1413
1413
return json .load (project_collaborator )
1414
1414
1415
- @_check_token
1415
+ @check_token
1416
1416
def remove_project_collaborator (self , project_id : str , user_id : int ):
1417
1417
"""
1418
1418
Remove a user from project collaborators
@@ -1424,7 +1424,7 @@ def server_config(self) -> dict:
1424
1424
response = self .get ("/config" )
1425
1425
return json .load (response )
1426
1426
1427
- @_check_token
1427
+ @check_token
1428
1428
def send_logs (
1429
1429
self ,
1430
1430
logfile : str ,
0 commit comments