Commit ab87f4fc by Bach Dániel

dashboard: autocomplete for group members

parent b61a5728
...@@ -1063,6 +1063,15 @@ class AclUserOrGroupAddForm(forms.Form): ...@@ -1063,6 +1063,15 @@ class AclUserOrGroupAddForm(forms.Form):
class AddGroupMemberForm(forms.Form):
new_member = forms.CharField(
widget=autocomplete_light.TextWidget(
'AclUserAutocomplete',
autocomplete_js_attributes={"placeholder": _("Name of user")},
attrs={'class': 'form-control'}),
label=_("E-mail address or identifier of user"))
class UserKeyForm(forms.ModelForm): class UserKeyForm(forms.ModelForm):
name = forms.CharField(required=True, label=_('Name')) name = forms.CharField(required=True, label=_('Name'))
key = forms.CharField( key = forms.CharField(
......
...@@ -591,11 +591,15 @@ footer a, footer a:hover, footer a:visited { ...@@ -591,11 +591,15 @@ footer a, footer a:hover, footer a:visited {
width: 100px; width: 100px;
} }
#group-detail-user-table tr:last-child td:nth-child(2) {
text-align: left;
}
#group-detail-perm-header { #group-detail-perm-header {
margin-top: 25px; margin-top: 25px;
} }
textarea[name="list-new-namelist"] { textarea[name="new_members"] {
max-width: 500px; max-width: 500px;
min-height: 80px; min-height: 80px;
margin-bottom: 10px; margin-bottom: 10px;
......
...@@ -89,13 +89,12 @@ ...@@ -89,13 +89,12 @@
<tr> <tr>
<td><i class="fa fa-plus"></i></td> <td><i class="fa fa-plus"></i></td>
<td colspan="2"> <td colspan="2">
<input type="text" class="form-control" name="list-new-name" {{addmemberform.new_member}}
placeholder="{% trans "Name of user" %}">
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<textarea name="list-new-namelist" class="form-control" <textarea name="new_members" class="form-control"
placeholder="{% trans "Add multiple users at once (one identifier per line)." %}"></textarea> placeholder="{% trans "Add multiple users at once (one identifier per line)." %}"></textarea>
<div class="form-actions"> <div class="form-actions">
<button type="submit" class="btn btn-success">{% trans "Save" %}</button> <button type="submit" class="btn btn-success">{% trans "Save" %}</button>
......
...@@ -72,7 +72,8 @@ from .forms import ( ...@@ -72,7 +72,8 @@ from .forms import (
CirclePasswordChangeForm, VmCreateDiskForm, VmDownloadDiskForm, CirclePasswordChangeForm, VmCreateDiskForm, VmDownloadDiskForm,
TraitsForm, RawDataForm, GroupPermissionForm, AclUserOrGroupAddForm, TraitsForm, RawDataForm, GroupPermissionForm, AclUserOrGroupAddForm,
VmResourcesForm, VmAddInterfaceForm, VmListSearchForm, VmResourcesForm, VmAddInterfaceForm, VmListSearchForm,
TemplateListSearchForm, ConnectCommandForm TemplateListSearchForm, ConnectCommandForm,
TransferOwnershipForm, AddGroupMemberForm
) )
from .tables import ( from .tables import (
...@@ -1283,6 +1284,7 @@ class GroupDetailView(CheckedDetailView): ...@@ -1283,6 +1284,7 @@ class GroupDetailView(CheckedDetailView):
self.object.profile, self.request.user, self.object.profile, self.request.user,
'dashboard.views.group-acl') 'dashboard.views.group-acl')
context['aclform'] = AclUserOrGroupAddForm() context['aclform'] = AclUserOrGroupAddForm()
context['addmemberform'] = AddGroupMemberForm()
context['group_profile_form'] = GroupProfileUpdate.get_form_object( context['group_profile_form'] = GroupProfileUpdate.get_form_object(
self.request, self.object.profile) self.request, self.object.profile)
...@@ -1299,17 +1301,15 @@ class GroupDetailView(CheckedDetailView): ...@@ -1299,17 +1301,15 @@ class GroupDetailView(CheckedDetailView):
if request.POST.get('new_name'): if request.POST.get('new_name'):
return self.__set_name(request) return self.__set_name(request)
if request.POST.get('list-new-name'): if request.POST.get('new_member'):
return self.__add_user(request) return self.__add_user(request)
if request.POST.get('list-new-namelist'): if request.POST.get('new_members'):
return self.__add_list(request) return self.__add_list(request)
if (request.POST.get('list-new-name') is not None) and \
(request.POST.get('list-new-namelist') is not None):
return redirect(reverse_lazy("dashboard.views.group-detail", return redirect(reverse_lazy("dashboard.views.group-detail",
kwargs={'pk': self.get_object().pk})) kwargs={'pk': self.get_object().pk}))
def __add_user(self, request): def __add_user(self, request):
name = request.POST['list-new-name'] name = request.POST['new_member']
self.__add_username(request, name) self.__add_username(request, name)
return redirect(reverse_lazy("dashboard.views.group-detail", return redirect(reverse_lazy("dashboard.views.group-detail",
kwargs={'pk': self.object.pk})) kwargs={'pk': self.object.pk}))
...@@ -1328,9 +1328,7 @@ class GroupDetailView(CheckedDetailView): ...@@ -1328,9 +1328,7 @@ class GroupDetailView(CheckedDetailView):
messages.warning(request, _('User "%s" not found.') % name) messages.warning(request, _('User "%s" not found.') % name)
def __add_list(self, request): def __add_list(self, request):
if not self.get_has_level()(request.user, 'operator'): userlist = request.POST.get('new_members').split('\r\n')
raise PermissionDenied()
userlist = request.POST.get('list-new-namelist').split('\r\n')
for line in userlist: for line in userlist:
self.__add_username(request, line) self.__add_username(request, line)
return redirect(reverse_lazy("dashboard.views.group-detail", return redirect(reverse_lazy("dashboard.views.group-detail",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment