Skip to content

Commit

Permalink
Merge branch 'master' into GH-54-make-apply
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrerich committed Aug 3, 2020
2 parents 96b9b95 + 014c742 commit 08e778a
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"release_notes_url": "https://github.com/mattermost/mattermost-plugin-confluence/releases/tag/v1.2.0",
"icon_path": "assets/icon.svg",
"version": "1.2.0",
"min_server_version": "5.12.0",
"min_server_version": "5.26.0",
"server": {
"executables": {
"linux-amd64": "server/dist/plugin-linux-amd64",
Expand Down
34 changes: 34 additions & 0 deletions server/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,43 @@ func GetCommand() *model.Command {
AutoComplete: true,
AutoCompleteDesc: "Available commands: subscribe, list, unsubscribe \"<name>\", edit \"<name>\", install cloud/server, help.",
AutoCompleteHint: "[command]",
AutocompleteData: getAutoCompleteData(),
}
}

func getAutoCompleteData() *model.AutocompleteData {
confluence := model.NewAutocompleteData("confluence", "[command]", "Available commands: subscribe, list, unsubscribe \"<name>\", edit \"<name>\", install cloud/server, help")

install := model.NewAutocompleteData("install", "", "Connect Mattermost to a Confluence instance")
installItems := []model.AutocompleteListItem{{
HelpText: "Connect Mattermost to a Confluence Cloud instance",
Item: "cloud",
}, {
HelpText: "Connect Mattermost to a Confluence Server or Data Center instance",
Item: "server",
}}
install.AddStaticListArgument("", false, installItems)
confluence.AddCommand(install)

list := model.NewAutocompleteData("list", "", "List all subscriptions for the current channel")
confluence.AddCommand(list)

edit := model.NewAutocompleteData("edit", "[name]", "Edit the subscription settings associated with the given subscription name")
edit.AddDynamicListArgument("name", "api/v1/autocomplete/GetChannelSubscriptions", false)
confluence.AddCommand(edit)

subscribe := model.NewAutocompleteData("subscribe", "", "Subscribe the current channel to notifications from Confluence")
confluence.AddCommand(subscribe)

unsubscribe := model.NewAutocompleteData("unsubscribe", "[name]", "Unsubscribe the current channel from notifications associated with the given subscription name")
unsubscribe.AddDynamicListArgument("name", "api/v1/autocomplete/GetChannelSubscriptions", false)
confluence.AddCommand(unsubscribe)

help := model.NewAutocompleteData("help", "", "Show confluence slash command help")
confluence.AddCommand(help)
return confluence
}

func executeConfluenceDefault(context *model.CommandArgs, args ...string) *model.CommandResponse {
out := invalidCommand + "\n\n"
out += getFullHelpText(context, args...)
Expand Down
36 changes: 36 additions & 0 deletions server/controller/get_subscriptions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package controller

import (
"encoding/json"
"net/http"

"github.com/mattermost/mattermost-plugin-confluence/server/service"
"github.com/mattermost/mattermost-server/v5/model"
)

var autocompleteGetChannelSubscriptions = &Endpoint{
RequiresAdmin: true,
Path: "/autocomplete/GetChannelSubscriptions",
Method: http.MethodGet,
Execute: handleGetChannelSubscriptions,
}

func handleGetChannelSubscriptions(w http.ResponseWriter, r *http.Request) {
channelID := r.FormValue("channel_id")
subscriptions, err := service.GetSubscriptionsByChannelID(channelID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

out := []model.AutocompleteListItem{}
for _, sub := range subscriptions {
out = append(out, model.AutocompleteListItem{
Item: sub.GetAlias(),
})
}

b, _ := json.Marshal(out)
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write(b)
}
2 changes: 2 additions & 0 deletions server/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var Endpoints = map[string]*Endpoint{
getEndpointKey(editChannelSubscription): editChannelSubscription,
getEndpointKey(confluenceServerWebhook): confluenceServerWebhook,
getEndpointKey(getChannelSubscription): getChannelSubscription,

getEndpointKey(autocompleteGetChannelSubscriptions): autocompleteGetChannelSubscriptions,
}

// Uniquely identifies an endpoint using path and method
Expand Down
1 change: 1 addition & 0 deletions server/serializer/channel_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Subscription interface {
Remove(*Subscriptions)
Edit(*Subscriptions)
Name() string
GetAlias() string
GetFormattedSubscription() string
IsValid() error
ValidateSubscription(*Subscriptions) error
Expand Down
4 changes: 4 additions & 0 deletions server/serializer/page_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (ps PageSubscription) Name() string {
return SubscriptionTypePage
}

func (ps PageSubscription) GetAlias() string {
return ps.Alias
}

func (ps PageSubscription) GetFormattedSubscription() string {
var events []string
for _, event := range ps.Events {
Expand Down
4 changes: 4 additions & 0 deletions server/serializer/space_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (ss SpaceSubscription) Name() string {
return SubscriptionTypeSpace
}

func (ss SpaceSubscription) GetAlias() string {
return ss.Alias
}

func (ss SpaceSubscription) GetFormattedSubscription() string {
var events []string
for _, event := range ss.Events {
Expand Down

0 comments on commit 08e778a

Please sign in to comment.