ogam 1.1.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -12
- data/.rubocop_todo.yml +47 -2
- data/Gemfile +1 -1
- data/Rakefile +2 -2
- data/bin/ogam +46 -21
- data/lib/ogam.rb +10 -10
- data/lib/ogam/execute.rb +16 -13
- data/lib/ogam/group.rb +10 -4
- data/lib/ogam/group_assigner.rb +41 -40
- data/lib/ogam/job_title.rb +9 -9
- data/lib/ogam/organisation.rb +6 -6
- data/lib/ogam/signature.rb +5 -5
- data/lib/ogam/user.rb +1 -1
- data/lib/ogam/version.rb +1 -1
- data/ogam.gemspec +21 -21
- metadata +4 -5
- data/.rubocop_metrics_todo.yml +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b41adf475cb00cb57164e2bbb0e330d3b7d0401abd7725cc4ddc39325e2e8e9f
|
4
|
+
data.tar.gz: 8519c7e4f82dfcdd87e2efde8fa0651841984d136fe6f4853bf85e042e1bdf1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d05195e69269c8700c50806953046a7676b9f380658d2168292795759c6b5be139b594362313fe2e378e192a6f4d2e8fd71efa6d43375fed08339b2ebdd1da6
|
7
|
+
data.tar.gz: 4ac972b6caf6c6b3f37f1ebd37f47fb8e76b12526394aa8c9d00bdd8ca6b58b4902b54be22780d7750a1f67de35e6d69bb8669363929edd8f168ff42d4fa1f71
|
data/.rubocop.yml
CHANGED
@@ -1,24 +1,21 @@
|
|
1
1
|
inherit_from:
|
2
2
|
- .rubocop_todo.yml
|
3
|
-
- .rubocop_metrics_todo.yml
|
4
3
|
|
5
4
|
inherit_gem:
|
6
5
|
rubocop-ogat:
|
7
6
|
- config/default.yml
|
8
7
|
|
8
|
+
inherit_mode:
|
9
|
+
merge:
|
10
|
+
- 'Include'
|
11
|
+
|
9
12
|
AllCops:
|
10
13
|
TargetRubyVersion: 2.6
|
11
|
-
|
12
|
-
|
13
|
-
Max: 120
|
14
|
-
|
15
|
-
Metrics/BlockLength:
|
14
|
+
Include:
|
15
|
+
- 'bin/ogam'
|
16
16
|
Exclude:
|
17
|
-
- '
|
18
|
-
- '
|
19
|
-
|
20
|
-
Rails/Output:
|
21
|
-
Enabled: false
|
17
|
+
- 'bin/console'
|
18
|
+
- 'vendor/bundle/**/*'
|
22
19
|
|
23
|
-
Rails
|
20
|
+
Rails:
|
24
21
|
Enabled: false
|
data/.rubocop_todo.yml
CHANGED
@@ -1,7 +1,52 @@
|
|
1
1
|
# This configuration was generated by
|
2
|
-
# `rubocop --auto-gen-config --exclude-limit
|
3
|
-
# using RuboCop version 0.
|
2
|
+
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 10000 --no-offense-counts --no-auto-gen-timestamp`
|
3
|
+
# using RuboCop version 0.82.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Configuration parameters: IgnoredMethods, Max.
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Exclude:
|
12
|
+
- 'spec/**/*'
|
13
|
+
- 'db/migrate/*'
|
14
|
+
- 'config/routes.rb'
|
15
|
+
- 'config/environments/*.rb'
|
16
|
+
- 'lib/ogam/group_assigner.rb'
|
17
|
+
|
18
|
+
# Configuration parameters: CountComments, Max.
|
19
|
+
Metrics/ClassLength:
|
20
|
+
Exclude:
|
21
|
+
- 'spec/**/*'
|
22
|
+
- 'db/migrate/*'
|
23
|
+
- 'config/routes.rb'
|
24
|
+
- 'config/environments/*.rb'
|
25
|
+
- 'lib/ogam/group_assigner.rb'
|
26
|
+
|
27
|
+
# Configuration parameters: IgnoredMethods, Max.
|
28
|
+
Metrics/CyclomaticComplexity:
|
29
|
+
Exclude:
|
30
|
+
- 'spec/**/*'
|
31
|
+
- 'db/migrate/*'
|
32
|
+
- 'config/routes.rb'
|
33
|
+
- 'config/environments/*.rb'
|
34
|
+
- 'lib/ogam/group_assigner.rb'
|
35
|
+
|
36
|
+
# Configuration parameters: CountComments, Max, ExcludedMethods.
|
37
|
+
Metrics/MethodLength:
|
38
|
+
Exclude:
|
39
|
+
- 'spec/**/*'
|
40
|
+
- 'db/migrate/*'
|
41
|
+
- 'config/routes.rb'
|
42
|
+
- 'config/environments/*.rb'
|
43
|
+
- 'lib/ogam/group_assigner.rb'
|
44
|
+
|
45
|
+
# Configuration parameters: IgnoredMethods, Max.
|
46
|
+
Metrics/PerceivedComplexity:
|
47
|
+
Exclude:
|
48
|
+
- 'spec/**/*'
|
49
|
+
- 'db/migrate/*'
|
50
|
+
- 'config/routes.rb'
|
51
|
+
- 'config/environments/*.rb'
|
52
|
+
- 'lib/ogam/group_assigner.rb'
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/ogam
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
4
|
+
require "bundler/setup"
|
5
|
+
require "ogam"
|
6
|
+
require "thor"
|
7
|
+
require "shellwords"
|
8
8
|
|
9
9
|
# Signature subcommand cli
|
10
10
|
class SignatureCLI < Thor
|
11
|
-
desc(
|
11
|
+
desc("user EMAIL", "Sets the signature for user with primary email EMAIL based on their name, job title, and org")
|
12
12
|
def user(email)
|
13
13
|
set_signatures(Ogam::User.active_by_email(email), pretend: parent_options[:pretend])
|
14
14
|
end
|
15
15
|
|
16
|
-
desc(
|
16
|
+
desc("domain DOMAIN", "Sets the signature for all users @DOMAIN based on their name, job title, and org")
|
17
17
|
def domain(domain)
|
18
18
|
set_signatures(Ogam::User.active_for_domain(domain), pretend: parent_options[:pretend])
|
19
19
|
end
|
@@ -32,38 +32,38 @@ class CLI < Thor
|
|
32
32
|
class_option :pretend, type: :boolean, default: false
|
33
33
|
|
34
34
|
desc(
|
35
|
-
|
36
|
-
|
35
|
+
"assign_to_standard_groups DOMAIN_OR_EMAIL",
|
36
|
+
"Assigns users at DOMAIN (e.g. newbold.outwood.com) or EMAIL address to standard groups based on their job title"
|
37
37
|
)
|
38
38
|
def assign_to_standard_groups(domain_or_email)
|
39
|
-
method = domain_or_email.include?(
|
39
|
+
method = domain_or_email.include?("@") ? :for_user : :for_domain
|
40
40
|
Ogam::GroupAssigner.public_send(method, domain_or_email, pretend: options[:pretend])
|
41
41
|
end
|
42
42
|
|
43
43
|
desc(
|
44
|
-
|
45
|
-
|
44
|
+
"populate_titles_and_orgs PATH_TO_CSV",
|
45
|
+
"Populates job titles and organisation names from a CSV with columns primary_email, job_title, organisation"
|
46
46
|
)
|
47
47
|
def populate_titles_and_orgs(csv_path)
|
48
48
|
Ogam::Execute.csv_command(
|
49
49
|
csv_path,
|
50
|
-
|
50
|
+
"gam update user ~primary_email organization name ~organisation title ~job_title primary",
|
51
51
|
pretend: options[:pretend]
|
52
52
|
)
|
53
53
|
end
|
54
54
|
|
55
|
-
desc(
|
55
|
+
desc("create_shared_mailbox EMAIL NAME", "Create a shared mailbox")
|
56
56
|
def create_shared_mailbox(email, name)
|
57
57
|
Ogam::Execute.single(Ogam::Group.create_shared_mailbox_command(email, name), pretend: options[:pretend])
|
58
58
|
end
|
59
59
|
|
60
|
-
desc(
|
60
|
+
desc("create_exec_mailbox EMAIL NAME", "Create an Exec mailbox")
|
61
61
|
def create_exec_mailbox(email, name)
|
62
62
|
Ogam::Execute.single(Ogam::Group.create_exec_mailbox_command(email, name), pretend: options[:pretend])
|
63
63
|
end
|
64
64
|
|
65
65
|
option :moderated, type: :boolean, default: false
|
66
|
-
desc(
|
66
|
+
desc("create_group EMAIL NAME [--moderated]", "Create a distribution list group, optionally moderated")
|
67
67
|
def create_group(email, name)
|
68
68
|
Ogam::Execute.single(
|
69
69
|
Ogam::Group.create_distribution_list_command(email, name, options[:moderated]), pretend: options[:pretend]
|
@@ -72,8 +72,8 @@ class CLI < Thor
|
|
72
72
|
|
73
73
|
option :organisation, type: :string
|
74
74
|
desc(
|
75
|
-
|
76
|
-
|
75
|
+
"set_job_title EMAIL TITLE [--organisation ORG_NAME]",
|
76
|
+
"Sets job title for a user, and updates their signature, groups, and organisation name. Optionally override org."
|
77
77
|
)
|
78
78
|
def set_job_title(email, title)
|
79
79
|
validate_job_title!(title)
|
@@ -85,8 +85,33 @@ class CLI < Thor
|
|
85
85
|
set_title_and_org_and_make_changes(email, title, org, pretend: options[:pretend])
|
86
86
|
end
|
87
87
|
|
88
|
-
desc(
|
89
|
-
|
88
|
+
desc(
|
89
|
+
"add_send_as USER GROUP NAME TITLE ORG_NAME",
|
90
|
+
"Adds a sendas address to USER to be able to send as GROUP, and sets the NAME, and signature for sending"
|
91
|
+
)
|
92
|
+
def add_send_as(user, group, name, title, org_name)
|
93
|
+
signature_html = Ogam::Signature.signature_html(name, title, org_name)
|
94
|
+
Ogam::Execute.single(Ogam::Group.add_send_as_command(user, group, name, signature_html), pretend: options[:pretend])
|
95
|
+
end
|
96
|
+
|
97
|
+
desc("set_signature user/domain EMAIL/DOMAIN", "Set email signatures for users/domains based on user attributes")
|
98
|
+
subcommand "set_signature", SignatureCLI
|
99
|
+
|
100
|
+
desc("delicense_suspended_ou", "De-licenses GSEfE from all users under /Suspended")
|
101
|
+
def delicense_suspended_ou
|
102
|
+
Ogam::Execute.single('gam ou "/Suspended" delete license 1010310002', pretend: options[:pretend])
|
103
|
+
end
|
104
|
+
|
105
|
+
desc("offboard USER", "Suspends a user, moves them to /Suspended, removes from groups, and delicenses GSEfE")
|
106
|
+
def offboard(user)
|
107
|
+
Ogam::Execute.single(
|
108
|
+
"gam update user #{user} suspended on org \"/Suspended\"", pretend: options[:pretend]
|
109
|
+
)
|
110
|
+
Ogam::Execute.single("gam user #{user} delete groups", pretend: options[:pretend])
|
111
|
+
puts "Waiting 5 seconds before delicensing..."
|
112
|
+
sleep(5)
|
113
|
+
Ogam::Execute.single("gam user #{user} delete license 1010310002", pretend: options[:pretend])
|
114
|
+
end
|
90
115
|
|
91
116
|
private
|
92
117
|
|
@@ -99,7 +124,7 @@ class CLI < Thor
|
|
99
124
|
end
|
100
125
|
|
101
126
|
def validate_organisation!(org, approved_organisations)
|
102
|
-
org.split(
|
127
|
+
org.split(" / ").each do |org_part|
|
103
128
|
unless approved_organisations.value?(org_part)
|
104
129
|
raise ArgumentError, "'#{org_part}' is not an approved organisation name."
|
105
130
|
end
|
@@ -109,7 +134,7 @@ class CLI < Thor
|
|
109
134
|
def infer_organisation_if_necessary(org, email, approved_organisations)
|
110
135
|
return org if org.present?
|
111
136
|
|
112
|
-
approved_organisations.fetch(email.split(
|
137
|
+
approved_organisations.fetch(email.split("@").last, "")
|
113
138
|
end
|
114
139
|
|
115
140
|
def set_title_and_org_and_make_changes(email, title, org, pretend: true)
|
data/lib/ogam.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
3
|
+
require "active_support/all"
|
4
|
+
require "attr_extras"
|
5
|
+
require "ogam/version"
|
6
|
+
require "ogam/execute"
|
7
|
+
require "ogam/group"
|
8
|
+
require "ogam/job_title"
|
9
|
+
require "ogam/user"
|
10
|
+
require "ogam/group_assigner"
|
11
|
+
require "ogam/signature"
|
12
|
+
require "ogam/organisation"
|
13
13
|
|
14
14
|
module Ogam
|
15
15
|
class Error < StandardError; end
|
data/lib/ogam/execute.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "csv"
|
4
|
+
require "tempfile"
|
5
|
+
require "English"
|
6
6
|
|
7
7
|
module Ogam
|
8
8
|
# Methods to execute GAM commands
|
9
9
|
class Execute
|
10
10
|
def self.single(command, pretend: true)
|
11
|
-
puts "#{pretend ?
|
11
|
+
puts "#{pretend ? "[PRETEND] " : nil}Executing #{command}"
|
12
12
|
return if pretend
|
13
13
|
|
14
|
-
system("~/bin/gam/#{command}", exception: true)
|
14
|
+
system("~/bin/gam/#{command.strip}", exception: true)
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.fetch(command, pretend: true)
|
18
|
-
puts "#{pretend ?
|
18
|
+
puts "#{pretend ? "[PRETEND] " : nil}Fetching results from #{command}"
|
19
19
|
return if pretend
|
20
20
|
|
21
|
-
`~/bin/gam/#{command}`
|
21
|
+
`~/bin/gam/#{command.strip}`
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.fetch_csv(command, pretend: true)
|
@@ -29,22 +29,25 @@ module Ogam
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.csv_command(csv_path, command, pretend: true)
|
32
|
-
single("gam csv #{Shellwords.escape(csv_path)} #{command}", pretend: pretend)
|
32
|
+
single("gam csv #{Shellwords.escape(csv_path)} #{command.strip}", pretend: pretend)
|
33
33
|
end
|
34
34
|
|
35
|
+
# rubocop:disable Metrics/MethodLength
|
35
36
|
def self.multiple(commands, pretend: true)
|
36
37
|
return if commands.empty?
|
37
38
|
|
38
|
-
puts "#{pretend ?
|
39
|
+
puts "#{pretend ? "[PRETEND] " : nil}Executing multiple commands:"
|
39
40
|
commands.each do |command|
|
40
41
|
puts "\t#{command}"
|
41
42
|
end
|
42
43
|
return if pretend
|
43
44
|
|
44
|
-
Tempfile.
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
f = Tempfile.new
|
46
|
+
commands.each { |command| f.puts command.strip }
|
47
|
+
f.close
|
48
|
+
single("gam batch #{f.path}", pretend: pretend)
|
49
|
+
f.unlink
|
48
50
|
end
|
51
|
+
# rubocop:enable Metrics/MethodLength
|
49
52
|
end
|
50
53
|
end
|
data/lib/ogam/group.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "shellwords"
|
4
4
|
module Ogam
|
5
5
|
# Methods relating to groups
|
6
6
|
class Group
|
7
7
|
def self.groups_for_domain(domain)
|
8
|
-
Ogam::Execute.fetch_csv("gam print groups domain #{domain}", pretend: false).map { |r| r[
|
8
|
+
Ogam::Execute.fetch_csv("gam print groups domain #{domain}", pretend: false).map { |r| r["Email"] }
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.add_group_member_command(user:, group:)
|
12
|
-
"gam update group #{group} add member user #{user}"
|
12
|
+
"gam update group #{group} add member user #{Shellwords.escape(user)}"
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.create_shared_mailbox_command(email_address, name)
|
@@ -26,7 +26,13 @@ module Ogam
|
|
26
26
|
|
27
27
|
def self.create_distribution_list_command(email_address, name, moderated)
|
28
28
|
<<~COMMAND
|
29
|
-
gam create group #{email_address} name #{Shellwords.escape(name)} allow_external_members false who_can_join invited_can_join primary_language en-GB who_can_view_membership all_in_domain_can_view include_in_global_address_list true is_archived false members_can_post_as_the_group false allow_web_posting false send_message_deny_notification true reply_to reply_to_sender message_moderation_level #{moderated ?
|
29
|
+
gam create group #{email_address} name #{Shellwords.escape(name)} allow_external_members false who_can_join invited_can_join primary_language en-GB who_can_view_membership all_in_domain_can_view include_in_global_address_list true is_archived false members_can_post_as_the_group false allow_web_posting false send_message_deny_notification true reply_to reply_to_sender message_moderation_level #{moderated ? "moderate_all_messages" : "moderate_none"} who_can_contact_owner all_managers_can_contact who_can_leave_group none_can_leave who_can_add none_can_add who_can_post_message all_in_domain_can_post who_can_invite none_can_invite who_can_view_group all_managers_can_view show_in_group_directory true archive_only false spam_moderation_level moderate
|
30
|
+
COMMAND
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.add_send_as_command(user_email, group_email, name, signature_html)
|
34
|
+
<<~COMMAND
|
35
|
+
gam user #{user_email} sendas #{group_email} #{Shellwords.escape(name)} treatasalias false signature "#{signature_html}"
|
30
36
|
COMMAND
|
31
37
|
end
|
32
38
|
end
|
data/lib/ogam/group_assigner.rb
CHANGED
@@ -5,28 +5,28 @@ module Ogam
|
|
5
5
|
class GroupAssigner
|
6
6
|
static_facade :call, :users, :domain, [pretend: true]
|
7
7
|
|
8
|
-
SUBJECT_TEACHER_TITLES = [
|
8
|
+
SUBJECT_TEACHER_TITLES = ["Teacher of ", "Head of ", "Second in ", "Third in "].freeze
|
9
9
|
SUBJECT_MAPPING = {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
10
|
+
"art-teachers" => ["Art", "Creative Arts"],
|
11
|
+
"business-teachers" => ["Business Studies", "Business & IT"],
|
12
|
+
"dance-teachers" => ["Dance", "Performing Arts", "Creative Arts"],
|
13
|
+
"design-technology-teachers" => %w[Technology Engineering],
|
14
|
+
"drama-teachers" => ["Drama", "Music & Drama", "Performing Arts", "Creative Arts"],
|
15
|
+
"english-teachers" => ["English"],
|
16
|
+
"epq-teachers" => [],
|
17
|
+
"geography-teachers" => ["Humanities"],
|
18
|
+
"guidance-teachers" => [],
|
19
|
+
"health-social-care-teachers" => ["Health & Social Care"],
|
20
|
+
"history-teachers" => %w[Humanities History],
|
21
|
+
"ict-teachers" => ["Computer Science", "Business & IT"],
|
22
|
+
"law-teachers" => ["Law"],
|
23
|
+
"maths-teachers" => ["Maths"],
|
24
|
+
"mfl-teachers" => ["MFL"],
|
25
|
+
"music-teachers" => ["Music", "Music & Drama", "Creative Arts"],
|
26
|
+
"pe-teachers" => ["PE"],
|
27
|
+
"re-life-teachers" => ["Humanities", "Religious Studies"],
|
28
|
+
"science-teachers" => ["Science"],
|
29
|
+
"social-sciences-teachers" => ["Social Sciences"]
|
30
30
|
}.freeze
|
31
31
|
|
32
32
|
def self.for_domain(domain, pretend: true)
|
@@ -34,37 +34,38 @@ module Ogam
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.for_user(email, pretend: true)
|
37
|
-
call(User.active_by_email(email), email.split(
|
37
|
+
call(User.active_by_email(email), email.split("@").last, pretend: pretend)
|
38
38
|
end
|
39
39
|
|
40
40
|
def self.groups_for_job_title(job_title, entry, domain)
|
41
41
|
groups_domain = "groups.#{domain}"
|
42
42
|
|
43
43
|
groups = groups_from_entry(entry, groups_domain)
|
44
|
-
groups += subject_groups(job_title, groups_domain) if entry[
|
44
|
+
groups += subject_groups(job_title, groups_domain) if entry["Teaching"]
|
45
45
|
|
46
|
-
groups << "heads-of-departments@#{groups_domain}" if entry[
|
47
|
-
groups << "principal@#{groups_domain}" if entry[
|
46
|
+
groups << "heads-of-departments@#{groups_domain}" if entry["Teaching"] && job_title.include?("Head of ")
|
47
|
+
groups << "principal@#{groups_domain}" if entry["SLT"] && ["Principal", "Acting Principal"].include?(job_title)
|
48
48
|
|
49
|
-
groups << "learning-managers@#{groups_domain}" if job_title.include?(
|
50
|
-
groups << "academy-council@#{groups_domain}" if job_title.include?(
|
51
|
-
groups <<
|
49
|
+
groups << "learning-managers@#{groups_domain}" if job_title.include?("Learning Manager")
|
50
|
+
groups << "academy-council@#{groups_domain}" if job_title.include?("Academy Council")
|
51
|
+
groups << "learning-support@#{groups_domain}" if job_title.include?("Teaching Assistant")
|
52
|
+
groups << "business-managers@trust-wide.outwood.com" if job_title == "Business Manager"
|
52
53
|
|
53
54
|
groups
|
54
55
|
end
|
55
56
|
|
56
57
|
def self.groups_from_entry(entry, groups_domain)
|
57
|
-
groups = []
|
58
|
-
groups << "teaching-staff@#{groups_domain}" if entry[
|
59
|
-
groups << "support-staff@#{groups_domain}" if entry[
|
60
|
-
if entry[
|
58
|
+
groups = ["all-staff-direct@trust-wide.outwood.com"]
|
59
|
+
groups << "teaching-staff@#{groups_domain}" if entry["Teaching"]
|
60
|
+
groups << "support-staff@#{groups_domain}" if entry["Support"]
|
61
|
+
if entry["SLT"]
|
61
62
|
groups << "slt@#{groups_domain}"
|
62
63
|
groups << "leadership-team@#{groups_domain}"
|
63
64
|
end
|
64
|
-
groups <<
|
65
|
-
groups <<
|
66
|
-
groups <<
|
67
|
-
groups <<
|
65
|
+
groups << "finance@trust-wide.outwood.com" if entry["Finance"]
|
66
|
+
groups << "data-exams@trust-wide.outwood.com" if entry["Data and Exams"]
|
67
|
+
groups << "human-resources@trust-wide.outwood.com" if entry["HR"]
|
68
|
+
groups << "ict-support@trust-wide.outwood.com" if entry["ICT Support"]
|
68
69
|
groups
|
69
70
|
end
|
70
71
|
|
@@ -74,9 +75,9 @@ module Ogam
|
|
74
75
|
groups = []
|
75
76
|
SUBJECT_MAPPING.each do |group_prefix, subject_words|
|
76
77
|
has_subject =
|
77
|
-
subject_words.any?
|
78
|
+
subject_words.any? { |subject|
|
78
79
|
SUBJECT_TEACHER_TITLES.any? { |title| job_title.include? "#{title}#{subject}" }
|
79
|
-
|
80
|
+
}
|
80
81
|
next unless has_subject
|
81
82
|
|
82
83
|
groups << "#{group_prefix}@#{groups_domain}"
|
@@ -97,7 +98,7 @@ module Ogam
|
|
97
98
|
end
|
98
99
|
|
99
100
|
def valid_groups
|
100
|
-
@valid_groups ||= Group.groups_for_domain("groups.#{domain}") + Group.groups_for_domain(
|
101
|
+
@valid_groups ||= Group.groups_for_domain("groups.#{domain}") + Group.groups_for_domain("trust-wide.outwood.com")
|
101
102
|
end
|
102
103
|
|
103
104
|
def generate_group_assignments
|
@@ -110,7 +111,7 @@ module Ogam
|
|
110
111
|
|
111
112
|
def group_assignments_for_user(user)
|
112
113
|
group_assignments = []
|
113
|
-
email = user[
|
114
|
+
email = user["primaryEmail"]
|
114
115
|
User.job_titles_for_user(user).each do |job_title|
|
115
116
|
entry = approved_job_titles.fetch(job_title, nil)
|
116
117
|
if entry.nil?
|
data/lib/ogam/job_title.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "open-uri"
|
4
|
+
require "csv"
|
5
5
|
|
6
6
|
module Ogam
|
7
7
|
# Allows working with a list of approved job titles
|
8
8
|
class JobTitle
|
9
9
|
static_facade :all
|
10
10
|
|
11
|
-
CSV_URL =
|
11
|
+
CSV_URL = "https://docs.google.com/spreadsheets/d/12nl5OBGSmOSsWilzWfflmAHO-8EyfCjVXYLeUDqjB60/export?format=csv&id=12nl5OBGSmOSsWilzWfflmAHO-8EyfCjVXYLeUDqjB60&gid=1604665254"
|
12
12
|
|
13
13
|
def self.job_titles(str)
|
14
14
|
return [] if str.blank?
|
15
15
|
|
16
|
-
str.split(
|
16
|
+
str.split(" / ")
|
17
17
|
end
|
18
18
|
|
19
19
|
def all
|
@@ -23,16 +23,16 @@ module Ogam
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def download
|
26
|
-
puts
|
26
|
+
puts "Fetching list of accepted job titles"
|
27
27
|
URI.parse(CSV_URL).read
|
28
28
|
end
|
29
29
|
|
30
30
|
def parse(str)
|
31
31
|
data = {}
|
32
32
|
CSV.parse(str, headers: true).each do |row|
|
33
|
-
next if row[
|
33
|
+
next if row["Job Title"].blank?
|
34
34
|
|
35
|
-
data[row[
|
35
|
+
data[row["Job Title"]] = entry_for_row(row)
|
36
36
|
end
|
37
37
|
|
38
38
|
data
|
@@ -40,8 +40,8 @@ module Ogam
|
|
40
40
|
|
41
41
|
def entry_for_row(row)
|
42
42
|
entry = {}
|
43
|
-
(row.headers - [
|
44
|
-
entry[col] = row[col] ==
|
43
|
+
(row.headers - ["Job Title"]).each do |col|
|
44
|
+
entry[col] = row[col] == "TRUE"
|
45
45
|
end
|
46
46
|
entry
|
47
47
|
end
|
data/lib/ogam/organisation.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "open-uri"
|
4
|
+
require "csv"
|
5
5
|
|
6
6
|
module Ogam
|
7
7
|
# Allows working with a list of approved organisations
|
8
8
|
class Organisation
|
9
9
|
static_facade :all
|
10
10
|
|
11
|
-
CSV_URL =
|
11
|
+
CSV_URL = "https://docs.google.com/spreadsheets/d/12nl5OBGSmOSsWilzWfflmAHO-8EyfCjVXYLeUDqjB60/export?format=csv&id=12nl5OBGSmOSsWilzWfflmAHO-8EyfCjVXYLeUDqjB60&gid=46181347"
|
12
12
|
|
13
13
|
def all
|
14
14
|
@all ||= parse(download)
|
@@ -17,16 +17,16 @@ module Ogam
|
|
17
17
|
private
|
18
18
|
|
19
19
|
def download
|
20
|
-
puts
|
20
|
+
puts "Fetching list of accepted organisations"
|
21
21
|
URI.parse(CSV_URL).read
|
22
22
|
end
|
23
23
|
|
24
24
|
def parse(str)
|
25
25
|
data = {}
|
26
26
|
CSV.parse(str, headers: true).each do |row|
|
27
|
-
next if row[
|
27
|
+
next if row["Domain"].blank?
|
28
28
|
|
29
|
-
data[row[
|
29
|
+
data[row["Domain"].strip] = row["Organisation Name"].strip
|
30
30
|
end
|
31
31
|
|
32
32
|
data
|
data/lib/ogam/signature.rb
CHANGED
@@ -4,11 +4,11 @@ module Ogam
|
|
4
4
|
# Methods relating to signatures
|
5
5
|
class Signature
|
6
6
|
def self.update_signature_command(user)
|
7
|
-
email = user.fetch(
|
7
|
+
email = user.fetch("primaryEmail")
|
8
8
|
html = signature_html(
|
9
|
-
user.fetch(
|
10
|
-
user.fetch(
|
11
|
-
user.fetch(
|
9
|
+
user.fetch("name.fullName", nil),
|
10
|
+
user.fetch("organizations.0.title", nil),
|
11
|
+
user.fetch("organizations.0.name", nil)
|
12
12
|
)
|
13
13
|
|
14
14
|
"gam user #{email} signature \"#{html}\""
|
@@ -16,7 +16,7 @@ module Ogam
|
|
16
16
|
|
17
17
|
def self.signature_html(name, job_title, organisation)
|
18
18
|
parts = [name, job_title, organisation].reject(&:blank?)
|
19
|
-
"<p>#{parts.join(
|
19
|
+
"<p>#{parts.join("<br />")}</p><hr color=#5b3293 />"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/ogam/user.rb
CHANGED
data/lib/ogam/version.rb
CHANGED
data/ogam.gemspec
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
5
|
+
require "ogam/version"
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name
|
9
|
-
spec.version
|
10
|
-
spec.authors
|
11
|
-
spec.email
|
8
|
+
spec.name = "ogam"
|
9
|
+
spec.version = Ogam::VERSION
|
10
|
+
spec.authors = ["Elliot Bowes"]
|
11
|
+
spec.email = ["e.bowes@outwood.com"]
|
12
12
|
|
13
|
-
spec.summary
|
13
|
+
spec.summary = "Wrapper around GAM for common tasks with OGAT's G Suite instance."
|
14
14
|
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
15
|
-
spec.homepage
|
16
|
-
spec.metadata[
|
17
|
-
spec.metadata[
|
15
|
+
spec.homepage = "https://github.com/Outwood/ogam"
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/Outwood/ogam"
|
18
18
|
|
19
19
|
# Specify which files should be added to the gem when it is released.
|
20
20
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -22,17 +22,17 @@ Gem::Specification.new do |spec|
|
|
22
22
|
Dir.chdir(File.expand_path(__dir__)) do
|
23
23
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
24
|
end
|
25
|
-
spec.bindir =
|
26
|
-
spec.executables <<
|
27
|
-
spec.require_paths = [
|
25
|
+
spec.bindir = "bin"
|
26
|
+
spec.executables << "ogam"
|
27
|
+
spec.require_paths = ["lib"]
|
28
28
|
|
29
|
-
spec.add_runtime_dependency
|
30
|
-
spec.add_runtime_dependency
|
31
|
-
spec.add_runtime_dependency
|
29
|
+
spec.add_runtime_dependency "activesupport", "~> 6.0.2"
|
30
|
+
spec.add_runtime_dependency "attr_extras", "~> 6.2.3"
|
31
|
+
spec.add_runtime_dependency "thor", "~> 1.0.1"
|
32
32
|
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
36
|
-
spec.add_development_dependency
|
37
|
-
spec.add_development_dependency
|
33
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
34
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_development_dependency "rubocop-ogat", "~> 2.6.0"
|
37
|
+
spec.add_development_dependency "simplecov", "~> 0.18.4"
|
38
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ogam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elliot Bowes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 2.6.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 2.6.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: simplecov
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,7 +133,6 @@ files:
|
|
133
133
|
- ".gitignore"
|
134
134
|
- ".rspec"
|
135
135
|
- ".rubocop.yml"
|
136
|
-
- ".rubocop_metrics_todo.yml"
|
137
136
|
- ".rubocop_todo.yml"
|
138
137
|
- ".ruby-version"
|
139
138
|
- ".travis.yml"
|
data/.rubocop_metrics_todo.yml
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
Metrics/AbcSize:
|
2
|
-
Exclude:
|
3
|
-
- db/**/*
|
4
|
-
- spec/**/*
|
5
|
-
- config/routes.rb
|
6
|
-
- lib/ogam/group_assigner.rb
|
7
|
-
|
8
|
-
Metrics/BlockLength:
|
9
|
-
Exclude:
|
10
|
-
- db/**/*
|
11
|
-
- spec/**/*
|
12
|
-
- config/routes.rb
|
13
|
-
|
14
|
-
Metrics/BlockNesting:
|
15
|
-
Exclude:
|
16
|
-
- db/**/*
|
17
|
-
- spec/**/*
|
18
|
-
- config/routes.rb
|
19
|
-
|
20
|
-
Metrics/ClassLength:
|
21
|
-
Exclude:
|
22
|
-
- db/**/*
|
23
|
-
- spec/**/*
|
24
|
-
- config/routes.rb
|
25
|
-
- lib/ogam/group_assigner.rb
|
26
|
-
|
27
|
-
Metrics/CyclomaticComplexity:
|
28
|
-
Exclude:
|
29
|
-
- db/**/*
|
30
|
-
- spec/**/*
|
31
|
-
- config/routes.rb
|
32
|
-
- lib/ogam/group_assigner.rb
|
33
|
-
|
34
|
-
Metrics/MethodLength:
|
35
|
-
Exclude:
|
36
|
-
- db/**/*
|
37
|
-
- spec/**/*
|
38
|
-
- config/routes.rb
|
39
|
-
- lib/ogam/group_assigner.rb
|
40
|
-
|
41
|
-
Metrics/ModuleLength:
|
42
|
-
Exclude:
|
43
|
-
- db/**/*
|
44
|
-
- spec/**/*
|
45
|
-
- config/routes.rb
|
46
|
-
|
47
|
-
Metrics/ParameterLists:
|
48
|
-
Exclude:
|
49
|
-
- db/**/*
|
50
|
-
- spec/**/*
|
51
|
-
- config/routes.rb
|
52
|
-
|
53
|
-
Metrics/PerceivedComplexity:
|
54
|
-
Exclude:
|
55
|
-
- db/**/*
|
56
|
-
- spec/**/*
|
57
|
-
- config/routes.rb
|
58
|
-
- lib/ogam/group_assigner.rb
|
59
|
-
|