Class: Ogam::GroupAssigner

Inherits:
Object
  • Object
show all
Defined in:
lib/ogam/group_assigner.rb

Overview

Assign users from a domain to standard groups based on their job titles

Constant Summary collapse

SUBJECT_TEACHER_TITLES =
["Teacher of ", "Head of ", "Second in ", "Third in "].freeze
SUBJECT_MAPPING =
{
  "art-teachers" => ["Art", "Creative Arts"],
  "business-teachers" => ["Business Studies", "Business & IT"],
  "dance-teachers" => ["Dance", "Performing Arts", "Creative Arts"],
  "design-technology-teachers" => %w[Technology Engineering],
  "drama-teachers" => ["Drama", "Music & Drama", "Performing Arts", "Creative Arts"],
  "english-teachers" => ["English"],
  "epq-teachers" => [],
  "geography-teachers" => ["Humanities"],
  "guidance-teachers" => [],
  "health-social-care-teachers" => ["Health & Social Care"],
  "history-teachers" => %w[Humanities History],
  "ict-teachers" => ["Computer Science", "Business & IT"],
  "law-teachers" => ["Law"],
  "maths-teachers" => ["Maths"],
  "mfl-teachers" => ["MFL"],
  "music-teachers" => ["Music", "Music & Drama", "Creative Arts"],
  "pe-teachers" => ["PE"],
  "re-life-teachers" => ["Humanities", "Religious Studies"],
  "science-teachers" => ["Science"],
  "social-sciences-teachers" => ["Social Sciences"]
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_domain(domain, pretend: true) ⇒ Object



32
33
34
# File 'lib/ogam/group_assigner.rb', line 32

def self.for_domain(domain, pretend: true)
  call(User.active_for_domain(domain), domain, pretend: pretend)
end

.for_user(email, pretend: true) ⇒ Object



36
37
38
# File 'lib/ogam/group_assigner.rb', line 36

def self.for_user(email, pretend: true)
  call(User.active_by_email(email), email.split("@").last, pretend: pretend)
end

.groups_for_job_title(job_title, entry, domain) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ogam/group_assigner.rb', line 40

def self.groups_for_job_title(job_title, entry, domain)
  groups_domain = "groups.#{domain}"

  groups = groups_from_entry(entry, groups_domain)
  groups += subject_groups(job_title, groups_domain) if entry["Teaching"]

  groups << "heads-of-departments@#{groups_domain}" if entry["Teaching"] && job_title.include?("Head of ")
  groups << "principal@#{groups_domain}" if entry["SLT"] && ["Principal", "Acting Principal"].include?(job_title)

  groups << "learning-managers@#{groups_domain}" if job_title.include?("Learning Manager")
  groups << "academy-council@#{groups_domain}" if job_title.include?("Academy Council")
  groups << "learning-support@#{groups_domain}" if job_title.include?("Teaching Assistant")
  groups << "[email protected]" if job_title == "Business Manager"

  groups
end

.groups_from_entry(entry, groups_domain) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ogam/group_assigner.rb', line 57

def self.groups_from_entry(entry, groups_domain)
  groups = ["[email protected]"]
  groups << "teaching-staff@#{groups_domain}" if entry["Teaching"]
  groups << "support-staff@#{groups_domain}" if entry["Support"]
  if entry["SLT"]
    groups << "slt@#{groups_domain}"
    groups << "leadership-team@#{groups_domain}"
  end
  groups << "[email protected]" if entry["Finance"]
  groups << "[email protected]" if entry["Data and Exams"]
  groups << "[email protected]" if entry["HR"]
  groups << "[email protected]" if entry["ICT Support"]
  groups
end

.subject_groups(job_title, groups_domain) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ogam/group_assigner.rb', line 72

def self.subject_groups(job_title, groups_domain)
  return [] unless SUBJECT_TEACHER_TITLES.any? { |title| job_title.include?(title) }

  groups = []
  SUBJECT_MAPPING.each do |group_prefix, subject_words|
    has_subject =
      subject_words.any? { |subject|
        SUBJECT_TEACHER_TITLES.any? { |title| job_title.include? "#{title}#{subject}" }
      }
    next unless has_subject

    groups << "#{group_prefix}@#{groups_domain}"
  end
  groups
end

Instance Method Details

#callObject



88
89
90
# File 'lib/ogam/group_assigner.rb', line 88

def call
  Execute.multiple(commands(generate_group_assignments), pretend: pretend)
end