Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mode and is_active to CourseEnrollment, shift enrollment logic to model #651

Merged
merged 1 commit into from
Aug 14, 2013

Conversation

ormsbee
Copy link
Contributor

@ormsbee ormsbee commented Aug 12, 2013

Add a mode field to allow us to support different kinds of enrollments (all current enrollments are honor code enrollments). Also add an is_active flag. This will let us do things like have an approval step before a CourseEnrollment is activated, as well as track what courses a person used to be signed up for, in case that information is necessary to determine their eligibility for other courses.

There's actually a lot more that I'd eventually like to move into CourseEnrollment (knowledge of courses, permissions, CourseEnrollmentAllowed, etc.) But shifting enroll/unenroll/is_enrolled was good enough for what I needed in the short term goal of supporting is_active as the toggle.

@dianakhuang: I still need to add some docs for this and test the migration on fake prod before I can merge this, but the code should be reviewable at this point.

@gwprice, @kevinchugh: Please review the forums code?

@sefk, @jbau: Just wanted to give you a heads up on this one.

created = models.DateTimeField(auto_now_add=True, null=True, db_index=True)

# If is_active is False, then the student is not enrolled, and
# `is_enrolled()` will return False. This lets us track a record of courses
# that the user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment trails off and seems a little confusing. I think it makes sense to say something like "then the student is not considered to be enrolled in the course"

Also, the last sentence trails off.

@ghost ghost assigned dianakhuang Aug 13, 2013
@dianakhuang
Copy link
Contributor

I think this looks good otherwise. We should also make sure Stanford is up to date on these changes.

@ormsbee
Copy link
Contributor Author

ormsbee commented Aug 13, 2013

Squashed and rebased.

@dianakhuang
Copy link
Contributor

Btw, this has a conflict and can't be merged right now (probably in the CHANGELOG file)

instance.user.roles.remove(*course_roles)
return

# We've enrolled the student, so make sure they have a default role
if instance.user.is_staff:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want two consecutive ifs rather than nested ones? It will likely never matter, but semantically, do you want to make one branch if you're a staff and another if you're a student. The edge case is a staff who unregisters for a course but should still have staff access. I guess the question is do you only want to check the active flag for non-staff, more as a policy question?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why a staff member should continue to have Moderator privileges for a course that they are no longer enrolled in?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was more concerned about the corollary where this essentially requires all moderators to be enrolled. Does every PM and every TA have to be enrolled explicitly to have rights in the forums? How about the instructor? I don't know the answer to that but if the answer is no, then we'll inadvertently remove all course roles for staff by virtue of their not being enrolled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I had forgotten just how divorced forum user privileges are from everything else in our system. @jimabramson: What's the desired behavior here? Remove student roles only?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is important for researchers studying course histories to know what roles a student had in the forum, during the course, eg community TA or other.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, how about this? I'll comment this check out, I'll comment out the tests that depend on it, and the forum team can implement whatever the right thing is at a later date. This will make the situation no worse than before the merge (since it didn't take any action back then on unenrollment either).

…and mode.

Features coming down the pipe will want to be able to:
* Refer to enrollments before they are actually activated (approval step).
* See what courses a user used to be enrolled in for when they re-enroll in
  the same course, or a different run of that course.
* Have different "modes" of enrolling in a course, representing things like
  honor certificate enrollment, auditing (no certs), etc.

This change adds an is_active flag and mode (with default being "honor").
The commit is only as large as it is because many parts of the codebase were
manipulating enrollments by adding and removing CourseEnrollment objects
directly. It was necessary to create classmethods on CourseEnrollment to
encapsulate this functionality and then port everything over to using them.

The migration to add columns has been tested on a prod replica, and seems to be
fine for running on a live system with single digit millions of rows of
enrollments.
ormsbee pushed a commit that referenced this pull request Aug 14, 2013
Add mode and is_active to CourseEnrollment, shift enrollment logic to model
@ormsbee ormsbee merged commit 57a8063 into master Aug 14, 2013
@jbau
Copy link

jbau commented Aug 14, 2013

@ormsbee @dianakhuang
Just to ask a summary question: basically the gist of these changes (32 files) is that now, for CourseEnrollment, existence now no longer denotes enrollment. Instead

  1. (is_active, mode ) = (True, "honor") indicates enrollment
  2. (is_active, mode) = (False, *) indicates non-enrollment
  3. (is_active, mode) = (True, "^honor") should not be used.

correct?

@jbau
Copy link

jbau commented Aug 15, 2013

oh, and no data migration is necessary because is_active defaults to true and mode defaults to "honor", correct?

@ormsbee
Copy link
Contributor Author

ormsbee commented Aug 15, 2013

@jbau
Correct, existence no longer denotes enrollment. Nos. 1 and 2 are true, but a major point of this transition is to encourage people to useCourseEnrollment.is_enrolled(user, course_id) instead. It's quite possible that the internal representation of what it means to be enrolled will change again, say to a status with intermediate states like "pending" or some such.

In regards to item 3, we'll be adding different types shortly, in the next week or so.

@ormsbee
Copy link
Contributor Author

ormsbee commented Aug 15, 2013

And yes, no data migration necessary because of the defaults. The migration is fast enough to run on our live prod instance without trouble.

@ormsbee ormsbee deleted the ormsbee/enrollment_modes branch August 15, 2013 14:31
@stroilova
Copy link
Contributor

Re: .is_enrolled()

We sometimes run SQL scripts to determine # enrolled. Some PMs also have
access to a wwc database replica and to the following query list:
(see, e.g.
https://edx-wiki.atlassian.net/wiki/pages/viewpage.action?pageId=7471154)

What is the best thing to do going forward to determine #Enrolled from the
database directly? Should we just update the query scripts according to
your documentation, or is there an API that would be queried? Thank you.

@rocha @jtauber @dave

On Thu, Aug 15, 2013 at 10:15 AM, David Ormsbee notifications@github.comwrote:

And yes, no data migration necessary because of the defaults. The defaults
also make the migration fast enough to run on our prod instance without
locking the table.


Reply to this email directly or view it on GitHubhttps://github.com/edx/edx-platform/pull/651#issuecomment-22705384
.

@ormsbee
Copy link
Contributor Author

ormsbee commented Aug 15, 2013

@stroilova: I'd like edx-platform code to use the CourseEnrollment model, but you folks should still use SQL in the aggregate queries. I updated the relevant SQL query on the linked page. Thank you.

@stroilova
Copy link
Contributor

Just saw that, thank you!

On Thu, Aug 15, 2013 at 12:59 PM, David Ormsbee notifications@github.comwrote:

@stroilova https://github.com/stroilova: I'd like edx-platform code to
use the CourseEnrollment model, but you folks should still use SQL in the
aggregate queries. I updated the relevant SQL query on the linked page.
Thank you.


Reply to this email directly or view it on GitHubhttps://github.com/edx/edx-platform/pull/651#issuecomment-22713766
.

@rocha
Copy link
Contributor

rocha commented Aug 15, 2013

@stroilova we should discourage PMs from running that kind of query on the database since the enrollment number is accessible from the analytics tab on the instructor panel.

However, if you still need the SQL query, it something like this:

SELECT COUNT(DISTINCT user_id) AS students FROM student_courseenrollment WHERE course_id=(course_id) AND is_active !=0;

@jbau
Copy link

jbau commented Aug 15, 2013

@ormsbee Yes, I'm planning on using the methods. Was just asking about the representation to make sure I understood it.

On Aug 15, 2013, at 7:14 AM, David Ormsbee notifications@github.com wrote:

@jbau
Correct, existence no longer denotes enrollment. Nos. 1 and 2 are true, but a major point of this transition is to encourage people to useCourseEnrollment.is_enrolled(user, course_id) instead. It's quite possible that the internal representation of what it means to be enrolled will change again, say to a status with intermediate states like "pending" or some such.

In regards to item 3, we'll be adding different types shortly, in the next week or so.


Reply to this email directly or view it on GitHub.

chrisrossi pushed a commit to jazkarta/edx-platform that referenced this pull request Mar 31, 2014
itsjeyd referenced this pull request in open-craft/edx-platform Mar 24, 2016
Update static tabs APIs to cache tab contents
jenkins-ks pushed a commit to nttks/edx-platform that referenced this pull request Mar 30, 2016
dfrojas pushed a commit to eduNEXT/edx-platform that referenced this pull request Aug 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants