Skip to content

Commit 08d36c5

Browse files
Update safeguarding flag call to match api changes (#400)
closes #399 --------- Co-authored-by: create-issue-branch[bot] <53036503+create-issue-branch[bot]@users.noreply.github.com> Co-authored-by: Dan Halson <[email protected]>
1 parent 34a5c63 commit 08d36c5

17 files changed

+57
-49
lines changed

.devcontainer/docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services:
33
build:
44
context: .
55
target: dev-container
6-
command: bash bin/dev-container-entrypoint.sh
6+
command: bash bin/docker-debug-entrypoint.sh
77
volumes:
88
# - ${HOME}/.bashrc:/root/.bashrc:ro # Map a ~/.bashrc in your home directory for customising bash
99
- ${HOME}/.ssh:/root/.ssh:ro # To share any ssh keys with the container
@@ -12,4 +12,3 @@ services:
1212

1313
volumes:
1414
node_modules: null
15-

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@
3939
/coverage
4040

4141
.byebug_history
42+
43+
docker-compose.override.yml

.vscode/launch.json

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
{
2-
// Use IntelliSense to learn about possible attributes.
3-
// Hover to view descriptions of existing attributes.
4-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
52
"version": "0.2.0",
63
"configurations": [
74
{
85
"type": "ruby_lsp",
6+
"name": "Debug",
97
"request": "launch",
10-
"name": "Debug program",
11-
"program": "ruby "
8+
"program": "ruby ${file}",
129
},
1310
{
14-
"type": "rdbg",
15-
"name": "Debug current file with rdbg",
11+
"type": "ruby_lsp",
1612
"request": "launch",
17-
"script": "${file}",
18-
"args": [],
19-
"askParameters": true
13+
"name": "Debug test file",
14+
"program": "ruby -Itest ${relativeFile}",
2015
},
2116
{
22-
"type": "rdbg",
23-
"name": "Attach with rdbg",
24-
"request": "attach"
25-
}
26-
]
17+
"type": "ruby_lsp",
18+
"request": "attach",
19+
"name": "Attach to existing server",
20+
},
21+
],
2722
}

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ gem 'sentry-rails'
3838

3939
group :development, :test do
4040
gem 'bullet'
41+
gem 'debug'
4142
gem 'dotenv-rails'
4243
gem 'factory_bot_rails'
4344
gem 'faker'

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ GEM
148148
database_cleaner-core (~> 2.0.0)
149149
database_cleaner-core (2.0.1)
150150
date (3.3.4)
151+
debug (1.9.2)
152+
irb (~> 1.10)
153+
reline (>= 0.3.8)
151154
diff-lcs (1.5.0)
152155
docile (1.4.0)
153156
dotenv (2.8.1)
@@ -515,6 +518,7 @@ DEPENDENCIES
515518
climate_control
516519
countries
517520
database_cleaner-active_record
521+
debug
518522
dotenv-rails
519523
email_validator
520524
factory_bot_rails

app/controllers/api/school_students_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def create_teacher_safeguarding_flag
7676

7777
ProfileApiClient.create_safeguarding_flag(
7878
token: current_user.token,
79-
flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher]
79+
flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher],
80+
email: current_user.email
8081
)
8182
end
8283

@@ -85,7 +86,8 @@ def create_owner_safeguarding_flag
8586

8687
ProfileApiClient.create_safeguarding_flag(
8788
token: current_user.token,
88-
flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner]
89+
flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner],
90+
email: current_user.email
8991
)
9092
end
9193
end

bin/dev-container-entrypoint.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

bin/docker-debug-entrypoint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rails db:prepare --trace
2+
rdbg -n -o -c -- bin/rails s -p 3009 -b '0.0.0.0'

db/seeds.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
if Rails.env.development?
66
Rake::Task['projects:create_all'].invoke
7-
Rake::Task['classroom_management:seed_a_school_with_lessons'].invoke
7+
Rake::Task['classroom_management:seed_a_school_with_lessons_and_students'].invoke
88
end

lib/profile_api_client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ def safeguarding_flags(token:)
153153
response.body.map { |flag| SafeguardingFlag.new(**flag.symbolize_keys) }
154154
end
155155

156-
def create_safeguarding_flag(token:, flag:)
156+
def create_safeguarding_flag(token:, flag:, email:)
157157
response = connection(token).post('/api/v1/safeguarding-flags') do |request|
158-
request.body = { flag: }
158+
request.body = { flag:, email: }
159159
end
160160

