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 all 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 |
---|---|---|
|
@@ -23,6 +23,8 @@ const ( | |
|
||
// WSEventConfigUpdate is the WebSocket event to update the Todo list's configurations on webapp | ||
WSEventConfigUpdate = "config_update" | ||
|
||
ErrorMsgAddIssue = "Unable to add issue" | ||
) | ||
|
||
// ListManager represents the logic on the lists | ||
|
@@ -33,6 +35,8 @@ type ListManager interface { | |
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 | ||
|
@@ -121,7 +125,7 @@ func (p *Plugin) initializeAPI() { | |
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) | ||
|
@@ -174,8 +178,9 @@ func (p *Plugin) handleTelemetry(w http.ResponseWriter, r *http.Request) { | |
|
||
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 | ||
} | ||
|
||
|
@@ -194,8 +199,9 @@ func (p *Plugin) handleAdd(w http.ResponseWriter, r *http.Request) { | |
|
||
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 | ||
} | ||
|
||
|
@@ -209,8 +215,8 @@ func (p *Plugin) handleAdd(w http.ResponseWriter, r *http.Request) { | |
if addRequest.SendTo == "" { | ||
_, err = p.listManager.AddIssue(userID, addRequest.Message, addRequest.Description, addRequest.PostID) | ||
if err != nil { | ||
p.API.LogError("Unable to add the issue err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to add issue", err) | ||
p.API.LogError(ErrorMsgAddIssue, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, ErrorMsgAddIssue, err) | ||
return | ||
} | ||
|
||
|
@@ -226,16 +232,17 @@ func (p *Plugin) handleAdd(w http.ResponseWriter, r *http.Request) { | |
|
||
receiver, appErr := p.API.GetUserByUsername(addRequest.SendTo) | ||
if appErr != nil { | ||
p.API.LogError("invalid username, err=" + appErr.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to find user", appErr) | ||
msg := "Unable to find user" | ||
p.API.LogError(msg, "err", appErr.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, appErr) | ||
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) | ||
p.API.LogError(ErrorMsgAddIssue, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, ErrorMsgAddIssue, err) | ||
return | ||
} | ||
|
||
|
@@ -261,8 +268,9 @@ func (p *Plugin) handleAdd(w http.ResponseWriter, r *http.Request) { | |
|
||
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 | ||
} | ||
|
||
|
@@ -287,31 +295,24 @@ func (p *Plugin) postReplyIfNeeded(postID, message, todo string) { | |
} | ||
} | ||
|
||
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 | ||
} | ||
|
||
|
@@ -324,7 +325,7 @@ func (p *Plugin) handleList(w http.ResponseWriter, r *http.Request) { | |
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 { | ||
|
@@ -333,14 +334,15 @@ func (p *Plugin) handleList(w http.ResponseWriter, r *http.Request) { | |
} | ||
} | ||
|
||
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 while listing issues err=" + err.Error()) | ||
} | ||
|
@@ -351,8 +353,9 @@ func (p *Plugin) handleEdit(w http.ResponseWriter, r *http.Request) { | |
|
||
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 | ||
} | ||
|
||
|
@@ -363,8 +366,9 @@ func (p *Plugin) handleEdit(w http.ResponseWriter, r *http.Request) { | |
|
||
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 | ||
} | ||
|
||
|
@@ -391,8 +395,9 @@ func (p *Plugin) handleChangeAssignment(w http.ResponseWriter, r *http.Request) | |
|
||
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 | ||
} | ||
|
||
|
@@ -403,15 +408,17 @@ func (p *Plugin) handleChangeAssignment(w http.ResponseWriter, r *http.Request) | |
|
||
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", appErr.Error()) | ||
p.handleErrorWithCode(w, http.StatusNotFound, msg, appErr) | ||
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 | ||
} | ||
|
||
|
@@ -437,8 +444,9 @@ func (p *Plugin) handleAccept(w http.ResponseWriter, r *http.Request) { | |
|
||
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 | ||
} | ||
|
||
|
@@ -449,8 +457,9 @@ func (p *Plugin) handleAccept(w http.ResponseWriter, r *http.Request) { | |
|
||
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 | ||
} | ||
|
||
|
@@ -469,8 +478,9 @@ func (p *Plugin) handleComplete(w http.ResponseWriter, r *http.Request) { | |
|
||
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 | ||
} | ||
|
||
|
@@ -481,8 +491,9 @@ func (p *Plugin) handleComplete(w http.ResponseWriter, r *http.Request) { | |
|
||
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 | ||
} | ||
|
||
|
@@ -509,8 +520,9 @@ func (p *Plugin) handleRemove(w http.ResponseWriter, r *http.Request) { | |
|
||
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 | ||
} | ||
|
||
|
@@ -521,8 +533,9 @@ func (p *Plugin) handleRemove(w http.ResponseWriter, r *http.Request) { | |
|
||
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}) | ||
|
@@ -555,8 +568,9 @@ func (p *Plugin) handleBump(w http.ResponseWriter, r *http.Request) { | |
|
||
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 | ||
} | ||
|
||
|
@@ -567,8 +581,9 @@ func (p *Plugin) handleBump(w http.ResponseWriter, r *http.Request) { | |
|
||
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 | ||
} | ||
|
||
|
@@ -602,8 +617,9 @@ func (p *Plugin) handleConfig(w http.ResponseWriter, r *http.Request) { | |
|
||
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