Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vouchers for user promotion - Part 2: Redemption #671

Merged
merged 205 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
205 commits
Select commit Hold shift + click to select a range
3980559
Initialize voucher model and add some unit tests
fosterfarrell9 Jul 28, 2024
f9876e4
Make ensure_no_other_active_voucher validation into a callback
fosterfarrell9 Jul 28, 2024
1e057fc
Add throw :abort in order to halt execution
fosterfarrell9 Aug 4, 2024
681fe94
Replace Time.now by Time.zone.now
fosterfarrell9 Aug 4, 2024
f514ffb
Set up basic functionality for display of vouchers for tutors
fosterfarrell9 Aug 4, 2024
eb1d17d
Create separate file for copy and paste button code and decaffeinate
fosterfarrell9 Aug 4, 2024
b594cc3
Set up destruction of tutor vouchers
fosterfarrell9 Aug 4, 2024
8f980b0
Merge branch 'dev' into feature/vouchers-user-promotion
fosterfarrell9 Aug 4, 2024
3b5425c
Rename view file as it containes embedded ruby
fosterfarrell9 Aug 4, 2024
aad2134
Add create action for vouchers and corresponding views
fosterfarrell9 Aug 5, 2024
e377f03
Adapt views and controller for adding and removing of vouchers of dif…
fosterfarrell9 Aug 6, 2024
9f4edc9
Put duplicate lines into a separate method
fosterfarrell9 Aug 6, 2024
74637b3
Set up redeeming of vouchers
fosterfarrell9 Aug 6, 2024
db61b04
fix typo
fosterfarrell9 Aug 8, 2024
71ea44b
remove obsolete methods
fosterfarrell9 Aug 8, 2024
d54a2ab
Avoid use of Time.now
fosterfarrell9 Aug 8, 2024
2a91c7c
Refactor active_vouhcer_of_sort method
fosterfarrell9 Aug 9, 2024
f63e204
remove unused expired? method
fosterfarrell9 Aug 9, 2024
3a30f97
Remove duplicate code
fosterfarrell9 Aug 9, 2024
5751c7b
remove unused variable
fosterfarrell9 Aug 9, 2024
4149f5e
Add controller spec for vouchers
fosterfarrell9 Aug 9, 2024
cab3981
Rewrite controller spec for vouchers
fosterfarrell9 Aug 11, 2024
5efa753
remove obsolete comment
fosterfarrell9 Aug 11, 2024
4ca6fea
Set up redemption of tutor vouchers
fosterfarrell9 Aug 13, 2024
555843b
Remove user lookup for tutor positions
fosterfarrell9 Aug 13, 2024
7b7b157
Set up redemption of editor vouchers
fosterfarrell9 Aug 13, 2024
b533d81
Merge branch 'dev' into feature/vouchers-user-promotion
fosterfarrell9 Aug 14, 2024
84c742c
Merge branch 'feature/vouchers-user-promotion' into feature/voucher-r…
fosterfarrell9 Aug 14, 2024
0da405e
Add Contract Model and setup selection of tutors and editors
fosterfarrell9 Aug 15, 2024
6c8d657
Set up notifications for redemption of tutor vouchers
fosterfarrell9 Aug 15, 2024
93d54f9
Invalidate vouchers instead of destroying them
fosterfarrell9 Aug 16, 2024
98a957a
Merge branch 'feature/vouchers-user-promotion' into feature/voucher-r…
fosterfarrell9 Aug 16, 2024
b712851
Add redemption and claim models and rewrite workflow accordingly
fosterfarrell9 Aug 16, 2024
08ffc49
Restore to previous state
fosterfarrell9 Aug 16, 2024
b1a6614
Fix typo
fosterfarrell9 Aug 16, 2024
ab82c87
Implement Rubocop suggestion
fosterfarrell9 Aug 16, 2024
f7e9b57
Replace voucher_hash by secure_hash
fosterfarrell9 Aug 17, 2024
19148e3
Replace redeem_voucher_params by check_voucher_params
fosterfarrell9 Aug 17, 2024
d2bdba7
Add cancel action to vouchers controller
fosterfarrell9 Aug 17, 2024
2538684
Differentiate between different cases of tutor voucher redemption
fosterfarrell9 Aug 17, 2024
0e728d4
Differentiate between different cases of editor voucher redemption
fosterfarrell9 Aug 17, 2024
102bcc2
Take first steps in setting up redemption of teacher vouchers
fosterfarrell9 Aug 17, 2024
09f47c2
Add notifications for redemption of teacher vouchers
fosterfarrell9 Aug 17, 2024
2205752
Add notification mails for teacher change by voucher redemption
fosterfarrell9 Aug 17, 2024
3b69eb1
Invalidate teacher vouchers after first use
fosterfarrell9 Aug 17, 2024
c00f482
Add vouchers for seminar speakers
fosterfarrell9 Aug 18, 2024
bdbaec5
Merge branch 'feature/vouchers-user-promotion' into feature/voucher-r…
fosterfarrell9 Aug 18, 2024
8f6c235
Add helpdesk for speaker vouchers
fosterfarrell9 Aug 18, 2024
34e0063
Set up redemption of speaker vouchers
fosterfarrell9 Aug 18, 2024
6b662ea
Add notifications for redemption of speaker vouchers
fosterfarrell9 Aug 18, 2024
9d441ff
Restrict access user select
fosterfarrell9 Aug 18, 2024
587b72f
Remove unused parameter
fosterfarrell9 Aug 18, 2024
a3e99ed
Introduce VoucherProcessor service object
fosterfarrell9 Aug 19, 2024
b71af1a
Use common partial for redemption of tutor and speeaker vouchers
fosterfarrell9 Aug 19, 2024
a704e57
Rename sort attribute of vouchers to role
fosterfarrell9 Aug 19, 2024
73aa5e6
Merge branch 'feature/vouchers-user-promotion' into feature/voucher-r…
fosterfarrell9 Aug 19, 2024
0c705e2
Rename remaining occurences of sort attribute of voucher to role
fosterfarrell9 Aug 19, 2024
4ed95d5
Add unit tests for VoucherProcessor
fosterfarrell9 Aug 19, 2024
06d06ac
Add .uniq to method
fosterfarrell9 Aug 19, 2024
d57e66f
Remove teacher selection for non-admins
fosterfarrell9 Aug 20, 2024
692dd16
Remove obsolete reference to non-existent model
fosterfarrell9 Aug 20, 2024
e5f471e
Remove permissions from non-admins to change teachers
fosterfarrell9 Aug 20, 2024
11fb080
Add cypress data attributes
fosterfarrell9 Aug 20, 2024
215b46b
Add first cypress tests
fosterfarrell9 Aug 20, 2024
e33db99
Add more cypress tests
fosterfarrell9 Aug 21, 2024
2eda386
Merge branch 'feature/vouchers-user-promotion' into feature/voucher-r…
fosterfarrell9 Aug 21, 2024
8a0e965
Add first cypress tests for voucher redemption
fosterfarrell9 Aug 21, 2024
7429387
Init future possibility to check clipboard content
Splines Aug 21, 2024
8e9d0f9
Merge branch 'dev' into feature/vouchers-user-promotion
fosterfarrell9 Aug 22, 2024
b13f875
Merge branch 'feature/vouchers-user-promotion' into feature/voucher-r…
fosterfarrell9 Aug 22, 2024
3710ee1
Add missing teacher field for non-admins
fosterfarrell9 Aug 22, 2024
049edec
Add cypress tests for redemption form
fosterfarrell9 Aug 22, 2024
329194f
Add cypress command .tomselect to select in TomSelect forms
fosterfarrell9 Aug 22, 2024
913f816
Add test for redemption form using the new .tomselect command
fosterfarrell9 Aug 22, 2024
7289053
Remove unnecessary call of trait
fosterfarrell9 Aug 24, 2024
5a65708
Use NO_SEMINAR_ROLES constant
fosterfarrell9 Aug 24, 2024
d719333
Merge branch 'feature/vouchers-user-promotion' into feature/voucher-r…
fosterfarrell9 Aug 24, 2024
7f68ee9
Clean up some experiments
fosterfarrell9 Aug 24, 2024
74cae07
Remove .tomselect Command for cypress
fosterfarrell9 Aug 24, 2024
9e5d4e4
Enlarge test user json by some data
fosterfarrell9 Aug 24, 2024
cec8dc6
Add logout command and expect correct statuses for login and logout r…
fosterfarrell9 Aug 24, 2024
b3ae179
Add more cypress tests for redemption of tutor vouchers
fosterfarrell9 Aug 24, 2024
1f5a9f6
Parse hashes with integer keys into arrays of strings
fosterfarrell9 Aug 24, 2024
e57e35f
Add tests for tutor voucher redemption in the case that all tutorials…
fosterfarrell9 Aug 24, 2024
9ccf03f
Add possibility to pass instance methods and refactor
fosterfarrell9 Aug 25, 2024
f6a2d1f
Update documentation
fosterfarrell9 Aug 25, 2024
c5c125c
Add tests for voucher redemption that check notifications
fosterfarrell9 Aug 25, 2024
a173655
Add missing speaker voucher case
fosterfarrell9 Aug 25, 2024
05f9959
Add missing locales
fosterfarrell9 Aug 25, 2024
13e0386
Add cypress tests fo editor vouchers, teacher vouchers and speaker vo…
fosterfarrell9 Aug 25, 2024
6422123
Remove out of scope test
fosterfarrell9 Aug 26, 2024
352ade6
Refactor helper methods
fosterfarrell9 Aug 26, 2024
4ebc186
Extract helper functions to separate file
fosterfarrell9 Aug 26, 2024
fdb4efe
Refactor tests
fosterfarrell9 Aug 26, 2024
3f68b1f
Extract more methods into helper
fosterfarrell9 Aug 26, 2024
c2c8b9d
Rename files according to conventions
fosterfarrell9 Aug 26, 2024
7acfa68
Add controller specs for changed lecture update policy
fosterfarrell9 Aug 26, 2024
2ce127f
Refactor tests by extracting methods
fosterfarrell9 Aug 27, 2024
4576b15
Merge branch 'dev' into feature/voucher-redemption
Splines Sep 21, 2024
ee16ca2
Don't define `redeem` method twice
Splines Sep 21, 2024
d01ec97
Pluralize voucher redemption spec filename
Splines Sep 21, 2024
b741b1f
Delete duplicate migration & update new migration dates/schema
Splines Sep 21, 2024
d8e5d36
Move cypress helpers to e2e folder
Splines Sep 21, 2024
3eb25e9
Merge remote-tracking branch 'origin/dev' into feature/voucher-redemp…
Splines Sep 22, 2024
4a18ac7
Improve naming for voucher finding method
Splines Sep 22, 2024
b16f599
Inline JSON object in user creator controller
Splines Sep 22, 2024
abe2ad9
Use symbolic keys upon voucher type case statement
Splines Sep 22, 2024
9ab1030
Fix "Redeem voucher" spelling mistake
Splines Sep 22, 2024
8ecb489
Use fixed width for voucher redemption selectize field
Splines Sep 23, 2024
c372a2e
Rename view file to `voucher_redemption_form`
Splines Sep 23, 2024
49b7077
Fix indentation in view file (tutor voucher)
Splines Sep 23, 2024
68a3c63
Replace cypress `describe` by `context`
Splines Sep 23, 2024
c1199be
Remove reviewer-TODO comments (selectize tomselect)
Splines Sep 23, 2024
09502a7
Reset Cypress-related code to 49cf16af3790
Splines Sep 25, 2024
f109d45
Merge branch 'dev' into feature/voucher-redemption
Splines Sep 25, 2024
035c6bd
Use new .call syntax in cypress tests
Splines Sep 25, 2024
0b88647
Explicitly set `name_in_tutorials` for users
Splines Sep 25, 2024
15fe4f1
Remove constraint that user id must be a number
Splines Sep 25, 2024
8cb3c43
Init support for entity-relationship-diagram creation
Splines Oct 3, 2024
c8e50d1
Merge branch 'feature/erd' into feature/voucher-redemption
Splines Oct 3, 2024
16bb765
Add `has_many :notifications` for better ERD visibility
Splines Oct 8, 2024
b5d5453
Remove usage of delegate methods from redemption
Splines Oct 8, 2024
e2786e3
Don't hardcode source_type as string
Splines Oct 8, 2024
d33072d
Refactor voucher_processor into model concern
Splines Oct 8, 2024
0c98e6a
Add missing notification and subscribe lecture steps
Splines Oct 8, 2024
66b6edf
Move vouchers down in UI (lecture edit page)
Splines Oct 8, 2024
84ab975
Turn off autocomplete for redeem voucher text field
Splines Oct 8, 2024
ae0b22c
Strip secure hash to avoid copy-pasting issues with voucher
Splines Oct 8, 2024
4530ef8
Improve voucher-model docstrings
Splines Oct 8, 2024
47784ca
Fix wrong permit syntax for arrays
Splines Oct 8, 2024
57530f2
Move Claim model to voucher folder
Splines Oct 8, 2024
6d0be7e
Adapt Redeemer specs to new architecture
Splines Oct 8, 2024
8f9ef78
Use `pluck` instead of `select` for better performance
Splines Oct 8, 2024
cab6097
Test timestamp in invalidate! voucher spec
Splines Oct 8, 2024
71fc49a
Remove unused routes
Splines Oct 9, 2024
7df4ee1
Fix missing CSpell configuration
Splines Oct 9, 2024
bd22c93
Improve tutor voucher redemption messages
Splines Oct 12, 2024
79d2c8a
Improve speaker voucher redemption messages
Splines Oct 12, 2024
ce0c831
Replace "Voucher" by "Gutschein" in German texts
Splines Oct 12, 2024
ab7c6b4
Improve teacher voucher redemption messages
Splines Oct 12, 2024
6990a2c
Improve editor voucher redemption messages
Splines Oct 12, 2024
787eb96
Remove duplicate `no_active_voucher` i18n key
Splines Oct 12, 2024
57fa450
Add help texts to voucher creation
Splines Oct 12, 2024
4ed73bc
Also eager_load additional modules
Splines Oct 15, 2024
008ae7d
Outsource x_by_redemption methods from lecture to redemption
Splines Oct 15, 2024
ee13d40
Fix wrong i18n controller error
Splines Oct 15, 2024
509a1ec
Fix cypress test (due to renaming of i18n keys / html)
Splines Oct 15, 2024
32f0d00
Cypress test that whitespaces in voucher hash work
Splines Oct 15, 2024
baac57b
Verify voucher is invalid after user became teacher
Splines Oct 15, 2024
aa7aec9
Add user deletion cypress spec (for tutor)
Splines Oct 15, 2024
ef15a6e
Add word to cspell list
Splines Oct 15, 2024
831f5a3
Replace "display" by "show"
Splines Oct 15, 2024
0ba6696
Fix two spelling mistakes (out of scope)
Splines Oct 15, 2024
68afdec
Move lecture notifications to separate file
Splines Oct 17, 2024
11f748d
Replace Notifier concern by LectureNotifier module
Splines Oct 17, 2024
7fec453
Remove unused set_recipients method for "new editor mail"
Splines Oct 17, 2024
82d6c67
Move email templates to right folder
Splines Oct 29, 2024
555e26e
Correct sender_nad_locale setting
Splines Oct 29, 2024
ae7a5cd
Introduce enqueue_mail_with_params matcher & test for editor
Splines Oct 29, 2024
b8c3fbf
Add spec for Current user model
Splines Oct 29, 2024
d080a0c
Inline sender_and_locale
Splines Oct 29, 2024
663b27f
Try to test email sending for editor voucher (fails)
Splines Oct 29, 2024
1d32640
Mock Current model in RSpec tests
Splines Oct 30, 2024
8470fc0
Rework sender and locale setting
Splines Oct 30, 2024
7fdfc85
Fix mail sending test for editor
Splines Oct 30, 2024
7264926
Test mail body (editor)
Splines Oct 30, 2024
10d28fb
Set locale in broader scope test
Splines Oct 30, 2024
a003fbc
Fix comment
Splines Oct 30, 2024
a78c767
Test previous and new teacher mail
Splines Oct 30, 2024
7da4d84
Use custom html body matcher (ignore \r\n)
Splines Oct 30, 2024
5350245
Improve wording in html body failure message
Splines Oct 31, 2024
5b8be7e
Test mails for co-speakers
Splines Oct 31, 2024
ccaa9ec
Ensure user that is now speaker doesn't receive a mail
Splines Oct 31, 2024
c25aa28
Use just one file for mail matchers
Splines Oct 31, 2024
0ce9536
Rename matcher to enqueue_mail_including_params
Splines Oct 31, 2024
7db17b5
Outsource from notification mailer assertion
Splines Oct 31, 2024
a40e13c
Refactor send mail to co-speaker test
Splines Oct 31, 2024
b9f28e8
Remove unwanted test
Splines Oct 31, 2024
f7d9d79
Add tests for teacher selection dropdown
Splines Nov 5, 2024
8b2de36
Write test for editor dropdown selection
Splines Nov 5, 2024
c1d843f
Allow admin to select any user in lecture editor select
Splines Nov 6, 2024
cd62839
Remove `only` from cypress test
Splines Nov 6, 2024
7d795f7
Add more words to spell checker
Splines Nov 6, 2024
e265d8c
Add tests for tutor selection dropdown
Splines Nov 6, 2024
f65f573
Add back ability for admin to select any user as tutor
Splines Nov 6, 2024
4f17464
Allow admin to choose arbitrary users as speakers & test
Splines Nov 6, 2024
28f1078
Remove unnecessary display: none
Splines Nov 6, 2024
b12cff8
Improve if statement in voucher redemption
Splines Nov 6, 2024
437deb1
Remove another unnecessary "be.visible" statement
Splines Nov 6, 2024
016a142
Allow admins to select arbitrary users in existing talks & test
Splines Nov 6, 2024
ddc48ec
Rename lecture spec file
Splines Nov 6, 2024
95eaa1f
Refactor lecture people select spec (extract methods)
Splines Nov 6, 2024
58091e6
Reuse speaker_select helper
Splines Nov 9, 2024
7d53f83
Outsource to new teacher_select helper
Splines Nov 9, 2024
1ae8f91
Outsource to new editors_select helper
Splines Nov 9, 2024
6c6a7c8
Remove with_seminar trait
Splines Nov 9, 2024
34b5b72
Make cypress input selecting more reliable
Splines Nov 9, 2024
7c898fd
Remove unnecessary div wrap
Splines Nov 9, 2024
43ac12f
Avoid flaky test by intercepting user fill request
Splines Nov 9, 2024
f1366b0
Fix cypress not typing "cy" in input box
Splines Nov 9, 2024
cc82b94
Remove current_user= test as method was removed
Splines Nov 9, 2024
68e161d
Intercept /talks/new route to avoid flaky test
Splines Nov 9, 2024
c496959
Add cy.wait as last resort
Splines Nov 9, 2024
c864be8
Visit #people page directly
Splines Nov 9, 2024
f7a71ca
Remove unwanted `only` in Cypress test
Splines Nov 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .config/commands/utils.justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Prints this help message
[private]
help:
@just --list --justfile {{source_file()}}

