Skip to content

Commit 6528271

Browse files
authored
Merge pull request #604 from MerginMaps/implement-#3233
Update count editors logic
2 parents 484149a + d90a936 commit 6528271

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

server/mergin/sync/workspace.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,17 +363,17 @@ def project_access(self, project: Project) -> List[ProjectAccessDetail]:
363363

364364
def server_editors_count(self) -> int:
365365
if Configuration.GLOBAL_ADMIN or Configuration.GLOBAL_WRITE:
366-
return User.query.filter(
367-
is_(User.username.ilike("deleted_%"), False),
368-
).count()
366+
return User.query.filter(User.active == True).count()
369367

370368
return (
371369
db.session.query(ProjectUser.user_id)
372370
.select_from(Project)
373371
.join(ProjectUser)
372+
.join(User, User.id == ProjectUser.user_id)
374373
.filter(
375374
Project.removed_at.is_(None),
376375
ProjectUser.role != ProjectRole.READER.value,
376+
User.active == True,
377377
)
378378
.group_by(ProjectUser.user_id)
379379
.count()

server/mergin/tests/test_workspace.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ def test_workspace_implementation(client):
4646
assert ws.user_has_permissions(user, "write")
4747
assert ws.user_has_permissions(user, "read")
4848
assert handler.server_editors_count() == 2
49+
# inactive user should not be counted
50+
user.active = False
51+
db.session.commit()
52+
assert handler.server_editors_count() == 1
53+
user.active = True
54+
db.session.commit()
4955
assert not ws.user_has_permissions(user, "admin")
5056
assert not ws.user_has_permissions(user, "owner")
5157

0 commit comments

Comments
 (0)