Currently when bulk-awarding a badge that can be granted multiple times, users that appear multiple times in the CSV file are granted the badge only once if they have not been granted the badge before, and never if they already have the badge.
This PR adds a new option to the Badge Bulk Award feature so that it’s possible to grant users a badge even if they already have the badge and as many times as they appear in the CSV file:
The way this feature works is when you upload a CSV file, the
Admin::BadgesController#mass_award action looks up the current sequence numbers of the badge for all the users in the CSV file, and then passes this data to the instances of
MassAwardBadge it enqueues.
The rationale behind making the controller action look up the current sequence numbers instead of the
MassAwardBadge job is to make the job “crash safe”. I.e., if the job looked up the current sequence numbers and it crashed midway through, Sidekiq would retry the job later and the job could potentially see new sequence numbers in the database and grant some users the badge more times than it should. In the current design we have no such problem because the controller passes the sequence numbers to the job and in the event it’s retried it reuses the same sequence numbers.