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:
parent
e3e85867b1
commit
91fae5c4d4
2 changed files with 10 additions and 0 deletions
|
@ -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,
|
||||||
|
|
|
@ -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])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue