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

Track number of visits on workspace invitation page #571

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion workspaces/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ class WorkspaceInviteAdmin(admin.ModelAdmin):
"email",
"status",
"has_expired",
"clicks",
"created_by",
"updated_by",
"created_at",
"updated_at",
]
list_filter = ["created_at", "status"]
readonly_fields = ["auto_accepted", "has_expired", "created_at", "updated_at"]
readonly_fields = [
"clicks",
"auto_accepted",
"has_expired",
"created_at",
"updated_at",
]
Comment on lines +32 to +38
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: clicks field added to readonly_fields but not included in WorkspaceInviteInline.readonly_fields - could lead to inconsistent behavior

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikochiko thoughts?

autocomplete_fields = ["workspace", "created_by", "updated_by"]


Expand Down
18 changes: 18 additions & 0 deletions workspaces/migrations/0007_workspaceinvite_clicks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.3 on 2024-12-23 08:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('workspaces', '0006_workspace_description'),
]

operations = [
migrations.AddField(
model_name='workspaceinvite',
name='clicks',
field=models.IntegerField(default=0),
devxpy marked this conversation as resolved.
Show resolved Hide resolved
),
]
4 changes: 3 additions & 1 deletion workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@ class Status(models.IntegerChoices):
choices=WorkspaceRole.choices, default=WorkspaceRole.MEMBER
)

clicks = models.IntegerField(default=0)

created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

Expand Down Expand Up @@ -637,7 +639,7 @@ def accept(
self.auto_accepted = auto_accepted

self.full_clean()
self.save()
self.save(update_fields=["status", "updated_by", "auto_accepted"])

return membership, created

Expand Down
3 changes: 3 additions & 0 deletions workspaces/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gooey_gui as gui
from django.contrib.humanize.templatetags.humanize import naturaltime
from django.core.exceptions import ValidationError
from django.db.models import F
from django.utils.translation import ngettext

from app_users.models import AppUser
Expand Down Expand Up @@ -33,6 +34,8 @@ def invitation_page(
set_current_workspace(session, int(invite.workspace_id))
raise gui.RedirectException(get_route_path(members_route))

WorkspaceInvite.objects.filter(id=invite.id).update(clicks=F("clicks") + 1)

with (
gui.div(
className="position-absolute top-0 start-0 bottom-0 bg-black min-vw-100 min-vh-100",
Expand Down
Loading