Skip to content

Commit

Permalink
Address comments @varmar05 - renaming attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelGeo committed Dec 19, 2024
1 parent 13e68b4 commit e61f7b5
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion server/mergin/sync/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class ProjectAccessDetail:
role: str
username: str
name: Optional[str]
project_permission: str
workspace_role: str
project_role: Optional[ProjectRole]
type: str

Expand Down
48 changes: 24 additions & 24 deletions server/mergin/sync/private_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,7 @@ components:
- id
- type
- email
- project_permission
- role
- workspace_role
properties:
id:
description: User/Invitation (uu)id
Expand All @@ -569,16 +568,9 @@ components:
type: string
format: email
example: [email protected]
role:
workspace_role:
description: Workspace role
type: string
enum:
- owner
- admin
- writer
- editor
- reader
- guest
$ref: "#/components/schemas/WorkspaceRole"
username:
description: Present only for type `member`
type: string
Expand All @@ -587,21 +579,13 @@ components:
description: Present only for type `member`
type: string
example: John Doe
project_permission:
type: string
enum:
- owner
- writer
- editor
- reader
role:
description: Project role defined as combination of project and workspace roles
$ref: "#/components/schemas/ProjectRole"
project_role:
type: string
nullable: true
enum:
- owner
- writer
- editor
- reader
description: Project role defined in database, not calculated version
$ref: "#/components/schemas/ProjectRole"
invitation:
description: Present only for type `invitation`
type: object
Expand Down Expand Up @@ -666,3 +650,19 @@ components:
items:
type: integer
example: [1]
WorkspaceRole:
type: string
enum:
- owner
- admin
- writer
- editor
- reader
- guest
ProjectRole:
type: string
enum:
- owner
- writer
- editor
- reader
2 changes: 1 addition & 1 deletion server/mergin/sync/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class ProjectAccessDetailSchema(Schema):
role = fields.String()
username = fields.String()
name = fields.String()
project_permission = fields.String()
workspace_role = fields.String()
project_role = fields.String()
type = fields.String()
invitation = fields.Nested(ProjectInvitationAccessSchema())
Expand Down
6 changes: 3 additions & 3 deletions server/mergin/sync/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@ def project_access(self, project: Project) -> List[ProjectAccessDetail]:
member = ProjectAccessDetail(
id=dm.id,
username=dm.username,
role=ws.get_user_role(dm).value,
workspace_role=ws.get_user_role(dm).value,
name=dm.profile.name(),
email=dm.email,
project_permission=project_permission and project_permission.value,
role=project_permission and project_permission.value,
project_role=project_role.value if project_role else None,
type="member",
)
Expand All @@ -347,8 +347,8 @@ def project_access(self, project: Project) -> List[ProjectAccessDetail]:
username=gm.username,
name=gm.profile.name(),
email=gm.email,
workspace_role=global_role,
role=global_role,
project_permission=global_role,
project_role=None,
type="member",
)
Expand Down
28 changes: 14 additions & 14 deletions server/mergin/tests/test_private_project_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,45 +490,45 @@ def test_get_project_access(client):
resp = client.get(url)
assert resp.status_code == 200
assert len(resp.json) == 1
assert resp.json[0]["project_permission"] == "owner"
assert resp.json[0]["role"] == "owner"
project.set_role(users[0].id, ProjectRole.OWNER)
project.set_role(users[1].id, ProjectRole.WRITER)
project.set_role(users[2].id, ProjectRole.READER)
db.session.commit()
resp = client.get(url)
assert resp.status_code == 200
assert len(resp.json) == 4
assert sum(map(lambda x: int(x["project_permission"] == "owner"), resp.json)) == 2
assert sum(map(lambda x: int(x["project_permission"] == "writer"), resp.json)) == 1
assert sum(map(lambda x: int(x["project_permission"] == "reader"), resp.json)) == 1
assert sum(map(lambda x: int(x["role"] == "owner"), resp.json)) == 2
assert sum(map(lambda x: int(x["role"] == "writer"), resp.json)) == 1
assert sum(map(lambda x: int(x["role"] == "reader"), resp.json)) == 1
# user3 does not have access to the project
assert not any(users[3].email == access["email"] for access in resp.json)
assert any(users[2].email == access["email"] for access in resp.json)
Configuration.GLOBAL_READ = True
resp = client.get(url)
assert resp.status_code == 200
assert len(resp.json) == 6
assert sum(map(lambda x: int(x["project_permission"] == "owner"), resp.json)) == 2
assert sum(map(lambda x: int(x["project_permission"] == "writer"), resp.json)) == 1
assert sum(map(lambda x: int(x["project_permission"] == "reader"), resp.json)) == 3
assert sum(map(lambda x: int(x["role"] == "owner"), resp.json)) == 2
assert sum(map(lambda x: int(x["role"] == "writer"), resp.json)) == 1
assert sum(map(lambda x: int(x["role"] == "reader"), resp.json)) == 3
Configuration.GLOBAL_WRITE = True
resp = client.get(url)
assert resp.status_code == 200
assert len(resp.json) == 6
assert sum(map(lambda x: int(x["project_permission"] == "owner"), resp.json)) == 2
assert sum(map(lambda x: int(x["project_permission"] == "writer"), resp.json)) == 4
assert sum(map(lambda x: int(x["project_permission"] == "reader"), resp.json)) == 0
assert sum(map(lambda x: int(x["role"] == "owner"), resp.json)) == 2
assert sum(map(lambda x: int(x["role"] == "writer"), resp.json)) == 4
assert sum(map(lambda x: int(x["role"] == "reader"), resp.json)) == 0
Configuration.GLOBAL_ADMIN = True
resp = client.get(url)
assert resp.status_code == 200
assert len(resp.json) == 6
assert sum(map(lambda x: int(x["project_permission"] == "owner"), resp.json)) == 6
assert sum(map(lambda x: int(x["project_permission"] == "writer"), resp.json)) == 0
assert sum(map(lambda x: int(x["project_permission"] == "reader"), resp.json)) == 0
assert sum(map(lambda x: int(x["role"] == "owner"), resp.json)) == 6
assert sum(map(lambda x: int(x["role"] == "writer"), resp.json)) == 0
assert sum(map(lambda x: int(x["role"] == "reader"), resp.json)) == 0
# pretend a user was deleted to test that api can handle it
users[3].inactivate()
users[3].anonymize()
resp = client.get(url)
assert resp.status_code == 200
assert len(resp.json) == 5
assert sum(map(lambda x: int(x["project_permission"] == "owner"), resp.json)) == 5
assert sum(map(lambda x: int(x["role"] == "owner"), resp.json)) == 5
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-MerginMaps-Commercial
<template #col-roles="{ item }">
<AppDropdown
:options="roles"
:model-value="item.project_permission"
:model-value="item.role"
@update:model-value="(e) => roleUpdate(item, e)"
:disabled="item.id === loggedUser.id"
class="w-6 lg:w-full"
Expand Down
2 changes: 1 addition & 1 deletion web-app/packages/lib/src/modules/project/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ export const useProjectStore = defineStore('projectModule', {
}
this.access = this.access.map((access) => {
if (access.id === payload.access.id) {
access.project_permission = payload.data.role
access.role = payload.data.role
access.project_role = payload.data.role
}
return access
Expand Down
4 changes: 2 additions & 2 deletions web-app/packages/lib/src/modules/project/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,11 @@ export type ProjectAccessDetailType = 'invitation' | 'member'
export interface ProjectAccessDetail {
id: number | string
type: ProjectAccessDetailType
role: WorkspaceRoleName
workspace_role: WorkspaceRoleName
name?: string
email: string
username?: string
project_permission?: ProjectRoleName
role?: ProjectRoleName
project_role?: ProjectRoleName | null
invitation?: {
expires_at: string
Expand Down

0 comments on commit e61f7b5

Please sign in to comment.