# Generates entity-relationship diagrams (ERD) of the database
erd:
#!/usr/bin/env bash

# Make sure the mampf dev container is running
cd {{justfile_directory()}}/docker/development/
if [ -z "$(docker compose ps --services --filter 'status=running' | grep mampf)" ]; then
echo "The mampf dev container is not running. Please start it first (use 'just docker')."
exit 1
fi

mkdir -p {{justfile_directory()}}/tmp/erd/

# ▶ Generate ERDs
# Customize it with options from here: https://voormedia.github.io/rails-erd/customise.html
# Also see the output from: 'bundle exec erd --help' (inside the dev container)

# Ignore some tables
ignored_thredded="Thredded::Post,Thredded::UserPostNotification,Thredded::PrivateUser,Thredded::UserPrivateTopicReadState,Thredded::PrivateTopic,Thredded::MessageboardUser,Thredded::PrivatePost,Thredded:UserDetail,Thredded::MessageboardGroup,Thredded::Messageboard,Thredded::Category,Thredded::TopicCategory,Thredded::Topic,Thredded::UserTopicReadState,Thredded::UserTopicFollow,Thredded::NotificationsForFollowedTopics,Thredded::MessageboardNotificationsForFollowedTopics,Thredded::UserPreference,Thredded::UserMessageboardPreference,Thredded::NotificationsForPrivateTopics,Thredded::PostModerationRecord,Thredded::UserDetail"
ignored_translation="Mobility::Backends::ActiveRecord::Table::Translation,Subject::Translation,Program::Translation,Division::Translation"
ignored_commontator="Commontable,Votable,Subscriber,Creator"
other_ignored="ActionMailbox::Record,ActionText::Record,ActiveStorage::Record,Sluggable,FriendlyId::Slug,ApplicationRecord,InteractionsRecord"
exclude_default="${ignored_thredded},${ignored_translation},${ignored_commontator},${other_ignored}"

