Skip to content

Commit

Permalink
Improve WikiEdits behavior when removing user from course
Browse files Browse the repository at this point in the history
When a user gets removed from a course, we don't necessarily want to remove the assignment templates for that user's assignments, because classmates may still be assigned to that same article. It's safer to just run WikiEdits.update_assignments after that user's assignments have been destroyed.

More broadly, the behavior of WikiEdits.update_assignments is too complex, because it can either update all assignments for a course or it can update just some based on assignment data passed to it, and it can be in 'delete' mode or normal mode. It will be better to just always do updates based on the course and the current_user, meaning that any user updating the assignments for a course will post updates to all relevant pages every time. The 'delete' part gets tricky, though.

Resolves #431
  • Loading branch information
ragesoss committed Oct 21, 2015
1 parent 164ac2e commit 353a4f6
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,16 @@ def remove
fetch_enroll_records
return if @user.nil?

cu = CoursesUsers.find_by(
course_user = CoursesUsers.find_by(
user_id: @user.id,
course_id: @course.id,
role: enroll_params[:role]
)
return if cu.nil? # This will happen if the user was already removed.
WikiEdits.update_assignments current_user, @course,
cu.assignments.as_json, true
cu.destroy
return if course_user.nil? # This will happen if the user was already removed.
course_user.destroy # destroying the course_user also destroys associated Assignments.

render 'users', formats: :json
WikiEdits.update_assignments(current_user, @course)
WikiEdits.update_course(@course, current_user)
end

Expand Down

0 comments on commit 353a4f6

Please sign in to comment.