Merge lp:~linaro-infrastructure/linaro-ci-dashboard/admin-app-openid into lp:linaro-ci-dashboard

Proposed by Stevan Radaković
Status: Merged
Approved by: Данило Шеган
Approved revision: 20
Merged at revision: 6
Proposed branch: lp:~linaro-infrastructure/linaro-ci-dashboard/admin-app-openid
Merge into: lp:linaro-ci-dashboard
Diff against target: 101 lines (+63/-1)
3 files modified
dashboard/frontend/management/commands/setsuperuser.py (+40/-0)
dashboard/frontend/tests.py (+22/-1)
dashboard/settings.py (+1/-0)
To merge this branch: bzr merge lp:~linaro-infrastructure/linaro-ci-dashboard/admin-app-openid
Reviewer Review Type Date Requested Status
Данило Шеган (community) Approve
Review via email: mp+113738@code.launchpad.net

Description of the change

Add admin openID support.
Add manage.py command 'setsuperuser' for enabling openID users to be set as system admins.

To post a comment you must log in.
20. By Stevan Radaković

Add tests for setsuperuser command.

Revision history for this message
Deepti B. Kalakeri (deeptik) wrote :

changes looks good. We could probably change the command to be named as setasadmin or setassuperuser or setasstaff which immediately gives a sense of what the command actually does.

Revision history for this message
Данило Шеган (danilo) wrote :

Please resolve conflicts on this and then it's good to land.

review: Approve
21. By Stevan Radaković

Merging trunk and resolving conflicts.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'dashboard/frontend/management'
=== added file 'dashboard/frontend/management/__init__.py'
=== added directory 'dashboard/frontend/management/commands'
=== added file 'dashboard/frontend/management/commands/__init__.py'
=== added file 'dashboard/frontend/management/commands/setsuperuser.py'
--- dashboard/frontend/management/commands/setsuperuser.py 1970-01-01 00:00:00 +0000
+++ dashboard/frontend/management/commands/setsuperuser.py 2012-07-09 11:09:20 +0000
@@ -0,0 +1,40 @@
1# Copyright (C) 2012 Linaro
2#
3# This file is part of linaro-ci-dashboard.
4#
5# linaro-ci-dashboard is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Affero General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# linaro-ci-dashboard is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU Affero General Public License for more details.
14#
15# You should have received a copy of the GNU Affero General Public License
16# along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
17# Django settings for dashboard project.
18
19from django.core.management.base import BaseCommand, CommandError
20from django.contrib.auth.models import User
21
22
23class Command(BaseCommand):
24 args = '<username username ...>'
25 help = 'Sets specified user as superuser of the dashboard admin app'
26
27 def handle(self, *args, **options):
28 for username in args:
29 self.find_and_update_user(username)
30 self.stdout.write('Successfully updated user "%s" \n' % username)
31
32 def find_and_update_user(self, username):
33 try:
34 user = User.objects.get(username=username)
35 except User.DoesNotExist:
36 raise CommandError('User "%s" does not exist' % username)
37
38 user.is_staff = True
39 user.is_superuser = True
40 user.save()
041
=== modified file 'dashboard/frontend/tests.py'
--- dashboard/frontend/tests.py 2012-07-06 12:30:37 +0000
+++ dashboard/frontend/tests.py 2012-07-09 11:09:20 +0000
@@ -15,10 +15,12 @@
15#15#
16# You should have received a copy of the GNU Affero General Public License16# You should have received a copy of the GNU Affero General Public License
17# along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.17# along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
1818from django.core.management.base import CommandError
19from django.contrib.auth.models import User
19from django.test import TestCase20from django.test import TestCase
20from mock import Mock, patch21from mock import Mock, patch
2122
23import frontend.management.commands.setsuperuser as setsuperuser
22from frontend.views.home_page_view import HomePageView24from frontend.views.home_page_view import HomePageView
23from frontend.views.index_view import IndexView25from frontend.views.index_view import IndexView
2426
@@ -39,3 +41,22 @@
39 index_view.request = "some request data"41 index_view.request = "some request data"
40 context = IndexView.get_context_data(index_view)42 context = IndexView.get_context_data(index_view)
41 self.assertEqual(context['request'], "some request data")43 self.assertEqual(context['request'], "some request data")
44
45
46class SetsuperuserCommandTest(TestCase):
47
48 def setUp(self):
49 self.command = setsuperuser.Command()
50
51 def test_find_and_update_user_non_existing(self):
52 self.assertRaises(CommandError,
53 self.command.find_and_update_user,
54 ("non_existing_user"))
55
56 def test_find_and_update_user(self):
57 user = User(username="existing_user")
58 user.save()
59 self.command.find_and_update_user("existing_user")
60 user = User.objects.get(username="existing_user")
61 self.assertEquals(user.is_staff, True)
62 self.assertEquals(user.is_superuser, True)
4263
=== modified file 'dashboard/settings.py'
--- dashboard/settings.py 2012-07-06 12:49:00 +0000
+++ dashboard/settings.py 2012-07-09 11:09:20 +0000
@@ -147,6 +147,7 @@
147LOGIN_URL = '/openid/login/'147LOGIN_URL = '/openid/login/'
148OPENID_SSO_SERVER_URL = 'https://login.launchpad.net/'148OPENID_SSO_SERVER_URL = 'https://login.launchpad.net/'
149OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO = True149OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO = True
150OPENID_USE_AS_ADMIN_LOGIN = True
150151
151# A sample logging configuration. The only tangible logging152# A sample logging configuration. The only tangible logging
152# performed by this configuration is to send an email to153# performed by this configuration is to send an email to

Subscribers

People subscribed via source and target branches

to all changes: