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

Proposed by James Tunnicliffe on 2011-11-03
Status: Merged
Merged at revision: 75
Proposed branch: lp:~dooferlad/offspring/ssh_ui_mods
Merge into: lp:~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:~dooferlad/offspring/ssh_ui_mods
Reviewer Review Type Date Requested Status
Guilherme Salgado 2011-11-03 Pending
James Tunnicliffe Pending
Review via email: mp+81217@code.launchpad.net

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

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.
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?

James Tunnicliffe (dooferlad) wrote : Posted in a previous version of this proposal

Have rebased. Should be fine now.

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.

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: Resubmit
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: Resubmit
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.
>

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.

James Tunnicliffe (dooferlad) wrote : Posted in a previous version of this proposal

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!

Guilherme Salgado (salgado) wrote : Posted in a previous version of this proposal
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
Guilherme Salgado (salgado) wrote :
Download full text (9.5 KiB)

On Thu, 2011-11-03 at 22:21 +0000, James Tunnicliffe wrote:
> === modified file 'lib/offspring/web/templates/queuemanager/project_create.html'
> --- lib/offspring/web/templates/queuemanager/project_create.html 2011-02-28 22:48:46 +0000
> +++ lib/offspring/web/templates/queuemanager/project_create.html 2011-11-03 22:20:29 +0000
> @@ -5,7 +5,9 @@
> {% endblock %}
>
> {% block header_js %}
> -<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
> +<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
> +<script type="text/javascript" src="/media/js/jquery.min.js"></script>
> +<script type="text/javascript" src="/assets/js/jquery.placeholder.js"></script>
> <script type="text/javascript">
> /* Override showAddAnotherPopup to use custom height and width. */
> function showAddAnotherPopup(triggeringLink) {
> @@ -29,29 +31,68 @@
> {% endblock %}
>
> {% block content %}
> - <form method="POST" action="">{% csrf_token %}
> + <form method="POST" action="" name="projsettings">{% csrf_token %}
> <div class="module aligned ">
> {% for field in form %}
> - <div class="form-row {% if line.errors %} errors{% endif %} {{ field.name }}">
> - <div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}>
> - {% if field.is_checkbox %}
> - {{ field }}{{ field.label_tag }}
> - {% else %}
> - {{ field.label_tag }}
> - {% if field.is_readonly %}
> - <p>{{ field.contents }}</p>
> + {% if field.html_name == "lp_user" or field.html_name == "lp_ssh_key_input" %}
> + <!-- This catches lp_user and lp_ssh_key_input so they aren't shown in the top of
> + the page. They are displayed below in their own section after some help text -->
> + {% else %}
> + <div class="form-row {% if line.errors %} errors{% endif %} {{ field.name }}">
> + <div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}>
> + {% if field.is_checkbox %}
> + {{ field }}{{ field.label_tag }}
> {% else %}
> - {{ field }}
> - {% endif %}
> - {% endif %}
> - {% if field.field.field.help_text %}
> - <p class="help">{{ field.field.field.help_text|safe }}</p>
> - {% endif %}
> + {{ field.label_tag }}
> + {% if field.is_readonly %}
> + <p>{{ field.contents }}</p>
> + {% else %}
> + {{ field }}
> + {% endif %}
> + {% endif %}
> + {% if field.field.field.help_text %}
> + <p class...

Read more...

James Tunnicliffe (dooferlad) wrote :
Download full text (5.3 KiB)

On 4 November 2011 20:46, Guilherme Salgado
<email address hidden> wrote:
> On Thu, 2011-11-03 at 22:21 +0000, James Tunnicliffe wrote:
>> === modified file 'lib/offspring/web/templates/queuemanager/project_create.html'
<snip>
>> +            If the config URL above points to a Bazaar repository that is only
>> +            available to authenticated users, you should add a user and private SSH
>> +            key to give the builder access. The SSH key will never be revealed. It
>> +            can be changed or deleted later. It should not be passphrase protected.
>> +            If you would like to add these details, tick here:
>
> Hmm. There's nothing to tick here anymore, right?

Good catch!

>> === modified file 'lib/offspring/web/templates/queuemanager/project_edit.html'
>> --- lib/offspring/web/templates/queuemanager/project_edit.html        2011-03-03 01:50:40 +0000
>> +++ lib/offspring/web/templates/queuemanager/project_edit.html        2011-11-03 22:20:29 +0000
>> @@ -5,7 +5,7 @@
>>  {% endblock %}
>>
>>  {% block header_js %}
>> -<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
>> +<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
>>  <script type="text/javascript">
>>  /* Override showAddAnotherPopup to use custom height and width. */
>>  function showAddAnotherPopup(triggeringLink) {
>> @@ -29,29 +29,46 @@
>>  {% endblock %}
>>
>>  {% block content %}
>> -    <form method="POST" action="">{% csrf_token %}
>> +    <form method="POST" action="" name="projsettings">{% csrf_token %}
>>          <div class="module aligned ">
>>               {% for field in form %}
>> -                <div class="form-row {% if line.errors %} errors{% endif %} {{ field.name }}">
>> -                    <div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}>
>> -                        {% if field.is_checkbox %}
>> -                            {{ field }}{{ field.label_tag }}
>> -                        {% else %}
>> -                            {{ field.label_tag }}
>> -                            {% if field.is_readonly %}
>> -                                <p>{{ field.contents }}</p>
>> +                {% if field.html_name == "lp_user" or field.html_name == "lp_ssh_key_input"%}
>
> This is no longer needed, right?  We've agreed on that in the previous
> review already, IIRC.

It is still required because the new fields are part of the project
form, so they need to be filtered out where they aren't needed.
Actually I just noticed that since I have switched lp_user to a
TextField to match the internal representation of Launchpad, it can
now contain newlines and the form doesn't stop this. I see my options
as:

01234567890123456789012345678901234567890123456789012345678901234567890123456789
1. Leave it as it is and add a custom validate to exclude newlines
2. Switch it back to a CharField in the DB and set max_length to None, or if
   that isn't allowed, something large, like 256.
3. Do something similar to the ssh input field - leave the internal
   representation as is, and have a CharField input box with a max_length
   set to something massive.
...

Read more...

Guilherme Salgado (salgado) wrote :
Download full text (6.6 KiB)

On Mon, 2011-11-07 at 17:10 +0000, James Tunnicliffe wrote:
> >> === modified file 'lib/offspring/web/templates/queuemanager/project_edit.html'
> >> --- lib/offspring/web/templates/queuemanager/project_edit.html 2011-03-03 01:50:40 +0000
> >> +++ lib/offspring/web/templates/queuemanager/project_edit.html 2011-11-03 22:20:29 +0000
> >> @@ -5,7 +5,7 @@
> >> {% endblock %}
> >>
> >> {% block header_js %}
> >> -<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
> >> +<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
> >> <script type="text/javascript">
> >> /* Override showAddAnotherPopup to use custom height and width. */
> >> function showAddAnotherPopup(triggeringLink) {
> >> @@ -29,29 +29,46 @@
> >> {% endblock %}
> >>
> >> {% block content %}
> >> - <form method="POST" action="">{% csrf_token %}
> >> + <form method="POST" action="" name="projsettings">{% csrf_token %}
> >> <div class="module aligned ">
> >> {% for field in form %}
> >> - <div class="form-row {% if line.errors %} errors{% endif %} {{ field.name }}">
> >> - <div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}>
> >> - {% if field.is_checkbox %}
> >> - {{ field }}{{ field.label_tag }}
> >> - {% else %}
> >> - {{ field.label_tag }}
> >> - {% if field.is_readonly %}
> >> - <p>{{ field.contents }}</p>
> >> + {% if field.html_name == "lp_user" or field.html_name == "lp_ssh_key_input"%}
> >
> > This is no longer needed, right? We've agreed on that in the previous
> > review already, IIRC.
>
> It is still required because the new fields are part of the project
> form, so they need to be filtered out where they aren't needed.

But the template is the worst place to do that, because the templating
language is not as powerfull as python and testing templates is harder
(and usually slower) than testing forms/views. And the above looks like
an ugly hack to me because of the empty if block, without even a
comment.

Having said that, I've just noticed that you already exclude the
unwanted fields in the form used by this template, so unless I'm missing
something this isn't needed.

        class EditProjectForm(ProjectBaseForm):
            launchpad_project = ModelChoiceField(
                LaunchpadProject.objects, widget=SelectWithAddNew, required=False)
            class Meta(ProjectBaseForm.Meta):
                exclude = ('name', 'priority', 'is_active', 'access_groups',
                           'lp_user', 'lp_ssh_key_input')

I thought the above would be enough to get rid of the lp_* fields on the
edit page, but I've just reverted the template changes locally and the
ssh key text area is still present on the form. That's probably why you
ended up doing the template changes, but instead of doing that we need
to find out why the ssh key field is still shown and fix it so that we
don't need the template hack to omit the field. I'll keep di...

Read more...

James Tunnicliffe (dooferlad) wrote :
Download full text (8.0 KiB)

On 8 November 2011 15:46, Guilherme Salgado
<email address hidden> wrote:
> On Mon, 2011-11-07 at 17:10 +0000, James Tunnicliffe wrote:
>> >> === modified file 'lib/offspring/web/templates/queuemanager/project_edit.html'
>> >> --- lib/offspring/web/templates/queuemanager/project_edit.html        2011-03-03 01:50:40 +0000
>> >> +++ lib/offspring/web/templates/queuemanager/project_edit.html        2011-11-03 22:20:29 +0000
>> >> @@ -5,7 +5,7 @@
>> >>  {% endblock %}
>> >>
>> >>  {% block header_js %}
>> >> -<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
>> >> +<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
>> >>  <script type="text/javascript">
>> >>  /* Override showAddAnotherPopup to use custom height and width. */
>> >>  function showAddAnotherPopup(triggeringLink) {
>> >> @@ -29,29 +29,46 @@
>> >>  {% endblock %}
>> >>
>> >>  {% block content %}
>> >> -    <form method="POST" action="">{% csrf_token %}
>> >> +    <form method="POST" action="" name="projsettings">{% csrf_token %}
>> >>          <div class="module aligned ">
>> >>               {% for field in form %}
>> >> -                <div class="form-row {% if line.errors %} errors{% endif %} {{ field.name }}">
>> >> -                    <div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}>
>> >> -                        {% if field.is_checkbox %}
>> >> -                            {{ field }}{{ field.label_tag }}
>> >> -                        {% else %}
>> >> -                            {{ field.label_tag }}
>> >> -                            {% if field.is_readonly %}
>> >> -                                <p>{{ field.contents }}</p>
>> >> +                {% if field.html_name == "lp_user" or field.html_name == "lp_ssh_key_input"%}
>> >
>> > This is no longer needed, right?  We've agreed on that in the previous
>> > review already, IIRC.
>>
>> It is still required because the new fields are part of the project
>> form, so they need to be filtered out where they aren't needed.
>
> But the template is the worst place to do that, because the templating
> language is not as powerfull as python and testing templates is harder
> (and usually slower) than testing forms/views. And the above looks like
> an ugly hack to me because of the empty if block, without even a
> comment.
>
> Having said that, I've just noticed that you already exclude the
> unwanted fields in the form used by this template, so unless I'm missing
> something this isn't needed.
>
>        class EditProjectForm(ProjectBaseForm):
>            launchpad_project = ModelChoiceField(
>                LaunchpadProject.objects, widget=SelectWithAddNew, required=False)
>            class Meta(ProjectBaseForm.Meta):
>                exclude = ('name', 'priority', 'is_active', 'access_groups',
>                           'lp_user', 'lp_ssh_key_input')
>
> I thought the above would be enough to get rid of the lp_* fields on the
> edit page, but I've just reverted the template changes locally and the
> ssh key text area is still present on the form. That's probably why you
> ended up doing the template changes, but instead o...

Read more...

James Tunnicliffe (dooferlad) wrote :

On 8 November 2011 16:43, James Tunnicliffe <email address hidden> wrote:

>> Did you change anything to make field.help_text work or is that just an
>> existing shortcut to field.field.field.help_text?
>
> I remember field.field.field.help_text not working, which is why I
> changed it to field.help_text, but I will try reverting it and seeing
> if it is still the case. It could be that I broke something during
> development.

