diff --git a/server/command.go b/server/command.go index 9abae21d..90f5edc4 100644 --- a/server/command.go +++ b/server/command.go @@ -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) diff --git a/server/command_test.go b/server/command_test.go index 8cc044e5..e6370bf7 100644 --- a/server/command_test.go +++ b/server/command_test.go @@ -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", @@ -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", @@ -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 @@ -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 } diff --git a/server/webhook.go b/server/webhook.go index 358ab085..073e30c3 100644 --- a/server/webhook.go +++ b/server/webhook.go @@ -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