Fix #548: Mods can now change a library visibility through the admin UI

environments/review-docs-rate-jr6phc/deployments/2479
Eliot Berriot 2019-07-25 14:14:44 +02:00
rodzic c885c10be1
commit 4d0fedab1f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: DD6965E2476E5C27
5 zmienionych plików z 55 dodań i 2 usunięć

Wyświetl plik

@ -500,6 +500,15 @@ class ManageLibrarySerializer(serializers.ModelSerializer):
"followers_url", "followers_url",
"actor", "actor",
] ]
read_only_fields = [
"fid",
"uuid",
"id",
"url",
"domain",
"actor",
"creation_date",
]
def get_uploads_count(self, obj): def get_uploads_count(self, obj):
return getattr(obj, "_uploads_count", obj.uploads_count) return getattr(obj, "_uploads_count", obj.uploads_count)

Wyświetl plik

@ -200,6 +200,7 @@ follows_subquery = (
class ManageLibraryViewSet( class ManageLibraryViewSet(
mixins.ListModelMixin, mixins.ListModelMixin,
mixins.RetrieveModelMixin, mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin, mixins.DestroyModelMixin,
viewsets.GenericViewSet, viewsets.GenericViewSet,
): ):

Wyświetl plik

@ -322,6 +322,18 @@ def test_library_detail(factories, superuser_api_client):
assert response.data["id"] == library.id assert response.data["id"] == library.id
def test_library_update(factories, superuser_api_client):
library = factories["music.Library"](privacy_level="public")
url = reverse(
"api:v1:manage:library:libraries-detail", kwargs={"uuid": library.uuid}
)
response = superuser_api_client.patch(url, {"privacy_level": "me"})
assert response.status_code == 200
library.refresh_from_db()
assert library.privacy_level == "me"
def test_library_detail_stats(factories, superuser_api_client): def test_library_detail_stats(factories, superuser_api_client):
library = factories["music.Library"]() library = factories["music.Library"]()
url = reverse( url = reverse(

Wyświetl plik

@ -0,0 +1 @@
Mods can now change a library visibility through the admin UI (#548)

Wyświetl plik

@ -96,7 +96,16 @@
</router-link> </router-link>
</td> </td>
<td> <td>
{{ sharedLabels.fields.privacy_level.shortChoices[object.privacy_level] }} <select
v-dropdown
v-if="object.is_local"
@change="updateObj('privacy_level')"
v-model="object.privacy_level"
class="ui search selection dropdown">
<option v-for="p in ['me', 'instance', 'everyone']" :value="p">{{ sharedLabels.fields.privacy_level.shortChoices[p] }}</option>
</select>
<template v-else>{{ sharedLabels.fields.privacy_level.shortChoices[object.privacy_level] }}</template>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -308,7 +317,28 @@ export default {
}, },
getQuery (field, value) { getQuery (field, value) {
return `${field}:"${value}"` return `${field}:"${value}"`
} },
updateObj(attr, toNull) {
let newValue = this.object[attr]
if (toNull && !newValue) {
newValue = null
}
let params = {}
params[attr] = newValue
axios.patch(`manage/library/libraries/${this.id}/`, params).then(
response => {
logger.default.info(
`${attr} was updated succcessfully to ${newValue}`
)
},
error => {
logger.default.error(
`Error while setting ${attr} to ${newValue}`,
error
)
}
)
},
}, },
computed: { computed: {
labels() { labels() {