launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06759
[Merge] lp:~rvb/maas/maas-no-user-message into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/maas-no-user-message into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~rvb/maas/maas-no-user-message/+merge/98191
This branch adds an error message to the login page if no user is present in the database. The message shows the command to be run to add an administrator user.
--
https://code.launchpad.net/~rvb/maas/maas-no-user-message/+merge/98191
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/maas-no-user-message into lp:maas.
=== modified file 'src/maas/demo.py'
--- src/maas/demo.py 2012-03-16 14:57:42 +0000
+++ src/maas/demo.py 2012-03-19 12:27:19 +0000
@@ -42,6 +42,7 @@
# This should match the setting in /etc/pserv.yaml.
PSERV_URL = "http://localhost:5241/api"
+MAAS_CLI = os.path.join(os.getcwd(), 'bin', 'maas')
LOGGING = {
'version': 1,
=== modified file 'src/maas/settings.py'
--- src/maas/settings.py 2012-03-16 14:38:57 +0000
+++ src/maas/settings.py 2012-03-19 12:27:19 +0000
@@ -45,6 +45,9 @@
LOGIN_REDIRECT_URL = '/'
LOGIN_URL = '/accounts/login/'
+# The MAAS CLI.
+MAAS_CLI = 'sudo maas'
+
# The location of the Longpoll server.
# Set LONGPOLL_SERVER_URL to have the web app proxy requests to
# a txlongpoll (note that this should only be required in a dev
=== modified file 'src/maasserver/templates/registration/login.html'
--- src/maasserver/templates/registration/login.html 2012-03-01 06:22:38 +0000
+++ src/maasserver/templates/registration/login.html 2012-03-19 12:27:19 +0000
@@ -21,7 +21,7 @@
<p class="form-errors">Your username and password didn't match. Please try again.</p>
{% endif %}
- <form method="post" action="{% url 'django.contrib.auth.views.login' %}">
+ <form method="post" action="{% url 'login' %}">
<input type="hidden" name="next" value="{{ next }}" />
<ul>
{% for field in form %}
=== modified file 'src/maasserver/tests/test_views.py'
--- src/maasserver/tests/test_views.py 2012-03-17 13:00:43 +0000
+++ src/maasserver/tests/test_views.py 2012-03-19 12:27:19 +0000
@@ -82,6 +82,32 @@
doc.cssselect('h2')])
+class TestLogin(TestCase):
+
+ def test_login_contains_input_tags(self):
+ response = self.client.get('/accounts/login/')
+ doc = fromstring(response.content)
+ self.assertEqual(1, len(doc.cssselect('input#id_username')))
+ self.assertEqual(1, len(doc.cssselect('input#id_password')))
+
+ def test_login_displays_createsuperuser_message_if_no_user(self):
+ path = factory.getRandomString()
+ self.patch(settings, 'MAAS_CLI', path)
+ response = self.client.get('/accounts/login/')
+ self.assertEqual(
+ [
+ "No user has been configured yet! "
+ "Run the following command to create an administrator user:"
+ "<pre>%s createsuperuser</pre>" % path
+ ],
+ [message.message for message in response.context['messages']])
+
+ def test_login_does_not_display_createsuperuser_message_if_user(self):
+ factory.make_user()
+ response = self.client.get('/accounts/login/')
+ self.assertEqual(0, len(response.context['messages']))
+
+
class TestSnippets(LoggedInTestCase):
def assertTemplateExistsAndContains(self, content, template_selector,
=== modified file 'src/maasserver/urls.py'
--- src/maasserver/urls.py 2012-03-16 16:16:11 +0000
+++ src/maasserver/urls.py 2012-03-19 12:27:19 +0000
@@ -20,7 +20,6 @@
url,
)
from django.contrib.auth.decorators import user_passes_test
-from django.contrib.auth.views import login
from django.views.generic.simple import (
direct_to_template,
redirect_to,
@@ -33,6 +32,7 @@
AccountsView,
combo_view,
KeystoreView,
+ login,
logout,
NodeListView,
NodesCreateView,
=== modified file 'src/maasserver/views.py'
--- src/maasserver/views.py 2012-03-15 18:38:12 +0000
+++ src/maasserver/views.py 2012-03-19 12:27:19 +0000
@@ -27,7 +27,10 @@
from django.contrib import messages
from django.contrib.auth.forms import PasswordChangeForm as PasswordForm
from django.contrib.auth.models import User
-from django.contrib.auth.views import logout as dj_logout
+from django.contrib.auth.views import (
+ login as dj_login,
+ logout as dj_logout,
+ )
from django.core.urlresolvers import reverse
from django.http import (
HttpResponse,
@@ -40,6 +43,7 @@
render_to_response,
)
from django.template import RequestContext
+from django.utils.safestring import mark_safe
from django.views.generic import (
CreateView,
DeleteView,
@@ -65,6 +69,16 @@
)
+def login(request):
+ if UserProfile.objects.all_users().count() == 0:
+ message = mark_safe(
+ "No user has been configured yet! "
+ "Run the following command to create an administrator user:"
+ "<pre>%s createsuperuser</pre>" % django_settings.MAAS_CLI)
+ messages.error(request, message)
+ return dj_login(request)
+
+
def logout(request):
messages.info(request, "You have been logged out.")
return dj_logout(request, next_page=reverse('login'))
Follow ups