-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow non-support users to add other users to their organisation
- Loading branch information
Showing
29 changed files
with
793 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class Placements::Providers::UsersController < ApplicationController | ||
before_action :set_provider | ||
|
||
def index | ||
@users = @provider.users.order("LOWER(first_name)") | ||
end | ||
|
||
def show | ||
@user = @provider.users.find(params.require(:id)) | ||
end | ||
|
||
def new | ||
@user_form = params[:user_invite_form].present? ? user_form : UserInviteForm.new | ||
end | ||
|
||
def check | ||
render :new unless user_form.valid? | ||
end | ||
|
||
def create | ||
if user_form.invite | ||
redirect_to placements_provider_users_path(@provider) | ||
flash[:success] = t(".user_added") | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_provider | ||
@provider = Placements::Provider.find(params.fetch(:provider_id)) | ||
end | ||
|
||
def user_params | ||
params.require(:user_invite_form) | ||
.permit(:first_name, :last_name, :email) | ||
.merge({ service: current_service, organisation: @provider }) | ||
end | ||
|
||
def user_form | ||
@user_form ||= UserInviteForm.new(user_params) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class Placements::Schools::UsersController < ApplicationController | ||
before_action :set_school | ||
|
||
def index | ||
@users = @school.users.order("LOWER(first_name)") | ||
end | ||
|
||
def show | ||
@user = @school.users.find(params.require(:id)) | ||
end | ||
|
||
def new | ||
@user_form = params[:user_invite_form].present? ? user_form : UserInviteForm.new | ||
end | ||
|
||
def check | ||
render :new unless user_form.valid? | ||
end | ||
|
||
def create | ||
if user_form.invite | ||
redirect_to placements_school_users_path(@school) | ||
flash[:success] = t(".user_added") | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_school | ||
@school = Placements::School.find(params.fetch(:school_id)) | ||
end | ||
|
||
def user_params | ||
params.require(:user_invite_form) | ||
.permit(:first_name, :last_name, :email) | ||
.merge({ service: current_service, organisation: @school }) | ||
end | ||
|
||
def user_form | ||
@user_form ||= UserInviteForm.new(user_params) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/views/placements/organisations/users/_check_form.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<%# locals: (user: nil, organisation: nil) -%> | ||
<div class="govuk-width-container"> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= form_with(model: user, url: placements_organisation_users_path(organisation), method: :post) do |f| %> | ||
<%= f.hidden_field :first_name, value: user.first_name %> | ||
<%= f.hidden_field :last_name, value: user.last_name %> | ||
<%= f.hidden_field :email, value: user.email %> | ||
|
||
<label class="govuk-label govuk-label--l"> | ||
<span class="govuk-caption-l"><%= t(".add_user", organisation_name: organisation.name) %></span> | ||
<%= t(".check_your_answers") %> | ||
</label> | ||
|
||
<%= govuk_summary_list do |summary_list| %> | ||
<% summary_list.with_row do |row| %> | ||
<% row.with_key(text: User.human_attribute_name(:first_name)) %> | ||
<% row.with_value(text: user.first_name) %> | ||
<% row.with_action(text: t(".change"), | ||
href: new_placements_organisation_user_path(organisation, user.as_form_params), | ||
html_attributes: { | ||
class: "govuk-link--no-visited-state", | ||
}) %> | ||
<% end %> | ||
<% summary_list.with_row do |row| %> | ||
<% row.with_key(text: User.human_attribute_name(:last_name)) %> | ||
<% row.with_value(text: user.last_name) %> | ||
<% row.with_action(text: t(".change"), | ||
href: new_placements_organisation_user_path(organisation, user.as_form_params), | ||
html_attributes: { | ||
class: "govuk-link--no-visited-state", | ||
}) %> | ||
<% end %> | ||
<% summary_list.with_row do |row| %> | ||
<% row.with_key(text: User.human_attribute_name(:email)) %> | ||
<% row.with_value(text: user.email) %> | ||
<% row.with_action(text: t(".change"), | ||
href: new_placements_organisation_user_path(organisation, user.as_form_params), | ||
html_attributes: { | ||
class: "govuk-link--no-visited-state", | ||
}) %> | ||
<% end %> | ||
<% end %> | ||
|
||
<div class="govuk-warning-text"> | ||
<span class="govuk-warning-text__icon" aria-hidden="true">!</span> | ||
<strong class="govuk-warning-text__text"><%= t(".warning", organisation_name: organisation.name) %></strong> | ||
</div> | ||
|
||
<%= f.govuk_submit t(".add_user") %> | ||
|
||
<p class="govuk-body"> | ||
<%= govuk_link_to(t(".cancel"), placements_organisation_users_path(organisation)) %> | ||
</p> | ||
<% end %> | ||
<div> | ||
<div> | ||
</div> |
33 changes: 33 additions & 0 deletions
33
app/views/placements/organisations/users/_new_form.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<%# locals: (organisation: nil, user: nil) -%> | ||
<%= form_with(model: user, url: check_placements_organisation_users_path(organisation), method: "get") do |f| %> | ||
<%= f.govuk_error_summary %> | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<span class="govuk-caption-l"><%= t(".add_user", organisation_name: organisation.name) %></span> | ||
<h2 class="govuk-heading-l"><%= t(".personal_details") %></h2> | ||
|
||
<div class="govuk-form-group"> | ||
<%= f.govuk_text_field :first_name, | ||
class: "govuk-input--width-20", | ||
label: { text: User.human_attribute_name(:first_name), size: "s" } %> | ||
</div> | ||
|
||
<div class="govuk-form-group"> | ||
<%= f.govuk_text_field :last_name, | ||
class: "govuk-input--width-20", | ||
label: { text: User.human_attribute_name(:last_name), size: "s" } %> | ||
</div> | ||
|
||
<div class="govuk-form-group"> | ||
<%= f.govuk_text_field :email, label: { text: User.human_attribute_name(:email), size: "s" } %> | ||
</div> | ||
|
||
<%= f.govuk_submit t(".continue") %> | ||
|
||
<p class="govuk-body"> | ||
<%= govuk_link_to(t(".cancel"), placements_organisation_users_path(organisation)) %> | ||
</p> | ||
</div> | ||
</div> | ||
<% end %> |
14 changes: 14 additions & 0 deletions
14
app/views/placements/organisations/users/_user_details.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<%= govuk_summary_list do |summary_list| %> | ||
<% summary_list.with_row do |row| %> | ||
<% row.with_key(text: User.human_attribute_name(:first_name)) %> | ||
<% row.with_value(text: @user.first_name) %> | ||
<% end %> | ||
<% summary_list.with_row do |row| %> | ||
<% row.with_key(text: User.human_attribute_name(:last_name)) %> | ||
<% row.with_value(text: @user.last_name) %> | ||
<% end %> | ||
<% summary_list.with_row do |row| %> | ||
<% row.with_key(text: User.human_attribute_name(:email)) %> | ||
<% row.with_value(text: @user.email) %> | ||
<% end %> | ||
<% end %> |
20 changes: 20 additions & 0 deletions
20
app/views/placements/organisations/users/_users_list.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<% if users.any? %> | ||
<%= govuk_table do |table| %> | ||
<% table.with_head do |head| %> | ||
<% head.with_row do |row| %> | ||
<% row.with_cell(header: true, text: t(".name")) %> | ||
<% row.with_cell(header: true, text: User.human_attribute_name(:email)) %> | ||
<% end %> | ||
<% end %> | ||
<% table.with_body do |body| %> | ||
<% users.each do |user| %> | ||
<% body.with_row do |row| %> | ||
<% row.with_cell(text: govuk_link_to(user.full_name, placements_organisation_user_path(organisation, user))) %> | ||
<% row.with_cell(text: user.email) %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% else %> | ||
<p><%= t("no_users", organisation_name: organisation.name) %></p> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<%= content_for :page_title, sanitize(t(".check_your_answers", provider_name: @provider.name)) %> | ||
<% if current_user.organisation_count > 1 %> | ||
<%= content_for(:header_content) do %> | ||
<%= render(ContentHeaderComponent.new( | ||
title: @provider.name, | ||
actions: [govuk_link_to(t(".change_organisation"), placements_organisations_path, no_visited_state: true)], | ||
)) %> | ||
<% end %> | ||
<% end %> | ||
<%= render "placements/primary_navigation", current_navigation: :users, organisation: @provider %> | ||
<%= content_for(:before_content) do %> | ||
<%= govuk_back_link(href: new_placements_provider_user_path( | ||
@user_form.as_form_params.merge(provider_id: @provider.id), | ||
)) %> | ||
<% end %> | ||
|
||
<div class="govuk-width-container"> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<label class="govuk-label govuk-label--l"> | ||
<span class="govuk-caption-l"><%= t(".add_user") %></span> | ||
<%= t(".check_your_answers") %> | ||
</label> | ||
|
||
<%= render "placements/organisations/users/check_form", user: @user_form, organisation: @provider %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<% content_for(:page_title) { t(".users") } %> | ||
<% if current_user.organisation_count > 1 %> | ||
<%= content_for(:header_content) do %> | ||
<%= render(ContentHeaderComponent.new( | ||
title: @provider.name, | ||
actions: [govuk_link_to(t(".change_organisation"), placements_organisations_path, no_visited_state: true)], | ||
)) %> | ||
<% end %> | ||
<% end %> | ||
<%= render "placements/primary_navigation", organisation: @provider, current_navigation: :users %> | ||
|
||
<div class="govuk-width-container"> | ||
<h1 class="govuk-heading-l"><%= t(".users") %></h1> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= govuk_button_to(t(".add_user"), new_placements_provider_user_path, method: :get) %> | ||
<%= render "placements/organisations/users/users_list", users: @users, organisation: @provider %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<%= content_for :page_title, t(".page_title") %> | ||
<%= render "placements/primary_navigation", current_navigation: :users, organisation: @provider %> | ||
<% if current_user.organisation_count > 1 %> | ||
<%= content_for(:header_content) do %> | ||
<%= render(ContentHeaderComponent.new( | ||
title: @provider.name, | ||
actions: [govuk_link_to(t(".change_organisation"), placements_organisations_path, no_visited_state: true)], | ||
)) %> | ||
<% end %> | ||
<% end %> | ||
|
||
<%= content_for(:before_content) do %> | ||
<%= govuk_back_link(href: placements_provider_users_path(@provider)) %> | ||
<% end %> | ||
|
||
<div class="govuk-width-container"> | ||
<%= render "placements/organisations/users/new_form", user: @user_form, organisation: @provider %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<% if current_user.organisation_count > 1 %> | ||
<%= content_for(:header_content) do %> | ||
<%= render(ContentHeaderComponent.new( | ||
title: @provider.name, | ||
actions: [govuk_link_to(t(".change_organisation"), placements_organisations_path, no_visited_state: true)], | ||
)) %> | ||
<% end %> | ||
<% end %> | ||
<%= render "placements/primary_navigation", organisation: @provider, current_navigation: :users %> | ||
<%= content_for :page_title, sanitize(@user.full_name) %> | ||
<%= content_for(:before_content) do %> | ||
<%= govuk_back_link(href: placements_provider_users_path(@provider)) %> | ||
<% end %> | ||
|
||
<div class="govuk-width-container"> | ||
<h1 class="govuk-heading-l"><%= @user.full_name %></h1> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= render "placements/organisations/user_details", user: @user %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.