Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MM-50981 Remove usage of model.AppError #921

Merged
merged 18 commits into from
Apr 5, 2023

Conversation

srkgupta
Copy link
Contributor

@srkgupta srkgupta commented Mar 7, 2023

Summary

Remove usage of model.AppError in JIRA plugin

Ticket Link

https://mattermost.atlassian.net/browse/MM-50981

@srkgupta srkgupta added the Work In Progress Not yet ready for review label Mar 7, 2023
@codecov-commenter
Copy link

codecov-commenter commented Mar 9, 2023

Codecov Report

Patch coverage: 21.05% and project coverage change: -0.13 ⚠️

Comparison is base (d6ba56f) 31.01% compared to head (aca3b96) 30.89%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #921      +/-   ##
==========================================
- Coverage   31.01%   30.89%   -0.13%     
==========================================
  Files          50       50              
  Lines        7389     7332      -57     
==========================================
- Hits         2292     2265      -27     
+ Misses       4911     4886      -25     
+ Partials      186      181       -5     
Impacted Files Coverage Δ
server/atlassian_connect.go 0.00% <0.00%> (ø)
server/client.go 8.04% <0.00%> (ø)
server/telemetry.go 0.00% <0.00%> (ø)
server/user_cloud.go 0.00% <0.00%> (ø)
server/user_server.go 7.54% <0.00%> (ø)
server/utils.go 17.69% <0.00%> (ø)
server/utils/kvstore/ots.go 0.00% <0.00%> (ø)
server/utils/kvstore/plugin_store.go 0.00% <0.00%> (ø)
server/webhook_parser.go 85.05% <0.00%> (ø)
server/plugin.go 11.65% <10.00%> (+0.12%) ⬆️
... and 10 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@srkgupta srkgupta added 2: Dev Review Requires review by a core committer 3: QA Review Requires review by a QA tester and removed Work In Progress Not yet ready for review labels Mar 9, 2023
@srkgupta srkgupta requested a review from hanzei March 9, 2023 06:19
@srkgupta srkgupta requested a review from m1lt0n March 15, 2023 08:35
Copy link

@m1lt0n m1lt0n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great changes and cleanup of the deprecated built-in go APIs too!

@hanzei
Copy link
Collaborator

hanzei commented Mar 23, 2023

@srkgupta Heads up that there is a merge conflict.

server/issue.go Outdated
}

if post != nil && len(post.FileIds) > 0 {
go func() {
conf := instance.Common().getConfig()
for _, fileID := range post.FileIds {
mattermostName, _, _, e := client.AddAttachment(p.API, created.ID, fileID, conf.maxAttachmentSize)
mattermostName, _, _, e := client.AddAttachment(*p.client, created.ID, fileID, conf.maxAttachmentSize)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we are here: Can we rename the error to the standard err?

Copy link
Collaborator

@hanzei hanzei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking over this huge effort 👍

  1. plugin_store.go was left untouched. Why is that the case? Can the code in there also get migrated?
  2. Let's double-check that the code migration around the KV store is correct. There are some edge cases we need to be aware of. More details in the comments below ⬇️

server/issue.go Show resolved Hide resolved
server/command.go Outdated Show resolved Hide resolved
server/kv.go Outdated
}

err := json.Unmarshal(data, v)
err := store.plugin.client.KV.Get(key, &v)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, v was passed to json.Unmarshal meaning it had to be an pointer. Why does a pointer to v get passed now?

server/kv.go Outdated
if appErr != nil {
return "", errors.WithMessage(appErr, "failed to load one-time secret "+key)
var secret string
err := store.get(hashkey(prefixOneTimeSecret, key), secret)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks suspicious. The stored data is not in JSON format, but store.get will try to unmarshal it. Are you sure this line works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Yes, this looks like the code was accidentally over-written. It should read:

err := store.plugin.client.KV.Get(hashkey(prefixOneTimeSecret, key), secret)

I will push a commit to fix this.

server/kv.go Outdated
Comment on lines 472 to 473
return nil, nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, the code returned an error in this case. Why was it removed?

server/plugin.go Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
Comment on lines 93 to 96
Configuration: validConfiguration,
CreatePostError: model.NewAppError("foo", "bar", nil, "", http.StatusInternalServerError),
CreatePostError: model.NewAppError("foo", "bar", nil, "", http.StatusBadRequest),
Request: httptest.NewRequest("POST", "/webhook?team=theteam&channel=thechannel&secret=thesecret", validRequestBody()),
ExpectedStatusCode: http.StatusInternalServerError,
ExpectedStatusCode: http.StatusBadRequest,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was there a behaviour change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Earlier, we were returning the status Code from the appError. However, since the error no longer has access to the returned Status Code, I had hardcoded it as http.StatusBadRequest which had caused this change. I will revert and hardcode the return status as http.StatusInternalServerError instead.

Screenshot 2023-03-24 at 10 45 21 AM

server/subscribe.go Outdated Show resolved Hide resolved
@srkgupta
Copy link
Contributor Author

Thanks for the detailed review @hanzei. Will be making the suggested changes shortly and request your re-review once its committed.

Copy link
Contributor

@mickmister mickmister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found other than Ben's comments above 👍

@srkgupta srkgupta requested a review from hanzei March 27, 2023 09:18
@srkgupta
Copy link
Contributor Author

srkgupta commented Mar 27, 2023

Hi @hanzei

I have made all the changes based on your feedback. Requesting your re-review on this.

Thanks

Copy link
Collaborator

@hanzei hanzei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two nits, but the rest LGTM 👍

server/kv.go Outdated Show resolved Hide resolved
server/kv.go Outdated Show resolved Hide resolved
@hanzei hanzei removed the 2: Dev Review Requires review by a core committer label Mar 30, 2023
Copy link
Collaborator

@hanzei hanzei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@hanzei hanzei added the Awaiting Submitter Action Blocked on the author label Apr 3, 2023
@hanzei
Copy link
Collaborator

hanzei commented Apr 3, 2023

@srkgupta Heads up that there are merge conflicts to resolve

@srkgupta srkgupta removed the Awaiting Submitter Action Blocked on the author label Apr 3, 2023
@srkgupta
Copy link
Contributor Author

srkgupta commented Apr 3, 2023

@DHaussermann this is ready to be QA'd, as it also has the code for mux.Router PR which was recently merged with master.

@hanzei hanzei added this to the v3.3.0 milestone Apr 3, 2023
Copy link

@DHaussermann DHaussermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smoke tested Jira

For the most part I saw no issue.

One problem I see on this branch is that authenticating to Jira server seems to no longer work. (no issues with Cloud authentication)
Steps:

  • Install a Jira server instance (mine is 9.5.0)

  • Run the /jira connect command

  • In the new tab click allow
    image

  • On the oAuth complete page I get a 405 response
    image
    -The ngrok tunnel to Jira shows nothing after the 302 (the other 2 calls in the screenshot happened later and are unrelated)
    image

@srkgupta unfortunately, because of a licensing issue on Jira server I was still working to resolve Friday, I did not confirm this was working on #923 and deffered testing until now so, I am unsure of which PR introduces the behavior.

@srkgupta
Copy link
Contributor Author

srkgupta commented Apr 4, 2023

Thanks @DHaussermann. I have fixed the issue now. This was again one of those cases, where the HTTP method wasn't clearly defined previously in the OAuth1 Complete endpoint. Please use the latest code and try again.

Copy link

@DHaussermann DHaussermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and passes
I have spent some time smoke testing and see no more regressions
Tested against both Cloud and Serever

  • Setup
  • Authentication flow (browser and desktop)
  • Issue creation and attachment
  • Subscription and delivery
  • Multiple instances connected
  • Tested various commands for assign, view and transition etc..

LGTM!

Thanks @srkgupta!

@DHaussermann DHaussermann added 4: Reviews Complete All reviewers have approved the pull request and removed 3: QA Review Requires review by a QA tester labels Apr 5, 2023
@hanzei hanzei merged commit fcc1205 into master Apr 5, 2023
@hanzei hanzei deleted the MM-50981_remove_model.AppError branch April 5, 2023 19:57
@mickmister mickmister mentioned this pull request Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants