generated from mattermost/mattermost-plugin-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Fix(Issue#202): counts in one request #225
Open
jufab
wants to merge
9
commits into
mattermost-community:master
Choose a base branch
from
jufab:issue-202
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bdb189c
feat: add count ressource for counter
jufab 80d96b7
chore: add count to update or add list
jufab 49f7ffc
fix: review
jufab e822f51
fix: count to fetchIssueCounts
jufab 6624565
chore: review count in one request and lists
jufab cd53a4b
fix: review
jufab 2d27842
fix: remove useless refreshAll
jufab 99b959c
fix: new review
jufab 046d508
Merge branch 'master' into issue-202
raghavaggarwal2308 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ | |
SendIssue(senderID, receiverID, message, description, postID string) (string, error) | ||
// GetIssueList gets the todos on listID for userID | ||
GetIssueList(userID, listID string) ([]*ExtendedIssue, error) | ||
// GetAllList get all issues | ||
GetAllList(userID string) (*ListsIssue, error) | ||
// CompleteIssue completes the todo issueID for userID, and returns the issue and the foreign ID if any | ||
CompleteIssue(userID, issueID string) (issue *Issue, foreignID string, listToUpdate string, err error) | ||
// AcceptIssue moves one the todo issueID of userID from inbox to myList, and returns the message and the foreignUserID if any | ||
|
@@ -115,7 +117,7 @@ | |
p.router.Use(p.withRecovery) | ||
|
||
p.router.HandleFunc("/add", p.checkAuth(p.handleAdd)).Methods(http.MethodPost) | ||
p.router.HandleFunc("/list", p.checkAuth(p.handleList)).Methods(http.MethodGet) | ||
p.router.HandleFunc("/lists", p.checkAuth(p.handleLists)).Methods(http.MethodGet) | ||
p.router.HandleFunc("/remove", p.checkAuth(p.handleRemove)).Methods(http.MethodPost) | ||
p.router.HandleFunc("/complete", p.checkAuth(p.handleComplete)).Methods(http.MethodPost) | ||
p.router.HandleFunc("/accept", p.checkAuth(p.handleAccept)).Methods(http.MethodPost) | ||
|
@@ -168,8 +170,9 @@ | |
|
||
telemetryRequest, err := GetTelemetryPayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get telemetry payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get telemetry payload from JSON.", err) | ||
msg := "Unable to get telemetry payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -188,8 +191,9 @@ | |
|
||
addRequest, err := GetAddIssuePayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get add issue payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get add issue payload from JSON.", err) | ||
msg := "Unable to get add issue payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -203,8 +207,9 @@ | |
if addRequest.SendTo == "" { | ||
_, err = p.listManager.AddIssue(userID, addRequest.Message, addRequest.Description, addRequest.PostID) | ||
if err != nil { | ||
p.API.LogError("Unable to add issue err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to add issue", err) | ||
msg := "Unable to add issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -220,16 +225,18 @@ | |
|
||
receiver, appErr := p.API.GetUserByUsername(addRequest.SendTo) | ||
if appErr != nil { | ||
p.API.LogError("username not valid, err=" + appErr.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to find user", appErr) | ||
msg := "Unable to find user" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
if receiver.Id == userID { | ||
_, err = p.listManager.AddIssue(userID, addRequest.Message, addRequest.Description, addRequest.PostID) | ||
if err != nil { | ||
p.API.LogError("Unable to add issue err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to add issue", err) | ||
msg := "Unable to add issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -255,8 +262,9 @@ | |
|
||
issueID, err := p.listManager.SendIssue(userID, receiver.Id, addRequest.Message, addRequest.Description, addRequest.PostID) | ||
if err != nil { | ||
p.API.LogError("Unable to send issue err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to send issue", err) | ||
msg := "Unable to send issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -281,31 +289,24 @@ | |
} | ||
} | ||
|
||
func (p *Plugin) handleList(w http.ResponseWriter, r *http.Request) { | ||
func (p *Plugin) handleLists(w http.ResponseWriter, r *http.Request) { | ||
userID := r.Header.Get("Mattermost-User-ID") | ||
|
||
listInput := r.URL.Query().Get("list") | ||
listID := MyListKey | ||
switch listInput { | ||
case OutFlag: | ||
listID = OutListKey | ||
case InFlag: | ||
listID = InListKey | ||
} | ||
|
||
issues, err := p.listManager.GetIssueList(userID, listID) | ||
allListIssue, err := p.listManager.GetAllList(userID) | ||
if err != nil { | ||
p.API.LogError("Unable to get issues for user err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to get issues for user", err) | ||
msg := "Unable to get issues for user" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
if len(issues) > 0 && r.URL.Query().Get("reminder") == "true" && p.getReminderPreference(userID) { | ||
if allListIssue != nil && len(allListIssue.My) > 0 && r.URL.Query().Get("reminder") == "true" && p.getReminderPreference(userID) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. I think we are changing the logic here, but I think we are actually fixing a bug. LGTM 👍 |
||
var lastReminderAt int64 | ||
lastReminderAt, err = p.getLastReminderTimeForUser(userID) | ||
if err != nil { | ||
p.API.LogError("Unable to send reminder err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to send reminder", err) | ||
msg := "Unable to send reminder" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -318,7 +319,7 @@ | |
nt := time.Unix(now/1000, 0).In(timezone) | ||
lt := time.Unix(lastReminderAt/1000, 0).In(timezone) | ||
if nt.Sub(lt).Hours() >= 1 && (nt.Day() != lt.Day() || nt.Month() != lt.Month() || nt.Year() != lt.Year()) { | ||
p.PostBotDM(userID, "Daily Reminder:\n\n"+issuesListToString(issues)) | ||
p.PostBotDM(userID, "Daily Reminder:\n\n"+issuesListToString(allListIssue.My)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this is a good bug fix here too. Nice work 👍 |
||
p.trackDailySummary(userID) | ||
err = p.saveLastReminderTimeForUser(userID) | ||
if err != nil { | ||
|
@@ -327,14 +328,15 @@ | |
} | ||
} | ||
|
||
issuesJSON, err := json.Marshal(issues) | ||
allListIssueJSON, err := json.Marshal(allListIssue) | ||
if err != nil { | ||
p.API.LogError("Unable marhsal issues list to json err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable marhsal issues list to json", err) | ||
msg := "Unable marhsal all lists issues to json" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
_, err = w.Write(issuesJSON) | ||
_, err = w.Write(allListIssueJSON) | ||
if err != nil { | ||
p.API.LogError("Unable to write json response err=" + err.Error()) | ||
} | ||
|
@@ -345,8 +347,9 @@ | |
|
||
editRequest, err := GetEditIssuePayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get edit issue payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get edit issue payload from JSON.", err) | ||
msg := "Unable to get edit issue payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -357,8 +360,9 @@ | |
|
||
foreignUserID, list, oldMessage, err := p.listManager.EditIssue(userID, editRequest.ID, editRequest.Message, editRequest.Description) | ||
if err != nil { | ||
p.API.LogError("Unable to edit message: err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to edit issue", err) | ||
msg := "Unable to edit message" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -385,8 +389,9 @@ | |
|
||
changeRequest, err := GetChangeAssignmentPayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get change request payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get change request from JSON.", err) | ||
msg := "Unable to get change request payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -397,15 +402,17 @@ | |
|
||
receiver, appErr := p.API.GetUserByUsername(changeRequest.SendTo) | ||
if appErr != nil { | ||
p.API.LogError("username not valid, err=" + appErr.Error()) | ||
p.handleErrorWithCode(w, http.StatusNotFound, "Unable to find user", appErr) | ||
msg := "username not valid" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusNotFound, msg, err) | ||
return | ||
} | ||
|
||
issueMessage, oldOwner, err := p.listManager.ChangeAssignment(changeRequest.ID, userID, receiver.Id) | ||
if err != nil { | ||
p.API.LogError("Unable to change the assignment of an issue: err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to change the assignment", err) | ||
msg := "Unable to change the assignment of an issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -431,8 +438,9 @@ | |
|
||
acceptRequest, err := GetAcceptRequestPayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get accept request payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get accept request from JSON.", err) | ||
msg := "Unable to get accept request payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -443,8 +451,9 @@ | |
|
||
todoMessage, sender, err := p.listManager.AcceptIssue(userID, acceptRequest.ID) | ||
if err != nil { | ||
p.API.LogError("Unable to accept issue err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to accept issue", err) | ||
msg := "Unable to accept issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -463,8 +472,9 @@ | |
|
||
completeRequest, err := GetCompleteIssuePayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get complete issue request payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get complete issue request from JSON.", err) | ||
msg := "Unable to get complete issue request payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -475,8 +485,9 @@ | |
|
||
issue, foreignID, listToUpdate, err := p.listManager.CompleteIssue(userID, completeRequest.ID) | ||
if err != nil { | ||
p.API.LogError("Unable to complete issue err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to complete issue", err) | ||
msg := "Unable to complete issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -503,8 +514,9 @@ | |
|
||
removeRequest, err := GetRemoveIssuePayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get remove issue request payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get remove issue request from JSON.", err) | ||
msg := "Unable to get remove issue request payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -515,8 +527,9 @@ | |
|
||
issue, foreignID, isSender, listToUpdate, err := p.listManager.RemoveIssue(userID, removeRequest.ID) | ||
if err != nil { | ||
p.API.LogError("Unable to remove issue, err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to remove issue", err) | ||
msg := "Unable to remove issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
p.sendRefreshEvent(userID, []string{listToUpdate}) | ||
|
@@ -549,8 +562,9 @@ | |
|
||
bumpRequest, err := GetBumpIssuePayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get bump issue request payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get bump issue request from JSON.", err) | ||
msg := "Unable to get bump issue request payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -561,8 +575,9 @@ | |
|
||
todoMessage, foreignUser, foreignIssueID, err := p.listManager.BumpIssue(userID, bumpRequest.ID) | ||
if err != nil { | ||
p.API.LogError("Unable to bump issue, err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to bump issue", err) | ||
msg := "Unable to bump issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -596,8 +611,9 @@ | |
|
||
configJSON, err := json.Marshal(clientConfig) | ||
if err != nil { | ||
p.API.LogError("Unable to marshal plugin configuration to json err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to marshal plugin configuration to json", err) | ||
msg := "Unable to marshal plugin configuration to json" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I was unclear about my request before. We shouldn't edit the log statements in functions unrelated to this PR's purpose. We can clean this up in a separate effort/PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry too. should I put everything back the way it was before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes everything that is not related to the main feature/effort of the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we do change the logging back the way it was for places unrelated the purpose of the PR, but I don't want to drag this PR on for that reason