Skip to content

Add flag to identify school as linked to excs #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/controllers/api/schools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def school_params
:creator_agree_authority,
:creator_agree_terms_and_conditions,
:creator_agree_to_ux_contact,
:creator_agree_responsible_safeguarding
:creator_agree_responsible_safeguarding,
:user_origin
)
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/school.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class School < ApplicationRecord

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

enum :user_origin, %i[for_education experience_cs], default: :for_education, validate: true

validates :name, presence: true
validates :website, presence: true, format: { with: VALID_URL_REGEX, message: I18n.t('validations.school.website') }
validates :address_line_1, presence: true
Expand Down
19 changes: 1 addition & 18 deletions app/views/api/my_school/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
# frozen_string_literal: true

json.call(
@school,
:id,
:name,
:website,
:reference,
:address_line_1,
:address_line_2,
:municipality,
:administrative_area,
:postal_code,
:country_code,
:code,
:verified_at,
:created_at,
:updated_at
)
json.roles @user.school_roles(@school)
json.partial! '/api/schools/school', school: @school, roles: @user.school_roles(@school), code: true
1 change: 0 additions & 1 deletion app/views/api/school_owners/_school_owner.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ json.call(owner, :id, :name)
json.type('owner')

include_email = local_assigns.fetch(:include_email, true)

json.email(owner.email) if include_email
27 changes: 27 additions & 0 deletions app/views/api/schools/_school.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

json.call(
school,
:id,
:name,
:website,
:reference,
:address_line_1,
:address_line_2,
:municipality,
:administrative_area,
:postal_code,
:country_code,
:verified_at,
:created_at,
:updated_at
)

include_roles = local_assigns.fetch(:roles, false)
json.roles(roles) if include_roles

include_code = local_assigns.fetch(:code, false)
json.code(school.code) if include_code

include_user_origin = local_assigns.fetch(:user_origin, false)
json.user_origin(school.user_origin) if include_user_origin
17 changes: 1 addition & 16 deletions app/views/api/schools/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
# frozen_string_literal: true

json.array!(@schools) do |school|
json.call(
school,
:id,
:name,
:website,
:reference,
:address_line_1,
:address_line_2,
:municipality,
:administrative_area,
:postal_code,
:country_code,
:verified_at,
:created_at,
:updated_at
)
json.partial! 'school', school:
end
17 changes: 1 addition & 16 deletions app/views/api/schools/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
# frozen_string_literal: true

json.call(
@school,
:id,
:name,
:website,
:reference,
:address_line_1,
:address_line_2,
:municipality,
:administrative_area,
:postal_code,
:country_code,
:verified_at,
:created_at,
:updated_at
)
json.partial! 'school', school: @school, user_origin: true
5 changes: 5 additions & 0 deletions db/migrate/20250515081023_add_user_origin_field_to_schools.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUserOriginToSchools < ActiveRecord::Migration[7.1]
def change
add_column :schools, :user_origin, :integer, default: 0
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion spec/features/school/creating_a_school_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
creator_agree_authority: true,
creator_agree_terms_and_conditions: true,
creator_agree_to_ux_contact: true,
creator_agree_responsible_safeguarding: true
creator_agree_responsible_safeguarding: true,
user_origin: 'for_education'
}
}
end
Expand Down
9 changes: 9 additions & 0 deletions spec/models/school_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@
school.update(code: '00-00-00')
expect(school.errors[:code]).to include('cannot be changed after verification')
end

it 'requires a user_origin' do
school.user_origin = nil
expect(school).to be_invalid
end

it 'sets the user_origin to for_education by default' do
expect(school.user_origin).to eq('for_education')
end
end

describe '#creator' do
Expand Down