fix datafixup to correctly count number of read entries for each user

We were not scoping a query correctly, which was resulting in some unread
counts to go < 0.

test plan:
 * The spec modification should adequately cover the data fixup change

Change-Id: I333d011e8656584fa261845805b87c6b4b1d53b3
Reviewed-on: https://gerrit.instructure.com/9473
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
fix saving questions in question banks; fixes #7754

test plan:
 * Create a new question bank
 * Create a question in the bank
 * Try to save the question. It should work.

Change-Id: I83213c32654e1bf0ce3e4349ae5c0b68355d5d0c
Reviewed-on: https://gerrit.instructure.com/9474
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Zach Wily <zach@instructure.com>
use flickr over ssl

test plan:
 * in a RTE, search for a flickr image, and add it
 * page should stay fully secure
 * after saving, clicking the link of the picture should go to ssl
   flickr
 * switching view of the RTE should show https urls only

Change-Id: Ia836bf127a14a50b30e7bc9e8b183e39dcb26f68
Reviewed-on: https://gerrit.instructure.com/9284
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Benji Edmund <benji@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
add spec for scribd in multiple shards refs #7695

test plan: n/a

Change-Id: I4632d236db0c3d55e7569e7f6f58687b09670796
Reviewed-on: https://gerrit.instructure.com/9368
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
error if the sis import is batch mode and no valid term is given

refs #7512

test plan:
  * post to the sis imports api, with batch_mode=1 but an invalid or
    missing batch_mode_term_id, verify the 400 error and response message
  * post with a valid term id, verify the successful creation
  * post in non-batch mode and verify things are coo

Change-Id: I804687e38f41bf9fb73b3a248907b9a27590ce52
Reviewed-on: https://gerrit.instructure.com/9460
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
add api for enrollments by section; fixes #7647

add the ability to query enrollments for a given section with the api, and use
that api URL to load the section lists for courses/x/sections/y.

test-plan:
- in a course users split between sections
- go to /courses/x/sections/y
- make sure appropriate people are there
- no gui the creates enrollments for the section, so try posting to
  /api/v1/sections/x/enrollments to create an enrollment for that section.

Change-Id: I434b10dc20e36f43e48bbad5caa8886796211b82
Reviewed-on: https://gerrit.instructure.com/9364
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
fix typo in course wizard fixes #7712

Change-Id: If6a04ca1978dd8d600bfc911a4f9cadbfc5a7811
Reviewed-on: https://gerrit.instructure.com/9480
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Rob Orton <rob@instructure.com>
indicate which appointment groups aren't published

fixes #7429

Test plan:
 - make an appointment group (save it, but do not publish)
 - verify that you can tell the difference between a published and
   un-published appointment group

Change-Id: Id7e004ac19d56e1418d57907a2a9526f5f7b5463
Reviewed-on: https://gerrit.instructure.com/9352
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Jon Jensen <jon@instructure.com>
return attach permission on discussion topics, closes #7376

This way api users can know whether the current user can post
attachments to the discussion or not.

test plan: hit the discussions api as a teacher in the course, verify
that attach is always true. hit it as a student, verify attach is only
true if the course settings allow student attachments.

Change-Id: I508e6b8f329f8472e0a2899676871a1b5318f585
Reviewed-on: https://gerrit.instructure.com/9384
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Stephen Lottermoser <stephen@instructure.com>
Reviewed-by: Zach Pendleton <zachp@instructure.com>
show archived conversations under the sent filter, fixes #7627

test plan:

* send a message
* archive the conversation
* go to your sent filter
* ensure the conversation shows up

Change-Id: I87086de2bcc33f1e2885e460117838ac3d66f364
Reviewed-on: https://gerrit.instructure.com/9420
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Zach Pendleton <zachp@instructure.com>
browsable conversations filter, fixes #7566

add browse button and corresponding functionality to conversations filter
(similar, but not identical, to recipient finder). subtle differences:

 * you can only pick one thing
 * there are no checkboxes or "Select All" options
 * you can't select sections (though you can browse them), since we don't
   tag by section, only course/group/user
 * to select a group/course, you have to drill into it and then pick the
   first option (named the same as the course/group, w/ an explanation)

test plan:

 * create conversations under various courses/groups/users
 * filter conversations by searching for courses/groups/users
 * filter conversations by browsing and selecing courses/groups/users
 * filter conversations by browsing a course and searching for users/
   groups

Change-Id: Icca7be0048b88ddb0eb638b28634f435cdcf1d76
Reviewed-on: https://gerrit.instructure.com/9417
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Zach Pendleton <zachp@instructure.com>
don't show concluded students under course in finder, fixes #7583

hide concluded student enrollments when browsing courses/sections in the
conversations recipient finder. when browsing a group or just doing a
context-less search, those users will still show up (assuming the course
is active or recently concluded, etc.)

test plan:
1. conlude a student's enrollment
2. confirm that you cannot find/message the user under the course
3. confirm that you can find/message the user under a group or via search
4. conclude a teacher's enrollment (or just conclude the course)
5. confirm that you can find/message the teacher under the course or via
   search

Change-Id: I5886d8c0805b9af617622132e7b24a9249d2a715
Reviewed-on: https://gerrit.instructure.com/9437
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Zach Pendleton <zachp@instructure.com>
update course section enrollment display to be less confusing

fixes #7600

test plan:

  1. add active enrollment
  2. add pending enrollment
  3. complete enrollment
  4. view section that enrollments
     are in and verify that the
     enrollment count display
     is less confusing

Change-Id: I72d1637665359aa75aa7a87bc399aa2d62258636
Reviewed-on: https://gerrit.instructure.com/9432
Reviewed-by: Jon Jensen <jon@instructure.com>
Tested-by: Hudson <hudson@instructure.com>
let students join inactive long-running conferences, fixes #7454

added a :resume permission so participants can join long-running
conferences even if they go inactive

test plan:
1. set up wimba (or bbb)
2. create a conference with a duration
3. confirm that students can't join unless it's active (in the case of
   wimba, that means an admin needs to be in the conference. for bbb,
   an admin needs to have been present in the last hour)
4. create a long running conference (no duration)
5. confirm that students can join any time after it was started,
   regardless of whether the admin is still participating

Change-Id: Ie81ea7309b6334d88269af098f3b0da6fb04a177
Reviewed-on: https://gerrit.instructure.com/9433
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Zach Pendleton <zachp@instructure.com>
Canvas.revision

and display the revision on /plugins

test plan: without a VERSION file, visit /plugins and see the "Unknown"
displayed. With a VERSION file, visit /plugins and see the first line of
that file displayed.

Change-Id: I0bcb3c855c70ba444158e17302eadab317dffb02
Reviewed-on: https://gerrit.instructure.com/9197
Reviewed-by: Brian Palmer <brianp@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
Tested-by: Hudson <hudson@instructure.com>
only send scheduler notifications to available courses; fixes #7267

test-plan:
- in an unpublished course (with students) create an appointment group
- notifications should not be send to those students

Change-Id: Ia194da05d7b4581f826a3690fe4a95bc249597c3
Reviewed-on: https://gerrit.instructure.com/9370
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Jon Jensen <jon@instructure.com>
separate require_pseudonym from require_user; closes #7718

previously, require_user actually required both a user and a pseudonym. this
change pulls them apart into separate require calls, creating the ability to
require at finer granularity.

test-plan: run specs

Change-Id: I0124d4685bd521c16ed47c7e2e35e960adc6598b
Reviewed-on: https://gerrit.instructure.com/9381
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
support for deferred delayed job creation, refs #7277

adds Delayed::Batch.serial_batch which, when given a block, will delay
the creation of (most) new jobs triggered within that block. a single
job will be created (per priority and queue) containing all the info for
those jobs. when it runs, it will create those jobs and run them
synchronously. if any of those jobs fail, they will be handled (and
possibly retried) according to the default logic.

note that jobs with a strand or a run at will not be deferred and will
be created as usual.

this is particularly helpful for places like conversations, where a
bulk private message can trigger thousands of jobs (2 per private
conversation). even though the jobs are not run synchronously with the
request, their mere creation is a significant performance bottleneck.

test plan:
1. do some stuff that creates jobs
2. ensure the jobs are created normally
3. do some stuff that creates jobs in a Delayed::Batch.serial_batch
   block
4. ensure a batch job is created for each unique priority+queue
5. ensure no jobs with a strand or run_at get put in batches
4. ensure that invoking each batch job creates all its component
   deferred jobs and runs them synchronously

Change-Id: I36a56fa0c7ee2ffcd19e82dd5733496d4872f51a
Reviewed-on: https://gerrit.instructure.com/9169
Reviewed-by: Jon Jensen <jon@instructure.com>
Tested-by: Hudson <hudson@instructure.com>
auto-unarchive when sending direct messages, fixes #5366

when sending a message to an archived conversation (private or group),
we should auto-unarchive it for the sender. if it's a bulk private
message, we should leave it alone

test plan:
1. archive a private conversation
2. send a message to it
3. ensure it gets unarchived
4. archive a private conversation
5. send a bulk private message w/ the user from 4. as one of the
   recipients
6. ensure it does not get unarchived

Change-Id: I5c32fb41a295f8042204d723aef41a1961e6869f
Reviewed-on: https://gerrit.instructure.com/9421
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Zach Pendleton <zachp@instructure.com>
flag topics as threaded, fixes #7792

If a discussion topic is threaded, it'll allow sub-entries to have other
sub-entries as parents. otherwise it'll force sub-entries to always have
a root entry as a parent (restoring the behavior pre-e9edb2a86f

test plan:

Make a side comment in reply to another side comment, reload the page,
and verify it shows your comment. Do the same via the API. There's no UI
yet for marking a discussion as threaded, but you can do it from the
console and then verify that replies to replies are now nested.

Change-Id: I6bddcfa318f36bcbc6ddb03c152ff1fa8fa550b8
Reviewed-on: https://gerrit.instructure.com/9506
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>