mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Split identities export by type
Different exports for account and alias types.
This commit is contained in:
@@ -6,8 +6,8 @@ export default {
|
||||
getAll() {
|
||||
return repository.get(`${resource}/`)
|
||||
},
|
||||
exportAll() {
|
||||
return repository.get(`/${resource}/export/`)
|
||||
exportAll(type) {
|
||||
return repository.get(`/${resource}/export/`, { params: { type } })
|
||||
},
|
||||
importFromCSV(data) {
|
||||
return repository.post(`/${resource}/import/`, data, {
|
||||
|
||||
@@ -551,6 +551,7 @@ onMounted(() => {
|
||||
|
||||
defineExpose({
|
||||
fetchIdentities,
|
||||
identityType,
|
||||
})
|
||||
|
||||
fetchIdentities = debounce(fetchIdentities, 500)
|
||||
|
||||
@@ -104,7 +104,7 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
import identitiesApi from '@/api/identities'
|
||||
@@ -124,8 +124,8 @@ const importForm = ref()
|
||||
const idList = ref()
|
||||
|
||||
function exportIdentities() {
|
||||
identitiesApi.exportAll().then((resp) => {
|
||||
exportContent(resp.data, 'identities', $gettext)
|
||||
identitiesApi.exportAll(idList.value.identityType).then((resp) => {
|
||||
exportContent(resp.data, `${idList.value.identityType}-list`, $gettext)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -653,6 +653,22 @@ dlist; dlist@test.com; True; user1@test.com; user@extdomain.com
|
||||
received_content[0] = ",".join(admin_row)
|
||||
self.assertCountEqual(expected_response.strip().split("\r\n"), received_content)
|
||||
|
||||
def test_export_accounts(self):
|
||||
response = self.client.get(f"{reverse('v2:identities-export')}?type=account")
|
||||
expected_response = "account,admin,,,,True,SuperAdmins,,\r\naccount,admin@test.com,{PLAIN}toto,,,True,DomainAdmins,admin@test.com,10,test.com\r\naccount,admin@test2.com,{PLAIN}toto,,,True,DomainAdmins,admin@test2.com,10,test2.com\r\naccount,user@test.com,{PLAIN}toto,,,True,SimpleUsers,user@test.com,10\r\naccount,user@test2.com,{PLAIN}toto,,,True,SimpleUsers,user@test2.com,10\r\n" # NOQA:E501
|
||||
received_content = force_str(response.content.strip()).split("\r\n")
|
||||
# Empty admin password because it is hashed using SHA512-CRYPT
|
||||
admin_row = received_content[0].split(",")
|
||||
admin_row[2] = ""
|
||||
received_content[0] = ",".join(admin_row)
|
||||
self.assertCountEqual(expected_response.strip().split("\r\n"), received_content)
|
||||
|
||||
def test_export_aliases(self):
|
||||
response = self.client.get(f"{reverse('v2:identities-export')}?type=alias")
|
||||
expected_response = "alias,alias@test.com,True,user@test.com\r\nalias,forward@test.com,True,user@external.com\r\nalias,postmaster@test.com,True,test@truc.fr,toto@titi.com\r\n" # NOQA:E501
|
||||
received_content = force_str(response.content.strip()).split("\r\n")
|
||||
self.assertCountEqual(expected_response.strip().split("\r\n"), received_content)
|
||||
|
||||
|
||||
class AliasViewSetTestCase(ModoAPITestCase):
|
||||
@classmethod
|
||||
|
||||
@@ -240,7 +240,8 @@ class IdentityViewSet(GetThrottleViewsetMixin, viewsets.ViewSet):
|
||||
def export(self, request, **kwargs):
|
||||
"""Export accounts and aliases to CSV."""
|
||||
result = []
|
||||
for idt in lib.get_identities(request.user):
|
||||
idtfilter = request.GET.get("type")
|
||||
for idt in lib.get_identities(request.user, idtfilter=idtfilter):
|
||||
result.append(idt.to_csv_row())
|
||||
return response.Response(result)
|
||||
|
||||
|
||||
@@ -31,7 +31,12 @@ from . import signals
|
||||
from .models import Alias, Domain, DomainAlias
|
||||
|
||||
|
||||
def get_identities(user, searchquery=None, idtfilter=None, grpfilter=None):
|
||||
def get_identities(
|
||||
user: User,
|
||||
searchquery: str | None = None,
|
||||
idtfilter: str | None = None,
|
||||
grpfilter: str | None = None,
|
||||
) -> chain:
|
||||
"""Return all the identities owned by a user.
|
||||
|
||||
:param user: the desired user
|
||||
|
||||
Reference in New Issue
Block a user