The most basic of 'onboarding', as it pertains to teams

This commit is contained in:
Klaas van Schelven
2024-06-06 10:54:56 +02:00
parent beef63b5d5
commit 004b586e2d
4 changed files with 18 additions and 19 deletions

View File

@@ -13,7 +13,7 @@ def home(request):
project_count = request.user.project_set.all().count()
if project_count == 0:
raise NotImplementedError("Onboarding not implemented yet")
return redirect("team_list")
elif project_count == 1:
project = request.user.project_set.get()

View File

@@ -6,6 +6,7 @@ from .views import (
urlpatterns = [
path('', team_list, name="team_list"),
path('mine/', team_list, kwargs={"ownership_filter": "mine"}, name="team_list_mine"),
path('other/', team_list, kwargs={"ownership_filter": "other"}, name="team_list_other"),
path('new/', team_new, name="team_new"),
path('<str:team_pk>/edit/', team_edit, name="team_edit"),

View File

@@ -22,7 +22,18 @@ from .tasks import send_team_invite_email, send_team_invite_email_new_user
User = get_user_model()
def team_list(request, ownership_filter="mine"):
def team_list(request, ownership_filter=None):
my_memberships = TeamMembership.objects.filter(user=request.user)
my_teams = Team.objects.filter(teammembership__in=my_memberships)
other_teams = Team.objects.exclude(teammembership__in=my_memberships).distinct() # TODO visibility-check
if ownership_filter is None:
# if no tab is provided, we redirect to the most informative one. generally we prefer "mine", but not when empty
if my_teams.exists() or not other_teams.exists():
# "or not other": if there are no teams at all, an empty "mine" is more informative than an empty "other"
return redirect('team_list_mine')
return redirect('team_list_other')
if request.method == 'POST':
full_action_str = request.POST.get('action')
action, team_pk = full_action_str.split(":", 1)
@@ -37,12 +48,10 @@ def team_list(request, ownership_filter="mine"):
TeamMembership.objects.create(team_id=team_pk, user_id=request.user.id, role=TeamRole.MEMBER, accepted=True)
return redirect('team_member_settings', team_pk=team_pk, user_pk=request.user.id)
my_memberships = TeamMembership.objects.filter(user=request.user)
if ownership_filter == "mine":
base_qs = Team.objects.filter(teammembership__in=my_memberships)
base_qs = my_teams
elif ownership_filter == "other":
base_qs = Team.objects.exclude(teammembership__in=my_memberships).distinct()
base_qs = other_teams
else:
raise ValueError("Invalid ownership_filter")

View File

@@ -15,19 +15,6 @@
<a href="/"><img src="{% static 'images/bugsink-logo.png' %}" class="p-2 h-12 w-12"></a>
<a href="/"><div class="pt-4 pb-4 pl-2 pr-2 font-bold">{{ site_title }}</div></a>
{# TODO how to handle single-org, single-project #}
<div class="dropdown">
<a href="TODO"><div class="p-4 hover:bg-slate-400">Group 1&nbsp;&nbsp;🞃 </div></a>
<div class="dropdown-content-left flex-col">
<a href="TODO"><div class="bg-slate-200 hover:bg-slate-400 p-4 whitespace-nowrap {% if project == loop_project %}italic{% endif %}">Group 1</div></a>
<a href="TODO"><div class="bg-slate-200 hover:bg-slate-400 p-4 whitespace-nowrap {% if project == loop_project %}italic{% endif %}">Group 2</div></a>
<a href="TODO"><div class="bg-slate-200 hover:bg-slate-400 p-4 whitespace-nowrap {% if project == loop_project %}italic{% endif %}">Group 3</div></a>
</div>
</div>
<div class="dropdown">
<a href="/issues/{{ project.id }}"><div class="p-4 hover:bg-slate-400">{{ project.name }}&nbsp;&nbsp;🞃 </div></a>
@@ -40,6 +27,8 @@
</div>
</div>
<a href="{% url "team_list" %}"><div class="p-4 hover:bg-slate-400">Teams</div></a>
<div class="ml-auto flex">
{% if user.is_staff %}
<a href="/admin/"><div class="p-4 hover:bg-slate-400">Admin</div></a>