Skip to content

Commit 05a97e8

Browse files
authored
Fixes #21 - Use 'From' instead of 'X-On-Behalf-Of'
2 parents b3a304a + bee6cec commit 05a97e8

4 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ groups.page(2,3) {|group|
183183

184184
## Perform actions on behalf of another user
185185

186-
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:
186+
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:
187+
188+
> **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)).
187189
188190
```ruby
189191
client.on_behalf_of = 'some_login'

‎lib/zammad_api/transport.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def run_request(verb, param)
5050
end
5151

5252
if !on_behalf_of.nil?
53-
req.headers['X-On-Behalf-Of'] = on_behalf_of
53+
req.headers['From'] = on_behalf_of
5454
end
5555

5656
yield(req) if block_given?

‎spec/zammad_api/client_spec.rb‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

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

@@ -80,7 +80,7 @@
8080

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

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

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

107107
instance.user.find(1)

‎spec/zammad_api/transport_spec.rb‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@
4040
expect(instance).to respond_to(:on_behalf_of=)
4141
end
4242

43-
it 'sets X-On-Behalf-Of header' do
43+
it 'sets From header' do
4444
on_behalf_of_identifier = 'some_login'
4545

4646
instance.on_behalf_of = on_behalf_of_identifier
4747

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

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

57-
it 'unsets X-On-Behalf-Of header' do
57+
it 'unsets From header' do
5858
on_behalf_of_identifier = 'some_login'
5959

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

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

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

0 commit comments

Comments
 (0)