# 🌟 Overview with attributes (warnings will be printed only here)
docker compose exec -it mampf rake erd \
title=false filename=/usr/src/app/tmp/erd/mampf-erd-overview-with-attributes \
inheritance=false polymorphism=true indirect=false attributes=content \
exclude="${exclude_default}"

# 🌟 Generic Overview
docker compose exec -it mampf rake erd warn=false \
title=false filename=/usr/src/app/tmp/erd/mampf-erd-overview \
inheritance=false polymorphism=true indirect=false attributes=false \
exclude="${exclude_default}"

# 🌟 Vouchers
docker compose exec -it mampf rake erd warn=false \
title="Vouchers" filename=/usr/src/app/tmp/erd/mampf-erd-vouchers \
inheritance=true polymorphism=true indirect=true attributes=content \
exclude="${exclude_default},Teachable,Editable" \
only="User,Claim,Voucher,Redemption,Lecture,Tutorial,Talk"

# 🌟 Tutorials
docker compose exec -it mampf rake erd warn=false \
title="Tutorials" filename=/usr/src/app/tmp/erd/mampf-erd-tutorials \
inheritance=true polymorphism=true indirect=true attributes=content \
exclude="${exclude_default},Claimable,Editable,Teachable" \
only="User,Lecture,Tutorial,Submission,Assignment,TutorTutorialJoin,UserSubmissionJoin"

# 🌟 Courses
docker compose exec -it mampf rake erd warn=false \
title="Courses" filename=/usr/src/app/tmp/erd/mampf-erd-courses \
inheritance=true polymorphism=true indirect=true attributes=content \
exclude="${exclude_default},Claimable,Editable" \
only="Subject,Program,Division,DivisionCourseJoin,Course,Lecture,CourseSelfJoin,Lesson"

# 🌟 Lectures
docker compose exec -it mampf rake erd warn=false \
title="Lectures" filename=/usr/src/app/tmp/erd/mampf-erd-lectures \
inheritance=true polymorphism=true indirect=true attributes=content \
exclude="${exclude_default},Claimable,Editable,Teachable" \
only="Lecture,Lesson,Chapter,Section,Item,LessonSectionJoin,Term"

echo "📂 Diagrams are ready for you in the folder {{justfile_directory()}}/tmp/erd/"
echo "🔀 For the meanings of the arrows, refer to https://voormedia.github.io/rails-erd/gallery.html#notations"
3 changes: 3 additions & 0 deletions .justfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ mod test ".config/commands/test.justfile"
# Docker-related commands
mod docker ".config/commands/docker.justfile"

# Some utils, e.g. ERD-generation etc.
mod utils ".config/commands/utils.justfile"

# Opens the MaMpf wiki in the default browser
wiki:
#!/usr/bin/env bash
Expand Down
24 changes: 22 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,32 @@
//////////////////////////////////////
// Spell Checker
//////////////////////////////////////
"cSpell.enabled": true,
"cSpell.ignorePaths": [
"node_modules",
".git"
],
"cSpell.language": "en,de",
"cSpell.words": [
"activerecord",
"ajax",
"commontator",
"cospeaker",
"cospeakers",
"datetime",
"factorybot",
"helpdesk",
"katex",
"preselection",
"selectize",
"Timecop",
"turbolinks"
]
"turbolinks",
"uncached",
"whitespaces"
],
"cSpell.enableFiletypes": [
"ruby"
// Other filetypes are handled by the default spell checker
],
"cSpell.maxNumberOfProblems": 10000
}
6 changes: 1 addition & 5 deletions app/abilities/user_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ def initialize(user)
user.admin? || (!user.generic? && user == given_user)
end

can :fill_user_select, User do
user.active_teachable_editor?
end

can :list_generic_users, User do
can [:fill_user_select, :list_generic_users], User do
user.admin?
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/abilities/voucher_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ def initialize(user)
can [:create, :invalidate], Voucher do |voucher|
user.can_update_personell?(voucher.lecture)
end

