Skip to content

Commit 294b67c

Browse files
committed
fix event log routing for accounts
1 parent fb819b5 commit 294b67c

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

app/serializers/event_log_serializer.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ class EventLogSerializer < BaseSerializer
9191

9292
if @object.resource_id.present? && @object.resource_type.present?
9393
link :related do
94-
@url_helpers.polymorphic_path [:v1, @object.account, @object.resource]
94+
if @object.resource == @object.account # event subject could be the account
95+
@url_helpers.polymorphic_path [:v1, @object.account]
96+
else
97+
@url_helpers.polymorphic_path [:v1, @object.account, @object.resource]
98+
end
9599
end
96100
end
97101
end

features/api/v1/event_logs/index.feature

+34-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ Feature: List event logs
77
| 9b96c003-85fa-40e8-a9ed-580491cd5d79 | Standard 1 |
88
| 44c7918c-80ab-4a13-a831-a2c46cda85c6 | Ent 1 |
99
Given the following "account" rows exist:
10-
| name | slug | plan_id |
11-
| Standard | standard | 9b96c003-85fa-40e8-a9ed-580491cd5d79 |
12-
| Ent | ent | 44c7918c-80ab-4a13-a831-a2c46cda85c6 |
10+
| id | name | slug | plan_id |
11+
| 99b7580f-d2fc-4b8f-8279-ec95fb523a17 | Standard | standard | 9b96c003-85fa-40e8-a9ed-580491cd5d79 |
12+
| c6c845b1-e9fa-4126-b89d-bdf32aa6d047 | Ent | ent | 44c7918c-80ab-4a13-a831-a2c46cda85c6 |
1313
And I send and accept JSON
1414

1515
Scenario: Endpoint should be inaccessible when account is not on Ent tier
@@ -33,11 +33,31 @@ Feature: List event logs
3333
Scenario: Admin retrieves all logs for their account
3434
Given I am an admin of account "ent"
3535
And the current account is "ent"
36-
And the current account has 3 "event-logs"
36+
And the following "event-type" rows exist:
37+
| id | event |
38+
| 1d721621-cbb5-4f4d-ae73-41d77a26276a | test.account.updated |
39+
| c257ce16-4f38-490e-8e4e-1be9ba1e8830 | test.license.created |
40+
| 8c312434-f8e9-402f-8169-49fc1409198e | test.license.updated |
41+
| 1e7c4ec0-127f-4691-b400-427333362176 | test.license.validation.succeeded |
42+
| 204590ba-b02e-4efd-ac32-5d1588932efa | test.license.validation.failed |
43+
And the current account has the following "license" rows:
44+
| id |
45+
| 19c0e512-d08a-408d-8d1a-6400baaf5a40 |
46+
And the current account has the following "event-log" rows:
47+
| whodunnit_type | whodunnit_id | event_type_id | resource_type | resource_id |
48+
| User | 97e58005-11ab-4186-aa78-c21550f6d0ce | c257ce16-4f38-490e-8e4e-1be9ba1e8830 | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 |
49+
| License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 | 1e7c4ec0-127f-4691-b400-427333362176 | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 |
50+
| Product | e37fa95d-7771-4e30-84be-acabdedc81ce | 8c312434-f8e9-402f-8169-49fc1409198e | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 |
51+
| License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 | 1e7c4ec0-127f-4691-b400-427333362176 | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 |
52+
| License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 | 1e7c4ec0-127f-4691-b400-427333362176 | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 |
53+
| | | 204590ba-b02e-4efd-ac32-5d1588932efa | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 |
54+
| User | 54a44eaf-6a83-4bb4-b3c1-17600dfdd77c | 8c312434-f8e9-402f-8169-49fc1409198e | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 |
55+
| User | 54a44eaf-6a83-4bb4-b3c1-17600dfdd77c | 8c312434-f8e9-402f-8169-49fc1409198e | Machine | 19ac6439-5576-4ba8-92cd-f4c17573159e |
56+
| User | 54a44eaf-6a83-4bb4-b3c1-17600dfdd77c | 1d721621-cbb5-4f4d-ae73-41d77a26276a | Account | c6c845b1-e9fa-4126-b89d-bdf32aa6d047 |
3757
And I use an authentication token
3858
When I send a GET request to "/accounts/ent/event-logs"
3959
Then the response status should be "200"
40-
And the response body should be an array with 3 "event-logs"
60+
And the response body should be an array with 9 "event-logs"
4161

