mas: implemented PUT /admin/v2/users/{userID} endpoint

MAS requires this endpoint to fetch the data for the account management page
This commit is contained in:
Roman Isaev 2024-12-30 17:14:04 +00:00
parent 9ebcebee43
commit be8d490e56
No known key found for this signature in database
GPG key ID: 7BE2B6A6C89AEC7F
5 changed files with 95 additions and 12 deletions

View file

@ -55,7 +55,7 @@ const deactivateAccountSQL = "" +
"UPDATE userapi_accounts SET is_deactivated = TRUE WHERE localpart = $1 AND server_name = $2"
const selectAccountByLocalpartSQL = "" +
"SELECT localpart, server_name, appservice_id, account_type FROM userapi_accounts WHERE localpart = $1 AND server_name = $2"
"SELECT localpart, server_name, appservice_id, account_type, is_deactivated FROM userapi_accounts WHERE localpart = $1 AND server_name = $2"
const selectPasswordHashSQL = "" +
"SELECT password_hash FROM userapi_accounts WHERE localpart = $1 AND server_name = $2 AND is_deactivated = FALSE"
@ -116,6 +116,7 @@ func (s *accountsStatements) InsertAccount(
localpart string, serverName spec.ServerName,
hash, appserviceID string, accountType api.AccountType,
) (*api.Account, error) {
// TODO: can we replace "UnixNano() / 1M" with "UnixMilli()"?
createdTimeMS := time.Now().UnixNano() / 1000000
stmt := sqlutil.TxStmt(txn, s.insertAccountStmt)
@ -135,6 +136,7 @@ func (s *accountsStatements) InsertAccount(
ServerName: serverName,
AppServiceID: appserviceID,
AccountType: accountType,
Deactivated: false,
}, nil
}
@ -167,7 +169,7 @@ func (s *accountsStatements) SelectAccountByLocalpart(
var acc api.Account
stmt := s.selectAccountByLocalpartStmt
err := stmt.QueryRowContext(ctx, localpart, serverName).Scan(&acc.Localpart, &acc.ServerName, &appserviceIDPtr, &acc.AccountType)
err := stmt.QueryRowContext(ctx, localpart, serverName).Scan(&acc.Localpart, &acc.ServerName, &appserviceIDPtr, &acc.AccountType, &acc.Deactivated)
if err != nil {
if err != sql.ErrNoRows {
log.WithError(err).Error("Unable to retrieve user from the db")