Skip to content

Commit

Permalink
Create Claims support users index page
Browse files Browse the repository at this point in the history
  • Loading branch information
gms-gs committed Jan 4, 2024
1 parent 71fa2ff commit fa9963c
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 7 deletions.
7 changes: 7 additions & 0 deletions app/controllers/claims/support/schools_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
class Claims::Support::SchoolsController < Claims::Support::ApplicationController
def index
@schools = Claims::School.includes(:gias_school).order("gias_schools.name ASC")
end

def show
@school = Claims::School.find(params.require(:id))
end
end
11 changes: 11 additions & 0 deletions app/controllers/claims/support/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
class Claims::Support::UsersController < Claims::Support::ApplicationController
before_action :set_school

def index
@users = @school.users
end

private

def set_school
@school = Claims::School.find(params[:school_id])
end
end
1 change: 1 addition & 0 deletions app/models/school.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
class School < ApplicationRecord
belongs_to :gias_school, foreign_key: :urn, primary_key: :urn
has_many :memberships, as: :organisation
has_many :users, through: :memberships

validates :urn, presence: true
validates :urn, uniqueness: { case_sensitive: false }
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ class User < ApplicationRecord
validates :email, uniqueness: { scope: :service, case_sensitive: false }

scope :support_users, -> { where(support_user: true) }

def full_name
"#{first_name} #{last_name}".strip
end
end
19 changes: 15 additions & 4 deletions app/views/claims/support/schools/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
Support / Schools
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl"><%= t("organisations") %></h1>

<ul>
<li><%= link_to "School 1", claims_support_school_path(1) %></li>
</ul>
<% if @schools.any? %>
<h2 class="govuk-heading-l"><%= t("schools") %></h2>
<ul class="govuk-list">
<% @schools.each do |school| %>
<li>
<%= govuk_link_to school.name, request.env["PATH_INFO"], no_visited_state: true %>
</li>
<% end %>
</ul>
<% end %>
</div>
</div>
23 changes: 22 additions & 1 deletion app/views/claims/support/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
Support / Users
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l"><%= t(".heading") %></h1>
</div>
</div>

<table class="govuk-table">
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header"><%= t(".attributes.users.name") %></th>
<th scope="col" class="govuk-table__header"><%= t(".attributes.users.email") %></th>
</tr>
</thead>
<tbody class="govuk-table__body">
<% @users.each do |user| %>
<tr class="govuk-table__row">
<td class="govuk-table__cell"><%= user.full_name %></td>
<td class="govuk-table__cell"><%= user.email %></td>
</tr>
<% end %>
</tbody>
</table>
10 changes: 10 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ en:
add_organisation: Add organisation
organisations: Organisations
schools: Schools
organisation_details: Organisation details
providers: Providers
account:
index:
Expand Down Expand Up @@ -55,3 +56,12 @@ en:
placements:
heading: Placements news and updates
contents: Contents
claims:
support:
users:
index:
heading: Users
attributes:
users:
name: Name
email: Email
4 changes: 2 additions & 2 deletions config/routes/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace :support do
root to: redirect("/support/schools")

resources :schools do
resources :schools, only: %i[index show] do
resources :claims
resources :users
resources :users, only: [:index]
end
end
end
6 changes: 6 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@
parent: :user do
service { "placements" }
end

factory :claims_support_user,
class: "Claims::SupportUser",
parent: :user do
service { "claims" }
end
end
36 changes: 36 additions & 0 deletions spec/system/claims/view_users_of_a_school_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require "rails_helper"

RSpec.describe "View users for school", type: :system do
before do
setup_school_and_anne_membership
end

scenario "I sign in as a support user and view a schools users index page" do
sign_in_as_support_user
visit_claims_support_school_users_page
verify_users_list_for_school
end

private

def setup_school_and_anne_membership
@school = create(:school, :claims, urn: "123456")
@anne_persona = create(:persona, :anne, service: "claims")
create(:membership, user: @anne_persona, organisation: @school)
end

def sign_in_as_support_user
create(:persona, :colin, service: "claims")
visit personas_path
click_on "Sign In as Colin"
end

def visit_claims_support_school_users_page
visit claims_support_school_users_path(@school)
end

def verify_users_list_for_school
expect(page).to have_content("Anne Wilson")
expect(page).to have_content("[email protected]")
end
end

0 comments on commit fa9963c

Please sign in to comment.