Skip to content

Commit b680b79

Browse files
authored
Add flag to identify school as linked to excs (#546)
## Status - Closes #543 ## Points for consideration: - Security - Performance ## What's changed? - Adds `user_origin` enum to capture user origin - Adds a school template to make views more DRY ## Steps to perform after deploying to production N/A
1 parent f348dfc commit b680b79

File tree

11 files changed

+52
-54
lines changed

11 files changed

+52
-54
lines changed

app/controllers/api/schools_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def school_params
6565
:creator_agree_authority,
6666
:creator_agree_terms_and_conditions,
6767
:creator_agree_to_ux_contact,
68-
:creator_agree_responsible_safeguarding
68+
:creator_agree_responsible_safeguarding,
69+
:user_origin
6970
)
7071
end
7172
end

app/models/school.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class School < ApplicationRecord
99

1010
VALID_URL_REGEX = %r{\A(?:https?://)?(?:www.)?[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,63}(\.[a-z]{2,63})*(/.*)?\z}ix
1111

12+
enum :user_origin, %i[for_education experience_cs], default: :for_education, validate: true
13+
1214
validates :name, presence: true
1315
validates :website, presence: true, format: { with: VALID_URL_REGEX, message: I18n.t('validations.school.website') }
1416
validates :address_line_1, presence: true
Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
11
# frozen_string_literal: true
22

3-
json.call(
4-
@school,
5-
:id,
6-
:name,
7-
:website,
8-
:reference,
9-
:address_line_1,
10-
:address_line_2,
11-
:municipality,
12-
:administrative_area,
13-
:postal_code,
14-
:country_code,
15-
:code,
16-
:verified_at,
17-
:created_at,
18-
:updated_at
19-
)
20-
json.roles @user.school_roles(@school)
3+
json.partial! '/api/schools/school', school: @school, roles: @user.school_roles(@school), code: true

app/views/api/school_owners/_school_owner.json.jbuilder

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ json.call(owner, :id, :name)
44
json.type('owner')
55

66
include_email = local_assigns.fetch(:include_email, true)
7-
87
json.email(owner.email) if include_email
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
json.call(
4+
school,
5+
:id,
6+
:name,
7+
:website,
8+
:reference,
9+
:address_line_1,
10+
:address_line_2,
11+
:municipality,
12+
:administrative_area,
13+
:postal_code,
14+
:country_code,
15+
:verified_at,
16+
:created_at,
17+
:updated_at
18+
)
19+
20+
include_roles = local_assigns.fetch(:roles, false)
21+
json.roles(roles) if include_roles
22+
23+
include_code = local_assigns.fetch(:code, false)
24+
json.code(school.code) if include_code
25+
26+
include_user_origin = local_assigns.fetch(:user_origin, false)
27+
json.user_origin(school.user_origin) if include_user_origin
Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
# frozen_string_literal: true
22

33
json.array!(@schools) do |school|
4-
json.call(
5-
school,
6-
:id,
7-
:name,
8-
:website,
9-
:reference,
10-
:address_line_1,
11-
:address_line_2,
12-
:municipality,
13-
:administrative_area,
14-
:postal_code,
15-
:country_code,
16-
:verified_at,
17-
:created_at,
18-
:updated_at
19-
)
4+
json.partial! 'school', school:
205
end
Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
11
# frozen_string_literal: true
22

3-
json.call(
4-
@school,
5-
:id,
6-
:name,
7-
:website,
8-
:reference,
9-
:address_line_1,
10-
:address_line_2,
11-
:municipality,
12-
:administrative_area,
13-
:postal_code,
14-
:country_code,
15-
:verified_at,
16-
:created_at,
17-
:updated_at
18-
)
3+
json.partial! 'school', school: @school, user_origin: true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddUserOriginToSchools < ActiveRecord::Migration[7.1]
2+
def change
3+
add_column :schools, :user_origin, :integer, default: 0
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/features/school/creating_a_school_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
creator_agree_authority: true,
2323
creator_agree_terms_and_conditions: true,
2424
creator_agree_to_ux_contact: true,
25-
creator_agree_responsible_safeguarding: true
25+
creator_agree_responsible_safeguarding: true,
26+
user_origin: 'for_education'
2627
}
2728
}
2829
end

spec/models/school_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,15 @@
242242
school.update(code: '00-00-00')
243243
expect(school.errors[:code]).to include('cannot be changed after verification')
244244
end
245+
246+
it 'requires a user_origin' do
247+
school.user_origin = nil
248+
expect(school).to be_invalid
249+
end
250+
251+
it 'sets the user_origin to for_education by default' do
252+
expect(school.user_origin).to eq('for_education')
253+
end
245254
end
246255

247256
describe '#creator' do

0 commit comments

Comments
 (0)