Skip to content

Commit b4e0448

Browse files
committed
#34 Removed all that fancy stuff I was trying to do with namespaced policies. Don't even bother.
1 parent 8b32cb6 commit b4e0448

File tree

12 files changed

+34
-304
lines changed

12 files changed

+34
-304
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
/**
2+
* This SASS file is used to create our Bootstrap 4 emails.
3+
* Keep in mind this is a Rails API application; we needed to uncomment `require 'sprockets/railtie'`
4+
* in `config/application.rb`
5+
*/
16
//noinspection CssUnknownTarget
27
@import 'bootstrap-email';

app/policies/api/v1/role_policy.rb

Lines changed: 0 additions & 35 deletions
This file was deleted.

app/policies/api/v1/session_activity_policy.rb

Lines changed: 0 additions & 25 deletions
This file was deleted.

app/policies/api/v1/session_policy.rb

Lines changed: 0 additions & 36 deletions
This file was deleted.

app/policies/api/v1/user_policy.rb

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# frozen_string_literal: true
22

3-
require 'namespaced_authorizing_processor'
4-
53
JSONAPI.configure do |config|
6-
# using a customer authorizing processor that applied namespace to all policies
7-
config.default_processor_klass = NamespacedAuthorizingProcessor
4+
config.default_processor_klass = JSONAPI::Authorization::AuthorizingProcessor
85
config.exception_class_whitelist = [JWTSessions::Errors::Unauthorized, Pundit::NotAuthorizedError]
96
end

test/controllers/cookie_authentications_controller_test.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,30 @@ class CookieAuthenticationsControllerTest < ActionDispatch::IntegrationTest
9393
assert mallory_archer.sessions.first.invalidated?
9494
assert mallory_archer.sessions.first.invalidated_by.present?
9595
end
96+
97+
test 'when access to the protected users index route is forbidden for a guest user' do
98+
Timecop.freeze
99+
100+
login(users(:sterling_archer))
101+
102+
Timecop.travel 30.seconds.from_now
103+
104+
get api_v1_users_url, headers: @headers
105+
106+
assert_response :forbidden
107+
assert_equal 'You are forbidden from performing this action', JSON.parse(response.body)['errors'].first['detail']
108+
end
109+
110+
test 'when access to the protected users index route is granted for an administrator user' do
111+
Timecop.freeze
112+
113+
login(users(:some_administrator))
114+
115+
Timecop.travel 30.seconds.from_now
116+
117+
get api_v1_users_url, headers: @headers
118+
119+
assert_response :ok
120+
assert_equal 5, JSON.parse(response.body)['data'].length
121+
end
96122
end

test/controllers/token_authentications_controller_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class TokenAuthenticationsControllerTest < ActionDispatch::IntegrationTest
8282
assert mallory_archer.sessions.first.invalidated_by.present?
8383
end
8484

85-
test 'when access to a protected resource with token authentication is forbidden' do
85+
test 'when access to the protected users index route is forbidden for a guest user' do
8686
Timecop.freeze
8787

8888
token(users(:sterling_archer))
@@ -95,7 +95,7 @@ class TokenAuthenticationsControllerTest < ActionDispatch::IntegrationTest
9595
assert_equal 'You are forbidden from performing this action', JSON.parse(response.body)['errors'].first['detail']
9696
end
9797

98-
test 'when accessing a protected resource with token authentication is permitted' do
98+
test 'when access to the protected users index route is granted for an administrator user' do
9999
Timecop.freeze
100100

101101
token(users(:some_administrator))

test/policies/api/v1/role_policy_test.rb

Lines changed: 0 additions & 34 deletions
This file was deleted.

test/policies/api/v1/session_activity_policy_test.rb

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)