Skip to content
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ groups.page(2,3) {|group|

## Perform actions on behalf of another user

As described in the [Zammad API documentation](https://docs.zammad.org/en/latest/api-intro.html#example-curl-request-on-behalf-of-a-different-user) it is possible to perfom actions on behalf other users. To use this feature you can set the attribute of the client accordingly:
As described in the [Zammad API documentation](https://docs.zammad.org/en/latest/api/intro.html#actions-on-behalf-of-other-users) it is possible to perfom actions on behalf other users. To use this feature you can set the attribute of the client accordingly:

> **Note:** This feature requires Zammad 5.0 or later, since the client sends the standard HTTP `From` header instead of the deprecated `X-On-Behalf-Of` header (see [zammad/zammad#3113](https://github.com/zammad/zammad/issues/3113)).

```ruby
client.on_behalf_of = 'some_login'
Expand Down
2 changes: 1 addition & 1 deletion lib/zammad_api/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def run_request(verb, param)
end

if !on_behalf_of.nil?
req.headers['X-On-Behalf-Of'] = on_behalf_of
req.headers['From'] = on_behalf_of
end

yield(req) if block_given?
Expand Down
6 changes: 3 additions & 3 deletions spec/zammad_api/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

stub_request(:get, /#{config[:url]}/)
.with(headers: {
'X-On-Behalf-Of' => on_behalf_of_identifier
'From' => on_behalf_of_identifier
})
.to_return(status: 200, body: '{}', headers: {})

Expand All @@ -80,7 +80,7 @@

stub_request(:get, /#{config[:url]}/)
.with(headers: {
'X-On-Behalf-Of' => on_behalf_of_identifier
'From' => on_behalf_of_identifier
})
.to_return(status: 200, body: '{}', headers: {})

Expand All @@ -101,7 +101,7 @@ def request_pattern.matches?(request_signature)
return false if !super
return true if request_signature.headers.empty?

!request_signature.headers.key?('X-On-Behalf-Of')
!request_signature.headers.key?('From')
end

instance.user.find(1)
Expand Down
8 changes: 4 additions & 4 deletions spec/zammad_api/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@
expect(instance).to respond_to(:on_behalf_of=)
end

it 'sets X-On-Behalf-Of header' do
it 'sets From header' do
on_behalf_of_identifier = 'some_login'

instance.on_behalf_of = on_behalf_of_identifier

stub_request(:get, "#{config[:url]}some/path")
.with(headers: {
'X-On-Behalf-Of' => on_behalf_of_identifier
'From' => on_behalf_of_identifier
})
.to_return(status: 200, body: '', headers: {})

instance.get(url: '/some/path')
end

it 'unsets X-On-Behalf-Of header' do
it 'unsets From header' do
on_behalf_of_identifier = 'some_login'

instance.on_behalf_of = on_behalf_of_identifier
Expand All @@ -71,7 +71,7 @@ def request_pattern.matches?(request_signature)
return false if !super
return true if request_signature.headers.empty?

!request_signature.headers.key?('X-On-Behalf-Of')
!request_signature.headers.key?('From')
end

instance.get(url: '/some/path')
Expand Down