Merge lp://staging/~dooferlad/offspring/ssh_ui_mods into lp://staging/~linaro-automation/offspring/private-builds

Proposed by James Tunnicliffe
Status: Superseded
Proposed branch: lp://staging/~dooferlad/offspring/ssh_ui_mods
Merge into: lp://staging/~linaro-automation/offspring/private-builds
Diff against target: 767 lines (+556/-44)
10 files modified
lib/offspring/web/media/js/jquery.placeholder.js (+106/-0)
lib/offspring/web/queuemanager/admin.py (+3/-1)
lib/offspring/web/queuemanager/forms.py (+133/-5)
lib/offspring/web/queuemanager/models.py (+1/-1)
lib/offspring/web/queuemanager/tests/test_views.py (+107/-1)
lib/offspring/web/queuemanager/views.py (+47/-0)
lib/offspring/web/templates/queuemanager/project_create.html (+59/-18)
lib/offspring/web/templates/queuemanager/project_edit.html (+35/-18)
lib/offspring/web/templates/queuemanager/project_edit_credentials.html (+64/-0)
lib/offspring/web/urls.py (+1/-0)
To merge this branch: bzr merge lp://staging/~dooferlad/offspring/ssh_ui_mods
Reviewer Review Type Date Requested Status
Guilherme Salgado (community) Needs Fixing
James Tunnicliffe Pending
Review via email: mp+80730@code.staging.launchpad.net

This proposal supersedes a proposal from 2011-10-28.

This proposal has been superseded by a proposal from 2011-11-03.

Description of the change

Adds to the web UI so Launchpad SSH credentials can be easily added, modified and removed without sharing the value of the SSH private key.

To post a comment you must log in.
Revision history for this message
Guilherme Salgado (salgado) wrote : Posted in a previous version of this proposal

Hi James, this branch has a conflict; care to resolve it before I review?

Revision history for this message
James Tunnicliffe (dooferlad) wrote : Posted in a previous version of this proposal

Have rebased. Should be fine now.

Revision history for this message
Guilherme Salgado (salgado) wrote : Posted in a previous version of this proposal

Hi James,

In my previous review I suggested creating a new page to edit the SSH keys and lp username because it would:

 1. be simpler to implement
 2. as a consequence, less fragile and easier to test
 3. allow us to provide a simple UI: we could use one form button to save an SSHkey/lp_username change and another to remove the SSHkey/username. Remember that these two things need to be removed together as having just one of them will cause the slave to crash

