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

User Invite Status Privacy Changes #425

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 15 additions & 8 deletions commcare_connect/opportunity/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class UserStatusTable(OrgContextTable):
passed_assessment = BooleanAggregateColumn(verbose_name="Passed Assessment")
started_delivery = AggregateColumn(verbose_name="Started Delivery", accessor="date_deliver_started")
last_visit_date = columns.Column(accessor="last_visit_date_d")
view_profile = columns.Column("View Profile", empty_values=(), footer=lambda table: f"Invited: {len(table.rows)}")
view_profile = columns.Column("", empty_values=(), footer=lambda table: f"Invited: {len(table.rows)}")

class Meta:
model = UserInvite
Expand All @@ -173,17 +173,24 @@ class Meta:
orderable = False

def render_display_name(self, record):
if record.opportunity_access is None:
return record.phone_number
if not record.opportunity_access.accepted:
if not getattr(record.opportunity_access, "accepted", False):
return "---"
return record.opportunity_access.display_name

def render_view_profile(self, record):
if record.opportunity_access is None:
return "---"
if not record.opportunity_access.accepted:
return "---"
invite_delete_url = reverse(
pxwxnvermx marked this conversation as resolved.
Show resolved Hide resolved
"opportunity:user_invite_delete",
args=(self.org_slug, record.opportunity.id, record.id),
)
if not getattr(record.opportunity_access, "accepted", False):
return format_html(
(
'<button hx-post="{}" hx-swap="none" '
'hx-confirm="Please confirm to delete the User Invite." '
'class="btn btn-danger">Delete</button>'
),
invite_delete_url,
)
url = reverse(
"opportunity:user_profile",
kwargs={"org_slug": self.org_slug, "opp_id": record.opportunity.id, "pk": record.opportunity_access_id},
Expand Down
1 change: 1 addition & 0 deletions commcare_connect/opportunity/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,5 @@
path("<int:pk>/invoice_table/", views.PaymentInvoiceTableView.as_view(), name="invoice_table"),
path("<int:pk>/invoice/create/", views.invoice_create, name="invoice_create"),
path("<int:pk>/invoice/approve/", views.invoice_approve, name="invoice_approve"),
path("<int:opp_id>/user_invite_delete/<int:pk>/", views.user_invite_delete, name="user_invite_delete"),
]
11 changes: 11 additions & 0 deletions commcare_connect/opportunity/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
Payment,
PaymentInvoice,
PaymentUnit,
UserInvite,
UserVisit,
VisitReviewStatus,
VisitValidationStatus,
Expand Down Expand Up @@ -1217,3 +1218,13 @@ def invoice_approve(request, org_slug, pk):
)
payment.save()
return HttpResponse(headers={"HX-Trigger": "newInvoice"})


@org_member_required
@require_POST
@csrf_exempt
def user_invite_delete(request, org_slug, opp_id, pk):
opportunity = get_opportunity_or_404(opp_id, org_slug)
invite = get_object_or_404(UserInvite, pk=pk, opportunity=opportunity)
invite.delete()
return HttpResponse(status=200, headers={"HX-Trigger": "userStatusReload"})
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ <h2 class="accordion-header" id="headingTwo">
<div class="tab-pane fade show active" id="user-status-tab-pane" role="tabpanel" aria-labelledby="user-status-tab"
tabindex="0" hx-on::after-request="refreshTooltips()">
<div hx-get="{% url "opportunity:user_status_table" org_slug=request.org.slug pk=opportunity.pk %}{% querystring %}"
hx-trigger="load" hx-swap="outerHTML">
hx-trigger="load, userStatusReload from:body">
{% include "tables/table_placeholder.html" with num_cols=4 %}
</div>
</div>
Expand Down
Loading