File tree Expand file tree Collapse file tree 3 files changed +16
-9
lines changed Expand file tree Collapse file tree 3 files changed +16
-9
lines changed Original file line number Diff line number Diff line change 1+ require 'errors/forbidden_path_error'
2+
13class ApplicationController < ActionController ::API
24 include CanCan ::ControllerAdditions
35
46 rescue_from CanCan ::AccessDenied , with : :not_authorized
57 rescue_from ActiveRecord ::RecordNotFound , :with => :not_found
8+ rescue_from ForbiddenPathError , :with => :forbidden
69
710 before_filter :fetch_team
811
@@ -24,6 +27,10 @@ def current_team_membership
2427 TeamMembership . find_by! ( user : current_user , team : current_team ) if current_team . present?
2528 end
2629
30+ def restrict_to_team_subdomain
31+ raise ForbiddenPathError , "Resource not allowed" unless has_team_subdomain?
32+ end
33+
2734 private
2835
2936 def has_team_subdomain?
Original file line number Diff line number Diff line change 66class PagesController < ApplicationController
77 acts_as_token_authentication_handler_for User , fallback_to_devise : false
88
9+ before_filter :restrict_to_team_subdomain
10+
911 def index
1012 authorize! :read , Page
1113
@@ -29,16 +31,12 @@ def create
2931 end
3032
3133 def update
32- if has_team_subdomain?
33- authorize! :update , current_page
34- page = TeamPlaybook ::Scenario ::UpdatePage . new . call ( page : current_page , page_params : page_params )
35- if page . valid?
36- render json : page , status : 200
37- else
38- render json : { error : page . errors . full_messages . to_sentence } , status : :unprocessable_entity
39- end
34+ authorize! :update , current_page
35+ page = TeamPlaybook ::Scenario ::UpdatePage . new . call ( page : current_page , page_params : page_params )
36+ if page . valid?
37+ render json : page , status : 200
4038 else
41- forbidden
39+ render json : { error : page . errors . full_messages . to_sentence } , status : :unprocessable_entity
4240 end
4341 end
4442
Original file line number Diff line number Diff line change 1+ class ForbiddenPathError < StandardError
2+ end
You can’t perform that action at this time.
0 commit comments