This repository was archived by the owner on Apr 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -137,7 +137,8 @@ public final class AdminPanelProvider<U: AdminPanelUserType>: Provider {
137137 " adminpanel:sidebar:heading " : SidebarHeadingTag ( ) ,
138138 " adminpanel:sidebar:menuitem " : SidebarMenuItemTag ( ) ,
139139 " adminpanel:user " : CurrentUserTag < U > ( ) ,
140- " adminpanel:user:requireRole " : RequireRoleTag < U > ( )
140+ " adminpanel:user:requireRole " : RequireRoleTag < U > ( ) ,
141+ " adminpanel:user:roleAllows " : RoleAllowsTag < U > ( )
141142 ] )
142143
143144 return . done( on: container)
Original file line number Diff line number Diff line change 1+ import Leaf
2+ import Authentication
3+ import Sugar
4+
5+ public final class RoleAllowsTag < U: AdminPanelUserType > : TagRenderer {
6+ public func render( tag: TagContext ) throws -> Future < TemplateData > {
7+ try tag. requireParameterCount ( 1 )
8+
9+ let container = try tag. container. make (
10+ CurrentUserContainer< U> . self
11+ )
12+
13+ guard
14+ let roleString: String = tag. parameters [ 0 ] . string,
15+ let requiredRole = U . Role. init ( roleString)
16+ else {
17+ throw tag. error ( reason: " Invalid role requirement " )
18+ }
19+
20+ guard
21+ let userRole = container. user? . role
22+ else {
23+ return tag. future ( . bool( false ) )
24+ }
25+
26+ return tag. future ( . bool( userRole >= requiredRole) )
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments