mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-24 21:34:41 +03:00
updating rest
This commit is contained in:
commit
fbd7edf709
@ -87,7 +87,7 @@ class Users(DetailHandler):
|
||||
del v['uuid']
|
||||
yield v
|
||||
|
||||
def getItems(self, parent, item):
|
||||
def getItems(self, parent: Authenticator, item: typing.Optional[str]):
|
||||
logger.debug(item)
|
||||
# Extract authenticator
|
||||
try:
|
||||
@ -179,7 +179,7 @@ class Users(DetailHandler):
|
||||
def getRowStyle(self, parent):
|
||||
return {'field': 'state', 'prefix': 'row-state-'}
|
||||
|
||||
def getLogs(self, parent, item):
|
||||
def getLogs(self, parent: Authenticator, item: str):
|
||||
user = None
|
||||
try:
|
||||
user = parent.users.get(uuid=processUuid(item))
|
||||
@ -188,7 +188,7 @@ class Users(DetailHandler):
|
||||
|
||||
return log.getLogs(user)
|
||||
|
||||
def saveItem(self, parent, item):
|
||||
def saveItem(self, parent: Authenticator, item):
|
||||
logger.debug('Saving user %s / %s', parent, item)
|
||||
valid_fields = [
|
||||
'name',
|
||||
@ -250,7 +250,7 @@ class Users(DetailHandler):
|
||||
|
||||
return self.getItems(parent, user.uuid)
|
||||
|
||||
def deleteItem(self, parent, item):
|
||||
def deleteItem(self, parent: Authenticator, item: str):
|
||||
try:
|
||||
user = parent.users.get(uuid=processUuid(item))
|
||||
if not self._user.is_admin and (user.is_admin or user.staff_member):
|
||||
@ -279,7 +279,7 @@ class Users(DetailHandler):
|
||||
|
||||
return 'deleted'
|
||||
|
||||
def servicesPools(self, parent, item):
|
||||
def servicesPools(self, parent: Authenticator, item: str):
|
||||
uuid = processUuid(item)
|
||||
user = parent.users.get(uuid=processUuid(uuid))
|
||||
res = []
|
||||
@ -301,7 +301,7 @@ class Users(DetailHandler):
|
||||
|
||||
return res
|
||||
|
||||
def userServices(self, parent, item):
|
||||
def userServices(self, parent: Authenticator, item: str):
|
||||
uuid = processUuid(item)
|
||||
user = parent.users.get(uuid=processUuid(uuid))
|
||||
res = []
|
||||
@ -319,7 +319,7 @@ class Groups(DetailHandler):
|
||||
|
||||
custom_methods = ['servicesPools', 'users']
|
||||
|
||||
def getItems(self, parent, item):
|
||||
def getItems(self, parent: Authenticator, item: typing.Optional[str]):
|
||||
try:
|
||||
multi = False
|
||||
if item is None:
|
||||
@ -346,21 +346,21 @@ class Groups(DetailHandler):
|
||||
if multi or not i:
|
||||
return res
|
||||
# Add pools field if 1 item only
|
||||
res = res[0]
|
||||
result = res[0]
|
||||
if i.is_meta:
|
||||
res[
|
||||
result[
|
||||
'pools'
|
||||
] = (
|
||||
[]
|
||||
) # Meta groups do not have "assigned "pools, they get it from groups interaction
|
||||
else:
|
||||
res['pools'] = [v.uuid for v in i.deployedServices.all()]
|
||||
return res
|
||||
result['pools'] = [v.uuid for v in i.deployedServices.all()]
|
||||
return result
|
||||
except Exception:
|
||||
logger.exception('REST groups')
|
||||
raise self.invalidItemException()
|
||||
|
||||
def getTitle(self, parent):
|
||||
def getTitle(self, parent: str):
|
||||
try:
|
||||
return _('Groups of {0}').format(
|
||||
Authenticator.objects.get(
|
||||
@ -393,7 +393,7 @@ class Groups(DetailHandler):
|
||||
},
|
||||
]
|
||||
|
||||
def getTypes(self, parent, forType):
|
||||
def getTypes(self, parent: Authenticator, forType: typing.Optional[str]):
|
||||
tDct = {
|
||||
'group': {'name': _('Group'), 'description': _('UDS Group')},
|
||||
'meta': {'name': _('Meta group'), 'description': _('UDS Meta Group')},
|
||||
@ -412,11 +412,11 @@ class Groups(DetailHandler):
|
||||
return types
|
||||
|
||||
try:
|
||||
return types[forType]
|
||||
return next(filter(lambda x: x['type'] == forType, types))
|
||||
except Exception:
|
||||
raise self.invalidRequestException()
|
||||
|
||||
def saveItem(self, parent, item):
|
||||
def saveItem(self, parent: Authenticator, item: typing.Optional[str]) -> None:
|
||||
group = None # Avoid warning on reference before assignment
|
||||
try:
|
||||
is_meta = self._params['type'] == 'meta'
|
||||
@ -476,9 +476,7 @@ class Groups(DetailHandler):
|
||||
logger.exception('Saving group')
|
||||
raise self.invalidRequestException()
|
||||
|
||||
return self.getItems(parent, group.uuid)
|
||||
|
||||
def deleteItem(self, parent, item):
|
||||
def deleteItem(self, parent: Authenticator, item: str) -> None:
|
||||
try:
|
||||
group = parent.groups.get(uuid=item)
|
||||
|
||||
@ -486,12 +484,10 @@ class Groups(DetailHandler):
|
||||
except Exception:
|
||||
raise self.invalidItemException()
|
||||
|
||||
return 'deleted'
|
||||
|
||||
def servicesPools(self, parent, item):
|
||||
def servicesPools(self, parent: Authenticator, item: str) -> typing.List[typing.Mapping[str, typing.Any]]:
|
||||
uuid = processUuid(item)
|
||||
group = parent.groups.get(uuid=processUuid(uuid))
|
||||
res = []
|
||||
res: typing.List[typing.Mapping[str, typing.Any]] = []
|
||||
for i in getPoolsForGroups((group,)):
|
||||
res.append(
|
||||
{
|
||||
@ -509,7 +505,7 @@ class Groups(DetailHandler):
|
||||
|
||||
return res
|
||||
|
||||
def users(self, parent, item):
|
||||
def users(self, parent: Authenticator, item: str) -> typing.List[typing.Mapping[str, typing.Any]]:
|
||||
uuid = processUuid(item)
|
||||
group = parent.groups.get(uuid=processUuid(uuid))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user