Just confirmed that field.field.field.help_text doesn't work, so this
is a bug fix.

--
James Tunnicliffe

James Tunnicliffe (dooferlad) wrote :

Got it (I think). Multiple inheritance saves the day!

class ProjectBaseWithSSHForm(ProjectBaseForm, ProjectSSHCredForm):
    pass

Using this as the form for ProjectAdmin and the base for
CreateProjectForm, leaving EditProjectForm as is, it creates the
correct combined forms when we need them. Will submit a new patch
after I have cleaned things up and verified the DB changes.

Guilherme Salgado (salgado) wrote :
Download full text (8.0 KiB)

On Tue, 2011-11-08 at 16:43 +0000, James Tunnicliffe wrote:
> On 8 November 2011 15:46, Guilherme Salgado
> <email address hidden> wrote:
> > On Mon, 2011-11-07 at 17:10 +0000, James Tunnicliffe wrote:
> >> >> === modified file 'lib/offspring/web/templates/queuemanager/project_edit.html'
> >> >> --- lib/offspring/web/templates/queuemanager/project_edit.html 2011-03-03 01:50:40 +0000
> >> >> +++ lib/offspring/web/templates/queuemanager/project_edit.html 2011-11-03 22:20:29 +0000
> >> >> @@ -5,7 +5,7 @@
> >> >> {% endblock %}
> >> >>
> >> >> {% block header_js %}
> >> >> -<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
> >> >> +<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
> >> >> <script type="text/javascript">
> >> >> /* Override showAddAnotherPopup to use custom height and width. */
> >> >> function showAddAnotherPopup(triggeringLink) {
> >> >> @@ -29,29 +29,46 @@
> >> >> {% endblock %}
> >> >>
> >> >> {% block content %}
> >> >> - <form method="POST" action="">{% csrf_token %}
> >> >> + <form method="POST" action="" name="projsettings">{% csrf_token %}
> >> >> <div class="module aligned ">
> >> >> {% for field in form %}
> >> >> - <div class="form-row {% if line.errors %} errors{% endif %} {{ field.name }}">
> >> >> - <div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}>
> >> >> - {% if field.is_checkbox %}
> >> >> - {{ field }}{{ field.label_tag }}
> >> >> - {% else %}
> >> >> - {{ field.label_tag }}
> >> >> - {% if field.is_readonly %}
> >> >> - <p>{{ field.contents }}</p>
> >> >> + {% if field.html_name == "lp_user" or field.html_name == "lp_ssh_key_input"%}
> >> >
> >> > This is no longer needed, right? We've agreed on that in the previous
> >> > review already, IIRC.
> >>
> >> It is still required because the new fields are part of the project
> >> form, so they need to be filtered out where they aren't needed.
> >
> > But the template is the worst place to do that, because the templating
> > language is not as powerfull as python and testing templates is harder
> > (and usually slower) than testing forms/views. And the above looks like
> > an ugly hack to me because of the empty if block, without even a
> > comment.
> >
> > Having said that, I've just noticed that you already exclude the
> > unwanted fields in the form used by this template, so unless I'm missing
> > something this isn't needed.
> >
> > class EditProjectForm(ProjectBaseForm):
> > launchpad_project = ModelChoiceField(
> > LaunchpadProject.objects, widget=SelectWithAddNew, required=False)
> > class Meta(ProjectBaseForm.Meta):
> > exclude = ('name', 'priority', 'is_active', 'access_groups',
> > 'lp_user', 'lp_ssh_key_input')
> >
> > I thought the above would be enough to get rid of the lp_* fields on the
> > edit page, but I've j...

Read more...

Guilherme Salgado (salgado) wrote :

Ok, so after admitting this code was too complicated for my small brain I decided to try and simplify it a bit. lp:~salgado/offspring/ssh_ui_mods has a simpler version of this, with a much simpler form class, no need for the custom field and validation on the lowest possible level. As a bonus I've also fixed a bug in which the +editcredentials page was setting some attributes back to their default values because these fields were not in Meta.exclude, but also weren't rendered in the template (the list of fields rendered there are hard-coded to just lp_user and lp_ssh_key).

