forked from shaba/openuds
added "remove all assigned user services" as an action
This commit is contained in:
parent
aee5b4501a
commit
7c37d37418
@ -52,7 +52,6 @@ logger = logging.getLogger(__name__)
|
||||
ALLOW = 'ALLOW'
|
||||
DENY = 'DENY'
|
||||
|
||||
|
||||
class AccessCalendars(DetailHandler):
|
||||
@staticmethod
|
||||
def as_dict(item: 'CalendarAccess'):
|
||||
|
@ -46,6 +46,7 @@ from uds.models.calendar_action import (
|
||||
CALENDAR_ACTION_ADD_GROUP,
|
||||
CALENDAR_ACTION_DEL_GROUP,
|
||||
CALENDAR_ACTION_IGNORE_UNUSED,
|
||||
CALENDAR_ACTION_REMOVE_USERSERVICES,
|
||||
)
|
||||
|
||||
from uds.core.managers import userServiceManager
|
||||
@ -472,7 +473,7 @@ class ServicesPools(ModelHandler):
|
||||
validActions += (CALENDAR_ACTION_ADD_TRANSPORT, CALENDAR_ACTION_DEL_TRANSPORT, CALENDAR_ACTION_ADD_GROUP, CALENDAR_ACTION_DEL_GROUP)
|
||||
|
||||
# Advanced actions
|
||||
validActions += (CALENDAR_ACTION_IGNORE_UNUSED,)
|
||||
validActions += (CALENDAR_ACTION_IGNORE_UNUSED, CALENDAR_ACTION_REMOVE_USERSERVICES)
|
||||
return validActions
|
||||
|
||||
def listAssignables(self, item: ServicePool) -> typing.Any:
|
||||
|
@ -66,6 +66,7 @@ CALENDAR_ACTION_DEL_TRANSPORT = {'id': 'REMOVE_TRANSPORT', 'description': _('Rem
|
||||
CALENDAR_ACTION_ADD_GROUP = {'id': 'ADD_GROUP', 'description': _('Add a group'), 'params': ({'type': 'group', 'name': 'group', 'description': _('Group'), 'default': ''},)}
|
||||
CALENDAR_ACTION_DEL_GROUP = {'id': 'REMOVE_GROUP', 'description': _('Remove a group'), 'params': ({'type': 'group', 'name': 'group', 'description': _('Group'), 'default': ''},)}
|
||||
CALENDAR_ACTION_IGNORE_UNUSED = {'id': 'IGNORE_UNUSED', 'description': _('Sets the ignore unused'), 'params': ({'type': 'bool', 'name': 'state', 'description': _('Ignore assigned and unused'), 'default': False},)}
|
||||
CALENDAR_ACTION_REMOVE_USERSERVICES = {'id': 'REMOVE_USERSERVICES', 'description': _('Remove ALL assigned user service. USE WITH CAUTION!'), 'params': ()}
|
||||
|
||||
|
||||
CALENDAR_ACTION_DICT: typing.Dict[str, typing.Dict] = {c['id']: c for c in (
|
||||
@ -74,7 +75,8 @@ CALENDAR_ACTION_DICT: typing.Dict[str, typing.Dict] = {c['id']: c for c in (
|
||||
CALENDAR_ACTION_MAX,
|
||||
CALENDAR_ACTION_ADD_TRANSPORT, CALENDAR_ACTION_DEL_TRANSPORT,
|
||||
CALENDAR_ACTION_ADD_GROUP, CALENDAR_ACTION_DEL_GROUP,
|
||||
CALENDAR_ACTION_IGNORE_UNUSED
|
||||
CALENDAR_ACTION_IGNORE_UNUSED,
|
||||
CALENDAR_ACTION_REMOVE_USERSERVICES
|
||||
)}
|
||||
|
||||
|
||||
@ -171,6 +173,8 @@ class CalendarAction(UUIDModel):
|
||||
executed = True
|
||||
elif CALENDAR_ACTION_IGNORE_UNUSED['id'] == self.action:
|
||||
self.service_pool.ignores_unused = params['state'] in ('true', '1', True)
|
||||
elif CALENDAR_ACTION_REMOVE_USERSERVICES:
|
||||
self.service_pool.assignedUserServices().delete()
|
||||
else:
|
||||
caTransports = (CALENDAR_ACTION_ADD_TRANSPORT['id'], CALENDAR_ACTION_DEL_TRANSPORT['id'])
|
||||
caGroups = (CALENDAR_ACTION_ADD_GROUP['id'], CALENDAR_ACTION_DEL_GROUP['id'])
|
||||
|
@ -63,6 +63,7 @@ from .util import getSqlDatetime
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds.models import UserService, ServicePoolPublication, User, Group, Proxy
|
||||
from django.db.models import QuerySet
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -471,7 +472,7 @@ class ServicePool(UUIDModel, TaggingMixin): # type: ignore
|
||||
if pub:
|
||||
pub.unpublish()
|
||||
|
||||
def cachedUserServices(self):
|
||||
def cachedUserServices(self) -> 'QuerySet':
|
||||
"""
|
||||
':rtype uds.models.user_service.UserService'
|
||||
Utility method to access the cached user services (level 1 and 2)
|
||||
@ -481,7 +482,7 @@ class ServicePool(UUIDModel, TaggingMixin): # type: ignore
|
||||
"""
|
||||
return self.userServices.exclude(cache_level=0)
|
||||
|
||||
def assignedUserServices(self):
|
||||
def assignedUserServices(self) -> 'QuerySet':
|
||||
"""
|
||||
Utility method to access the assigned user services
|
||||
|
||||
@ -490,7 +491,7 @@ class ServicePool(UUIDModel, TaggingMixin): # type: ignore
|
||||
"""
|
||||
return self.userServices.filter(cache_level=0)
|
||||
|
||||
def erroneousUserServices(self):
|
||||
def erroneousUserServices(self) -> 'QuerySet':
|
||||
"""
|
||||
Utility method to locate invalid assigned user services.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user