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
1=== added directory 'dashboard/frontend/management'
2=== added file 'dashboard/frontend/management/__init__.py'
3=== added directory 'dashboard/frontend/management/commands'
4=== added file 'dashboard/frontend/management/commands/__init__.py'
5=== added file 'dashboard/frontend/management/commands/setsuperuser.py'
6--- dashboard/frontend/management/commands/setsuperuser.py 1970-01-01 00:00:00 +0000
7+++ dashboard/frontend/management/commands/setsuperuser.py 2012-07-09 11:09:20 +0000
8@@ -0,0 +1,40 @@
9+# Copyright (C) 2012 Linaro
10+#
11+# This file is part of linaro-ci-dashboard.
12+#
13+# linaro-ci-dashboard is free software: you can redistribute it and/or modify
14+# it under the terms of the GNU Affero General Public License as published by
15+# the Free Software Foundation, either version 3 of the License, or
16+# (at your option) any later version.
17+#
18+# linaro-ci-dashboard is distributed in the hope that it will be useful,
19+# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+# GNU Affero General Public License for more details.
22+#
23+# You should have received a copy of the GNU Affero General Public License
24+# along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
25+# Django settings for dashboard project.
26+
27+from django.core.management.base import BaseCommand, CommandError
28+from django.contrib.auth.models import User
29+
30+
31+class Command(BaseCommand):
32+ args = '<username username ...>'
33+ help = 'Sets specified user as superuser of the dashboard admin app'
34+
35+ def handle(self, *args, **options):
36+ for username in args:
37+ self.find_and_update_user(username)
38+ self.stdout.write('Successfully updated user "%s" \n' % username)
39+
40+ def find_and_update_user(self, username):
41+ try:
42+ user = User.objects.get(username=username)
43+ except User.DoesNotExist:
44+ raise CommandError('User "%s" does not exist' % username)
45+
46+ user.is_staff = True
47+ user.is_superuser = True
48+ user.save()
49
50=== modified file 'dashboard/frontend/tests.py'
51--- dashboard/frontend/tests.py 2012-07-06 12:30:37 +0000
52+++ dashboard/frontend/tests.py 2012-07-09 11:09:20 +0000
53@@ -15,10 +15,12 @@
54 #
55 # You should have received a copy of the GNU Affero General Public License
56 # along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
57-
58+from django.core.management.base import CommandError
59+from django.contrib.auth.models import User
60 from django.test import TestCase
61 from mock import Mock, patch
62
63+import frontend.management.commands.setsuperuser as setsuperuser
64 from frontend.views.home_page_view import HomePageView
65 from frontend.views.index_view import IndexView
66
67@@ -39,3 +41,22 @@
68 index_view.request = "some request data"
69 context = IndexView.get_context_data(index_view)
70 self.assertEqual(context['request'], "some request data")
71+
72+
73+class SetsuperuserCommandTest(TestCase):
74+
75+ def setUp(self):
76+ self.command = setsuperuser.Command()
77+
78+ def test_find_and_update_user_non_existing(self):
79+ self.assertRaises(CommandError,
80+ self.command.find_and_update_user,
81+ ("non_existing_user"))
82+
83+ def test_find_and_update_user(self):
84+ user = User(username="existing_user")
85+ user.save()
86+ self.command.find_and_update_user("existing_user")
87+ user = User.objects.get(username="existing_user")
88+ self.assertEquals(user.is_staff, True)
89+ self.assertEquals(user.is_superuser, True)
90
91=== modified file 'dashboard/settings.py'
92--- dashboard/settings.py 2012-07-06 12:49:00 +0000
93+++ dashboard/settings.py 2012-07-09 11:09:20 +0000
94@@ -147,6 +147,7 @@
95 LOGIN_URL = '/openid/login/'
96 OPENID_SSO_SERVER_URL = 'https://login.launchpad.net/'
97 OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO = True
98+OPENID_USE_AS_ADMIN_LOGIN = True
99
100 # A sample logging configuration. The only tangible logging
101 # performed by this configuration is to send an email to

Subscribers

People subscribed via source and target branches

to all changes: