@ -1,14 +1,23 @@ 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					// Copyright 2015 The Gogs Authors. All rights reserved.
  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					// Use of this source code is governed by a MIT-style
  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					// license that can be found in the LICENSE file.
  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					package  migrations  
					 
					 
					 
					package  migrations  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					import  (  
					 
					 
					 
					import  (  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						"errors"   
					 
					 
					 
						"errors"   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						"strconv "   
					 
					 
					 
						"fmt "   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
						"strings"   
					 
					 
					 
						"strings"   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						"time"   
					 
					 
					 
						"time"   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
						"github.com/Unknwon/com"   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						"github.com/go-xorm/xorm"   
					 
					 
					 
						"github.com/go-xorm/xorm"   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
						"github.com/gogits/gogs/modules/setting"   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					)  
					 
					 
					 
					)  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					const  _DB_VER  =  1  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					type  migration  func ( * xorm . Engine )  error  
					 
					 
					 
					type  migration  func ( * xorm . Engine )  error  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					// The version table. Should have only one row with id==1
  
					 
					 
					 
					// The version table. Should have only one row with id==1
  
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -26,39 +35,38 @@ var migrations = []migration{ 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					// Migrate database to current version
  
					 
					 
					 
					// Migrate database to current version
  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					func  Migrate ( x  * xorm . Engine )  error  {  
					 
					 
					 
					func  Migrate ( x  * xorm . Engine )  error  {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						if  err  :=  x . Sync ( new ( Version ) ) ;  err  !=  nil  {   
					 
					 
					 
						if  err  :=  x . Sync ( new ( Version ) ) ;  err  !=  nil  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							return  err   
					 
					 
					 
							return  fmt . Errorf ( "sync: %v" ,  err )   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
						}   
					 
					 
					 
						}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						currentVersion  :=  & Version { Id :  1 }   
					 
					 
					 
						currentVersion  :=  & Version { Id :  1 }   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						has ,  err  :=  x . Get ( currentVersion )   
					 
					 
					 
						has ,  err  :=  x . Get ( currentVersion )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						if  err  !=  nil  {   
					 
					 
					 
						if  err  !=  nil  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							return  err   
					 
					 
					 
							return  fmt . Errorf ( "get: %v" ,  err )   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
						}  else  if  ! has  {   
					 
					 
					 
						}  else  if  ! has  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							needsMigration ,  err  :=  x . IsTableExist ( "user" )   
					 
					 
					 
							needsMigration ,  err  :=  x . IsTableExist ( "user" )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							if  err  !=  nil  {   
					 
					 
					 
							if  err  !=  nil  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								return  err   
					 
					 
					 
								return  err   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							}   
					 
					 
					 
							}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							if  needsMigration  {   
					 
					 
					 
							// if needsMigration {
   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								isEmpty ,  err  :=  x . IsTableEmpty ( "user" )    
					 
					 
					 
							// 	isEmpty, err := x.IsTableEmpty("user")
   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								if  err  !=  nil  {    
					 
					 
					 
							// 	if err != nil {
   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
									return  err    
					 
					 
					 
							// 		return err
   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								}    
					 
					 
					 
							// 	}
   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								needsMigration  =  ! isEmpty    
					 
					 
					 
							// 	needsMigration = !isEmpty
   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
							}   
					 
					 
					 
							// }
   
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
							if  ! needsMigration  {   
					 
					 
					 
							if  ! needsMigration  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								currentVersion . Version  =  int64 ( len ( migrations ) )   
					 
					 
					 
								currentVersion . Version  =  int64 ( len ( migrations ) )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							}   
					 
					 
					 
							}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							if  _ ,  err  =  x . InsertOne ( currentVersion ) ;  err  !=  nil  {   
					 
					 
					 
							if  _ ,  err  =  x . InsertOne ( currentVersion ) ;  err  !=  nil  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								return  err   
					 
					 
					 
								return  fmt . Errorf ( "insert: %v" ,  err )   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
							}   
					 
					 
					 
							}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						}   
					 
					 
					 
						}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						v  :=  currentVersion . Version   
					 
					 
					 
						v  :=  currentVersion . Version   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						for  i ,  migration  :=  range  migrations [ v : ]  {   
					 
					 
					 
						for  i ,  migration  :=  range  migrations [ v : ]  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							if  err  =  migration ( x ) ;  err  !=  nil  {   
					 
					 
					 
							if  err  =  migration ( x ) ;  err  !=  nil  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								return  err   
					 
					 
					 
								return  fmt . Errorf ( "run migration: %v" ,  err )   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
							}   
					 
					 
					 
							}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							currentVersion . Version  =  v  +  int64 ( i )  +  1   
					 
					 
					 
							currentVersion . Version  =  v  +  int64 ( i )  +  1   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							if  _ ,  err  =  x . Id ( 1 ) . Update ( currentVersion ) ;  err  !=  nil  {   
					 
					 
					 
							if  _ ,  err  =  x . Id ( 1 ) . Update ( currentVersion ) ;  err  !=  nil  {   
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -72,48 +80,48 @@ func expiredMigration(x *xorm.Engine) error { 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						return  errors . New ( "You are migrating from a too old gogs version" )   
					 
					 
					 
						return  errors . New ( "You are migrating from a too old gogs version" )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					}  
					 
					 
					 
					}  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					func  mustParseInt64 ( in  [ ] byte )  int64  {  
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						i ,  err  :=  strconv . ParseInt ( string ( in ) ,  10 ,  64 )   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						if  err  !=  nil  {   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							i  =  0   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						}   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						return  i   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					}  
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					func  accessToCollaboration ( x  * xorm . Engine )  error  {  
					 
					 
					 
					func  accessToCollaboration ( x  * xorm . Engine )  error  {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						type  Collaboration  struct  {   
					 
					 
					 
						type  Collaboration  struct  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							ID       int64  ` xorm:"pk autoincr" `   
					 
					 
					 
							ID       int64  ` xorm:"pk autoincr" `   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							RepoID   int64  ` xorm:"UNIQUE(s) INDEX NOT NULL" `   
					 
					 
					 
							RepoID   int64  ` xorm:"UNIQUE(s) INDEX NOT NULL" `   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							UserID   int64  ` xorm:"UNIQUE(s) INDEX NOT NULL" `   
					 
					 
					 
							UserID   int64  ` xorm:"UNIQUE(s) INDEX NOT NULL" `   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							Created  time . Time  ` xorm:"CREATED" `    
					 
					 
					 
							Created  time . Time   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
						}   
					 
					 
					 
						}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						x . Sync ( new ( Collaboration ) )   
					 
					 
					 
						x . Sync ( new ( Collaboration ) )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						sql  :=  ` SELECT u.id AS uid, a.repo_name AS repo, a.mode AS mode, a.created as created FROM access a JOIN user u ON a.user_name=u.lower_name `   
					 
					 
					 
						results ,  err  :=  x . Query ( "SELECT u.id AS `uid`, a.repo_name AS `repo`, a.mode AS `mode`, a.created as `created` FROM `access` a JOIN `user` u ON a.user_name=u.lower_name" )   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
						results ,  err  :=  x . Query ( sql )   
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
						if  err  !=  nil  {   
					 
					 
					 
						if  err  !=  nil  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							return  err   
					 
					 
					 
							return  err   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						}   
					 
					 
					 
						}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
						offset  :=  strings . Split ( time . Now ( ) . String ( ) ,  " " ) [ 2 ]   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						for  _ ,  result  :=  range  results  {   
					 
					 
					 
						for  _ ,  result  :=  range  results  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							userID  :=  mustParseInt64 ( result [ "uid" ] )   
					 
					 
					 
							mode  :=  com . StrTo ( result [ "mode" ] ) . MustInt64 ( )   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
							repoRefName  :=  string ( result [ "repo" ] )   
					 
					 
					 
							// Collaborators must have write access.
   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
							mode  :=  mustParseInt64 ( result [ "mode" ] )   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							created  :=  result [ "created" ]   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							//Collaborators must have write access
   
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
							if  mode  <  2  {   
					 
					 
					 
							if  mode  <  2  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								continue   
					 
					 
					 
								continue   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							}   
					 
					 
					 
							}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
							userID  :=  com . StrTo ( result [ "uid" ] ) . MustInt64 ( )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
							repoRefName  :=  string ( result [ "repo" ] )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
							var  created  time . Time   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
							switch  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
							case  setting . UseSQLite3 :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
								created ,  _  =  time . Parse ( time . RFC3339 ,  string ( result [ "created" ] ) )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
							case  setting . UseMySQL :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
								created ,  _  =  time . Parse ( "2006-01-02 15:04:05-0700" ,  string ( result [ "created" ] ) + offset )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
							case  setting . UsePostgreSQL :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
								created ,  _  =  time . Parse ( "2006-01-02T15:04:05Z-0700" ,  string ( result [ "created" ] ) + offset )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
							}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							// find owner of repository
   
					 
					 
					 
							// find owner of repository
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							parts  :=  strings . SplitN ( repoRefName ,  "/" ,  2 )   
					 
					 
					 
							parts  :=  strings . SplitN ( repoRefName ,  "/" ,  2 )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							ownerName  :=  parts [ 0 ]   
					 
					 
					 
							ownerName  :=  parts [ 0 ]   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							repoName  :=  parts [ 1 ]   
					 
					 
					 
							repoName  :=  parts [ 1 ]   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							sql  =  ` SELECT u.id as uid, ou.uid as memberid FROM user u LEFT JOIN org_user ou ON ou.org_id=u.id WHERE u.lower_name=? `   
					 
					 
					 
							results ,  err  :=  x . Query ( "SELECT u.id as `uid`, ou.uid as `memberid` FROM `user` u LEFT JOIN org_user ou ON ou.org_id=u.id WHERE u.lower_name=?" ,  ownerName )   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
							results ,  err  :=  x . Query ( sql ,  ownerName )   
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
							if  err  !=  nil  {   
					 
					 
					 
							if  err  !=  nil  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								return  err   
					 
					 
					 
								return  err   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							}   
					 
					 
					 
							}   
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -121,7 +129,7 @@ func accessToCollaboration(x *xorm.Engine) error { 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								continue   
					 
					 
					 
								continue   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							}   
					 
					 
					 
							}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							ownerID  :=  mustParseInt64 ( results [ 0 ] [ "uid" ] )   
					 
					 
					 
							ownerID  :=  com . StrTo ( results [ 0 ] [ "uid" ] ) . MustInt64 ( )   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
							if  ownerID  ==  userID  {   
					 
					 
					 
							if  ownerID  ==  userID  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								continue   
					 
					 
					 
								continue   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							}   
					 
					 
					 
							}   
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -129,7 +137,7 @@ func accessToCollaboration(x *xorm.Engine) error { 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							// test if user is member of owning organization
   
					 
					 
					 
							// test if user is member of owning organization
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							isMember  :=  false   
					 
					 
					 
							isMember  :=  false   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							for  _ ,  member  :=  range  results  {   
					 
					 
					 
							for  _ ,  member  :=  range  results  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								memberID  :=  mustParseInt64 ( member [ "memberid" ] )   
					 
					 
					 
								memberID  :=  com . StrTo ( member [ "memberid" ] ) . MustInt64 ( )   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
								// We can skip all cases that a user is member of the owning organization
   
					 
					 
					 
								// We can skip all cases that a user is member of the owning organization
   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								if  memberID  ==  userID  {   
					 
					 
					 
								if  memberID  ==  userID  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									isMember  =  true   
					 
					 
					 
									isMember  =  true   
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -139,8 +147,7 @@ func accessToCollaboration(x *xorm.Engine) error { 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								continue   
					 
					 
					 
								continue   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							}   
					 
					 
					 
							}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							sql  =  ` SELECT id FROM repository WHERE owner_id=? AND lower_name=? `   
					 
					 
					 
							results ,  err  =  x . Query ( "SELECT id FROM `repository` WHERE owner_id=? AND lower_name=?" ,  ownerID ,  repoName )   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
							results ,  err  =  x . Query ( sql ,  ownerID ,  repoName )   
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
							if  err  !=  nil  {   
					 
					 
					 
							if  err  !=  nil  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								return  err   
					 
					 
					 
								return  err   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							}   
					 
					 
					 
							}   
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -148,11 +155,11 @@ func accessToCollaboration(x *xorm.Engine) error { 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								continue   
					 
					 
					 
								continue   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							}   
					 
					 
					 
							}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							repoID  :=  results [ 0 ] [ "id" ]   
					 
					 
					 
							if  _ ,  err  =  x . InsertOne ( & Collaboration {   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					
  
					 
					 
					 
								UserID :   userID ,   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
							sql  =  ` INSERT INTO collaboration (user_id, repo_id, created) VALUES (?,?,?) `   
					 
					 
					 
								RepoID :   com . StrTo ( results [ 0 ] [ "id" ] ) . MustInt64 ( ) ,    
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
							_ ,  err  =  x . Exec ( sql ,  userID ,  repoID ,  created )   
					 
					 
					 
								Created :  created ,    
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
							if   err  !=  nil  {   
					 
					 
					 
							} ) ;   err  !=  nil  {   
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
								return  err   
					 
					 
					 
								return  err   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							}   
					 
					 
					 
							}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						}   
					 
					 
					 
						}