Skip to content

Commit

Permalink
Refactor user data handling in Schools::DFESignInAPI::OrganisationUse…
Browse files Browse the repository at this point in the history
…rs and update view to use new attributes

- Update specs
  • Loading branch information
ekumachidi committed Mar 15, 2024
1 parent 351665f commit 44451ad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/schools/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Schools
class UsersController < BaseController
def index
@users = DFESignInAPI::OrganisationUsers.new(current_user.sub, current_school.urn).users
@users = DFESignInAPI::OrganisationUsers.new(current_user.sub, current_school.urn).users_as_invite_objects
@dfe_sign_in_manage_users_url =
Rails.application.config.x.dfe_sign_in_manage_users_url.presence
end
Expand Down
14 changes: 14 additions & 0 deletions app/services/schools/dfe_sign_in_api/organisation_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ def ukprn

def users
response&.fetch('users', nil)
# users_as_invite_objects
end

def users_as_invite_objects
return [] if users.blank?

users.map do |user_data|
Schools::DFESignInAPI::UserInvite.new(
email: user_data['email'],
firstname: user_data['firstName'],
lastname: user_data['lastName'],
organisation_id: current_school_urn
)
end
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/views/schools/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
<tbody class="govuk-table__body">
<% @users.each do |user| %>
<tr class="govuk-table__row">
<td class="govuk-table__cell"><%= "#{user['firstName']} #{user['lastName']}" %></td>
<td class="govuk-table__cell"><%= user['email'] %></td>
<td class="govuk-table__cell"><%= "#{user.firstname} #{user.lastname}" %></td>
<td class="govuk-table__cell"><%= user.email %></td>
</tr>
<% end %>

Expand Down

0 comments on commit 44451ad

Please sign in to comment.