From dc5db3a0c1a27b5c02c3a080b5bdc7618c6de5f8 Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Thu, 27 Jun 2019 14:50:56 +0200
Subject: [PATCH] Fix #869: broken user admin for users with non-digit or
 letters in their username

---
 api/funkwhale_api/manage/serializers.py          | 6 ++++++
 api/funkwhale_api/manage/views.py                | 2 +-
 changes/changelog.d/869.bugfix                   | 1 +
 front/src/components/manage/users/UsersTable.vue | 3 ++-
 4 files changed, 10 insertions(+), 2 deletions(-)
 create mode 100644 changes/changelog.d/869.bugfix

diff --git a/api/funkwhale_api/manage/serializers.py b/api/funkwhale_api/manage/serializers.py
index add9364e86..a9b19939d8 100644
--- a/api/funkwhale_api/manage/serializers.py
+++ b/api/funkwhale_api/manage/serializers.py
@@ -44,12 +44,14 @@ class ManageUserSimpleSerializer(serializers.ModelSerializer):
 class ManageUserSerializer(serializers.ModelSerializer):
     permissions = PermissionsSerializer(source="*")
     upload_quota = serializers.IntegerField(allow_null=True)
+    actor = serializers.SerializerMethodField()
 
     class Meta:
         model = users_models.User
         fields = (
             "id",
             "username",
+            "actor",
             "email",
             "name",
             "is_active",
@@ -82,6 +84,10 @@ class ManageUserSerializer(serializers.ModelSerializer):
             )
         return instance
 
+    def get_actor(self, obj):
+        if obj.actor:
+            return ManageBaseActorSerializer(obj.actor).data
+
 
 class ManageInvitationSerializer(serializers.ModelSerializer):
     users = ManageUserSimpleSerializer(many=True, required=False)
diff --git a/api/funkwhale_api/manage/views.py b/api/funkwhale_api/manage/views.py
index 83981116c5..6e4edc888b 100644
--- a/api/funkwhale_api/manage/views.py
+++ b/api/funkwhale_api/manage/views.py
@@ -291,7 +291,7 @@ class ManageUserViewSet(
     mixins.UpdateModelMixin,
     viewsets.GenericViewSet,
 ):
-    queryset = users_models.User.objects.all().order_by("-id")
+    queryset = users_models.User.objects.all().select_related("actor").order_by("-id")
     serializer_class = serializers.ManageUserSerializer
     filterset_class = filters.ManageUserFilterSet
     required_scope = "instance:users"
diff --git a/changes/changelog.d/869.bugfix b/changes/changelog.d/869.bugfix
new file mode 100644
index 0000000000..7d56f3175a
--- /dev/null
+++ b/changes/changelog.d/869.bugfix
@@ -0,0 +1 @@
+Fixed broken user admin for users with non-digit or letters in their username (#869)
diff --git a/front/src/components/manage/users/UsersTable.vue b/front/src/components/manage/users/UsersTable.vue
index ee1d3110b2..a508f5be94 100644
--- a/front/src/components/manage/users/UsersTable.vue
+++ b/front/src/components/manage/users/UsersTable.vue
@@ -45,7 +45,8 @@
         </template>
         <template slot="row-cells" slot-scope="scope">
           <td>
-            <router-link :to="{name: 'manage.moderation.accounts.detail', params: {id: scope.obj.full_username }}">{{ scope.obj.username }}</router-link>
+            <router-link v-if="scope.obj.actor" :to="{name: 'manage.moderation.accounts.detail', params: {id: scope.obj.actor.full_username }}">{{ scope.obj.username }}</router-link>
+            <router-link v-else :to="{name: 'manage.moderation.accounts.detail', params: {id: scope.obj.full_username }}">{{ scope.obj.username }}</router-link>
           </td>
           <td>
             <span>{{ scope.obj.email }}</span>
-- 
GitLab