Skip to content

Commit 9708aec

Browse files
authored
Merge branch 'main' into 1532_robust-auth-header-parsing
2 parents c884142 + 961e2a5 commit 9708aec

6 files changed

Lines changed: 78 additions & 28 deletions

File tree

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ group :test do
8383
gem 'climate_control'
8484
gem 'database_cleaner-active_record'
8585
gem 'selenium-webdriver'
86-
gem 'shoulda-matchers', '~> 7.0'
86+
gem 'shoulda-matchers', '~> 8.0'
8787
gem 'webdrivers'
8888
gem 'webmock'
8989
end

Gemfile.lock

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ GEM
9898
ast (2.4.3)
9999
awesome_print (1.9.2)
100100
aws-eventstream (1.4.0)
101-
aws-partitions (1.1258.0)
102-
aws-sdk-core (3.251.0)
101+
aws-partitions (1.1261.0)
102+
aws-sdk-core (3.252.0)
103103
aws-eventstream (~> 1, >= 1.3.0)
104104
aws-partitions (~> 1, >= 1.992.0)
105105
aws-sigv4 (~> 1.9)
@@ -110,7 +110,7 @@ GEM
110110
aws-sdk-kms (1.129.0)
111111
aws-sdk-core (~> 3, >= 3.248.0)
112112
aws-sigv4 (~> 1.5)
113-
aws-sdk-s3 (1.225.0)
113+
aws-sdk-s3 (1.225.1)
114114
aws-sdk-core (~> 3, >= 3.248.0)
115115
aws-sdk-kms (~> 1)
116116
aws-sigv4 (~> 1.5)
@@ -337,7 +337,7 @@ GEM
337337
postmark-rails (0.22.1)
338338
actionmailer (>= 3.0.0)
339339
postmark (>= 1.21.3, < 2.0)
340-
pp (0.6.3)
340+
pp (0.6.4)
341341
prettyprint
342342
prettyprint (0.2.0)
343343
prism (1.9.0)
@@ -455,7 +455,7 @@ GEM
455455
rspec-support (3.13.7)
456456
rspec_junit_formatter (0.6.0)
457457
rspec-core (>= 2, < 4, != 2.12.0)
458-
rubocop (1.87.0)
458+
rubocop (1.88.0)
459459
json (~> 2.3)
460460
language_server-protocol (~> 3.17.0.2)
461461
lint_roller (~> 1.1.0)
@@ -519,15 +519,15 @@ GEM
519519
rubyzip (>= 1.2.2)
520520
semantic_logger (4.18.0)
521521
concurrent-ruby (~> 1.0)
522-
sentry-rails (6.6.0)
522+
sentry-rails (6.6.2)
523523
railties (>= 5.2.0)
524-
sentry-ruby (~> 6.6.0)
525-
sentry-ruby (6.6.0)
524+
sentry-ruby (~> 6.6.2)
525+
sentry-ruby (6.6.2)
526526
bigdecimal
527527
concurrent-ruby (~> 1.0, >= 1.0.2)
528528
logger
529-
shoulda-matchers (7.0.1)
530-
activesupport (>= 7.1)
529+
shoulda-matchers (8.0.1)
530+
activesupport (>= 7.2)
531531
simplecov (0.22.0)
532532
docile (~> 1.1)
533533
simplecov-html (~> 0.11)
@@ -643,7 +643,7 @@ DEPENDENCIES
643643
rubyzip
644644
selenium-webdriver
645645
sentry-rails
646-
shoulda-matchers (~> 7.0)
646+
shoulda-matchers (~> 8.0)
647647
simplecov
648648
statesman
649649
webdrivers

app/jobs/upload_job.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class DataNotFoundError < StandardError; end
2121

2222
VALID_LOCALES = Locales.load_locales.freeze
2323

