Skip to content

Commit dc7d654

Browse files
authored
Merge branch 'main' into env-example-updates
2 parents 7ff5cb9 + 62aaabf commit dc7d654

22 files changed

+464
-31
lines changed

.github/pull_request_template.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Status
2+
3+
- Closes _add issue numbers or delete_
4+
- Related to _add issue numbers or delete_
5+
6+
## Points for consideration:
7+
8+
- Security
9+
- Performance
10+
11+
## What's changed?
12+
13+
_Description of what's been done - bullets are often best_
14+
15+
## Steps to perform after deploying to production
16+
17+
_If the production environment requires any extra work after this PR has been deployed detail it here. This could be running a Rake task, a migration, or upgrading a Gem. That kind of thing._

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ RUN gem install bundler \
33
&& apt-get update \
44
&& apt-get upgrade --yes \
55
&& apt-get install --yes --no-install-recommends \
6-
libpq5 libxml2 libxslt1.1 \
6+
libpq5 libxml2 libxslt1.1 libvips \
77
curl gnupg graphviz nodejs \
88
&& echo "deb http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
99
&& curl -sL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \

app/controllers/admin/projects_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def destroy_image
1717
private
1818

1919
def set_host_for_local_storage
20-
ActiveStorage::Current.host = request.base_url if Rails.application.config.active_storage.service == :local
20+
return unless Rails.application.config.active_storage.service == :local
21+
22+
ActiveStorage::Current.url_options = { host: request.base_url }
2123
end
2224
end
2325
end

app/controllers/admin/schools_controller.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,13 @@ def reject_school
3838

3939
redirect_to admin_school_path(id: school_id)
4040
end
41+
42+
def default_sorting_attribute
43+
:created_at
44+
end
45+
46+
def default_sorting_direction
47+
:desc
48+
end
4149
end
4250
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
module Api
4+
class TeacherInvitationsController < ApiController
5+
rescue_from ActiveSupport::MessageVerifier::InvalidSignature, with: -> { denied }
6+
7+
before_action :authorize_user
8+
before_action :load_invitation
9+
before_action :ensure_invitation_email_matches_user_email
10+
11+
def show
12+
render :show, formats: [:json], status: :ok
13+
end
14+
15+
def accept
16+
role = Role.teacher.build(user_id: current_user.id, school: @invitation.school)
17+
if role.valid?
18+
role.save
19+
@invitation.update!(accepted_at: Time.current) if @invitation.accepted_at.blank?
20+
head :ok
21+
else
22+
render json: { error: role.errors }, status: :unprocessable_entity
23+
end
24+
end
25+
26+
private
27+
28+
def load_invitation
29+
@invitation = TeacherInvitation.find_by_token_for!(:teacher_invitation, params[:token])
30+
end
31+
32+
def ensure_invitation_email_matches_user_email
33+
return if @invitation.email_address == current_user.email
34+
35+
render json: { error: 'Invitation email does not match user email' }, status: :forbidden
36+
end
37+
end
38+
end

app/dashboards/school_dashboard.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class SchoolDashboard < Administrate::BaseDashboard
3838
name
3939
reference
4040
country_code
41+
created_at
4142
verified_at
4243
rejected_at
4344
].freeze

app/models/invitation.rb renamed to app/models/teacher_invitation.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

3-
class Invitation < ApplicationRecord
3+
class TeacherInvitation < ApplicationRecord
4+
delegate :name, to: :school, prefix: true
5+
46
belongs_to :school
57
validates :email_address,
68
format: { with: EmailValidator.regexp, message: I18n.t('validations.invitation.email_address') }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
json.call(
4+
@invitation,
5+
:school_name
6+
)

config/routes.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
resources :lessons, only: %i[index create show update destroy] do
5454
post :copy, on: :member, to: 'lessons#create_copy'
5555
end
56+
57+
resources :teacher_invitations, param: :token, only: :show do
58+
put :accept, on: :member
59+
end
5660
end
5761

5862
resource :github_webhooks, only: :create, defaults: { formats: :json }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddAcceptedAtToInvitation < ActiveRecord::Migration[7.1]
2+
def change
3+
add_column :invitations, :accepted_at, :datetime
4+
end
5+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class RenameInvitationsToTeacherInvitations < ActiveRecord::Migration[7.1]
2+
def change
3+
rename_table :invitations, :teacher_invitations
4+
end
5+
end

db/schema.rb

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/concepts/school_teacher/invite.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def call(school:, school_teacher_params:, token:)
1717

1818
def invite_teacher(school, school_teacher_params, _token)
1919
email_address = school_teacher_params.fetch(:email_address)
20-
Invitation.create!(school:, email_address:)
20+
TeacherInvitation.create!(school:, email_address:)
2121
end
2222
end
2323
end

lib/tasks/classroom_management_helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module ClassroomManagementHelper
1111
def create_school(creator_id, school_id = nil)
1212
School.find_or_create_by!(creator_id:, id: school_id) do |school|
1313
Rails.logger.info 'Seeding a school...'
14-
school.name = 'School Name'
14+
school.name = 'Test School'
1515
school.website = 'http://example.com'
1616
school.address_line_1 = 'School Address'
1717
school.municipality = 'City'
@@ -31,7 +31,7 @@ def verify_school(school)
3131
def create_school_class(teacher_id, school)
3232
SchoolClass.find_or_create_by!(teacher_id:, school:) do |school_class|
3333
Rails.logger.info 'Seeding a class...'
34-
school_class.name = 'De§ult Class Name'
34+
school_class.name = 'Test Class'
3535
school_class.teacher_id = teacher_id
3636
school_class.school = school
3737
end
@@ -51,7 +51,7 @@ def create_lessons(user_id, school, school_class, visibility = 'public')
5151
lesson.user_id = user_id
5252
lesson.school = school
5353
lesson.school_class = school_class
54-
lesson.name = "Lesson #{i + 1}"
54+
lesson.name = "Test Lesson #{i + 1}"
5555
lesson.description = "This is lesson #{i + 1}"
5656
lesson.visibility = visibility
5757
end
@@ -62,7 +62,7 @@ def create_lessons(user_id, school, school_class, visibility = 'public')
6262
def create_project(user_id, school, lesson)
6363
Project.find_or_create_by!(user_id:, school:, lesson:) do |project|
6464
Rails.logger.info "Seeding a project for #{lesson.name}..."
65-
project.name = 'Default Project Name'
65+
project.name = "Test Project for #{lesson.name}"
6666
project.user_id = user_id
6767
project.school = school
6868
project.lesson = lesson

spec/concepts/school_teacher/invite_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
expect(response.success?).to be(true)
1717
end
1818

19-
it 'creates an Invitation' do
20-
expect { described_class.call(school:, school_teacher_params:, token:) }.to change(Invitation, :count)
19+
it 'creates a TeacherInvitation' do
20+
expect { described_class.call(school:, school_teacher_params:, token:) }.to change(TeacherInvitation, :count)
2121
end
2222

2323
context 'when creation fails' do

spec/factories/school.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111
creator_agree_authority { true }
1212
creator_agree_terms_and_conditions { true }
1313
end
14+
15+
factory :verified_school, parent: :school do
16+
verified_at { Time.current }
17+
end
1418
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# frozen_string_literal: true
22

33
FactoryBot.define do
4-
factory :invitation do
4+
factory :teacher_invitation do
55
email_address { '[email protected]' }
6-
school factory: :school, verified_at: Time.zone.now
6+
school factory: :verified_school
77
end
88
end

0 commit comments

Comments
 (0)