shared providers: allow to immediately re-add soft-deleted users

there is no need to wait for cache updates

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino 2022-11-01 12:53:08 +01:00
parent e3e85867b1
commit 91fae5c4d4
No known key found for this signature in database
GPG key ID: 935D2952DEC4EECF
2 changed files with 10 additions and 0 deletions

View file

@ -987,6 +987,12 @@ func sqlCommonAddUser(user *User, dbHandle *sql.DB) error {
defer cancel() defer cancel()
return sqlCommonExecuteTx(ctx, dbHandle, func(tx *sql.Tx) error { return sqlCommonExecuteTx(ctx, dbHandle, func(tx *sql.Tx) error {
if config.IsShared == 1 {
_, err := tx.ExecContext(ctx, getRemoveSoftDeletedUserQuery(), user.Username)
if err != nil {
return err
}
}
q := getAddUserQuery() q := getAddUserQuery()
_, err := tx.ExecContext(ctx, q, user.Username, user.Password, string(publicKeys), user.HomeDir, user.UID, user.GID, _, err := tx.ExecContext(ctx, q, user.Username, user.Password, string(publicKeys), user.HomeDir, user.UID, user.GID,
user.MaxSessions, user.QuotaSize, user.QuotaFiles, string(permissions), user.UploadBandwidth, user.MaxSessions, user.QuotaSize, user.QuotaFiles, string(permissions), user.UploadBandwidth,

View file

@ -527,6 +527,10 @@ func getDeleteUserQuery(softDelete bool) string {
return fmt.Sprintf(`DELETE FROM %s WHERE id = %s`, sqlTableUsers, sqlPlaceholders[0]) return fmt.Sprintf(`DELETE FROM %s WHERE id = %s`, sqlTableUsers, sqlPlaceholders[0])
} }
func getRemoveSoftDeletedUserQuery() string {
return fmt.Sprintf(`DELETE FROM %s WHERE username = %s AND deleted_at > 0`, sqlTableUsers, sqlPlaceholders[0])
}
func getFolderByNameQuery() string { func getFolderByNameQuery() string {
return fmt.Sprintf(`SELECT %s FROM %s WHERE name = %s`, selectFolderFields, sqlTableFolders, sqlPlaceholders[0]) return fmt.Sprintf(`SELECT %s FROM %s WHERE name = %s`, selectFolderFields, sqlTableFolders, sqlPlaceholders[0])
} }