Skip to content

Commit

Permalink
MM-51188 Use mux.Router (#923)
Browse files Browse the repository at this point in the history
* Use mux.Router
  • Loading branch information
srkgupta authored Apr 3, 2023
1 parent 8dbe4b0 commit a8167cc
Show file tree
Hide file tree
Showing 21 changed files with 200 additions and 383 deletions.
15 changes: 0 additions & 15 deletions server/atlassian_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ import (
const userRedirectPageKey = "user-redirect"

func (p *Plugin) httpACJSON(w http.ResponseWriter, r *http.Request, instanceID types.ID) (int, error) {
if r.Method != http.MethodGet {
return respondErr(w, http.StatusMethodNotAllowed,
errors.New("method "+r.Method+" is not allowed, must be GET"))
}

return p.respondTemplate(w, r, "application/json", map[string]string{
"BaseURL": p.GetPluginURL(),
"RouteACJSON": instancePath(routeACJSON, instanceID),
Expand All @@ -34,11 +29,6 @@ func (p *Plugin) httpACJSON(w http.ResponseWriter, r *http.Request, instanceID t
}

func (p *Plugin) httpACInstalled(w http.ResponseWriter, r *http.Request) (int, error) {
if r.Method != http.MethodPost {
return respondErr(w, http.StatusMethodNotAllowed,
errors.New("method "+r.Method+" is not allowed, must be POST"))
}

body, err := ioutil.ReadAll(r.Body)
if err != nil {
return respondErr(w, http.StatusInternalServerError,
Expand Down Expand Up @@ -93,11 +83,6 @@ func (p *Plugin) httpACInstalled(w http.ResponseWriter, r *http.Request) (int, e
}

func (p *Plugin) httpACUninstalled(w http.ResponseWriter, r *http.Request) (int, error) {
if r.Method != http.MethodPost {
return respondErr(w, http.StatusMethodNotAllowed,
errors.New("method "+r.Method+" is not allowed, must be POST"))
}

// Just send an ok to the Jira server, even though we're not doing anything.
return respondJSON(w, []string{"OK"})
}
18 changes: 0 additions & 18 deletions server/autocomplete_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@ import (
)

func (p *Plugin) httpGetAutoCompleteFields(w http.ResponseWriter, r *http.Request) (int, error) {
if r.Method != http.MethodGet {
return http.StatusMethodNotAllowed,
errors.New("Request: " + r.Method + " is not allowed, must be GET")
}

mattermostUserID := r.Header.Get("Mattermost-User-Id")
if mattermostUserID == "" {
return http.StatusUnauthorized, errors.New("not authorized")
}

instanceID := r.FormValue("instance_id")
params := map[string]string{
"fieldName": r.FormValue("fieldName"),
Expand Down Expand Up @@ -59,16 +50,7 @@ func (p *Plugin) httpGetAutoCompleteFields(w http.ResponseWriter, r *http.Reques
}

func (p *Plugin) httpGetSearchUsers(w http.ResponseWriter, r *http.Request) (int, error) {
if r.Method != http.MethodGet {
return http.StatusMethodNotAllowed,
errors.New("Request: " + r.Method + " is not allowed, must be GET")
}

mattermostUserID := r.Header.Get("Mattermost-User-Id")
if mattermostUserID == "" {
return http.StatusUnauthorized, errors.New("not authorized")
}

instanceID := r.FormValue("instance_id")
projectKey := r.FormValue("project")
userSearch := r.FormValue("q")
Expand Down
24 changes: 12 additions & 12 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func createInstanceCommand(optInstance bool) *model.AutocompleteData {
uninstall := model.NewAutocompleteData(
"uninstall", "[cloud|server] [URL]", "Disconnect Mattermost from a Jira instance")
uninstall.AddStaticListArgument("Jira type: server or cloud", true, jiraTypes)
uninstall.AddDynamicListArgument("Jira instance", routeAutocompleteInstalledInstance, true)
uninstall.AddDynamicListArgument("Jira instance", makeAutocompleteRoute(routeAutocompleteInstalledInstance), true)
uninstall.RoleID = model.SystemAdminRoleId

list := model.NewAutocompleteData(
Expand Down Expand Up @@ -219,28 +219,28 @@ func withParamIssueKey(cmd *model.AutocompleteData) {
func createConnectCommand() *model.AutocompleteData {
connect := model.NewAutocompleteData(
"connect", "", "Connect your Mattermost account to your Jira account")
connect.AddDynamicListArgument("Jira URL", routeAutocompleteConnect, false)
connect.AddDynamicListArgument("Jira URL", makeAutocompleteRoute(routeAutocompleteConnect), false)
return connect
}

func createAliasCommand() *model.AutocompleteData {
alias := model.NewAutocompleteData(
"alias", "", "Create an alias to your Jira instance")
alias.AddDynamicListArgument("Jira URL", routeAutocompleteInstalledInstanceWithAlias, false)
alias.AddDynamicListArgument("Jira URL", makeAutocompleteRoute(routeAutocompleteInstalledInstanceWithAlias), false)
return alias
}

func createUnAliasCommand() *model.AutocompleteData {
alias := model.NewAutocompleteData(
"unalias", "", "Remove an alias from a Jira instance")
alias.AddDynamicListArgument("Jira URL", routeAutocompleteInstalledInstanceWithAlias, false)
alias.AddDynamicListArgument("Jira URL", makeAutocompleteRoute(routeAutocompleteInstalledInstanceWithAlias), false)
return alias
}

func createDisconnectCommand() *model.AutocompleteData {
disconnect := model.NewAutocompleteData(
"disconnect", "[Jira URL]", "Disconnect your Mattermost account from your Jira account")
disconnect.AddDynamicListArgument("Jira URL", routeAutocompleteInstalledInstanceWithAlias, false)
disconnect.AddDynamicListArgument("Jira URL", makeAutocompleteRoute(routeAutocompleteInstalledInstanceWithAlias), false)
return disconnect
}

Expand All @@ -258,7 +258,7 @@ func createSettingsCommand(optInstance bool) *model.AutocompleteData {
{HelpText: "Turn notifications on", Item: "on"},
{HelpText: "Turn notifications off", Item: "off"},
})
withFlagInstance(notifications, optInstance, routeAutocompleteInstalledInstanceWithAlias)
withFlagInstance(notifications, optInstance, makeAutocompleteRoute(routeAutocompleteInstalledInstanceWithAlias))
settings.AddCommand(notifications)

return settings
Expand All @@ -268,7 +268,7 @@ func createViewCommand(optInstance bool) *model.AutocompleteData {
view := model.NewAutocompleteData(
"view", "[issue]", "Display a Jira issue")
withParamIssueKey(view)
withFlagInstance(view, optInstance, routeAutocompleteInstalledInstanceWithAlias)
withFlagInstance(view, optInstance, makeAutocompleteRoute(routeAutocompleteInstalledInstanceWithAlias))
return view
}

Expand All @@ -278,7 +278,7 @@ func createTransitionCommand(optInstance bool) *model.AutocompleteData {
withParamIssueKey(transition)
// TODO: Implement dynamic transition autocomplete
transition.AddTextArgument("To state", "", "")
withFlagInstance(transition, optInstance, routeAutocompleteInstalledInstanceWithAlias)
withFlagInstance(transition, optInstance, makeAutocompleteRoute(routeAutocompleteInstalledInstanceWithAlias))
return transition
}

Expand All @@ -288,15 +288,15 @@ func createAssignCommand(optInstance bool) *model.AutocompleteData {
withParamIssueKey(assign)
// TODO: Implement dynamic Jira user search autocomplete
assign.AddTextArgument("User", "", "")
withFlagInstance(assign, optInstance, routeAutocompleteInstalledInstanceWithAlias)
withFlagInstance(assign, optInstance, makeAutocompleteRoute(routeAutocompleteInstalledInstanceWithAlias))
return assign
}

func createUnassignCommand(optInstance bool) *model.AutocompleteData {
unassign := model.NewAutocompleteData(
"unassign", "[Jira issue]", "Unassign a Jira issue")
withParamIssueKey(unassign)
withFlagInstance(unassign, optInstance, routeAutocompleteInstalledInstanceWithAlias)
withFlagInstance(unassign, optInstance, makeAutocompleteRoute(routeAutocompleteInstalledInstanceWithAlias))
return unassign
}

Expand All @@ -308,7 +308,7 @@ func createSubscribeCommand(optInstance bool) *model.AutocompleteData {

list := model.NewAutocompleteData(
"list", "", "List the Jira notifications sent to this channel")
withFlagInstance(list, optInstance, routeAutocompleteInstalledInstanceWithAlias)
withFlagInstance(list, optInstance, makeAutocompleteRoute(routeAutocompleteInstalledInstanceWithAlias))
subscribe.AddCommand(list)
return subscribe
}
Expand All @@ -317,7 +317,7 @@ func createWebhookCommand(optInstance bool) *model.AutocompleteData {
webhook := model.NewAutocompleteData(
"webhook", "[Jira URL]", "Display the webhook URLs to set up on Jira")
webhook.RoleID = model.SystemAdminRoleId
withFlagInstance(webhook, optInstance, routeAutocompleteInstalledInstanceWithAlias)
withFlagInstance(webhook, optInstance, makeAutocompleteRoute(routeAutocompleteInstalledInstanceWithAlias))
return webhook
}

Expand Down
Loading

0 comments on commit a8167cc

Please sign in to comment.