mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-07 06:03:09 -06:00
Add new DeleteProfile API
This commit is contained in:
parent
cacb611fb0
commit
016d451d90
|
|
@ -61,6 +61,7 @@ type MediaUserAPI interface {
|
|||
type FederationUserAPI interface {
|
||||
QueryOpenIDToken(ctx context.Context, req *QueryOpenIDTokenRequest, res *QueryOpenIDTokenResponse) error
|
||||
QueryProfile(ctx context.Context, req *QueryProfileRequest, res *QueryProfileResponse) error
|
||||
DeleteProfile(ctx context.Context, req *PerformDeleteProfileRequest, res *struct{}) error
|
||||
}
|
||||
|
||||
// api functions required by the sync api
|
||||
|
|
@ -629,3 +630,9 @@ type PerformForgetThreePIDRequest QueryLocalpartForThreePIDRequest
|
|||
type PerformSaveThreePIDAssociationRequest struct {
|
||||
ThreePID, Localpart, Medium string
|
||||
}
|
||||
|
||||
type PerformDeleteProfileRequest struct {
|
||||
UserID string
|
||||
}
|
||||
|
||||
type PerformDeleteProfileResponse struct{}
|
||||
|
|
|
|||
|
|
@ -203,6 +203,12 @@ func (t *UserInternalAPITrace) PerformSaveThreePIDAssociation(ctx context.Contex
|
|||
return err
|
||||
}
|
||||
|
||||
func (t *UserInternalAPITrace) DeleteProfile(ctx context.Context, req *PerformDeleteProfileRequest, res *struct{}) error {
|
||||
err := t.Impl.DeleteProfile(ctx, req, res)
|
||||
util.GetLogger(ctx).Infof("DeleteProfile req=%+v res=%+v", js(req), js(res))
|
||||
return err
|
||||
}
|
||||
|
||||
func js(thing interface{}) string {
|
||||
b, err := json.Marshal(thing)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -832,4 +832,12 @@ func (a *UserInternalAPI) PerformSaveThreePIDAssociation(ctx context.Context, re
|
|||
return a.DB.SaveThreePIDAssociation(ctx, req.ThreePID, req.Localpart, req.Medium)
|
||||
}
|
||||
|
||||
func (a *UserInternalAPI) DeleteProfile(ctx context.Context, req *api.PerformDeleteProfileRequest, res *struct{}) error {
|
||||
localpart, serverName, err := gomatrixserverlib.SplitID('@', req.UserID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return a.DB.DeleteProfile(ctx, localpart, serverName)
|
||||
}
|
||||
|
||||
const pushRulesAccountDataType = "m.push_rules"
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ const (
|
|||
PerformSetDisplayNamePath = "/userapi/performSetDisplayName"
|
||||
PerformForgetThreePIDPath = "/userapi/performForgetThreePID"
|
||||
PerformSaveThreePIDAssociationPath = "/userapi/performSaveThreePIDAssociation"
|
||||
PerformDeleteUserProfilePath = "/userapi/performDeleteUserProfile"
|
||||
|
||||
QueryKeyBackupPath = "/userapi/queryKeyBackup"
|
||||
QueryProfilePath = "/userapi/queryProfile"
|
||||
|
|
@ -391,3 +392,11 @@ func (h *httpUserInternalAPI) PerformSaveThreePIDAssociation(ctx context.Context
|
|||
apiURL := h.apiURL + PerformSaveThreePIDAssociationPath
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
||||
}
|
||||
|
||||
func (h *httpUserInternalAPI) DeleteProfile(ctx context.Context, req *api.PerformDeleteProfileRequest, res *struct{}) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, PerformDeleteUserProfilePath)
|
||||
defer span.Finish()
|
||||
|
||||
apiURL := h.apiURL + PerformDeleteUserProfilePath
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -457,4 +457,16 @@ func AddRoutes(internalAPIMux *mux.Router, s api.UserInternalAPI) {
|
|||
return util.JSONResponse{Code: http.StatusOK, JSON: &struct{}{}}
|
||||
}),
|
||||
)
|
||||
internalAPIMux.Handle(PerformDeleteUserProfilePath,
|
||||
httputil.MakeInternalAPI("performDeleteUserProfilePath", func(req *http.Request) util.JSONResponse {
|
||||
request := api.PerformDeleteProfileRequest{}
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||
}
|
||||
if err := s.DeleteProfile(req.Context(), &request, &struct{}{}); err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return util.JSONResponse{Code: http.StatusOK, JSON: &struct{}{}}
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue