diff options
author | Till <2353100+S7evinK@users.noreply.github.com> | 2023-04-14 13:35:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-14 12:35:27 +0100 |
commit | c45d8cd68875f7f5081f252cfdc2dd32f99c58f8 (patch) | |
tree | ee3d2fd0df11fc7bebc0d57ffa6040c5fb2bd203 /userapi/internal | |
parent | ca63b414da87f7bdb25effffd187d51191a42b3e (diff) |
Add pushrules tests (#3044)
partly takes care of https://github.com/matrix-org/dendrite/issues/2870
by making sure that rule IDs don't start with a dot.
Co-authored-by: kegsay <kegan@matrix.org>
Diffstat (limited to 'userapi/internal')
-rw-r--r-- | userapi/internal/user_api.go | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/userapi/internal/user_api.go b/userapi/internal/user_api.go index 6dad91dd..139ca758 100644 --- a/userapi/internal/user_api.go +++ b/userapi/internal/user_api.go @@ -26,6 +26,7 @@ import ( appserviceAPI "github.com/matrix-org/dendrite/appservice/api" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" fedsenderapi "github.com/matrix-org/dendrite/federationapi/api" + "github.com/matrix-org/dendrite/internal/pushrules" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" "github.com/sirupsen/logrus" @@ -872,36 +873,28 @@ func (a *UserInternalAPI) QueryPushers(ctx context.Context, req *api.QueryPusher func (a *UserInternalAPI) PerformPushRulesPut( ctx context.Context, - req *api.PerformPushRulesPutRequest, - _ *struct{}, + userID string, + ruleSets *pushrules.AccountRuleSets, ) error { - bs, err := json.Marshal(&req.RuleSets) + bs, err := json.Marshal(ruleSets) if err != nil { return err } userReq := api.InputAccountDataRequest{ - UserID: req.UserID, + UserID: userID, DataType: pushRulesAccountDataType, AccountData: json.RawMessage(bs), } var userRes api.InputAccountDataResponse // empty - if err := a.InputAccountData(ctx, &userReq, &userRes); err != nil { - return err - } - return nil + return a.InputAccountData(ctx, &userReq, &userRes) } -func (a *UserInternalAPI) QueryPushRules(ctx context.Context, req *api.QueryPushRulesRequest, res *api.QueryPushRulesResponse) error { - localpart, domain, err := gomatrixserverlib.SplitID('@', req.UserID) - if err != nil { - return fmt.Errorf("failed to split user ID %q for push rules", req.UserID) - } - pushRules, err := a.DB.QueryPushRules(ctx, localpart, domain) +func (a *UserInternalAPI) QueryPushRules(ctx context.Context, userID string) (*pushrules.AccountRuleSets, error) { + localpart, domain, err := gomatrixserverlib.SplitID('@', userID) if err != nil { - return fmt.Errorf("failed to query push rules: %w", err) + return nil, fmt.Errorf("failed to split user ID %q for push rules", userID) } - res.RuleSets = pushRules - return nil + return a.DB.QueryPushRules(ctx, localpart, domain) } func (a *UserInternalAPI) SetAvatarURL(ctx context.Context, localpart string, serverName gomatrixserverlib.ServerName, avatarURL string) (*authtypes.Profile, bool, error) { |