fix up adding logins through the UI

api actions use params[:user][:id] and an Account @context, non-api
actions use params[:user_id] and and either params[:account_id] or the
@domain_root_account. correctly handle both paths.

while we're at it, when the API call was added, the json response
changed (lost the pseudonym[] wrapper) and the javascript broke. fix
that, and fix the html so the javascript can correctly populate the
template.

test-plan:
  - log in as a site admin
    - add a login to a user with a non-default account selected in the
      dropdown; the login should be created in the correct account
  - log in as a non-site admin account admin
    - add a login to a user (no account dropdown); the login should be
      created in the current domain root account
  - while adding accounts through the UI, observe proper addition of new
    login to the logins list
  - through the API, add a login to a user via a root account; should
    succeed
  - through the API, add a login to a user via a non-root account should
    fail with a 400 Bad Request
  - through the API, attempt to add a login without specifying any
    parameters; should return a 404, not a 500
  - through the API, attempt to list logins without specifying any
    parameters; should return a 404, not a 500

Change-Id: Ic28e73a992916b81a18b40244bbb6d919cccf858
Reviewed-on: https://gerrit.instructure.com/8269
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Zach Pendleton <zachp@instructure.com>
delay MediaObject creation from uploaded files

in some S3 regions uploads are only eventually consistent. this means a
file may not be immediately available for reading after we've finished
uploading it. when an appropriate Attachment is created,
MediaObject.add_media_files is called to tell Kaltura to try and
download the file from S3; given the eventual consistency this download
could fail. so we'll delay the add_media_files call by a configurable
amount to give S3 time to settle. fixes #6787

test-plan:
  - need delayed jobs running
  - record media to kaltura (e.g. discussions); should still work
  - set attachment_build_media_object_delay_seconds to something large,
    such as 300 (5 minutes).
  - record media to kaltura; new media should not be available for 5
    minutes, but should be available shortly after the 5 minutes expire

Change-Id: Ie39a4a32c9819dcd577fb84c3a1e6df60b2b3da0
Reviewed-on: https://gerrit.instructure.com/8298
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
more selenium file cleanup

Change-Id: I3e805f804e710ac8674bde7474e5463e33cc37d6
Reviewed-on: https://gerrit.instructure.com/8202
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Bryan Madsen <bryan@instructure.com>
update parallel_tests-instructure to 0.6.18

there was a bug when logging failures

Change-Id: I6672e5b5157268d2f7ddf2df042bf3877e6840eb
Reviewed-on: https://gerrit.instructure.com/8378
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Jake Sorce <jake@instructure.com>
add user update api. fixes #6863

affects: users api
test plan:
  * as account admin, send request to update
    user's name, short name, sortable name,
    and time zone and verify that changes are
    made and user json is returned;
  * as unauthorized user, send same request and
    verify that 401 is returned.

Change-Id: I3ede1b0ae62143c47a564a709fade9259a07543e
Reviewed-on: https://gerrit.instructure.com/8027
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
allow importing of multiple module links to same external tool

The importer was incorrectly using the external tool's
migration id as the content tags migration id. This made
it so that links to the same tool just updated the first
tag instead of creating a new one.

Test Plan:
 * Create an external tool
 * Link two module items to it on the modules page
 * Export that course and import it into a different course
 * The imported module should have both items and not just the second one

refs #7017

Change-Id: Iba377b9085607e3503f7f0113a4b9720bf8f0305
Reviewed-on: https://gerrit.instructure.com/8290
Reviewed-by: Brian Whitmer <brian@instructure.com>
Tested-by: Hudson <hudson@instructure.com>
show correct context in "coming up" list fixes #6333

was using a cached @context, so the first person
who viewed the assignment was the context

Change-Id: I35fe55040d00ee6cc7375e3e830fd38316b4e6f0
Reviewed-on: https://gerrit.instructure.com/8314
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Zach Pendleton <zachp@instructure.com>
allow observers to see the observed quiz submissions fixes #6300

test plan:
 * enroll a student, and link an observer
 * as the student, take a quiz
 * as the observer, go to the grade summary page
 * click the quiz
 * you should see the quiz results for the student

Change-Id: Id0bfa2e0c1c0c7f0ce9f21095781251be47d2847
Reviewed-on: https://gerrit.instructure.com/8392
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
find relative pathed files when translating links on assessment questions

sometimes urls to files/images have relative urls instead of
the id of a file. Those should also be attempted to be
translated.

Test Plan:
 * Make an assessment question with both types of urls
 * run translate links on that question
 * The urls should be happy when done

refs #6951

Change-Id: I9d4a526357871ac8ea7e1018df6c39f0dda95060
Reviewed-on: https://gerrit.instructure.com/8196
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
changed selenium implicit wait time to 3 from 10

Change-Id: I0509424fb1dfd2c73eb11164470c5eb711ea6907
Reviewed-on: https://gerrit.instructure.com/8394
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Bryan Madsen <bryan@instructure.com>
add pseudonym update api. fixes #6866.

