diff options
author | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2011-08-09 15:59:45 -0400 |
---|---|---|
committer | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2011-08-09 15:59:45 -0400 |
commit | 0323a45504087bca852bc1171972e4380661b756 (patch) | |
tree | c40c526678a130b40c4031caa62c867b980e79fe | |
parent | 5b4841cf29eb62cbdc1cf86f07aac0a228420bb4 (diff) | |
download | askbot-0323a45504087bca852bc1171972e4380661b756.tar.gz askbot-0323a45504087bca852bc1171972e4380661b756.tar.bz2 askbot-0323a45504087bca852bc1171972e4380661b756.zip |
admin can add administrators too, added test cases, added postgres startup procedure
-rw-r--r-- | askbot/forms.py | 9 | ||||
-rw-r--r-- | askbot/models/__init__.py | 16 | ||||
-rw-r--r-- | askbot/startup_procedures.py | 22 | ||||
-rw-r--r-- | askbot/tests/form_tests.py | 28 |
4 files changed, 70 insertions, 5 deletions
diff --git a/askbot/forms.py b/askbot/forms.py index fb81f851..b13abe0c 100644 --- a/askbot/forms.py +++ b/askbot/forms.py @@ -343,7 +343,8 @@ MODERATOR_STATUS_CHOICES = ( ('s', _('suspended')), ('b', _('blocked')), ) -ADMINISTRATOR_STATUS_CHOICES = (('m', _('moderator')), ) \ +ADMINISTRATOR_STATUS_CHOICES = (('d', _('administrator')), + ('m', _('moderator')), ) \ + MODERATOR_STATUS_CHOICES @@ -427,6 +428,12 @@ class ChangeUserStatusForm(forms.Form): _('Cannot change status of another moderator') ) + #do not allow moderator to change to admin + if self.moderator.is_moderator() and user_status == 'd': + raise forms.ValidationError( + _("Cannot change status to admin") + ) + if user_status == 'select': del self.cleaned_data['user_status'] msg = _( diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index ecbd5fdd..098cfa1f 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -1502,19 +1502,29 @@ def user_set_status(self, new_status): if new status is applied to user, then the record is committed to the database """ + #d - administrator #m - moderator #s - suspended #b - blocked #w - watched #a - approved (regular user) - assert(new_status in ('m', 's', 'b', 'w', 'a')) + assert(new_status in ('d', 'm', 's', 'b', 'w', 'a')) if new_status == self.status: return #clear admin status if user was an administrator #because this function is not dealing with the site admins - if self.is_administrator(): - self.remove_admin_status() + + if new_status == 'd': + #create a new admin + self.set_admin_status() + else: + #This was the old method, kept in the else clause when changing + #to admin, so if you change the status to another thing that + #is not Administrator it will simply remove admin if the user have + #that permission, it will mostly be false. + if self.is_administrator(): + self.remove_admin_status() self.status = new_status self.save() diff --git a/askbot/startup_procedures.py b/askbot/startup_procedures.py index 3673ea3c..3e272aa7 100644 --- a/askbot/startup_procedures.py +++ b/askbot/startup_procedures.py @@ -127,6 +127,27 @@ def try_import(module_name, pypi_package_name): def test_modules(): try_import('recaptcha_works', 'django-recaptcha-works') +def test_postgres(): + '''Validates postgres buggy driver 2.4.2''' + if hasattr(django_settings, 'DATABASE_ENGINE'): + if django_settings.DATABASE_ENGINE in ('postgresql_psycopg2',): + try: + import psycopg2 + version = psycopg2.__version__.split(' ')[0].split('.') + if version == ['2', '4', '2']: + raise ImproperlyConfigured('Please install psycopg2 version 2.4.1,\n version 2.4.2 has a bug') + elif version > ['2', '4', '2']: + pass #don't know what to do + else: + pass #everythin is ok + except ImportError: + #Using mysql not a problem + pass + else: + pass #using other thing than postgres + else: + pass #TODO: test new django dictionary databases + def run_startup_tests(): """function that runs all startup tests, mainly checking settings config so far @@ -136,6 +157,7 @@ def run_startup_tests(): test_modules() test_askbot_url() test_i18n() + test_postgres() test_middleware() @transaction.commit_manually diff --git a/askbot/tests/form_tests.py b/askbot/tests/form_tests.py index 519d81c0..5e889382 100644 --- a/askbot/tests/form_tests.py +++ b/askbot/tests/form_tests.py @@ -244,9 +244,35 @@ class AskFormTests(AskbotTestCase): """ self.setup_data(ask_anonymously = True) self.assert_anon_is(True) - + def test_ask_anonymously_field_negative(self): """check that the 'no' selection goes through """ self.setup_data(ask_anonymously = False) self.assert_anon_is(False) + +class UserStatusFormTest(AskbotTestCase): + + def setup_data(self, status): + data = {'user_status': status} + self.moderator = self.create_user('moderator_user') + self.moderator.set_status('m') + self.subject = self.create_user('normal_user') + self.subject.set_status('a') + self.form = forms.ChangeUserStatusForm(data, moderator = self.moderator, + subject = self.subject) + def test_moderator_can_suspend_user(self): + self.setup_data('s') + self.assertEquals(self.form.is_valid(), True) + + def test_moderator_can_block_user(self): + self.setup_data('s') + self.assertEquals(self.form.is_valid(), True) + + def test_moderator_cannot_grant_admin(self): + self.setup_data('d') + self.assertEquals(self.form.is_valid(), False) + + def test_moderator_cannot_grant_moderator(self): + self.setup_data('m') + self.assertEquals(self.form.is_valid(), False) |