Skip to content

Commit

Permalink
Merge branch 'master' into GH-179
Browse files Browse the repository at this point in the history
  • Loading branch information
mickmister authored May 8, 2024
2 parents f901f42 + e0e2bda commit cb2c204
Show file tree
Hide file tree
Showing 21 changed files with 593 additions and 393 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ require (
github.com/rudderlabs/analytics-go v3.3.1+incompatible
github.com/stretchr/testify v1.7.0
golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb
golang.org/x/text v0.3.7
)
1 change: 1 addition & 0 deletions server/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
SubscriptionEventAssignedTo = "assigned_to"
SubscriptionEventAssignmentGroup = "assignment_group"
SubscriptionEventCreated = "created"
BulkSubscription = "Bulk"

// Filters
FilterCreatedByMe = "me"
Expand Down
2 changes: 2 additions & 0 deletions server/constants/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ const (
PathSysUserGroup = "/sys_user_group.do?sys_id=%s"
PathKnowledgeBase = PathServiceNowURL + "/kb_knowledge_base.do%%3Fsys_id=%s"
PathCategory = PathServiceNowURL + "/kb_category.do%%3Fsys_id=%s"
PathRecordList = "%s/nav_to.do?uri=%s_list.do%%3Fsysparm_query=active=true"
PathRecord = "%s/nav_to.do?uri=%s.do%%3Fsys_id=%s%%26sysparm_stack=%s_list.do%%3Fsysparm_query=active=true"
)
50 changes: 34 additions & 16 deletions server/mocks/mock_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 26 additions & 6 deletions server/plugin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,22 @@ func (p *Plugin) createSubscription(w http.ResponseWriter, r *http.Request) {
return
}

if statusCode, err = client.CreateSubscription(subscription); err != nil {
resp, statusCode, err := client.CreateSubscription(subscription)
if err != nil {
_ = p.handleClientError(w, r, err, false, statusCode, "", "")
p.API.LogError("Error in creating subscription", "Error", err.Error())
return
}

if subscription.RecordNumber != nil {
resp.Number = *subscription.RecordNumber
}

post := resp.CreateSubscriptionCreatedPost(p.botID, p.getConfiguration().ServiceNowBaseURL)
if _, postErr := p.API.CreatePost(post); postErr != nil {
p.API.LogError(constants.ErrorCreatePost, "Error", postErr.Error())
}

// Here, we are setting the Content-Type header even when it is being set in the "returnStatusOK" function
// because after "WriteHeader" is called, no headers can be set, so we have to set it before the call to "WriteHeader"
w.Header().Set("Content-Type", "application/json")
Expand Down Expand Up @@ -331,7 +341,7 @@ func (p *Plugin) deleteSubscription(w http.ResponseWriter, r *http.Request) {
subscriptionID := pathParams[constants.PathParamSubscriptionID]
client := p.GetClientFromRequest(r)
if statusCode, err := client.DeleteSubscription(subscriptionID); err != nil {
p.API.LogError(constants.ErrorDeleteSubscription, "subscriptionID", subscriptionID, "Error", err.Error())
p.API.LogError(constants.ErrorDeleteSubscription, "SubscriptionID", subscriptionID, "Error", err.Error())
responseMessage := "No record found"
if statusCode != http.StatusNotFound {
responseMessage = fmt.Sprintf("%s. Error: %s", constants.ErrorDeleteSubscription, err.Error())
Expand Down Expand Up @@ -367,16 +377,26 @@ func (p *Plugin) editSubscription(w http.ResponseWriter, r *http.Request) {
}

client := p.GetClientFromRequest(r)
if statusCode, err := client.EditSubscription(subscriptionID, subscription); err != nil {
p.API.LogError(constants.ErrorEditingSubscription, "subscriptionID", subscriptionID, "Error", err.Error())
resp, statusCode, editErr := client.EditSubscription(subscriptionID, subscription)
if editErr != nil {
p.API.LogError(constants.ErrorEditingSubscription, "SubscriptionID", subscriptionID, "Error", editErr.Error())
responseMessage := "No record found"
if statusCode != http.StatusNotFound {
responseMessage = fmt.Sprintf("%s. Error: %s", constants.ErrorEditingSubscription, err.Error())
responseMessage = fmt.Sprintf("%s. Error: %s", constants.ErrorEditingSubscription, editErr.Error())
}
_ = p.handleClientError(w, r, err, false, statusCode, "", responseMessage)
_ = p.handleClientError(w, r, editErr, false, statusCode, "", responseMessage)
return
}

if subscription.RecordNumber != nil {
resp.Number = *subscription.RecordNumber
}

post := resp.CreateSubscriptionEditedPost(p.botID, p.getConfiguration().ServiceNowBaseURL)
if _, postErr := p.API.CreatePost(post); postErr != nil {
p.API.LogError(constants.ErrorCreatePost, "Error", postErr.Error())
}

returnStatusOK(w)
}

Expand Down
Loading

0 comments on commit cb2c204

Please sign in to comment.