can [:verify, :redeem, :cancel], Voucher
end
end
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ApplicationController < ActionController::Base
before_action :authenticate_user!
before_action :set_locale
after_action :store_interaction, if: :user_signed_in?
before_action :set_current_user

etag { current_user.try(:id) }

Expand Down Expand Up @@ -135,4 +136,9 @@ def cookie_locale_param
def available_locales
I18n.available_locales.map(&:to_s)
end

# https://stackoverflow.com/a/69313330/
def set_current_user
Current.user = current_user
end
end
Empty file removed app/controllers/concerns/.keep
Empty file.
10 changes: 5 additions & 5 deletions app/controllers/cypress/i18n_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ def create

substitutions = {}
if params[:substitutions].present?
unless params[:substitutions].is_a?(Hash)
msg = "Argument `substitution` must be a hash indicating the substitutions."
msg += " But we got: '#{params[:substitutions]}'"
begin
substitutions = params[:substitutions].to_unsafe_hash.symbolize_keys
rescue NoMethodError
msg = "Argument `substitution` is '#{params[:substitutions]}'."
msg += " We cannot convert that to a hash."
raise(ArgumentError, msg)
end
substitutions = params[:substitutions].to_unsafe_hash.symbolize_keys
end

i18n_key = params[:i18n_key]

render json: I18n.t(i18n_key, **substitutions), status: :created
end
end
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/cypress/user_creator_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def create

user = User.create(name: "#{role} Cypress #{random_hash}",
email: "#{role}-#{random_hash}@mampf.cypress",
# Note that some Cypress tests rely on the username
# beginning with "cy" (!)
name_in_tutorials: "cy-#{role}-#{random_hash}",
password: CYPRESS_PASSWORD, consents: true, admin: is_admin,
locale: I18n.default_locale)
user.confirm
Expand Down
45 changes: 45 additions & 0 deletions app/controllers/lecture_notifier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module LectureNotifier
extend self

def notify_new_editor_by_mail(editor, lecture)
LectureNotificationMailer.with(recipient: editor,
locale: editor.locale,
lecture: lecture)
.new_editor_email.deliver_later
end

def notify_about_teacher_change_by_mail(lecture, previous_teacher)
notify_new_teacher_by_mail(lecture)
notify_previous_teacher_by_mail(previous_teacher, lecture)
end

def notify_cospeakers_by_mail(speaker, talks)
talks.each do |talk|
talk.speakers.each do |cospeaker|
next if cospeaker == speaker

LectureNotificationMailer.with(recipient: cospeaker,
locale: cospeaker.locale,
talk: talk,
speaker: speaker)
.new_speaker_email.deliver_later
end
end
end

private

def notify_new_teacher_by_mail(lecture)
LectureNotificationMailer.with(recipient: lecture.teacher,
locale: lecture.teacher.locale,
lecture: lecture)
.new_teacher_email.deliver_later
end

def notify_previous_teacher_by_mail(previous_teacher, lecture)
LectureNotificationMailer.with(recipient: previous_teacher,
locale: previous_teacher.locale,
lecture: lecture)
.previous_teacher_email.deliver_later
end
end
15 changes: 7 additions & 8 deletions app/controllers/lectures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ def edit

def create
@lecture = Lecture.new(lecture_params)
@lecture.teacher = current_user unless current_user.admin?
Splines marked this conversation as resolved.
Show resolved Hide resolved
authorize! :create, @lecture
@lecture.save
if @lecture.valid?
@lecture.update(sort: "special") if @lecture.course.term_independent
# set organizational_concept to default
set_organizational_defaults
# set lenguage to default language
# set language to default language
set_language
# depending on where the create action was trriggered from, return
# depending on where the create action was triggered from, return
# to admin index view or edit course view
unless params[:lecture][:from] == "course"
redirect_to administration_path,
Expand Down Expand Up @@ -105,10 +106,7 @@ def update
recipients = User.where(id: new_ids)

recipients.each do |r|
NotificationMailer.with(recipient: r,
locale: r.locale,
lecture: @lecture)
.new_editor_email.deliver_later
LectureNotifier.notify_new_editor_by_mail(r, @lecture)
end
end

Expand Down Expand Up @@ -336,9 +334,10 @@ def lecture_params
:submission_max_team_size, :submission_grace_period,
:annotations_status]
if action_name == "update" && current_user.can_update_personell?(@lecture)
allowed_params.push(:teacher_id, { editor_ids: [] })
allowed_params.push({ editor_ids: [] })
end
allowed_params.push(:course_id, :teacher_id, { editor_ids: [] }) if action_name == "create"
allowed_params.push(:course_id, { editor_ids: [] }) if action_name == "create"
allowed_params.push(:teacher_id) if current_user.admin?
params.require(:lecture).permit(allowed_params)
end

Expand Down
50 changes: 48 additions & 2 deletions app/controllers/vouchers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,35 @@ def invalidate
end
end

def verify
@voucher = Voucher.find_voucher_by_hash(params[:secure_hash])
respond_to do |format|
if @voucher
format.js
format.html { head :no_content }
else
error_message = I18n.t("controllers.voucher_invalid")
format.js { render "error", locals: { error_message: error_message } }
format.html { redirect_to edit_profile_path, alert: error_message }
end
end
end

def redeem
# TODO: this will be dealt with in the corresponding 2nd PR
render js: "alert('Voucher redeemed!')"
voucher = Voucher.find_voucher_by_hash(params[:secure_hash])
if voucher
voucher.redeem(params.permit(tutorial_ids: [], talk_ids: []))
redirect_to edit_profile_path, notice: success_message(voucher)
else
handle_invalid_voucher
end
end

def cancel
respond_to do |format|
format.html { redirect_to edit_profile_path }
format.js
end
end

private
Expand All @@ -50,6 +76,18 @@ def set_related_data
I18n.locale = @lecture.locale
end

def success_message(voucher)
if voucher.tutor?
I18n.t("controllers.become_tutor_success")
elsif voucher.editor?
I18n.t("controllers.become_editor_success")
elsif voucher.teacher?
I18n.t("controllers.become_teacher_success")
elsif voucher.speaker?
I18n.t("controllers.become_speaker_success")
end
end

def handle_successful_save(format)
format.html { redirect_to edit_lecture_path(@lecture, anchor: "people") }
format.js
Expand Down Expand Up @@ -80,4 +118,12 @@ def handle_voucher_not_found
end
end
end

def handle_invalid_voucher
error_message = I18n.t("controllers.voucher_invalid")
respond_to do |format|
format.js { render "error", locals: { error_message: error_message } }
format.html { redirect_to edit_profile_path, alert: error_message }
end
end
end
6 changes: 6 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,10 @@ def get_class_for_any_path(paths)
def get_class_for_any_path_startswith(paths)
paths.any? { |path| request.path.starts_with?(path) } ? ACTIVE_CSS_CLASS : ""
end

def truncate_result(result, length = 40)
result.first(length).tap do |truncated|
return truncated.length < length ? truncated : "#{truncated}..."
end
end
end
Loading