Commit 283e2b2e by cahrens

Don't store abbreviations for state.

parent 01557b26
......@@ -32,8 +32,7 @@ class CourseCreatorAdmin(admin.ModelAdmin):
)
# Fields that filtering support
list_filter = ['state', 'state_changed']
# Fields that search supports. Note that the search term for state has to be
# its key (ie, 'g' instead of 'granted').
# Fields that search supports.
search_fields = ['user__username', 'user__email', 'state', 'note']
# Turn off the action bar (we have no bulk actions)
actions = None
......
......@@ -13,7 +13,7 @@ class Migration(SchemaMigration):
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], unique=True)),
('state_changed', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('state', self.gf('django.db.models.fields.CharField')(default='u', max_length=1)),
('state', self.gf('django.db.models.fields.CharField')(default='unrequested', max_length=24)),
('note', self.gf('django.db.models.fields.CharField')(max_length=512, blank=True)),
))
db.send_create_signal('course_creators', ['CourseCreator'])
......@@ -65,7 +65,7 @@ class Migration(SchemaMigration):
'Meta': {'object_name': 'CourseCreator'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'note': ('django.db.models.fields.CharField', [], {'max_length': '512', 'blank': 'True'}),
'state': ('django.db.models.fields.CharField', [], {'default': "'u'", 'max_length': '1'}),
'state': ('django.db.models.fields.CharField', [], {'default': "'unrequested'", 'max_length': '24'}),
'state_changed': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'})
}
......
......@@ -7,6 +7,7 @@ from django.dispatch import receiver, Signal
from django.contrib.auth.models import User
from django.utils import timezone
from django.utils.translation import ugettext as _
# A signal that will be sent when users should be added or removed from the creator group
update_creator_state = Signal(providing_args=["caller", "user", "add"])
......@@ -15,23 +16,29 @@ class CourseCreator(models.Model):
"""
Creates the database table model.
"""
UNREQUESTED = 'unrequested'
PENDING = 'pending'
GRANTED = 'granted'
DENIED = 'denied'
# Second value is the "human-readable" version.
STATES = (
(u'u', u'unrequested'),
(u'p', u'pending'),
(u'g', u'granted'),
(u'd', u'denied'),
(UNREQUESTED, _(u'unrequested')),
(PENDING, _(u'pending')),
(GRANTED, _(u'granted')),
(DENIED, _(u'denied')),
)
user = models.ForeignKey(User, help_text="Studio user", unique=True)
user = models.ForeignKey(User, help_text=_("Studio user"), unique=True)
state_changed = models.DateTimeField('state last updated', auto_now_add=True,
help_text='The date when state was last updated')
state = models.CharField(max_length=1, blank=False, choices=STATES, default='u',
help_text='Current course creator state')
note = models.CharField(max_length=512, blank=True, help_text='Optional notes about this user (for example, '
'why course creation access was denied)')
help_text=_("The date when state was last updated"))
state = models.CharField(max_length=24, blank=False, choices=STATES, default=UNREQUESTED,
help_text=_("Current course creator state"))
note = models.CharField(max_length=512, blank=True, help_text=_("Optional notes about this user (for example, "
"why course creation access was denied)"))
def __unicode__(self):
s = "%str | %str [%str] | %str" % (self.user, self.state, self.state_changed, self.note)
s = u'%str | %str [%str] | %str' % (self.user, self.state, self.state_changed, self.note)
return s
......@@ -57,7 +64,7 @@ def post_save_callback(sender, **kwargs):
sender=sender,
caller=instance.admin,
user=instance.user,
add=instance.state == 'g'
add=instance.state == CourseCreator.GRANTED
)
instance.state_changed = timezone.now()
instance.orig_state = instance.state
......
......@@ -46,23 +46,17 @@ class CourseCreatorAdminTest(TestCase):
# User is initially unrequested.
self.assertFalse(is_user_in_creator_group(self.user))
# change state to 'g' (granted)
change_state('g', True)
change_state(CourseCreator.GRANTED, True)
# change state to 'd' (denied)
change_state('d', False)
change_state(CourseCreator.DENIED, False)
# and change state back to 'g' (granted)
change_state('g', True)
change_state(CourseCreator.GRANTED, True)
# change state to 'p' (pending)
change_state('p', False)
change_state(CourseCreator.PENDING, False)
# and change state back to 'g' (granted)
change_state('g', True)
change_state(CourseCreator.GRANTED, True)
# and change state back to 'u' (unrequested)
change_state('u', False)
change_state(CourseCreator.UNREQUESTED, False)
def test_add_permission(self):
......
......@@ -42,11 +42,11 @@ class CourseCreatorView(TestCase):
def test_add_unrequested(self):
add_user_with_status_unrequested(self.admin, self.user)
self.assertEqual('u', get_course_creator_status(self.user))
self.assertEqual('unrequested', get_course_creator_status(self.user))
# Calling add again will be a no-op (even if state is different).
add_user_with_status_granted(self.admin, self.user)
self.assertEqual('u', get_course_creator_status(self.user))
self.assertEqual('unrequested', get_course_creator_status(self.user))
def test_add_granted(self):
with mock.patch.dict('django.conf.settings.MITX_FEATURES', {"ENABLE_CREATOR_GROUP": True}):
......@@ -54,11 +54,11 @@ class CourseCreatorView(TestCase):
self.assertFalse(is_user_in_creator_group(self.user))
add_user_with_status_granted(self.admin, self.user)
self.assertEqual('g', get_course_creator_status(self.user))
self.assertEqual('granted', get_course_creator_status(self.user))
# Calling add again will be a no-op (even if state is different).
add_user_with_status_unrequested(self.admin, self.user)
self.assertEqual('g', get_course_creator_status(self.user))
self.assertEqual('granted', get_course_creator_status(self.user))
self.assertTrue(is_user_in_creator_group(self.user))
......
......@@ -14,7 +14,7 @@ def add_user_with_status_unrequested(caller, user):
If the user is already in the table, this method is a no-op
(state will not be changed). Caller must have staff permissions.
"""
_add_user(caller, user, 'u')
_add_user(caller, user, CourseCreator.UNREQUESTED)
def add_user_with_status_granted(caller, user):
......@@ -26,7 +26,7 @@ def add_user_with_status_granted(caller, user):
This method also adds the user to the course creator group maintained by authz.py.
"""
_add_user(caller, user, 'g')
_add_user(caller, user, CourseCreator.GRANTED)
update_course_creator_group(caller, user, True)
......@@ -47,10 +47,10 @@ def get_course_creator_status(user):
Returns the status for a particular user, or None if user is not in the table.
Possible return values are:
'g' = 'granted'
'u' = 'unrequested'
'p' = 'pending'
'd' = 'denied'
'unrequested' = user has not requested course creation rights
'pending' = user has requested course creation rights
'granted' = user has been granted course creation rights
'denied' = user has been denied course creation rights
None = user does not exist in the table
"""
user = CourseCreator.objects.filter(user=user)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment