mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 18:25:56 +01:00
Merge pull request #203 from xiahaoshawn/master
change password for admin user when in LDAP mode
This commit is contained in:
commit
f6a1b1c4e4
@ -187,7 +187,9 @@ func (ua *UserAPI) Delete() {
|
||||
// ChangePassword handles PUT to /api/users/{}/password
|
||||
func (ua *UserAPI) ChangePassword() {
|
||||
|
||||
if !(ua.AuthMode == "db_auth") {
|
||||
ldapAdminUser := (ua.AuthMode == "ldap_auth" && ua.userID == 1 && ua.userID == ua.currentUserID)
|
||||
|
||||
if !(ua.AuthMode == "db_auth" || ldapAdminUser) {
|
||||
ua.CustomAbort(http.StatusForbidden, "")
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ type BaseController struct {
|
||||
beego.Controller
|
||||
i18n.Locale
|
||||
SelfRegistration bool
|
||||
IsLdapAdminUser bool
|
||||
IsAdmin bool
|
||||
AuthMode string
|
||||
}
|
||||
@ -115,7 +116,11 @@ func (b *BaseController) Prepare() {
|
||||
if sessionUserID != nil {
|
||||
b.Data["Username"] = b.GetSession("username")
|
||||
b.Data["UserId"] = sessionUserID.(int)
|
||||
|
||||
|
||||
if (sessionUserID == 1 && b.AuthMode == "ldap_auth") {
|
||||
b.IsLdapAdminUser = true
|
||||
}
|
||||
|
||||
var err error
|
||||
b.IsAdmin, err = dao.IsAdminRole(sessionUserID.(int))
|
||||
if err != nil {
|
||||
@ -126,6 +131,7 @@ func (b *BaseController) Prepare() {
|
||||
|
||||
b.Data["IsAdmin"] = b.IsAdmin
|
||||
b.Data["SelfRegistration"] = b.SelfRegistration
|
||||
b.Data["IsLdapAdminUser"] = b.IsLdapAdminUser
|
||||
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,10 @@
|
||||
<li><a id="aChangePassword" href="/changePassword" target="_blank"><span class="glyphicon glyphicon-pencil"></span> {{i18n .Lang "change_password"}}</a></li>
|
||||
<li role="separator" class="divider"></li>
|
||||
{{ end }}
|
||||
{{ if eq .IsLdapAdminUser true }}
|
||||
<li><a id="aChangePassword" href="/changePassword" target="_blank"><span class="glyphicon glyphicon-pencil"></span> {{i18n .Lang "change_password"}}</a></li>
|
||||
<li role="separator" class="divider"></li>
|
||||
{{ end }}
|
||||
{{ if eq .AuthMode "db_auth" }}
|
||||
{{ if eq .IsAdmin true }}
|
||||
<li><a id="aAddUser" href="/addUser" target="_blank"><span class="glyphicon glyphicon-plus"></span> {{i18n .Lang "add_user"}}</a></li>
|
||||
|
Loading…
Reference in New Issue
Block a user