161161
raise UnexpectedResponse, response unless [201, 303].include?(response.status)

lib/tasks/classroom_management_helper.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
module ClassroomManagementHelper
44
TEST_USERS = {
5-
# Use this in conjunction with BYPASS_OAUTH=true to generate data for the bypass user
6-
bypass_oauth: '00000000-0000-0000-0000-000000000000',
75
jane_doe: '583ba872-b16e-46e1-9f7d-df89d267550d', # [email protected]
86
john_doe: 'bbb9b8fd-f357-4238-983d-6f87b99bdbb2', # [email protected]
97
jane_smith: 'e52de409-9210-4e94-b08c-dd11439e07d9', # student
108
john_smith: '0d488bec-b10d-46d3-b6f3-4cddf5d90c71' # student
119
}.freeze
1210

13-
TEST_SCHOOL = 'e52de409-9210-4e94-b08c-dd11439e07d9'
11+
# Match the school in profile...
12+
TEST_SCHOOL = 'e52de409-9210-4e94-b08c-dd11439e07d9' # e52de409-9210-4e94-b08c-dd11439e07d9
13+
SCHOOL_CODE = '12-12-12-12'
1414

1515
def create_school(creator_id, school_id = nil)
1616
School.find_or_create_by!(creator_id:, id: school_id) do |school|
@@ -30,6 +30,11 @@ def create_school(creator_id, school_id = nil)
3030
def verify_school(school)
3131
Rails.logger.info 'Verifying the school...'
3232
school.verify!
33+
34+
# rubocop:disable Rails/SkipsModelValidations
35+
school.update_column(:code, SCHOOL_CODE) # The code needs to match the one in the profile
36+
# rubocop:enable Rails/SkipsModelValidations
37+
3338
Role.owner.create!(user_id: school.creator_id, school:)
3439
Role.teacher.create!(user_id: school.creator_id, school:)
3540
end

spec/features/school_student/creating_a_batch_of_school_students_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
it 'creates the school owner safeguarding flag' do
2020
post("/api/schools/#{school.id}/students/batch", headers:, params: { file: })
21-
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner])
21+
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner], email: owner.email)
2222
end
2323

2424
it 'does not create the school teacher safeguarding flag' do
2525
post("/api/schools/#{school.id}/students/batch", headers:, params: { file: })
26-
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher])
26+
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher], email: owner.email)
2727
end
2828

2929
it 'responds 204 No Content' do
@@ -44,15 +44,15 @@
4444
authenticated_in_hydra_as(teacher)
4545

4646
post("/api/schools/#{school.id}/students/batch", headers:, params: { file: })
47-
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner])
47+
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner], email: owner.email)
4848
end
4949

5050
it 'creates the school teacher safeguarding flag when the user is a school-teacher' do
5151
teacher = create(:teacher, school:)
5252
authenticated_in_hydra_as(teacher)
5353

5454
post("/api/schools/#{school.id}/students/batch", headers:, params: { file: })
55-
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher])
55+
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher], email: teacher.email)
5656
end
5757

5858
it 'responds 422 Unprocessable Entity when params are invalid' do

spec/features/school_student/creating_a_school_student_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525

2626
it 'creates the school owner safeguarding flag' do
2727
post("/api/schools/#{school.id}/students", headers:, params:)
28-
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner])
28+
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner], email: owner.email)
2929
end
3030

3131
it 'does not create the school teacher safeguarding flag' do
3232
post("/api/schools/#{school.id}/students", headers:, params:)
33-
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher])
33+
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher], email: owner.email)
3434
end
3535

3636
it 'responds 204 No Content' do
@@ -51,15 +51,15 @@
5151
authenticated_in_hydra_as(teacher)
5252

5353
post("/api/schools/#{school.id}/students", headers:, params:)
54-
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner])
54+
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner], email: owner.email)
5555
end
5656

5757
it 'creates the school teacher safeguarding flag when the user is a school teacher' do
5858
teacher = create(:teacher, school:)
5959
authenticated_in_hydra_as(teacher)
6060

6161
post("/api/schools/#{school.id}/students", headers:, params:)
62-
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher])
62+
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher], email: teacher.email)
6363
end
6464

6565
it 'responds 400 Bad Request when params are missing' do

spec/features/school_student/deleting_a_school_student_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
it 'creates the school owner safeguarding flag' do
1818
delete("/api/schools/#{school.id}/students/#{student_id}", headers:)
19-
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner])
19+
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner], email: owner.email)
2020
end
2121

