-
Notifications
You must be signed in to change notification settings - Fork 5
Simplify class links by removing special cases for teachers & owners #1003
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,14 +16,11 @@ def create | |
| case action_status | ||
| when :wrong_school, :domain_mismatch, :not_a_student | ||
| render json: { error: action_status.to_s }, status: :forbidden | ||
| when :already_member, :owner | ||
| render json: { redirect_url: class_redirect_path }, status: :ok | ||
| when :joinable_as_teacher | ||
| add_user_to_class_as_teacher | ||
| render json: { redirect_url: class_redirect_path }, status: :ok | ||
| when :already_member | ||
| render json: {}, status: :ok | ||
| when :joinable | ||
| add_student_to_school_and_class | ||
| render json: { redirect_url: class_redirect_path }, status: :ok | ||
| render json: {}, status: :ok | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this and
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The behaviour is different as there's a call to |
||
| else | ||
| raise "Unexpected join action_status: #{action_status.inspect}" | ||
| end | ||
|
|
@@ -46,10 +43,6 @@ def action_status | |
| @action_status ||= JoinStatusService.new(school: @school, school_class: @school_class, user: current_user).call | ||
| end | ||
|
|
||
| def class_redirect_path | ||
| "/school/#{@school.code}/class/#{@school_class.code}" | ||
| end | ||
|
|
||
| def add_student_to_school_and_class | ||
| ActiveRecord::Base.transaction do | ||
| Role.find_or_create_by!(school: @school, user_id: current_user.id, role: :student) | ||
|
|
@@ -64,16 +57,5 @@ def add_student_to_school_and_class | |
| raise unless e.record.errors.of_kind?(:student_id, :taken) | ||
| # Concurrent join request raced the in-memory uniqueness validator. Already enrolled. | ||
| end | ||
|
|
||
| def add_user_to_class_as_teacher | ||
| ClassTeacher.find_or_create_by!(school_class: @school_class, teacher_id: current_user.id) do |class_teacher| | ||
| class_teacher.teacher = current_user | ||
| end | ||
| rescue ActiveRecord::RecordNotUnique | ||
| # Concurrent join request for the same teacher/class — already enrolled. | ||
| rescue ActiveRecord::RecordInvalid => e | ||
| raise unless e.record.errors.of_kind?(:teacher_id, :taken) | ||
| # Concurrent join raced the in-memory uniqueness validator. Already enrolled. | ||
| end | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.