File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,35 @@ import (
64
64
"gopkg.in/macaron.v1"
65
65
)
66
66
67
+ func sudo () macaron.Handler {
68
+ return func (ctx * context.APIContext ) {
69
+ sudo := ctx .Query ("sudo" )
70
+ if len (sudo ) <= 0 {
71
+ sudo = ctx .Req .Header .Get ("Sudo" )
72
+ }
73
+
74
+ if len (sudo ) > 0 {
75
+ if ctx .User .IsAdmin {
76
+ user , err := models .GetUserByName (sudo )
77
+ if err != nil {
78
+ if models .IsErrUserNotExist (err ) {
79
+ ctx .Status (404 )
80
+ } else {
81
+ ctx .Error (500 , "GetUserByName" , err )
82
+ }
83
+ return
84
+ }
85
+ ctx .User = user
86
+ } else {
87
+ ctx .JSON (403 , map [string ]string {
88
+ "message" : "Only administrators allowed to sudo." ,
89
+ })
90
+ return
91
+ }
92
+ }
93
+ }
94
+ }
95
+
67
96
func repoAssignment () macaron.Handler {
68
97
return func (ctx * context.APIContext ) {
69
98
userName := ctx .Params (":username" )
@@ -589,5 +618,5 @@ func RegisterRoutes(m *macaron.Macaron) {
589
618
m .Group ("/topics" , func () {
590
619
m .Get ("/search" , repo .TopicSearch )
591
620
})
592
- }, context .APIContexter ())
621
+ }, context .APIContexter (), sudo () )
593
622
}
You can’t perform that action at this time.
0 commit comments