Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow the user to skip notifying email #122

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions lib/globus_client/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ class Endpoint # rubocop:disable Metrics/ClassLength
# @param client [GlobusClient] a configured instance of the GlobusClient
# @param path [String] the path to operate on
# @param user_id [String] a Globus user ID (e.g., a @stanford.edu email address)
def initialize(client, path:, user_id:)
# @param notify_email [Boolean] indicates if we should ask Globus to send emails on access change (default: true)
def initialize(client, path:, user_id:, notify_email: true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a new @param YARD doc above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch - added

@client = client
@user_id = user_id
@path = path
@notify_email = notify_email
end

def has_files?
Expand Down Expand Up @@ -63,7 +65,7 @@ def delete_access_rule

private

attr_reader :client, :path, :user_id
attr_reader :client, :path, :user_id, :notify_email

def globus_identity_id
Identity.new(client).get_identity_id(user_id)
Expand Down Expand Up @@ -129,17 +131,18 @@ def access_request(permissions:)
if access_rule_id
update_access_request(permissions:)
else
body = {
DATA_TYPE: 'access',
principal_type: 'identity',
principal: globus_identity_id,
path: full_path,
permissions:
}
body[:notify_email] = user_id if notify_email
client.post(
base_url: client.config.transfer_url,
path: access_path,
body: {
DATA_TYPE: 'access',
principal_type: 'identity',
principal: globus_identity_id,
path: full_path,
permissions:,
notify_email: user_id
}
body:
)
end
end
Expand Down
69 changes: 69 additions & 0 deletions spec/globus_client/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -949,4 +949,73 @@
end
end
end

context 'with notify email setting' do
subject(:endpoint) { described_class.new(client, user_id:, path:, notify_email:) }

let(:fake_identity) { instance_double(GlobusClient::Identity, get_identity_id: 'example') }
let(:access_list_response) do
{
DATA_TYPE: 'access_list',
endpoint: transfer_endpoint_id,
DATA: [
{
DATA_TYPE: 'access',
create_time: '2022-11-22T16:08:24+00:00',
id: 'e3ee1ec2-6a7f-11ed-b0bd-bfe7e7197080',
path: '/foo/bar/',
permissions: 'rw',
principal: 'ae3e3f70-4065-408b-9cd8-39dc01b07d29',
principal_type: 'identity',
role_id: nil,
role_type: nil
}
]
}
end

before do
allow(GlobusClient::Identity).to receive(:new).and_return(fake_identity)
allow(client).to receive(:post)
stub_request(:get, "#{transfer_url}/v0.10/endpoint/#{transfer_endpoint_id}/access_list")
.to_return(status: 200, body: access_list_response.to_json)
end

context 'when notify_email is false' do
let(:notify_email) { false }
let(:params) do
{ base_url: 'https://transfer.api.example.org',
body: { DATA_TYPE: 'access',
path: '/uploads/example/work123/version1/',
permissions: 'rw',
principal: 'example',
principal_type: 'identity' },
path: '/v0.10/endpoint/NOT_A_REAL_ENDPOINT/access' }
end

it 'leaves off notify_email parameter for when setting access' do
endpoint.allow_writes
expect(client).to have_received(:post).with(params)
end
end

context 'when notify_email is true' do
let(:notify_email) { true }
let(:params) do
{ base_url: 'https://transfer.api.example.org',
body: { DATA_TYPE: 'access',
notify_email: '[email protected]',
path: '/uploads/example/work123/version1/',
permissions: 'rw',
principal: 'example',
principal_type: 'identity' },
path: '/v0.10/endpoint/NOT_A_REAL_ENDPOINT/access' }
end

it 'adds notify_email parameter for when setting access' do
endpoint.allow_writes
expect(client).to have_received(:post).with(params)
end
end
end
end