Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,9 @@ func (p *Plugin) subscriptionsAddCommand(ctx context.Context, info *gitlab.UserI
}

if hasPermission := p.permissionToProject(ctx, info.UserID, namespace, project); !hasPermission {
p.API.LogWarn("You don't have the permission to create subscription for this project")
return "You don't have the permission to create subscription for this project."
msg := "You don't have the permissions to create subscriptions for this project"
p.client.Log.Warn(msg)
return msg
}

updatedSubscriptions, subscribeErr := p.Subscribe(info, namespace, project, channelID, features)
Expand Down
7 changes: 3 additions & 4 deletions server/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var subscribeCommandTests = []subscribeCommandTest{
testName: "No Repository permissions",
parameters: []string{"add", "group/project"},
mockGitlab: true,
want: "You don't have the permission to create subscription for this project.",
want: "You don't have the permissions to create subscriptions for this project",
webhookInfo: []*gitlab.WebhookInfo{{URL: "example.com/somewebhookURL"}},
noAccess: true,
mattermostURL: "example.com",
Expand All @@ -65,7 +65,7 @@ var subscribeCommandTests = []subscribeCommandTest{
testName: "Guest permissions only",
parameters: []string{"add", "group/project"},
mockGitlab: true,
want: "You don't have the permission to create subscription for this project.",
want: "You don't have the permissions to create subscriptions for this project",
webhookInfo: []*gitlab.WebhookInfo{{URL: "example.com/somewebhookURL"}},
noAccess: true,
mattermostURL: "example.com",
Expand Down Expand Up @@ -283,6 +283,7 @@ func getTestPlugin(t *testing.T, mockCtrl *gomock.Controller, hooks []*gitlab.We

api := &plugintest.API{}
p.SetAPI(api)
p.client = pluginapi.NewClient(api, p.Driver)

conf := &model.Config{}
conf.ServiceSettings.SiteURL = &mattermostURL
Expand Down Expand Up @@ -324,8 +325,6 @@ func getTestPlugin(t *testing.T, mockCtrl *gomock.Controller, hooks []*gitlab.We
mock.AnythingOfTypeArgument("string"),
mock.AnythingOfTypeArgument("string"))

p.client = pluginapi.NewClient(api, p.Driver)

return p
}

Expand Down
6 changes: 5 additions & 1 deletion server/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,15 @@ func (p *Plugin) permissionToProject(ctx context.Context, userID, namespace, pro
result, err := p.GitlabClient.GetProject(ctx, info, namespace, project)
if result == nil || err != nil {
if err != nil {
p.API.LogWarn("Can't get project in webhook", "err", err.Error(), "project", namespace+"/"+project)
p.client.Log.Warn("Can't get project in webhook", "err", err.Error(), "project", namespace+"/"+project)
}
return false
}

if result.Permissions.ProjectAccess == nil {
return false
}

// Check for guest level permissions
if result.Permissions.ProjectAccess != nil && result.Permissions.ProjectAccess.AccessLevel == gitlabLib.GuestPermissions {
return false
Expand Down