Skip to content

Commit 665ce1d

Browse files
6543zeripath
authored andcommitted
Drop Admin attribute based on LDAP when login (continue #1743) (#8849)
* Update User information in Gitea based on LDAP when login * Update Admin Flag only if exist in settings * Fix affectation * Update models/login_source.go Co-Authored-By: JustKiddingCode <[email protected]> * Better ident * Apply suggestions from code review Update user information Co-Authored-By: 6543 <[email protected]> * Make fmt * add err handling * if user exist but login is Prohibit return return nil, and Prohibit err * keep login speed * User sync is implemented at #1478 - so only make sure that admin acces is drpoed if changed * handle error and still use async task * no async * only update admin if Sync is enabled * update two comments * add lafriks suggestions Co-Authored-By: Lauris BH <[email protected]> * if adminFilter is set - use it Co-Authored-By: Lauris BH <[email protected]> * Update models/login_source.go well - I should look more detaild at suggestions :D Co-Authored-By: Lauris BH <[email protected]> * make it work again * set is_admin value to user * look nicer
1 parent 9bd879b commit 665ce1d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

models/login_source.go

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2014 The Gogs Authors. All rights reserved.
2+
// Copyright 2019 The Gitea Authors. All rights reserved.
23
// Use of this source code is governed by a MIT-style
34
// license that can be found in the LICENSE file.
45

@@ -403,6 +404,19 @@ func LoginViaLDAP(user *User, login, password string, source *LoginSource, autoR
403404

404405
var isAttributeSSHPublicKeySet = len(strings.TrimSpace(source.LDAP().AttributeSSHPublicKey)) > 0
405406

407+
// Update User admin flag if exist
408+
if isExist, err := IsUserExist(0, sr.Username); err != nil {
409+
return nil, err
410+
} else if isExist &&
411+
!user.ProhibitLogin && len(source.LDAP().AdminFilter) > 0 && user.IsAdmin != sr.IsAdmin {
412+
// Change existing admin flag only if AdminFilter option is set
413+
user.IsAdmin = sr.IsAdmin
414+
err = UpdateUserCols(user, "is_admin")
415+
if err != nil {
416+
return nil, err
417+
}
418+
}
419+
406420
if !autoRegister {
407421
if isAttributeSSHPublicKeySet && synchronizeLdapSSHPublicKeys(user, source, sr.SSHPublicKey) {
408422
return user, RewriteAllPublicKeys()

0 commit comments

Comments
 (0)