@@ -56,6 +56,28 @@ func (org *Organization) UnitPermission(ctx *Context, doerID int64, unitType uni
5656	return  perm .AccessModeNone 
5757}
5858
59+ func  GetOrganizationByParams (ctx  * Context ) {
60+ 	orgName  :=  ctx .Params (":org" )
61+ 
62+ 	var  err  error 
63+ 	ctx .Org .Organization , err  =  organization .GetOrgByName (orgName )
64+ 	if  err  !=  nil  {
65+ 		if  organization .IsErrOrgNotExist (err ) {
66+ 			redirectUserID , err  :=  user_model .LookupUserRedirect (orgName )
67+ 			if  err  ==  nil  {
68+ 				RedirectToUser (ctx , orgName , redirectUserID )
69+ 			} else  if  user_model .IsErrUserRedirectNotExist (err ) {
70+ 				ctx .NotFound ("GetUserByName" , err )
71+ 			} else  {
72+ 				ctx .ServerError ("LookupUserRedirect" , err )
73+ 			}
74+ 		} else  {
75+ 			ctx .ServerError ("GetUserByName" , err )
76+ 		}
77+ 		return 
78+ 	}
79+ }
80+ 
5981// HandleOrgAssignment handles organization assignment 
6082func  HandleOrgAssignment (ctx  * Context , args  ... bool ) {
6183	var  (
@@ -77,25 +99,13 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
7799		requireTeamAdmin  =  args [3 ]
78100	}
79101
80- 	orgName  :=  ctx .Params (":org" )
81- 
82102	var  err  error 
83- 	ctx .Org .Organization , err  =  organization .GetOrgByName (orgName )
84- 	if  err  !=  nil  {
85- 		if  organization .IsErrOrgNotExist (err ) {
86- 			redirectUserID , err  :=  user_model .LookupUserRedirect (orgName )
87- 			if  err  ==  nil  {
88- 				RedirectToUser (ctx , orgName , redirectUserID )
89- 			} else  if  user_model .IsErrUserRedirectNotExist (err ) {
90- 				ctx .NotFound ("GetUserByName" , err )
91- 			} else  {
92- 				ctx .ServerError ("LookupUserRedirect" , err )
93- 			}
94- 		} else  {
95- 			ctx .ServerError ("GetUserByName" , err )
96- 		}
97- 		return 
103+ 
104+ 	// if Organization is not defined, get it from params 
105+ 	if  ctx .Org .Organization  ==  nil  {
106+ 		GetOrganizationByParams (ctx )
98107	}
108+ 
99109	org  :=  ctx .Org .Organization 
100110
101111	// Handle Visibility 
0 commit comments