-
Notifications
You must be signed in to change notification settings - Fork 5
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
Support multiple teachers per class #456
Open
loiswells97
wants to merge
31
commits into
main
Choose a base branch
from
spike-multiple-teachers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
a876fcb
inconsequential change to generate pr
loiswells97 c81c521
revert previous change
loiswells97 8d9eec7
Merge branch 'main' into spike-multiple-teachers
loiswells97 ea9ea6e
WIP: change models to allow multiple teachers
loiswells97 c8f54e1
switching existing class members model to class students
loiswells97 720ef16
fixing remove class teacher id rollback function
loiswells97 a6a5a2f
fixing teacher and owner abilities
loiswells97 d41dd2a
fixing some student abilities
loiswells97 0ca6424
allow multiple class teachers to view student work
loiswells97 6215d97
Merge branch 'main' into spike-multiple-teachers
KristinaDudnyk f050fbc
Merge branch 'main' into spike-multiple-teachers
loiswells97 287cd4a
class teacher and class student factories
loiswells97 82fb69e
fix class creation and find and replace
loiswells97 8e4fba0
fixing factory and massive find and replace
loiswells97 003a012
test fixing
loiswells97 e4029e4
more test fixes
loiswells97 3024068
lots of fixing
loiswells97 3ec5215
getting tests passing!!!
loiswells97 36add40
fixing rubocop
loiswells97 3d19d2e
Merge branch 'main' into spike-multiple-teachers
loiswells97 6714801
tidying
loiswells97 51c855e
tidying
loiswells97 ee3fca7
adding tests
loiswells97 dbf031f
more tests
loiswells97 9b0e9b4
test school class model with multiple teachers
loiswells97 30fa842
rubocop
loiswells97 c670d11
tidying
loiswells97 b697e17
fixing ability of joint calss teacher to set project visible to students
loiswells97 4a8bed9
bug fixing
loiswells97 0a418c1
rubocop
loiswells97 c0c49f1
Merge branch 'main' into spike-multiple-teachers
loiswells97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
class ClassTeacher < ApplicationRecord | ||
belongs_to :school_class | ||
delegate :school, to: :school_class | ||
attr_accessor :teacher | ||
|
||
validates :teacher_id, presence: true, uniqueness: { | ||
scope: :school_class_id, | ||
case_sensitive: false | ||
} | ||
|
||
validate :teacher_has_the_school_teacher_role_for_the_school | ||
|
||
has_paper_trail( | ||
meta: { | ||
meta_school_id: ->(cm) { cm.school_class&.school_id } | ||
} | ||
) | ||
|
||
private | ||
|
||
def teacher_has_the_school_teacher_role_for_the_school | ||
return unless teacher_id_changed? && errors.blank? && teacher.present? | ||
|
||
return if teacher.school_teacher?(school) | ||
|
||
msg = "'#{teacher.id}' does not have the 'school-teacher' role for organisation '#{school.id}'" | ||
errors.add(:teacher, msg) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
json.array!(@school_classes_with_teachers) do |school_class, teacher| | ||
json.array!(@school_classes_with_teachers) do |school_class, teachers| | ||
json.call( | ||
school_class, | ||
:id, | ||
:description, | ||
:school_id, | ||
:teacher_id, | ||
:name, | ||
:created_at, | ||
:updated_at | ||
) | ||
|
||
json.teacher_name(teacher&.name) | ||
json.teachers(teachers) do |teacher| | ||
json.call( | ||
teacher, | ||
:id, | ||
:name | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
school_class, teacher = @school_class_with_teacher | ||
school_class, teachers = @school_class_with_teachers | ||
|
||
json.call( | ||
school_class, | ||
:id, | ||
:description, | ||
:school_id, | ||
:teacher_id, | ||
:name, | ||
:created_at, | ||
:updated_at | ||
) | ||
|
||
json.teacher_name(teacher&.name) | ||
json.teachers(teachers) do |teacher| | ||
json.call( | ||
teacher, | ||
:id, | ||
:name | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateClassTeachers < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :class_teachers, id: :uuid do |t| | ||
t.references :school_class, type: :uuid, foreign_key: true, index: true, null: false | ||
t.uuid :teacher_id, null: false | ||
t.timestamps | ||
end | ||
|
||
add_index :class_teachers, :teacher_id | ||
add_index :class_teachers, %i[school_class_id teacher_id], unique: true | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
db/migrate/20241101125505_move_teacher_data_to_class_teachers_table.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class MoveTeacherDataToClassTeachersTable < ActiveRecord::Migration[7.1] | ||
def up | ||
SchoolClass.find_each do |school_class| | ||
ClassTeacher.create!(school_class: school_class, teacher_id: school_class.teacher_id) | ||
end | ||
end | ||
|
||
def down | ||
ClassTeacher.destroy_all | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class RemoveClassTeacherId < ActiveRecord::Migration[7.1] | ||
def up | ||
remove_column :school_classes, :teacher_id | ||
end | ||
|
||
def down | ||
add_column :school_classes, :teacher_id, :uuid | ||
ClassTeacher.find_each do |class_teacher| | ||
school_class = class_teacher.school_class | ||
school_class.update!(teacher_id: class_teacher.teacher_id) | ||
end | ||
change_column_null :school_classes, :teacher_id, false | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
db/migrate/20241101142545_rename_class_members_to_class_students.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class RenameClassMembersToClassStudents < ActiveRecord::Migration[7.1] | ||
def up | ||
rename_table :class_members, :class_students | ||
end | ||
|
||
def down | ||
rename_table :class_students, :class_members | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why use
:students
and then:class_teachers
instead of:teachers
or vice versa? going with one or the other would be nice for consistency