Skip to content
Snippets Groups Projects
Commit c1956ce9 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

Merge branch 'master' of github.com:noesya/osuny

parents f6b7f6db b1266cb2
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,8 @@ module ActiveStorage::CheckAbilities
private
def check_abilities
render(file: Rails.root.join('public/403.html'), formats: [:html], status: 403, layout: false) and return if current_university.present? && @blob.university_id != current_university.id
# TEMP: Warning, we disable university check (TO REMOVE)
# render(file: Rails.root.join('public/403.html'), formats: [:html], status: 403, layout: false) and return if current_university.present? && @blob.university_id != current_university.id
end
def current_university
......
......@@ -25,9 +25,17 @@
# fk_rails_... (university_id => universities.id)
#
class University::Person::Involvement < ApplicationRecord
include WithPosition
belongs_to :university
belongs_to :person
belongs_to :target, polymorphic: true
enum kind: { administrator: 10, researcher: 20, teacher: 30 }
protected
def last_ordered_element
self.class.unscoped.where(university_id: university_id, target: target).ordered.last
end
end
......@@ -21,6 +21,14 @@
# fk_rails_... (university_id => universities.id)
#
class University::Role < ApplicationRecord
include WithPosition
belongs_to :university
belongs_to :target, polymorphic: true, optional: true
protected
def last_ordered_element
self.class.unscoped.where(university_id: university_id, target: target).ordered.last
end
end
......@@ -17,3 +17,44 @@ Ce modèle permet de lier une personne à une cible polymorphique. On définit a
Ce modèle sert pour les liens non intrinsèques. On crée un rôle au niveau d'une cible polymorphique, description et position, et possiblement un rôle parent pour définir la hiérarchie au sein d'un organigramme.
Ensuite, on connecte une personne à ce rôle en utilisant le modèle Involvement avec pour target, le rôle en question.
### Exemples
Soient :
- `mmi_program` : l'objet `Education::Program` représentant le BUT MMI
- `teacher` : l'objet `University::Person` représentant un enseignant
- `director` : l'objet `University::Person` représentant la cheffe de département
- `program_manager` : l'objet `University::Person` représentant le directeur des études
- `secretary` : l'objet `University::Person` représentant le secrétaire
Pour l'enseignant on crée un objet `University::Person::Involvement`:
- target: `mmi_program`
- person: `teacher`
- kind: teacher
Pour la cheffe de département on crée :
- Un objet `University::Role`, qu'on nomme `director_role`
- target: `mmi_program`
- description: "Cheffe de département"
- Un objet `University::Person::Involvement`
- target: `director_role`
- person: `director`
- kind: administrator
Pour le directeur des études on crée :
- Un objet `University::Role`, qu'on nomme `program_manager_role`
- target: `mmi_program`
- description: "Directeur des études"
- Un objet `University::Person::Involvement`
- target: `program_manager_role`
- person: `program_manager`
- kind: administrator
Pour le secrétaire on crée :
- Un objet `University::Role`, qu'on nomme `secretary_role`
- target: `mmi_program`
- description: "Secrétaire"
- Un objet `University::Person::Involvement`
- target: `secretary_role`
- person: `secretary`
- kind: administrator
......@@ -40,6 +40,50 @@ namespace :app do
imported_post.post&.update_column :published_at, imported_post.published_at
end
end
Education::Program::Teacher.find_each { |teacher|
involvement = University::Person::Involvement.where(
kind: 'teacher',
target: teacher.program,
person_id: teacher.person_id,
university_id: teacher.person.university_id
).first_or_create
involvement.update_column(:description, teacher.description)
}
Education::Program::Role.find_each { |program_role|
university_role = University::Role.where(
description: program_role.description,
target: program_role.program,
position: program_role.position,
university_id: program_role.university_id
).first_or_create
program_role.people.find_each { |role_person|
University::Person::Involvement.where(
kind: 'administrator',
target: university_role,
person_id: role_person.person_id,
position: role_person.position,
university_id: program_role.university_id
).first_or_create
}
}
Education::School::Administrator.find_each { |administrator|
university_role = University::Role.where(
description: administrator.description,
target: administrator.school,
university_id: administrator.person.university_id
).first_or_create
University::Person::Involvement.where(
kind: 'administrator',
target: university_role,
person_id: administrator.person_id,
university_id: administrator.person.university_id
).first_or_create
}
end
namespace :db do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment