Skip to content

Commit

Permalink
MI-824 Update Imports
Browse files Browse the repository at this point in the history
* add validate subscription function for subscription interface

* update test cases

* Update plugin version
  • Loading branch information
jatinkksharma authored Mar 4, 2020
1 parent fb6ce25 commit 9c05165
Show file tree
Hide file tree
Showing 32 changed files with 141 additions and 131 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jobs:
build:
docker:
- image: circleci/golang:1.13-node
working_directory: /go/src/github.com/Brightscout/mattermost-plugin-confluence
working_directory: /go/src/github.com/mattermost/mattermost-plugin-confluence
steps:
- checkout
- restore_cache:
Expand All @@ -27,7 +27,7 @@ jobs:
release:
docker:
- image: cibuilds/github:0.12
working_directory: /go/src/github.com/Brightscout/mattermost-plugin-confluence
working_directory: /go/src/github.com/mattermost/mattermost-plugin-confluence
steps:
- checkout
- attach_workspace:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Mattermost Plugin Confluence [![CircleCI branch](https://img.shields.io/circleci/project/github/Brightscout/mattermost-plugin-confluence/master.svg)](https://circleci.com/gh/Brightscout/mattermost-plugin-confluence)
# Mattermost Plugin Confluence [![CircleCI branch](https://img.shields.io/circleci/project/github/mattermost/mattermost-plugin-confluence/master.svg)](https://circleci.com/gh/mattermost/mattermost-plugin-confluence)

A Mattermost plugin for Confluence. Supports Confluence Cloud, Server and Data Center versions.

Expand All @@ -25,7 +25,7 @@ Set up CircleCI to run the build job for each branch and build-and-release for e

## Installation

1. Go to the [releases page of this GitHub repository](https://github.com/Brightscout/mattermost-plugin-confluence/releases/latest) and download the latest release for your Mattermost server.
1. Go to the [releases page of this GitHub repository](https://github.com/mattermost/mattermost-plugin-confluence/releases/latest) and download the latest release for your Mattermost server.
2. Upload this file in the Mattermost **System Console > Plugins > Management** page to install the plugin. To learn more about how to upload a plugin, [see the documentation](https://docs.mattermost.com/administration/plugins.html#plugin-uploads).
3. You can configure the Plugin from **System Console > Plugins > Confluence**.

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/Brightscout/mattermost-plugin-confluence
module github.com/mattermost/mattermost-plugin-confluence

go 1.13

Expand Down
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "com.mattermost.confluence",
"name": "Confluence",
"description": "",
"version": "0.1.0",
"description": "Atlassian Confluence plugin for Mattermost.",
"version": "1.1.0",
"min_server_version": "5.12.0",
"server": {
"executables": {
Expand Down
8 changes: 4 additions & 4 deletions server/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (

"github.com/mattermost/mattermost-server/model"

"github.com/Brightscout/mattermost-plugin-confluence/server/config"
"github.com/Brightscout/mattermost-plugin-confluence/server/serializer"
"github.com/Brightscout/mattermost-plugin-confluence/server/service"
"github.com/Brightscout/mattermost-plugin-confluence/server/util"
"github.com/mattermost/mattermost-plugin-confluence/server/config"
"github.com/mattermost/mattermost-plugin-confluence/server/serializer"
"github.com/mattermost/mattermost-plugin-confluence/server/service"
"github.com/mattermost/mattermost-plugin-confluence/server/util"
)

type HandlerFunc func(context *model.CommandArgs, args ...string) *model.CommandResponse
Expand Down
4 changes: 2 additions & 2 deletions server/controller/atlassian_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"path"
"path/filepath"

"github.com/Brightscout/mattermost-plugin-confluence/server/config"
"github.com/Brightscout/mattermost-plugin-confluence/server/util"
"github.com/mattermost/mattermost-plugin-confluence/server/config"
"github.com/mattermost/mattermost-plugin-confluence/server/util"
)

var atlassianConnectJSON = &Endpoint{
Expand Down
6 changes: 3 additions & 3 deletions server/controller/confluence_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (

"github.com/gorilla/mux"

"github.com/Brightscout/mattermost-plugin-confluence/server/config"
"github.com/Brightscout/mattermost-plugin-confluence/server/serializer"
"github.com/Brightscout/mattermost-plugin-confluence/server/service"
"github.com/mattermost/mattermost-plugin-confluence/server/config"
"github.com/mattermost/mattermost-plugin-confluence/server/serializer"
"github.com/mattermost/mattermost-plugin-confluence/server/service"
)

var confluenceCloudWebhook = &Endpoint{
Expand Down
6 changes: 3 additions & 3 deletions server/controller/confluence_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package controller
import (
"net/http"

"github.com/Brightscout/mattermost-plugin-confluence/server/config"
"github.com/Brightscout/mattermost-plugin-confluence/server/serializer"
"github.com/Brightscout/mattermost-plugin-confluence/server/service"
"github.com/mattermost/mattermost-plugin-confluence/server/config"
"github.com/mattermost/mattermost-plugin-confluence/server/serializer"
"github.com/mattermost/mattermost-plugin-confluence/server/service"
)

var confluenceServerWebhook = &Endpoint{
Expand Down
6 changes: 3 additions & 3 deletions server/controller/edit_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"github.com/gorilla/mux"
"github.com/mattermost/mattermost-server/model"

"github.com/Brightscout/mattermost-plugin-confluence/server/config"
"github.com/Brightscout/mattermost-plugin-confluence/server/serializer"
"github.com/Brightscout/mattermost-plugin-confluence/server/service"
"github.com/mattermost/mattermost-plugin-confluence/server/config"
"github.com/mattermost/mattermost-plugin-confluence/server/serializer"
"github.com/mattermost/mattermost-plugin-confluence/server/service"
)

var editChannelSubscription = &Endpoint{
Expand Down
2 changes: 1 addition & 1 deletion server/controller/get_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/gorilla/mux"

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

var getChannelSubscription = &Endpoint{
Expand Down
4 changes: 2 additions & 2 deletions server/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/mattermost/mattermost-server/model"
"github.com/pkg/errors"

"github.com/Brightscout/mattermost-plugin-confluence/server/config"
"github.com/Brightscout/mattermost-plugin-confluence/server/util"
"github.com/mattermost/mattermost-plugin-confluence/server/config"
"github.com/mattermost/mattermost-plugin-confluence/server/util"
)

type Endpoint struct {
Expand Down
20 changes: 5 additions & 15 deletions server/controller/save_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"github.com/gorilla/mux"
"github.com/mattermost/mattermost-server/model"

"github.com/Brightscout/mattermost-plugin-confluence/server/config"
"github.com/Brightscout/mattermost-plugin-confluence/server/serializer"
"github.com/Brightscout/mattermost-plugin-confluence/server/service"
"github.com/mattermost/mattermost-plugin-confluence/server/config"
"github.com/mattermost/mattermost-plugin-confluence/server/serializer"
"github.com/mattermost/mattermost-plugin-confluence/server/service"
)

const subscriptionSaveSuccess = "Your subscription has been saved."
Expand All @@ -34,27 +34,17 @@ func handleSaveSubscription(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Could not decode request body", http.StatusBadRequest)
return
}
if errCode, vsErr := service.ValidateSpaceSubscription(subscription.(serializer.SpaceSubscription)); vsErr != nil {
config.Mattermost.LogError(vsErr.Error())
http.Error(w, vsErr.Error(), errCode)
return
}
} else if subscriptionType == serializer.SubscriptionTypePage {
subscription, err = serializer.PageSubscriptionFromJSON(r.Body)
if err != nil {
config.Mattermost.LogError("Error decoding request body.", "Error", err.Error())
http.Error(w, "Could not decode request body", http.StatusBadRequest)
return
}
if errCode, psErr := service.ValidatePageSubscription(subscription.(serializer.PageSubscription)); psErr != nil {
config.Mattermost.LogError(psErr.Error())
http.Error(w, psErr.Error(), errCode)
return
}
}
if sErr := service.SaveSubscription(subscription); sErr != nil {
if statusCode, sErr := service.SaveSubscription(subscription); sErr != nil {
config.Mattermost.LogError(sErr.Error())
http.Error(w, sErr.Error(), http.StatusBadRequest)
http.Error(w, sErr.Error(), statusCode)
return
}
post := &model.Post{
Expand Down
8 changes: 4 additions & 4 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/plugin"

"github.com/Brightscout/mattermost-plugin-confluence/server/command"
"github.com/Brightscout/mattermost-plugin-confluence/server/util"
"github.com/mattermost/mattermost-plugin-confluence/server/command"
"github.com/mattermost/mattermost-plugin-confluence/server/util"

"github.com/Brightscout/mattermost-plugin-confluence/server/config"
"github.com/Brightscout/mattermost-plugin-confluence/server/controller"
"github.com/mattermost/mattermost-plugin-confluence/server/config"
"github.com/mattermost/mattermost-plugin-confluence/server/controller"
)

const (
Expand Down
21 changes: 12 additions & 9 deletions server/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

"github.com/Brightscout/mattermost-plugin-confluence/server/config"
"github.com/Brightscout/mattermost-plugin-confluence/server/service"
"github.com/Brightscout/mattermost-plugin-confluence/server/util"
"github.com/mattermost/mattermost-plugin-confluence/server/config"
"github.com/mattermost/mattermost-plugin-confluence/server/service"
)

const (
Expand Down Expand Up @@ -41,6 +40,7 @@ func TestExecuteCommand(t *testing.T) {
for name, val := range map[string]struct {
commandArgs *model.CommandArgs
ephemeralMessage string
patchAPICalls func()
}{
"empty command ": {
commandArgs: &model.CommandArgs{Command: "/confluence", UserId: "abcdabcdabcdabcd", ChannelId: "testtesttesttest"},
Expand All @@ -53,6 +53,11 @@ func TestExecuteCommand(t *testing.T) {
"unsubscribe command ": {
commandArgs: &model.CommandArgs{Command: "/confluence unsubscribe \"abc\"", UserId: "abcdabcdabcdabcd", ChannelId: "testtesttesttest"},
ephemeralMessage: fmt.Sprintf(subscriptionDeleteSuccess, "abc"),
patchAPICalls: func() {
monkey.Patch(service.DeleteSubscription, func(channelID, alias string) error {
return nil
})
},
},
"unsubscribe command no alias": {
commandArgs: &model.CommandArgs{Command: "/confluence unsubscribe", UserId: "abcdabcdabcdabcd", ChannelId: "testtesttesttest"},
Expand All @@ -69,12 +74,10 @@ func TestExecuteCommand(t *testing.T) {
post := args.Get(1).(*model.Post)
assert.Equal(t, val.ephemeralMessage, post.Message)
}).Once().Return(&model.Post{})
monkey.Patch(service.DeleteSubscription, func(channelID, alias string) error {
return nil
})
monkey.Patch(util.IsSystemAdmin, func(userID string) bool {
return false
})
mockAPI.On("GetUser", mock.AnythingOfType("string")).Return(&model.User{Id: "123", Roles: ""}, nil)
if val.patchAPICalls != nil {
val.patchAPICalls()
}
res, err := p.ExecuteCommand(&plugin.Context{}, val.commandArgs)
assert.Nil(t, err)
assert.NotNil(t, res)
Expand Down
5 changes: 5 additions & 0 deletions server/serializer/channel_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const (
PageRemovedEvent = "page_removed"
SubscriptionTypeSpace = "space_subscription"
SubscriptionTypePage = "page_subscription"

aliasAlreadyExist = "A subscription with the same alias already exists."
urlSpaceKeyAlreadyExist = "A subscription with the same url and space key already exists."
urlPageIDAlreadyExist = "A subscription with the same url and page id already exists."
)

var eventDisplayName = map[string]string{
Expand All @@ -37,6 +41,7 @@ type Subscription interface {
Name() string
GetFormattedSubscription() string
IsValid() error
ValidateSubscription(*Subscriptions) error
}

type BaseSubscription struct {
Expand Down
2 changes: 1 addition & 1 deletion server/serializer/confluence_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/mattermost/mattermost-server/model"

"github.com/Brightscout/mattermost-plugin-confluence/server/config"
"github.com/mattermost/mattermost-plugin-confluence/server/config"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion server/serializer/confluence_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/mattermost/mattermost-server/model"

"github.com/Brightscout/mattermost-plugin-confluence/server/config"
"github.com/mattermost/mattermost-plugin-confluence/server/config"
)

const (
Expand Down
24 changes: 22 additions & 2 deletions server/serializer/page_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
url2 "net/url"
"strings"

"github.com/Brightscout/mattermost-plugin-confluence/server/store"
"github.com/mattermost/mattermost-plugin-confluence/server/store"
)

type PageSubscription struct {
Expand Down Expand Up @@ -52,7 +52,6 @@ func (ps PageSubscription) GetFormattedSubscription() string {
}

func (ps PageSubscription) IsValid() error {
// TODO : Clean subscription data
if ps.Alias == "" {
return errors.New("alias can not be empty")
}
Expand All @@ -65,6 +64,9 @@ func (ps PageSubscription) IsValid() error {
if ps.PageID == "" {
return errors.New("page id can not be empty")
}
if ps.ChannelID == "" {
return errors.New("channel id can not be empty")
}
return nil
}

Expand All @@ -73,3 +75,21 @@ func PageSubscriptionFromJSON(data io.Reader) (PageSubscription, error) {
err := json.NewDecoder(data).Decode(&ps)
return ps, err
}

func (ps PageSubscription) ValidateSubscription(subs *Subscriptions) error {
if err := ps.IsValid(); err != nil {
return err
}
if channelSubscriptions, valid := subs.ByChannelID[ps.ChannelID]; valid {
if _, ok := channelSubscriptions[ps.Alias]; ok {
return errors.New(aliasAlreadyExist)
}
}
key := store.GetURLPageIDCombinationKey(ps.BaseURL, ps.PageID)
if urlPageIDSubscriptions, valid := subs.ByURLPagID[key]; valid {
if _, ok := urlPageIDSubscriptions[ps.ChannelID]; ok {
return errors.New(urlPageIDAlreadyExist)
}
}
return nil
}
24 changes: 22 additions & 2 deletions server/serializer/space_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
url2 "net/url"
"strings"

"github.com/Brightscout/mattermost-plugin-confluence/server/store"
"github.com/mattermost/mattermost-plugin-confluence/server/store"
)

type SpaceSubscription struct {
Expand Down Expand Up @@ -52,7 +52,6 @@ func (ss SpaceSubscription) GetFormattedSubscription() string {
}

func (ss SpaceSubscription) IsValid() error {
// TODO : Clean subscription data
if ss.Alias == "" {
return errors.New("alias can not be empty")
}
Expand All @@ -65,6 +64,9 @@ func (ss SpaceSubscription) IsValid() error {
if ss.SpaceKey == "" {
return errors.New("space key can not be empty")
}
if ss.ChannelID == "" {
return errors.New("channel id can not be empty")
}
return nil
}

Expand All @@ -73,3 +75,21 @@ func SpaceSubscriptionFromJSON(data io.Reader) (SpaceSubscription, error) {
err := json.NewDecoder(data).Decode(&ps)
return ps, err
}

func (ss SpaceSubscription) ValidateSubscription(subs *Subscriptions) error {
if err := ss.IsValid(); err != nil {
return err
}
if channelSubscriptions, valid := subs.ByChannelID[ss.ChannelID]; valid {
if _, ok := channelSubscriptions[ss.Alias]; ok {
return errors.New(aliasAlreadyExist)
}
}
key := store.GetURLSpaceKeyCombinationKey(ss.BaseURL, ss.SpaceKey)
if urlSpaceKeySubscriptions, valid := subs.ByURLSpaceKey[key]; valid {
if _, ok := urlSpaceKeySubscriptions[ss.ChannelID]; ok {
return errors.New(urlSpaceKeyAlreadyExist)
}
}
return nil
}
4 changes: 2 additions & 2 deletions server/service/delete_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"encoding/json"
"fmt"

"github.com/Brightscout/mattermost-plugin-confluence/server/serializer"
"github.com/Brightscout/mattermost-plugin-confluence/server/store"
"github.com/mattermost/mattermost-plugin-confluence/server/serializer"
"github.com/mattermost/mattermost-plugin-confluence/server/store"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions server/service/delete_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"bou.ke/monkey"
"github.com/stretchr/testify/assert"

"github.com/Brightscout/mattermost-plugin-confluence/server/serializer"
"github.com/Brightscout/mattermost-plugin-confluence/server/store"
"github.com/mattermost/mattermost-plugin-confluence/server/serializer"
"github.com/mattermost/mattermost-plugin-confluence/server/store"
)

func TestDeleteSubscription(t *testing.T) {
Expand Down
Loading

0 comments on commit 9c05165

Please sign in to comment.