Skip to content

Commit

Permalink
Merge branch 'patrik-quota-visibility' into 'master'
Browse files Browse the repository at this point in the history
Update display of disk quota #46

See merge request ikus-soft/rdiffweb!334
  • Loading branch information
ikus060 committed May 31, 2023
2 parents 13383c9 + e783885 commit e55e019
Show file tree
Hide file tree
Showing 19 changed files with 2,078 additions and 999 deletions.
1 change: 0 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ deploy:demo:
- package:deb
image: registry.gitlab.com/finestructure/pipeline-trigger
script:
- apk update && apk add git
- export DEB_VERSION=$(ls -1 ./dist/bullseye/rdiffweb_*_all.deb | cut -d '_' -f 2)
- echo DEB_VERSION=$DEB_VERSION
# Trigger ansible-config pipeline
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ Professional support for Rdiffweb is available by [contacting IKUS Soft](https:/
* Hide LDAP label in users view when LDAP is not configured #237
* Add support for Ubuntu Lunar
* Add support for SQLAlchemy v2.0
* When reaching 100% disk usage, show quota in red to improve visibility
* Send notification when user's quota reach 90% #46

## 2.7.1 (2023-04-27)

Expand Down
2 changes: 1 addition & 1 deletion doc/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The following Ubuntu Release are supported: Jammy (22.04), Kinetic (22.10), Luna

apt install lsb-release
curl -L https://www.ikus-soft.com/archive/rdiffweb/public.key | gpg --dearmor > /usr/share/keyrings/rdiffweb-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/rdiffweb-keyring.gpg] https://nexus.ikus-soft.com/repository/apt-release-$(lsb_release -sc)/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/rdiffweb.list
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/rdiffweb-keyring.gpg] https://nexus.ikus-soft.com/repository/apt-release-$(lsb_release -sc)/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/rdiffweb.list
apt update
apt install rdiffweb

Expand Down
22 changes: 11 additions & 11 deletions rdiffweb/controller/page_admin_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,6 @@ class UserForm(CherryForm):
"Admin: may browse and delete everything. Maintainer: may browse and delete their own repo. User: may only browser their own repo."
),
)
disk_quota = SizeField(
_('Disk space'),
validators=[validators.optional()],
description=_("Users disk spaces (in bytes). Set to 0 to remove quota (unlimited)."),
)
disk_usage = SizeField(
_('Quota Used'),
validators=[validators.optional()],
description=_("Disk spaces (in bytes) used by this user."),
widget=widgets.HiddenInput(),
)
report_time_range = SelectField(
_('Send Backup report'),
choices=[
Expand All @@ -158,6 +147,17 @@ class UserForm(CherryForm):
coerce=int,
default='0',
)
disk_quota = SizeField(
_('Disk space'),
validators=[validators.optional()],
description=_("Users disk spaces (in bytes). Set to 0 to remove quota (unlimited)."),
)
disk_usage = SizeField(
_('Quota Used'),
validators=[validators.optional()],
description=_("Disk spaces (in bytes) used by this user."),
widget=widgets.HiddenInput(),
)

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand Down
12 changes: 10 additions & 2 deletions rdiffweb/core/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,27 @@ def notification_job(self):
Loop trough all the user repository and send notifications.
"""
# For Each user with an email.
# Identify the repository without activities using the backup statistics.

for userobj in UserObject.query.filter(UserObject.email != ''):
try:
# Identify the repository without activities using the backup statistics.
old_repos = [
repo
for repo in RepoObject.query.filter(RepoObject.user == userobj, RepoObject.maxage > 0)
if not repo.check_activity()
]
if old_repos:
# Check user's disk usage
disk_usage = userobj.disk_usage
disk_quota = userobj.disk_quota
used_pct = disk_usage / disk_quota * 100 if disk_quota else 0
# Send email if required
if old_repos or used_pct > 90:
self._queue_mail(
userobj,
template="email_notification.html",
repos=old_repos,
disk_usage=disk_usage,
disk_quota=disk_quota,
)
except Exception:
logger.exception('fail to send notification to user %s', userobj)
Expand Down
30 changes: 30 additions & 0 deletions rdiffweb/core/tests/test_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ def tearDown(self):


class NotificationJobTest(AbstractNotificationTest):
def setUp(self):
super().setUp()
cherrypy.engine.subscribe("get_disk_quota", self.listener.get_disk_quota, priority=40)
self.listener.get_disk_quota.return_value = False

def tearDown(self):
cherrypy.engine.unsubscribe("get_disk_quota", self.listener.get_disk_quota)
return super().tearDown()

def test_check_schedule(self):
# Given the application is started
# Then remove_older job should be schedule
Expand Down Expand Up @@ -94,6 +103,27 @@ def test_notification_job_undefined_last_backup_date(self):
message=ANY,
)

def test_notification_job_disk_usage(self):
# Given a user with an email address and a disk quota
# Set user config
user = UserObject.get_user(self.USERNAME)
user.email = 'test@test.com'
user.commit()
self.listener.get_disk_quota.return_value = user.disk_usage
# Given a user with a repo without max age.
repo = RepoObject.query.filter(RepoObject.user == user, RepoObject.repopath == self.REPO).first()
repo.commit()
self.listener.queue_email.reset_mock()
# When running notification_job
cherrypy.notification.notification_job()

# Then an email is queue for this user
self.listener.queue_email.assert_called_once_with(
to='test@test.com',
subject='Notification',
message=ANY,
)

def test_notification_job_without_notification(self):
# Given a valid user with a repository configured without notification (-1)
user = UserObject.get_user(self.USERNAME)
Expand Down

0 comments on commit e55e019

Please sign in to comment.