From e447f2a64c88dcc75173d59b77e577fd53ee3346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com> Date: Tue, 11 Jan 2022 12:31:50 +0100 Subject: [PATCH] sync program when teacher/role/person is commited --- app/models/education/program/role.rb | 6 ++++++ app/models/education/program/role/person.rb | 7 +++++++ app/models/education/program/teacher.rb | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/app/models/education/program/role.rb b/app/models/education/program/role.rb index d79798d06..1f9113f5e 100644 --- a/app/models/education/program/role.rb +++ b/app/models/education/program/role.rb @@ -28,6 +28,8 @@ class Education::Program::Role < ApplicationRecord has_many :people, class_name: 'Education::Program::Role::Person', dependent: :destroy has_many :university_people, through: :people, source: :person + after_commit :sync_program + def to_s "#{title}" end @@ -37,4 +39,8 @@ class Education::Program::Role < ApplicationRecord def last_ordered_element program.roles.ordered.last end + + def sync_program + program.sync_with_git + end end diff --git a/app/models/education/program/role/person.rb b/app/models/education/program/role/person.rb index f61f1d20f..648a7ffb6 100644 --- a/app/models/education/program/role/person.rb +++ b/app/models/education/program/role/person.rb @@ -24,6 +24,9 @@ class Education::Program::Role::Person < ApplicationRecord belongs_to :person, class_name: 'University::Person' belongs_to :role, class_name: 'Education::Program::Role' + delegate :program, to: :role + + after_commit :sync_program def to_s person.to_s @@ -34,4 +37,8 @@ class Education::Program::Role::Person < ApplicationRecord def last_ordered_element role.people.ordered.last end + + def sync_program + program.sync_with_git + end end diff --git a/app/models/education/program/teacher.rb b/app/models/education/program/teacher.rb index 2a85d5928..bed1c1afd 100644 --- a/app/models/education/program/teacher.rb +++ b/app/models/education/program/teacher.rb @@ -27,7 +27,15 @@ class Education::Program::Teacher < ApplicationRecord scope :ordered, -> { joins(:person).order('university_people.last_name, university_people.first_name') } + after_commit :sync_program + def to_s person.to_s end + + protected + + def sync_program + program.sync_with_git + end end -- GitLab