Commit a87215f0 by Kálmán Viktor

dashboard: display multiple connections strings

Also add empty text and prefix to tables in profile
parent 69abf63b
...@@ -155,22 +155,25 @@ class Profile(Model): ...@@ -155,22 +155,25 @@ class Profile(Model):
default=2048 * 1024 * 1024, default=2048 * 1024 * 1024,
help_text=_('Disk quota in mebibytes.')) help_text=_('Disk quota in mebibytes.'))
def get_connect_command(self, instance, use_ipv6=False): def get_connect_commands(self, instance, use_ipv6=False):
""" Generate connection command based on template.""" """ Generate connection command based on template."""
try: single_command = instance.get_connect_command(use_ipv6)
command = self.user.command_set.get( if single_command: # can we even connect to that VM
commands = self.user.command_set.filter(
access_method=instance.access_method) access_method=instance.access_method)
except ConnectCommand.DoesNotExist: if commands.count() < 1:
# No template for this protocol return default return [single_command]
return instance.get_connect_command(use_ipv6) else:
return [
command.template % {
'port': instance.get_connect_port(use_ipv6=use_ipv6),
'host': instance.get_connect_host(use_ipv6=use_ipv6),
'password': instance.pw,
'app': command.application,
'username': 'cloud',
} for command in commands]
else: else:
return command.template % { return []
'port': instance.get_connect_port(use_ipv6=use_ipv6),
'host': instance.get_connect_host(use_ipv6=use_ipv6),
'password': instance.pw,
'app': command.application,
'username': 'cloud'
}
def notify(self, subject, template, context=None, valid_until=None, def notify(self, subject, template, context=None, valid_until=None,
**kwargs): **kwargs):
......
...@@ -251,6 +251,8 @@ class UserKeyListTable(Table): ...@@ -251,6 +251,8 @@ class UserKeyListTable(Table):
model = UserKey model = UserKey
attrs = {'class': ('table table-bordered table-striped table-hover')} attrs = {'class': ('table table-bordered table-striped table-hover')}
fields = ('name', 'fingerprint', 'created', 'actions') fields = ('name', 'fingerprint', 'created', 'actions')
prefix = "key-"
empty_text = _("You haven't added any public keys yet.")
class ConnectCommandListTable(Table): class ConnectCommandListTable(Table):
...@@ -279,3 +281,6 @@ class ConnectCommandListTable(Table): ...@@ -279,3 +281,6 @@ class ConnectCommandListTable(Table):
model = ConnectCommand model = ConnectCommand
attrs = {'class': ('table table-bordered table-striped table-hover')} attrs = {'class': ('table table-bordered table-striped table-hover')}
fields = ('access_method', 'application', 'template', 'actions') fields = ('access_method', 'application', 'template', 'actions')
prefix = "cmd-"
empty_text = _("You don't have any custom connection string, the "
"default ones will be used.")
...@@ -111,16 +111,28 @@ ...@@ -111,16 +111,28 @@
</div> </div>
</dd> </dd>
</dl> </dl>
{% for c in connect_commands %}
<div class="input-group" id="dashboard-vm-details-connect-command"> <div class="input-group" id="dashboard-vm-details-connect-command">
<span class="input-group-addon input-tags">{% trans "Command" %}</span> <span class="input-group-addon input-tags">{% trans "Command" %}</span>
<input type="text" spellcheck="false" <input type="text" spellcheck="false"
value="{% if connect_command %}{{ connect_command }}{% else %}{% trans "Connection is not possible." %}{% endif %}" value="{{ c }}"
id="vm-details-connection-string" class="form-control input-tags" />
<span class="input-group-addon input-tags" id="vm-details-connection-string-copy">
<i class="fa fa-copy" title="{% trans "Select all" %}"></i>
</span>
</div>
{% empty %}
<div class="input-group" id="dashboard-vm-details-connect-command">
<span class="input-group-addon input-tags">{% trans "Command" %}</span>
<input type="text" spellcheck="false" value="{% trans "Connection is not possible." %}"
id="vm-details-connection-string" class="form-control input-tags" /> id="vm-details-connection-string" class="form-control input-tags" />
<span class="input-group-addon input-tags" id="vm-details-connection-string-copy"> <span class="input-group-addon input-tags" id="vm-details-connection-string-copy">
<i class="fa fa-copy" title="{% trans "Select all" %}"></i> <i class="fa fa-copy" title="{% trans "Select all" %}"></i>
</span> </span>
</div> </div>
{% endfor %}
</div> </div>
<div class="col-md-8" id="vm-detail-pane"> <div class="col-md-8" id="vm-detail-pane">
<div class="panel panel-default" id="vm-detail-panel"> <div class="panel panel-default" id="vm-detail-panel">
......
...@@ -304,7 +304,7 @@ class VmDetailView(CheckedDetailView): ...@@ -304,7 +304,7 @@ class VmDetailView(CheckedDetailView):
kwargs={'pk': self.object.pk}), kwargs={'pk': self.object.pk}),
'ops': ops, 'ops': ops,
'op': {i.op: i for i in ops}, 'op': {i.op: i for i in ops},
'connect_command': user.profile.get_connect_command(instance) 'connect_commands': user.profile.get_connect_commands(instance)
}) })
# activity data # activity data
...@@ -3201,8 +3201,7 @@ class ConnectCommandDetail(LoginRequiredMixin, SuccessMessageMixin, ...@@ -3201,8 +3201,7 @@ class ConnectCommandDetail(LoginRequiredMixin, SuccessMessageMixin,
object = self.get_object() object = self.get_object()
if object.user != request.user: if object.user != request.user:
raise PermissionDenied() raise PermissionDenied()
return super(ConnectCommandDetail, self).post(self, request, return super(ConnectCommandDetail, self).post(request, args, kwargs)
args, kwargs)
class ConnectCommandDelete(LoginRequiredMixin, DeleteView): class ConnectCommandDelete(LoginRequiredMixin, DeleteView):
......
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