summaryrefslogtreecommitdiffstats
path: root/models/user.go
diff options
context:
space:
mode:
authorkolaente <konrad@kola-entertainments.de>2019-06-12 21:41:28 +0200
committertechknowlogick <techknowlogick@gitea.io>2019-06-12 15:41:28 -0400
commitf9ec2f89f2265bc1371a6c62359de9816534fa6b (patch)
treef48b138a457e5ac6cf843bbb38400926704370f7 /models/user.go
parent5832f8d90df2d72cb38698c3e9050f2b29717dc7 (diff)
downloadgitea-f9ec2f89f2265bc1371a6c62359de9816534fa6b.tar.gz
gitea-f9ec2f89f2265bc1371a6c62359de9816534fa6b.zip
Add golangci (#6418)
Diffstat (limited to 'models/user.go')
-rw-r--r--models/user.go29
1 files changed, 19 insertions, 10 deletions
diff --git a/models/user.go b/models/user.go
index e29cf5b32a..2820d2edbc 100644
--- a/models/user.go
+++ b/models/user.go
@@ -1072,7 +1072,10 @@ func deleteUser(e *xorm.Session, u *User) error {
if _, err = e.Delete(&PublicKey{OwnerID: u.ID}); err != nil {
return fmt.Errorf("deletePublicKeys: %v", err)
}
- rewriteAllPublicKeys(e)
+ err = rewriteAllPublicKeys(e)
+ if err != nil {
+ return err
+ }
// ***** END: PublicKey *****
// ***** START: GPGPublicKey *****
@@ -1401,8 +1404,7 @@ func (opts *SearchUserOptions) toConds() builder.Cond {
} else {
exprCond = builder.Expr("org_user.org_id = \"user\".id")
}
- var accessCond = builder.NewCond()
- accessCond = builder.Or(
+ accessCond := builder.Or(
builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": structs.VisibleTypePrivate}))),
builder.In("visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited))
cond = cond.And(accessCond)
@@ -1512,9 +1514,9 @@ func deleteKeysMarkedForDeletion(keys []string) (bool, error) {
}
// addLdapSSHPublicKeys add a users public keys. Returns true if there are changes.
-func addLdapSSHPublicKeys(usr *User, s *LoginSource, SSHPublicKeys []string) bool {
+func addLdapSSHPublicKeys(usr *User, s *LoginSource, sshPublicKeys []string) bool {
var sshKeysNeedUpdate bool
- for _, sshKey := range SSHPublicKeys {
+ for _, sshKey := range sshPublicKeys {
_, _, _, _, err := ssh.ParseAuthorizedKey([]byte(sshKey))
if err == nil {
sshKeyName := fmt.Sprintf("%s-%s", s.Name, sshKey[0:40])
@@ -1536,7 +1538,7 @@ func addLdapSSHPublicKeys(usr *User, s *LoginSource, SSHPublicKeys []string) boo
}
// synchronizeLdapSSHPublicKeys updates a users public keys. Returns true if there are changes.
-func synchronizeLdapSSHPublicKeys(usr *User, s *LoginSource, SSHPublicKeys []string) bool {
+func synchronizeLdapSSHPublicKeys(usr *User, s *LoginSource, sshPublicKeys []string) bool {
var sshKeysNeedUpdate bool
log.Trace("synchronizeLdapSSHPublicKeys[%s]: Handling LDAP Public SSH Key synchronization for user %s", s.Name, usr.Name)
@@ -1554,7 +1556,7 @@ func synchronizeLdapSSHPublicKeys(usr *User, s *LoginSource, SSHPublicKeys []str
// Get Public Keys from LDAP and skip duplicate keys
var ldapKeys []string
- for _, v := range SSHPublicKeys {
+ for _, v := range sshPublicKeys {
sshKeySplit := strings.Split(v, " ")
if len(sshKeySplit) > 1 {
ldapKey := strings.Join(sshKeySplit[:2], " ")
@@ -1634,9 +1636,13 @@ func SyncExternalUsers() {
// Find all users with this login type
var users []*User
- x.Where("login_type = ?", LoginLDAP).
+ err = x.Where("login_type = ?", LoginLDAP).
And("login_source = ?", s.ID).
Find(&users)
+ if err != nil {
+ log.Error("SyncExternalUsers: %v", err)
+ return
+ }
sr := s.LDAP().SearchEntries()
for _, su := range sr {
@@ -1694,7 +1700,7 @@ func SyncExternalUsers() {
// Check if user data has changed
if (len(s.LDAP().AdminFilter) > 0 && usr.IsAdmin != su.IsAdmin) ||
- strings.ToLower(usr.Email) != strings.ToLower(su.Mail) ||
+ !strings.EqualFold(usr.Email, su.Mail) ||
usr.FullName != fullName ||
!usr.IsActive {
@@ -1718,7 +1724,10 @@ func SyncExternalUsers() {
// Rewrite authorized_keys file if LDAP Public SSH Key attribute is set and any key was added or removed
if sshKeysNeedUpdate {
- RewriteAllPublicKeys()
+ err = RewriteAllPublicKeys()
+ if err != nil {
+ log.Error("RewriteAllPublicKeys: %v", err)
+ }
}
// Deactivate users not present in LDAP