1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-03 01:17:56 +03:00

Updated user and admin interfaces

Updated download logic
This commit is contained in:
Adolfo Gómez García 2024-09-26 17:05:51 +02:00
parent dca747969e
commit fa31a30ba2
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
10 changed files with 77 additions and 30 deletions

View File

@ -34,9 +34,11 @@ Author: Adolfo Gómez, dkmaster at dkmon dot com
import os
import logging
import typing
from wsgiref.util import FileWrapper
from django.http import HttpResponse, Http404, HttpRequest
from uds.core import types
from uds.core.managers.crypto import CryptoManager
from uds.core.util import singleton
@ -55,7 +57,7 @@ class DownloadsManager(metaclass=singleton.Singleton):
'application/x-msdos-program')
"""
_downloadables: dict[str, dict[str, str]] = {}
_downloadables: dict[str, types.downloads.Downloadable]
def __init__(self) -> None:
super().__init__()
@ -66,7 +68,7 @@ class DownloadsManager(metaclass=singleton.Singleton):
# Singleton pattern will return always the same instance
return DownloadsManager()
def register(self, name: str, comment: str, path: str, mime: str = 'application/octet-stream') -> None:
def register(self, name: str, description: str, path: str, *, mimetype: str = 'application/octet-stream', legacy: bool = False) -> None:
"""
Registers a downloadable file.
@param name: name shown
@ -74,14 +76,15 @@ class DownloadsManager(metaclass=singleton.Singleton):
@params zip: If download as zip
"""
_id = CryptoManager.manager().uuid(name)
self._downloadables[_id] = {
'name': name,
'comment': comment,
'path': path,
'mime': mime,
}
self._downloadables[_id] = types.downloads.Downloadable(
name=name,
description=description,
path=path,
mimetype=mimetype,
legacy=legacy,
)
def downloadables(self) -> dict[str, dict[str, str]]:
def downloadables(self) -> typing.Mapping[str, types.downloads.Downloadable]:
return self._downloadables
def send(self, request: 'HttpRequest', _id: str) -> HttpResponse:
@ -90,9 +93,9 @@ class DownloadsManager(metaclass=singleton.Singleton):
raise Http404
return self._send_file(
request,
self._downloadables[_id]['name'],
self._downloadables[_id]['path'],
self._downloadables[_id]['mime'],
self._downloadables[_id].name,
self._downloadables[_id].path,
self._downloadables[_id].mimetype,
)
def _send_file(self, request: 'HttpRequest', name: str, filename: str, mime: str) -> HttpResponse:

View File

@ -34,6 +34,7 @@ from . import (
auth,
calendar,
connections,
downloads,
errors,
os,
permissions,

View File

@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2024 Virtual Cable S.L.U.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Virtual Cable S.L.U. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
Author: Adolfo Gómez, dkmaster at dkmon dot com
"""
import dataclasses
@dataclasses.dataclass
class Downloadable:
name: str
description: str
path: str
mimetype: str
legacy: bool

View File

@ -52,14 +52,14 @@ downloads_manager().register(
f'udsactor_{VERSION}_all.deb',
_('UDS Actor for Debian, Ubuntu, ... Linux machines <b>(Requires python >= 3.9)</b>'),
_mypath + f'/files/udsactor_{VERSION}_all.deb',
'application/x-debian-package',
mimetype='application/x-debian-package',
)
downloads_manager().register(
f'udsactor-{VERSION}-1.noarch.rpm',
_('UDS Actor for Centos, Fedora, RH, Suse, ... Linux machines <b>(Requires python >= 3.9)</b>'),
_mypath + f'/files/udsactor-{VERSION}-1.noarch.rpm',
'application/x-redhat-package-manager',
mimetype='application/x-redhat-package-manager',
)
downloads_manager().register(
@ -68,7 +68,7 @@ downloads_manager().register(
'UDS Actor for Debian based Linux machines. Used ONLY for static machines. <b>(Requires python >= 3.9)</b>'
),
_mypath + f'/files/udsactor-unmanaged_{VERSION}_all.deb',
'application/x-debian-package',
mimetype='application/x-debian-package',
)
downloads_manager().register(
@ -77,6 +77,6 @@ downloads_manager().register(
'UDS Actor for Centos, Fedora, RH, Suse, ... Linux machines. Used ONLY for static machines. <b>(Requires python >= 3.9)</b>'
),
_mypath + f'/files/udsactor-unmanaged-{VERSION}-1.noarch.rpm',
'application/x-redhat-package-manager',
mimetype='application/x-redhat-package-manager',
)

View File

