-
Notifications
You must be signed in to change notification settings - Fork 7
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
Editor sync handling #207
Merged
Merged
Editor sync handling #207
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3e59832
Added initial push handling for editors
MarcelGeo 52ff9af
Refactor read_metadate handling in merginproject
MarcelGeo 6744c8f
Prevent conflicted copy of qgis and mergin-config.json file
MarcelGeo 78b3a59
Cleanup edtor CLI tests
MarcelGeo 2a51dc8
Reolving some comments requirements
MarcelGeo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
from itertools import filterfalse | ||
|
||
from .utils import is_mergin_config, is_qgis_file, is_versioned_file | ||
|
||
EDITOR_ROLE_NAME = "editor" | ||
|
||
""" | ||
Determines whether a given file change should be disallowed based on the file path. | ||
|
||
Returns: | ||
bool: True if the file change should be disallowed, False otherwise. | ||
""" | ||
_disallowed_added_changes = lambda change: is_qgis_file(change["path"]) or is_mergin_config(change["path"]) | ||
""" | ||
Determines whether a given file change should be disallowed from being updated. | ||
|
||
The function checks the following conditions: | ||
- If the file path matches a QGIS file | ||
- If the file path matches a Mergin configuration file | ||
- If the file is versioned and the change does not have a diff | ||
|
||
Returns: | ||
bool: True if the change should be disallowed, False otherwise. | ||
""" | ||
_disallowed_updated_changes = ( | ||
lambda change: is_qgis_file(change["path"]) | ||
or is_mergin_config(change["path"]) | ||
or (is_versioned_file(change["path"]) and change.get("diff") is None) | ||
) | ||
""" | ||
Determines whether a given file change should be disallowed from being removed. | ||
|
||
The function checks if the file path of the change matches any of the following conditions: | ||
- The file is a QGIS file (e.g. .qgs, .qgz) | ||
- The file is a Mergin configuration file (mergin-config.json) | ||
- The file is a versioned file (.gpkg, .sqlite) | ||
|
||
If any of these conditions are met, the change is considered disallowed from being removed. | ||
""" | ||
_disallowed_removed_changes = ( | ||
lambda change: is_qgis_file(change["path"]) or is_mergin_config(change["path"]) or is_versioned_file(change["path"]) | ||
) | ||
wonder-sk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def is_editor_enabled(mc, project_info: dict) -> bool: | ||
""" | ||
The function checks if the server supports editor access, and if the current user's project role matches the expected role name for editors. | ||
""" | ||
server_support = mc.has_editor_support() | ||
project_role = project_info.get("role") | ||
|
||
return server_support and project_role == EDITOR_ROLE_NAME | ||
|
||
|
||
def _apply_editor_filters(changes: dict[str, list[dict]]) -> dict[str, list[dict]]: | ||
""" | ||
Applies editor-specific filters to the changes dictionary, removing any changes to files that are not in the editor's list of allowed files. | ||
|
||
Args: | ||
changes (dict[str, list[dict]]): A dictionary containing the added, updated, and removed changes. | ||
|
||
Returns: | ||
dict[str, list[dict]]: The filtered changes dictionary. | ||
""" | ||
added = changes.get("added", []) | ||
updated = changes.get("updated", []) | ||
removed = changes.get("removed", []) | ||
|
||
# filter out files that are not in the editor's list of allowed files | ||
changes["added"] = list(filterfalse(_disallowed_added_changes, added)) | ||
changes["updated"] = list(filterfalse(_disallowed_updated_changes, updated)) | ||
changes["removed"] = list(filterfalse(_disallowed_removed_changes, removed)) | ||
return changes | ||
|
||
|
||
def filter_changes(mc, project_info: dict, changes: dict[str, list[dict]]) -> dict[str, list[dict]]: | ||
""" | ||
Filters the given changes dictionary based on the editor's enabled state. | ||
|
||
If the editor is not enabled, the changes dictionary is returned as-is. Otherwise, the changes are passed through the `_apply_editor_filters` method to apply any configured filters. | ||
|
||
Args: | ||
changes (dict[str, list[dict]]): A dictionary mapping file paths to lists of change dictionaries. | ||
|
||
Returns: | ||
dict[str, list[dict]]: The filtered changes dictionary. | ||
""" | ||
if not is_editor_enabled(mc, project_info): | ||
return changes | ||
return _apply_editor_filters(changes) | ||
|
||
|
||
def prevent_conflicted_copy(path: str, mc, project_info: dict) -> bool: | ||
wonder-sk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return is_editor_enabled(mc, project_info) and any([is_qgis_file(path), is_mergin_config(path)]) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to keep the direct call to job.mp.apply_pull_changes() instead of introducing a new method in PullJob (it is meant just as a structure to keep everything that is needed for a pull)