Skip to content

Commit

Permalink
Merge pull request #352 from MerginMaps/fix_v2_apis
Browse files Browse the repository at this point in the history
Fix issues in new v2 API
  • Loading branch information
MarcelGeo authored Jan 10, 2025
2 parents 32270a8 + 61313dc commit 8f6a611
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion server/mergin/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def custom_protect():
_get_csrf_token = csrf._get_csrf_token

def get_csrf_token():
if request.path.startswith("/v1/"):
if request.path.startswith("/v1/") or request.path.startswith("/v2/"):
for header_name in app.app.config["WTF_CSRF_HEADERS"]:
csrf_token = request.headers.get(header_name)
if csrf_token:
Expand Down
4 changes: 3 additions & 1 deletion server/mergin/auth/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ def create_user():
username = request.json.get(
"username", User.generate_username(request.json["email"])
)
form = UserRegistrationForm()

# in public endpoint we want to disable form csrf - for browser clients endpoint is protected anyway
form = UserRegistrationForm(meta={"csrf": False})
form.confirm.data = form.password.data
form.username.data = username
if not form.validate():
Expand Down
4 changes: 2 additions & 2 deletions server/mergin/sync/public_api_v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ paths:
schema:
type: object
required:
- username
- user
- role
properties:
username:
user:
type: string
example: john.doe
description: username or email
Expand Down
2 changes: 1 addition & 1 deletion server/mergin/sync/public_api_v2_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def get_project_collaborators(id):
def add_project_collaborator(id):
"""Add project collaborator"""
project = require_project_by_uuid(id, ProjectPermissions.Update)
user = User.get_by_login(request.json["username"])
user = User.get_by_login(request.json["user"])
if not user:
abort(404)

Expand Down
2 changes: 1 addition & 1 deletion server/mergin/tests/test_public_api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_project_members(client):
assert response.status_code == 404

# add direct access
response = client.post(url, json={"role": role, "username": user.email})
response = client.post(url, json={"role": role, "user": user.email})
assert response.status_code == 201
assert response.json["id"] == user.id
assert response.json["project_role"] == role
Expand Down
4 changes: 2 additions & 2 deletions web-app/packages/lib/src/modules/project/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ export const useProjectStore = defineStore('projectModule', {
if (!payload.access.project_role) {
await ProjectApi.addProjectCollaborator(payload.projectId, {
...payload.data,
username: payload.access.username
user: payload.access.username
})
} else {
await ProjectApi.updateProjectCollaborator(
Expand Down Expand Up @@ -844,7 +844,7 @@ export const useProjectStore = defineStore('projectModule', {
if (!payload.collaborator.project_role) {
await ProjectApi.addProjectCollaborator(payload.projectId, {
...payload.data,
username: payload.collaborator.username
user: payload.collaborator.username
})
} else {
await ProjectApi.updateProjectCollaborator(
Expand Down
2 changes: 1 addition & 1 deletion web-app/packages/lib/src/modules/project/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export type EnhancedProjectDetail = ProjectDetail & {

export interface AddProjectCollaboratorPayload {
role: ProjectRoleName
username: string
user: string
}

export interface UpdateProjectCollaboratorPayload {
Expand Down

0 comments on commit 8f6a611

Please sign in to comment.