-
Notifications
You must be signed in to change notification settings - Fork 18
Add user management methods to py-client integration page #563
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0d3a96f
Add user management methods to py-client integration page
harminius 5493df4
Fix typing, typos, docsting
harminius 502e368
Fix typo
harminius 1b3cbe3
merge main
alex-cit bbecdd0
separate pages for python and c++ clients
alex-cit 7fc944f
check fix
alex-cit f215ba4
checks fix
alex-cit 5b5eb76
Merge branch 'main' into py-client_user_management
tomasMizera d95c6d5
Update api reference and associated texts
tomasMizera b11de6d
Fix CI checks
tomasMizera 0252bb8
Use different icon for notes in API
tomasMizera 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 hidden or 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 hidden or 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,34 @@ | ||
# C++ Standalone Client Integration | ||
[[toc]] | ||
|
||
Do you want to integrate <MainPlatformNameLink />? <MainPlatformName /> is an open platform that aims to be developer friendly and it has been designed to allow easy integration with other software. | ||
|
||
## C++ client installation | ||
C++ client is completely without any dependencies. To install the C++ client, just download the binary for your platform from <GitHubRepo id="MerginMaps/cpp-api-client/releases"/> and use it from the command line. | ||
|
||
Go to <GitHubRepo id="MerginMaps/cpp-api-client" /> repository for more information on how to use it. | ||
|
||
## Command line tool | ||
When the client is installed, it comes with `mergin` command line tool. | ||
|
||
```bash | ||
$ mergin --help | ||
Usage: mergin [OPTIONS] COMMAND [ARGS]... | ||
|
||
Options: | ||
--help Show this message and exit. | ||
--version Show the version information. | ||
--username Mergin username (or MERGIN_USERNAME env. variable) | ||
--password Mergin password (or MERGIN_PASSWORD env. variable) | ||
--url Mergin url (defaults to app.merginmaps.com) | ||
|
||
Commands: | ||
create Create a new project on Mergin server | ||
download Download last version of mergin project | ||
sync Pull&Push the changes | ||
remove Remove project from server. | ||
``` | ||
|
||
## Mergin Maps API core library | ||
|
||
C++ Client is based on the Qt-based <GitHubRepo id="MerginMaps/mobile/tree/master/core" desc="Mergin Maps API core library" /> used by the <MainDomainNameLink desc="Mergin Maps mobile app" /> to sync the projects in the mobile application. |
This file contains hidden or 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 |
---|---|---|
@@ -1,10 +1,9 @@ | ||
# Integrate Mergin Maps | ||
# Python Client Module Integration | ||
[[toc]] | ||
|
||
Do you want to integrate <MainPlatformNameLink />? <MainPlatformName /> is an open platform that aims to be developer friendly and it has been designed to allow easy integration with other software. | ||
|
||
|
||
## Python client module | ||
## Python client module installation | ||
The Python client module is the easiest way to programmatically use <MainPlatformNameLink />. You can use Python API or a command-line tool to easily work with <MainPlatformName /> projects, such as to get project status, push and pull changes, or to download, create and delete projects. | ||
|
||
The <GitHubRepo id="MerginMaps/python-api-client" /> repository contains the source code of the Python client module and more information on how to use it. | ||
|
@@ -15,59 +14,148 @@ Python client is available in the PyPI repository and can be installed with `pip | |
pip3 install mergin-client | ||
``` | ||
|
||
### Python module | ||
## Python module | ||
To use <MainPlatformNameLink /> from Python, just create `MerginClient` object and then use it. Here, for instance, to download a project: | ||
|
||
```python | ||
import mergin | ||
|
||
client = mergin.MerginClient(login='john', password='topsecret') | ||
client = mergin.MerginClient(login='john', password='T0p_secret') | ||
client.download_project('lutraconsulting/Basic survey', '/tmp/basic-survey') | ||
``` | ||
If you have <QGISPluginName /> installed and you want to use it from the QGIS' Python console | ||
|
||
```python | ||
import Mergin.mergin as mergin | ||
client = mergin.MerginClient(login='john', password='topsecret') | ||
client = mergin.MerginClient(login='john', password='T0p_secret') | ||
``` | ||
|
||
### Python command line interface | ||
For those who prefer using terminal, there is `mergin` command line tool shipped with the Python client. With several built-in commands, it is possible to download <MainPlatformName /> projects, push/pull changes, create or delete projects and more. | ||
## User and roles management in Python module | ||
You can create new users and manage their permissions using the following methods: | ||
|
||
For example, to download a <MainPlatformName /> project to a local folder: | ||
### Create a user | ||
|
||
```python | ||
client.create_user(<email>, <password>, <workspace_id>, <workspace_role>, [username], [notify_user]) | ||
``` | ||
mergin download john/project1 ~/mergin/project1 | ||
Arguments: | ||
|
||
`email` (string): Must be a unique email. | ||
|
||
`password` (string): Must meet security requirements. | ||
|
||
tomasMizera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`workspace_id` (int): The workspace ID where the user will be added. | ||
|
||
`workspace_role`(string): The user’s role in the workspace. [See the roles options](../../manage/permissions.md). | ||
|
||
tomasMizera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`username` (string, optional): Custom username; if not provided, it will be automatically generated. | ||
|
||
`notify_user` (Boolean, optional): Flag for email notifications (invitations, access requests etc.). Default is `False`. | ||
|
||
Example: | ||
```python | ||
client.create_user("[email protected]", "T0p_secret", 1, "editor", notify_user=True) | ||
``` | ||
For more details, visit <GitHubRepo id="MerginMaps/python-api-client" />. | ||
|
||
## C++ standalone client | ||
C++ Client has advantage over Python that it is completely without any dependencies. | ||
### Get a workspace member detail | ||
|
||
```python | ||
client.get_workspace_member(<workspace_id>, <user_id>) | ||
``` | ||
Arguments: | ||
|
||
`workspace_id` (int): The workspace ID used to retrieve the user's roles for the workspace and its projects. | ||
|
||
`user_id` (int): ID of the user. | ||
|
||
### Get a list of workspace members | ||
|
||
```python | ||
client.list_workspace_members(<workspace_id>) | ||
``` | ||
Arguments: | ||
|
||
`workspace_id` (int): The workspace ID to list the members. | ||
|
||
### Update workspace role | ||
|
||
```python | ||
client.update_workspace_member(<workspace_id>, <user_id>, <workspace_role>, [reset_projects_roles]) | ||
``` | ||
Arguments: | ||
|
||
`workspace_id` (int): Workspace ID where to update user's role. | ||
|
||
`user_id` (int): User to be updated. | ||
|
||
`workspace_role` (string): New role. | ||
|
||
To install the C++ client, just download the binary for your platform from <GitHubRepo id="MerginMaps/cpp-api-client/releases"/> and use it from the command line. | ||
`reset_projects_roles` (Boolean, optional): Flag to remove all project specific roles. | ||
|
||
Go to <GitHubRepo id="MerginMaps/cpp-api-client" /> repository for more information on how to use it. | ||
### Remove a user from a workspace | ||
|
||
### C++ Command line tool | ||
When the client is installed, it comes with `mergin` command line tool. | ||
```python | ||
client.remove_workspace_member(<workspace_id>, <user_id>) | ||
``` | ||
Arguments: | ||
|
||
`workspace_id` (int): Workspace ID from which to remove the user. | ||
|
||
`user_id` (int): ID of the user to be removed. | ||
|
||
### Get a list of project collaborators | ||
|
||
```python | ||
client.list_project_collaborators(<project_id>) | ||
``` | ||
Arguments: | ||
|
||
`project_id` (string): Project ID to list the users. | ||
|
||
### Add a user to project | ||
|
||
```python | ||
client.add_project_collaborator(<project_id>, <user>, <project_role>) | ||
``` | ||
Arguments: | ||
|
||
`project_id` (string): Project ID to add the user. | ||
|
||
`user` (string): Email or username of the user to be added to the project. | ||
|
||
`project_role`: (string): Role of the user in the project. | ||
|
||
```bash | ||
$ mergin --help | ||
Usage: mergin [OPTIONS] COMMAND [ARGS]... | ||
### Update project role | ||
|
||
Options: | ||
--help Show this message and exit. | ||
--version Show the version information. | ||
--username Mergin username (or MERGIN_USERNAME env. variable) | ||
--password Mergin password (or MERGIN_PASSWORD env. variable) | ||
--url Mergin url (defaults to app.merginmaps.com) | ||
```python | ||
client.update_project_collaborator(<project_id>, <user_id>, <project_role>) | ||
``` | ||
Arguments: | ||
|
||
`project_id` (string): Project ID in which the role will be updated. | ||
|
||
`user_id` (int): ID of the user to update. | ||
|
||
Commands: | ||
create Create a new project on Mergin server | ||
download Download last version of mergin project | ||
sync Pull&Push the changes | ||
remove Remove project from server. | ||
`project_role`: (string): New role. | ||
|
||
Note that the user must have a project role to update it. You can create one using the previous method. | ||
|
||
### Update project role | ||
|
||
```python | ||
client.remove_project_collaborator(<project_id>, <user_id>) | ||
``` | ||
Arguments: | ||
|
||
### C++ Mergin Maps API core library | ||
`project_id` (string): Project ID to remove the user. | ||
|
||
Client is based on the Qt-based <GitHubRepo id="MerginMaps/mobile/tree/master/core" desc="Mergin Maps API core library" /> used by the <MainDomainNameLink desc="Mergin Maps mobile app" /> to sync the projects in the mobile application. | ||
`user_id` (int): ID of the user to remove from the project. | ||
|
||
## Command line interface | ||
For those who prefer using terminal, there is `mergin` command line tool shipped with the Python client. With several built-in commands, it is possible to download <MainPlatformName /> projects, push/pull changes, create or delete projects and more. | ||
|
||
For example, to download a <MainPlatformName /> project to a local folder: | ||
``` | ||
mergin download john/project1 ~/mergin/project1 | ||
``` | ||
For more details, visit <GitHubRepo id="MerginMaps/python-api-client" />. |
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.