-
Notifications
You must be signed in to change notification settings - Fork 20
Let connected non-admins manage channel subscriptions on Confluence #232
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestCloudClientGetSpaceData(t *testing.T) { | ||
| var requestedPath string | ||
| ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| requestedPath = r.URL.RequestURI() | ||
| w.Header().Set("Content-Type", "application/json") | ||
| _, _ = w.Write([]byte(`{"id":1,"key":"MM","name":"Mattermost"}`)) | ||
| })) | ||
| defer ts.Close() | ||
|
|
||
| client := newCloudClient(ts.URL, ts.Client()) | ||
| space, err := client.GetSpaceData("MM") | ||
|
|
||
| require.NoError(t, err) | ||
| assert.Equal(t, "MM", space.Key) | ||
| assert.Equal(t, "/wiki/rest/api/space/MM?status=any", requestedPath) | ||
| } | ||
|
|
||
| func TestCloudClientGetSpaceDataForbidden(t *testing.T) { | ||
| ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
| w.WriteHeader(http.StatusForbidden) | ||
| })) | ||
| defer ts.Close() | ||
|
|
||
| _, err := newCloudClient(ts.URL, ts.Client()).GetSpaceData("MM") | ||
|
|
||
| require.Error(t, err) | ||
| assert.Contains(t, err.Error(), "403") | ||
| } | ||
|
|
||
| func TestCloudClientGetPageData(t *testing.T) { | ||
| var requestedPath string | ||
| ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| requestedPath = r.URL.Path | ||
| w.Header().Set("Content-Type", "application/json") | ||
| _, _ = w.Write([]byte(`{"id":"12345","title":"Release notes"}`)) | ||
| })) | ||
| defer ts.Close() | ||
|
|
||
| page, err := newCloudClient(ts.URL, ts.Client()).GetPageData(12345) | ||
|
|
||
| require.NoError(t, err) | ||
| assert.Equal(t, "Release notes", page.Title) | ||
| assert.Equal(t, "/wiki/rest/api/content/12345", requestedPath) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -287,31 +287,11 @@ func deleteSubscription(p *Plugin, context *model.CommandArgs, args ...string) * | |
| userID := context.UserId | ||
| channelID := context.ChannelId | ||
|
|
||
| if !util.IsSystemAdmin(userID) { | ||
| postCommandResponse(context, commandsOnlySystemAdmin) | ||
| if access := p.checkSubscriptionAccess(userID); !access.Allowed { | ||
| postCommandResponse(context, access.Message) | ||
|
Comment on lines
+290
to
+291
Member
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. It looks like with these changes, any member of a channel who connected their account to an instance can remove a subscription previously set by an admin, should this be something that also requires the permissions to manage a channel to do? (at least as I recall that's what was done for other plugins)
Contributor
Author
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. Good catch and Jira does this with No content risk at least
Member
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 agreed that it might be beneficial to have a product call on the behavior here, I personally feel like a model where:
Would be more ideal and prevents the possibility of anyone considering this a security concern (as similar gaps have needed to be closed due to this in other plugins)
Contributor
Author
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. @jgheithcock would you be able to lead us in the right direction here? |
||
| return &model.CommandResponse{} | ||
| } | ||
|
|
||
| pluginConfig := config.GetConfig() | ||
| if pluginConfig.ServerVersionGreaterthan9 { | ||
| conn, err := store.LoadConnection(pluginConfig.ConfluenceURL, userID) | ||
| if err != nil { | ||
| if strings.Contains(err.Error(), "not found") { | ||
| postCommandResponse(context, disconnectedUser) | ||
| return &model.CommandResponse{} | ||
| } | ||
|
|
||
| p.client.Log.Error("Error loading the connection for the user", "UserID", context.UserId, "error", err.Error()) | ||
| postCommandResponse(context, errorExecutingCommand) | ||
| return &model.CommandResponse{} | ||
| } | ||
|
|
||
| if len(conn.ConfluenceAccountID()) == 0 { | ||
| postCommandResponse(context, disconnectedUser) | ||
| return &model.CommandResponse{} | ||
| } | ||
| } | ||
|
|
||
| if len(args) == 0 { | ||
| postCommandResponse(context, specifyAlias) | ||
| return &model.CommandResponse{} | ||
|
|
@@ -334,26 +314,8 @@ func deleteSubscription(p *Plugin, context *model.CommandArgs, args ...string) * | |
| } | ||
|
|
||
| func listChannelSubscription(p *Plugin, context *model.CommandArgs, _ ...string) *model.CommandResponse { | ||
| pluginConfig := config.GetConfig() | ||
| if pluginConfig.ServerVersionGreaterthan9 { | ||
| conn, err := store.LoadConnection(pluginConfig.ConfluenceURL, context.UserId) | ||
| if err != nil { | ||
| if strings.Contains(err.Error(), "not found") { | ||
| postCommandResponse(context, disconnectedUser) | ||
| return &model.CommandResponse{} | ||
| } | ||
|
|
||
| p.client.Log.Error("Error loading the connection for the user", "UserID", context.UserId, "error", err.Error()) | ||
| postCommandResponse(context, errorExecutingCommand) | ||
| return &model.CommandResponse{} | ||
| } | ||
|
|
||
| if len(conn.ConfluenceAccountID()) == 0 { | ||
| postCommandResponse(context, disconnectedUser) | ||
| return &model.CommandResponse{} | ||
| } | ||
| } else if !util.IsSystemAdmin(context.UserId) { | ||
| postCommandResponse(context, commandsOnlySystemAdmin) | ||
| if access := p.checkSubscriptionAccess(context.UserId); !access.Allowed { | ||
| postCommandResponse(context, access.Message) | ||
| return &model.CommandResponse{} | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.