@ -192,15 +192,15 @@ func (u *User) SetLastLogin() {
}
// UpdateUserDiffViewStyle updates the users diff view style
func UpdateUserDiffViewStyle ( u * User , style string ) error {
func UpdateUserDiffViewStyle ( ctx context . Context , u * User , style string ) error {
u . DiffViewStyle = style
return UpdateUserCols ( db . Defaul tConte xt , u , "diff_view_style" )
return UpdateUserCols ( c tx, u , "diff_view_style" )
}
// UpdateUserTheme updates a users' theme irrespective of the site wide theme
func UpdateUserTheme ( u * User , themeName string ) error {
func UpdateUserTheme ( ctx context . Context , u * User , themeName string ) error {
u . Theme = themeName
return UpdateUserCols ( db . Defaul tConte xt , u , "theme" )
return UpdateUserCols ( c tx, u , "theme" )
}
// GetPlaceholderEmail returns an noreply email
@ -218,9 +218,9 @@ func (u *User) GetEmail() string {
}
// GetAllUsers returns a slice of all individual users found in DB.
func GetAllUsers ( ) ( [ ] * User , error ) {
func GetAllUsers ( ctx context . Context ) ( [ ] * User , error ) {
users := make ( [ ] * User , 0 )
return users , db . GetEngine ( db . Defaul tConte xt ) . OrderBy ( "id" ) . Where ( "type = ?" , UserTypeIndividual ) . Find ( & users )
return users , db . GetEngine ( c tx) . OrderBy ( "id" ) . Where ( "type = ?" , UserTypeIndividual ) . Find ( & users )
}
// IsLocal returns true if user login type is LoginPlain.
@ -478,9 +478,9 @@ func (u *User) EmailNotifications() string {
}
// SetEmailNotifications sets the user's email notification preference
func SetEmailNotifications ( u * User , set string ) error {
func SetEmailNotifications ( ctx context . Context , u * User , set string ) error {
u . EmailNotificationsPreference = set
if err := UpdateUserCols ( db . Defaul tConte xt , u , "email_notifications_preference" ) ; err != nil {
if err := UpdateUserCols ( c tx, u , "email_notifications_preference" ) ; err != nil {
log . Error ( "SetEmailNotifications: %v" , err )
return err
}
@ -582,7 +582,7 @@ type CreateUserOverwriteOptions struct {
}
// CreateUser creates record of a new user.
func CreateUser ( u * User , overwriteDefault ... * CreateUserOverwriteOptions ) ( err error ) {
func CreateUser ( ctx context . Context , u * User , overwriteDefault ... * CreateUserOverwriteOptions ) ( err error ) {
if err = IsUsableUsername ( u . Name ) ; err != nil {
return err
}
@ -640,7 +640,7 @@ func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err e
return err
}
ctx , committer , err := db . TxContext ( db . Defaul tConte xt )
ctx , committer , err := db . TxContext ( c tx)
if err != nil {
return err
}
@ -711,8 +711,8 @@ type CountUserFilter struct {
}
// CountUsers returns number of users.
func CountUsers ( opts * CountUserFilter ) int64 {
return countUsers ( db . Defaul tConte xt , opts )
func CountUsers ( ctx context . Context , opts * CountUserFilter ) int64 {
return countUsers ( c tx, opts )
}
func countUsers ( ctx context . Context , opts * CountUserFilter ) int64 {
@ -727,7 +727,7 @@ func countUsers(ctx context.Context, opts *CountUserFilter) int64 {
}
// GetVerifyUser get user by verify code
func GetVerifyUser ( code string ) ( user * User ) {
func GetVerifyUser ( ctx context . Context , c ode string ) ( user * User ) {
if len ( code ) <= base . TimeLimitCodeLength {
return nil
}
@ -735,7 +735,7 @@ func GetVerifyUser(code string) (user *User) {
// use tail hex username query user
hexStr := code [ base . TimeLimitCodeLength : ]
if b , err := hex . DecodeString ( hexStr ) ; err == nil {
if user , err = GetUserByName ( db . Defaul tConte xt , string ( b ) ) ; user != nil {
if user , err = GetUserByName ( c tx, string ( b ) ) ; user != nil {
return user
}
log . Error ( "user.getVerifyUser: %v" , err )
@ -745,10 +745,10 @@ func GetVerifyUser(code string) (user *User) {
}
// VerifyUserActiveCode verifies active code when active account
func VerifyUserActiveCode ( code string ) ( user * User ) {
func VerifyUserActiveCode ( ctx context . Context , c ode string ) ( user * User ) {
minutes := setting . Service . ActiveCodeLives
if user = GetVerifyUser ( code ) ; user != nil {
if user = GetVerifyUser ( ctx , c ode ) ; user != nil {
// time limit code
prefix := code [ : base . TimeLimitCodeLength ]
data := fmt . Sprintf ( "%d%s%s%s%s" , user . ID , user . Email , user . LowerName , user . Passwd , user . Rands )
@ -872,8 +872,8 @@ func UpdateUserCols(ctx context.Context, u *User, cols ...string) error {
}
// UpdateUserSetting updates user's settings.
func UpdateUserSetting ( u * User ) ( err error ) {
ctx , committer , err := db . TxContext ( db . Defaul tConte xt )
func UpdateUserSetting ( ctx context . Context , u * User ) ( err error ) {
ctx , committer , err := db . TxContext ( c tx)
if err != nil {
return err
}
@ -1021,9 +1021,9 @@ func GetMaileableUsersByIDs(ctx context.Context, ids []int64, isMention bool) ([
}
// GetUserNamesByIDs returns usernames for all resolved users from a list of Ids.
func GetUserNamesByIDs ( ids [ ] int64 ) ( [ ] string , error ) {
func GetUserNamesByIDs ( ctx context . Context , ids [ ] int64 ) ( [ ] string , error ) {
unames := make ( [ ] string , 0 , len ( ids ) )
err := db . GetEngine ( db . Defaul tConte xt ) . In ( "id" , ids ) .
err := db . GetEngine ( c tx) . In ( "id" , ids ) .
Table ( "user" ) .
Asc ( "name" ) .
Cols ( "name" ) .
@ -1062,9 +1062,9 @@ func GetUserIDsByNames(ctx context.Context, names []string, ignoreNonExistent bo
}
// GetUsersBySource returns a list of Users for a login source
func GetUsersBySource ( s * auth . Source ) ( [ ] * User , error ) {
func GetUsersBySource ( ctx context . Context , s * auth . Source ) ( [ ] * User , error ) {
var users [ ] * User
err := db . GetEngine ( db . Defaul tConte xt ) . Where ( "login_type = ? AND login_source = ?" , s . Type , s . ID ) . Find ( & users )
err := db . GetEngine ( c tx) . Where ( "login_type = ? AND login_source = ?" , s . Type , s . ID ) . Find ( & users )
return users , err
}
@ -1145,12 +1145,12 @@ func GetUserByEmail(ctx context.Context, email string) (*User, error) {
}
// GetUser checks if a user already exists
func GetUser ( user * User ) ( bool , error ) {
return db . GetEngine ( db . Defaul tConte xt ) . Get ( user )
func GetUser ( ctx context . Context , user * User ) ( bool , error ) {
return db . GetEngine ( c tx) . Get ( user )
}
// GetUserByOpenID returns the user object by given OpenID if exists.
func GetUserByOpenID ( uri string ) ( * User , error ) {
func GetUserByOpenID ( ctx context . Context , uri string ) ( * User , error ) {
if len ( uri ) == 0 {
return nil , ErrUserNotExist { 0 , uri , 0 }
}
@ -1164,12 +1164,12 @@ func GetUserByOpenID(uri string) (*User, error) {
// Otherwise, check in openid table
oid := & UserOpenID { }
has , err := db . GetEngine ( db . Defaul tConte xt ) . Where ( "uri=?" , uri ) . Get ( oid )
has , err := db . GetEngine ( c tx) . Where ( "uri=?" , uri ) . Get ( oid )
if err != nil {
return nil , err
}
if has {
return GetUserByID ( db . Defaul tConte xt , oid . UID )
return GetUserByID ( c tx, oid . UID )
}
return nil , ErrUserNotExist { 0 , uri , 0 }
@ -1279,13 +1279,13 @@ func IsUserVisibleToViewer(ctx context.Context, u, viewer *User) bool {
}
// CountWrongUserType count OrgUser who have wrong type
func CountWrongUserType ( ) ( int64 , error ) {
return db . GetEngine ( db . Defaul tConte xt ) . Where ( builder . Eq { "type" : 0 } . And ( builder . Neq { "num_teams" : 0 } ) ) . Count ( new ( User ) )
func CountWrongUserType ( ctx context . Context ) ( int64 , error ) {
return db . GetEngine ( c tx) . Where ( builder . Eq { "type" : 0 } . And ( builder . Neq { "num_teams" : 0 } ) ) . Count ( new ( User ) )
}
// FixWrongUserType fix OrgUser who have wrong type
func FixWrongUserType ( ) ( int64 , error ) {
return db . GetEngine ( db . Defaul tConte xt ) . Where ( builder . Eq { "type" : 0 } . And ( builder . Neq { "num_teams" : 0 } ) ) . Cols ( "type" ) . NoAutoTime ( ) . Update ( & User { Type : 1 } )
func FixWrongUserType ( ctx context . Context ) ( int64 , error ) {
return db . GetEngine ( c tx) . Where ( builder . Eq { "type" : 0 } . And ( builder . Neq { "num_teams" : 0 } ) ) . Cols ( "type" ) . NoAutoTime ( ) . Update ( & User { Type : 1 } )
}
func GetOrderByName ( ) string {