2222
it 'does not create the school teacher safeguarding flag' do
2323
delete("/api/schools/#{school.id}/students/#{student_id}", headers:)
24-
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher])
24+
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher], email: owner.email)
2525
end
2626

2727
it 'responds 204 No Content' do
@@ -55,15 +55,15 @@
5555
authenticated_in_hydra_as(teacher)
5656

5757
delete("/api/schools/#{school.id}/students/#{student_id}", headers:)
58-
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner])
58+
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner], email: owner.email)
5959
end
6060

6161
it 'does not create the school teacher safeguarding flag when logged in as a teacher' do
6262
teacher = create(:teacher, school:)
6363
authenticated_in_hydra_as(teacher)
6464

6565
delete("/api/schools/#{school.id}/students/#{student_id}", headers:)
66-
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher])
66+
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher], email: teacher.email)
6767
end
6868

6969
it 'responds 403 Forbidden when the user is a school-student' do

spec/features/school_student/listing_school_students_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323
it 'creates the school owner safeguarding flag' do
2424
get("/api/schools/#{school.id}/students", headers:)
25-
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner])
25+
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner], email: owner.email)
2626
end
2727

2828
it 'does not create the school teacher safeguarding flag' do
2929
get("/api/schools/#{school.id}/students", headers:)
30-
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher])
30+
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher], email: owner.email)
3131
end
3232

3333
it 'responds 200 OK when the user is a school-teacher' do
@@ -43,15 +43,15 @@
4343
authenticated_in_hydra_as(teacher)
4444

4545
get("/api/schools/#{school.id}/students", headers:)
46-
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner])
46+
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner], email: owner.email)
4747
end
4848

4949
it 'creates the school teacher safeguarding flag when the user is a school teacher' do
5050
teacher = create(:teacher, school:)
5151
authenticated_in_hydra_as(teacher)
5252

5353
get("/api/schools/#{school.id}/students", headers:)
54-
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher])
54+
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher], email: teacher.email)
5555
end
5656

5757
it 'responds with the school students JSON' do

spec/features/school_student/updating_a_school_student_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
it 'creates the school owner safeguarding flag' do
2828
put("/api/schools/#{school.id}/students/#{student_id}", headers:, params:)
29-
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner])
29+
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner], email: owner.email)
3030
end
3131

3232
it 'does not create the school teacher safeguarding flag' do
3333
put("/api/schools/#{school.id}/students/#{student_id}", headers:, params:)
34-
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher])
34+
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher], email: owner.email)
3535
end
3636

3737
it 'responds 204 No Content' do
@@ -52,15 +52,15 @@
5252
authenticated_in_hydra_as(teacher)
5353

5454
put("/api/schools/#{school.id}/students/#{student_id}", headers:, params:)
55-
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner])
55+
expect(ProfileApiClient).not_to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:owner], email: owner.email)
5656
end
5757

5858
it 'creates the school teacher safeguarding flag when the user is a school teacher' do
5959
teacher = create(:teacher, school:)
6060
authenticated_in_hydra_as(teacher)
6161

6262
put("/api/schools/#{school.id}/students/#{student_id}", headers:, params:)
63-
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher])
63+
expect(ProfileApiClient).to have_received(:create_safeguarding_flag).with(token: UserProfileMock::TOKEN, flag: ProfileApiClient::SAFEGUARDING_FLAGS[:teacher], email: teacher.email)
6464
end
6565

6666
it 'responds 401 Unauthorized when no token is given' do

spec/lib/profile_api_client_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def list_safeguarding_flags
246246

247247
it 'sends the safeguarding flag in the request body' do
248248
create_safeguarding_flag
249-
expect(WebMock).to have_requested(:post, create_safeguarding_flag_url).with(body: { flag: }.to_json)
249+
expect(WebMock).to have_requested(:post, create_safeguarding_flag_url).with(body: { flag:, email: '[email protected]' }.to_json)
250250
end
251251

252252
it 'returns empty body if created successfully' do
@@ -276,7 +276,7 @@ def list_safeguarding_flags
276276
end
277277

278278
def create_safeguarding_flag
279-
described_class.create_safeguarding_flag(token:, flag:)
279+
described_class.create_safeguarding_flag(token:, flag:, email: '[email protected]')
280280
end
281281
end
282282

0 commit comments

Comments
 (0)