@ -51,12 +51,12 @@ managers.downloads_manager().register(
f'UDSActorSetup-{VERSION}.exe',
_('UDS Actor for windows machines'),
_mypath + f'/files/UDSActorSetup-{VERSION}.exe',
'application/vnd.microsoft.portable-executable',
mimetype='application/vnd.microsoft.portable-executable',
)
managers.downloads_manager().register(
f'UDSActorUnmanagedSetup-{VERSION}.exe',
_('UDS Actor for Unmanaged windows machines. Used ONLY for static machines.'),
_mypath + f'/files/UDSActorUnmanagedSetup-{VERSION}.exe',
'application/vnd.microsoft.portable-executable',
mimetype='application/vnd.microsoft.portable-executable',
)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -102,6 +102,6 @@
</svg>
</div>
</uds-root>
<link rel="modulepreload" href="/uds/res/admin/chunk-73GRIXMY.js?stamp=1726504179" integrity="sha384-Fpv0IdDryEri8NL538mQTvQZuUECB0hfUOg4tD6kZBiqZQ3FcrF5c0zhJzv7Jo4U"><script src="/uds/res/admin/polyfills.js?stamp=1726504179" type="module" crossorigin="anonymous" integrity="sha384-TVRkn44wOGJBeCKWJBHWLvXubZ+Julj/yA0OoEFa3LgJHVHaPeeATX6NcjuNgsIA"></script><script src="/uds/res/admin/main.js?stamp=1726504179" type="module" crossorigin="anonymous" integrity="sha384-nCeugctkRurEmWqhkTrHftQYKE7YgvMaq4t6/6LGfAqiwhIjzH5UbXdR6abHAN0S"></script></body>
<link rel="modulepreload" href="/uds/res/admin/chunk-73GRIXMY.js?stamp=1727363038" integrity="sha384-Fpv0IdDryEri8NL538mQTvQZuUECB0hfUOg4tD6kZBiqZQ3FcrF5c0zhJzv7Jo4U"><script src="/uds/res/admin/polyfills.js?stamp=1727363038" type="module" crossorigin="anonymous" integrity="sha384-TVRkn44wOGJBeCKWJBHWLvXubZ+Julj/yA0OoEFa3LgJHVHaPeeATX6NcjuNgsIA"></script><script src="/uds/res/admin/main.js?stamp=1727363038" type="module" crossorigin="anonymous" integrity="sha384-yoO6CHaYaHwauEU0EYuLYArKCtNaiUuN4QzkRFDc85sAz6zv/DTY5bTob6pwBEe9"></script></body>
</html>

View File

@ -109,6 +109,6 @@
</svg>
</div>
</uds-root>
<script src="/uds/res/modern/polyfills.js" type="module" crossorigin="anonymous" integrity="sha384-gjZXw6bYB+td6SIdruY5JyqQBkqxY+puwSPNXlrc1Fu5fcv6y+sthRBgUlAL3EJp"></script><script src="/uds/res/modern/scripts.js" defer crossorigin="anonymous" integrity="sha384-gJ6CPuwXlJNL6wOYMLzD98cFi988rpY6Ln6S+UhAkZs84+MOQ+ws+0qgV4WicE5i"></script><script src="/uds/res/modern/main.js" type="module" crossorigin="anonymous" integrity="sha384-3VkmDnTsGPF2e/Fj+vdKHFJYmtxfimxEzlMUwma8aXpzQqcEwxRX2xpD4d+TOzp1"></script></body>
<script src="/uds/res/modern/polyfills.js" type="module" crossorigin="anonymous" integrity="sha384-gjZXw6bYB+td6SIdruY5JyqQBkqxY+puwSPNXlrc1Fu5fcv6y+sthRBgUlAL3EJp"></script><script src="/uds/res/modern/scripts.js" defer crossorigin="anonymous" integrity="sha384-gJ6CPuwXlJNL6wOYMLzD98cFi988rpY6Ln6S+UhAkZs84+MOQ+ws+0qgV4WicE5i"></script><script src="/uds/res/modern/main.js" type="module" crossorigin="anonymous" integrity="sha384-VOPdy8egqxyAkOsPhDQQ1AJbecy42gTvZxEEk7hXnl7NXz2BVEUg8+9NyBgVBXgm"></script></body>
</html>

View File

@ -185,7 +185,7 @@ def uds_js(request: 'ExtendedHttpRequest') -> str:
('UDSClient-{version}.pkg', gettext('Mac OS X client'), 'MacOS', False),
(
'udsclient3_{version}_all.deb',
gettext('Debian based Linux client') + ' ' + gettext('(requires Python-3.6 or newer)'),
gettext('Debian based Linux client') + ' ' + gettext('(requires Python-3.9 or newer)'),
'Linux',
False,
),
@ -193,7 +193,7 @@ def uds_js(request: 'ExtendedHttpRequest') -> str:
'udsclient3-{version}-1.noarch.rpm',
gettext('RPM based Linux client (Fedora, Suse, ...)')
+ ' '
+ gettext('(requires Python-3.6 or newer)'),
+ gettext('(requires Python-3.9 or newer)'),
'Linux',
False,
),
@ -205,13 +205,13 @@ def uds_js(request: 'ExtendedHttpRequest') -> str:
),
(
'udsclient3-armhf-{version}.tar.gz',
gettext('Binary appimage Raspberry Linux client'),
gettext('Binary appimage ARMHF Linux client (Raspberry, ...)'),
'Linux',
False,
),
(
'udsclient3-{version}.tar.gz',
gettext('Generic .tar.gz Linux client') + ' ' + gettext('(requires Python-3.6 or newer)'),
gettext('Generic .tar.gz Linux client') + ' ' + gettext('(requires Python-3.9 or newer)'),
'Linux',
False,
),
@ -226,7 +226,7 @@ def uds_js(request: 'ExtendedHttpRequest') -> str:
# 'legacy': False # True = Gray, False = White
# })
actors: list[dict[str, str]] = []
actors: list[dict[str, str|bool]] = []
if user and user.is_staff(): # Add staff things
# If is admin (informational, REST api checks users privileges anyway...)
@ -238,8 +238,9 @@ def uds_js(request: 'ExtendedHttpRequest') -> str:
actors = [
{
'url': reverse('utility.downloader', kwargs={'download_id': key}),
'name': val['name'],
'description': gettext(val['comment']),
'name': val.name,
'description': val.description,
'legacy': val.legacy,
}
for key, val in downloads_manager().downloadables().items()
]