The key was using separate form classes depending on whether you're creating or editing a project and moving the validation to the model so that it's used in both forms. Please let me know if it looks good, James, or if you see any issues with it: https://code.launchpad.net/~salgado/offspring/ssh_ui_mods/+merge/81641

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'lib/offspring/web/media/js/jquery.placeholder.js'
2--- lib/offspring/web/media/js/jquery.placeholder.js 1970-01-01 00:00:00 +0000
3+++ lib/offspring/web/media/js/jquery.placeholder.js 2011-11-03 22:20:29 +0000
4@@ -0,0 +1,106 @@
5+/*
6+* Placeholder plugin for jQuery
7+* ---
8+* Copyright 2010, Daniel Stocks (http://webcloud.se)
9+* Released under the MIT, BSD, and GPL Licenses.
10+*/
11+(function($) {
12+ function Placeholder(input) {
13+ this.input = input;
14+ if (input.attr('type') == 'password') {
15+ this.handlePassword();
16+ }
17+ // Prevent placeholder values from submitting
18+ $(input[0].form).submit(function() {
19+ if (input.hasClass('placeholder') && input[0].value == input.attr('placeholder')) {
20+ input[0].value = '';
21+ }
22+ });
23+ }
24+ Placeholder.prototype = {
25+ show : function(loading) {
26+ // FF and IE saves values when you refresh the page. If the user refreshes the page with
27+ // the placeholders showing they will be the default values and the input fields won't be empty.
28+ if (this.input[0].value === '' || (loading && this.valueIsPlaceholder())) {
29+ if (this.isPassword) {
30+ try {
31+ this.input[0].setAttribute('type', 'text');
32+ } catch (e) {
33+ this.input.before(this.fakePassword.show()).hide();
34+ }
35+ }
36+ this.input.addClass('placeholder');
37+ this.input[0].value = this.input.attr('placeholder');
38+ }
39+ },
40+ hide : function() {
41+ if (this.valueIsPlaceholder() && this.input.hasClass('placeholder')) {
42+ this.input.removeClass('placeholder');
43+ this.input[0].value = '';
44+ if (this.isPassword) {
45+ try {
46+ this.input[0].setAttribute('type', 'password');
47+ } catch (e) { }
48+ // Restore focus for Opera and IE
49+ this.input.show();
50+ this.input[0].focus();
51+ }
52+ }
53+ },
54+ valueIsPlaceholder : function() {
55+ return this.input[0].value == this.input.attr('placeholder');
56+ },
57+ handlePassword: function() {
58+ var input = this.input;
59+ input.attr('realType', 'password');
60+ this.isPassword = true;
61+ // IE < 9 doesn't allow changing the type of password inputs
62+ if ($.browser.msie && input[0].outerHTML) {
63+ var fakeHTML = $(input[0].outerHTML.replace(/type=(['"])?password\1/gi, 'type=$1text$1'));
64+ this.fakePassword = fakeHTML.val(input.attr('placeholder')).addClass('placeholder').focus(function() {
65+ input.trigger('focus');
66+ $(this).hide();
67+ });
68+ $(input[0].form).submit(function() {
69+ fakeHTML.remove();
70+ input.show()
71+ });
72+ }
73+ }
74+ };
75+ var NATIVE_SUPPORT = !!("placeholder" in document.createElement( "input" ));
76+ $.fn.placeholder = function() {
77+ return NATIVE_SUPPORT ? this : this.each(function() {
78+ var input = $(this);
79+ var placeholder = new Placeholder(input);
80+ placeholder.show(true);
81+ input.focus(function() {
82+ placeholder.hide();
83+ });
84+ input.blur(function() {
85+ placeholder.show(false);
86+ });
87+
88+ // On page refresh, IE doesn't re-populate user input
89+ // until the window.onload event is fired.
90+ if ($.browser.msie) {
91+ $(window).load(function() {
92+ if(input.val()) {
93+ input.removeClass("placeholder");
94+ }
95+ placeholder.show(true);
96+ });
97+ // What's even worse, the text cursor disappears
98+ // when tabbing between text inputs, here's a fix
99+ input.focus(function() {
100+ if(this.value == "") {
101+ var range = this.createTextRange();
102+ range.collapse(true);
103+ range.moveStart('character', 0);
104+ range.select();
105+ }
106+ });
107+ }
108+ });
109+ }
110+})(jQuery);
111
112=== modified file 'lib/offspring/web/queuemanager/admin.py'
113--- lib/offspring/web/queuemanager/admin.py 2011-02-24 05:08:42 +0000
114+++ lib/offspring/web/queuemanager/admin.py 2011-11-03 22:20:29 +0000
115@@ -43,7 +43,9 @@
116
117
118 class ProjectAdmin(admin.ModelAdmin):
119- fields = ['title', 'name', 'arch', 'project_group', 'launchpad_project', 'suite', 'series', 'priority', 'status', 'is_active', 'config_url', 'notes']
120+ fields = ['title', 'name', 'arch', 'project_group', 'launchpad_project',
121+ 'suite', 'series', 'priority', 'status', 'is_active',
122+ 'config_url', 'lp_user', 'lp_ssh_key_input', 'notes']
123 list_display = ('display_name', 'arch', 'series', 'project_group', 'launchpad_project', 'is_active', 'status', 'priority', 'config_url')
124 list_filter = ['arch', 'series', 'is_active', 'project_group', 'status']
125 search_fields = ['title', 'name', 'arch', 'notes']
126
127=== modified file 'lib/offspring/web/queuemanager/forms.py'
128--- lib/offspring/web/queuemanager/forms.py 2011-10-19 20:23:49 +0000
129+++ lib/offspring/web/queuemanager/forms.py 2011-11-03 22:20:29 +0000
130@@ -1,8 +1,11 @@
131 # Copyright 2010 Canonical Ltd. This software is licensed under the
132 # GNU Affero General Public License version 3 (see the file LICENSE).
133
134+import re
135+
136 from django.contrib.auth.models import User
137 from django.db import models
138+from django import forms
139 from django.forms import (
140 Form, ModelChoiceField, ModelForm, Textarea, TextInput, ValidationError)
141 from django.forms import fields
142@@ -15,9 +18,125 @@
143
144 from offspring.web.queuemanager.widgets import SelectWithAddNew
145
146-class ProjectBaseForm(ModelForm):
147- status = fields.CharField(max_length=200,
148- widget=fields.Select(choices=Project.STATUS_CHOICES), required=True)
149+class SSHPrivateKeyField(forms.Field):
150+
151+ def validate(self, value):
152+ "Check to see if the value looks like an SSH private key"
153+
154+ # Use the parent's handling of required fields, etc.
155+ super(SSHPrivateKeyField, self).validate(value)
156+ if not value: # If nothing is passed, don't try and validate it.
157+ return
158+
159+ key_search_regexp = (r"-----BEGIN \w+ PRIVATE KEY-----"+
160+ r".*"+
161+ r"-----END \w+ PRIVATE KEY-----")
162+ is_key = re.search(key_search_regexp, value, re.DOTALL | re.MULTILINE)
163+
164+ if not is_key:
165+ msg = ("The key you entered doesn't appear to be valid. I am "+
166+ "expecting a key in the form:\n "+
167+ "-----BEGIN <type> PRIVATE KEY-----\n"+
168+ "<ASCII key>\n"+
169+ "-----END <type> PRIVATE KEY-----\n")
170+ raise forms.ValidationError(msg)
171+
172+class ProjectSSHCredForm(ModelForm):
173+ ssh_help = ("Enter a private SSH ASCII key block, complete with begin "+
174+ "and end markers.")
175+
176+ lp_ssh_key_input = SSHPrivateKeyField(label="Launchpad User's SSH key",
177+ required=False,
178+ widget=forms.Textarea(
179+ attrs={'cols': 70, 'rows' : 4}),
180+ help_text=ssh_help)
181+
182+ lp_fields_set = False
183+ lp_ssh_set = False
184+ lp_ssh_set_message = ("An SSH key is stored for this project. To replace "+
185+ "it, paste a new SSH private key block here.")
186+ lp_ssh_clear_meessage = ("To enable access to private repositories,"+
187+ "enter an SSH private key here in the form of an "+
188+ "ASCII key block.")
189+
190+ def __init__(self, *args, **kwargs):
191+ super(ProjectSSHCredForm, self).__init__(*args, **kwargs)
192+ # Set the form fields based on the model object
193+ if kwargs.has_key('instance'):
194+ self.has_instance = True
195+ instance = kwargs['instance']
196+ if instance.lp_ssh_key:
197+ self.lp_ssh_set = True
198+ else:
199+ self.lp_ssh_set = False
200+
201+ if instance.lp_user:
202+ self.lp_user_set = True
203+ else:
204+ self.lp_user_set = False
205+
206+ self.lp_fields_set = instance.lp_ssh_key or instance.lp_user
207+ else:
208+ self.has_instance = None
209+
210+ def get_ssh_key_set(self):
211+ if self.has_instance: # self.lp_user_set valid if instance exists
212+ return self.lp_ssh_set or self.data['lp_ssh_key_input']
213+ return self.data['lp_ssh_key_input'] != ""
214+
215+ def get_lp_user_set(self):
216+ if self.has_instance: # self.lp_user_set valid if instance exists
217+ return self.lp_user_set or self.data['lp_user']
218+ return self.data['lp_user'] != ""
219+
220+ def clean_lp_user(self):
221+ # We don't want to check that lp_user and SSH key are both set or clear
222+ # if we are on a project edit page that doesn't provide these fields.
223+ key_set = self.get_ssh_key_set()
224+ user_set = self.get_lp_user_set()
225+
226+ if not user_set and key_set:
227+ raise forms.ValidationError("Launchpad User is required.")
228+
229+ return self.cleaned_data['lp_user']
230+
231+ def clean_lp_ssh_key_input(self):
232+ # We have to manually check the exclude list for lp_ssh_key_input
233+ # because it isn't excluded automatically, which seems to be the case
234+ # because it was defined in this class.
235+ if "lp_ssh_key_input" not in self.Meta.exclude:
236+ key_set = self.get_ssh_key_set()
237+ user_set = self.get_lp_user_set()
238+
239+ if not key_set and user_set:
240+ raise forms.ValidationError("SSH Key is required.")
241+
242+ return self.cleaned_data['lp_ssh_key_input']
243+
244+ class Meta:
245+ model = Project
246+ widgets = {
247+ 'lp_user' : Textarea(attrs={'cols': 70, 'rows' : 1}),
248+ }
249+
250+class ProjectBaseForm(ProjectSSHCredForm):
251+ def save(self, commit=True):
252+ model = super(ProjectBaseForm, self).save(commit=False)
253+
254+ if 'lp_ssh_key_input' in self.cleaned_data:
255+ # Save the SSH key
256+ new_key = self.cleaned_data['lp_ssh_key_input']
257+
258+ if new_key == "":
259+ pass # No new key entered
260+
261+ else: # Save new key (validated in clean_lp_ssh_key_input)
262+ model.lp_ssh_key = new_key
263+
264+ if commit:
265+ model.save()
266+
267+ return model
268
269 class Meta:
270 model = Project
271@@ -25,7 +144,8 @@
272 'name' : TextInput(attrs={'style': 'text-transform: lowercase;'}),
273 'series' : TextInput(attrs={'style': 'text-transform: lowercase;'}),
274 'config_url': TextInput(attrs={'size': 50}),
275- 'notes' : Textarea(attrs={'cols': 73, 'rows' : 4}),
276+ 'notes' : Textarea(attrs={'cols': 70, 'rows' : 4}),
277+ 'lp_user' : Textarea(attrs={'cols': 70, 'rows' : 1}),
278 }
279
280 def clean_name(self):
281@@ -52,7 +172,15 @@
282 launchpad_project = ModelChoiceField(
283 LaunchpadProject.objects, widget=SelectWithAddNew, required=False)
284 class Meta(ProjectBaseForm.Meta):
285- exclude = ('name', 'priority', 'is_active', 'access_groups')
286+ exclude = ('name', 'priority', 'is_active', 'access_groups',
287+ 'lp_user', 'lp_ssh_key_input')
288+
289+
290+class EditProjectSSHCredentialsForm(ProjectSSHCredForm):
291+ class Meta(ProjectSSHCredForm.Meta):
292+ exclude = ('priority', 'is_active', 'suite', 'access_groups', 'arch',
293+ 'config_url', 'name', 'priority', 'series', 'status',
294+ 'title')
295
296
297 class AccessGroupMemberForm(Form):
298
299=== modified file 'lib/offspring/web/queuemanager/models.py'
300--- lib/offspring/web/queuemanager/models.py 2011-10-21 16:44:19 +0000
301+++ lib/offspring/web/queuemanager/models.py 2011-11-03 22:20:29 +0000
302@@ -233,7 +233,7 @@
303 # The Launchpad User and SSH key are stored per project. If we stored them
304 # per LauncpadProject, anyone who could create a Project referencing that
305 # LaunchpadProject could get access to the private data in it.
306- lp_user = models.TextField('Launchpad User', null=True, editable=False,
307+ lp_user = models.TextField('Launchpad User', null=True,
308 blank=True)
309 lp_ssh_key = models.TextField("Launchpad User's SSH Key", blank=True,
310 null=True, editable=False)
311
312=== modified file 'lib/offspring/web/queuemanager/tests/test_views.py'
313--- lib/offspring/web/queuemanager/tests/test_views.py 2011-10-21 14:36:55 +0000
314+++ lib/offspring/web/queuemanager/tests/test_views.py 2011-11-03 22:20:29 +0000
315@@ -8,6 +8,8 @@
316 Template,
317 )
318 from django.test import TestCase
319+from django.test.client import Client
320+from django.contrib.auth.models import User
321
322 from offspring.enums import ProjectBuildStates
323 from offspring.web.queuemanager.models import (
324@@ -138,6 +140,108 @@
325 status_code=200, msg_prefix=response.content)
326
327
328+class ProjectEditSSHViewTests(TestCase):
329+ def test_edit_ssh_auth(self):
330+ project = factory.makeProject(is_private=True)
331+ user = project.owner
332+ grant_permission_to_user(user, 'change_project')
333+ self.assertTrue(
334+ self.client.login(username=user.username, password=user.username))
335+
336+ key = ("-----BEGIN type PRIVATE KEY-----\n"+
337+ "12qwaszx34erdfcv\n"+
338+ "-----END type PRIVATE KEY-----\n")
339+
340+ data = {'lp_user': "lpuser",
341+ 'lp_ssh_key_input': key,
342+ '_save': 1}
343+ response = self.client.post(
344+ reverse('offspring.web.queuemanager.views.project_editsshcredentials',
345+ args=[project.name]),
346+ data, follow=True)
347+
348+ self.assertEqual(200, response.status_code)
349+
350+ # re-load the project from the database to pick up changes
351+ user_visible_objects = Project.all_objects.accessible_by_user(user)
352+ project = get_possibly_private_object(
353+ user, user_visible_objects, pk=project.name)
354+
355+ self.assertEqual('lpuser', project.lp_user)
356+ self.assertEqual(key, project.lp_ssh_key)
357+
358+ def test_edit_ssh_auth_bad_key(self):
359+ project = factory.makeProject(is_private=True)
360+ user = project.owner
361+ grant_permission_to_user(user, 'change_project')
362+ self.assertTrue(
363+ self.client.login(username=user.username, password=user.username))
364+
365+ key = ("-----BEGIN type PR---VATE KEY-----\n"+
366+ "12qwaszx34erdfcv\n"+
367+ "-----END type PRIVATE KEY-----\n")
368+
369+ data = {'lp_user': "lpuser",
370+ 'lp_ssh_key_input': key,
371+ '_save': 1}
372+ response = self.client.post(
373+ reverse('offspring.web.queuemanager.views.project_editsshcredentials',
374+ args=[project.name]),
375+ data, follow=True)
376+
377+ self.assertEqual(200, response.status_code)
378+
379+ # re-load the project from the database to pick up changes
380+ user_visible_objects = Project.all_objects.accessible_by_user(user)
381+ project = get_possibly_private_object(
382+ user, user_visible_objects, pk=project.name)
383+
384+ self.assertNotEqual('lpuser', project.lp_user)
385+ self.assertNotEqual(key, project.lp_ssh_key)
386+
387+ def test_edit_ssh_auth_private_protected(self):
388+ project = factory.makeProject(is_private=True)
389+ user = factory.makeUser()
390+ self.assertTrue(
391+ self.client.login(username=user.username, password=user.username))
392+
393+ # Check can't read a private projects ssh cred page
394+ response = self.client.get(
395+ reverse('offspring.web.queuemanager.views.project_editsshcredentials',
396+ args=[project.name]), follow=True)
397+ self.assertEqual(200, response.status_code)
398+ self.assertContains(response, "Lexbuilder Control Administration")
399+ self.assertContains(response, "Username")
400+ self.assertContains(response, "Password")
401+
402+ # Check can't write to a private projects ssh cred page
403+ key = ("-----BEGIN type PR---VATE KEY-----\n"+
404+ "12qwaszx34erdfcv\n"+
405+ "-----END type PRIVATE KEY-----\n")
406+
407+ data = {'lp_user': "lpuser",
408+ 'lp_ssh_key_input': key,
409+ '_save': 1}
410+ response = self.client.post(
411+ reverse('offspring.web.queuemanager.views.project_editsshcredentials',
412+ args=[project.name]),
413+ data, follow=True)
414+
415+ self.assertEqual(200, response.status_code)
416+ self.assertContains(response, "Lexbuilder Control Administration")
417+ self.assertContains(response, "Username")
418+ self.assertContains(response, "Password")
419+
420+ # re-load the project from the database to pick up changes
421+ user_visible_objects = Project.all_objects.accessible_by_user(
422+ project.owner)
423+ project = get_possibly_private_object(
424+ project.owner, user_visible_objects, pk=project.name)
425+
426+ self.assertNotEqual('lpuser', project.lp_user)
427+ self.assertNotEqual(key, project.lp_ssh_key)
428+
429+
430 class ProjectCreateViewTests(TestCase):
431 view_path = 'offspring.web.queuemanager.views.project_create'
432
433@@ -156,7 +260,9 @@
434 '_is_private': [u'on'],
435 '_save': [u'Save'],
436 'series': [u'natty'],
437- 'arch': [u'amd64']}
438+ 'arch': [u'amd64'],
439+ 'lp_user': '',
440+ 'lp_ssh_key_input': ''}
441 response = self.client.post(reverse(self.view_path), data)
442 self.assertContains(
443 response, 'A private project needs an owner',
444
445=== modified file 'lib/offspring/web/queuemanager/views.py'
446--- lib/offspring/web/queuemanager/views.py 2011-10-20 16:08:24 +0000
447+++ lib/offspring/web/queuemanager/views.py 2011-11-03 22:20:29 +0000
448@@ -45,6 +45,7 @@
449 AccessGroupMemberForm,
450 CreateProjectForm,
451 EditProjectForm,
452+ EditProjectSSHCredentialsForm,
453 LaunchpadProjectForm,
454 ReleaseForm,
455 )
456@@ -356,6 +357,52 @@
457 'queuemanager/project_acl.html', pageData,
458 context_instance=RequestContext(request))
459
460+@permission_required('queuemanager.change_project')
461+def project_editsshcredentials(request, projectName):
462+ user_visible_objects = Project.all_objects.accessible_by_user(
463+ request.user)
464+ project = get_possibly_private_object(
465+ request.user, user_visible_objects, pk=projectName)
466+ access_group = None
467+ allowed_users = []
468+ if len(project.access_groups.all()) > 0:
469+ # We always use the first access group because there's no way for
470+ # users to register more than one access group for any given project.
471+ access_group = project.access_groups.all()[0]
472+ allowed_users = access_group.members.all()
473+
474+ if request.method == 'POST':
475+
476+ form = EditProjectSSHCredentialsForm(request.POST, instance=project)
477+
478+ # Don't validate the data (call form.is_valid) before deleting - we
479+ # don't care what the form input is since we don't use it.
480+ if "delete" in request.POST:
481+ project.lp_user = ""
482+ project.lp_ssh_key = ""
483+ project.save()
484+ return HttpResponseRedirect(".")
485+
486+ if form.is_valid():
487+ if "_save" in request.POST:
488+ project.lp_user = form.cleaned_data['lp_user']
489+ if form.cleaned_data['lp_ssh_key_input']:
490+ project.lp_ssh_key = form.cleaned_data['lp_ssh_key_input']
491+ project.save()
492+
493+ return HttpResponseRedirect(".")
494+
495+ else:
496+ form = EditProjectSSHCredentialsForm(instance=project)
497+ pageData = {
498+ 'csrf_token' : csrf.get_token(request),
499+ 'project' : project,
500+ 'form': form,
501+ 'allowed_users': allowed_users,
502+ }
503+ return render_to_response(
504+ 'queuemanager/project_edit_credentials.html', pageData,
505+ context_instance=RequestContext(request))
506
507 def projectgroup_details(request, projectGroupName):
508 pg = get_object_or_404(
509
510=== modified file 'lib/offspring/web/templates/queuemanager/project_create.html'
511--- lib/offspring/web/templates/queuemanager/project_create.html 2011-02-28 22:48:46 +0000
512+++ lib/offspring/web/templates/queuemanager/project_create.html 2011-11-03 22:20:29 +0000
513@@ -5,7 +5,9 @@
514 {% endblock %}
515
516 {% block header_js %}
517-<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
518+<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
519+<script type="text/javascript" src="/media/js/jquery.min.js"></script>
520+<script type="text/javascript" src="/assets/js/jquery.placeholder.js"></script>
521 <script type="text/javascript">
522 /* Override showAddAnotherPopup to use custom height and width. */
523 function showAddAnotherPopup(triggeringLink) {
524@@ -29,29 +31,68 @@
525 {% endblock %}
526
527 {% block content %}
528- <form method="POST" action="">{% csrf_token %}
529+ <form method="POST" action="" name="projsettings">{% csrf_token %}
530 <div class="module aligned ">
531 {% for field in form %}
532- <div class="form-row {% if line.errors %} errors{% endif %} {{ field.name }}">
533- <div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}>
534- {% if field.is_checkbox %}
535- {{ field }}{{ field.label_tag }}
536- {% else %}
537- {{ field.label_tag }}
538- {% if field.is_readonly %}
539- <p>{{ field.contents }}</p>
540+ {% if field.html_name == "lp_user" or field.html_name == "lp_ssh_key_input" %}
541+ <!-- This catches lp_user and lp_ssh_key_input so they aren't shown in the top of
542+ the page. They are displayed below in their own section after some help text -->
543+ {% else %}
544+ <div class="form-row {% if line.errors %} errors{% endif %} {{ field.name }}">
545+ <div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}>
546+ {% if field.is_checkbox %}
547+ {{ field }}{{ field.label_tag }}
548 {% else %}
549- {{ field }}
550- {% endif %}
551- {% endif %}
552- {% if field.field.field.help_text %}
553- <p class="help">{{ field.field.field.help_text|safe }}</p>
554- {% endif %}
555+ {{ field.label_tag }}
556+ {% if field.is_readonly %}
557+ <p>{{ field.contents }}</p>
558+ {% else %}
559+ {{ field }}
560+ {% endif %}
561+ {% endif %}
562+ {% if field.field.field.help_text %}
563+ <p class="help">{{ field.field.field.help_text|safe }}</p>
564+ {% endif %}
565+ </div>
566+ {{ field.errors }}
567 </div>
568- {{ field.errors }}
569- </div>
570+ {% endif %}
571
572 {% endfor %}
573+
574+ <br>
575+ If the config URL above points to a Bazaar repository that is only
576+ available to authenticated users, you should add a user and private SSH
577+ key to give the builder access. The SSH key will never be revealed. It
578+ can be changed or deleted later. It should not be passphrase protected.
579+ If you would like to add these details, tick here:
580+
581+ <br>
582+
583+ <div class="form-row {{ form.lp_user.name }}">
584+ <div class="field-box">
585+ {{ form.lp_user.label_tag }}
586+ <br>
587+ {{ form.lp_user }}
588+ </div>
589+ {{ form.lp_user.errors }}
590+ </div>
591+
592+ <div class="form-row {{ form.lp_ssh_key_input.name }}">
593+ <div class="field-box">
594+ {{ form.lp_ssh_key_input.label_tag }}
595+ <br>
596+ <textarea id="id_lp_ssh_key_input" rows="4" cols="70" name="lp_ssh_key_input"
597+ placeholder="{% if form.lp_ssh_set %}{{ form.lp_ssh_set_message }}{% else %}{{ form.lp_ssh_clear_meessage }}{% endif %}"></textarea>
598+ {% if form.lp_ssh_key_input.help_text %}
599+ <p class="help">{{ form.lp_ssh_key_input.help_text|safe }}</p>
600+ {% endif %}
601+ </div>
602+ {{ form.lp_ssh_key_input.errors|linebreaksbr }}
603+ </div>
604+
605+ <br>
606+
607 <div class="submit-row" style="overflow: auto;">
608 <input type="submit" value="Save" class="default" name="_save"/>
609 <input type="button" value="Cancel" class="default" name="_cancel" OnClick="window.location.href = '/';"/>
610
611=== modified file 'lib/offspring/web/templates/queuemanager/project_edit.html'
612--- lib/offspring/web/templates/queuemanager/project_edit.html 2011-03-03 01:50:40 +0000
613+++ lib/offspring/web/templates/queuemanager/project_edit.html 2011-11-03 22:20:29 +0000
614@@ -5,7 +5,7 @@
615 {% endblock %}
616
617 {% block header_js %}
618-<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
619+<script type="text/javascript" src="/media/js/admin/RelatedObjectLookups.js"></script>
620 <script type="text/javascript">
621 /* Override showAddAnotherPopup to use custom height and width. */
622 function showAddAnotherPopup(triggeringLink) {
623@@ -29,29 +29,46 @@
624 {% endblock %}
625
626 {% block content %}
627- <form method="POST" action="">{% csrf_token %}
628+ <form method="POST" action="" name="projsettings">{% csrf_token %}
629 <div class="module aligned ">
630 {% for field in form %}
631- <div class="form-row {% if line.errors %} errors{% endif %} {{ field.name }}">
632- <div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}>
633- {% if field.is_checkbox %}
634- {{ field }}{{ field.label_tag }}
635- {% else %}
636- {{ field.label_tag }}
637- {% if field.is_readonly %}
638- <p>{{ field.contents }}</p>
639+ {% if field.html_name == "lp_user" or field.html_name == "lp_ssh_key_input"%}
640+ {% else %}
641+ <div class="form-row {% if line.errors %} errors{% endif %} {{ field.name }}">
642+ <div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}>
643+ {% if field.is_checkbox %}
644+ {{ field }}{{ field.label_tag }}
645 {% else %}
646- {{ field }}
647- {% endif %}
648- {% endif %}
649- {% if field.field.field.help_text %}
650- <p class="help">{{ field.field.field.help_text|safe }}</p>
651- {% endif %}
652+ {{ field.label_tag }}
653+ {% if field.is_readonly %}
654+ <p>{{ field.contents }}</p>
655+ {% else %}
656+ {{ field }}
657+ {% endif %}
658+ {% endif %}
659+ {% if field.help_text %}
660+ <p class="help">{{ field.help_text|safe }}</p>
661+ {% endif %}
662+ </div>
663+ {{ field.errors }}
664 </div>
665- {{ field.errors }}
666- </div>
667+ {% endif %}
668
669 {% endfor %}
670+
671+ <br>
672+ If the config URL above points to a Bazaar repository that is only
673+ available to authenticated users, you should add a user and private SSH
674+ key to give the builder access. The SSH key will never be revealed. It
675+ can be changed or deleted later. It should not be passphrase protected.
676+
677+ {% if form.lp_fields_set %}
678+ To update or delete these details, use
679+ {% else %}
680+ If you would like to add these details,
681+ {% endif %}
682+ <a href="+editcredentials">use this form.</a>
683+
684 <div class="submit-row" style="overflow: auto;">
685 <input type="submit" value="Save" class="default" name="_save"/>
686 <input type="button" value="Cancel" class="default" name="_cancel" OnClick="window.location.href = '{% url offspring.web.queuemanager.views.project_details project.name %}';"/>
687
688=== added file 'lib/offspring/web/templates/queuemanager/project_edit_credentials.html'
689--- lib/offspring/web/templates/queuemanager/project_edit_credentials.html 1970-01-01 00:00:00 +0000
690+++ lib/offspring/web/templates/queuemanager/project_edit_credentials.html 2011-11-03 22:20:29 +0000
691@@ -0,0 +1,64 @@
692+{% extends "base.html" %}
693+
694+{% block header_css %}
695+<link rel="stylesheet" type="text/css" href="/media/css/forms.css" />
696+{% endblock %}
697+
698+{% block header_js %}
699+<script type="text/javascript" src="/media/js/jquery.min.js"></script>
700+<script type="text/javascript" src="/assets/js/jquery.placeholder.js"></script>
701+{% endblock %}
702+
703+{% block title %}
704+Update SSH Credentials for {{project.title|capfirst}}
705+{% endblock %}
706+
707+{% block content %}
708+ <form method="POST" action="" name="projsettings">{% csrf_token %}
709+ {{ formset.non_form_errors }}
710+ <div class="module aligned ">
711+ <div class="form-row {{ form.lp_user.name }}">
712+ <div class="field-box">
713+ {{ form.lp_user.label_tag }}
714+ <br>
715+ {{ form.lp_user }}
716+ </div>
717+ {{ form.lp_user.errors }}
718+ </div>
719+
720+ <div class="form-row {{ form.lp_ssh_key_input.name }}">
721+ <div class="field-box">
722+ {{ form.lp_ssh_key_input.label_tag }}
723+ <br>
724+ <textarea id="id_lp_ssh_key_input" rows="4" cols="70" name="lp_ssh_key_input"
725+ placeholder="{% if form.lp_ssh_set %}{{ form.lp_ssh_set_message }}{% else %}{{ form.lp_ssh_clear_meessage }}{% endif %}"></textarea>
726+ {% if form.lp_ssh_key_input.help_text %}
727+ <p class="help">
728+ {{ form.lp_ssh_key_input.help_text|safe }}
729+ {% if form.lp_ssh_set %}
730+ Your saved key is not shown. To replace it, paste a new key in the above box.
731+ {% else %}
732+ No key is stored for this project. Saved keys are not shown.
733+ {% endif %}
734+ </p>
735+ {% endif %}
736+ </div>
737+ {{ form.lp_ssh_key_input.errors|linebreaksbr }}
738+ </div>
739+
740+ <br>
741+
742+ <div class="submit-row" style="overflow: auto;">
743+ <input type="submit" value="Save Updated Credentials" class="default" name="_save"/>
744+ <input type="submit" value="Delete Existing Credentials" class="default" name="delete"/>
745+ <input type="button" value="Cancel" class="default" name="_cancel" OnClick="window.location.href = '{% url offspring.web.queuemanager.views.project_details project.name %}';"/>
746+ </div>
747+ </div>
748+ </form>
749+{% endblock %}
750+
751+{% block two-columns %}
752+<script>
753+ $('input[placeholder], textarea[placeholder]').placeholder();
754+</script>
755+{% endblock %}
756
757=== modified file 'lib/offspring/web/urls.py'
758--- lib/offspring/web/urls.py 2011-10-18 15:17:15 +0000
759+++ lib/offspring/web/urls.py 2011-11-03 22:20:29 +0000
760@@ -79,6 +79,7 @@
761 (r'^projects/(?P<projectName>[^/]+)/\+api/buildrequest/(?P<request_id>[^/]+)/$', buildrequest_handler),
762 (r'^projects/(?P<projectName>[^/]+)/\+build$', 'offspring.web.queuemanager.views.queue_build'),
763 (r'^projects/(?P<projectName>[^/]+)/\+builds$', 'offspring.web.queuemanager.views.builds'),
764+ (r'^projects/(?P<projectName>[^/]+)/\+editcredentials$', 'offspring.web.queuemanager.views.project_editsshcredentials'),
765 (r'^projects/(?P<projectName>[^/]+)/$', 'offspring.web.queuemanager.views.project_details'),
766 (r'^projects/$', 'offspring.web.queuemanager.views.projects'),
767 (r'^schedule/\+api/milestones/$', milestone_handler),

Subscribers

People subscribed via source and target branches