Skip to content

Commit

Permalink
Merge pull request #425 from dimagi/pkv/user-invite-status-changes
Browse files Browse the repository at this point in the history
User Invite Status Privacy Changes
  • Loading branch information
pxwxnvermx authored Dec 9, 2024
2 parents 6172ff7 + e4deacd commit b47fc88
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
25 changes: 16 additions & 9 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,22 +173,29 @@ 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 "---"
if not getattr(record.opportunity_access, "accepted", False):
invite_delete_url = reverse(
"opportunity:user_invite_delete",
args=(self.org_slug, record.opportunity.id, record.id),
)
return format_html(
(
'<button hx-post="{}" hx-swap="none" '
'hx-confirm="Please confirm to delete the User Invite." '
'class="btn btn-danger btn-sm">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},
)
return format_html('<a href="{}">View Profile</a>', url)
return format_html('<a class="btn btn-primary btn-sm" href="{}">View Profile</a>', url)

def render_started_learning(self, record, value):
return date_with_time_popup(self, value)
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 @@ -1222,3 +1223,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

0 comments on commit b47fc88

Please sign in to comment.