Verified Commit 048339c7 authored by Agate's avatar Agate 💬

Fix #809: Added admin options to disable login for users, ensure related...

Fix #809: Added admin options to disable login for users, ensure related content is deleted when deleting a user account
parent 62a2d949
Pipeline #4041 passed with stages
in 3 minutes and 16 seconds
......@@ -33,6 +33,20 @@ class MyUserCreationForm(UserCreationForm):
raise forms.ValidationError(self.error_messages["duplicate_username"])
def disable(modeladmin, request, queryset):
queryset.exclude(pk=request.user.pk).update(is_active=False)
disable.short_description = "Disable login"
def enable(modeladmin, request, queryset):
queryset.update(is_active=True)
enable.short_description = "Enable login"
@admin.register(models.User)
class UserAdmin(AuthUserAdmin):
form = MyUserChangeForm
......@@ -40,6 +54,7 @@ class UserAdmin(AuthUserAdmin):
list_display = [
"username",
"email",
"is_active",
"date_joined",
"last_login",
"is_staff",
......@@ -53,7 +68,7 @@ class UserAdmin(AuthUserAdmin):
"permission_library",
"permission_moderation",
]
actions = [disable, enable]
fieldsets = (
(None, {"fields": ("username", "password", "privacy_level")}),
(
......
......@@ -388,3 +388,10 @@ def warm_user_avatar(sender, instance, **kwargs):
instance_or_queryset=instance, rendition_key_set="square", image_attr="avatar"
)
num_created, failed_to_create = user_avatar_warmer.warm()
@receiver(models.signals.pre_delete, sender=User)
def delete_actor(sender, instance, **kwargs):
if not instance.actor:
return
instance.actor.delete()
......@@ -219,3 +219,13 @@ def test_user_get_quota_status(factories, preferences, mocker):
"errored": 3,
"finished": 4,
}
def test_deleting_users_deletes_associated_actor(factories):
actor = factories["federation.Actor"]()
user = factories["users.User"](actor=actor)
user.delete()
with pytest.raises(actor.DoesNotExist):
actor.refresh_from_db()
Added admin options to disable login for users, ensure related content is deleted when deleting a user account (#809)
......@@ -27,6 +27,35 @@
</div>
</div>
</h2>
<div class="header-buttons">
<div class="ui icon buttons">
<a
v-if="object.user && $store.state.auth.profile && $store.state.auth.profile.is_superuser"
class="ui labeled icon button"
:href="$store.getters['instance/absoluteUrl'](`/api/admin/users/user/${object.user.id}`)"
target="_blank" rel="noopener noreferrer">
<i class="wrench icon"></i>
<translate translate-context="Content/Moderation/Link/Verb">View in Django's admin</translate>&nbsp;
</a>
<a
v-else-if="$store.state.auth.profile && $store.state.auth.profile.is_superuser"
class="ui labeled icon button"
:href="$store.getters['instance/absoluteUrl'](`/api/admin/federation/actor/${object.id}`)"
target="_blank" rel="noopener noreferrer">
<i class="wrench icon"></i>
<translate translate-context="Content/Moderation/Link/Verb">View in Django's admin</translate>&nbsp;
</a>
<div class="ui floating dropdown icon button" v-dropdown>
<i class="dropdown icon"></i>
<div class="menu">
<a class="basic item" :href="object.url || object.fid" target="_blank" rel="noopener noreferrer">
<i class="external icon"></i>
<translate translate-context="Content/Moderation/Link/Verb">Open remote profile</translate>&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="ui column">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment