Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup @deprecated code that affect only tests #767

Merged
merged 6 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions docker-app/qfieldcloud/core/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from deprecated import deprecated
from rest_framework import status


Expand Down Expand Up @@ -177,12 +176,3 @@ class ProjectAlreadyExistsError(QFieldCloudException):
code = "project_already_exists"
message = "This user already owns a project with the same name."
status_code = status.HTTP_400_BAD_REQUEST


@deprecated("moved to subscription")
class ReachedMaxOrganizationMembersError(QFieldCloudException):
"""Raised when an organization has exhausted its quota of members"""

code = "organization_has_max_number_of_members"
message = "Cannot add new organization members, account limit has been reached."
status_code = status.HTTP_403_FORBIDDEN
20 changes: 0 additions & 20 deletions docker-app/qfieldcloud/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,6 @@ def current_subscription(self):
Subscription = get_subscription_model()
return Subscription.get_or_create_current_subscription(self)

@property
@deprecated("Use `current_subscription` instead")
def active_subscription(self):
return self.current_subscription()

@property
def upcoming_subscription(self):
from qfieldcloud.subscription.models import get_subscription_model
Expand All @@ -437,13 +432,6 @@ def avatar_url(self):
else:
return None

@property
@deprecated("Use `UserAccount().storage_used_bytes` instead")
# TODO delete this method after refactoring tests so it's no longer used there
def storage_used_mb(self) -> float:
"""Returns the storage used in MB"""
return self.storage_used_bytes / 1000 / 1000

@property
def storage_used_bytes(self) -> float:
"""Returns the storage used in bytes"""
Expand All @@ -457,14 +445,6 @@ def storage_used_bytes(self) -> float:

return used_quota

@property
@deprecated("Use `UserAccount().storage_free_bytes` instead")
# TODO delete this method after refactoring tests so it's no longer used there
def storage_free_mb(self) -> float:
"""Returns the storage quota left in MB (quota from account and packages minus storage of all owned projects)"""

return self.storage_free_bytes / 1000 / 1000

@property
def storage_free_bytes(self) -> float:
"""Returns the storage quota left in bytes (quota from account and packages minus storage of all owned projects)"""
Expand Down
69 changes: 0 additions & 69 deletions docker-app/qfieldcloud/core/permissions_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import List, Literal, Union

from deprecated import deprecated
from django.utils.translation import gettext as _
from qfieldcloud.authentication.models import AuthToken
from qfieldcloud.core.models import (
Expand Down Expand Up @@ -336,33 +335,6 @@ def can_apply_pending_deltas_for_project(user: QfcUser, project: Project) -> boo
)


@deprecated("Use `can_set_delta_status_for_project` instead")
def can_apply_deltas(user: QfcUser, project: Project) -> bool:
return user_has_project_roles(
user,
project,
[
ProjectCollaborator.Roles.ADMIN,
ProjectCollaborator.Roles.MANAGER,
ProjectCollaborator.Roles.EDITOR,
ProjectCollaborator.Roles.REPORTER,
],
)


@deprecated("Use `can_set_delta_status_for_project` instead")
def can_overwrite_deltas(user: QfcUser, project: Project) -> bool:
return user_has_project_roles(
user,
project,
[
ProjectCollaborator.Roles.ADMIN,
ProjectCollaborator.Roles.MANAGER,
ProjectCollaborator.Roles.EDITOR,
],
)


def can_set_delta_status_for_project(user: QfcUser, project: Project) -> bool:
return user_has_project_roles(
user,
Expand Down Expand Up @@ -414,47 +386,6 @@ def can_create_delta(user: QfcUser, delta: Delta) -> bool:
return False


@deprecated("Use `can_set_delta_status` instead")
def can_retry_delta(user: QfcUser, delta: Delta) -> bool:
if not can_apply_deltas(user, delta.project):
return False

if delta.last_status not in (
Delta.Status.CONFLICT,
Delta.Status.NOT_APPLIED,
Delta.Status.ERROR,
):
return False

return True


@deprecated("Use `can_set_delta_status` instead")
def can_overwrite_delta(user: QfcUser, delta: Delta) -> bool:
if not can_overwrite_deltas(user, delta.project):
return False

if delta.last_status not in (Delta.Status.CONFLICT):
return False

return True


@deprecated("Use `can_set_delta_status` instead")
def can_ignore_delta(user: QfcUser, delta: Delta) -> bool:
if not can_apply_deltas(user, delta.project):
return False

if delta.last_status not in (
Delta.Status.CONFLICT,
Delta.Status.NOT_APPLIED,
Delta.Status.ERROR,
):
return False

return True


def can_read_jobs(user: QfcUser, project: Project) -> bool:
return user_has_project_roles(
user,
Expand Down
5 changes: 4 additions & 1 deletion docker-app/qfieldcloud/notifs/cron.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os

from django.conf import settings
from django.core.mail import send_mail
Expand Down Expand Up @@ -43,12 +44,14 @@ def do(self):
logging.warning(f"{user} has notifications, but no email set !")
continue

QFIELDCLOUD_HOST = os.environ.get("QFIELDCLOUD_HOST")

logging.debug(f"Sending an email to {user} !")

context = {
"notifs": notifs,
"username": user.username,
"hostname": settings.ALLOWED_HOSTS[0],
"hostname": QFIELDCLOUD_HOST,
}

subject = render_to_string(
Expand Down
9 changes: 0 additions & 9 deletions docker-app/qfieldcloud/subscription/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,6 @@ def current(self):

return qs

@deprecated("Use `current` instead. Remove this once parent repo uses current")
def active(self):
return self.current()

def managed_by(self, user_id: int):
"""Returns all subscriptions that are managed by given `user_id`. It means the owner personal account and all organizations they own.

Expand Down Expand Up @@ -698,11 +694,6 @@ def get_or_create_current_subscription(cls, account: UserAccount) -> "Subscripti

return subscription

@property
@deprecated("Use `get_or_create_current_subscription` instead")
def get_or_create_active_subscription(cls, account: UserAccount) -> "Subscription":
return cls.get_or_create_current_subscription(account)

@classmethod
def get_upcoming_subscription(cls, account: UserAccount) -> "Subscription":
result = (
Expand Down
8 changes: 6 additions & 2 deletions docker-app/qfieldcloud/subscription/tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ def assertStorage(
user.useraccount.current_subscription.future_storage_package_changed_mb,
future_storage_package_changed_mb,
)
self.assertEqual(user.useraccount.storage_used_mb, storage_used_mb)
self.assertEqual(user.useraccount.storage_free_mb, storage_free_mb)
self.assertEqual(
user.useraccount.storage_used_bytes, storage_used_mb * 1000 * 1000
)
self.assertEqual(
user.useraccount.storage_free_bytes, storage_free_mb * 1000 * 1000
)

def test_get_storage_package_type(self):
PackageType.objects.all().delete()
Expand Down
Loading