mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-19 02:03:49 +08:00
feat: add pagination for LdapSyncPage and fix the bug Ldap auto-sync cannot disable (#496)
* feat: add pagination for LdapSyncPage Signed-off-by: Yixiang Zhao <seriouszyx@foxmail.com> * fix: Ldap auto sync cannot disable Signed-off-by: Yixiang Zhao <seriouszyx@foxmail.com>
This commit is contained in:
@ -170,6 +170,7 @@ func (c *ApiController) UpdateLdap() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prevLdap := object.GetLdap(ldap.Id)
|
||||||
affected := object.UpdateLdap(&ldap)
|
affected := object.UpdateLdap(&ldap)
|
||||||
resp := wrapActionResponse(affected)
|
resp := wrapActionResponse(affected)
|
||||||
if affected {
|
if affected {
|
||||||
@ -177,6 +178,8 @@ func (c *ApiController) UpdateLdap() {
|
|||||||
}
|
}
|
||||||
if ldap.AutoSync != 0 {
|
if ldap.AutoSync != 0 {
|
||||||
object.GetLdapAutoSynchronizer().StartAutoSync(ldap.Id)
|
object.GetLdapAutoSynchronizer().StartAutoSync(ldap.Id)
|
||||||
|
} else if ldap.AutoSync == 0 && prevLdap.AutoSync != 0{
|
||||||
|
object.GetLdapAutoSynchronizer().StopAutoSync(ldap.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = resp
|
c.Data["json"] = resp
|
||||||
|
@ -162,7 +162,7 @@ func (l *ldapConn) GetLdapUsers(baseDn string) ([]ldapUser, error) {
|
|||||||
searchReq := goldap.NewSearchRequest(baseDn,
|
searchReq := goldap.NewSearchRequest(baseDn,
|
||||||
goldap.ScopeWholeSubtree, goldap.NeverDerefAliases, 0, 0, false,
|
goldap.ScopeWholeSubtree, goldap.NeverDerefAliases, 0, 0, false,
|
||||||
SearchFilter, SearchAttributes, nil)
|
SearchFilter, SearchAttributes, nil)
|
||||||
searchResult, err := l.Conn.Search(searchReq)
|
searchResult, err := l.Conn.SearchWithPaging(searchReq, 100)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,13 @@ func (l *LdapAutoSynchronizer) syncRoutine(ldap *Ldap, stopChan chan struct{}) {
|
|||||||
ticker := time.NewTicker(time.Duration(ldap.AutoSync) * time.Minute)
|
ticker := time.NewTicker(time.Duration(ldap.AutoSync) * time.Minute)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
for {
|
for {
|
||||||
|
select {
|
||||||
|
case <-stopChan:
|
||||||
|
logs.Info(fmt.Sprintf("autoSync goroutine for %s stopped", ldap.Id))
|
||||||
|
return
|
||||||
|
case <-ticker.C:
|
||||||
|
}
|
||||||
|
|
||||||
UpdateLdapSyncTime(ldap.Id)
|
UpdateLdapSyncTime(ldap.Id)
|
||||||
//fetch all users
|
//fetch all users
|
||||||
conn, err := GetLdapConn(ldap.Host, ldap.Port, ldap.Admin, ldap.Passwd)
|
conn, err := GetLdapConn(ldap.Host, ldap.Port, ldap.Admin, ldap.Passwd)
|
||||||
@ -84,12 +91,6 @@ func (l *LdapAutoSynchronizer) syncRoutine(ldap *Ldap, stopChan chan struct{}) {
|
|||||||
} else {
|
} else {
|
||||||
logs.Info(fmt.Sprintf("ldap autosync success, %d new users, %d existing users", len(users)-len(*existed), len(*existed)))
|
logs.Info(fmt.Sprintf("ldap autosync success, %d new users, %d existing users", len(users)-len(*existed), len(*existed)))
|
||||||
}
|
}
|
||||||
select {
|
|
||||||
case <-stopChan:
|
|
||||||
logs.Info(fmt.Sprintf("autoSync goroutine for %s stopped", ldap.Id))
|
|
||||||
return
|
|
||||||
case <-ticker.C:
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ class LdapSyncPage extends React.Component {
|
|||||||
ldap: null,
|
ldap: null,
|
||||||
users: [],
|
users: [],
|
||||||
existUuids: [],
|
existUuids: [],
|
||||||
selectedUsers: []
|
selectedUsers: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ class LdapSyncPage extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Table rowSelection={rowSelection} columns={columns} dataSource={users} rowKey="uuid" bordered
|
<Table rowSelection={rowSelection} columns={columns} dataSource={users} rowKey="uuid" bordered
|
||||||
pagination={{pageSize: 100}}
|
pagination={{defaultPageSize: 10, showQuickJumper: true, showSizeChanger: true}}
|
||||||
title={() => (
|
title={() => (
|
||||||
<div>
|
<div>
|
||||||
<span>{this.state.ldap?.serverName}</span>
|
<span>{this.state.ldap?.serverName}</span>
|
||||||
|
Reference in New Issue
Block a user