mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-16 14:12:24 +03:00
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:
parent
9ebcebee43
commit
be8d490e56
5 changed files with 95 additions and 12 deletions
|
@ -31,7 +31,6 @@ type UserInternalAPI interface {
|
|||
FederationUserAPI
|
||||
|
||||
QuerySearchProfilesAPI // used by p2p demos
|
||||
QueryAccountByLocalpart(ctx context.Context, req *QueryAccountByLocalpartRequest, res *QueryAccountByLocalpartResponse) (err error)
|
||||
QueryExternalUserIDByLocalpartAndProvider(ctx context.Context, req *QueryLocalpartExternalIDRequest, res *QueryLocalpartExternalIDResponse) (err error)
|
||||
PerformLocalpartExternalUserIDCreation(ctx context.Context, req *PerformLocalpartExternalUserIDCreationRequest) (err error)
|
||||
}
|
||||
|
@ -89,6 +88,7 @@ type ClientUserAPI interface {
|
|||
QueryPushers(ctx context.Context, req *QueryPushersRequest, res *QueryPushersResponse) error
|
||||
QueryPushRules(ctx context.Context, userID string) (*pushrules.AccountRuleSets, error)
|
||||
QueryAccountAvailability(ctx context.Context, req *QueryAccountAvailabilityRequest, res *QueryAccountAvailabilityResponse) error
|
||||
QueryAccountByLocalpart(ctx context.Context, req *QueryAccountByLocalpartRequest, res *QueryAccountByLocalpartResponse) (err error)
|
||||
PerformAdminCreateRegistrationToken(ctx context.Context, registrationToken *clientapi.RegistrationToken) (bool, error)
|
||||
PerformAdminListRegistrationTokens(ctx context.Context, returnAll bool, valid bool) ([]clientapi.RegistrationToken, error)
|
||||
PerformAdminGetRegistrationToken(ctx context.Context, tokenString string) (*clientapi.RegistrationToken, error)
|
||||
|
@ -461,6 +461,7 @@ type Account struct {
|
|||
ServerName spec.ServerName
|
||||
AppServiceID string
|
||||
AccountType AccountType
|
||||
Deactivated bool
|
||||
// TODO: Associations (e.g. with application services)
|
||||
}
|
||||
|
||||
|
@ -660,7 +661,7 @@ type QueryAccountByLocalpartResponse struct {
|
|||
}
|
||||
|
||||
type QueryLocalpartExternalIDRequest struct {
|
||||
ExternalID string
|
||||
ExternalID string
|
||||
AuthProvider string
|
||||
}
|
||||
|
||||
|
@ -669,8 +670,8 @@ type QueryLocalpartExternalIDResponse struct {
|
|||
}
|
||||
|
||||
type PerformLocalpartExternalUserIDCreationRequest struct {
|
||||
Localpart string
|
||||
ExternalID string
|
||||
Localpart string
|
||||
ExternalID string
|
||||
AuthProvider string
|
||||
}
|
||||
|
||||
|
@ -914,7 +915,7 @@ type PerformUploadDeviceKeysResponse struct {
|
|||
}
|
||||
|
||||
type PerformAllowingMasterCrossSigningKeyReplacementWithoutUIARequest struct {
|
||||
UserID string
|
||||
UserID string
|
||||
Duration time.Duration
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -54,7 +54,7 @@ const deactivateAccountSQL = "" +
|
|||
"UPDATE userapi_accounts SET is_deactivated = 1 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 = 0"
|
||||
|
@ -135,6 +135,7 @@ func (s *accountsStatements) InsertAccount(
|
|||
ServerName: serverName,
|
||||
AppServiceID: appserviceID,
|
||||
AccountType: accountType,
|
||||
Deactivated: false,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -167,7 +168,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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue