-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Update user management link in index.html.erb
- Refactor user creation and show page - Remove redundant <div> Refactor user creation logic in Schools::UsersController - Fix user attribute names in show.html.erb - Add change links to user details in show.html.erb
- Loading branch information
1 parent
271bd6b
commit c27aa35
Showing
10 changed files
with
278 additions
and
113 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 |
---|---|---|
@@ -1,26 +1,44 @@ | ||
module Schools | ||
class UsersController < BaseController | ||
def index; end | ||
def index | ||
@users = DFESignInAPI::OrganisationUsers.new(current_user.sub, current_school.urn).users['users'] | ||
@dfe_sign_in_request_organisation_url = | ||
Rails.application.config.x.dfe_sign_in_request_organisation_url.presence | ||
end | ||
|
||
def new | ||
@user = DFESignInAPI::UserInvite.new | ||
@user_invite = DFESignInAPI::UserInvite.new | ||
end | ||
|
||
def create | ||
@user_invite = DfeSignInApi::UserInvite.new(user_params) | ||
@user_invite = DFESignInAPI::UserInvite.new(user_params) | ||
@user_invite.organisation_id = DFESignInAPI::Organisation.new(current_user.sub, current_school.urn).current_organisation_id | ||
|
||
if @user_invite.valid? | ||
@user_invite.invite_user | ||
redirect_to users_path, notice: 'User invited successfully.' | ||
if params[:confirmed] == 'true' | ||
if @user_invite.valid? | ||
@user_invite.invite_user | ||
redirect_to schools_users_path, notice: "#{@user_invite.email} has been added." | ||
else | ||
render :new | ||
end | ||
else | ||
render :new | ||
render :show, locals: { user_invite: @user_invite } | ||
end | ||
end | ||
|
||
def show | ||
render :show | ||
end | ||
|
||
def edit | ||
@user_invite = DFESignInAPI::UserInvite.new(user_params) | ||
render :new, locals: { user_invite: @user_invite } | ||
end | ||
|
||
private | ||
|
||
def user_params | ||
params.require(:user).permit(:email, :first_name, :last_name, :organisation_id) | ||
params.require(:schools_dfe_sign_in_api_user_invite).permit(:email, :firstname, :lastname, :organisation_id) | ||
end | ||
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,24 @@ | ||
module Schools | ||
module DFESignInAPI | ||
class Organisation < Organisations | ||
attr_accessor :current_school_urn | ||
|
||
def initialize(user_uuid, current_school_urn) | ||
super(user_uuid) | ||
self.current_school_urn = current_school_urn | ||
end | ||
|
||
def current_organisation | ||
organisations.find { |org| org['urn'].to_i == current_school_urn } | ||
end | ||
|
||
def current_organisation_ukprn | ||
current_organisation['ukprn'] if current_organisation | ||
end | ||
|
||
def current_organisation_id | ||
current_organisation['id'] if current_organisation | ||
end | ||
end | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
app/services/schools/dfe_sign_in_api/organisation_users.rb
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,29 @@ | ||
module Schools | ||
module DFESignInAPI | ||
class OrganisationUsers < Client | ||
attr_accessor :user_uuid, :current_school_urn | ||
|
||
def initialize(user_uuid, current_school_urn) | ||
self.user_uuid = user_uuid | ||
self.current_school_urn = current_school_urn | ||
end | ||
|
||
def ukprn | ||
Organisation.new(user_uuid, current_school_urn).current_organisation_ukprn | ||
end | ||
|
||
def users | ||
@users ||= response | ||
end | ||
|
||
private | ||
|
||
def endpoint | ||
URI::HTTPS.build( | ||
host: Rails.configuration.x.dfe_sign_in_api_host, | ||
path: ['/organisations', ukprn, 'users'].join('/') | ||
) | ||
end | ||
end | ||
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
<%= render partial: "form", locals: { user: @user } %> | ||
<%= render partial: "form", locals: { user_invite: @user_invite } %> |
Oops, something went wrong.