4262
Scenario: Admin retrieves a list of logs that is automatically limited
4363
Given I am an admin of account "ent"
@@ -121,6 +141,7 @@ Feature: List event logs
121141
And the current account is "ent"
122142
And the following "event-type" rows exist:
123143
| id | event |
144+
| 1d721621-cbb5-4f4d-ae73-41d77a26276a | test.account.updated |
124145
| c257ce16-4f38-490e-8e4e-1be9ba1e8830 | test.license.created |
125146
| 8c312434-f8e9-402f-8169-49fc1409198e | test.license.updated |
126147
| 1e7c4ec0-127f-4691-b400-427333362176 | test.license.validation.succeeded |
@@ -137,6 +158,8 @@ Feature: List event logs
137158
| License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 | 1e7c4ec0-127f-4691-b400-427333362176 | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 |
138159
| | | 204590ba-b02e-4efd-ac32-5d1588932efa | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 |
139160
| User | 54a44eaf-6a83-4bb4-b3c1-17600dfdd77c | 8c312434-f8e9-402f-8169-49fc1409198e | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 |
161+
| User | 54a44eaf-6a83-4bb4-b3c1-17600dfdd77c | 8c312434-f8e9-402f-8169-49fc1409198e | Machine | 19ac6439-5576-4ba8-92cd-f4c17573159e |
162+
| User | 54a44eaf-6a83-4bb4-b3c1-17600dfdd77c | 1d721621-cbb5-4f4d-ae73-41d77a26276a | Account | c6c845b1-e9fa-4126-b89d-bdf32aa6d047 |
140163
And I use an authentication token
141164
When I send a GET request to "/accounts/ent/event-logs?whodunnit[type]=license&whodunnit[id]=19c0e512-d08a-408d-8d1a-6400baaf5a40"
142165
Then the response status should be "200"
@@ -147,6 +170,7 @@ Feature: List event logs
147170
And the current account is "ent"
148171
And the following "event-type" rows exist:
149172
| id | event |
173+
| 1d721621-cbb5-4f4d-ae73-41d77a26276a | test.account.updated |
150174
| c257ce16-4f38-490e-8e4e-1be9ba1e8830 | test.license.created |
151175
| 8c312434-f8e9-402f-8169-49fc1409198e | test.license.updated |
152176
| 1e7c4ec0-127f-4691-b400-427333362176 | test.license.validation.succeeded |
@@ -164,6 +188,7 @@ Feature: List event logs
164188
| License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 | 1e7c4ec0-127f-4691-b400-427333362176 | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 |
165189
| | | 204590ba-b02e-4efd-ac32-5d1588932efa | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 |
166190
| User | 54a44eaf-6a83-4bb4-b3c1-17600dfdd77c | 8c312434-f8e9-402f-8169-49fc1409198e | Machine | 19ac6439-5576-4ba8-92cd-f4c17573159e |
191+
| User | 54a44eaf-6a83-4bb4-b3c1-17600dfdd77c | 1d721621-cbb5-4f4d-ae73-41d77a26276a | Account | c6c845b1-e9fa-4126-b89d-bdf32aa6d047 |
167192
And I use an authentication token
168193
When I send a GET request to "/accounts/ent/event-logs?resource[type]=license&resource[id]=19c0e512-d08a-408d-8d1a-6400baaf5a40"
169194
Then the response status should be "200"
@@ -174,6 +199,7 @@ Feature: List event logs
174199
And the current account is "ent"
175200
And the following "event-type" rows exist:
176201
| id | event |
202+
| 1d721621-cbb5-4f4d-ae73-41d77a26276a | test.account.updated |
177203
| c257ce16-4f38-490e-8e4e-1be9ba1e8830 | test.license.created |
178204
| 8c312434-f8e9-402f-8169-49fc1409198e | test.license.updated |
179205
| 1e7c4ec0-127f-4691-b400-427333362176 | test.license.validation.succeeded |
@@ -192,6 +218,7 @@ Feature: List event logs
192218
| | | 204590ba-b02e-4efd-ac32-5d1588932efa | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 |
193219
| | | 204590ba-b02e-4efd-ac32-5d1588932efa | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 |
194220
| User | 54a44eaf-6a83-4bb4-b3c1-17600dfdd77c | 8c312434-f8e9-402f-8169-49fc1409198e | Machine | 19ac6439-5576-4ba8-92cd-f4c17573159e |
221+
| User | 54a44eaf-6a83-4bb4-b3c1-17600dfdd77c | 1d721621-cbb5-4f4d-ae73-41d77a26276a | Account | c6c845b1-e9fa-4126-b89d-bdf32aa6d047 |
195222
And I use an authentication token
196223
When I send a GET request to "/accounts/ent/event-logs?event=test.license.validation.failed"
197224
Then the response status should be "200"
@@ -202,6 +229,7 @@ Feature: List event logs
202229
And the current account is "ent"
203230
And the following "event-type" rows exist:
204231
| id | event |
232+
| 1d721621-cbb5-4f4d-ae73-41d77a26276a | test.account.updated |
205233
| c257ce16-4f38-490e-8e4e-1be9ba1e8830 | test.license.created |
206234
| 8c312434-f8e9-402f-8169-49fc1409198e | test.license.updated |
207235
| 1e7c4ec0-127f-4691-b400-427333362176 | test.license.validation.succeeded |
@@ -223,6 +251,7 @@ Feature: List event logs
223251
| | | 204590ba-b02e-4efd-ac32-5d1588932efa | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 | |
224252
| | | 204590ba-b02e-4efd-ac32-5d1588932efa | License | 19c0e512-d08a-408d-8d1a-6400baaf5a40 | |
225253
| User | 54a44eaf-6a83-4bb4-b3c1-17600dfdd77c | 8c312434-f8e9-402f-8169-49fc1409198e | Machine | 19ac6439-5576-4ba8-92cd-f4c17573159e | |
254+
| User | 54a44eaf-6a83-4bb4-b3c1-17600dfdd77c | 1d721621-cbb5-4f4d-ae73-41d77a26276a | Account | c6c845b1-e9fa-4126-b89d-bdf32aa6d047 | |
226255
And I use an authentication token
227256
When I send a GET request to "/accounts/ent/event-logs?request=97708dc6-9dd2-4de1-84be-24f50287296c"
228257
Then the response status should be "200"

0 commit comments

Comments
 (0)