Skip to content

Commit

Permalink
Address commnets @varmar05
Browse files Browse the repository at this point in the history
- updatte returning storage size to number not formated string
  • Loading branch information
MarcelGeo committed Dec 16, 2024
1 parent d3598a3 commit 1d4c45a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions server/mergin/auth/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -934,9 +934,9 @@ components:
description: total number of projects
example: 12
storage:
type: string
type: number
description: projest files size in bytes
example: 1024 kB
example: 1024
users:
type: integer
description: count of registered accounts
Expand Down
2 changes: 1 addition & 1 deletion server/mergin/sync/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def files_size():
LEFT OUTER JOIN file_history fh ON fh.id = lf.file_id
WHERE fh.change = 'update_diff'::push_change_type
)
SELECT pg_size_pretty(COALESCE(SUM(sum), 0)) FROM partials;
SELECT COALESCE(SUM(sum), 0) FROM partials;
"""
)
return db.session.execute(files_size).scalar()
2 changes: 1 addition & 1 deletion server/mergin/sync/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def project_access(self, project: Project) -> List[ProjectAccessDetail]:
def server_editors_count(self) -> int:
if Configuration.GLOBAL_ADMIN or Configuration.GLOBAL_WRITE:
return User.query.filter(
is_(User.username.ilike("deleted_%"), False) | User.active,
is_(User.username.ilike("deleted_%"), False),
).count()

return (
Expand Down
7 changes: 6 additions & 1 deletion server/mergin/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-MerginMaps-Commercial

from datetime import datetime, timedelta
import os
import pytest
import json
from flask import url_for
Expand Down Expand Up @@ -30,6 +31,7 @@
login_as_admin,
login,
upload_file_to_project,
test_project_dir,
)


Expand Down Expand Up @@ -853,6 +855,9 @@ def test_server_usage(client):
"""Test server usage endpoint"""
login_as_admin(client)
workspace = create_workspace()
init_project = Project.query.filter_by(workspace_id=workspace.id).first()
resp = client.get("/app/admin/usage")
print(resp.json)
user = add_user()
admin = User.query.filter_by(username="mergin").first()
# create new project
Expand All @@ -865,7 +870,7 @@ def test_server_usage(client):
assert resp.json["users"] == 2
assert resp.json["workspaces"] == 1
assert resp.json["projects"] == 2
assert resp.json["storage"] == "454 kB"
assert resp.json["storage"] == project.disk_usage + init_project.disk_usage
assert resp.json["active_monthly_contributors"] == 1
assert resp.json["editors"] == 1
project.set_role(user.id, ProjectRole.EDITOR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-MerginMaps-Commercial
<usage-card class="col-12 sm:col-6 lg:col-3">
<template #heading>Used storage</template>
<div
class="w-full"
:style="{
class="w-full"
:style="{
height: '40px'
}"
>
<PProgressBar :value="0" :show-value="false"></PProgressBar>
</div>
<template #title
><span>{{ usage?.storage }}</span></template
><span>{{
$filters.filesize(usage.storage, null, 0)
}}</span></template
>
</usage-card>
<usage-card class="col-12 sm:col-6 lg:col-3">
Expand Down Expand Up @@ -98,14 +100,6 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-MerginMaps-Commercial
><span>{{ usage?.active_monthly_contributors }}</span></template
>
<template #subtitle>this month</template>
<template #footer>
<!-- TODO: click to see last three month graph-->
<!-- <PButton-->
<!-- @click=""-->
<!-- class="w-full"-->
<!-- label="See more"-->
<!-- />-->
</template>
</usage-card>
<usage-card v-if="showWorkspaces" class="col-12 sm:col-6 lg:col-3">
<template #heading>Workspaces</template>
Expand Down

0 comments on commit 1d4c45a

Please sign in to comment.