diff --git a/go.mod b/go.mod index 9e0ee00c..cda01535 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,7 @@ require ( github.com/lestrrat-go/jwx/v2 v2.0.18 github.com/lithammer/shortuuid/v3 v3.0.7 github.com/mattn/go-sqlite3 v1.14.18 - github.com/mhale/smtpd v0.8.0 + github.com/mhale/smtpd v0.8.1 github.com/minio/sio v0.3.1 github.com/otiai10/copy v1.14.0 github.com/pires/go-proxyproto v0.7.0 diff --git a/go.sum b/go.sum index 566000c9..dad59854 100644 --- a/go.sum +++ b/go.sum @@ -286,8 +286,8 @@ github.com/mattn/go-sqlite3 v1.14.18 h1:JL0eqdCOq6DJVNPSvArO/bIV9/P7fbGrV00LZHc+ github.com/mattn/go-sqlite3 v1.14.18/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= -github.com/mhale/smtpd v0.8.0 h1:5JvdsehCg33PQrZBvFyDMMUDQmvbzVpZgKob7eYBJc0= -github.com/mhale/smtpd v0.8.0/go.mod h1:MQl+y2hwIEQCXtNhe5+55n0GZOjSmeqORDIXbqUL3x4= +github.com/mhale/smtpd v0.8.1 h1:O02u8O3eYAGxZCGf4E98WjyB+rA3DVFZtchEialjX4s= +github.com/mhale/smtpd v0.8.1/go.mod h1:MQl+y2hwIEQCXtNhe5+55n0GZOjSmeqORDIXbqUL3x4= github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM= github.com/miekg/dns v1.1.57/go.mod h1:uqRjCRUuEAA6qsOiJvDd+CFo/vW+y5WR6SNmHE55hZk= github.com/minio/sio v0.3.1 h1:d59r5RTHb1OsQaSl1EaTWurzMMDRLA5fgNmjzD4eVu4= diff --git a/internal/dataprovider/bolt.go b/internal/dataprovider/bolt.go index ec9443f2..315b11a0 100644 --- a/internal/dataprovider/bolt.go +++ b/internal/dataprovider/bolt.go @@ -397,6 +397,9 @@ func (p *BoltProvider) addAdmin(admin *Admin) error { admin.LastLogin = 0 admin.CreatedAt = util.GetTimeAsMsSinceEpoch(time.Now()) admin.UpdatedAt = util.GetTimeAsMsSinceEpoch(time.Now()) + sort.Slice(admin.Groups, func(i, j int) bool { + return admin.Groups[i].Name < admin.Groups[j].Name + }) for idx := range admin.Groups { err = p.addAdminToGroupMapping(admin.Username, admin.Groups[idx].Name, groupBucket) if err != nil { @@ -455,6 +458,9 @@ func (p *BoltProvider) updateAdmin(admin *Admin) error { if err = p.addAdminToRole(admin.Username, admin.Role, rolesBucket); err != nil { return err } + sort.Slice(admin.Groups, func(i, j int) bool { + return admin.Groups[i].Name < admin.Groups[j].Name + }) for idx := range admin.Groups { err = p.addAdminToGroupMapping(admin.Username, admin.Groups[idx].Name, groupBucket) if err != nil { @@ -663,12 +669,18 @@ func (p *BoltProvider) addUser(user *User) error { if err := p.addUserToRole(user.Username, user.Role, rolesBucket); err != nil { return err } + sort.Slice(user.VirtualFolders, func(i, j int) bool { + return user.VirtualFolders[i].Name < user.VirtualFolders[j].Name + }) for idx := range user.VirtualFolders { err = p.addRelationToFolderMapping(user.VirtualFolders[idx].Name, user, nil, foldersBucket) if err != nil { return err } } + sort.Slice(user.Groups, func(i, j int) bool { + return user.Groups[i].Name < user.Groups[j].Name + }) for idx := range user.Groups { err = p.addUserToGroupMapping(user.Username, user.Groups[idx].Name, groupBucket) if err != nil { @@ -1434,6 +1446,9 @@ func (p *BoltProvider) addGroup(group *Group) error { group.UpdatedAt = util.GetTimeAsMsSinceEpoch(time.Now()) group.Users = nil group.Admins = nil + sort.Slice(group.VirtualFolders, func(i, j int) bool { + return group.VirtualFolders[i].Name < group.VirtualFolders[j].Name + }) for idx := range group.VirtualFolders { err = p.addRelationToFolderMapping(group.VirtualFolders[idx].Name, nil, group, foldersBucket) if err != nil { @@ -1476,6 +1491,9 @@ func (p *BoltProvider) updateGroup(group *Group) error { return err } } + sort.Slice(group.VirtualFolders, func(i, j int) bool { + return group.VirtualFolders[i].Name < group.VirtualFolders[j].Name + }) for idx := range group.VirtualFolders { err = p.addRelationToFolderMapping(group.VirtualFolders[idx].Name, nil, group, foldersBucket) if err != nil { @@ -3641,12 +3659,18 @@ func (p *BoltProvider) updateUserRelations(tx *bolt.Tx, user *User, oldUser User if err = p.removeUserFromRole(oldUser.Username, oldUser.Role, rolesBucket); err != nil { return err } + sort.Slice(user.VirtualFolders, func(i, j int) bool { + return user.VirtualFolders[i].Name < user.VirtualFolders[j].Name + }) for idx := range user.VirtualFolders { err = p.addRelationToFolderMapping(user.VirtualFolders[idx].Name, user, nil, foldersBucket) if err != nil { return err } } + sort.Slice(user.Groups, func(i, j int) bool { + return user.Groups[i].Name < user.Groups[j].Name + }) for idx := range user.Groups { err = p.addUserToGroupMapping(user.Username, user.Groups[idx].Name, groupsBucket) if err != nil { diff --git a/internal/dataprovider/memory.go b/internal/dataprovider/memory.go index ca6a27b6..79b31b3c 100644 --- a/internal/dataprovider/memory.go +++ b/internal/dataprovider/memory.go @@ -348,6 +348,9 @@ func (p *MemoryProvider) addUser(user *User) error { if err := p.addUserToRole(user.Username, user.Role); err != nil { return err } + sort.Slice(user.Groups, func(i, j int) bool { + return user.Groups[i].Name < user.Groups[j].Name + }) var mappedGroups []string for idx := range user.Groups { if err = p.addUserToGroupMapping(user.Username, user.Groups[idx].Name); err != nil { @@ -359,6 +362,9 @@ func (p *MemoryProvider) addUser(user *User) error { } mappedGroups = append(mappedGroups, user.Groups[idx].Name) } + sort.Slice(user.VirtualFolders, func(i, j int) bool { + return user.VirtualFolders[i].Name < user.VirtualFolders[j].Name + }) var mappedFolders []string for idx := range user.VirtualFolders { if err = p.addUserToFolderMapping(user.Username, user.VirtualFolders[idx].Name); err != nil { @@ -404,6 +410,9 @@ func (p *MemoryProvider) updateUser(user *User) error { //nolint:gocyclo for idx := range u.Groups { p.removeUserFromGroupMapping(u.Username, u.Groups[idx].Name) } + sort.Slice(user.Groups, func(i, j int) bool { + return user.Groups[i].Name < user.Groups[j].Name + }) for idx := range user.Groups { if err = p.addUserToGroupMapping(user.Username, user.Groups[idx].Name); err != nil { // try to add old mapping @@ -419,6 +428,9 @@ func (p *MemoryProvider) updateUser(user *User) error { //nolint:gocyclo for _, oldFolder := range u.VirtualFolders { p.removeRelationFromFolderMapping(oldFolder.Name, u.Username, "") } + sort.Slice(user.VirtualFolders, func(i, j int) bool { + return user.VirtualFolders[i].Name < user.VirtualFolders[j].Name + }) for idx := range user.VirtualFolders { if err = p.addUserToFolderMapping(user.Username, user.VirtualFolders[idx].Name); err != nil { // try to add old mapping @@ -728,6 +740,9 @@ func (p *MemoryProvider) addAdmin(admin *Admin) error { return err } var mappedAdmins []string + sort.Slice(admin.Groups, func(i, j int) bool { + return admin.Groups[i].Name < admin.Groups[j].Name + }) for idx := range admin.Groups { if err = p.addAdminToGroupMapping(admin.Username, admin.Groups[idx].Name); err != nil { // try to remove group mapping @@ -770,6 +785,9 @@ func (p *MemoryProvider) updateAdmin(admin *Admin) error { for idx := range a.Groups { p.removeAdminFromGroupMapping(a.Username, a.Groups[idx].Name) } + sort.Slice(admin.Groups, func(i, j int) bool { + return admin.Groups[i].Name < admin.Groups[j].Name + }) for idx := range admin.Groups { if err = p.addAdminToGroupMapping(admin.Username, admin.Groups[idx].Name); err != nil { // try to add old mapping @@ -1030,6 +1048,9 @@ func (p *MemoryProvider) addGroup(group *Group) error { group.UpdatedAt = util.GetTimeAsMsSinceEpoch(time.Now()) group.Users = nil group.Admins = nil + sort.Slice(group.VirtualFolders, func(i, j int) bool { + return group.VirtualFolders[i].Name < group.VirtualFolders[j].Name + }) var mappedFolders []string for idx := range group.VirtualFolders { if err = p.addGroupToFolderMapping(group.Name, group.VirtualFolders[idx].Name); err != nil { @@ -1063,6 +1084,9 @@ func (p *MemoryProvider) updateGroup(group *Group) error { for _, oldFolder := range g.VirtualFolders { p.removeRelationFromFolderMapping(oldFolder.Name, "", g.Name) } + sort.Slice(group.VirtualFolders, func(i, j int) bool { + return group.VirtualFolders[i].Name < group.VirtualFolders[j].Name + }) for idx := range group.VirtualFolders { if err = p.addGroupToFolderMapping(group.Name, group.VirtualFolders[idx].Name); err != nil { // try to add old mapping diff --git a/internal/dataprovider/sqlqueries.go b/internal/dataprovider/sqlqueries.go index 4ee644f3..7683d0f0 100644 --- a/internal/dataprovider/sqlqueries.go +++ b/internal/dataprovider/sqlqueries.go @@ -554,7 +554,7 @@ func getRelatedUsersForAPIKeysQuery(apiKeys []APIKey) string { } else { sb.WriteString("(0)") } - return fmt.Sprintf(`SELECT id,username FROM %s WHERE id IN %s`, sqlTableUsers, sb.String()) + return fmt.Sprintf(`SELECT id,username FROM %s WHERE id IN %s ORDER BY username`, sqlTableUsers, sb.String()) } func getRelatedAdminsForAPIKeysQuery(apiKeys []APIKey) string { @@ -575,7 +575,7 @@ func getRelatedAdminsForAPIKeysQuery(apiKeys []APIKey) string { } else { sb.WriteString("(0)") } - return fmt.Sprintf(`SELECT id,username FROM %s WHERE id IN %s`, sqlTableAdmins, sb.String()) + return fmt.Sprintf(`SELECT id,username FROM %s WHERE id IN %s ORDER BY username`, sqlTableAdmins, sb.String()) } func getUserByUsernameQuery(role string) string { @@ -838,7 +838,7 @@ func getRelatedGroupsForUsersQuery(users []User) string { sb.WriteString(")") } return fmt.Sprintf(`SELECT g.name,ug.group_type,ug.user_id FROM %s g INNER JOIN %s ug ON g.id = ug.group_id WHERE - ug.user_id IN %s ORDER BY ug.user_id`, getSQLQuotedName(sqlTableGroups), sqlTableUsersGroupsMapping, sb.String()) + ug.user_id IN %s ORDER BY g.name`, getSQLQuotedName(sqlTableGroups), sqlTableUsersGroupsMapping, sb.String()) } func getRelatedGroupsForAdminsQuery(admins []Admin) string { @@ -855,7 +855,7 @@ func getRelatedGroupsForAdminsQuery(admins []Admin) string { sb.WriteString(")") } return fmt.Sprintf(`SELECT g.name,ag.options,ag.admin_id FROM %s g INNER JOIN %s ag ON g.id = ag.group_id WHERE - ag.admin_id IN %s ORDER BY ag.admin_id`, getSQLQuotedName(sqlTableGroups), sqlTableAdminsGroupsMapping, sb.String()) + ag.admin_id IN %s ORDER BY g.name`, getSQLQuotedName(sqlTableGroups), sqlTableAdminsGroupsMapping, sb.String()) } func getRelatedFoldersForUsersQuery(users []User) string { @@ -873,7 +873,7 @@ func getRelatedFoldersForUsersQuery(users []User) string { } return fmt.Sprintf(`SELECT f.id,f.name,f.path,f.used_quota_size,f.used_quota_files,f.last_quota_update,fm.virtual_path, fm.quota_size,fm.quota_files,fm.user_id,f.filesystem,f.description FROM %s f INNER JOIN %s fm ON f.id = fm.folder_id WHERE - fm.user_id IN %s ORDER BY fm.user_id`, sqlTableFolders, sqlTableUsersFoldersMapping, sb.String()) + fm.user_id IN %s ORDER BY f.name`, sqlTableFolders, sqlTableUsersFoldersMapping, sb.String()) } func getRelatedUsersForFoldersQuery(folders []vfs.BaseVirtualFolder) string { @@ -890,7 +890,7 @@ func getRelatedUsersForFoldersQuery(folders []vfs.BaseVirtualFolder) string { sb.WriteString(")") } return fmt.Sprintf(`SELECT fm.folder_id,u.username FROM %s fm INNER JOIN %s u ON fm.user_id = u.id - WHERE fm.folder_id IN %s ORDER BY fm.folder_id`, sqlTableUsersFoldersMapping, sqlTableUsers, sb.String()) + WHERE fm.folder_id IN %s ORDER BY u.username`, sqlTableUsersFoldersMapping, sqlTableUsers, sb.String()) } func getRelatedGroupsForFoldersQuery(folders []vfs.BaseVirtualFolder) string { @@ -907,7 +907,7 @@ func getRelatedGroupsForFoldersQuery(folders []vfs.BaseVirtualFolder) string { sb.WriteString(")") } return fmt.Sprintf(`SELECT fm.folder_id,g.name FROM %s fm INNER JOIN %s g ON fm.group_id = g.id - WHERE fm.folder_id IN %s ORDER BY fm.folder_id`, sqlTableGroupsFoldersMapping, getSQLQuotedName(sqlTableGroups), + WHERE fm.folder_id IN %s ORDER BY g.name`, sqlTableGroupsFoldersMapping, getSQLQuotedName(sqlTableGroups), sb.String()) } @@ -925,7 +925,7 @@ func getRelatedUsersForGroupsQuery(groups []Group) string { sb.WriteString(")") } return fmt.Sprintf(`SELECT um.group_id,u.username FROM %s um INNER JOIN %s u ON um.user_id = u.id - WHERE um.group_id IN %s ORDER BY um.group_id`, sqlTableUsersGroupsMapping, sqlTableUsers, sb.String()) + WHERE um.group_id IN %s ORDER BY u.username`, sqlTableUsersGroupsMapping, sqlTableUsers, sb.String()) } func getRelatedAdminsForGroupsQuery(groups []Group) string { @@ -942,7 +942,7 @@ func getRelatedAdminsForGroupsQuery(groups []Group) string { sb.WriteString(")") } return fmt.Sprintf(`SELECT am.group_id,a.username FROM %s am INNER JOIN %s a ON am.admin_id = a.id - WHERE am.group_id IN %s ORDER BY am.group_id`, sqlTableAdminsGroupsMapping, sqlTableAdmins, sb.String()) + WHERE am.group_id IN %s ORDER BY a.username`, sqlTableAdminsGroupsMapping, sqlTableAdmins, sb.String()) } func getRelatedFoldersForGroupsQuery(groups []Group) string { @@ -960,7 +960,7 @@ func getRelatedFoldersForGroupsQuery(groups []Group) string { } return fmt.Sprintf(`SELECT f.id,f.name,f.path,f.used_quota_size,f.used_quota_files,f.last_quota_update,fm.virtual_path, fm.quota_size,fm.quota_files,fm.group_id,f.filesystem,f.description FROM %s f INNER JOIN %s fm ON f.id = fm.folder_id WHERE - fm.group_id IN %s ORDER BY fm.group_id`, sqlTableFolders, sqlTableGroupsFoldersMapping, sb.String()) + fm.group_id IN %s ORDER BY f.name`, sqlTableFolders, sqlTableGroupsFoldersMapping, sb.String()) } func getActiveTransfersQuery() string {