affects: pseudonym/login api
test plan:
  * send request as authorized user and verify that
    pseudonym is updated;
  * send request as unauthorized user and verify that
    request is rejected with 401;
  * attempt to set a protected attribute like password_salt
    and verify that 400 is returned;
  * attempt to change your own pseudonym and verify that it's
    allowed.

Change-Id: I83562ddd6dbf83c47bcc1adadfda9f9e1a4867da
Reviewed-on: https://gerrit.instructure.com/8233
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
don't duplicate enrollments on sis import if all enrollments are deleted

test plan:
 * import the same deleted enrollment several times; only one should be
   in the db

Change-Id: If067578fc1b42e501e4c43243f9745654b633701
Reviewed-on: https://gerrit.instructure.com/8417
Reviewed-by: Zach Wily <zach@instructure.com>
Tested-by: Hudson <hudson@instructure.com>
don't wait on media object processing when importing a course

Just fire off the kaltura upload jobs in the background, so that the
import can continue. Attachments in the special media_objects export
folder will still be deleted when those uploads complete.

Note we still wait for canvas common cartidge imports, since we need the
completed media object imports in order to translate the rich text
content. We plan to address this limitation later.

test plan:

 * do a course import from a source other than canvas CC, verify that
   the import finishes without waiting on Kaltura.
 * do a course import from a canvas CC package with
   some audio/video. Verify that the import finishes after waiting on
   kaltura, but the attachments in /media_objects are removed as the
   kaltura jobs complete.

fixes #5383

Change-Id: I7dbf12c211fc332fe9d4f16bc4d31fd0656c1941
Reviewed-on: https://gerrit.instructure.com/8031
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
fix messaging for group assignment submissions. fixes #6178

when user submits a group assignment that is graded individually,
he/she no longer receives messaging about their submission counting
for all members of the group.

test plan:
  * create a group assignment and select 'Assign grades to each
    student individually;'
  * login as a student in the group;
  * open the assignment submission page and verify that no message
    is present.

Change-Id: I83eca7a8ab211f58868f0f7c6c97e91b039f4d69
Reviewed-on: https://gerrit.instructure.com/8380
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Cameron Matheson <cameron@instructure.com>
fix for intermittently failing selenium specs

Change-Id: I577827ce1252e52e808984673c227d239cf0f298
Reviewed-on: https://gerrit.instructure.com/8407
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Bryan Madsen <bryan@instructure.com>
fixed multiple selenium files to work with postgres

Change-Id: I11b7d5590ec83257645c5fc469b5dba6e60d29df
Reviewed-on: https://gerrit.instructure.com/8384
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Bryan Madsen <bryan@instructure.com>
normalize user_id out of notification_policies

fixes #6585, #7096

by normalizing, it's impossible to not maintain a column that isn't
there (yes, triple negative is intended in that sentence), thus
preventing sending notifications to the wrong user after a merge
or any other bugs that would have missing maintaining the
denormalization.

test plan:
 * test notifications in general
 * merge two active users together - their notification preferences
   should survive the merge

Change-Id: I239d810c5499b94550b65128cac71c42cedd11ba
Reviewed-on: https://gerrit.instructure.com/8013
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Jacob Fugal <jacob@instructure.com>
allow ignoring learning outcomes for grading; fixes #5271

when you add a learning outcome to a rubric, you can optionally choose to
ignore it when grading. this commit ensures that point totals acutally ignore
the line consistently across the varios places they are displayed, including
when creating the rubric, when grading from the speed grader, and when grading
from the assignment submission page.

test plan:
- create a learning outcome
- create an assignment with a rubric for grading
- make sure the rubric has at least one normal criterion for grading
- include the learning outcome, and choose ignore for grading
- make sure point totals are consistent in the rubric form
- grade the assignment with the speed_grader, make sure point totals are
  consistent.
- modify the grade at /courses/c.id/assignments/a.id/submissions/user.id and
  make sure point totals are still constistant.

Change-Id: I454d73897ee5d4e6413b7c653ffafa1c4ac98e2e
Reviewed-on: https://gerrit.instructure.com/8263
Reviewed-by: Cody Cutrer <cody@instructure.com>
Tested-by: Hudson <hudson@instructure.com>
add indexes that weren't created because of too-long names

also add some code to AR to raise an exception if this happens again,
rather than just log a warning to the log file.

testplan (for all 3 supported dbs):
  * run all the migrations on a new db
    * no error, and check that the indexes in the new migration exist
  * run the new migration on a db that is up to date
    * before running, verify that the indexes in the new migration don't yet exist due to this problem
    * no error, and check that the indexes in the new migration exist

Change-Id: Iaf7ebb31763bf7e5848c26d0daf179a0b31c6625
Reviewed-on: https://gerrit.instructure.com/7162
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
allow overriding periodic jobs schedules

using a new config/periodic_jobs.yml file

test plan: edit config/periodic_jobs.yml, and verify that the overridden
jobs run at that new schedule. add an invalid override, and verify that
`script/delayed_job run` dies immediately.

closes #6875

Change-Id: Ia4611fb6f81fe82feda784300a3adf82e37a53e4
Reviewed-on: https://gerrit.instructure.com/8262
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>