mirror of
https://github.com/dkmstr/openuds.git
synced 2025-03-11 00:58:39 +03:00
added assigned service edition. Now we can change the onwership of a machine
This commit is contained in:
parent
cbdd61cfa8
commit
8c882852db
@ -37,8 +37,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
from uds.models import Group, Transport, DeployedServicePublication
|
||||
from uds.models import Group, Transport, DeployedServicePublication, User
|
||||
from uds.core.util.State import State
|
||||
from uds.core.util.model import processUuid
|
||||
from uds.core.util import log
|
||||
@ -46,8 +45,6 @@ from uds.REST.model import DetailHandler
|
||||
from uds.REST import ResponseError
|
||||
from uds.core.util import permissions
|
||||
|
||||
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -168,6 +165,22 @@ class AssignedService(DetailHandler):
|
||||
|
||||
return self.success()
|
||||
|
||||
# Only owner is allowed to change right now
|
||||
def saveItem(self, parent, item):
|
||||
fields = self.readFieldsFromParams(['auth_id', 'user_id'])
|
||||
logger.debug('Saving userService {} / {} ({})'.format(parent, item, fields))
|
||||
service = parent.userServices.get(uuid=processUuid(item))
|
||||
user = User.objects.get(uuid=processUuid(fields['user_id']))
|
||||
|
||||
# If there is another service that has this same owner, raise an exception
|
||||
if parent.userServices.filter(user=user).exclude(uuid=service.uuid).count() > 0:
|
||||
raise self.invalidResponseException('There is already another user service assigned to {}'.format(user.pretty_name))
|
||||
|
||||
service.user = user
|
||||
service.save()
|
||||
|
||||
return service
|
||||
|
||||
|
||||
class CachedService(AssignedService):
|
||||
'''
|
||||
@ -215,6 +228,7 @@ class Groups(DetailHandler):
|
||||
'''
|
||||
Processes the groups detail requests of a Service Pool
|
||||
'''
|
||||
|
||||
def getItems(self, parent, item):
|
||||
return [{
|
||||
'id': i.uuid,
|
||||
@ -252,6 +266,7 @@ class Transports(DetailHandler):
|
||||
'''
|
||||
Processes the transports detail requests of a Service Pool
|
||||
'''
|
||||
|
||||
def getItems(self, parent, item):
|
||||
return [{
|
||||
'id': i.uuid,
|
||||
@ -352,6 +367,7 @@ class Changelog(DetailHandler):
|
||||
'''
|
||||
Processes the transports detail requests of a Service Pool
|
||||
'''
|
||||
|
||||
def getItems(self, parent, item):
|
||||
return [{
|
||||
'revision': i.revision,
|
||||
|
@ -401,10 +401,12 @@ gui.servicesPools.link = (event) ->
|
||||
rowSelect: "multi"
|
||||
buttons: (if info.must_assign_manually then [
|
||||
"new"
|
||||
"edit"
|
||||
"delete"
|
||||
"xls"
|
||||
] else [
|
||||
"delete"
|
||||
"edit"
|
||||
"xls"
|
||||
])
|
||||
|
||||
@ -434,6 +436,60 @@ gui.servicesPools.link = (event) ->
|
||||
)
|
||||
return
|
||||
|
||||
onEdit: (item, event, table, refreshFnc) ->
|
||||
gui.doLog(item)
|
||||
api.templates.get "pool_edit_assigned", (tmpl) ->
|
||||
api.authenticators.overview (data) ->
|
||||
# Sorts groups, expression means that "if a > b returns 1, if b > a returns -1, else returns 0"
|
||||
api.authenticators.detail(item.owner_info.auth_id, "users").overview (users) ->
|
||||
modalId = gui.launchModal(gettext("Edit Assigned Service ownership"), api.templates.evaluate(tmpl,
|
||||
auths: data,
|
||||
auth_id: item.owner_info.auth_id,
|
||||
users: users,
|
||||
user_id: item.owner_info.user_id,
|
||||
))
|
||||
$(modalId + " #id_auth_select").on "change", (event) ->
|
||||
auth = $(modalId + " #id_auth_select").val()
|
||||
api.authenticators.detail(auth, "users").overview (data) ->
|
||||
$select = $(modalId + " #id_user_select")
|
||||
$select.empty()
|
||||
$.each data, (undefined_, value) ->
|
||||
console.log('Val: ', value)
|
||||
$select.append "<option value=\"" + value.id + "\">" + value.name + "</option>"
|
||||
return
|
||||
|
||||
|
||||
# Refresh selectpicker if item is such
|
||||
$select.selectpicker "refresh" if $select.hasClass("selectpicker")
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
$(modalId + " .button-accept").on "click", (event) ->
|
||||
auth = $(modalId + " #id_auth_select").val()
|
||||
user = $(modalId + " #id_user_select").val()
|
||||
if auth is -1 or user is -1
|
||||
gui.notify gettext("You must provide authenticator and user"), "danger"
|
||||
else # Save & close modal
|
||||
assignedServices.rest.save
|
||||
id: item.id,
|
||||
auth_id: auth,
|
||||
user_id: user
|
||||
, (data) ->
|
||||
$(modalId).modal "hide"
|
||||
refreshFnc()
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
|
||||
# Makes form "beautyfull" :-)
|
||||
gui.tools.applyCustoms modalId
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
onDelete: gui.methods.del(assignedServices, gettext("Remove Assigned service"), gettext("Deletion error"))
|
||||
)
|
||||
|
@ -198,6 +198,8 @@
|
||||
{% js_template 'services_pool' %}
|
||||
{% js_template 'pool_access_default' %}
|
||||
{% js_template 'pool_add_access' %}
|
||||
{% js_template 'pool_add_group' %}
|
||||
{% js_template 'pool_edit_assigned' %}
|
||||
{% js_template 'configuration' %}
|
||||
{% js_template 'gallery' %}
|
||||
{% js_template 'permissions' %}
|
||||
|
@ -0,0 +1,29 @@
|
||||
{% load i18n %}
|
||||
{% verbatim %}
|
||||
<form class="form-horizontal" role="form">
|
||||
<div class="form-group">
|
||||
<label for="id_auth_select" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Authenticator' %}{% verbatim %}</label>
|
||||
<div class="col-sm-10">
|
||||
<select id="id_auth_select" name="auth" class="selectpicker show-menu-arrow show-tick modal_field_data" data-style="btn-default" data-width="100%">
|
||||
<option value="-1"></option>
|
||||
{{# each auths }}
|
||||
<option value="{{ id }}"{{# ifequals id ../auth_id }} selected{{/ ifequals }}>{{ name }}</option>
|
||||
{{/ each }}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="id_user_select" class="col-sm-2 control-label">{% endverbatim %}{% trans 'User' %}{% verbatim %}</label>
|
||||
<div class="col-sm-10">
|
||||
<select id="id_user_select" name="user" class="selectpicker show-menu-arrow show-tick modal_field_data" data-style="btn-default" data-width="100%">
|
||||
{{# each users }}
|
||||
<option value="{{ id }}"{{# ifequals id ../user_id }} selected{{/ ifequals }}>{{ name }}</option>
|
||||
{{/ each }}
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{% endverbatim %}
|
Loading…
x
Reference in New Issue
Block a user