-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1244 from alphagov/amend-user-related-forms
Amend user-related forms
- Loading branch information
Showing
32 changed files
with
688 additions
and
985 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
51 changes: 0 additions & 51 deletions
51
app/controllers/accounts_permissions_and_training_requests_controller.rb
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
app/controllers/change_existing_user_requests_controller.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,37 @@ | ||
require "gds_zendesk/users" | ||
require "zendesk_api/error" | ||
|
||
class ChangeExistingUserRequestsController < RequestsController | ||
protected | ||
|
||
def new_request | ||
Support::Requests::ChangeExistingUserRequest.new | ||
end | ||
|
||
def zendesk_ticket_class | ||
Zendesk::Ticket::ChangeExistingUserRequestTicket | ||
end | ||
|
||
def parse_request_from_params | ||
Support::Requests::ChangeExistingUserRequest.new(create_or_change_user_request_params) | ||
end | ||
|
||
def create_or_change_user_request_params | ||
params.require(:support_requests_change_existing_user_request).permit( | ||
:additional_comments, | ||
requester_attributes: %i[email name collaborator_emails], | ||
requested_user_attributes: %i[name email], | ||
).to_h | ||
end | ||
|
||
def save_to_zendesk(submitted_request) | ||
super | ||
create_or_update_user_in_zendesk(submitted_request.requested_user) if submitted_request.for_new_user? | ||
end | ||
|
||
def create_or_update_user_in_zendesk(requested_user) | ||
GDS_ZENDESK_CLIENT.users.create_or_update_user(requested_user) | ||
rescue ZendeskAPI::Error::ClientError => e | ||
exception_notification_for(e) | ||
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,49 @@ | ||
require "gds_zendesk/users" | ||
require "zendesk_api/error" | ||
|
||
class CreateNewUserRequestsController < RequestsController | ||
include ExploreHelper | ||
|
||
protected | ||
|
||
def new_request | ||
@organisations_list = support_api.organisations_list.to_a.map { |o| organisation_title(o) } | ||
Support::Requests::CreateNewUserRequest.new | ||
end | ||
|
||
def zendesk_ticket_class | ||
Zendesk::Ticket::CreateNewUserRequestTicket | ||
end | ||
|
||
def parse_request_from_params | ||
Support::Requests::CreateNewUserRequest.new(create_or_change_user_request_params) | ||
end | ||
|
||
def create_or_change_user_request_params | ||
params.require(:support_requests_create_new_user_request).permit( | ||
:additional_comments, | ||
requester_attributes: %i[email name collaborator_emails], | ||
requested_user_attributes: %i[name email organisation], | ||
).to_h | ||
end | ||
|
||
def save_to_zendesk(submitted_request) | ||
super | ||
create_or_update_user_in_zendesk(submitted_request.requested_user) if submitted_request.for_new_user? | ||
end | ||
|
||
def create_or_update_user_in_zendesk(requested_user) | ||
GDS_ZENDESK_CLIENT.users.create_or_update_user(requested_user) | ||
rescue ZendeskAPI::Error::ClientError => e | ||
exception_notification_for(e) | ||
end | ||
|
||
private | ||
|
||
def support_api | ||
GdsApi::SupportApi.new( | ||
Plek.find("support-api"), | ||
bearer_token: ENV["SUPPORT_API_BEARER_TOKEN"], | ||
) | ||
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
105 changes: 0 additions & 105 deletions
105
app/models/support/requests/accounts_permissions_and_training_request.rb
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
app/models/support/requests/change_existing_user_request.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,50 @@ | ||
module Support | ||
module Requests | ||
class ChangeExistingUserRequest < Request | ||
attr_accessor :requested_user, | ||
:additional_comments | ||
|
||
validate do |request| | ||
if request.requested_user && !request.requested_user.valid? | ||
errors.add :base, message: "The details of the user in question are either incomplete or invalid." | ||
end | ||
end | ||
validates :requested_user, presence: true | ||
validates :additional_comments, presence: true | ||
|
||
def requested_user_attributes=(attr) | ||
self.requested_user = Support::GDS::RequestedUser.new(attr) | ||
end | ||
|
||
def initialize(attrs = {}) | ||
self.requested_user = Support::GDS::RequestedUser.new | ||
|
||
super | ||
end | ||
|
||
def action | ||
"change_user" | ||
end | ||
|
||
def for_new_user? | ||
false | ||
end | ||
|
||
def formatted_action | ||
"Change an existing user's account" | ||
end | ||
|
||
def inside_government_related? | ||
false | ||
end | ||
|
||
def self.label | ||
"Change an existing user's account" | ||
end | ||
|
||
def self.description | ||
"Request changes to an existing user's account." | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.