Skip to content

Commit e54bde8

Browse files
committed
Drop versions and permissions check
1 parent c6dafca commit e54bde8

File tree

5 files changed

+17
-39
lines changed

5 files changed

+17
-39
lines changed

mergin/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ def push_project(self, directory):
918918
:param directory: Project's directory
919919
:type directory: String
920920
"""
921-
job = push_project_async(self, directory, check_version=True)
921+
job = push_project_async(self, directory)
922922
if job is None:
923923
return # there is nothing to push (or we only deleted some files)
924924
push_project_wait(job)

mergin/client_push.py

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def create_upload_job(
276276
return job
277277

278278

279-
def push_project_async(mc, directory, check_version=False) -> Optional[UploadJob]:
279+
def push_project_async(mc, directory) -> Optional[UploadJob]:
280280
"""Starts push of a project and returns pending upload job"""
281281

282282
mp = MerginProject(directory)
@@ -289,34 +289,10 @@ def push_project_async(mc, directory, check_version=False) -> Optional[UploadJob
289289
mp.log.info("--- version: " + mc.user_agent_info())
290290
mp.log.info(f"--- start push {project_path}")
291291

292-
try:
293-
project_info = mc.project_info(project_path)
294-
except ClientError as err:
295-
mp.log.error("Error getting project info: " + str(err))
296-
mp.log.info("--- push aborted")
297-
raise
298-
server_version = project_info["version"] if project_info["version"] else "v0"
299-
300-
mp.log.info(f"got project info: local version {local_version} / server version {server_version}")
301-
302-
username = mc.username()
303-
# permissions field contains information about update, delete and upload privileges of the user
304-
# on a specific project. This is more accurate information then "writernames" field, as it takes
305-
# into account namespace privileges. So we have to check only "permissions", namely "upload" one
306-
if not mc.has_writing_permissions(project_path):
307-
mp.log.error(f"--- push {project_path} - username {username} does not have write access")
308-
raise ClientError(f"You do not seem to have write access to the project (username '{username}')")
309-
310-
# DISCUSSION: do we want to check if the project is up to date before pushing? For now, we removed this part
311-
if check_version and local_version != server_version:
312-
mp.log.error(f"--- push {project_path} - not up to date (local {local_version} vs server {server_version})")
313-
raise ClientError(
314-
"There is a new version of the project on the server. Please update your local copy."
315-
+ f"\n\nLocal version: {local_version}\nServer version: {server_version}"
316-
)
292+
mp.log.info(f"got project info: local version {local_version}")
317293

318294
tmp_dir = tempfile.TemporaryDirectory(prefix="python-api-client-")
319-
changes, changes_len = get_push_changes_batch(mc, mp, project_info)
295+
changes, changes_len = get_push_changes_batch(mc, mp)
320296
if not changes_len:
321297
mp.log.info(f"--- push {project_path} - nothing to do")
322298
return
@@ -489,11 +465,12 @@ def remove_diff_files(job: UploadJob) -> None:
489465
os.remove(diff_file)
490466

491467

492-
def get_push_changes_batch(mc, mp: MerginProject, project_info: dict) -> Tuple[dict, int]:
468+
def get_push_changes_batch(mc, mp: MerginProject) -> Tuple[dict, int]:
493469
"""
494470
Get changes that need to be pushed to the server.
495471
"""
496472
changes = mp.get_push_changes()
497-
changes = filter_changes(mc, project_info, changes)
473+
project_role = mp.project_role()
474+
changes = filter_changes(mc, project_role, changes)
498475

499476
return changes, sum(len(v) for v in changes.values())

mergin/editor.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
_disallowed_changes: Callable[[dict], bool] = lambda change: is_qgis_file(change["path"])
1515

1616

17-
def is_editor_enabled(mc, project_info: dict) -> bool:
17+
def is_editor_enabled(mc, project_role: str) -> bool:
1818
"""
1919
The function checks if the server supports editor access, and if the current user's project role matches the expected role name for editors.
2020
"""
2121
server_support = mc.has_editor_support()
22-
project_role = project_info.get("role")
2322

2423
return server_support and project_role == EDITOR_ROLE_NAME
2524

@@ -40,7 +39,7 @@ def _apply_editor_filters(changes: Dict[str, List[dict]]) -> Dict[str, List[dict
4039
return changes
4140

4241

43-
def filter_changes(mc, project_info: dict, changes: Dict[str, List[dict]]) -> Dict[str, List[dict]]:
42+
def filter_changes(mc, project_role: str, changes: Dict[str, List[dict]]) -> Dict[str, List[dict]]:
4443
"""
4544
Filters the given changes dictionary based on the editor's enabled state.
4645
@@ -52,7 +51,7 @@ def filter_changes(mc, project_info: dict, changes: Dict[str, List[dict]]) -> Di
5251
Returns:
5352
dict[str, list[dict]]: The filtered changes dictionary.
5453
"""
55-
if not is_editor_enabled(mc, project_info):
54+
if not is_editor_enabled(mc, project_role):
5655
return changes
5756
return _apply_editor_filters(changes)
5857

mergin/merginproject.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ def workspace_name(self) -> str:
155155
full_name = self.project_full_name()
156156
slash_index = full_name.index("/")
157157
return full_name[:slash_index]
158+
159+
def project_role(self) -> str:
160+
self._read_metadata()
161+
return self._metadata.get("role")
158162

159163
def project_id(self) -> str:
160164
"""Returns ID of the project (UUID using 8-4-4-4-12 formatting without braces)

mergin/test/test_client.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,22 +2639,20 @@ def test_download_failure(mc):
26392639
def test_editor(mc: MerginClient):
26402640
"""Test editor handler class and push with editor"""
26412641

2642-
project_info = {"role": "editor"}
26432642
if not mc.has_editor_support():
2644-
assert is_editor_enabled(mc, project_info) is False
2643+
assert is_editor_enabled(mc, EDITOR_ROLE_NAME) is False
26452644
return
26462645

26472646
# mock that user is editor
2648-
project_info["role"] = EDITOR_ROLE_NAME
2649-
assert is_editor_enabled(mc, project_info) is True
2647+
assert is_editor_enabled(mc, EDITOR_ROLE_NAME) is True
26502648

26512649
# unit test for editor methods
26522650
qgs_changeset = {
26532651
"added": [{"path": "/folder/project.new.Qgz"}],
26542652
"updated": [{"path": "/folder/project.updated.Qgs"}],
26552653
"removed": [{"path": "/folder/project.removed.qgs"}],
26562654
}
2657-
qgs_changeset = filter_changes(mc, project_info, qgs_changeset)
2655+
qgs_changeset = filter_changes(mc, EDITOR_ROLE_NAME, qgs_changeset)
26582656
assert sum(len(v) for v in qgs_changeset.values()) == 2
26592657

26602658

0 commit comments

Comments
 (0)