I see you've added a way to remove an ssh key, but using a checkbox for that is poor UI at best, and it doesn't seem to remove the LP user, as we should do, at the same time (if it did, it'd be even more confusing).

I also suggested placing the "An SSH key is stored for this project...." helper text outside of the textarea instead of using JS to place it inside because the latter doesn't add (IMO) much value and can't be unit tested (unless we spend a significant amount of time writing/configuring some way of testing the JS in our views). This also depends on jquery and an extra jquery plugin, which should not be included without some discussion because Offspring already includes a javascript library (http://www.smartclient.com/product/smartclient.jsp).

I'm not trying to make things perfect here, but I think we should try hard to avoid unnecessary complexity, and I do believe my suggestions would make things just as nice (nicer, in some cases) to the user and much simpler for us.

Revision history for this message
James Tunnicliffe (dooferlad) wrote : Posted in a previous version of this proposal

Right, have moved the SSH credentials editing to a new page, removed the extra jquery, added some more unit tests and made sure that help text is always complete outside the placeholder text inside the SSH key entry box.

review: Needs Resubmitting
Revision history for this message
Guilherme Salgado (salgado) wrote : Posted in a previous version of this proposal

Hi James,
This one still has stuff that ought to have been removed, like the two js files and changes to project_create.html. Please go through the diff when you submit a MP so that the person who's reviewing the code can focus on the interesting things rather than trying to guess what's left over from previous commits and what's actually used in the current code.

review: Needs Resubmitting
Revision history for this message
James Tunnicliffe (dooferlad) wrote : Posted in a previous version of this proposal

Sorry, I was under the impression that I was keeping in the updates to
project_create.html, which its why it and the js files are still there. I
will get the changes reverted and remove the js. If we want something more
fancy in the future I can go back and revisit it.

I am out at dinner now so don't expect any updates tonight.

James
On Oct 28, 2011 8:53 PM, "Guilherme Salgado" <email address hidden>
wrote:

> Review: Resubmit
>
> Hi James,
> This one still has stuff that ought to have been removed, like the two js
> files and changes to project_create.html. Please go through the diff when
> you submit a MP so that the person who's reviewing the code can focus on the
> interesting things rather than trying to guess what's left over from
> previous commits and what's actually used in the current code.
> --
> https://code.launchpad.net/~dooferlad/offspring/ssh_ui_mods/+merge/80701
> You are the owner of lp:~dooferlad/offspring/ssh_ui_mods.
>

Revision history for this message
Guilherme Salgado (salgado) wrote : Posted in a previous version of this proposal

Oh, sorry, I mixed up project_create with project_edit. You're right that we want to allow people to enter the ssh key when creating a new project, but I don't see a reason for having the ssh_key/lp_user fields hidden initially, so we could probably get rid of the other js file. There's also the showAddAnotherPopup() function in the new template, which probably comes from the edit template that you used as a base, although I don't think is needed?

I'm not fond of using javascript (and specially a jquery placeholder plugin, as that's not the js library used in Offspring) to have the help text displayed inside the text area, but if you feel strong about it, that's fine.

Revision history for this message
James Tunnicliffe (dooferlad) wrote :

No worries. I have got rid of the show/hide bit on the project add page and showAddAnotherPopup(). I have left the jquery placeholder plugin in because I think it improves the user experience and provides backwards compatibility for those using lesser browsers. I am not sure if it is a strong opinion though!

Revision history for this message
Guilherme Salgado (salgado) wrote :
Download full text (28.1 KiB)

Here are the things we discussed in person today...

> === modified file 'lib/offspring/web/queuemanager/forms.py'
> --- lib/offspring/web/queuemanager/forms.py 2011-10-19 20:23:49 +0000
> +++ lib/offspring/web/queuemanager/forms.py 2011-10-31 15:48:00 +0000
> @@ -1,8 +1,11 @@
> # Copyright 2010 Canonical Ltd. This software is licensed under the
> # GNU Affero General Public License version 3 (see the file LICENSE).
>
> +import re
> +
> from django.contrib.auth.models import User
> from django.db import models
> +from django import forms
> from django.forms import (
> Form, ModelChoiceField, ModelForm, Textarea, TextInput, ValidationError)
> from django.forms import fields
> @@ -15,9 +18,81 @@
>
> from offspring.web.queuemanager.widgets import SelectWithAddNew
>
> -class ProjectBaseForm(ModelForm):
> - status = fields.CharField(max_length=200,
> - widget=fields.Select(choices=Project.STATUS_CHOICES), required=True)
> +class SSHPrivateKeyField(forms.Field):
> +
> + def validate(self, value):
> + "Check to see if the value looks like an SSH private key"
> +
> + # Use the parent's handling of required fields, etc.
> + super(SSHPrivateKeyField, self).validate(value)
> +
> + key_search_regexp = (r"-----BEGIN \w+ PRIVATE KEY-----"+
> + r".*"+
> + r"-----END \w+ PRIVATE KEY-----")
> + is_key = re.search(key_search_regexp, value, re.DOTALL | re.MULTILINE)
> +
> + if not is_key and not value == "":
> + msg = ("The key you entered doesn't appear to be valid. I am "+
> + "expecting a key in the form:\n "+
> + "-----BEGIN <type> PRIVATE KEY-----\n"+
> + "<ASCII key>\n"+
> + "-----END <type> PRIVATE KEY-----\n")
> + raise forms.ValidationError(msg)
> +
> +class ProjectSSHCredForm(ModelForm):
> + ssh_help = ("Enter a private SSH ASCII key block, complete with begin "+
> + "and end markers.")
> +
> + lp_ssh_key_input = SSHPrivateKeyField(label="Launchpad User's SSH key",
> + required=False,
> + widget=forms.Textarea(
> + attrs={'cols': 70, 'rows' : 4}),
> + help_text=ssh_help)
> +
> + lp_fields_set = False
> + lp_ssh_set = False
> + lp_ssh_set_message = ("An SSH key is stored for this project. To replace "+
> + "it, paste a new SSH private key block here.")
> + lp_ssh_clear_meessage = ("To enable access to private repositories,"+
> + "enter an SSH private key here in the form of an "+
> + "ASCII key block.")
> +
> + def __init__(self, *args, **kwargs):
> + super(ProjectSSHCredForm, self).__init__(*args, **kwargs)
> + # Set the form fields based on the model object
> + if kwargs.has_key('instance'):
> + instance = kwargs['instance']
> + if instance.lp_ssh_key and instance.lp_ssh_key != "":

The second clause is redundant her...

review: Needs Fixing
86. By James Tunnicliffe

* Require both or neither ssh user and key.
* Removed bad tests
* Added test to ensure we can't edit a projects SSH credentials if it is private and we don't have permissions
* Code clean up and tidy.

87. By James Tunnicliffe

Updated and fixed logic for requiring SSH user and key to be both set, or neither set.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches