fix submission -> conversation regression, fixes #9165

fix issue where new submission comments cause conversations to be marked
as unread for everyone, including the comment author.

slight cleanup, and also make no_submission_comments_inbox compatible with
assignment muting.

test plan:
1. as a teacher, send a message to the student
2. the conversation should be unread for the student, but read for the
   teacher
3. as a student, submit an assignment
4. as the teacher add a comment to the submission
5. as the teacher, confirm that the submission appears in the
   conversation, but is NOT marked as unread
6. as the student, confirm that the submission appears in the
   conversation, and IS marked as unread
7. as the student, add a comment to the submission
8. confirm that it is NOT marked as unread for the student
9. confirm that it IS marked as unread for the teacher

Change-Id: I73376e563ccbaea092cf1d22d5d16f186bf5dfac
Reviewed-on: https://gerrit.instructure.com/11848
Reviewed-by: Mark Ericksen <marke@instructure.com>
Tested-by: Jon Jensen <jon@instructure.com>
Dir.mkdir -> FileUtils.makedirs

when creating a directory for a plugin symlink, the parent directory may
also not yet exist. use FileUtils.makedirs (behaves like mkdir -p)
instead of Dir.mkdir to ensure the full path is created as necessary.

Change-Id: Iafc00c945923c40613fffd9206a1e45ecb735cb6
Reviewed-on: https://gerrit.instructure.com/11915
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jon Jensen <jon@instructure.com>
don't re-assign page views when merging users together

fixes #9250

This isn't realistic on such a large table where many users have so many
rows, and when page views are moved to another data store that'll make
it even more difficult.

test plan: merge two users together. verify that the merge works, but
page views from the old user won't be moved to the new user.

Change-Id: I0d5cb73acaebc9ed38a16bd0952a64f6b5284f5a
Reviewed-on: https://gerrit.instructure.com/11948
Reviewed-by: Zach Wily <zach@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
fix module progression w/o @current_user; fixes #8933

if there isn't a logged-in user (i.e., because we're on the files
domain), use the user_id parameter (if present) to find
module progression from the view

Change-Id: Id149316749afbfcde190c0adb70536effb228caa
Reviewed-on: https://gerrit.instructure.com/11823
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
constrain assignments.group_category_id in db

we already had defined GroupCategory.has_many :assignments, :dependent
=> :nullify, but somehow a handful of a assignments existed with a
non-null group_category_ids that pointed at non-existent group
categories. clean up the data and then force the constraint with a
foreign key in the database.

fixes #9075

test-plan:
  - run the migration
  - query "select count(*) from assignments left join group_categories
    on group_categories.id=assignments.group_category_id where
    group_categories.id is null"; shoud be 0
  - create a group category
  - create a group assignment associated with that category
  - delete the group category
  - the assignment's group category id should be nil

Change-Id: I1e88c3fe05e1879575e2bf5d8ff8a40df84fef0e
Reviewed-on: https://gerrit.instructure.com/11850
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
recompute enrollment grades after transaction commits

fixes #8360

there was a race condition where the delayed job that was created after
a submission was graded or an assignment's points were changed could have run
before the original transaction finished, meaning it would have recomputed the
grades with an incorrect score.  this ensures that the delayed job is not
created until after the transaction commits.

test plan: this is difficult to test, and was confirmed using timing data from
logs, but you could try setting a breakpoint in the old code after the delayed
job was created in the callback and confirming that it ran with old data.

Change-Id: Iaff08f080702df6e0817a2075898428bfd19e67e
Reviewed-on: https://gerrit.instructure.com/11960
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
export the course's grading_standard too

The course.grading_standard isn't necessarily included in
course.grading_standards -- I think because in the old course copy code,
we just copied the id over and the standard was still owned by the old
course. This change makes it so we export+import that standard, as well.

Note there is a difference still here, the old course copy was a copy by
ref rather than copy by value, so updating the standard in one place
updated it everywhere. That's not true of the new export/import
workflow.

closes #9197

test plan: make a course that has a grading_standard_id pointing to a
standard owned by another course (or find one already in the db). copy
that course, and verify that the new course correctly has the standard
as well.

Change-Id: I74272db46f511cc329c68493962ef35aedfeba5d
Reviewed-on: https://gerrit.instructure.com/12000
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
prevent peer reviewers from seeing turnitin the score

fixes #9288

for file upload submission, peer reviewers could see the turnitin score and
report, which should only be visible to the teacher and the student who
submitted the work.

test plan:
- create a file upload assignment with turnitin enabled
- have two students submit the assignment
- wait for turnitin scores
- assign the students to peer review each other
- as one of the students, open the peer review
- you should see the preview to view the file, but not the turnitin score

Change-Id: Ibaf2a84d65401e0ab85d75422f9fb2eead5d72d0
Reviewed-on: https://gerrit.instructure.com/12026
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
only show peer reviewers comments they have made

fixes #8881

disallow peer reviewers from seeing comments from the teacher or from other
peer reviewers on a submission they are reviewing.

test plan:
- enable peer reviews on an assignment, and have >1 reviewer per submission
- leave a comment as a teacher
- leave a comment as one of the reviewers, you should not see the teacher's
  comment
- as the second reviewer, you should not see either of the previous comments

Change-Id: I5fb112ea20858748eb399408236ebb319e0b9cbc
Reviewed-on: https://gerrit.instructure.com/12029
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
unstick workflow_state when batch deleting a course

This course.destroy call was marking the workflow_state of the course as
sticky, so that it could never be un-deleted via a SIS import ever
again.

I think an argument could be made that actually courses whose
workflow_state is currently sticky because of a UI change, shouldn't
even be deleted by a full batch delete. That's a big change from how
batch deletes currently work, though, and might cause issues with
manually published courses.

sections and enrollments also get batch deleted, but their
workflow_state fields aren't sticky.

refs #9200

test plan: import a course via sis as active, then upload a full batch
sis that doesn't include the course. the course should now be deleted.
then import the course again, and see that it's no longer deleted.

Change-Id: I14925e60fd4bd24dafaf8143a555eec6cccc9236
Reviewed-on: https://gerrit.instructure.com/12014
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
partially Revert "add foreign keys part 1"

This reverts commit a51d1ac78b682d22d2f0567c4f2e2f00c441abfa.

Change-Id: I944976ac48bdfed1002f0163148d478d22b6732d
Revert "constrain assignments.group_category_id in db"

This reverts commit d9495ccc4946a303e4d079f4e4b450b90dc7b1f7.
treesame commit of origin/stable/2012-07-07

Treesame-Commit-Id: 9cb4627ff1832e10ff68002a1601bee72d14c7d9
try to identify referenced files in invalid qti

some qti vendors generate file references to files that
might not be where they are specified. This tries to find
them anyway.

Test Plan:
 * Import the test fixture for bb_vista qti specs
 * The images in the questions should appear

closes #8051 #8671

Change-Id: I0cbfd0e8dee8654fe54996a041c81038eb53dd34
Reviewed-on: https://gerrit.instructure.com/10947
Reviewed-by: Cody Cutrer <cody@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
fix permission checks for submission comments

fixes #9370

a typo (instance_eval instead of class_eval) was causing submission comments to
not check permissions, so peer reviewers were receiving extra comments in ajax
responses.

test plan:
- submit an assignment, and comment on it
- also comment as the teacher
- set up a peer review
- load the page as the peer reviewer, it should not show the other comments
- make a comment as the reviewer. the other comments should not appear

Change-Id: I067e323a813ff836cfcadb5400e313de47be0e37
Reviewed-on: https://gerrit.instructure.com/12101
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
preload pseudonyms for enrollments api fixes #9385

avoids N+1 queries

test plan:
 * run specs for enrollments api

Change-Id: I8704677379521a42fbaf5c0f3c06ccb6b88f6806
Reviewed-on: https://gerrit.instructure.com/12118
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
files/folders api

A complete api for folder and file management
Also updates the alphabetical sorting features to escape
a backslash caused errors when casting a string to a
bytea in postgres

Test Plan:
 * CRUD yourself some files
 * CRUD yourself some folder

closes #9163

Change-Id: I0b937f9273077b66ab9d6c37171bec1fcc5380dd
Reviewed-on: https://gerrit.instructure.com/12085
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
allow resetting student view; closes #9229

this creates a fixed bottom bar that shows up on every page when you are in
student view, serving as both a reminder and a place for the buttons to leave
student view or to reset the test student.  resetting the test student is a new
piece of functionality which removes all course artifacts created by the test
student, letting a teacher "start over" the test student.

test plan:
- enter student view
- there should be a permanant bar at the bottom of the page, with buttons
- there should no longer be a [Leave Student View] link in the top right corner
- the leave button should work
- as the test student, interact with the course (submit assignments, take
  quizzes, comment in discussions, etc)
- click the reset student link in the bottom bar
- all of the interactions above should be gone

Change-Id: If73be7a28f6af5378da26f92e82a69a72352d831
Reviewed-on: https://gerrit.instructure.com/12057
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
disable profiles based on account setting

fixes #9386

Test plan:
  * Click on the 'Profile' link in the header, you should go to the
    profile settings page
    - There should not be a 'Profile' tab in the left nav
  * Enable the 'enable_profiles' account setting for your user's
    account.  Clicking on 'Profile' should now take you to the new-style
    profile page

Change-Id: Ie2bcd41ae98ec93d6a423e00936d79fac291be0c
Reviewed-on: https://gerrit.instructure.com/12132
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Ryan Florence <ryanf@instructure.com>
search for xlisted sections when enrolling via CSV fixes #9175

test plan:
 * create two courses via SIS CSV
 * enroll a user in course 1 via SIS CSV by course_id only
 * xlist course 1's default section to course 2
 * enroll another user in course 1 via SIS CSV by course_id only again
 * the user should end up in the xlisted section in course 2

Change-Id: I3a114d70a109594a56915b705de77b87a177e966
Reviewed-on: https://gerrit.instructure.com/12122
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>