aboutsummaryrefslogtreecommitdiff
path: root/clientapi
diff options
context:
space:
mode:
authorS7evinK <2353100+S7evinK@users.noreply.github.com>2022-02-16 18:55:38 +0100
committerGitHub <noreply@github.com>2022-02-16 18:55:38 +0100
commit5a39512f5f35b13adea3afc2e366e01ec73924de (patch)
treeac0e5cd6de8798e45cf0b5b37440ae08f4c7ba90 /clientapi
parente9b672a34e08bce9d12b2a2454c19fde6e52036e (diff)
Add account type (#2171)
* Add account_type for sqlite3 * Add account_type for postgres * Remove CreateGuestAccount from interface * Add new AccountTypes & update test * Use newly added AccountType for account creation * Add migrations * Reuse type * Add AccounnType to Device, so it can be verified on requests * Rename migration, add missing update for appservices * Rename sqlite3 migration * Add missing AccountType to return value * Update sqlite migration Change allowance check on /admin/whois * Fix migration, add IS NULL * Move accountType to completeRegistration * Fix migrations * Add passing test
Diffstat (limited to 'clientapi')
-rw-r--r--clientapi/routing/admin_whois.go4
-rw-r--r--clientapi/routing/register.go26
2 files changed, 18 insertions, 12 deletions
diff --git a/clientapi/routing/admin_whois.go b/clientapi/routing/admin_whois.go
index b448791c..87bb7936 100644
--- a/clientapi/routing/admin_whois.go
+++ b/clientapi/routing/admin_whois.go
@@ -47,8 +47,8 @@ func GetAdminWhois(
req *http.Request, userAPI api.UserInternalAPI, device *api.Device,
userID string,
) util.JSONResponse {
- if userID != device.UserID {
- // TODO: Still allow if user is admin
+ allowed := device.AccountType == api.AccountTypeAdmin || userID == device.UserID
+ if !allowed {
return util.JSONResponse{
Code: http.StatusForbidden,
JSON: jsonerror.Forbidden("userID does not match the current user"),
diff --git a/clientapi/routing/register.go b/clientapi/routing/register.go
index 8823a41e..fc275a5d 100644
--- a/clientapi/routing/register.go
+++ b/clientapi/routing/register.go
@@ -32,6 +32,12 @@ import (
"github.com/matrix-org/dendrite/internal/eventutil"
"github.com/matrix-org/dendrite/setup/config"
+ "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/tokens"
+ "github.com/matrix-org/util"
+ "github.com/prometheus/client_golang/prometheus"
+ log "github.com/sirupsen/logrus"
+
"github.com/matrix-org/dendrite/clientapi/auth"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
"github.com/matrix-org/dendrite/clientapi/httputil"
@@ -39,11 +45,6 @@ import (
"github.com/matrix-org/dendrite/clientapi/userutil"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/dendrite/userapi/storage/accounts"
- "github.com/matrix-org/gomatrixserverlib"
- "github.com/matrix-org/gomatrixserverlib/tokens"
- "github.com/matrix-org/util"
- "github.com/prometheus/client_golang/prometheus"
- log "github.com/sirupsen/logrus"
)
var (
@@ -701,7 +702,7 @@ func handleApplicationServiceRegistration(
// application service registration is entirely separate.
return completeRegistration(
req.Context(), userAPI, r.Username, "", appserviceID, req.RemoteAddr, req.UserAgent(),
- r.InhibitLogin, r.InitialDisplayName, r.DeviceID,
+ r.InhibitLogin, r.InitialDisplayName, r.DeviceID, userapi.AccountTypeAppService,
)
}
@@ -720,7 +721,7 @@ func checkAndCompleteFlow(
// This flow was completed, registration can continue
return completeRegistration(
req.Context(), userAPI, r.Username, r.Password, "", req.RemoteAddr, req.UserAgent(),
- r.InhibitLogin, r.InitialDisplayName, r.DeviceID,
+ r.InhibitLogin, r.InitialDisplayName, r.DeviceID, userapi.AccountTypeUser,
)
}
@@ -745,6 +746,7 @@ func completeRegistration(
username, password, appserviceID, ipAddr, userAgent string,
inhibitLogin eventutil.WeakBoolean,
displayName, deviceID *string,
+ accType userapi.AccountType,
) util.JSONResponse {
if username == "" {
return util.JSONResponse{
@@ -759,13 +761,12 @@ func completeRegistration(
JSON: jsonerror.BadJSON("missing password"),
}
}
-
var accRes userapi.PerformAccountCreationResponse
err := userAPI.PerformAccountCreation(ctx, &userapi.PerformAccountCreationRequest{
AppServiceID: appserviceID,
Localpart: username,
Password: password,
- AccountType: userapi.AccountTypeUser,
+ AccountType: accType,
OnConflict: userapi.ConflictAbort,
}, &accRes)
if err != nil {
@@ -963,5 +964,10 @@ func handleSharedSecretRegistration(userAPI userapi.UserInternalAPI, sr *SharedS
return *resErr
}
deviceID := "shared_secret_registration"
- return completeRegistration(req.Context(), userAPI, ssrr.User, ssrr.Password, "", req.RemoteAddr, req.UserAgent(), false, &ssrr.User, &deviceID)
+
+ accType := userapi.AccountTypeUser
+ if ssrr.Admin {
+ accType = userapi.AccountTypeAdmin
+ }
+ return completeRegistration(req.Context(), userAPI, ssrr.User, ssrr.Password, "", req.RemoteAddr, req.UserAgent(), false, &ssrr.User, &deviceID, accType)
}