Skip to content

Commit 1d103e0

Browse files
authored
Merge pull request #201 from docusign/feature/delete-restore-envelope
Delete and Restore an Envelope
2 parents 6c6638c + bb5d135 commit 1d103e0

File tree

10 files changed

+342
-148
lines changed

10 files changed

+342
-148
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../../services/utils'
4+
5+
class ESign::Eeg045DeleteRestoreEnvelopeController < EgController
6+
before_action -> { check_auth('eSignature') }
7+
before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 45, 'eSignature') }
8+
9+
DELETE_FOLDER_ID = 'recyclebin'
10+
11+
def delete_envelope
12+
args = {
13+
account_id: session['ds_account_id'],
14+
base_path: session['ds_base_path'],
15+
access_token: session['ds_access_token'],
16+
envelope_id: param_gsub(params['envelope_id']),
17+
delete_folder_id: DELETE_FOLDER_ID
18+
}
19+
20+
delete_restore_envelope_service = ESign::Eg045DeleteRestoreEnvelopeService.new
21+
22+
delete_restore_envelope_service.delete_envelope args
23+
24+
session[:envelope_id] = args[:envelope_id]
25+
additional_page_data = @example['AdditionalPage'].find { |p| p['Name'] == 'envelope_is_deleted' }
26+
@title = @example['ExampleName']
27+
@message = format_string(additional_page_data['ResultsPageText'], args[:envelope_id])
28+
@redirect_url = "/#{session[:eg]}restore"
29+
30+
render 'ds_common/example_done'
31+
end
32+
33+
def restore_envelope
34+
folder_name = param_gsub(params['folder_name'])
35+
args = {
36+
account_id: session['ds_account_id'],
37+
base_path: session['ds_base_path'],
38+
access_token: session['ds_access_token'],
39+
envelope_id: param_gsub(session[:envelope_id]),
40+
from_folder_id: DELETE_FOLDER_ID
41+
}
42+
43+
delete_restore_envelope_service = ESign::Eg045DeleteRestoreEnvelopeService.new
44+
45+
folders = delete_restore_envelope_service.get_folders args
46+
args[:folder_id] = Utils::DocuSignUtils.new.get_folder_id_by_name(folders.folders, folder_name)
47+
48+
if args[:folder_id].nil? || args[:folder_id].empty?
49+
additional_page_data = @example['AdditionalPage'].find { |p| p['Name'] == 'folder_does_not_exist' }
50+
@title = @example['ExampleName']
51+
@message = format_string(additional_page_data['ResultsPageText'], folder_name)
52+
@redirect_url = "/#{session[:eg]}restore"
53+
54+
return render 'ds_common/example_done'
55+
end
56+
57+
delete_restore_envelope_service.move_envelope_to_folder args
58+
59+
session[:envelope_id] = args[:envelope_id]
60+
@title = @example['ExampleName']
61+
@message = format_string(@example['ResultsPageText'], session[:envelope_id], args[:folder_id], folder_name)
62+
render 'ds_common/example_done'
63+
end
64+
65+
def get_delete_envelope
66+
get
67+
@envelope_id = session[:envelope_id]
68+
@submit_button_text = @manifest['SupportingTexts']['HelpingTexts']['SubmitButtonDeleteText']
69+
70+
render 'e_sign/eeg045_delete_restore_envelope/delete'
71+
end
72+
73+
def get_restore_envelope
74+
return redirect_to "/#{session[:eg]}" if session[:envelope_id].nil?
75+
76+
get
77+
@envelope_id = session[:envelope_id]
78+
@submit_button_text = @manifest['SupportingTexts']['HelpingTexts']['SubmitButtonRestoreText']
79+
80+
render 'e_sign/eeg045_delete_restore_envelope/restore'
81+
end
82+
end

app/services/api_creator.rb

Lines changed: 60 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,60 @@
1-
# frozen_string_literal: true
2-
3-
module ApiCreator
4-
def create_initial_api_client(host: nil, client_module: DocuSign_eSign, debugging: false)
5-
configuration = client_module::Configuration.new
6-
configuration.debugging = debugging
7-
api_client = client_module::ApiClient.new(configuration)
8-
api_client.set_oauth_base_path(host)
9-
api_client
10-
end
11-
12-
def create_account_api(args)
13-
# Obtain your OAuth token
14-
configuration = DocuSign_eSign::Configuration.new
15-
configuration.host = args[:base_path]
16-
api_client = DocuSign_eSign::ApiClient.new configuration
17-
18-
# Construct your API headers
19-
api_client.default_headers['Authorization'] = "Bearer #{args[:access_token]}"
20-
21-
# Construct your request body
22-
DocuSign_eSign::AccountsApi.new api_client
23-
end
24-
25-
def create_template_api(args)
26-
configuration = DocuSign_eSign::Configuration.new
27-
configuration.host = args[:base_path]
28-
api_client = DocuSign_eSign::ApiClient.new configuration
29-
api_client.default_headers['Authorization'] = "Bearer #{args[:access_token]}"
30-
DocuSign_eSign::TemplatesApi.new api_client
31-
end
32-
33-
def create_envelope_api(args)
34-
# Obtain your OAuth token
35-
#ds-snippet-start:eSignRubyStep2
36-
configuration = DocuSign_eSign::Configuration.new
37-
configuration.host = args[:base_path]
38-
api_client = DocuSign_eSign::ApiClient.new configuration
39-
40-
api_client.default_headers['Authorization'] = "Bearer #{args[:access_token]}"
41-
#ds-snippet-end:eSignRubyStep2
42-
DocuSign_eSign::EnvelopesApi.new api_client
43-
end
44-
45-
def create_group_api(args)
46-
configuration = DocuSign_eSign::Configuration.new
47-
configuration.host = args[:base_path]
48-
api_client = DocuSign_eSign::ApiClient.new configuration
49-
api_client.default_headers['Authorization'] = "Bearer #{args[:access_token]}"
50-
DocuSign_eSign::GroupsApi.new api_client
51-
end
52-
end
1+
# frozen_string_literal: true
2+
3+
module ApiCreator
4+
def create_initial_api_client(host: nil, client_module: DocuSign_eSign, debugging: false)
5+
configuration = client_module::Configuration.new
6+
configuration.debugging = debugging
7+
api_client = client_module::ApiClient.new(configuration)
8+
api_client.set_oauth_base_path(host)
9+
api_client
10+
end
11+
12+
def create_account_api(args)
13+
# Obtain your OAuth token
14+
configuration = DocuSign_eSign::Configuration.new
15+
configuration.host = args[:base_path]
16+
api_client = DocuSign_eSign::ApiClient.new configuration
17+
18+
# Construct your API headers
19+
api_client.default_headers['Authorization'] = "Bearer #{args[:access_token]}"
20+
21+
# Construct your request body
22+
DocuSign_eSign::AccountsApi.new api_client
23+
end
24+
25+
def create_template_api(args)
26+
configuration = DocuSign_eSign::Configuration.new
27+
configuration.host = args[:base_path]
28+
api_client = DocuSign_eSign::ApiClient.new configuration
29+
api_client.default_headers['Authorization'] = "Bearer #{args[:access_token]}"
30+
DocuSign_eSign::TemplatesApi.new api_client
31+
end
32+
33+
def create_envelope_api(args)
34+
# Obtain your OAuth token
35+
#ds-snippet-start:eSignRubyStep2
36+
configuration = DocuSign_eSign::Configuration.new
37+
configuration.host = args[:base_path]
38+
api_client = DocuSign_eSign::ApiClient.new configuration
39+
40+
api_client.default_headers['Authorization'] = "Bearer #{args[:access_token]}"
41+
#ds-snippet-end:eSignRubyStep2
42+
DocuSign_eSign::EnvelopesApi.new api_client
43+
end
44+
45+
def create_group_api(args)
46+
configuration = DocuSign_eSign::Configuration.new
47+
configuration.host = args[:base_path]
48+
api_client = DocuSign_eSign::ApiClient.new configuration
49+
api_client.default_headers['Authorization'] = "Bearer #{args[:access_token]}"
50+
DocuSign_eSign::GroupsApi.new api_client
51+
end
52+
53+
def create_folders_api(args)
54+
configuration = DocuSign_eSign::Configuration.new
55+
configuration.host = args[:base_path]
56+
api_client = DocuSign_eSign::ApiClient.new configuration
57+
api_client.default_headers['Authorization'] = "Bearer #{args[:access_token]}"
58+
DocuSign_eSign::FoldersApi.new api_client
59+
end
60+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
class ESign::Eg045DeleteRestoreEnvelopeService
4+
include ApiCreator
5+
6+
def delete_envelope(args)
7+
#ds-snippet-start:eSign45Step2
8+
folders_api = create_folders_api(args)
9+
#ds-snippet-end:eSign45Step2
10+
11+
#ds-snippet-start:eSign45Step3
12+
folders_request = DocuSign_eSign::FoldersRequest.new
13+
folders_request.envelope_ids = [args[:envelope_id]]
14+
#ds-snippet-end:eSign45Step3
15+
16+
#ds-snippet-start:eSign45Step4
17+
folders_api.move_envelopes(args[:account_id], args[:delete_folder_id], folders_request)
18+
#ds-snippet-end:eSign45Step4
19+
end
20+
21+
def move_envelope_to_folder(args)
22+
folders_api = create_folders_api(args)
23+
24+
#ds-snippet-start:eSign45Step6
25+
folders_request = DocuSign_eSign::FoldersRequest.new
26+
folders_request.envelope_ids = [args[:envelope_id]]
27+
folders_request.from_folder_id = args[:from_folder_id]
28+
29+
folders_api.move_envelopes(args[:account_id], args[:folder_id], folders_request)
30+
#ds-snippet-end:eSign45Step6
31+
end
32+
33+
def get_folders(args)
34+
folders_api = create_folders_api(args)
35+
36+
#ds-snippet-start:eSign45Step5
37+
folders_api.list(args[:account_id])
38+
#ds-snippet-end:eSign45Step5
39+
end
40+
end

app/services/utils.rb

Lines changed: 69 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,69 @@
1-
module Utils
2-
class ManifestUtils
3-
def get_manifest(manifest_url)
4-
uri = URI(manifest_url)
5-
res = Net::HTTP.get_response(uri)
6-
JSON.parse(res.body)
7-
end
8-
9-
def get_example(manifest, number, api_name = 'eSignature')
10-
manifest['APIs'].each do |api|
11-
next unless api_name == api['Name']
12-
13-
api['Groups'].each do |group|
14-
group['Examples'].each do |example|
15-
return example if example['ExampleNumber'] == number
16-
end
17-
end
18-
end
19-
end
20-
end
21-
22-
class DocuSignUtils
23-
def get_user_id(args)
24-
configuration = DocuSign_eSign::Configuration.new
25-
configuration.host = args[:base_path]
26-
api_client = DocuSign_eSign::ApiClient.new configuration
27-
api_client.set_base_path(args[:base_path])
28-
api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
29-
user_info = api_client.get_user_info(args[:access_token])
30-
user_info.sub
31-
end
32-
end
33-
34-
class FileUtils
35-
def replace_template_id(file_path, template_id)
36-
content = File.read(file_path)
37-
38-
content.gsub!('template-id', template_id)
39-
40-
File.write(file_path, content)
41-
end
42-
end
43-
44-
class URLUtils
45-
def get_parameter_value_from_url(url, param_name)
46-
parsed_url = URI.parse(url)
47-
query_params = URI.decode_www_form(parsed_url.query || '')
48-
49-
# Access the parameter value (returns a list)
50-
param_value_list = query_params.assoc(param_name)
51-
52-
# If the parameter exists, return the first value; otherwise, return nil
53-
param_value_list ? param_value_list[1] : nil
54-
end
55-
end
56-
end
1+
module Utils
2+
class ManifestUtils
3+
def get_manifest(manifest_url)
4+
uri = URI(manifest_url)
5+
res = Net::HTTP.get_response(uri)
6+
JSON.parse(res.body)
7+
end
8+
9+
def get_example(manifest, number, api_name = 'eSignature')
10+
manifest['APIs'].each do |api|
11+
next unless api_name == api['Name']
12+
13+
api['Groups'].each do |group|
14+
group['Examples'].each do |example|
15+
return example if example['ExampleNumber'] == number
16+
end
17+
end
18+
end
19+
end
20+
end
21+
22+
class DocuSignUtils
23+
def get_user_id(args)
24+
configuration = DocuSign_eSign::Configuration.new
25+
configuration.host = args[:base_path]
26+
api_client = DocuSign_eSign::ApiClient.new configuration
27+
api_client.set_base_path(args[:base_path])
28+
api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
29+
user_info = api_client.get_user_info(args[:access_token])
30+
user_info.sub
31+
end
32+
33+
def get_folder_id_by_name(folders, folder_name)
34+
folders.each do |folder|
35+
return folder.folder_id if folder.name.downcase == folder_name.downcase
36+
37+
if folder.folders&.any?
38+
folder_id = get_folder_id_by_name(folder.folders, folder_name)
39+
return folder_id if folder_id
40+
end
41+
end
42+
43+
nil
44+
end
45+
end
46+
47+
class FileUtils
48+
def replace_template_id(file_path, template_id)
49+
content = File.read(file_path)
50+
51+
content.gsub!('template-id', template_id)
52+
53+
File.write(file_path, content)
54+
end
55+
end
56+
57+
class URLUtils
58+
def get_parameter_value_from_url(url, param_name)
59+
parsed_url = URI.parse(url)
60+
query_params = URI.decode_www_form(parsed_url.query || '')
61+
62+
# Access the parameter value (returns a list)
63+
param_value_list = query_params.assoc(param_name)
64+
65+
# If the parameter exists, return the first value; otherwise, return nil
66+
param_value_list ? param_value_list[1] : nil
67+
end
68+
end
69+
end

app/services/webforms/eg002_create_remote_instance_service.rb

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,20 @@ def create_web_form_instance(form_id)
5757
'Company' => 'Tally',
5858
'JobTitle' => 'Programmer Writer'
5959
}
60-
recipient = DocuSign_WebForms::CreateInstanceRequestBodyRecipients.new({
61-
'roleName' => 'signer',
62-
'name' => args[:signer_name],
63-
'email' => args[:signer_email]
64-
})
65-
web_form_req_object = DocuSign_WebForms::CreateInstanceRequestBody.new({
66-
'formValues' => web_form_values,
67-
'recipients' => [recipient],
68-
'sendOption' => 'now'
69-
})
60+
recipient = DocuSign_WebForms::CreateInstanceRequestBodyRecipients.new(
61+
{
62+
'roleName' => 'signer',
63+
'name' => args[:signer_name],
64+
'email' => args[:signer_email]
65+
}
66+
)
67+
web_form_req_object = DocuSign_WebForms::CreateInstanceRequestBody.new(
68+
{
69+
'formValues' => web_form_values,
70+
'recipients' => [recipient],
71+
'sendOption' => 'now'
72+
}
73+
)
7074
#ds-snippet-end:WebForms2Step4
7175

7276
#ds-snippet-start:WebForms2Step5

0 commit comments

Comments
 (0)