mampf icon indicating copy to clipboard operation
mampf copied to clipboard

Vouchers for user promotion - Part 2: Redemption

Open fosterfarrell9 opened this issue 6 months ago • 1 comments

This PR continues #670. Vouchers can be redeemed in order to take over tutorials, become a lecture editor, become a teacher or become a speaker (of a talk in a seminar).

To Dos

  • [x] Redemption of tutor vouchers
  • [x] Redemption of editor vouchers
  • [x] Redemption of teacher vouchers
  • [x] Redemption of speaker vouchers
  • [x] Notifications for the redemption of tutor vouchers, editor vouchers, teacher vouchers and speaker vouchers
  • [x] Write unit tests
  • [x] Write cypress tests

Further To Dos (for reviewer)

  • [ ] Moving people around in lecture tutorials, should still be visible in dropdowns
  • [ ] Test user deletion with redemptions -> should be deleted as well
  • [x] Make sure secure hash also works with empty spaces at the beginning / at the end (when copied since oftentimes whitespaces are also copied)
  • [x] Tell browser that secure hash text box shouldn't be auto-completable as to avoid storing these hashes as user suggestions.
  • [ ] Test sending of mails
  • [X] Refactor VoucherProcessor
  • [ ] Refactor Lecture model

Out of scope

  • Restrict the "My courses" invisible form to be rendered only when user is administrator. See views/administration/index/_my_courses.html.erb.
  • ~~Allow instance methods to be passed to spec FactoriesController for Cypress specs~~
    -> moved to #696
  • ~~Refactor UserCreatorController for Cypress specs~~
    -> moved to #696
  • Fix some CSpell configuration (increase max number of problems shown in one file and enable spell checking in ruby files)

Notes for the reviewer

The redemption of Vouchers is basically done via two actions of the VouchersController, namely #verify and #redeem. In order to keep the controller lean, I introduced a service model VoucherProcessor in app/services (see e.g. here). Also, I extracted some stuff into the Notifier concern in apps/controllers/concerns since this contains some code also used by the LecturesController. On the model side, two new ActiveRecord models are used to store redemptions of vouchers: Redemption and Claim. The first one is basically a join table between User and Voucher (it stores that a certain user redeemed a certain voucher at a given time). The second one is a (polymorphic) join table between Redemption and so called Claimables, where the latter ones can be tutorials or talks. A claim describes what was taken over ("claimed") in the act of redeeming a voucher. In order to understand things it is probably best to play around a little in the GUI (with two users, one who is creating vouchers and one who is redeeming them) and observe what happens in the database. There are four different kinds of vouchers, hence there should be a lot to play around with. Depending on what kind of voucher that is redeemed, notifications in MaMpf and by email are issued: For each kind of voucher, notifications in MaMpf are created for the teacher and editors of the lecture. Additionally,

  • for the redemption of a teacher voucher, one email is sent to the new teacher and one to the previous teacher informing them of the change
  • for the redemption of an editor voucher, an email is sent to the new editor
  • for the redemption of a speaker voucher, an email is sent to all cospeakers of the same talk informing them that another user has joined them

Note that redemptions only work additively: E.g. you can only take over tutorials, not resign from ones you are already a tutor of; similarly for the other kinds of vouchers. This is deliberate and by design: If you want to resign from a tutorial as a tutor you should contact a lecture editor. The same goes for the other kinds of status upgrades provided by vouchers. I wrote unit tests for the vouchers model, the voucher processor and some security relevant routes in the vouchers controller. I have not yet written unit tests for some newly defined methods in the lecture model.

fosterfarrell9 avatar Aug 13 '24 12:08 fosterfarrell9