Use html5 to show videos by default

using a library called mediaElement.js, try to show
all kaltura video and audio using html5 and fall back
on flash if needed.

Test Plan:
 * in all the different browsers (including mobile safari/chrome)
 * try recording webcam videos (as homework submission, as content in a wiki page, etc)
 * view those same pages
 * view recorded submission in speedgrader

use the playlist urls to get kaltura urls

This will get CDN-configured links from Kaltura instead of direct Kaltura
links. It also allows for the case where a MediaObject does not exist. When
one is requested, it will be created in the database and details fetched.

Test Plan for cdn urls:
 * Make sure kaltura is enabled
 * Open your web inspector's network tab
 * Browse to a recorded media file in Canvas, and play it
 * Ensure that the file is streamed from kaltura's configured CDN (s3 in the case of instructure).

Test Plan for nonexistent MediaObjects:
 * Make sure kaltura is enabled
 * In a wiki page, record a media comment
 * Destroy that MediaObject from the database (use Inspect Element to find the media_id which looks like 0_1234abcd)
 * Reload the page, and verify that you can still view the video

fix error when viewing a video file that has an unknown source type

There are some videos that have valid sources that don't
have an extension for some reason. This fixes handling
of those correctly.
There was also a bug that would sort by bitrate as
strings, instead of as integers. The sort function was
refactored out and tests written to ensure that's fixed.

Test Plan
 * find a video in kaltura that has an asset with no extension,
   and make sure you can view that video in a wiki page

refs #CNVS-324

Change-Id: I8ff24a94b8af11fc29b84e45545f8a8b639eeaff
Reviewed-on: https://gerrit.instructure.com/16824
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
QA-Review: Adam Phillipps <adam@instructure.com>
Allow uploading subtitle tracks to videos

when you upload a video, you will now see a [cc]
box in the player for that video if you are
the uploader of that video and in a modern browser.
it will have a link to upload a caption track in
SRT or WebVTT format in any language you specify.

once you attach a caption track to any of your
videos, other people that view it will be able
to choose that track while playing it.
helpful for people that are deaf or that speak
another language!

this change also adds google analytics tracking to
videos so we know when a given media_id was
played, paused, and ended.

Test Plan:
* record a video, go to play the video
* you should see a [cc] button
* click the "upload subtitles" link, a dialog should appear
  that lets you choose a language and file to upload.  here's
  one you can test with:
  http://mediaelementjs.com/media/NT113_u008_v005_transcript.srt
* refresh, you (and anyone else that can see video)
  should now have the option to select that track
  for subtitles. (if using in HTML5 player)
* you should see a delete 'x' on it to delete
  it, when you click it it should go away. reload
  to make sure it is not there.
* The user who created the video, or any admins of the course
  the video is in should be able to manage these captions

closes CNVS-324

Change-Id: Id6d4abcb581f0daf101d601221dc45edaad6eaa8
Reviewed-on: https://gerrit.instructure.com/16882
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
QA-Review: Adam Phillipps <adam@instructure.com>
add reorder method

similar to Rails 3

test plan:
 * run the specs

Change-Id: If117151c784b2303892ac59eb30a1d133568ac5a
Reviewed-on: https://gerrit.instructure.com/17354
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
process user account associations for multi-shard users

fixes CNVS-1338

basically, just process associations for the current shard, unless
we're explicitly calling update_account_associations on just the user
(since all the other triggers will only affect associations within
 the same shard)

test plan:
 * enroll an existing site admin user from the default shard in to a
   course on another shard
 * the user should immediately show up in the course's account's user
   list
 * remove the user from the course
 * the user should immediately disappear from the course's account's
   user list
 * note the associations a user has
  (u.user_account_associations.with_each_shard)
 * delete them all (u.user_account_associations.with_each_shard { |s|
     s.delete_all })
 * call u.update_account_associations
 * make sure they all get recreated

Change-Id: I794363d1703fb2d46cd27b67b1216fedef4deaae
Reviewed-on: https://gerrit.instructure.com/17155
Reviewed-by: Cody Cutrer <cody@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Clare Hetherington <clare@instructure.com>
add accessibility for drag-and-drop on course navigation tab

based on the outcomes ui

test plan:
* on the course settings navigation tab:
 * read hidden instructions at top of navigation tab

 * In Jaws: Use Insert-Z to turn virtal cursor off
 * use the tab key to focus on one of the navigation bars
 * use up/down arrow keys to change focus
 * use spacebar to start dragging the bar
 * use up/down again to move around
 * use spacebar again to drop it after the currently
   focused bar

 * make sure you can move the tabs from the enabled
 to the disabled group and vis versa

closes #CNVS-288

Change-Id: If4a8f8314855144830d8c7e3573f7c56d441fb8c
Reviewed-on: https://gerrit.instructure.com/16941
Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Clare Hetherington <clare@instructure.com>
Improve accessiblity when managing modules

fixes #CNVS-287

Allow screen readers to interact with managing modules. Added the
appropriate aria labels and fixed some really quarky bugs with JAWS not
being able to pick up so labels and text in forms.

Test Plan
In a course, go to a the modules tab. Create a module to test.

1. With JAWS ensure the indent/outdent/edit and remove icons show
up when moving around on modules. This normally only happens when
you hover with your cursor.
2. Create a new module with the screen reader. Name text field should be
labeled including all dropdowns, links and other labels in the form.
3. Edit a module with the screen reader. All text and
labels/instructions should show up correctly

Change-Id: Iae9cac75e27b29e3baabd106d2d8e9d4886da69f
Reviewed-on: https://gerrit.instructure.com/17213
QA-Review: Clare Hetherington <clare@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
don't allow multiple root folders for courses

change the way we create the default course root folder
("course files") to use a atomic sql statement

this should prevent suspected race conditions from creating
multiple root folders for a course, as this causes the
files page to become unusable

test plan:
* Unfortunately there seems to be no consistent way to
 reproduce the errors, and thus no consistent way to
 test that this fixes the error

Change-Id: I223a2b230921752ef1175c82adfdd854e1331668
Reviewed-on: https://gerrit.instructure.com/17014
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
QA-Review: Bracken Mosbacker <bracken@instructure.com>
fix role overrides that apply to self only

AccountUser#has_permission_to? was relying on an array result
from enabled_for?

test plan:
 * enable a role override for only self for manage_account_settings
 * add a user to that role *and* enroll them in a course
 * attempt to log in as that user
 * it should not fail

Change-Id: Iff2fdb3bac25f802baee2eb0e7337481e519126a
Reviewed-on: https://gerrit.instructure.com/17188
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Clare Hetherington <clare@instructure.com>
Reviewed-by: Rob Orton <rob@instructure.com>
make assignments_needing_x shard safe

fixes CNVS-2200

normalize ignores out of the users.preferences column into
its own table. makes it more performant, and shard safe

test plan:
 * add a user as a teacher in courses on two different shards
 * set up an assignment needing grading (i.e. have a student
   submit an assignment that requires grading) in both courses
 * the assignment should show up on the teacher's dashboard
   regardless of which shard he's on
 * ignore the assignment on your dashboard on one shard
 * reload - it should stay gone
 * it should also be gone on the other shard
 * have another student submit to that assignment
 * it should come back on both shards for the teacher
 * ignore it, permanently this time
 * have another student submit to that assignment
 * it should still be gone on both shards

Change-Id: I6646410273c6be05d4b21b29b6ab76feb8e65d0f
Reviewed-on: https://gerrit.instructure.com/17295
Reviewed-by: Cody Cutrer <cody@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Clare Hetherington <clare@instructure.com>
display varied due dates on discussion topic show page.

fixes CNVS-751

test plan:
  * create a discussion assignment with assignment
    overrides;
  * as a teacher, view the discussion and verify that
    all of the due dates are visible;
  * as a student, view the discussion and verify that
    the due date applicable to you is visible.

Change-Id: I455260a6993d6d04bad8a526ea60d3cc223805e8
Reviewed-on: https://gerrit.instructure.com/17030
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Mark Ericksen <marke@instructure.com>
QA-Review: Marc LeGendre <marc@instructure.com>
context profiles, refs CNVS-2650

add Profile model which can be used by context-y things, and a basic
CourseProfile model

test plan: N/A, see https://gerrit.instructure.com/17020

Change-Id: I68f4a5a4f0913167e7e25e7bc231b5bf8394c335
Reviewed-on: https://gerrit.instructure.com/17019
Reviewed-by: Jon Jensen <jon@instructure.com>
QA-Review: Jon Jensen <jon@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
shim for cross-shard conversations without messageable_users working

closes CNVS-3557

test plan:
 * view a cross-shard conversation
 * it shouldn't give you a page error

Change-Id: I5100554ba592ef03816757f79b205efa0012c948
Reviewed-on: https://gerrit.instructure.com/17380
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Clare Hetherington <clare@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
handle tags for cross-shard conversations

refs CNVS-1171

test plan:
 * tags should show up and make sense when communicating with
   someone in a different shard

Change-Id: I21da08d17740dafde766d368300d197897c3639b
Reviewed-on: https://gerrit.instructure.com/17082
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
api: return calendar events ordered by start_at

Test plan:
 - Create three calendar events, ensuring that the create order is
   different from the start order. So like Wed, Fri, Mon.
 - Use the API to request a date range of events back.
 - Verify that events are returned sorted, like Mon, Wed, Fri.

Change-Id: Id25bcc3cd5eba68d243586decddf4a394702f147
Reviewed-on: https://gerrit.instructure.com/17280
QA-Review: Clare Hetherington <clare@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
don't do an extra disableWhileLoading call each time the form submits

fixes #CNVS-3401

test plan:
1. find a form that can be submitted repeatedly w/o refreshing the page,
   or just check out https://gerrit.instructure.com/17019 with the
   accompanying canvasnet_registration commit
2. use the form multiple times
3. the form should get disabled every time you submit it

Change-Id: I2dcc4da885740513dc75300c01e75f93b5ca0d1b
Reviewed-on: https://gerrit.instructure.com/17199
QA-Review: Jon Jensen <jon@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Stanley Stuart <stanley@instructure.com>
api: don't call empty on possible nils

Fixes a bug where sending nil assignment overrides through the api would
throw an error because nil doesn't respond to the method "empty?". The
code before was checking for the presence of an empty string, and blank?
works for both empty strings and nil via active_support's core object
extensions.

test plan:
  - specs should pass
  - Create an override through the api that has the key "due_at" but a
    null value. You should not get server errors.
  - Request the same override through the api. You should not get server
    errors.

Change-Id: I5792d96e307a9c563d751fbe21cef6178cb350e0
Reviewed-on: https://gerrit.instructure.com/17348
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
Reviewed-by: Erik Lyngved <erik@12spokes.com>
QA-Review: Myller de Araujo <myller@instructure.com>
create messages from DelayedMessage.summarize on the user's shard

fixes CNVS-1714

test plan:
 * do an action that goes through DelayedMessage.summarize
   (I think just means setting some notifications to every 5 minutes
    or something)
 * wait the five minutes
 * the message(s) should show up in /users/x/messages

Change-Id: Ibcc646f9ec869543b8ba84c1d7c7f8171ce55d78
Reviewed-on: https://gerrit.instructure.com/17166
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jacob Fugal <jacob@instructure.com>
QA-Review: Clare Hetherington <clare@instructure.com>
1.9: fix our multipart form building to work with StringIO objects again

In 1.8 StringIO#path returns nil, but in 1.9 the method doesn't exist,
so building multipart forms was failing.

lib/multipart.rb could use some larger refactoring but I'm limiting the
scope of this change since it's getting race tracked.

fixes CNVS-3562

test plan: With an environment running ruby 1.9, do a course copy with a
course that includes at least 1 video. The copy should succeed and the
video should work in the new course, as expected.

Change-Id: Ib8a9f1559c639831977f0118874735891b98d02f
Reviewed-on: https://gerrit.instructure.com/17407
Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Clare Hetherington <clare@instructure.com>
this migration is non-transactional in dev

Change-Id: I1698e157f1dbcfdc44c5d66bbff6489e6b7c4476
Reviewed-on: https://gerrit.instructure.com/17419
Reviewed-by: Jon Jensen <jon@instructure.com>
QA-Review: Jon Jensen <jon@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
change sections' root_account_id when the course changes

test plan:
 * move a course to a different root account
 * check the database - the section's root_account_id should have
   changed as well

Change-Id: I75647cc2c920af1b3f5e28ca8df30d32afa704a1
Reviewed-on: https://gerrit.instructure.com/17406
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Rob Orton <rob@instructure.com>
QA-Review: Clare Hetherington <clare@instructure.com>