24-
@skip_job = false
25-
2624
ProjectContentQuery = GithubApi::Client.parse <<-GRAPHQL
2725
query($owner: String!, $repository: String!, $expression: String!) {
2826
repository(owner: $owner, name: $repository) {
@@ -63,7 +61,7 @@ def perform(payload)
6361

6462
projects_data.data.repository.object.entries.each do |project_dir|
6563
project = format_project(project_dir, locale, repository(payload), owner(payload))
66-
if @skip_job
64+
if project[:build] == false
6765
Rails.logger.warn "Build skipped for #{project[:name]}"
6866
next
6967
end
@@ -107,10 +105,8 @@ def format_project(project_dir, locale, repository, owner)
107105
proj_config_file = data.entries.find { |file| file.name == PROJECT_CONFIG }
108106
proj_config = YAML.safe_load(proj_config_file.object.text, symbolize_names: true)
109107

110-
if proj_config[:build] == false
111-
@skip_job = true
112-
return proj_config
113-
end
108+
# if the build is false, no need to check files, just return the config
109+
return proj_config if proj_config[:build] == false
114110

115111
files = data.entries.reject { |file| file.name == PROJECT_CONFIG }
116112
categorized_files = categorize_files(files, project_dir, locale, repository, owner)

app/models/ability.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def define_school_teacher_abilities(user:, school:)
9191
can(%i[create], Project) do |project|
9292
school_teacher_can_manage_project?(user:, school:, project:)
9393
end
94-
can(%i[read update show_context], Project, school_id: school.id, lesson: { visibility: %w[teachers students] })
94+
can(%i[read update show_context], Project, school_id: school.id, lesson: { visibility: %w[teachers students], school_class: { teachers: { teacher_id: user.id } } })
9595
teacher_project_ids = Project.where(
9696
school_id: school.id,
9797
remixed_from_id: nil,

spec/jobs/upload_job_spec.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,60 @@
255255
end
256256
end
257257

258+
context 'with multiple projects where an earlier one has build set to false' do
259+
let(:raw_response) { modifiable_response.deep_dup }
260+
261+
before do
262+
entries = raw_response['data']['repository']['object']['entries']
263+
264+
# Turn the existing project into a build: false project
265+
build_false_dir = entries.find { |entry| entry['name'] == 'dont-collide-starter' }
266+
build_false_config = build_false_dir['object']['entries'].find { |entry| entry['name'] == 'project_config.yml' }
267+
build_false_config['object']['text'] += "build: false\n"
268+
269+
# add second project with build set to true
270+
entries << {
271+
'name' => 'build-me-starter',
272+
'object' => {
273+
'__typename' => 'Tree',
274+
'entries' => [
275+
{
276+
'name' => 'main.py',
277+
'extension' => '.py',
278+
'object' => {
279+
'__typename' => 'Blob',
280+
'text' => "print('hello')\n",
281+
'isBinary' => false
282+
}
283+
},
284+
{
285+
'name' => 'project_config.yml',
286+
'extension' => '.yml',
287+
'object' => {
288+
'__typename' => 'Blob',
289+
'text' => "name: \"Build Me\"\nidentifier: \"build-me-starter\"\ntype: \"python\"\nbuild: true\n",
290+
'isBinary' => true
291+
}
292+
}
293+
]
294+
}
295+
}
296+
297+
allow(GithubApi::Client).to receive(:query).and_return(graphql_response)
298+
allow(ProjectImporter).to receive(:new).and_call_original
299+
end
300+
301+
it 'still imports the later buildable project' do
302+
expect { described_class.perform_now(payload) }.to change(Project, :count).by(1)
303+
expect(Project.find_by(identifier: 'build-me-starter', locale: 'ja-JP')).to be_present
304+
end
305+
306+
it 'does not import the build: false project' do
307+
described_class.perform_now(payload)
308+
expect(Project.find_by(identifier: 'dont-collide-starter', locale: 'ja-JP')).to be_nil
309+
end
310+
end
311+
258312
context 'when GitHub returns nothing for the locale' do
259313
let(:raw_response) { { data: { repository: nil } } }
260314

spec/models/ability_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,15 @@
186186
it { is_expected.not_to be_able_to(:destroy, project) }
187187
end
188188

189-
context 'when user is a school teacher' do
189+
context 'when user is another teacher in the same school' do
190190
before do
191191
create(:teacher_role, user_id: user.id, school:)
192192
end
193193

194-
it { is_expected.to be_able_to(:read, project) }
195-
it { is_expected.to be_able_to(:show_context, project) }
194+
it { is_expected.not_to be_able_to(:read, project) }
195+
it { is_expected.not_to be_able_to(:show_context, project) }
196196
it { is_expected.not_to be_able_to(:create, project) }
197-
it { is_expected.to be_able_to(:update, project) }
197+
it { is_expected.not_to be_able_to(:update, project) }
198198
it { is_expected.not_to be_able_to(:set_finished, project.school_project) }
199199
it { is_expected.not_to be_able_to(:destroy, project) }
200200
end
@@ -248,15 +248,15 @@
248248
it { is_expected.not_to be_able_to(:destroy, project) }
249249
end
250250

251-
context 'when user is a school teacher' do
251+
context 'when user is another teacher in the same school' do
252252
before do
253253
create(:teacher_role, user_id: user.id, school:)
254254
end
255255

256-
it { is_expected.to be_able_to(:read, project) }
257-
it { is_expected.to be_able_to(:show_context, project) }
256+
it { is_expected.not_to be_able_to(:read, project) }
257+
it { is_expected.not_to be_able_to(:show_context, project) }
258258
it { is_expected.not_to be_able_to(:create, project) }
259-
it { is_expected.to be_able_to(:update, project) }
259+
it { is_expected.not_to be_able_to(:update, project) }
260260
it { is_expected.not_to be_able_to(:set_finished, project.school_project) }
261261
it { is_expected.not_to be_able_to(:destroy, project) }
262262
end

0 commit comments

Comments
 (0)