Skip to content

Commit

Permalink
Merge branch 'main' into bug/299-anonymous-invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
TreyWW authored Apr 10, 2024
2 parents 9356afe + b998bda commit 60ac7f2
Show file tree
Hide file tree
Showing 54 changed files with 2,103 additions and 219 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,7 @@ Writerside/**
# Generated fronted files
frontend/static/src/output.css
frontend/static/js/bundle.js
frontend/static/js/bundle.js.map
frontend/static/js/bundle.js.map

# Pulumi
infrastructure/aws/pulumi/Pulumi.dev.yaml
63 changes: 28 additions & 35 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,45 +1,38 @@
repos:
- repo: https://github.com/psf/black
- repo: https://github.com/psf/black
rev: 24.3.0
entry: black --check --diff
hooks:
- id: black
- repo: local
hooks:
- id: pre-commit-django-migrations
name: Check django migrations
entry: python manage.py makemigrations --dry-run --check --no-input
language: system
types: [python]
pass_filenames: false
- repo: local
hooks:
- id: pre-commit-djlint
name: Djlint (html files)
entry: djlint . --check --profile=django
language: system
types: [python]
pass_filenames: false
- repo: https://github.com/pre-commit/pre-commit-hooks
- id: black
- repo: local
hooks:
- id: pre-commit-django-migrations
name: Check django migrations
entry: python manage.py makemigrations --dry-run --check --no-input
language: system
types: [ python ]
pass_filenames: false
- repo: local
hooks:
- id: pre-commit-djlint
name: Djlint (html files)
entry: djlint . --profile django --check
language: system
types: [ python ]
pass_filenames: false
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- id: name-tests-test
- repo: https://github.com/asottile/setup-cfg-fmt
- id: trailing-whitespace
- id: end-of-file-fixer
- id: debug-statements
- id: name-tests-test
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.5.0
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.12.0
hooks:
- id: reorder-python-imports
exclude: ^(pre_commit/resources/|testing/resources/python3_hooks_repo/)
args: [--py39-plus, --add-import, 'from __future__ import annotations']
- repo: https://github.com/asottile/pyupgrade
- id: setup-cfg-fmt
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args: [--py39-plus]
- id: pyupgrade
args: [ --py39-plus ]
6 changes: 6 additions & 0 deletions backend/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
QuotaIncreaseRequest,
Receipt,
ReceiptDownloadToken,
EmailSendStatus,
)

# from django.contrib.auth.models imp/ort User
Expand Down Expand Up @@ -64,7 +65,12 @@ class QuotaLimitAdmin(admin.ModelAdmin):
readonly_fields = ["name", "slug"]


class EmailSendStatusAdmin(admin.ModelAdmin):
readonly_fields = ["aws_message_id"]


admin.site.register(QuotaLimit, QuotaLimitAdmin)
admin.site.register(EmailSendStatus, EmailSendStatusAdmin)

# admin.site.unregister(User)
fields = list(UserAdmin.fieldsets)
Expand Down
21 changes: 19 additions & 2 deletions backend/api/base/modal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from django.http import HttpRequest, HttpResponseBadRequest
from __future__ import annotations

from django.http import HttpRequest
from django.http import HttpResponseBadRequest
from django.shortcuts import render

from backend.models import UserSettings, Invoice, Team, QuotaLimit
from backend.models import Client
from backend.models import Invoice
from backend.models import QuotaLimit
from backend.models import Team
from backend.models import UserSettings


# Still working on
Expand Down Expand Up @@ -77,6 +84,16 @@ def open_modal(request: HttpRequest, modal_name, context_type=None, context_valu
else:
context[context_type] = context_value

if modal_name == "send_single_email" or modal_name == "send_bulk_email":
context["content_min_length"] = 64
quota = QuotaLimit.objects.prefetch_related("quota_overrides").get(slug="emails-email_character_count")
context["content_max_length"] = quota.get_quota_limit(user=request.user, quota_limit=quota)
if request.user.logged_in_as_team:
clients = Client.objects.filter(organization=request.user.logged_in_as_team)
else:
clients = Client.objects.filter(user=request.user)
context["email_list"] = clients

return render(request, template_name, context)
except ValueError as e:
print(f"Something went wrong with loading modal {modal_name}. Error: {e}")
Expand Down
42 changes: 42 additions & 0 deletions backend/api/emails/fetch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from django.contrib import messages
from django.core.paginator import Paginator
from django.db.models import Q
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render, redirect
from django_ratelimit.core import is_ratelimited
from django_ratelimit.decorators import ratelimit

from backend.models import EmailSendStatus


def fetch_all_emails(request: HttpRequest):
if is_ratelimited(request, group="fetch_all_emails", key="user", rate="2/4s", increment=True) or is_ratelimited(
request,
group="fetch_all_emails",
key="user",
rate="5/10s",
increment=True or is_ratelimited(request, group="fetch_all_emails", key="user", rate="20/2m", increment=True),
):
return HttpResponse(status=429)
context = {}
if not request.htmx:
return redirect("quotas")

search_text = request.GET.get("search")
page_num = request.GET.get("page")

if request.user.logged_in_as_team:
results = EmailSendStatus.objects.filter(organization=request.user.logged_in_as_team)
else:
results = EmailSendStatus.objects.filter(user=request.user)

if search_text:
results = results.filter(Q(recipient__icontains=search_text))

results = results.order_by("-id")

paginator = Paginator(results, 8)
results = paginator.get_page(page_num)

context.update({"emails": results})
return render(request, "pages/emails/_fetch_body.html", context)
Loading

0 comments on commit 60ac7f2

Please sign in to comment.