@@ -54,19 +54,27 @@ def render_page(page)
5454 end
5555
5656 def root_route ( req )
57- if TinyAdmin . settings . root [ :redirect ]
58- req . redirect route_for ( TinyAdmin . settings . root [ :redirect ] )
57+ if authorization . allowed? ( current_user , :root )
58+ if TinyAdmin . settings . root [ :redirect ]
59+ req . redirect route_for ( TinyAdmin . settings . root [ :redirect ] )
60+ else
61+ page_class = to_class ( TinyAdmin . settings . root [ :page ] )
62+ attributes = TinyAdmin . settings . root . slice ( :content , :title , :widgets )
63+ render_page prepare_page ( page_class , attributes : attributes , params : request . params )
64+ end
5965 else
60- page_class = to_class ( TinyAdmin . settings . root [ :page ] )
61- attributes = TinyAdmin . settings . root . slice ( :content , :title , :widgets )
62- render_page prepare_page ( page_class , attributes : attributes , params : request . params )
66+ render_page prepare_page ( TinyAdmin . settings . page_not_allowed )
6367 end
6468 end
6569
6670 def setup_page_route ( req , slug , page_data )
6771 req . get slug do
68- attributes = page_data . slice ( :content , :title , :widgets )
69- render_page prepare_page ( page_data [ :class ] , slug : slug , attributes : attributes , params : request . params )
72+ if authorization . allowed? ( current_user , :page , slug )
73+ attributes = page_data . slice ( :content , :title , :widgets )
74+ render_page prepare_page ( page_data [ :class ] , slug : slug , attributes : attributes , params : request . params )
75+ else
76+ render_page prepare_page ( TinyAdmin . settings . page_not_allowed )
77+ end
7078 end
7179 end
7280
@@ -93,15 +101,19 @@ def setup_collection_routes(req, slug, options:)
93101 # Index
94102 if options [ :only ] . include? ( :index ) || options [ :only ] . include? ( 'index' )
95103 req . is do
96- context = Context . new (
97- actions : custom_actions ,
98- repository : repository ,
99- request : request ,
100- router : req ,
101- slug : slug
102- )
103- index_action = TinyAdmin ::Actions ::Index . new
104- render_page index_action . call ( app : self , context : context , options : action_options )
104+ if authorization . allowed? ( current_user , :resource_index , slug )
105+ context = Context . new (
106+ actions : custom_actions ,
107+ repository : repository ,
108+ request : request ,
109+ router : req ,
110+ slug : slug
111+ )
112+ index_action = TinyAdmin ::Actions ::Index . new
113+ render_page index_action . call ( app : self , context : context , options : action_options )
114+ else
115+ render_page prepare_page ( TinyAdmin . settings . page_not_allowed )
116+ end
105117 end
106118 end
107119 end
@@ -124,16 +136,20 @@ def setup_member_routes(req, slug, options:)
124136 # Show
125137 if options [ :only ] . include? ( :show ) || options [ :only ] . include? ( 'show' )
126138 req . is do
127- context = Context . new (
128- actions : custom_actions ,
129- reference : reference ,
130- repository : repository ,
131- request : request ,
132- router : req ,
133- slug : slug
134- )
135- show_action = TinyAdmin ::Actions ::Show . new
136- render_page show_action . call ( app : self , context : context , options : action_options )
139+ if authorization . allowed? ( current_user , :resource_show , slug )
140+ context = Context . new (
141+ actions : custom_actions ,
142+ reference : reference ,
143+ repository : repository ,
144+ request : request ,
145+ router : req ,
146+ slug : slug
147+ )
148+ show_action = TinyAdmin ::Actions ::Show . new
149+ render_page show_action . call ( app : self , context : context , options : action_options )
150+ else
151+ render_page prepare_page ( TinyAdmin . settings . page_not_allowed )
152+ end
137153 end
138154 end
139155 end
@@ -145,20 +161,28 @@ def setup_custom_actions(req, custom_actions = nil, options:, repository:, slug:
145161 action_class = to_class ( action )
146162
147163 req . get action_slug . to_s do
148- context = Context . new (
149- actions : { } ,
150- reference : reference ,
151- repository : repository ,
152- request : request ,
153- router : req ,
154- slug : slug
155- )
156- custom_action = action_class . new
157- render_page custom_action . call ( app : self , context : context , options : options )
164+ if authorization . allowed? ( current_user , :custom_action , action_slug . to_s )
165+ context = Context . new (
166+ actions : { } ,
167+ reference : reference ,
168+ repository : repository ,
169+ request : request ,
170+ router : req ,
171+ slug : slug
172+ )
173+ custom_action = action_class . new
174+ render_page custom_action . call ( app : self , context : context , options : options )
175+ else
176+ render_page prepare_page ( TinyAdmin . settings . page_not_allowed )
177+ end
158178 end
159179
160180 result [ action_slug . to_s ] = action_class
161181 end
162182 end
183+
184+ def authorization
185+ TinyAdmin . settings . authorization_class
186+ end
163187 end
164188end
0 commit comments