Skip to content

Commit

Permalink
fix user display (#58)
Browse files Browse the repository at this point in the history
* fixed user badge "title" pop-over

  by eliminating leading & trailing whitespace from attribute value

* fixed listing of users missing first/last name -- fall back to username

* fixed display of users missing first/last name -- everywhere else across site

  (fall back to username)

* display users' contact info to logged-in sessions (only)

  * email addresses are listed -- along with user names -- most-anywhere they fit
  * email addresses are mailto: links in administrative pages
  * any add'l contact info (e.g. phone) listed on user profile

  resolves #57
  • Loading branch information
jesteria authored Dec 3, 2020
1 parent 7710a5b commit 17f86f3
Show file tree
Hide file tree
Showing 21 changed files with 123 additions and 52 deletions.
28 changes: 14 additions & 14 deletions src/marketplace/domain/proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def create_project(request_user, project, organization, organization_members):
qa_channel.save()


message = "The project {0} was created by {1} within the organization {2}.".format(project.name, request_user.standard_display_name(), organization.name)
message = "The project {0} was created by {1} within the organization {2}.".format(project.name, request_user.standard_display_name, organization.name)
NotificationService.add_multiuser_notification(organization_members,
message,
NotificationSeverity.INFO,
Expand All @@ -461,7 +461,7 @@ def save_project(request_user, projid, project):
validate_consistent_keys(project, ('id', projid))
ensure_user_has_permission(request_user, project, 'project.information_edit')
project.save()
message = "The project {0} was edited by {1}.".format(project.name, request_user.standard_display_name())
message = "The project {0} was edited by {1}.".format(project.name, request_user.standard_display_name)
NotificationService.add_multiuser_notification(ProjectService.get_public_notification_users(request_user, project),
message,
NotificationSeverity.INFO,
Expand Down Expand Up @@ -500,7 +500,7 @@ def publish_project(request_user, projid, project):
# working on domain tasks?
project.actual_start_date = timezone.now()
project.save()
message = "The project {0} was published by {1} and can now be applied to by volunteers.".format(project.name, request_user.standard_display_name())
message = "The project {0} was published by {1} and can now be applied to by volunteers.".format(project.name, request_user.standard_display_name)
NotificationService.add_multiuser_notification(ProjectService.get_project_members(request_user, project),
message,
NotificationSeverity.WARNING,
Expand Down Expand Up @@ -543,7 +543,7 @@ def add_staff_member(request_user, projid, project_role):
try:
previous_members = ProjectService.get_project_members(request_user, project)
project_role.save()
message = "New staff member {0} added to the project {1} with role {2}.".format(project_role.user.standard_display_name(), project.name, project_role.get_role_display())
message = "New staff member {0} added to the project {1} with role {2}.".format(project_role.user.standard_display_name, project.name, project_role.get_role_display())
NotificationService.add_multiuser_notification(previous_members,
message,
NotificationSeverity.INFO,
Expand Down Expand Up @@ -576,7 +576,7 @@ def save_project_role(request_user, projid, project_role):
raise ValueError('You are trying to remove the last administrator of the project. Please appoint another administrator before removing the current one.')
project_role.save()
project = project_role.project
message = "The role of {0} in project {1} has been changed to {2}.".format(project_role.user.standard_display_name(), project.name, project_role.get_role_display())
message = "The role of {0} in project {1} has been changed to {2}.".format(project_role.user.standard_display_name, project.name, project_role.get_role_display())
NotificationService.add_multiuser_notification(ProjectService.get_project_members(request_user, project),
message,
NotificationSeverity.INFO,
Expand All @@ -602,7 +602,7 @@ def delete_project_role(request_user, projid, project_role):
raise ValueError('You are trying to remove the last administrator of the project. Please appoint another administrator before removing the current one.')
project_role.delete()
project = project_role.project
message = "The user {0} has been removed from the staff of project {1}.".format(project_role.user.standard_display_name(), project.name)
message = "The user {0} has been removed from the staff of project {1}.".format(project_role.user.standard_display_name, project.name)
NotificationService.add_multiuser_notification(ProjectService.get_project_members(request_user, project),
message,
NotificationSeverity.INFO,
Expand Down Expand Up @@ -650,7 +650,7 @@ def update_project_scope(request_user, projid, project_scope):
project_scope.creation_date = None
try:
project_scope.save()
message = "The project scope of project {0} was edited by {1}.".format(project.name, request_user.standard_display_name())
message = "The project scope of project {0} was edited by {1}.".format(project.name, request_user.standard_display_name)
NotificationService.add_multiuser_notification(ProjectService.get_project_members(request_user, project),
message,
NotificationSeverity.INFO,
Expand Down Expand Up @@ -1353,7 +1353,7 @@ def cancel_volunteering(request_user, projid, taskid, project_task_role):
project_task.accepting_volunteers = True
ProjectTaskService.save_task_internal(request_user, projid, taskid, project_task)
project = project_task.project
message = "The volunteer {0} working on task {1} of project {2} has canceled the work and has stopped volunteering in the project.".format(project_task_role.user.standard_display_name(), project_task.name, project.name)
message = "The volunteer {0} working on task {1} of project {2} has canceled the work and has stopped volunteering in the project.".format(project_task_role.user.standard_display_name, project_task.name, project.name)
NotificationService.add_multiuser_notification(ProjectService.get_project_members(request_user, project),
message,
NotificationSeverity.ERROR,
Expand Down Expand Up @@ -1389,7 +1389,7 @@ def apply_to_volunteer(request_user, projid, taskid, task_application_request):
task_application_request.volunteer = request_user
task_application_request.save()
project = project_task.project
message = "User {0} has applied to volunteer on task {1} of project {2}. Please review the application and accept or reject it as soon as possible.".format(task_application_request.volunteer.standard_display_name(), project_task.name, project.name)
message = "User {0} has applied to volunteer on task {1} of project {2}. Please review the application and accept or reject it as soon as possible.".format(task_application_request.volunteer.standard_display_name, project_task.name, project.name)
NotificationService.add_multiuser_notification(ProjectService.get_project_officials(request_user, project),
message,
NotificationSeverity.WARNING,
Expand Down Expand Up @@ -1485,7 +1485,7 @@ def accept_volunteer(request_user, projid, taskid, volunteer_application):
ProjectTaskService.save_volunteer_application(request_user, projid, taskid, volunteer_application)
project_task = volunteer_application.task
project = project_task.project
message = "The user {0} has been accepted as volunteer for task {1} of project {2}.".format(volunteer_application.volunteer.standard_display_name(), project_task.name, project.name)
message = "The user {0} has been accepted as volunteer for task {1} of project {2}.".format(volunteer_application.volunteer.standard_display_name, project_task.name, project.name)
NotificationService.add_multiuser_notification(ProjectService.get_project_members(request_user, project),
message,
NotificationSeverity.INFO,
Expand Down Expand Up @@ -1516,7 +1516,7 @@ def reject_volunteer(request_user, projid, taskid, volunteer_application):
ProjectTaskService.save_volunteer_application(request_user, projid, taskid, volunteer_application)
project_task = volunteer_application.task
project = project_task.project
message = "The user {0} has been rejected as volunteer for task {1} of project {2}.".format(volunteer_application.volunteer.standard_display_name(), project_task.name, project.name)
message = "The user {0} has been rejected as volunteer for task {1} of project {2}.".format(volunteer_application.volunteer.standard_display_name, project_task.name, project.name)
NotificationService.add_multiuser_notification(ProjectService.get_project_members(request_user, project),
message,
NotificationSeverity.INFO,
Expand Down Expand Up @@ -1687,7 +1687,7 @@ def save_project_task_role(request_user, projid, taskid, project_task_role):
if project_task.stage == TaskStatus.COMPLETED:
raise ValueError('Cannot edit the role of a completed task')
project_task_role.save()
message = "The volunteer {0} of project {1} has been assigned to the task {2}.".format(project_task_role.user.standard_display_name(), project.name, project_task.name)
message = "The volunteer {0} of project {1} has been assigned to the task {2}.".format(project_task_role.user.standard_display_name, project.name, project_task.name)
NotificationService.add_multiuser_notification(ProjectService.get_project_members(request_user, project),
message,
NotificationSeverity.INFO,
Expand All @@ -1714,7 +1714,7 @@ def delete_project_task_role(request_user, projid, taskid, project_task_role):
if project_task.stage == TaskStatus.COMPLETED:
raise ValueError('Cannot delete the role of a completed task')
project_task_role.delete()
message = "The volunteer {0} has been removed from task {1} of project {2}.".format(project_task_role.user.standard_display_name(), project_task.name, project.name)
message = "The volunteer {0} has been removed from task {1} of project {2}.".format(project_task_role.user.standard_display_name, project_task.name, project.name)
NotificationService.add_multiuser_notification(ProjectService.get_project_members(request_user, project),
message,
NotificationSeverity.INFO,
Expand Down Expand Up @@ -1804,7 +1804,7 @@ def publish_project_task(request_user, projid, taskid, project_task):
if project_task.stage == TaskStatus.DRAFT:
project_task.stage = TaskStatus.NOT_STARTED
project_task.save()
message = "The project task {0} from project {1} was published by {2}.".format(project_task.name, project.name, request_user.standard_display_name())
message = "The project task {0} from project {1} was published by {2}.".format(project_task.name, project.name, request_user.standard_display_name)
NotificationService.add_multiuser_notification(ProjectService.get_project_members(request_user, project),
message,
NotificationSeverity.WARNING,
Expand Down
2 changes: 1 addition & 1 deletion src/marketplace/models/proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ class ProjectTaskRole(models.Model):
)

def __str__(self):
return self.user.standard_display_name() + "-" + self.task.name + "-" + self.get_role_display()
return self.user.standard_display_name + "-" + self.task.name + "-" + self.get_role_display()

class Meta:
unique_together = ('user', 'task', 'role')
6 changes: 4 additions & 2 deletions src/marketplace/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ class User(AbstractUser):

objects = UserManager()

@property
def full_name(self):
return self.first_name + " " + self.last_name
return ' '.join(part for part in (self.first_name, self.last_name) if part)

@property
def standard_display_name(self):
return self.full_name() + "(" + self.username + ")"
return f'{self.full_name} ({self.username})' if self.full_name else self.username

def is_type_dssg_staff(self):
return self.initial_type == UserType.DSSG_STAFF
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% load include_redux %}

<span class="{% if badge.is_tier_basic %}badge-basic{% elif badge.is_tier_advanced %}badge-advanced{% elif badge.is_tier_master %}badge-master{% endif %}"
title="{% include 'marketplace/components/user_badge_text.html' %}">
title="{% include-stripped 'marketplace/components/user_badge_text.html' %}">
{% if badge.is_type_work_speed %}
<i class="fas fa-crown"></i>
{% elif badge.is_type_early_user %}
Expand Down
17 changes: 11 additions & 6 deletions src/marketplace/templates/marketplace/components/user_display.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{% if not hide_anchor %}<a href="{% url 'marketplace:user_profile' user.id %}">{% endif %}
{{ user.first_name }}
{{ user.last_name }}
{% if not hide_username %}

{% if user.full_name %}
{{ user.full_name }}
{% if include_username|default_if_none:True %}
({{ user.username }})
{% endif %}
{% else %}
{{ user.username }}
{% endif %}

{% for badge in user.userbadge_set.all %}
{% include 'marketplace/components/user_badge.html' with badge=badge compact_display=True %}
{% endfor %}

{% for badge in user.userbadge_set.all %}
{% include 'marketplace/components/user_badge.html' with badge=badge compact_display=True %}
{% endfor %}
{% if not hide_anchor %}</a>{% endif %}
8 changes: 4 additions & 4 deletions src/marketplace/templates/marketplace/org_staff.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h4 class="section-header">
<thead>
<tr>
<th>Full name</th>
{# <th>Email address</th> #}
<th>Email address</th>
<th>Role</th>
<th>Member since</th>
{% if user_is_administrator %}
Expand All @@ -28,7 +28,7 @@ <h4 class="section-header">
{% for staff in organization_staff %}
<tr>
<td>{% include 'marketplace/components/user_display.html' with user=staff.user %}</td>
{# <td><a href="{% url 'marketplace:user_profile' staff.user.id %}">{{ staff.user.email }}</a></td> #}
<td><a href="mailto:{{ staff.user.email }}">{{ staff.user.email }}</a></td>
<td>{{ staff.get_role_display }}</td>
<td>{{ staff.creation_date }}</td>
{% if user_is_administrator %}
Expand Down Expand Up @@ -166,7 +166,7 @@ <h4 class="section-header">Organization membership requests</h4>
<thead>
<tr>
<th>Full name</th>
{# <th>Email address</th> #}
<th>Email address</th>
<th>Request date</th>
<th>Status</th>
<th>Resolution date</th>
Expand All @@ -176,7 +176,7 @@ <h4 class="section-header">Organization membership requests</h4>
{% for request in organization_requests %}
<tr>
<td>{% include 'marketplace/components/user_display.html' with user=request.user %}</td>
{# <td><a href="{% url 'marketplace:user_profile' request.user.id %}">{{ request.user.email }}</a></td> #}
<td><a href="mailto:{{ request.user.email }}">{{ request.user.email }}</a></td>
<td>{{ request.request_date }}</td>
<td>
<a href="{% url 'marketplace:org_staff_request_review' organization.id request.id %}"
Expand Down
3 changes: 2 additions & 1 deletion src/marketplace/templates/marketplace/org_staff_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ <h4 class="section-header">
{% endif %}
</h4>
<p>User: {% include 'marketplace/components/user_display.html' with user=organizationrole.user %}</p>
{# <p>Email: {{ organizationrole.user.email }}</p> #}
<p>Email: <a href="mailto:{{ organizationrole.user.email }}">{{ organizationrole.user.email }}</a></p>

{% csrf_token %}
{% include 'marketplace/components/standard_form_fields.html' %}

Expand Down
4 changes: 3 additions & 1 deletion src/marketplace/templates/marketplace/org_staff_remove.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ <h4 class="section-header">
Remove staff member
{% endif %}
</h4>

<p>User: {% include 'marketplace/components/user_display.html' with user=organizationrole.user %}</p>
{# <p>Email: {{ organizationrole.user.email }}</p> #}
<p>Email: <a href="mailto:{{ organizationrole.user.email }}">{{ organizationrole.user.email }}</a></p>

{% csrf_token %}
{% include 'marketplace/components/standard_form_fields.html' %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ <h4 class="section-header">Membership request review</h4>
application and accept or reject it.</p>

<p>User: {% include 'marketplace/components/user_display.html' with user=organizationmembershiprequest.user %}</p>
{% comment %} <p>Email addres:<a href="{% url 'marketplace:user_profile' organizationmembershiprequest.user.id %}">
{{ organizationmembershiprequest.user.email }}</a></p> {% endcomment %}
<p>Email: <a href="mailto:{{ organizationmembershiprequest.user.email }}">
{{ organizationmembershiprequest.user.email }}
</a></p>
<p>Request date: {{ organizationmembershiprequest.request_date }} </p>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/marketplace/templates/marketplace/proj_staff.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h4 class="section-header">Staff members</h4>
<thead>
<tr>
<th>Full name</th>
{# <th>Email address</th> #}
<th>Email address</th>
<th>Role</th>
{% if perm_staff_edit %}
<th></th>
Expand All @@ -27,7 +27,7 @@ <h4 class="section-header">Staff members</h4>
{% for staff in project_staff %}
<tr>
<td>{% include 'marketplace/components/user_display.html' with user=staff.user %}</td>
{# <td><a href="{% url 'marketplace:user_profile' staff.user.id %}">{{ staff.user.email }}</a></td> #}
<td><a href="mailto:{{ staff.user.email }}">{{ staff.user.email }}</a></td>
<td>{{ staff.get_role_display }}</td>
{% if perm_staff_edit %}
<td>
Expand Down
3 changes: 2 additions & 1 deletion src/marketplace/templates/marketplace/proj_staff_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<form id="editstaff">
<h4 class="section-header">Edit staff member</h4>
<p>User: {% include 'marketplace/components/user_display.html' with user=projectrole.user %}</p>
{# <p>Email: {{ projectrole.user.email }}</p> #}
<p>Email: <a href="mailto:{{ projectrole.user.email }}">{{ projectrole.user.email }}</a></p>

{% csrf_token %}
{% include 'marketplace/components/standard_form_fields.html' %}

Expand Down
3 changes: 2 additions & 1 deletion src/marketplace/templates/marketplace/proj_staff_remove.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<form id="removestaff">
<h4 class="section-header">Remove staff member</h4>
<p>User: {% include 'marketplace/components/user_display.html' with user=projectrole.user %}</p>
{# <p>Email: {{ projectrole.user.email }}</p> #}
<p>Email: <a href="mailto:{{ projectrole.user.email }}">{{ projectrole.user.email }}</a></p>

{% csrf_token %}
{% include 'marketplace/components/standard_form_fields.html' %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<h4 class="section-header">Volunteer application</h4>
<p>This person has applied to volunteer in your project.</p>

<p>User:{% include 'marketplace/components/user_display.html' with user=volunteerapplication.volunteer %}</p>
{# <p>Email addres:<a href="">{{ volunteerapplication.volunteer.email }}</a></p> #}
<p>Application date: {{ volunteerapplication.application_date }} </p>
<p>User: {% include 'marketplace/components/user_display.html' with user=volunteerapplication.volunteer %}</p>
<p>Email: <a href="mailto:{{ volunteerapplication.volunteer.email }}">{{ volunteerapplication.volunteer.email }}</a></p>
<p>Application date: {{ volunteerapplication.application_date }}</p>
<p>Task: {{ volunteerapplication.task.name }}</p>
<h4>Volunteer application letter</h4>
<p>{{ volunteerapplication.volunteer_application_letter|markdown }}</p>
Expand Down
Loading

0 comments on commit 17f86f3

Please sign in to comment.